eliminate some useless drawing for the progress bar, and ensure width is an integer (drawing with pixels is quite annoying)

This commit is contained in:
Mitchell Livingston 2007-09-26 17:30:54 +00:00
parent 9c0b470457
commit 0743709b51
1 changed files with 72 additions and 55 deletions

View File

@ -181,7 +181,7 @@ static uint32_t kRed = BE(0xFF6450FF), //255, 100, 80
else
result.origin.y += PADDING_BETWEEN_TITLE_AND_PROGRESS + HEIGHT_STATUS + PADDING_BETWEEN_PROGRESS_AND_BAR;
result.size.width = NSMaxX(bounds) - result.origin.x - PADDING_HORIZONAL - BUTTONS_TOTAL_WIDTH;
result.size.width = round(NSMaxX(bounds) - result.origin.x - PADDING_HORIZONAL - BUTTONS_TOTAL_WIDTH);
return result;
}
@ -278,34 +278,49 @@ static uint32_t kRed = BE(0xFF6450FF), //255, 100, 80
@implementation TorrentCell (Private)
#warning NSDivideRect ?
- (void) drawSimpleBar: (NSRect) barRect
{
Torrent * torrent = [self representedObject];
int leftWidth = barRect.size.width;
float progress = [torrent progress], left = [torrent progressLeft];
if (progress < 1.0)
{
if (!fWhiteGradient)
fWhiteGradient = [[CTGradient progressWhiteGradient] retain];
[fWhiteGradient fillRect: barRect angle: -90];
int rightWidth = leftWidth * progress;
leftWidth -= rightWidth;
float include = progress + left;
if (include < 1.0)
float rightProgress = 1.0 - progress;
if (left < rightProgress)
{
if (!fLightGrayGradient)
fLightGrayGradient = [[CTGradient progressLightGrayGradient] retain];
int rightNoIncludeWidth = rightWidth * ((rightProgress - left) / rightProgress);
rightWidth -= rightNoIncludeWidth;
NSRect noIncludeRect = barRect;
noIncludeRect.origin.x += barRect.size.width * include;
noIncludeRect.size.width *= 1.0 - include;
noIncludeRect.origin.x += barRect.size.width - rightNoIncludeWidth;
noIncludeRect.size.width = rightNoIncludeWidth;
if (!fLightGrayGradient)
fLightGrayGradient = [[CTGradient progressLightGrayGradient] retain];
[fLightGrayGradient fillRect: noIncludeRect angle: -90];
}
if (leftWidth > 0)
{
NSRect includeRect = barRect;
includeRect.origin.x += leftWidth;
includeRect.size.width = rightWidth;
if (!fWhiteGradient)
fWhiteGradient = [[CTGradient progressWhiteGradient] retain];
[fWhiteGradient fillRect: includeRect angle: -90];
}
}
if (leftWidth > 0)
{
NSRect completeRect = barRect;
completeRect.size.width *= progress;
completeRect.size.width = leftWidth;
if ([torrent isActive])
{
@ -317,6 +332,7 @@ static uint32_t kRed = BE(0xFF6450FF), //255, 100, 80
}
else if ([torrent isSeeding])
{
#warning integer-ize!
NSRect ratioRect = completeRect;
ratioRect.size.width *= [torrent progressStopRatio];
@ -362,6 +378,7 @@ static uint32_t kRed = BE(0xFF6450FF), //255, 100, 80
[fGrayGradient fillRect: completeRect angle: -90];
}
}
}
[fBarOverlayColor set];
[NSBezierPath strokeRect: NSInsetRect(barRect, 0.5, 0.5)];