Changeset 9217


Ignore:
Timestamp:
Sep 28, 2009, 5:42:24 PM (12 years ago)
Author:
livings124
Message:

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

Location:
trunk/macosx
Files:
3 edited

Legend:

Unmodified
Added
Removed
  • trunk/macosx/FileNameCell.m

    r9201 r9217  
    4242- (NSRect) rectForStatusWithString: (NSAttributedString *) string withTitleRect: (NSRect) titleRect inBounds: (NSRect) bounds;
    4343
    44 - (NSAttributedString *) attributedTitleWithColor: (NSColor *) color;
    45 - (NSAttributedString *) attributedStatusWithColor: (NSColor *) color;
     44- (NSAttributedString *) attributedTitle;
     45- (NSAttributedString *) attributedStatus;
    4646
    4747@end
     
    125125- (NSRect) titleRectForBounds: (NSRect) bounds
    126126{
    127     return [self rectForTitleWithString: [self attributedTitleWithColor: nil] inBounds: bounds];
     127    return [self rectForTitleWithString: [self attributedTitle] inBounds: bounds];
    128128}
    129129
    130130- (NSRect) statusRectForBounds: (NSRect) bounds
    131131{
    132     return [self rectForStatusWithString: [self attributedStatusWithColor: nil]
     132    return [self rectForStatusWithString: [self attributedStatus]
    133133            withTitleRect: [(FileListNode *)[self objectValue] isFolder] ? [self titleRectForBounds: bounds] : NSZeroRect
    134134            inBounds: bounds];
     
    151151    }
    152152   
     153    [fTitleAttributes setObject: titleColor forKey: NSForegroundColorAttributeName];
     154    [fStatusAttributes setObject: statusColor forKey: NSForegroundColorAttributeName];
     155   
    153156    //title
    154     NSAttributedString * titleString = [self attributedTitleWithColor: titleColor];
     157    NSAttributedString * titleString = [self attributedTitle];
    155158    NSRect titleRect = [self rectForTitleWithString: titleString inBounds: cellFrame];
    156159    [titleString drawInRect: titleRect];
    157160   
    158161    //status
    159     NSAttributedString * statusString = [self attributedStatusWithColor: statusColor];
     162    NSAttributedString * statusString = [self attributedStatus];
    160163    NSRect statusRect = [self rectForStatusWithString: statusString withTitleRect: titleRect inBounds: cellFrame];
    161164    [statusString drawInRect: statusRect];
     
    210213}
    211214
    212 - (NSAttributedString *) attributedTitleWithColor: (NSColor *) color
    213 {
    214     if (color)
    215         [fTitleAttributes setObject: color forKey: NSForegroundColorAttributeName];
    216        
     215- (NSAttributedString *) attributedTitle
     216{
    217217    NSString * title = [(FileListNode *)[self objectValue] name];
    218218    return [[[NSAttributedString alloc] initWithString: title attributes: fTitleAttributes] autorelease];
    219219}
    220220
    221 - (NSAttributedString *) attributedStatusWithColor: (NSColor *) color
    222 {
    223     if (color)
    224         [fStatusAttributes setObject: color forKey: NSForegroundColorAttributeName];
    225    
     221- (NSAttributedString *) attributedStatus
     222{
    226223    Torrent * torrent = [(FileOutlineView *)[self controlView] torrent];
    227224    FileListNode * node = (FileListNode *)[self objectValue];
  • trunk/macosx/TorrentCell.m

    r9050 r9217  
    7474- (NSRect) rectForStatusWithString: (NSAttributedString *) string inBounds: (NSRect) bounds;
    7575
    76 - (NSAttributedString *) attributedTitleWithColor: (NSColor *) color;
    77 - (NSAttributedString *) attributedStatusString: (NSString *) string withColor: (NSColor *) color;
     76- (NSAttributedString *) attributedTitle;
     77- (NSAttributedString *) attributedStatusString: (NSString *) string;
    7878
    7979- (NSString *) buttonString;
     
    131131- (NSRect) titleRectForBounds: (NSRect) bounds
    132132{
    133     return [self rectForTitleWithString: [self attributedTitleWithColor: nil]
     133    return [self rectForTitleWithString: [self attributedTitle]
    134134            basedOnMinimalStatusRect: [self minimalStatusRectForBounds: bounds] inBounds: bounds];
    135135}
     
    140140        return NSZeroRect;
    141141   
    142     return [self rectForMinimalStatusWithString: [self attributedStatusString: [self minimalStatusString] withColor: nil]
     142    return [self rectForMinimalStatusWithString: [self attributedStatusString: [self minimalStatusString]]
    143143            inBounds: bounds];
    144144}
     
    149149        return NSZeroRect;
    150150   
    151     return [self rectForProgressWithString: [self attributedStatusString: [[self representedObject] progressString] withColor: nil]
     151    return [self rectForProgressWithString: [self attributedStatusString: [[self representedObject] progressString]]
    152152            inBounds: bounds];
    153153}
     
    177177        return NSZeroRect;
    178178   
    179     return [self rectForStatusWithString: [self attributedStatusString: [self statusString] withColor: nil] inBounds: bounds];
     179    return [self rectForStatusWithString: [self attributedStatusString: [self statusString]] inBounds: bounds];
    180180}
    181181
     
    457457    }
    458458   
     459    [fTitleAttributes setObject: titleColor forKey: NSForegroundColorAttributeName];
     460    [fStatusAttributes setObject: statusColor forKey: NSForegroundColorAttributeName];
     461   
    459462    //minimal status
    460463    NSRect minimalStatusRect;
    461464    if (minimal)
    462465    {
    463         NSAttributedString * minimalString = [self attributedStatusString: [self minimalStatusString] withColor: statusColor];
     466        NSAttributedString * minimalString = [self attributedStatusString: [self minimalStatusString]];
    464467        minimalStatusRect = [self rectForMinimalStatusWithString: minimalString inBounds: cellFrame];
    465468       
     
    468471   
    469472    //title
    470     NSAttributedString * titleString = [self attributedTitleWithColor: titleColor];
     473    NSAttributedString * titleString = [self attributedTitle];
    471474    NSRect titleRect = [self rectForTitleWithString: titleString basedOnMinimalStatusRect: minimalStatusRect inBounds: cellFrame];
    472475    [titleString drawInRect: titleRect];
     
    486489    if (!minimal)
    487490    {
    488         NSAttributedString * progressString = [self attributedStatusString: [torrent progressString] withColor: statusColor];
     491        NSAttributedString * progressString = [self attributedStatusString: [torrent progressString]];
    489492        NSRect progressRect = [self rectForProgressWithString: progressString inBounds: cellFrame];
    490493       
     
    549552    if (!minimal)
    550553    {
    551         NSAttributedString * statusString = [self attributedStatusString: [self statusString] withColor: statusColor];
     554        NSAttributedString * statusString = [self attributedStatusString: [self statusString]];
    552555        [statusString drawInRect: [self rectForStatusWithString: statusString inBounds: cellFrame]];
    553556    }
     
    745748}
    746749
    747 - (NSAttributedString *) attributedTitleWithColor: (NSColor *) color
    748 {
    749     if (color)
    750         [fTitleAttributes setObject: color forKey: NSForegroundColorAttributeName];
    751    
     750- (NSAttributedString *) attributedTitle
     751{
    752752    NSString * title = [[self representedObject] name];
    753753    return [[[NSAttributedString alloc] initWithString: title attributes: fTitleAttributes] autorelease];
    754754}
    755755
    756 - (NSAttributedString *) attributedStatusString: (NSString *) string withColor: (NSColor *) color
    757 {
    758     if (color)
    759         [fStatusAttributes setObject: color forKey: NSForegroundColorAttributeName];
    760    
     756- (NSAttributedString *) attributedStatusString: (NSString *) string
     757{
    761758    return [[[NSAttributedString alloc] initWithString: string attributes: fStatusAttributes] autorelease];
    762759}
  • trunk/macosx/TrackerCell.m

    r9215 r9217  
    3434#define PADDING_ABOVE_NAME 2.0
    3535#define PADDING_BETWEEN_LINES 1.0
    36 #define PADDING_BETWEEN_LINES_ON_SAME_LINE 3.0
     36#define PADDING_BETWEEN_LINES_ON_SAME_LINE 4.0
    3737#define COUNT_WIDTH 40.0
    3838
     
    4949            inBounds: (NSRect) bounds;
    5050
    51 - (NSAttributedString *) attributedNameWithColor: (NSColor *) color;
    52 - (NSAttributedString *) attributedStatusWithString: (NSString *) statusString color: (NSColor *) color;
    53 - (NSAttributedString *) attributedCount: (NSInteger) count color: (NSColor *) color;
     51- (NSAttributedString *) attributedName;
     52- (NSAttributedString *) attributedStatusWithString: (NSString *) statusString;
     53- (NSAttributedString *) attributedCount: (NSInteger) count;
    5454
    5555@end
     
    119119    }
    120120
    121    
     121    //set table colors
    122122    NSColor * nameColor, * statusColor;
    123123    if ([self backgroundStyle] == NSBackgroundStyleDark)
     
    129129    }
    130130   
     131    [fNameAttributes setObject: nameColor forKey: NSForegroundColorAttributeName];
     132    [fStatusAttributes setObject: statusColor forKey: NSForegroundColorAttributeName];
     133   
    131134    TrackerNode * node = (TrackerNode *)[self objectValue];
    132135   
    133136    //name
    134     NSAttributedString * nameString = [self attributedNameWithColor: nameColor];
     137    NSAttributedString * nameString = [self attributedName];
    135138    const NSRect nameRect = [self rectForNameWithString: nameString inBounds: cellFrame];
    136139    [nameString drawInRect: nameRect];
    137140   
    138141    //count strings
    139     NSAttributedString * seederString = [self attributedCount: [node totalSeeders] color: statusColor];
     142    NSAttributedString * seederString = [self attributedCount: [node totalSeeders]];
    140143    const NSRect seederRect = [self rectForCountWithString: seederString withAboveRect: nameRect inBounds: cellFrame];
    141144    [seederString drawInRect: seederRect];
    142145   
    143     NSAttributedString * leecherString = [self attributedCount: [node totalLeechers] color: statusColor];
     146    NSAttributedString * leecherString = [self attributedCount: [node totalLeechers]];
    144147    const NSRect leecherRect = [self rectForCountWithString: leecherString withAboveRect: seederRect inBounds: cellFrame];
    145148    [leecherString drawInRect: leecherRect];
    146149   
    147     NSAttributedString * downloadedString = [self attributedCount: [node totalDownloaded] color: statusColor];
     150    NSAttributedString * downloadedString = [self attributedCount: [node totalDownloaded]];
    148151    const NSRect downloadedRect = [self rectForCountWithString: downloadedString withAboveRect: leecherRect inBounds: cellFrame];
    149152    [downloadedString drawInRect: downloadedRect];
     
    151154    //count label strings
    152155    NSString * seederLabelBaseString = [NSLocalizedString(@"Seeders", "tracker peer stat") stringByAppendingFormat: @": "];
    153     NSAttributedString * seederLabelString = [self attributedStatusWithString: seederLabelBaseString color: statusColor];
     156    NSAttributedString * seederLabelString = [self attributedStatusWithString: seederLabelBaseString];
    154157    const NSRect seederLabelRect = [self rectForCountLabelWithString: seederLabelString withRightRect: seederRect
    155158                                        inBounds: cellFrame];
     
    157160   
    158161    NSString * leecherLabelBaseString = [NSLocalizedString(@"Leechers", "tracker peer stat") stringByAppendingFormat: @": "];
    159     NSAttributedString * leecherLabelString = [self attributedStatusWithString: leecherLabelBaseString color: statusColor];
     162    NSAttributedString * leecherLabelString = [self attributedStatusWithString: leecherLabelBaseString];
    160163    const NSRect leecherLabelRect = [self rectForCountLabelWithString: leecherLabelString withRightRect: leecherRect
    161164                                        inBounds: cellFrame];
     
    163166   
    164167    NSString * downloadedLabelBaseString = [NSLocalizedString(@"Downloaded", "tracker peer stat") stringByAppendingFormat: @": "];
    165     NSAttributedString * downloadedLabelString = [self attributedStatusWithString: downloadedLabelBaseString color: statusColor];
     168    NSAttributedString * downloadedLabelString = [self attributedStatusWithString: downloadedLabelBaseString];
    166169    const NSRect downloadedLabelRect = [self rectForCountLabelWithString: downloadedLabelString withRightRect: downloadedRect
    167170                                        inBounds: cellFrame];
     
    169172   
    170173    //status strings
    171     NSAttributedString * lastAnnounceString = [self attributedStatusWithString: [node lastAnnounceStatusString] color: statusColor];
     174    NSAttributedString * lastAnnounceString = [self attributedStatusWithString: [node lastAnnounceStatusString]];
    172175    const NSRect lastAnnounceRect = [self rectForStatusWithString: lastAnnounceString withAboveRect: nameRect
    173176                                        withRightRect: seederLabelRect inBounds: cellFrame];
    174177    [lastAnnounceString drawInRect: lastAnnounceRect];
    175178   
    176     NSAttributedString * nextAnnounceString = [self attributedStatusWithString: [node nextAnnounceStatusString] color: statusColor];
     179    NSAttributedString * nextAnnounceString = [self attributedStatusWithString: [node nextAnnounceStatusString]];
    177180    const NSRect nextAnnounceRect = [self rectForStatusWithString: nextAnnounceString withAboveRect: lastAnnounceRect
    178181                                        withRightRect: leecherLabelRect inBounds: cellFrame];
    179182    [nextAnnounceString drawInRect: nextAnnounceRect];
    180183   
    181     NSAttributedString * lastScrapeString = [self attributedStatusWithString: [node lastScrapeStatusString] color: statusColor];
     184    NSAttributedString * lastScrapeString = [self attributedStatusWithString: [node lastScrapeStatusString]];
    182185    const NSRect lastScrapeRect = [self rectForStatusWithString: lastScrapeString withAboveRect: nextAnnounceRect
    183186                                    withRightRect: downloadedLabelRect inBounds: cellFrame];
     
    291294}
    292295
    293 - (NSAttributedString *) attributedNameWithColor: (NSColor *) color
    294 {
    295     [fNameAttributes setObject: color forKey: NSForegroundColorAttributeName];
    296    
     296- (NSAttributedString *) attributedName
     297{
    297298    NSString * name = [(TrackerNode *)[self objectValue] host];
    298299    return [[[NSAttributedString alloc] initWithString: name attributes: fNameAttributes] autorelease];
    299300}
    300301
    301 - (NSAttributedString *) attributedStatusWithString: (NSString *) statusString color: (NSColor *) color
    302 {
    303     [fStatusAttributes setObject: color forKey: NSForegroundColorAttributeName];
    304    
     302- (NSAttributedString *) attributedStatusWithString: (NSString *) statusString
     303{
    305304    return [[[NSAttributedString alloc] initWithString: statusString attributes: fStatusAttributes] autorelease];
    306305}
    307306
    308 - (NSAttributedString *) attributedCount: (NSInteger) count color: (NSColor *) color
    309 {
    310     [fStatusAttributes setObject: color forKey: NSForegroundColorAttributeName];
    311    
     307- (NSAttributedString *) attributedCount: (NSInteger) count
     308{
    312309    NSString * countString = count != -1 ? [NSString stringWithFormat: @"%d", count] : NSLocalizedString(@"N/A", "tracker peer stat");
    313310    return [[[NSAttributedString alloc] initWithString: countString attributes: fStatusAttributes] autorelease];
Note: See TracChangeset for help on using the changeset viewer.