Don't redraw the progress bar completely each time. The number of pieces for the bar is returned to the previous, larger value.
This commit is contained in:
parent
7a0a45d46c
commit
f9560758ed
|
@ -52,6 +52,9 @@
|
||||||
BOOL fFinishedSeeding, fWaitToStart, fError;
|
BOOL fFinishedSeeding, fWaitToStart, fError;
|
||||||
|
|
||||||
int fOrderValue;
|
int fOrderValue;
|
||||||
|
|
||||||
|
NSBitmapImageRep * fBitmap;
|
||||||
|
int8_t * fPieces;
|
||||||
}
|
}
|
||||||
|
|
||||||
- (id) initWithPath: (NSString *) path lib: (tr_handle_t *) lib;
|
- (id) initWithPath: (NSString *) path lib: (tr_handle_t *) lib;
|
||||||
|
|
|
@ -27,6 +27,9 @@
|
||||||
|
|
||||||
#define BAR_HEIGHT 12.0
|
#define BAR_HEIGHT 12.0
|
||||||
|
|
||||||
|
#define MAX_PIECES 324
|
||||||
|
#define BLANK_PIECE -99
|
||||||
|
|
||||||
@interface Torrent (Private)
|
@interface Torrent (Private)
|
||||||
|
|
||||||
- (id) initWithHash: (NSString *) hashString path: (NSString *) path lib: (tr_handle_t *) lib
|
- (id) initWithHash: (NSString *) hashString path: (NSString *) path lib: (tr_handle_t *) lib
|
||||||
|
@ -138,6 +141,10 @@ static uint32_t kRed = BE(0xFF6450FF), //255, 100, 80
|
||||||
[fStatusString release];
|
[fStatusString release];
|
||||||
[fShortStatusString release];
|
[fShortStatusString release];
|
||||||
[fRemainingTimeString release];
|
[fRemainingTimeString release];
|
||||||
|
|
||||||
|
|
||||||
|
[fBitmap release];
|
||||||
|
free(fPieces);
|
||||||
}
|
}
|
||||||
[super dealloc];
|
[super dealloc];
|
||||||
}
|
}
|
||||||
|
@ -821,32 +828,36 @@ static uint32_t kRed = BE(0xFF6450FF), //255, 100, 80
|
||||||
fShortStatusString = [[NSMutableString alloc] initWithCapacity: 30];
|
fShortStatusString = [[NSMutableString alloc] initWithCapacity: 30];
|
||||||
fRemainingTimeString = [[NSMutableString alloc] initWithCapacity: 30];
|
fRemainingTimeString = [[NSMutableString alloc] initWithCapacity: 30];
|
||||||
|
|
||||||
|
//set up advanced bar
|
||||||
|
fBitmap = [[NSBitmapImageRep alloc] initWithBitmapDataPlanes: nil
|
||||||
|
pixelsWide: MAX_PIECES pixelsHigh: BAR_HEIGHT bitsPerSample: 8 samplesPerPixel: 4 hasAlpha: YES
|
||||||
|
isPlanar: NO colorSpaceName: NSCalibratedRGBColorSpace bytesPerRow: 0 bitsPerPixel: 0];
|
||||||
|
|
||||||
|
fPieces = malloc(MAX_PIECES);
|
||||||
|
int i;
|
||||||
|
for (i = 0; i < MAX_PIECES; i++)
|
||||||
|
fPieces[i] = BLANK_PIECE;
|
||||||
|
|
||||||
[self update];
|
[self update];
|
||||||
return self;
|
return self;
|
||||||
}
|
}
|
||||||
|
|
||||||
- (NSImage *) advancedBar
|
- (NSImage *) advancedBar
|
||||||
{
|
{
|
||||||
int width = 225; //amount of pixels/"pieces"
|
|
||||||
|
|
||||||
NSBitmapImageRep * bitmap = [[NSBitmapImageRep alloc] initWithBitmapDataPlanes: nil
|
|
||||||
pixelsWide: width pixelsHigh: BAR_HEIGHT bitsPerSample: 8 samplesPerPixel: 4 hasAlpha: YES
|
|
||||||
isPlanar: NO colorSpaceName: NSCalibratedRGBColorSpace bytesPerRow: 0 bitsPerPixel: 0];
|
|
||||||
|
|
||||||
int h, w;
|
int h, w;
|
||||||
uint32_t * p;
|
uint32_t * p;
|
||||||
uint8_t * bitmapData = [bitmap bitmapData];
|
uint8_t * bitmapData = [fBitmap bitmapData];
|
||||||
int bytesPerRow = [bitmap bytesPerRow];
|
int bytesPerRow = [fBitmap bytesPerRow];
|
||||||
|
|
||||||
int8_t * pieces = malloc(width);
|
int8_t * pieces = malloc(MAX_PIECES);
|
||||||
[self getAvailability: pieces size: width];
|
[self getAvailability: pieces size: MAX_PIECES];
|
||||||
int avail = 0;
|
int avail = 0;
|
||||||
for (w = 0; w < width; w++)
|
for (w = 0; w < MAX_PIECES; w++)
|
||||||
if (pieces[w] != 0)
|
if (pieces[w] != 0)
|
||||||
avail++;
|
avail++;
|
||||||
|
|
||||||
//first two lines: dark blue to show progression, green to show available
|
//first two lines: dark blue to show progression, green to show available
|
||||||
int end = lrintf(floor([self progress] * width));
|
int end = [self progress] * MAX_PIECES;
|
||||||
p = (uint32_t *) bitmapData;
|
p = (uint32_t *) bitmapData;
|
||||||
|
|
||||||
for (w = 0; w < end; w++)
|
for (w = 0; w < end; w++)
|
||||||
|
@ -859,7 +870,7 @@ static uint32_t kRed = BE(0xFF6450FF), //255, 100, 80
|
||||||
p[w] = kGreen;
|
p[w] = kGreen;
|
||||||
p[w + bytesPerRow / 4] = kGreen;
|
p[w + bytesPerRow / 4] = kGreen;
|
||||||
}
|
}
|
||||||
for (; w < width; w++)
|
for (; w < MAX_PIECES; w++)
|
||||||
{
|
{
|
||||||
p[w] = kWhite;
|
p[w] = kWhite;
|
||||||
p[w + bytesPerRow / 4] = kWhite;
|
p[w + bytesPerRow / 4] = kWhite;
|
||||||
|
@ -867,19 +878,58 @@ static uint32_t kRed = BE(0xFF6450FF), //255, 100, 80
|
||||||
|
|
||||||
//lines 2 to 14: blue or grey depending on whether we have the piece or not
|
//lines 2 to 14: blue or grey depending on whether we have the piece or not
|
||||||
uint32_t color;
|
uint32_t color;
|
||||||
for( w = 0; w < width; w++ )
|
BOOL change;
|
||||||
|
for (w = 0; w < MAX_PIECES; w++)
|
||||||
{
|
{
|
||||||
|
change = NO;
|
||||||
if (pieces[w] < 0)
|
if (pieces[w] < 0)
|
||||||
|
{
|
||||||
|
if (fPieces[w] != -1)
|
||||||
|
{
|
||||||
color = kGreen;
|
color = kGreen;
|
||||||
|
fPieces[w] = -1;
|
||||||
|
change = YES;
|
||||||
|
}
|
||||||
|
}
|
||||||
else if (pieces[w] == 0)
|
else if (pieces[w] == 0)
|
||||||
|
{
|
||||||
|
if (fPieces[w] != 0)
|
||||||
|
{
|
||||||
color = kGray;
|
color = kGray;
|
||||||
|
fPieces[w] = 0;
|
||||||
|
change = YES;
|
||||||
|
}
|
||||||
|
}
|
||||||
else if (pieces[w] == 1)
|
else if (pieces[w] == 1)
|
||||||
|
{
|
||||||
|
if (fPieces[w] != 1)
|
||||||
|
{
|
||||||
color = kBlue1;
|
color = kBlue1;
|
||||||
|
fPieces[w] = 1;
|
||||||
|
change = YES;
|
||||||
|
}
|
||||||
|
}
|
||||||
else if (pieces[w] == 2)
|
else if (pieces[w] == 2)
|
||||||
|
{
|
||||||
|
if (fPieces[w] != 2)
|
||||||
|
{
|
||||||
color = kBlue2;
|
color = kBlue2;
|
||||||
|
fPieces[w] = 2;
|
||||||
|
change = YES;
|
||||||
|
}
|
||||||
|
}
|
||||||
else
|
else
|
||||||
|
{
|
||||||
|
if (fPieces[w] != 3)
|
||||||
|
{
|
||||||
color = kBlue3;
|
color = kBlue3;
|
||||||
|
fPieces[w] = 3;
|
||||||
|
change = YES;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if (change)
|
||||||
|
{
|
||||||
//point to pixel (w, 2) and draw "vertically"
|
//point to pixel (w, 2) and draw "vertically"
|
||||||
p = (uint32_t *)(bitmapData + 2 * bytesPerRow) + w;
|
p = (uint32_t *)(bitmapData + 2 * bytesPerRow) + w;
|
||||||
for (h = 2; h < BAR_HEIGHT; h++)
|
for (h = 2; h < BAR_HEIGHT; h++)
|
||||||
|
@ -888,14 +938,13 @@ static uint32_t kRed = BE(0xFF6450FF), //255, 100, 80
|
||||||
p = (uint32_t *)((uint8_t *)p + bytesPerRow);
|
p = (uint32_t *)((uint8_t *)p + bytesPerRow);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
free(pieces);
|
free(pieces);
|
||||||
|
|
||||||
//actually draw image
|
//actually draw image
|
||||||
NSImage * bar = [[NSImage alloc] initWithSize: [bitmap size]];
|
NSImage * bar = [[NSImage alloc] initWithSize: [fBitmap size]];
|
||||||
[bar addRepresentation: bitmap];
|
[bar addRepresentation: fBitmap];
|
||||||
[bitmap release];
|
|
||||||
|
|
||||||
[bar setScalesWhenResized: YES];
|
[bar setScalesWhenResized: YES];
|
||||||
|
|
||||||
return [bar autorelease];
|
return [bar autorelease];
|
||||||
|
|
Loading…
Reference in New Issue