simplify the advanced bar drawing code
This commit is contained in:
parent
70471f78d1
commit
42a09ba6ac
|
@ -39,7 +39,6 @@
|
||||||
NSColor * fGrayColor, * fBlueColor, * fBlue1Color, * fBlue2Color, * fBlue3Color, * fBlue4Color;
|
NSColor * fGrayColor, * fBlueColor, * fBlue1Color, * fBlue2Color, * fBlue3Color, * fBlue4Color;
|
||||||
|
|
||||||
NSBitmapImageRep * fBitmap;
|
NSBitmapImageRep * fBitmap;
|
||||||
int8_t * fPieces;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
- (NSRect) iconRectForBounds: (NSRect) bounds;
|
- (NSRect) iconRectForBounds: (NSRect) bounds;
|
||||||
|
|
|
@ -55,7 +55,6 @@
|
||||||
#define WIDTH_GROUP_MIN 24.0
|
#define WIDTH_GROUP_MIN 24.0
|
||||||
|
|
||||||
#define MAX_PIECES 324
|
#define MAX_PIECES 324
|
||||||
#define BLANK_PIECE -99
|
|
||||||
|
|
||||||
@interface TorrentCell (Private)
|
@interface TorrentCell (Private)
|
||||||
|
|
||||||
|
@ -110,9 +109,7 @@
|
||||||
- (id) copyWithZone: (NSZone *) zone
|
- (id) copyWithZone: (NSZone *) zone
|
||||||
{
|
{
|
||||||
TorrentCell * copy = [super copyWithZone: zone];
|
TorrentCell * copy = [super copyWithZone: zone];
|
||||||
|
|
||||||
copy->fBitmap = nil;
|
copy->fBitmap = nil;
|
||||||
copy->fPieces = NULL;
|
|
||||||
|
|
||||||
return copy;
|
return copy;
|
||||||
}
|
}
|
||||||
|
@ -120,9 +117,6 @@
|
||||||
- (void) dealloc
|
- (void) dealloc
|
||||||
{
|
{
|
||||||
[fBitmap release];
|
[fBitmap release];
|
||||||
if (fPieces)
|
|
||||||
free(fPieces);
|
|
||||||
|
|
||||||
[super dealloc];
|
[super dealloc];
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -311,13 +305,8 @@
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
if (fPieces)
|
|
||||||
{
|
|
||||||
free(fPieces);
|
|
||||||
fPieces = NULL;
|
|
||||||
[fBitmap release];
|
[fBitmap release];
|
||||||
fBitmap = nil;
|
fBitmap = nil;
|
||||||
}
|
|
||||||
|
|
||||||
[self drawRegularBar: barRect];
|
[self drawRegularBar: barRect];
|
||||||
}
|
}
|
||||||
|
@ -464,14 +453,6 @@
|
||||||
pixelsWide: MAX_PIECES pixelsHigh: barRect.size.height bitsPerSample: 8 samplesPerPixel: 4 hasAlpha: YES
|
pixelsWide: MAX_PIECES pixelsHigh: barRect.size.height bitsPerSample: 8 samplesPerPixel: 4 hasAlpha: YES
|
||||||
isPlanar: NO colorSpaceName: NSCalibratedRGBColorSpace bytesPerRow: 0 bitsPerPixel: 0];
|
isPlanar: NO colorSpaceName: NSCalibratedRGBColorSpace bytesPerRow: 0 bitsPerPixel: 0];
|
||||||
|
|
||||||
if (!fPieces)
|
|
||||||
{
|
|
||||||
fPieces = malloc(MAX_PIECES);
|
|
||||||
int i;
|
|
||||||
for (i = 0; i < MAX_PIECES; i++)
|
|
||||||
fPieces[i] = BLANK_PIECE;
|
|
||||||
}
|
|
||||||
|
|
||||||
#warning add flashing orange
|
#warning add flashing orange
|
||||||
|
|
||||||
Torrent * torrent = [self representedObject];
|
Torrent * torrent = [self representedObject];
|
||||||
|
@ -486,58 +467,20 @@
|
||||||
for (i = 0; i < MAX_PIECES; i++)
|
for (i = 0; i < MAX_PIECES; i++)
|
||||||
{
|
{
|
||||||
index = i * increment;
|
index = i * increment;
|
||||||
pieceColor = nil;
|
|
||||||
|
|
||||||
if (piecePercent[index] >= 1.0)
|
if (piecePercent[index] >= 1.0)
|
||||||
{
|
|
||||||
if (fPieces[i] != -1)
|
|
||||||
{
|
|
||||||
pieceColor = fBlueColor;
|
pieceColor = fBlueColor;
|
||||||
fPieces[i] = -1;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
else if (piecePercent[index] <= 0.0)
|
else if (piecePercent[index] <= 0.0)
|
||||||
{
|
|
||||||
if (fPieces[i] != 0)
|
|
||||||
{
|
|
||||||
pieceColor = fGrayColor;
|
pieceColor = fGrayColor;
|
||||||
fPieces[i] = 0;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
else if (piecePercent[index] <= 0.25)
|
else if (piecePercent[index] <= 0.25)
|
||||||
{
|
|
||||||
if (fPieces[i] != 1)
|
|
||||||
{
|
|
||||||
pieceColor = fBlue1Color;
|
pieceColor = fBlue1Color;
|
||||||
fPieces[i] = 1;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
else if (piecePercent[index] <= 0.5)
|
else if (piecePercent[index] <= 0.5)
|
||||||
{
|
|
||||||
if (fPieces[i] != 2)
|
|
||||||
{
|
|
||||||
pieceColor = fBlue2Color;
|
pieceColor = fBlue2Color;
|
||||||
fPieces[i] = 2;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
else if (piecePercent[index] <= 0.75)
|
else if (piecePercent[index] <= 0.75)
|
||||||
{
|
|
||||||
if (fPieces[i] != 3)
|
|
||||||
{
|
|
||||||
pieceColor = fBlue3Color;
|
pieceColor = fBlue3Color;
|
||||||
fPieces[i] = 3;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
else
|
else
|
||||||
{
|
|
||||||
if (fPieces[i] != 4)
|
|
||||||
{
|
|
||||||
pieceColor = fBlue4Color;
|
pieceColor = fBlue4Color;
|
||||||
fPieces[i] = 4;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
if (pieceColor)
|
if (![pieceColor isEqualTo: [fBitmap colorAtX: i y: 0]])
|
||||||
for (h = 0; h < barRect.size.height; h++)
|
for (h = 0; h < barRect.size.height; h++)
|
||||||
[fBitmap setColor: pieceColor atX: i y: h];
|
[fBitmap setColor: pieceColor atX: i y: h];
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue