1
0
Fork 0
mirror of https://github.com/transmission/transmission synced 2025-02-22 06:00:41 +00:00

set the color for table cells only when actually drawing (and only once each time the draw method is alled)

This commit is contained in:
Mitchell Livingston 2009-09-28 17:42:24 +00:00
parent a6d55367cc
commit a88683d650
3 changed files with 47 additions and 56 deletions

View file

@ -41,8 +41,8 @@
- (NSRect) rectForTitleWithString: (NSAttributedString *) string inBounds: (NSRect) bounds;
- (NSRect) rectForStatusWithString: (NSAttributedString *) string withTitleRect: (NSRect) titleRect inBounds: (NSRect) bounds;
- (NSAttributedString *) attributedTitleWithColor: (NSColor *) color;
- (NSAttributedString *) attributedStatusWithColor: (NSColor *) color;
- (NSAttributedString *) attributedTitle;
- (NSAttributedString *) attributedStatus;
@end
@ -124,12 +124,12 @@
- (NSRect) titleRectForBounds: (NSRect) bounds
{
return [self rectForTitleWithString: [self attributedTitleWithColor: nil] inBounds: bounds];
return [self rectForTitleWithString: [self attributedTitle] inBounds: bounds];
}
- (NSRect) statusRectForBounds: (NSRect) bounds
{
return [self rectForStatusWithString: [self attributedStatusWithColor: nil]
return [self rectForStatusWithString: [self attributedStatus]
withTitleRect: [(FileListNode *)[self objectValue] isFolder] ? [self titleRectForBounds: bounds] : NSZeroRect
inBounds: bounds];
}
@ -150,13 +150,16 @@
statusColor = [NSColor darkGrayColor];
}
[fTitleAttributes setObject: titleColor forKey: NSForegroundColorAttributeName];
[fStatusAttributes setObject: statusColor forKey: NSForegroundColorAttributeName];
//title
NSAttributedString * titleString = [self attributedTitleWithColor: titleColor];
NSAttributedString * titleString = [self attributedTitle];
NSRect titleRect = [self rectForTitleWithString: titleString inBounds: cellFrame];
[titleString drawInRect: titleRect];
//status
NSAttributedString * statusString = [self attributedStatusWithColor: statusColor];
NSAttributedString * statusString = [self attributedStatus];
NSRect statusRect = [self rectForStatusWithString: statusString withTitleRect: titleRect inBounds: cellFrame];
[statusString drawInRect: statusRect];
}
@ -209,20 +212,14 @@
return result;
}
- (NSAttributedString *) attributedTitleWithColor: (NSColor *) color
- (NSAttributedString *) attributedTitle
{
if (color)
[fTitleAttributes setObject: color forKey: NSForegroundColorAttributeName];
NSString * title = [(FileListNode *)[self objectValue] name];
return [[[NSAttributedString alloc] initWithString: title attributes: fTitleAttributes] autorelease];
}
- (NSAttributedString *) attributedStatusWithColor: (NSColor *) color
- (NSAttributedString *) attributedStatus
{
if (color)
[fStatusAttributes setObject: color forKey: NSForegroundColorAttributeName];
Torrent * torrent = [(FileOutlineView *)[self controlView] torrent];
FileListNode * node = (FileListNode *)[self objectValue];

View file

@ -73,8 +73,8 @@
- (NSRect) rectForProgressWithString: (NSAttributedString *) string inBounds: (NSRect) bounds;
- (NSRect) rectForStatusWithString: (NSAttributedString *) string inBounds: (NSRect) bounds;
- (NSAttributedString *) attributedTitleWithColor: (NSColor *) color;
- (NSAttributedString *) attributedStatusString: (NSString *) string withColor: (NSColor *) color;
- (NSAttributedString *) attributedTitle;
- (NSAttributedString *) attributedStatusString: (NSString *) string;
- (NSString *) buttonString;
- (NSString *) statusString;
@ -130,7 +130,7 @@
- (NSRect) titleRectForBounds: (NSRect) bounds
{
return [self rectForTitleWithString: [self attributedTitleWithColor: nil]
return [self rectForTitleWithString: [self attributedTitle]
basedOnMinimalStatusRect: [self minimalStatusRectForBounds: bounds] inBounds: bounds];
}
@ -139,7 +139,7 @@
if (![fDefaults boolForKey: @"SmallView"])
return NSZeroRect;
return [self rectForMinimalStatusWithString: [self attributedStatusString: [self minimalStatusString] withColor: nil]
return [self rectForMinimalStatusWithString: [self attributedStatusString: [self minimalStatusString]]
inBounds: bounds];
}
@ -148,7 +148,7 @@
if ([fDefaults boolForKey: @"SmallView"])
return NSZeroRect;
return [self rectForProgressWithString: [self attributedStatusString: [[self representedObject] progressString] withColor: nil]
return [self rectForProgressWithString: [self attributedStatusString: [[self representedObject] progressString]]
inBounds: bounds];
}
@ -176,7 +176,7 @@
if ([fDefaults boolForKey: @"SmallView"])
return NSZeroRect;
return [self rectForStatusWithString: [self attributedStatusString: [self statusString] withColor: nil] inBounds: bounds];
return [self rectForStatusWithString: [self attributedStatusString: [self statusString]] inBounds: bounds];
}
- (NSRect) controlButtonRectForBounds: (NSRect) bounds
@ -456,18 +456,21 @@
statusColor = [NSColor darkGrayColor];
}
[fTitleAttributes setObject: titleColor forKey: NSForegroundColorAttributeName];
[fStatusAttributes setObject: statusColor forKey: NSForegroundColorAttributeName];
//minimal status
NSRect minimalStatusRect;
if (minimal)
{
NSAttributedString * minimalString = [self attributedStatusString: [self minimalStatusString] withColor: statusColor];
NSAttributedString * minimalString = [self attributedStatusString: [self minimalStatusString]];
minimalStatusRect = [self rectForMinimalStatusWithString: minimalString inBounds: cellFrame];
[minimalString drawInRect: minimalStatusRect];
}
//title
NSAttributedString * titleString = [self attributedTitleWithColor: titleColor];
NSAttributedString * titleString = [self attributedTitle];
NSRect titleRect = [self rectForTitleWithString: titleString basedOnMinimalStatusRect: minimalStatusRect inBounds: cellFrame];
[titleString drawInRect: titleRect];
@ -485,7 +488,7 @@
//progress
if (!minimal)
{
NSAttributedString * progressString = [self attributedStatusString: [torrent progressString] withColor: statusColor];
NSAttributedString * progressString = [self attributedStatusString: [torrent progressString]];
NSRect progressRect = [self rectForProgressWithString: progressString inBounds: cellFrame];
[progressString drawInRect: progressRect];
@ -548,7 +551,7 @@
//status
if (!minimal)
{
NSAttributedString * statusString = [self attributedStatusString: [self statusString] withColor: statusColor];
NSAttributedString * statusString = [self attributedStatusString: [self statusString]];
[statusString drawInRect: [self rectForStatusWithString: statusString inBounds: cellFrame]];
}
}
@ -744,20 +747,14 @@
return result;
}
- (NSAttributedString *) attributedTitleWithColor: (NSColor *) color
- (NSAttributedString *) attributedTitle
{
if (color)
[fTitleAttributes setObject: color forKey: NSForegroundColorAttributeName];
NSString * title = [[self representedObject] name];
return [[[NSAttributedString alloc] initWithString: title attributes: fTitleAttributes] autorelease];
}
- (NSAttributedString *) attributedStatusString: (NSString *) string withColor: (NSColor *) color
- (NSAttributedString *) attributedStatusString: (NSString *) string
{
if (color)
[fStatusAttributes setObject: color forKey: NSForegroundColorAttributeName];
return [[[NSAttributedString alloc] initWithString: string attributes: fStatusAttributes] autorelease];
}

View file

@ -33,7 +33,7 @@
#define PADDING_ABOVE_ICON 1.0
#define PADDING_ABOVE_NAME 2.0
#define PADDING_BETWEEN_LINES 1.0
#define PADDING_BETWEEN_LINES_ON_SAME_LINE 3.0
#define PADDING_BETWEEN_LINES_ON_SAME_LINE 4.0
#define COUNT_WIDTH 40.0
@interface TrackerCell (Private)
@ -48,9 +48,9 @@
- (NSRect) rectForStatusWithString: (NSAttributedString *) string withAboveRect: (NSRect) aboveRect withRightRect: (NSRect) rightRect
inBounds: (NSRect) bounds;
- (NSAttributedString *) attributedNameWithColor: (NSColor *) color;
- (NSAttributedString *) attributedStatusWithString: (NSString *) statusString color: (NSColor *) color;
- (NSAttributedString *) attributedCount: (NSInteger) count color: (NSColor *) color;
- (NSAttributedString *) attributedName;
- (NSAttributedString *) attributedStatusWithString: (NSString *) statusString;
- (NSAttributedString *) attributedCount: (NSInteger) count;
@end
@ -118,7 +118,7 @@ NSMutableSet * fTrackerIconLoading;
[icon drawInRect: [self imageRectForBounds: cellFrame] fromRect: NSZeroRect operation: NSCompositeSourceOver fraction: 1.0];
}
//set table colors
NSColor * nameColor, * statusColor;
if ([self backgroundStyle] == NSBackgroundStyleDark)
nameColor = statusColor = [NSColor whiteColor];
@ -128,57 +128,60 @@ NSMutableSet * fTrackerIconLoading;
statusColor = [NSColor darkGrayColor];
}
[fNameAttributes setObject: nameColor forKey: NSForegroundColorAttributeName];
[fStatusAttributes setObject: statusColor forKey: NSForegroundColorAttributeName];
TrackerNode * node = (TrackerNode *)[self objectValue];
//name
NSAttributedString * nameString = [self attributedNameWithColor: nameColor];
NSAttributedString * nameString = [self attributedName];
const NSRect nameRect = [self rectForNameWithString: nameString inBounds: cellFrame];
[nameString drawInRect: nameRect];
//count strings
NSAttributedString * seederString = [self attributedCount: [node totalSeeders] color: statusColor];
NSAttributedString * seederString = [self attributedCount: [node totalSeeders]];
const NSRect seederRect = [self rectForCountWithString: seederString withAboveRect: nameRect inBounds: cellFrame];
[seederString drawInRect: seederRect];
NSAttributedString * leecherString = [self attributedCount: [node totalLeechers] color: statusColor];
NSAttributedString * leecherString = [self attributedCount: [node totalLeechers]];
const NSRect leecherRect = [self rectForCountWithString: leecherString withAboveRect: seederRect inBounds: cellFrame];
[leecherString drawInRect: leecherRect];
NSAttributedString * downloadedString = [self attributedCount: [node totalDownloaded] color: statusColor];
NSAttributedString * downloadedString = [self attributedCount: [node totalDownloaded]];
const NSRect downloadedRect = [self rectForCountWithString: downloadedString withAboveRect: leecherRect inBounds: cellFrame];
[downloadedString drawInRect: downloadedRect];
//count label strings
NSString * seederLabelBaseString = [NSLocalizedString(@"Seeders", "tracker peer stat") stringByAppendingFormat: @": "];
NSAttributedString * seederLabelString = [self attributedStatusWithString: seederLabelBaseString color: statusColor];
NSAttributedString * seederLabelString = [self attributedStatusWithString: seederLabelBaseString];
const NSRect seederLabelRect = [self rectForCountLabelWithString: seederLabelString withRightRect: seederRect
inBounds: cellFrame];
[seederLabelString drawInRect: seederLabelRect];
NSString * leecherLabelBaseString = [NSLocalizedString(@"Leechers", "tracker peer stat") stringByAppendingFormat: @": "];
NSAttributedString * leecherLabelString = [self attributedStatusWithString: leecherLabelBaseString color: statusColor];
NSAttributedString * leecherLabelString = [self attributedStatusWithString: leecherLabelBaseString];
const NSRect leecherLabelRect = [self rectForCountLabelWithString: leecherLabelString withRightRect: leecherRect
inBounds: cellFrame];
[leecherLabelString drawInRect: leecherLabelRect];
NSString * downloadedLabelBaseString = [NSLocalizedString(@"Downloaded", "tracker peer stat") stringByAppendingFormat: @": "];
NSAttributedString * downloadedLabelString = [self attributedStatusWithString: downloadedLabelBaseString color: statusColor];
NSAttributedString * downloadedLabelString = [self attributedStatusWithString: downloadedLabelBaseString];
const NSRect downloadedLabelRect = [self rectForCountLabelWithString: downloadedLabelString withRightRect: downloadedRect
inBounds: cellFrame];
[downloadedLabelString drawInRect: downloadedLabelRect];
//status strings
NSAttributedString * lastAnnounceString = [self attributedStatusWithString: [node lastAnnounceStatusString] color: statusColor];
NSAttributedString * lastAnnounceString = [self attributedStatusWithString: [node lastAnnounceStatusString]];
const NSRect lastAnnounceRect = [self rectForStatusWithString: lastAnnounceString withAboveRect: nameRect
withRightRect: seederLabelRect inBounds: cellFrame];
[lastAnnounceString drawInRect: lastAnnounceRect];
NSAttributedString * nextAnnounceString = [self attributedStatusWithString: [node nextAnnounceStatusString] color: statusColor];
NSAttributedString * nextAnnounceString = [self attributedStatusWithString: [node nextAnnounceStatusString]];
const NSRect nextAnnounceRect = [self rectForStatusWithString: nextAnnounceString withAboveRect: lastAnnounceRect
withRightRect: leecherLabelRect inBounds: cellFrame];
[nextAnnounceString drawInRect: nextAnnounceRect];
NSAttributedString * lastScrapeString = [self attributedStatusWithString: [node lastScrapeStatusString] color: statusColor];
NSAttributedString * lastScrapeString = [self attributedStatusWithString: [node lastScrapeStatusString]];
const NSRect lastScrapeRect = [self rectForStatusWithString: lastScrapeString withAboveRect: nextAnnounceRect
withRightRect: downloadedLabelRect inBounds: cellFrame];
[lastScrapeString drawInRect: lastScrapeRect];
@ -290,25 +293,19 @@ NSMutableSet * fTrackerIconLoading;
return result;
}
- (NSAttributedString *) attributedNameWithColor: (NSColor *) color
- (NSAttributedString *) attributedName
{
[fNameAttributes setObject: color forKey: NSForegroundColorAttributeName];
NSString * name = [(TrackerNode *)[self objectValue] host];
return [[[NSAttributedString alloc] initWithString: name attributes: fNameAttributes] autorelease];
}
- (NSAttributedString *) attributedStatusWithString: (NSString *) statusString color: (NSColor *) color
- (NSAttributedString *) attributedStatusWithString: (NSString *) statusString
{
[fStatusAttributes setObject: color forKey: NSForegroundColorAttributeName];
return [[[NSAttributedString alloc] initWithString: statusString attributes: fStatusAttributes] autorelease];
}
- (NSAttributedString *) attributedCount: (NSInteger) count color: (NSColor *) color
- (NSAttributedString *) attributedCount: (NSInteger) count
{
[fStatusAttributes setObject: color forKey: NSForegroundColorAttributeName];
NSString * countString = count != -1 ? [NSString stringWithFormat: @"%d", count] : NSLocalizedString(@"N/A", "tracker peer stat");
return [[[NSAttributedString alloc] initWithString: countString attributes: fStatusAttributes] autorelease];
}