Changeset 2724


Ignore:
Timestamp:
Aug 11, 2007, 5:04:10 PM (15 years ago)
Author:
livings124
Message:

have the code generate each attributed string once per draw instead of twice

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/macosx/TorrentCell.m

    r2723 r2724  
    5151- (NSImage *) advancedBarSimple;
    5252
    53 - (NSRect) rectForTitleBasedOnMinimalStatusRect: (NSRect) statusRect inBounds: (NSRect) bounds;
    54 - (NSRect) rectForProgressBasedOnTitleRect: (NSRect) titleRect inBounds: (NSRect) bounds;
     53#warning rearrange
     54- (NSRect) rectForMinimalStatusRectWithString: (NSAttributedString *) string inBounds: (NSRect) bounds;
     55- (NSRect) rectForTitleBasedOnMinimalStatusRect: (NSRect) statusRect withString: (NSAttributedString *) string
     56            inBounds: (NSRect) bounds;
     57- (NSRect) rectForProgressBasedOnTitleRect: (NSRect) titleRect withString: (NSAttributedString *) string inBounds: (NSRect) bounds;
    5558- (NSRect) rectForBarBasedOnAboveRect: (NSRect) aboveRect inBounds: (NSRect) bounds;
    56 - (NSRect) rectForStatusBasedOnProgressRect: (NSRect) progressRect inBounds: (NSRect) bounds;
     59- (NSRect) rectForStatusBasedOnProgressRect: (NSRect) progressRect withString: (NSAttributedString *) string
     60            inBounds: (NSRect) bounds;
    5761
    5862- (NSAttributedString *) attributedTitleWithColor: (NSColor *) color;
     
    139143- (NSRect) titleRectForBounds: (NSRect) bounds
    140144{
    141     return [self rectForTitleBasedOnMinimalStatusRect: [self minimalStatusRectForBounds: bounds] inBounds: bounds];
     145    return [self rectForTitleBasedOnMinimalStatusRect: [self minimalStatusRectForBounds: bounds]
     146                    withString: [self attributedTitleWithColor: nil] inBounds: bounds];
    142147}
    143148
    144149- (NSRect) minimalStatusRectForBounds: (NSRect) bounds
    145150{
    146     if (![fDefaults boolForKey: @"SmallView"])
    147         return NSZeroRect;
    148    
    149151    Torrent * torrent = [self representedObject];
    150     NSString * string = ![fDefaults boolForKey: @"SmallStatusRegular"] && [torrent isActive]
     152    NSString * string = [torrent isActive] && ![fDefaults boolForKey: @"SmallStatusRegular"]
    151153                            ? [torrent remainingTimeString] : [torrent shortStatusString];
    152     NSAttributedString * status = [self attributedStatusString: string withColor: nil];
    153    
    154     NSRect result = bounds;
    155     result.size = [status size];
    156    
    157     result.origin.x += bounds.size.width - result.size.width - PADDING_HORIZONAL;
    158     result.origin.y += PADDING_ABOVE_MIN_STATUS;
    159    
    160     return result;
     154    return [self rectForMinimalStatusRectWithString: [self attributedStatusString: string withColor: nil] inBounds: bounds];
    161155}
    162156
    163157- (NSRect) progressRectForBounds: (NSRect) bounds
    164158{
    165     return [self rectForProgressBasedOnTitleRect: [self titleRectForBounds: bounds] inBounds: bounds];
     159    NSString * string = [[self representedObject] progressString];
     160    return [self rectForProgressBasedOnTitleRect: [self titleRectForBounds: bounds]
     161            withString: [self attributedStatusString: string withColor: nil] inBounds: bounds];
    166162}
    167163
     
    175171- (NSRect) statusRectForBounds: (NSRect) bounds
    176172{
    177     return [self rectForStatusBasedOnProgressRect: [self progressRectForBounds: bounds] inBounds: bounds];
    178 }
    179 
    180 - (void) drawWithFrame: (NSRect) cellFrame inView: (NSView *) controlView
    181 {
     173    NSString * string = [[self representedObject] statusString];
     174    return [self rectForStatusBasedOnProgressRect: [self progressRectForBounds: bounds]
     175            withString: [self attributedStatusString: string withColor: nil] inBounds: bounds];
     176}
     177
     178- (void) drawInteriorWithFrame: (NSRect) cellFrame inView: (NSView *) controlView
     179{
     180    [super drawInteriorWithFrame: cellFrame inView: controlView];
     181   
    182182    Torrent * torrent = [self representedObject];
    183183   
     
    221221   
    222222    //minimal status
    223     NSRect minimalStatusRect = [self minimalStatusRectForBounds: cellFrame];
     223    NSRect minimalStatusRect;
    224224    if (minimal)
    225225    {
    226226        NSString * string = ![fDefaults boolForKey: @"SmallStatusRegular"] && [torrent isActive]
    227227                                ? [torrent remainingTimeString] : [torrent shortStatusString];
    228         [[self attributedStatusString: string withColor: statusColor] drawInRect: minimalStatusRect];
     228        NSAttributedString * minimalString = [self attributedStatusString: string withColor: statusColor];
     229        minimalStatusRect = [self rectForMinimalStatusRectWithString: minimalString inBounds: cellFrame];
     230       
     231        [minimalString drawInRect: minimalStatusRect];
    229232    }
    230233   
    231234    //title
    232     NSRect titleRect = [self rectForTitleBasedOnMinimalStatusRect: minimalStatusRect inBounds: cellFrame];
    233     [[self attributedTitleWithColor: titleColor] drawInRect: titleRect];
     235    NSAttributedString * titleString = [self attributedTitleWithColor: titleColor];
     236    NSRect titleRect = [self rectForTitleBasedOnMinimalStatusRect: minimalStatusRect withString: titleString inBounds: cellFrame];
     237    [titleString drawInRect: titleRect];
    234238   
    235239    //progress
     
    237241    if (!minimal)
    238242    {
    239         progressRect = [self rectForProgressBasedOnTitleRect: titleRect inBounds: cellFrame];
    240         [[self attributedStatusString: [torrent progressString] withColor: statusColor] drawInRect: progressRect];
     243        NSAttributedString * progressString = [self attributedStatusString: [torrent progressString] withColor: statusColor];
     244        progressRect = [self rectForProgressBasedOnTitleRect: titleRect withString: progressString inBounds: cellFrame];
     245        [progressString drawInRect: progressRect];
    241246    }
    242247   
     
    249254    if (!minimal)
    250255    {
    251         NSRect statusRect = [self rectForStatusBasedOnProgressRect: progressRect inBounds: cellFrame];
    252         [[self attributedStatusString: [torrent statusString] withColor: statusColor] drawInRect: statusRect];
     256        NSAttributedString * statusString = [self attributedStatusString: [torrent statusString] withColor: statusColor];
     257        NSRect statusRect = [self rectForStatusBasedOnProgressRect: progressRect withString: statusString inBounds: cellFrame];
     258        [statusString drawInRect: statusRect];
    253259    }
    254260}
     
    524530}
    525531
    526 - (NSRect) rectForTitleBasedOnMinimalStatusRect: (NSRect) statusRect inBounds: (NSRect) bounds
     532- (NSRect) rectForMinimalStatusRectWithString: (NSAttributedString *) string inBounds: (NSRect) bounds
     533{
     534    if (![fDefaults boolForKey: @"SmallView"])
     535        return NSZeroRect;
     536   
     537    NSRect result = bounds;
     538    result.size = [string size];
     539   
     540    result.origin.x += bounds.size.width - result.size.width - PADDING_HORIZONAL;
     541    result.origin.y += PADDING_ABOVE_MIN_STATUS;
     542   
     543    return result;
     544}
     545
     546- (NSRect) rectForTitleBasedOnMinimalStatusRect: (NSRect) statusRect withString: (NSAttributedString *) string
     547            inBounds: (NSRect) bounds
    527548{
    528549    BOOL minimal = [fDefaults boolForKey: @"SmallView"];
    529550   
    530    NSRect result = bounds;
     551    NSRect result = bounds;
    531552   
    532553    result.origin.y += PADDING_ABOVE_TITLE;
    533554    result.origin.x += PADDING_HORIZONAL + (minimal ? IMAGE_SIZE_MIN : IMAGE_SIZE_REG) + PADDING_BETWEEN_IMAGE_AND_TITLE;
    534555   
    535     result.size = [[self attributedTitleWithColor: nil] size];
     556    result.size = [string size];
    536557    result.size.width = MIN(result.size.width, NSMaxX(bounds) - result.origin.x - PADDING_HORIZONAL
    537558                            - (minimal ? PADDING_BETWEEN_TITLE_AND_MIN_STATUS + statusRect.size.width : 0));
     
    540561}
    541562
    542 - (NSRect) rectForProgressBasedOnTitleRect: (NSRect) titleRect inBounds: (NSRect) bounds
     563- (NSRect) rectForProgressBasedOnTitleRect: (NSRect) titleRect withString: (NSAttributedString *) string inBounds: (NSRect) bounds
    543564{
    544565    if ([fDefaults boolForKey: @"SmallView"])
    545566        return NSZeroRect;
    546567   
    547     NSSize progressSize = [[self attributedStatusString: [[self representedObject] progressString] withColor: nil] size];
     568    NSSize progressSize = [string size];
    548569   
    549570    NSRect result = titleRect;
    550    
    551571    result.size.width = MIN(progressSize.width, NSMaxX(bounds) - result.origin.x - PADDING_HORIZONAL);
    552572   
     
    570590}
    571591
    572 - (NSRect) rectForStatusBasedOnProgressRect: (NSRect) progressRect inBounds: (NSRect) bounds
     592- (NSRect) rectForStatusBasedOnProgressRect: (NSRect) progressRect withString: (NSAttributedString *) string
     593            inBounds: (NSRect) bounds
    573594{
    574595    if ([fDefaults boolForKey: @"SmallView"])
    575596        return NSZeroRect;
    576597   
    577     NSSize statusSize = [[self attributedStatusString: [[self representedObject] statusString] withColor: nil] size];
     598    NSSize statusSize = [string size];
    578599   
    579600    NSRect result = progressRect;
Note: See TracChangeset for help on using the changeset viewer.