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 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
@ -140,40 +144,95 @@
break;
}
NSColor * pieceColor;
NSColor * pieceColor = nil;
if (showAvailablity)
{
if (pieces[index] == -1)
{
pieceColor = !first && fPieces[index] != FINISHED ? [NSColor orangeColor] : fBluePieceColor;
fPieces[index] = FINISHED;
if (first || fPieces[index] != PIECE_FINISHED)
{
if (!first && fPieces[index] != PIECE_FLASHING)
{
pieceColor = [NSColor orangeColor];
fPieces[index] = PIECE_FLASHING;
}
else
{
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
{
float percent = MIN(1.0, (float)pieces[index]/HIGH_PEERS);
pieceColor = [[NSColor whiteColor] blendedColorWithFraction: percent ofColor: fGreenAvailabilityColor];
fPieces[index] = 0;
if (first || fPieces[index] != PIECE_MIXED)
{
float percent = (float)pieces[index]/HIGH_PEERS;
pieceColor = [[NSColor whiteColor] blendedColorWithFraction: percent ofColor: fGreenAvailabilityColor];
fPieces[index] = PIECE_MIXED;
}
}
}
else
{
if (piecesPercent[index] == 1.0)
{
pieceColor = !first && fPieces[index] != FINISHED ? [NSColor orangeColor] : fBluePieceColor;
fPieces[index] = FINISHED;
if (first || fPieces[index] != PIECE_FINISHED)
{
if (!first && fPieces[index] != PIECE_FLASHING)
{
pieceColor = [NSColor orangeColor];
fPieces[index] = PIECE_FLASHING;
}
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
{
pieceColor = [[NSColor whiteColor] blendedColorWithFraction: piecesPercent[index] ofColor: fBluePieceColor];
fPieces[index] = 0;
if (first || fPieces[index] != PIECE_MIXED)
{
pieceColor = [[NSColor whiteColor] blendedColorWithFraction: piecesPercent[index] ofColor: fBluePieceColor];
fPieces[index] = PIECE_MIXED;
}
}
}
rect.origin = NSMakePoint(j * (fWidth + BETWEEN) + BETWEEN + fExtraBorder,
[image size].width - (i + 1) * (fWidth + BETWEEN) - fExtraBorder);
if (pieceColor)
{
rect.origin = NSMakePoint(j * (fWidth + BETWEEN) + BETWEEN + fExtraBorder,
[image size].width - (i + 1) * (fWidth + BETWEEN) - fExtraBorder);
[pieceColor set];
NSRectFill(rect);
[pieceColor set];
NSRectFill(rect);
}
}
[image unlockFocus];

View file

@ -735,9 +735,9 @@
Torrent * torrent = [self representedObject];
int pieceCount = MIN([torrent pieceCount], MAX_PIECES);
float * piecePercent = malloc(pieceCount * sizeof(float)),
float * piecesPercent = malloc(pieceCount * sizeof(float)),
* previousPiecePercent = [torrent getPreviousAmountFinished];
[torrent getAmountFinished: piecePercent size: pieceCount];
[torrent getAmountFinished: piecesPercent size: pieceCount];
NSBitmapImageRep * bitmap = [[NSBitmapImageRep alloc] initWithBitmapDataPlanes: nil
pixelsWide: pieceCount pixelsHigh: 1 bitsPerSample: 8 samplesPerPixel: 4 hasAlpha: YES
@ -747,16 +747,16 @@
for (i = 0; i < pieceCount; i++)
{
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];
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
[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
[bitmap drawInRect: barRect];