- Timestamp:
- Sep 12, 2006, 12:08:30 AM (16 years ago)
- Location:
- trunk/macosx
- Files:
-
- 2 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/macosx/Torrent.m
r855 r856 26 26 #import "StringAdditions.h" 27 27 28 #define BAR_HEIGHT 12.0 29 28 30 @interface Torrent (Private) 29 31 … … 34 36 orderValue: (NSNumber *) orderValue; 35 37 38 - (NSImage *) advancedBar; 39 36 40 - (void) trashFile: (NSString *) path; 37 41 … … 39 43 40 44 @implementation Torrent 45 46 // Used to optimize drawing. They contain packed RGBA pixels for every color needed. 47 #define BE OSSwapBigToHostConstInt32 48 static 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 53 static uint32_t kBack[] = { BE(0xB4B4B4FF), BE(0xE3E3E3FF) }; 54 55 static 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 41 62 42 63 - (id) initWithPath: (NSString *) path lib: (tr_handle_t *) lib … … 294 315 } 295 316 317 if ([fDefaults boolForKey: @"UseAdvancedBar"]) 318 [info setObject: [self advancedBar] forKey: @"AdvancedBar"]; 319 296 320 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]; 297 407 } 298 408 -
trunk/macosx/TorrentCell.m
r855 r856 27 27 #import "StringAdditions.h" 28 28 29 //also defined in Torrent.m 29 30 #define BAR_HEIGHT 12.0 30 31 … … 38 39 39 40 @implementation TorrentCell 40 41 // Used to optimize drawing. They contain packed RGBA pixels for every color needed.42 #define BE OSSwapBigToHostConstInt3243 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, 8051 kBlue1 = BE(0xA0DCFFFF), //160, 220, 25552 kBlue2 = BE(0x78BEFFFF), //120, 190, 25553 kBlue3 = BE(0x50A0FFFF), //80, 160, 25554 kBlue4 = BE(0x1E46B4FF), //30, 70, 18055 kGray = BE(0x828282FF), //130, 130, 13056 kGreen = BE(0x00FF00FF); //0, 255, 057 41 58 42 - (id) init … … 164 148 } 165 149 166 /*- (void) buildAdvancedBar: (float) widthFloat point: (NSPoint) point 167 { 150 - (void) buildAdvancedBar: (float) widthFloat point: (NSPoint) point 151 { 152 NSDictionary * info = [self objectValue]; 153 168 154 //if seeding, there's no need for the advanced bar 169 if ([ fTorrent isSeeding])155 if ([[info objectForKey: @"Seeding"] boolValue]) 170 156 { 171 157 [self buildSimpleBar: widthFloat point: point]; … … 173 159 } 174 160 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"]; 255 162 [img setSize: NSMakeSize(widthFloat, BAR_HEIGHT)]; 256 163 257 164 [img compositeToPoint: point operation: NSCompositeSourceOver]; 258 [img release];259 [bitmap release];260 165 261 166 //draw overlay over advanced bar … … 268 173 point.x += widthFloat; 269 174 [fProgressEndAdvanced compositeToPoint: point operation: NSCompositeSourceOver]; 270 } */175 } 271 176 272 177 - (void) toggleMinimalStatus … … 336 241 float barWidth = mainWidth + EXTRA_NAME_SHIFT - BUTTONS_TOTAL_WIDTH + PADDING; 337 242 338 /*if ([fDefaults boolForKey: @"UseAdvancedBar"])243 if ([fDefaults boolForKey: @"UseAdvancedBar"]) 339 244 [self buildAdvancedBar: barWidth point: pen]; 340 else */245 else 341 246 [self buildSimpleBar: barWidth point: pen]; 342 247 … … 390 295 float barWidth = mainWidth + EXTRA_NAME_SHIFT - BUTTONS_TOTAL_WIDTH + PADDING; 391 296 392 /*if ([fDefaults boolForKey: @"UseAdvancedBar"])297 if ([fDefaults boolForKey: @"UseAdvancedBar"]) 393 298 [self buildAdvancedBar: barWidth point: pen]; 394 else */299 else 395 300 [self buildSimpleBar: barWidth point: pen]; 396 301 }
Note: See TracChangeset
for help on using the changeset viewer.