store progress gradients in the gradient class; miscellaneous cleanup

This commit is contained in:
Mitchell Livingston
2008-06-25 05:01:04 +00:00
parent b1cc67ce2b
commit 88e907383f
9 changed files with 60 additions and 97 deletions
+40 -10
View File
@@ -65,54 +65,84 @@
return [newInstance autorelease];
}
CTGradient * fProgressWhiteGradient = nil;
+ (CTGradient *)progressWhiteGradient
{
return [[self class] progressGradientForRed: 0.95 green: 0.95 blue: 0.95];
if (!fProgressWhiteGradient)
fProgressWhiteGradient = [[[self class] progressGradientForRed: 0.95 green: 0.95 blue: 0.95] retain];
return fProgressWhiteGradient;
}
CTGradient * fProgressGrayGradient = nil;
+ (CTGradient *)progressGrayGradient
{
return [[self class] progressGradientForRed: 0.7 green: 0.7 blue: 0.7];
if (!fProgressGrayGradient)
fProgressGrayGradient = [[[self class] progressGradientForRed: 0.7 green: 0.7 blue: 0.7] retain];
return fProgressGrayGradient;
}
CTGradient * fProgressLightGrayGradient = nil;
+ (CTGradient *)progressLightGrayGradient
{
return [[self class] progressGradientForRed: 0.87 green: 0.87 blue: 0.87];
if (!fProgressLightGrayGradient)
fProgressLightGrayGradient = [[[self class] progressGradientForRed: 0.87 green: 0.87 blue: 0.87] retain];
return fProgressLightGrayGradient;
}
CTGradient * fProgressBlueGradient = nil;
+ (CTGradient *)progressBlueGradient
{
return [[self class] progressGradientForRed: 0.373 green: 0.698 blue: 0.972];
if (!fProgressBlueGradient)
fProgressBlueGradient = [[[self class] progressGradientForRed: 0.373 green: 0.698 blue: 0.972] retain];
return fProgressBlueGradient;
}
CTGradient * fProgressDarkBlueGradient = nil;
+ (CTGradient *)progressDarkBlueGradient
{
return [[self class] progressGradientForRed: 0.616 green: 0.722 blue: 0.776];
if (!fProgressDarkBlueGradient)
fProgressDarkBlueGradient = [[[self class] progressGradientForRed: 0.616 green: 0.722 blue: 0.776] retain];
return fProgressDarkBlueGradient;
}
CTGradient * fProgressGreenGradient = nil;
+ (CTGradient *)progressGreenGradient
{
return [[self class] progressGradientForRed: 0.384 green: 0.847 blue: 0.310];
if (!fProgressGreenGradient)
fProgressGreenGradient = [[[self class] progressGradientForRed: 0.384 green: 0.847 blue: 0.310] retain];
return fProgressGreenGradient;
}
CTGradient * fProgressLightGreenGradient = nil;
+ (CTGradient *)progressLightGreenGradient
{
return [[self class] progressGradientForRed: 0.780 green: 0.894 blue: 0.729];
if (!fProgressLightGreenGradient)
fProgressLightGreenGradient = [[[self class] progressGradientForRed: 0.780 green: 0.894 blue: 0.729] retain];
return fProgressLightGreenGradient;
}
CTGradient * fProgressDarkGreenGradient = nil;
+ (CTGradient *)progressDarkGreenGradient
{
return [[self class] progressGradientForRed: 0.627 green: 0.714 blue: 0.639];
if (!fProgressDarkGreenGradient)
fProgressDarkGreenGradient = [[[self class] progressGradientForRed: 0.627 green: 0.714 blue: 0.639] retain];
return fProgressDarkGreenGradient;
}
CTGradient * fProgressRedGradient = nil;
+ (CTGradient *)progressRedGradient
{
return [[self class] progressGradientForRed: 0.902 green: 0.439 blue: 0.451];
if (!fProgressRedGradient)
fProgressRedGradient = [[[self class] progressGradientForRed: 0.902 green: 0.439 blue: 0.451] retain];
return fProgressRedGradient;
}
CTGradient * fProgressYellowGradient = nil;
+ (CTGradient *)progressYellowGradient
{
return [[self class] progressGradientForRed: 0.933 green: 0.890 blue: 0.243];
if (!fProgressYellowGradient)
fProgressYellowGradient = [[[self class] progressGradientForRed: 0.933 green: 0.890 blue: 0.243] retain];
return fProgressYellowGradient;
}
@end
Binary file not shown.
+1 -2
View File
@@ -1102,9 +1102,8 @@ typedef enum
- (BOOL) canQuickLook
{
FileOutlineView * fileOutlineView = [fFileController outlineView];
Torrent * torrent = [fTorrents objectAtIndex: 0];
NSIndexSet * indexes = [fileOutlineView selectedRowIndexes];
int i;
for (i = [indexes firstIndex]; i != NSNotFound; i = [indexes indexGreaterThanIndex: i])
if ([self canQuickLookFile: [fileOutlineView itemAtRow: i]])
+1 -1
View File
@@ -36,7 +36,7 @@
+ (NSString *) stringForRatio: (float) ratio;
+ (NSString *) timeString: (uint64_t) seconds showSeconds: (BOOL) showSeconds;
+ (NSString *) timeString: (NSUInteger) seconds showSeconds: (BOOL) showSeconds maxDigits: (NSUInteger) max;
+ (NSString *) timeString: (NSUInteger) seconds showSeconds: (BOOL) showSeconds maxFields: (NSUInteger) max;
- (NSComparisonResult) compareIP: (NSString *) string;
+2 -2
View File
@@ -108,10 +108,10 @@
+ (NSString *) timeString: (uint64_t) seconds showSeconds: (BOOL) showSeconds
{
return [NSString timeString: seconds showSeconds: showSeconds maxDigits: UINT_MAX];
return [NSString timeString: seconds showSeconds: showSeconds maxFields: UINT_MAX];
}
+ (NSString *) timeString: (NSUInteger) seconds showSeconds: (BOOL) showSeconds maxDigits: (NSUInteger) max
+ (NSString *) timeString: (NSUInteger) seconds showSeconds: (BOOL) showSeconds maxFields: (NSUInteger) max
{
NSMutableArray * timeArray = [NSMutableArray arrayWithCapacity: MIN(max, 4)];
NSUInteger remaining = seconds;
+4 -4
View File
@@ -40,7 +40,7 @@
fStatus = PORT_STATUS_CHECKING;
fTimer = [NSTimer scheduledTimerWithTimeInterval: CHECK_FIRE target: self selector: @selector(startProbe)
userInfo: nil repeats: NO];
userInfo: nil repeats: NO];
}
return self;
@@ -124,7 +124,7 @@
if ([nodes count] == 1)
{
NSString * portStatus = [[[[nodes objectAtIndex: 0] stringValue] stringByTrimmingCharactersInSet:
[[NSCharacterSet letterCharacterSet] invertedSet]] lowercaseString];
[[NSCharacterSet letterCharacterSet] invertedSet]] lowercaseString];
if ([portStatus isEqualToString: @"open"])
[self callBackWithStatus: PORT_STATUS_OPEN];
@@ -140,8 +140,8 @@
}
else
{
NSLog(@"Unable to get port status: invalid response");
[self callBackWithStatus: PORT_STATUS_ERROR];
NSLog(@"Unable to get port status: invalid response");
[self callBackWithStatus: PORT_STATUS_ERROR];
}
[shieldsUpProbe release];
}
+1 -1
View File
@@ -1922,7 +1922,7 @@ void completenessChangeCallback(tr_torrent * torrent, cp_status_t status, void *
return NSLocalizedString(@"remaining time unknown", "Torrent -> eta string");
default:
return [NSString stringWithFormat: NSLocalizedString(@"%@ remaining", "Torrent -> eta string"),
[NSString timeString: eta showSeconds: YES maxDigits: 2]];
[NSString timeString: eta showSeconds: YES maxFields: 2]];
}
}
+1 -5
View File
@@ -34,11 +34,7 @@
BOOL fTracking, fMouseDownControlButton, fMouseDownRevealButton, fMouseDownActionButton,
fHoverControl, fHoverReveal, fHoverAction;
NSColor * fBarBorderColor;
CTGradient * fWhiteGradient, * fGrayGradient, * fLightGrayGradient, * fBlueGradient, * fDarkBlueGradient,
* fGreenGradient, * fLightGreenGradient, * fDarkGreenGradient, * fYellowGradient, * fRedGradient;
NSColor * fBluePieceColor;
NSColor * fBarBorderColor, * fBluePieceColor;
}
- (NSRect) iconRectForBounds: (NSRect) bounds;
+10 -72
View File
@@ -104,38 +104,6 @@
return self;
}
- (id) copyWithZone: (NSZone *) zone
{
TorrentCell * copy = [super copyWithZone: zone];
copy->fGrayGradient = [fGrayGradient retain];
copy->fLightGrayGradient = [fLightGrayGradient retain];
copy->fBlueGradient = [fBlueGradient retain];
copy->fDarkBlueGradient = [fDarkBlueGradient retain];
copy->fGreenGradient = [fGreenGradient retain];
copy->fLightGreenGradient = [fLightGreenGradient retain];
copy->fDarkGreenGradient = [fDarkGreenGradient retain];
copy->fYellowGradient = [fYellowGradient retain];
copy->fRedGradient = [fRedGradient retain];
return copy;
}
- (void) dealloc
{
[fGrayGradient release];
[fLightGrayGradient release];
[fBlueGradient release];
[fDarkBlueGradient release];
[fGreenGradient release];
[fLightGreenGradient release];
[fDarkGreenGradient release];
[fYellowGradient release];
[fRedGradient release];
[super dealloc];
}
- (NSRect) iconRectForBounds: (NSRect) bounds
{
float imageSize = [fDefaults boolForKey: @"SmallView"] ? IMAGE_SIZE_MIN : IMAGE_SIZE_REG;
@@ -620,9 +588,7 @@
noIncludeRect.origin.x += barRect.size.width - rightNoIncludeWidth;
noIncludeRect.size.width = rightNoIncludeWidth;
if (!fLightGrayGradient)
fLightGrayGradient = [[CTGradient progressLightGrayGradient] retain];
[fLightGrayGradient fillRect: noIncludeRect angle: 90];
[[CTGradient progressLightGrayGradient] fillRect: noIncludeRect angle: 90];
}
if (rightWidth > 0)
@@ -639,9 +605,7 @@
notAvailableRect.origin.x += leftWidth + rightWidth;
notAvailableRect.size.width = notAvailableWidth;
if (!fRedGradient)
fRedGradient = [[CTGradient progressRedGradient] retain];
[fRedGradient fillRect: notAvailableRect angle: 90];
[[CTGradient progressRedGradient] fillRect: notAvailableRect angle: 90];
}
}
@@ -651,9 +615,7 @@
includeRect.origin.x += leftWidth;
includeRect.size.width = rightWidth;
if (!fWhiteGradient)
fWhiteGradient = [[CTGradient progressWhiteGradient] retain];
[fWhiteGradient fillRect: includeRect angle: 90];
[[CTGradient progressWhiteGradient] fillRect: includeRect angle: 90];
}
}
}
@@ -666,11 +628,7 @@
if ([torrent isActive])
{
if ([torrent isChecking])
{
if (!fYellowGradient)
fYellowGradient = [[CTGradient progressYellowGradient] retain];
[fYellowGradient fillRect: completeRect angle: 90];
}
[[CTGradient progressYellowGradient] fillRect: completeRect angle: 90];
else if ([torrent isSeeding])
{
int ratioLeftWidth = leftWidth * (1.0 - [torrent progressStopRatio]);
@@ -682,50 +640,30 @@
ratioLeftRect.origin.x += leftWidth;
ratioLeftRect.size.width = ratioLeftWidth;
if (!fLightGreenGradient)
fLightGreenGradient = [[CTGradient progressLightGreenGradient] retain];
[fLightGreenGradient fillRect: ratioLeftRect angle: 90];
[[CTGradient progressLightGreenGradient] fillRect: ratioLeftRect angle: 90];
}
if (leftWidth > 0)
{
completeRect.size.width = leftWidth;
if (!fGreenGradient)
fGreenGradient = [[CTGradient progressGreenGradient] retain];
[fGreenGradient fillRect: completeRect angle: 90];
[[CTGradient progressGreenGradient] fillRect: completeRect angle: 90];
}
}
else
{
if (!fBlueGradient)
fBlueGradient = [[CTGradient progressBlueGradient] retain];
[fBlueGradient fillRect: completeRect angle: 90];
}
[[CTGradient progressBlueGradient] fillRect: completeRect angle: 90];
}
else
{
if ([torrent waitingToStart])
{
if ([torrent progressLeft] <= 0.0)
{
if (!fDarkGreenGradient)
fDarkGreenGradient = [[CTGradient progressDarkGreenGradient] retain];
[fDarkGreenGradient fillRect: completeRect angle: 90];
}
[[CTGradient progressDarkGreenGradient] fillRect: completeRect angle: 90];
else
{
if (!fDarkBlueGradient)
fDarkBlueGradient = [[CTGradient progressDarkBlueGradient] retain];
[fDarkBlueGradient fillRect: completeRect angle: 90];
}
[[CTGradient progressDarkBlueGradient] fillRect: completeRect angle: 90];
}
else
{
if (!fGrayGradient)
fGrayGradient = [[CTGradient progressGrayGradient] retain];
[fGrayGradient fillRect: completeRect angle: 90];
}
[[CTGradient progressGrayGradient] fillRect: completeRect angle: 90];
}
}
}