1
0
Fork 0
mirror of https://github.com/transmission/transmission synced 2025-03-04 10:38:13 +00:00

remember the previous color of the pieces view as much as possible to avoid excessive drawing

This commit is contained in:
Mitchell Livingston 2008-06-10 21:13:33 +00:00
parent 658881a93b
commit a896093804
2 changed files with 80 additions and 21 deletions

View file

@ -31,7 +31,11 @@
#define HIGH_PEERS 15 #define HIGH_PEERS 15
#define FINISHED 1 #define PIECE_NONE 0
#define PIECE_MIXED 1
#define PIECE_FINISHED 2
#define PIECE_HIGH_PEERS 3
#define PIECE_FLASHING 4
@implementation PiecesView @implementation PiecesView
@ -140,41 +144,96 @@
break; break;
} }
NSColor * pieceColor; NSColor * pieceColor = nil;
if (showAvailablity) if (showAvailablity)
{ {
if (pieces[index] == -1) if (pieces[index] == -1)
{ {
pieceColor = !first && fPieces[index] != FINISHED ? [NSColor orangeColor] : fBluePieceColor; if (first || fPieces[index] != PIECE_FINISHED)
fPieces[index] = FINISHED; {
if (!first && fPieces[index] != PIECE_FLASHING)
{
pieceColor = [NSColor orangeColor];
fPieces[index] = PIECE_FLASHING;
} }
else else
{ {
float percent = MIN(1.0, (float)pieces[index]/HIGH_PEERS); pieceColor = fBluePieceColor;
fPieces[index] = PIECE_FINISHED;
}
}
}
else if (pieces[index] == 0)
{
if (first || fPieces[index] != PIECE_NONE)
{
pieceColor = [NSColor whiteColor];
fPieces[index] = PIECE_NONE;
}
}
else if (pieces[index] >= HIGH_PEERS)
{
if (first || fPieces[index] != PIECE_HIGH_PEERS)
{
pieceColor = fGreenAvailabilityColor;
fPieces[index] = PIECE_HIGH_PEERS;
}
}
else
{
if (first || fPieces[index] != PIECE_MIXED)
{
float percent = (float)pieces[index]/HIGH_PEERS;
pieceColor = [[NSColor whiteColor] blendedColorWithFraction: percent ofColor: fGreenAvailabilityColor]; pieceColor = [[NSColor whiteColor] blendedColorWithFraction: percent ofColor: fGreenAvailabilityColor];
fPieces[index] = 0; fPieces[index] = PIECE_MIXED;
}
} }
} }
else else
{ {
if (piecesPercent[index] == 1.0) if (piecesPercent[index] == 1.0)
{ {
pieceColor = !first && fPieces[index] != FINISHED ? [NSColor orangeColor] : fBluePieceColor; if (first || fPieces[index] != PIECE_FINISHED)
fPieces[index] = FINISHED; {
if (!first && fPieces[index] != PIECE_FLASHING)
{
pieceColor = [NSColor orangeColor];
fPieces[index] = PIECE_FLASHING;
} }
else else
{
pieceColor = fBluePieceColor;
fPieces[index] = PIECE_FINISHED;
}
}
}
else if (piecesPercent[index] == 0.0)
{
if (first || fPieces[index] != PIECE_NONE)
{
pieceColor = [NSColor whiteColor];
fPieces[index] = PIECE_NONE;
}
}
else
{
if (first || fPieces[index] != PIECE_MIXED)
{ {
pieceColor = [[NSColor whiteColor] blendedColorWithFraction: piecesPercent[index] ofColor: fBluePieceColor]; pieceColor = [[NSColor whiteColor] blendedColorWithFraction: piecesPercent[index] ofColor: fBluePieceColor];
fPieces[index] = 0; fPieces[index] = PIECE_MIXED;
}
} }
} }
if (pieceColor)
{
rect.origin = NSMakePoint(j * (fWidth + BETWEEN) + BETWEEN + fExtraBorder, 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);
} }
}
[image unlockFocus]; [image unlockFocus];
[self setNeedsDisplay]; [self setNeedsDisplay];

View file

@ -735,9 +735,9 @@
Torrent * torrent = [self representedObject]; Torrent * torrent = [self representedObject];
int pieceCount = MIN([torrent pieceCount], MAX_PIECES); int pieceCount = MIN([torrent pieceCount], MAX_PIECES);
float * piecePercent = malloc(pieceCount * sizeof(float)), float * piecesPercent = malloc(pieceCount * sizeof(float)),
* previousPiecePercent = [torrent getPreviousAmountFinished]; * previousPiecePercent = [torrent getPreviousAmountFinished];
[torrent getAmountFinished: piecePercent size: pieceCount]; [torrent getAmountFinished: piecesPercent size: pieceCount];
NSBitmapImageRep * bitmap = [[NSBitmapImageRep alloc] initWithBitmapDataPlanes: nil NSBitmapImageRep * bitmap = [[NSBitmapImageRep alloc] initWithBitmapDataPlanes: nil
pixelsWide: pieceCount pixelsHigh: 1 bitsPerSample: 8 samplesPerPixel: 4 hasAlpha: YES pixelsWide: pieceCount pixelsHigh: 1 bitsPerSample: 8 samplesPerPixel: 4 hasAlpha: YES
@ -747,16 +747,16 @@
for (i = 0; i < pieceCount; i++) for (i = 0; i < pieceCount; i++)
{ {
NSColor * pieceColor; NSColor * pieceColor;
if (piecePercent[i] == 1.0 && previousPiecePercent != NULL && previousPiecePercent[i] < 1.0) if (piecesPercent[i] == 1.0 && previousPiecePercent != NULL && previousPiecePercent[i] < 1.0)
pieceColor = [NSColor orangeColor]; pieceColor = [NSColor orangeColor];
else else
pieceColor = [[NSColor whiteColor] blendedColorWithFraction: piecePercent[i] ofColor: fBluePieceColor]; pieceColor = [[NSColor whiteColor] blendedColorWithFraction: piecesPercent[i] ofColor: fBluePieceColor];
//it's faster to just set color instead of checking previous color //it's faster to just set color instead of checking previous color
[bitmap setColor: pieceColor atX: i y: 0]; [bitmap setColor: pieceColor atX: i y: 0];
} }
[torrent setPreviousAmountFinished: piecePercent]; //holds onto piecePercent, so no need to release it here [torrent setPreviousAmountFinished: piecesPercent]; //holds onto piecePercent, so no need to release it here
//actually draw image //actually draw image
[bitmap drawInRect: barRect]; [bitmap drawInRect: barRect];