1
0
Fork 0
mirror of https://github.com/transmission/transmission synced 2025-02-25 15:32:33 +00:00

some cleanup of the pieces view code

This commit is contained in:
Mitchell Livingston 2008-06-10 20:15:00 +00:00
parent 493d0fa474
commit 658881a93b
2 changed files with 21 additions and 36 deletions

View file

@ -1146,7 +1146,6 @@ typedef enum
[fPiecesControl setSelected: !available forSegment: PIECES_CONTROL_PROGRESS]; [fPiecesControl setSelected: !available forSegment: PIECES_CONTROL_PROGRESS];
[[NSUserDefaults standardUserDefaults] setBool: available forKey: @"PiecesViewShowAvailability"]; [[NSUserDefaults standardUserDefaults] setBool: available forKey: @"PiecesViewShowAvailability"];
[fPiecesView clearView];
[fPiecesView updateView]; [fPiecesView updateView];
} }

View file

@ -108,8 +108,6 @@
fPieces = (int8_t *)tr_malloc(fNumPieces * sizeof(int8_t)); fPieces = (int8_t *)tr_malloc(fNumPieces * sizeof(int8_t));
first = YES; first = YES;
} }
NSImage * image = [self image];
int8_t * pieces = NULL; int8_t * pieces = NULL;
float * piecesPercent = NULL; float * piecesPercent = NULL;
@ -129,7 +127,8 @@
int i, j, index = -1; int i, j, index = -1;
NSRect rect = NSMakeRect(0, 0, fWidth, fWidth); NSRect rect = NSMakeRect(0, 0, fWidth, fWidth);
BOOL change = NO; NSImage * image = [self image];
[image lockFocus];
for (i = 0; i < fAcross; i++) for (i = 0; i < fAcross; i++)
for (j = 0; j < fAcross; j++) for (j = 0; j < fAcross; j++)
@ -142,56 +141,43 @@
} }
NSColor * pieceColor; NSColor * pieceColor;
if (showAvailablity) if (showAvailablity)
{ {
if (pieces[index] == -1) if (pieces[index] == -1)
{
pieceColor = !first && fPieces[index] != FINISHED ? [NSColor orangeColor] : fBluePieceColor; pieceColor = !first && fPieces[index] != FINISHED ? [NSColor orangeColor] : fBluePieceColor;
fPieces[index] = FINISHED;
}
else else
{ {
float percent; float percent = MIN(1.0, (float)pieces[index]/HIGH_PEERS);
if (pieces[index] < HIGH_PEERS)
percent = (float)pieces[index]/HIGH_PEERS;
else
percent = 1.0;
pieceColor = [[NSColor whiteColor] blendedColorWithFraction: percent ofColor: fGreenAvailabilityColor]; pieceColor = [[NSColor whiteColor] blendedColorWithFraction: percent ofColor: fGreenAvailabilityColor];
fPieces[index] = 0;
} }
fPieces[index] = pieces[index] == -1 ? FINISHED : 0;
} }
else else
{ {
if (piecesPercent[index] == 1.0 && !first && fPieces[index] != FINISHED) if (piecesPercent[index] == 1.0)
pieceColor = [NSColor orangeColor]; {
pieceColor = !first && fPieces[index] != FINISHED ? [NSColor orangeColor] : fBluePieceColor;
fPieces[index] = FINISHED;
}
else else
{
pieceColor = [[NSColor whiteColor] blendedColorWithFraction: piecesPercent[index] ofColor: fBluePieceColor]; pieceColor = [[NSColor whiteColor] blendedColorWithFraction: piecesPercent[index] ofColor: fBluePieceColor];
fPieces[index] = 0;
fPieces[index] = piecesPercent[index] == 1.0 ? FINISHED : 0; }
} }
if (pieceColor) rect.origin = NSMakePoint(j * (fWidth + BETWEEN) + BETWEEN + fExtraBorder,
{
//drawing actually will occur
if (!change)
{
[image lockFocus];
change = YES;
}
rect.origin = NSMakePoint(j * (fWidth + BETWEEN) + BETWEEN + fExtraBorder,
[image size].width - (i + 1) * (fWidth + BETWEEN) - fExtraBorder); [image size].width - (i + 1) * (fWidth + BETWEEN) - fExtraBorder);
[pieceColor set]; [pieceColor set];
NSRectFill(rect); NSRectFill(rect);
}
} }
if (change) [image unlockFocus];
{ [self setNeedsDisplay];
[image unlockFocus];
[self setNeedsDisplay];
}
tr_free(pieces); tr_free(pieces);
tr_free(piecesPercent); tr_free(piecesPercent);