Changeset 9210


Ignore:
Timestamp:
Sep 28, 2009, 2:42:00 PM (13 years ago)
Author:
livings124
Message:

add tracker stats to the tracker cell

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/macosx/TrackerCell.m

    r9209 r9210  
    3434#define PADDING_ABOVE_NAME 2.0
    3535#define PADDING_BETWEEN_LINES 1.0
     36#define PADDING_BETWEEN_LINES_ON_SAME_LINE 3.0
     37#define COUNT_WIDTH 100.0
    3638
    3739@interface TrackerCell (Private)
     
    4244- (NSRect) imageRectForBounds: (NSRect) bounds;
    4345- (NSRect) rectForNameWithString: (NSAttributedString *) string inBounds: (NSRect) bounds;
    44 - (NSRect) rectForStatusWithString: (NSAttributedString *) string withAboveRect: (NSRect) nameRect inBounds: (NSRect) bounds;
     46- (NSRect) rectForCountWithString: (NSAttributedString *) string withAboveRect: (NSRect) nameRect inBounds: (NSRect) bounds;
     47- (NSRect) rectForStatusWithString: (NSAttributedString *) string withAboveRect: (NSRect) aboveRect withRightRect: (NSRect) rightRect
     48            inBounds: (NSRect) bounds;
    4549
    4650- (NSAttributedString *) attributedNameWithColor: (NSColor *) color;
     
    123127    }
    124128   
     129    TrackerNode * node = (TrackerNode *)[self objectValue];
     130   
    125131    //name
    126132    NSAttributedString * nameString = [self attributedNameWithColor: nameColor];
     
    128134    [nameString drawInRect: nameRect];
    129135   
     136    //count strings
     137    NSString * seederBaseString = [NSLocalizedString(@"Seeders", "tracker peer stat") stringByAppendingFormat: @": %d",
     138                                    [node totalSeeders]];
     139    NSAttributedString * seederString = [self attributedStatusWithString: seederBaseString color: statusColor];
     140    const NSRect seederRect = [self rectForCountWithString: seederString withAboveRect: nameRect inBounds: cellFrame];
     141    [seederString drawInRect: seederRect];
     142   
     143    NSString * leecherBaseString = [NSLocalizedString(@"Leechers", "tracker peer stat") stringByAppendingFormat: @": %d",
     144                                    [node totalLeechers]];
     145    NSAttributedString * leecherString = [self attributedStatusWithString: leecherBaseString color: statusColor];
     146    const NSRect leecherRect = [self rectForCountWithString: leecherString withAboveRect: seederRect inBounds: cellFrame];
     147    [leecherString drawInRect: leecherRect];
     148   
     149    NSString * downloadedBaseString = [NSLocalizedString(@"Downloaded", "tracker peer stat") stringByAppendingFormat: @": %d",
     150                                    [node totalDownloaded]];
     151    NSAttributedString * downloadedString = [self attributedStatusWithString: downloadedBaseString color: statusColor];
     152    const NSRect downloadedRect = [self rectForCountWithString: downloadedString withAboveRect: leecherRect inBounds: cellFrame];
     153    [downloadedString drawInRect: downloadedRect];
     154   
    130155    //status strings
    131     TrackerNode * node = (TrackerNode *)[self objectValue];
    132    
    133156    NSAttributedString * lastAnnounceString = [self attributedStatusWithString: [node lastAnnounceStatusString] color: statusColor];
    134     const NSRect lastAnnounceRect = [self rectForStatusWithString: lastAnnounceString withAboveRect: nameRect inBounds: cellFrame];
     157    const NSRect lastAnnounceRect = [self rectForStatusWithString: lastAnnounceString withAboveRect: nameRect withRightRect: seederRect
     158                                        inBounds: cellFrame];
    135159    [lastAnnounceString drawInRect: lastAnnounceRect];
    136160   
    137161    NSAttributedString * nextAnnounceString = [self attributedStatusWithString: [node nextAnnounceStatusString] color: statusColor];
    138162    const NSRect nextAnnounceRect = [self rectForStatusWithString: nextAnnounceString withAboveRect: lastAnnounceRect
    139                                         inBounds: cellFrame];
     163                                        withRightRect: leecherRect inBounds: cellFrame];
    140164    [nextAnnounceString drawInRect: nextAnnounceRect];
    141165   
    142166    NSAttributedString * lastScrapeString = [self attributedStatusWithString: [node lastScrapeStatusString] color: statusColor];
    143     const NSRect lastScrapeRect = [self rectForStatusWithString: lastScrapeString withAboveRect: nextAnnounceRect inBounds: cellFrame];
     167    const NSRect lastScrapeRect = [self rectForStatusWithString: lastScrapeString withAboveRect: nextAnnounceRect
     168                                    withRightRect: downloadedRect inBounds: cellFrame];
    144169    [lastScrapeString drawInRect: lastScrapeRect];
    145170}
     
    220245}
    221246
    222 - (NSRect) rectForStatusWithString: (NSAttributedString *) string withAboveRect: (NSRect) nameRect inBounds: (NSRect) bounds;
     247- (NSRect) rectForCountWithString: (NSAttributedString *) string withAboveRect: (NSRect) nameRect inBounds: (NSRect) bounds
     248{
     249    return NSMakeRect(NSMaxX(bounds) - PADDING_HORIZONAL - COUNT_WIDTH,
     250                        NSMaxY(nameRect) + PADDING_BETWEEN_LINES,
     251                        COUNT_WIDTH, [string size].height);
     252}
     253
     254- (NSRect) rectForStatusWithString: (NSAttributedString *) string withAboveRect: (NSRect) aboveRect withRightRect: (NSRect) rightRect
     255            inBounds: (NSRect) bounds
    223256{
    224257    const NSSize statusSize = [string size];
     
    226259    NSRect result = bounds;
    227260    result.origin.x += PADDING_STATUS_HORIZONAL;
    228     result.origin.y = NSMaxY(nameRect) + PADDING_BETWEEN_LINES;
     261    result.origin.y = NSMaxY(aboveRect) + PADDING_BETWEEN_LINES;
    229262   
    230263    result.size = statusSize;
    231     result.size.width = MIN(result.size.width, NSMaxX(bounds) - NSMinX(result));
     264    result.size.width = MIN(result.size.width, (NSMinX(rightRect) - PADDING_BETWEEN_LINES_ON_SAME_LINE) - NSMinX(result));
    232265   
    233266    return result;
Note: See TracChangeset for help on using the changeset viewer.