Changeset 856


Ignore:
Timestamp:
Sep 12, 2006, 12:08:30 AM (15 years ago)
Author:
livings124
Message:

Advanced bar should work again.

Location:
trunk/macosx
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • trunk/macosx/Torrent.m

    r855 r856  
    2626#import "StringAdditions.h"
    2727
     28#define BAR_HEIGHT 12.0
     29
    2830@interface Torrent (Private)
    2931
     
    3436        orderValue: (NSNumber *) orderValue;
    3537
     38- (NSImage *) advancedBar;
     39
    3640- (void) trashFile: (NSString *) path;
    3741
     
    3943
    4044@implementation Torrent
     45
     46// Used to optimize drawing. They contain packed RGBA pixels for every color needed.
     47#define BE OSSwapBigToHostConstInt32
     48static uint32_t kBorder[] =
     49    { BE(0x00000005), BE(0x00000010), BE(0x00000015), BE(0x00000015),
     50      BE(0x00000015), BE(0x00000015), BE(0x00000015), BE(0x00000015),
     51      BE(0x00000015), BE(0x00000015), BE(0x00000010), BE(0x00000005) };
     52
     53static uint32_t kBack[] = { BE(0xB4B4B4FF), BE(0xE3E3E3FF) };
     54
     55static uint32_t kRed   = BE(0xFF6450FF), //255, 100, 80
     56                kBlue1 = BE(0xA0DCFFFF), //160, 220, 255
     57                kBlue2 = BE(0x78BEFFFF), //120, 190, 255
     58                kBlue3 = BE(0x50A0FFFF), //80, 160, 255
     59                kBlue4 = BE(0x1E46B4FF), //30, 70, 180
     60                kGray  = BE(0x828282FF), //130, 130, 130
     61                kGreen = BE(0x00FF00FF); //0, 255, 0
    4162
    4263- (id) initWithPath: (NSString *) path lib: (tr_handle_t *) lib
     
    294315    }
    295316   
     317    if ([fDefaults boolForKey: @"UseAdvancedBar"])
     318        [info setObject: [self advancedBar] forKey: @"AdvancedBar"];
     319   
    296320    return info;
     321}
     322
     323- (NSImage *) advancedBar
     324{
     325    int width = 100; //integers for bars
     326   
     327    NSBitmapImageRep * bitmap = [[NSBitmapImageRep alloc] initWithBitmapDataPlanes: nil
     328        pixelsWide: width pixelsHigh: BAR_HEIGHT bitsPerSample: 8 samplesPerPixel: 4 hasAlpha: YES
     329        isPlanar: NO colorSpaceName: NSCalibratedRGBColorSpace bytesPerRow: 0 bitsPerPixel: 0];
     330
     331    int h, w;
     332    uint32_t * p;
     333    uint8_t * bitmapData = [bitmap bitmapData];
     334    int bytesPerRow = [bitmap bytesPerRow];
     335
     336    //left and right borders
     337    p = (uint32_t *) bitmapData;
     338    for(h = 0; h < BAR_HEIGHT; h++)
     339    {
     340        p[0] = kBorder[h];
     341        p[width - 1] = kBorder[h];
     342        p += bytesPerRow / 4;
     343    }
     344
     345    int8_t * pieces = malloc(width);
     346    [self getAvailability: pieces size: width];
     347    int avail = 0;
     348    for (w = 0; w < width; w++)
     349        if (pieces[w] != 0)
     350            avail++;
     351
     352    //first two lines: dark blue to show progression, green to show available
     353    int end = lrintf(floor([self progress] * (width - 2)));
     354    p = (uint32_t *) (bitmapData) + 1;
     355
     356    for (w = 0; w < end; w++)
     357    {
     358        p[w] = kBlue4;
     359        p[w + bytesPerRow / 4] = kBlue4;
     360    }
     361    for (; w < avail; w++)
     362    {
     363        p[w] = kGreen;
     364        p[w + bytesPerRow / 4] = kGreen;
     365    }
     366    for (; w < width - 2; w++)
     367    {
     368        p[w] = kBack[0];
     369        p[w + bytesPerRow / 4] = kBack[1];
     370    }
     371   
     372    //lines 2 to 14: blue or grey depending on whether we have the piece or not
     373    uint32_t color;
     374    for( w = 0; w < width - 2; w++ )
     375    {
     376        //point to pixel ( 2 + w, 2 ). We will then draw "vertically"
     377        p = (uint32_t *) ( bitmapData + 2 * bytesPerRow ) + 1 + w;
     378
     379        if (pieces[w] < 0)
     380            color = kGray;
     381        else if (pieces[w] == 0)
     382            color = kRed;
     383        else if (pieces[w] == 1)
     384            color = kBlue1;
     385        else if (pieces[w] == 2)
     386            color = kBlue2;
     387        else
     388            color = kBlue3;
     389
     390        for( h = 2; h < BAR_HEIGHT; h++ )
     391        {
     392            p[0] = color;
     393            p = (uint32_t *) ( (uint8_t *) p + bytesPerRow );
     394        }
     395    }
     396
     397    free(pieces);
     398   
     399    //actually draw image
     400    NSImage * bar = [[NSImage alloc] initWithSize: [bitmap size]];
     401    [bar addRepresentation: bitmap];
     402    [bitmap release];
     403   
     404    [bar setScalesWhenResized: YES];
     405   
     406    return [bar autorelease];
    297407}
    298408
  • trunk/macosx/TorrentCell.m

    r855 r856  
    2727#import "StringAdditions.h"
    2828
     29//also defined in Torrent.m
    2930#define BAR_HEIGHT 12.0
    3031
     
    3839
    3940@implementation TorrentCell
    40 
    41 // Used to optimize drawing. They contain packed RGBA pixels for every color needed.
    42 #define BE OSSwapBigToHostConstInt32
    43 static uint32_t kBorder[] =
    44     { BE(0x00000005), BE(0x00000010), BE(0x00000015), BE(0x00000015),
    45       BE(0x00000015), BE(0x00000015), BE(0x00000015), BE(0x00000015),
    46       BE(0x00000015), BE(0x00000015), BE(0x00000010), BE(0x00000005) };
    47 
    48 static uint32_t kBack[] = { BE(0xB4B4B4FF), BE(0xE3E3E3FF) };
    49 
    50 static uint32_t kRed   = BE(0xFF6450FF), //255, 100, 80
    51                 kBlue1 = BE(0xA0DCFFFF), //160, 220, 255
    52                 kBlue2 = BE(0x78BEFFFF), //120, 190, 255
    53                 kBlue3 = BE(0x50A0FFFF), //80, 160, 255
    54                 kBlue4 = BE(0x1E46B4FF), //30, 70, 180
    55                 kGray  = BE(0x828282FF), //130, 130, 130
    56                 kGreen = BE(0x00FF00FF); //0, 255, 0
    5741
    5842- (id) init
     
    164148}
    165149
    166 /*- (void) buildAdvancedBar: (float) widthFloat point: (NSPoint) point
    167 {
     150- (void) buildAdvancedBar: (float) widthFloat point: (NSPoint) point
     151{
     152    NSDictionary * info = [self objectValue];
     153   
    168154    //if seeding, there's no need for the advanced bar
    169     if ([fTorrent isSeeding])
     155    if ([[info objectForKey: @"Seeding"] boolValue])
    170156    {
    171157        [self buildSimpleBar: widthFloat point: point];
     
    173159    }
    174160
    175     int width = widthFloat; //integers for bars
    176    
    177     NSBitmapImageRep * bitmap = [[NSBitmapImageRep alloc] initWithBitmapDataPlanes: nil
    178         pixelsWide: width pixelsHigh: BAR_HEIGHT bitsPerSample: 8 samplesPerPixel: 4 hasAlpha: YES
    179         isPlanar: NO colorSpaceName: NSCalibratedRGBColorSpace bytesPerRow: 0 bitsPerPixel: 0];
    180 
    181     int h, w;
    182     uint32_t * p;
    183     uint8_t * bitmapData = [bitmap bitmapData];
    184     int bytesPerRow = [bitmap bytesPerRow];
    185 
    186     //left and right borders
    187     p = (uint32_t *) bitmapData;
    188     for(h = 0; h < BAR_HEIGHT; h++)
    189     {
    190         p[0] = kBorder[h];
    191         p[width - 1] = kBorder[h];
    192         p += bytesPerRow / 4;
    193     }
    194 
    195     int8_t * pieces = malloc(width);
    196     [fTorrent getAvailability: pieces size: width];
    197     int avail = 0;
    198     for (w = 0; w < width; w++)
    199         if (pieces[w] != 0)
    200             avail++;
    201 
    202     //first two lines: dark blue to show progression, green to show available
    203     int end = lrintf(floor([fTorrent progress] * (width - 2)));
    204     p = (uint32_t *) (bitmapData) + 1;
    205 
    206     for (w = 0; w < end; w++)
    207     {
    208         p[w] = kBlue4;
    209         p[w + bytesPerRow / 4] = kBlue4;
    210     }
    211     for (; w < avail; w++)
    212     {
    213         p[w] = kGreen;
    214         p[w + bytesPerRow / 4] = kGreen;
    215     }
    216     for (; w < width - 2; w++)
    217     {
    218         p[w] = kBack[0];
    219         p[w + bytesPerRow / 4] = kBack[1];
    220     }
    221    
    222     //lines 2 to 14: blue or grey depending on whether we have the piece or not
    223     uint32_t color;
    224     for( w = 0; w < width - 2; w++ )
    225     {
    226         //point to pixel ( 2 + w, 2 ). We will then draw "vertically"
    227         p = (uint32_t *) ( bitmapData + 2 * bytesPerRow ) + 1 + w;
    228 
    229         if (pieces[w] < 0)
    230             color = kGray;
    231         else if (pieces[w] == 0)
    232             color = kRed;
    233         else if (pieces[w] == 1)
    234             color = kBlue1;
    235         else if (pieces[w] == 2)
    236             color = kBlue2;
    237         else
    238             color = kBlue3;
    239 
    240         for( h = 2; h < BAR_HEIGHT; h++ )
    241         {
    242             p[0] = color;
    243             p = (uint32_t *) ( (uint8_t *) p + bytesPerRow );
    244         }
    245     }
    246 
    247     free( pieces );
    248    
    249     //actually draw image
    250     NSImage * img = [[NSImage alloc] initWithSize: [bitmap size]];
    251     [img addRepresentation: bitmap];
    252    
    253     //bar size with float, not double, to match standard bar
    254     [img setScalesWhenResized: YES];
     161    NSImage * img = [info objectForKey: @"AdvancedBar"];
    255162    [img setSize: NSMakeSize(widthFloat, BAR_HEIGHT)];
    256    
     163
    257164    [img compositeToPoint: point operation: NSCompositeSourceOver];
    258     [img release];
    259     [bitmap release];
    260165   
    261166    //draw overlay over advanced bar
     
    268173    point.x += widthFloat;
    269174    [fProgressEndAdvanced compositeToPoint: point operation: NSCompositeSourceOver];
    270 }*/
     175}
    271176
    272177- (void) toggleMinimalStatus
     
    336241        float barWidth = mainWidth + EXTRA_NAME_SHIFT - BUTTONS_TOTAL_WIDTH + PADDING;
    337242       
    338         /*if ([fDefaults boolForKey: @"UseAdvancedBar"])
     243        if ([fDefaults boolForKey: @"UseAdvancedBar"])
    339244            [self buildAdvancedBar: barWidth point: pen];
    340         else*/
     245        else
    341246            [self buildSimpleBar: barWidth point: pen];
    342247
     
    390295        float barWidth = mainWidth + EXTRA_NAME_SHIFT - BUTTONS_TOTAL_WIDTH + PADDING;
    391296       
    392         /*if ([fDefaults boolForKey: @"UseAdvancedBar"])
     297        if ([fDefaults boolForKey: @"UseAdvancedBar"])
    393298            [self buildAdvancedBar: barWidth point: pen];
    394         else*/
     299        else
    395300            [self buildSimpleBar: barWidth point: pen];
    396301    }
Note: See TracChangeset for help on using the changeset viewer.