Ignore:
Timestamp:
Mar 22, 2007, 4:30:08 AM (15 years ago)
Author:
livings124
Message:

seeding bar shows progress towards ratio

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/macosx/TorrentCell.m

    r1402 r1575  
    6464        [fProgressGreen setScalesWhenResized: YES];
    6565       
     66        fProgressLightGreen = [NSImage imageNamed: @"ProgressBarLightGreen.png"];
     67        [fProgressLightGreen setScalesWhenResized: YES];
     68       
    6669        fProgressAdvanced = [NSImage imageNamed: @"ProgressBarAdvanced.png"];
    6770        [fProgressAdvanced setScalesWhenResized: YES];
     
    9295
    9396    width -= 2.0;
    94     if ([[info objectForKey: @"Seeding"] boolValue])
    95     {
    96         [fProgressEndGreen compositeToPoint: point operation: NSCompositeSourceOver];
    97        
    98         point.x += 1.0;
    99         [self placeBar: fProgressGreen width: width point: point];
    100        
    101         point.x += width;
    102         [fProgressEndGreen compositeToPoint: point operation: NSCompositeSourceOver];
     97   
     98    BOOL seeding = [[info objectForKey: @"Seeding"] boolValue],
     99        isActive = [[info objectForKey: @"Active"] boolValue];
     100    float completedWidth, remainingWidth;
     101   
     102    //bar images
     103    NSImage * barLeftEnd, * barRightEnd, * barComplete, * barRemaining;
     104    if (seeding)
     105    {
     106        float stopRatio, ratio;
     107        if ((stopRatio = [[info objectForKey: @"StopRatio"] floatValue]) != INVALID
     108                && (ratio = [[info objectForKey: @"Ratio"] floatValue]) < stopRatio)
     109            completedWidth = width * ratio / stopRatio;
     110        else
     111            completedWidth = width;
     112        remainingWidth = width - completedWidth;
     113       
     114        barLeftEnd = fProgressEndGreen;
     115        barRightEnd = fProgressEndGreen;
     116        barComplete = fProgressGreen;
     117        barRemaining = fProgressLightGreen;
    103118    }
    104119    else
    105120    {
    106         float completedWidth = [[info objectForKey: @"Progress"] floatValue] * width,
    107                 remainingWidth = width - completedWidth;
    108         BOOL isActive = [[info objectForKey: @"Active"] boolValue];
    109        
    110         //left end
    111         NSImage * barLeftEnd;
     121        completedWidth = [[info objectForKey: @"Progress"] floatValue] * width;
     122        remainingWidth = width - completedWidth;
     123       
    112124        if (remainingWidth == width)
    113125            barLeftEnd = fProgressEndWhite;
     
    117129            barLeftEnd = fProgressEndGray;
    118130       
    119         [barLeftEnd compositeToPoint: point operation: NSCompositeSourceOver];
    120        
    121         //active bar
    122         point.x += 1.0;
    123         [self placeBar: isActive ? fProgressBlue : fProgressGray width: completedWidth point: point];
    124        
    125         //remaining bar
    126         point.x += completedWidth;
    127         [self placeBar: fProgressWhite width: remainingWidth point: point];
    128        
    129         //right end
    130         NSImage * barRightEnd;
    131131        if (completedWidth < width)
    132132            barRightEnd = fProgressEndWhite;
     
    136136            barRightEnd = fProgressEndGray;
    137137       
    138         point.x += remainingWidth;
    139         [barRightEnd compositeToPoint: point operation: NSCompositeSourceOver];
    140     }
     138        barComplete = isActive ? fProgressBlue : fProgressGray;
     139        barRemaining = fProgressWhite;
     140    }
     141   
     142    [barLeftEnd compositeToPoint: point operation: NSCompositeSourceOver];
     143   
     144    //active bar
     145    point.x += 1.0;
     146    [self placeBar: barComplete width: completedWidth point: point];
     147   
     148    //remaining bar
     149    point.x += completedWidth;
     150    [self placeBar: barRemaining width: remainingWidth point: point];
     151   
     152    point.x += remainingWidth;
     153    [barRightEnd compositeToPoint: point operation: NSCompositeSourceOver];
    141154}
    142155
Note: See TracChangeset for help on using the changeset viewer.