This look for the progress bars matches the new smooth aqua look a lot more and is generated from images instead of drawing the bar from scratch.
The advanced bar should also be easier on the eyes now that the overlay isn't as extreme. Thanks to FOOOD for the images.
|
@ -80,6 +80,16 @@
|
|||
A21610FC0A050B1700E8E4C1 /* MenuButton.m in Sources */ = {isa = PBXBuildFile; fileRef = A21610FB0A050B1700E8E4C1 /* MenuButton.m */; };
|
||||
A2173E1C0A33C1B300B0D8AB /* ActionButtonPressed.tiff in Resources */ = {isa = PBXBuildFile; fileRef = A2173E1B0A33C1B300B0D8AB /* ActionButtonPressed.tiff */; };
|
||||
A21DFF100A292B2B007C5F76 /* Transfers.png in Resources */ = {isa = PBXBuildFile; fileRef = A21DFF0F0A292B2B007C5F76 /* Transfers.png */; };
|
||||
A2305A800A3DC9E400AB2D77 /* ProgressBarWhite.png in Resources */ = {isa = PBXBuildFile; fileRef = A2305A7C0A3DC9E400AB2D77 /* ProgressBarWhite.png */; };
|
||||
A2305A810A3DC9E400AB2D77 /* ProgressBarBlue.png in Resources */ = {isa = PBXBuildFile; fileRef = A2305A7D0A3DC9E400AB2D77 /* ProgressBarBlue.png */; };
|
||||
A2305A820A3DC9E400AB2D77 /* ProgressBarGray.png in Resources */ = {isa = PBXBuildFile; fileRef = A2305A7E0A3DC9E400AB2D77 /* ProgressBarGray.png */; };
|
||||
A2305A830A3DC9E400AB2D77 /* ProgressBarGreen.png in Resources */ = {isa = PBXBuildFile; fileRef = A2305A7F0A3DC9E400AB2D77 /* ProgressBarGreen.png */; };
|
||||
A2305A950A3DCAC500AB2D77 /* ProgressBarAdvanced.png in Resources */ = {isa = PBXBuildFile; fileRef = A2305A940A3DCAC500AB2D77 /* ProgressBarAdvanced.png */; };
|
||||
A2305AA90A3DCCEF00AB2D77 /* ProgressBarEndAdvanced.png in Resources */ = {isa = PBXBuildFile; fileRef = A2305AA40A3DCCEF00AB2D77 /* ProgressBarEndAdvanced.png */; };
|
||||
A2305AAA0A3DCCEF00AB2D77 /* ProgressBarEndBlue.png in Resources */ = {isa = PBXBuildFile; fileRef = A2305AA50A3DCCEF00AB2D77 /* ProgressBarEndBlue.png */; };
|
||||
A2305AAB0A3DCCEF00AB2D77 /* ProgressBarEndWhite.png in Resources */ = {isa = PBXBuildFile; fileRef = A2305AA60A3DCCEF00AB2D77 /* ProgressBarEndWhite.png */; };
|
||||
A2305AAC0A3DCCEF00AB2D77 /* ProgressBarEndGreen.png in Resources */ = {isa = PBXBuildFile; fileRef = A2305AA70A3DCCEF00AB2D77 /* ProgressBarEndGreen.png */; };
|
||||
A2305AAD0A3DCCEF00AB2D77 /* ProgressBarEndGray.png in Resources */ = {isa = PBXBuildFile; fileRef = A2305AA80A3DCCEF00AB2D77 /* ProgressBarEndGray.png */; };
|
||||
A24F19080A3A790800C9C145 /* Sparkle.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = A24F19070A3A790800C9C145 /* Sparkle.framework */; };
|
||||
A24F19210A3A796800C9C145 /* Sparkle.framework in CopyFiles */ = {isa = PBXBuildFile; fileRef = A24F19070A3A790800C9C145 /* Sparkle.framework */; };
|
||||
A2519D490A2FADFC00479D0C /* SmoothAquaView.m in Sources */ = {isa = PBXBuildFile; fileRef = A2519D470A2FADFC00479D0C /* SmoothAquaView.m */; };
|
||||
|
@ -252,6 +262,16 @@
|
|||
A21610FB0A050B1700E8E4C1 /* MenuButton.m */ = {isa = PBXFileReference; fileEncoding = 30; lastKnownFileType = sourcecode.c.objc; name = MenuButton.m; path = macosx/MenuButton.m; sourceTree = "<group>"; };
|
||||
A2173E1B0A33C1B300B0D8AB /* ActionButtonPressed.tiff */ = {isa = PBXFileReference; lastKnownFileType = image.tiff; name = ActionButtonPressed.tiff; path = macosx/Images/ActionButtonPressed.tiff; sourceTree = "<group>"; };
|
||||
A21DFF0F0A292B2B007C5F76 /* Transfers.png */ = {isa = PBXFileReference; lastKnownFileType = image.png; name = Transfers.png; path = macosx/Images/Transfers.png; sourceTree = "<group>"; };
|
||||
A2305A7C0A3DC9E400AB2D77 /* ProgressBarWhite.png */ = {isa = PBXFileReference; lastKnownFileType = image.png; name = ProgressBarWhite.png; path = macosx/Images/ProgressBarWhite.png; sourceTree = "<group>"; };
|
||||
A2305A7D0A3DC9E400AB2D77 /* ProgressBarBlue.png */ = {isa = PBXFileReference; lastKnownFileType = image.png; name = ProgressBarBlue.png; path = macosx/Images/ProgressBarBlue.png; sourceTree = "<group>"; };
|
||||
A2305A7E0A3DC9E400AB2D77 /* ProgressBarGray.png */ = {isa = PBXFileReference; lastKnownFileType = image.png; name = ProgressBarGray.png; path = macosx/Images/ProgressBarGray.png; sourceTree = "<group>"; };
|
||||
A2305A7F0A3DC9E400AB2D77 /* ProgressBarGreen.png */ = {isa = PBXFileReference; lastKnownFileType = image.png; name = ProgressBarGreen.png; path = macosx/Images/ProgressBarGreen.png; sourceTree = "<group>"; };
|
||||
A2305A940A3DCAC500AB2D77 /* ProgressBarAdvanced.png */ = {isa = PBXFileReference; lastKnownFileType = image.png; name = ProgressBarAdvanced.png; path = macosx/Images/ProgressBarAdvanced.png; sourceTree = "<group>"; };
|
||||
A2305AA40A3DCCEF00AB2D77 /* ProgressBarEndAdvanced.png */ = {isa = PBXFileReference; lastKnownFileType = image.png; name = ProgressBarEndAdvanced.png; path = macosx/Images/ProgressBarEndAdvanced.png; sourceTree = "<group>"; };
|
||||
A2305AA50A3DCCEF00AB2D77 /* ProgressBarEndBlue.png */ = {isa = PBXFileReference; lastKnownFileType = image.png; name = ProgressBarEndBlue.png; path = macosx/Images/ProgressBarEndBlue.png; sourceTree = "<group>"; };
|
||||
A2305AA60A3DCCEF00AB2D77 /* ProgressBarEndWhite.png */ = {isa = PBXFileReference; lastKnownFileType = image.png; name = ProgressBarEndWhite.png; path = macosx/Images/ProgressBarEndWhite.png; sourceTree = "<group>"; };
|
||||
A2305AA70A3DCCEF00AB2D77 /* ProgressBarEndGreen.png */ = {isa = PBXFileReference; lastKnownFileType = image.png; name = ProgressBarEndGreen.png; path = macosx/Images/ProgressBarEndGreen.png; sourceTree = "<group>"; };
|
||||
A2305AA80A3DCCEF00AB2D77 /* ProgressBarEndGray.png */ = {isa = PBXFileReference; lastKnownFileType = image.png; name = ProgressBarEndGray.png; path = macosx/Images/ProgressBarEndGray.png; sourceTree = "<group>"; };
|
||||
A24F19070A3A790800C9C145 /* Sparkle.framework */ = {isa = PBXFileReference; lastKnownFileType = wrapper.framework; path = Sparkle.framework; sourceTree = "<group>"; };
|
||||
A2519D470A2FADFC00479D0C /* SmoothAquaView.m */ = {isa = PBXFileReference; fileEncoding = 30; lastKnownFileType = sourcecode.c.objc; name = SmoothAquaView.m; path = macosx/SmoothAquaView.m; sourceTree = "<group>"; };
|
||||
A2519D480A2FADFC00479D0C /* SmoothAquaView.h */ = {isa = PBXFileReference; fileEncoding = 30; lastKnownFileType = sourcecode.c.h; name = SmoothAquaView.h; path = macosx/SmoothAquaView.h; sourceTree = "<group>"; };
|
||||
|
@ -361,6 +381,16 @@
|
|||
isa = PBXGroup;
|
||||
children = (
|
||||
A2F8951E0A2D4BA500ED2127 /* Credits.rtf */,
|
||||
A2305AA40A3DCCEF00AB2D77 /* ProgressBarEndAdvanced.png */,
|
||||
A2305AA50A3DCCEF00AB2D77 /* ProgressBarEndBlue.png */,
|
||||
A2305AA60A3DCCEF00AB2D77 /* ProgressBarEndWhite.png */,
|
||||
A2305AA70A3DCCEF00AB2D77 /* ProgressBarEndGreen.png */,
|
||||
A2305AA80A3DCCEF00AB2D77 /* ProgressBarEndGray.png */,
|
||||
A2305A940A3DCAC500AB2D77 /* ProgressBarAdvanced.png */,
|
||||
A2305A7C0A3DC9E400AB2D77 /* ProgressBarWhite.png */,
|
||||
A2305A7D0A3DC9E400AB2D77 /* ProgressBarBlue.png */,
|
||||
A2305A7E0A3DC9E400AB2D77 /* ProgressBarGray.png */,
|
||||
A2305A7F0A3DC9E400AB2D77 /* ProgressBarGreen.png */,
|
||||
A21DFF0F0A292B2B007C5F76 /* Transfers.png */,
|
||||
A27A53640A06AED200E1F16F /* StatusBorder.tiff */,
|
||||
A27A53420A06A62500E1F16F /* StatusSep.png */,
|
||||
|
@ -634,6 +664,16 @@
|
|||
A2F40AE40A361C00006B8288 /* Transmission.icns in Resources */,
|
||||
A25FCDEF0A3769A6002BCBBE /* PauseSelected.png in Resources */,
|
||||
A25FCDF00A3769AC002BCBBE /* ResumeSelected.png in Resources */,
|
||||
A2305A800A3DC9E400AB2D77 /* ProgressBarWhite.png in Resources */,
|
||||
A2305A810A3DC9E400AB2D77 /* ProgressBarBlue.png in Resources */,
|
||||
A2305A820A3DC9E400AB2D77 /* ProgressBarGray.png in Resources */,
|
||||
A2305A830A3DC9E400AB2D77 /* ProgressBarGreen.png in Resources */,
|
||||
A2305A950A3DCAC500AB2D77 /* ProgressBarAdvanced.png in Resources */,
|
||||
A2305AA90A3DCCEF00AB2D77 /* ProgressBarEndAdvanced.png in Resources */,
|
||||
A2305AAA0A3DCCEF00AB2D77 /* ProgressBarEndBlue.png in Resources */,
|
||||
A2305AAB0A3DCCEF00AB2D77 /* ProgressBarEndWhite.png in Resources */,
|
||||
A2305AAC0A3DCCEF00AB2D77 /* ProgressBarEndGreen.png in Resources */,
|
||||
A2305AAD0A3DCCEF00AB2D77 /* ProgressBarEndGray.png in Resources */,
|
||||
);
|
||||
runOnlyForDeploymentPostprocessing = 0;
|
||||
};
|
||||
|
|
After Width: | Height: | Size: 157 B |
After Width: | Height: | Size: 159 B |
After Width: | Height: | Size: 131 B |
After Width: | Height: | Size: 130 B |
After Width: | Height: | Size: 130 B |
After Width: | Height: | Size: 130 B |
After Width: | Height: | Size: 130 B |
After Width: | Height: | Size: 159 B |
After Width: | Height: | Size: 159 B |
After Width: | Height: | Size: 159 B |
|
@ -26,201 +26,229 @@
|
|||
#import "TorrentTableView.h"
|
||||
#import "StringAdditions.h"
|
||||
|
||||
#define BAR_HEIGHT 12
|
||||
#define BAR_HEIGHT 12.0
|
||||
|
||||
@interface TorrentCell (Private)
|
||||
|
||||
- (void) placeBar: (NSImage *) barImage width: (float) width point: (NSPoint) point;
|
||||
- (void) buildSimpleBar: (int) width point: (NSPoint) point;
|
||||
- (void) buildAdvancedBar: (int) width point: (NSPoint) point;
|
||||
|
||||
@end
|
||||
|
||||
@implementation TorrentCell
|
||||
|
||||
/***********************************************************************
|
||||
* Static tables
|
||||
***********************************************************************
|
||||
* We use these tables to optimize the drawing. They contain packed
|
||||
* RGBA pixels for every color we might need.
|
||||
**********************************************************************/
|
||||
static NSImage * fProgressWhite, * fProgressBlue, * fProgressGray, * fProgressGreen,
|
||||
* fProgressAdvanced, * fProgressEndWhite, * fProgressEndBlue,
|
||||
* fProgressEndGray, * fProgressEndGreen, * fProgressEndAdvanced;
|
||||
|
||||
// Used to optimize drawing. They contain packed RGBA pixels for every color needed.
|
||||
static uint32_t kBorder[] =
|
||||
{ 0x00000005, 0x00000010, 0x00000015, 0x00000015,
|
||||
0x00000015, 0x00000015, 0x00000015, 0x00000015,
|
||||
0x00000015, 0x00000015, 0x00000010, 0x00000005 };
|
||||
|
||||
static uint32_t kBack[] =
|
||||
{ 0xB4B4B4FF, 0xE3E3E3FF, 0xE8E8E8FF, 0xDEDEDEFF,
|
||||
0xDBDBDBFF, 0xE5E5E5FF, 0xE7E7E7FF, 0xF5F5F5FF,
|
||||
0xFAFAFAFF, 0xDEDEDEFF, 0x0000003F, 0x00000015 };
|
||||
static uint32_t kBack[] = { 0xB4B4B4FF, 0xE3E3E3FF };
|
||||
|
||||
/* Coefficients for the "3D effect":
|
||||
0.59, 0.91, 0.97, 0.92, 0.79, 0.76, 0.85, 0.93, 1.00, 0.99 */
|
||||
static uint32_t kRed = 0xFF6450FF, //255, 100, 80
|
||||
kBlue1 = 0xA0DCFFFF, //160, 220, 255
|
||||
kBlue2 = 0x78BEFFFF, //120, 190, 255
|
||||
kBlue3 = 0x50A0FFFF, //80, 160, 255
|
||||
kBlue4 = 0x1E46B4FF, //30, 70, 180
|
||||
kGray = 0x828282FF, //130, 130, 130
|
||||
kGreen = 0x00FF00FF; //0, 255, 0
|
||||
|
||||
/* 255, 100, 80 */
|
||||
static uint32_t kRed[] =
|
||||
{ 0x963A2FFF, 0xE85B48FF, 0xF7614DFF, 0xEA5C49FF,
|
||||
0xC94F3FFF, 0xC14C3CFF, 0xD85544FF, 0xED5D4AFF,
|
||||
0xFF6450FF, 0xFC634FFF, 0x0000003F, 0x00000015 };
|
||||
|
||||
/* 160, 220, 255 */
|
||||
static uint32_t kBlue1[] =
|
||||
{ 0x5E8196FF, 0x91C8E8FF, 0x9BD5F7FF, 0x93CAEAFF,
|
||||
0x7EADC9FF, 0x79A7C1FF, 0x88BBD8FF, 0x94CCEDFF,
|
||||
0xA0DCFFFF, 0x9ED9FCFF, 0x0000003F, 0x00000015 };
|
||||
|
||||
/* 120, 190, 255 */
|
||||
static uint32_t kBlue2[] =
|
||||
{ 0x467096FF, 0x6DACE8FF, 0x74B8F7FF, 0x6EAEEAFF,
|
||||
0x5E96C9FF, 0x5B90C1FF, 0x66A1D8FF, 0x6FB0EDFF,
|
||||
0x78BEFFFF, 0x76BCFCFF, 0x0000003F, 0x00000015 };
|
||||
|
||||
/* 80, 160, 255 */
|
||||
static uint32_t kBlue3[] =
|
||||
{ 0x2F5E96FF, 0x4891E8FF, 0x4D9BF7FF, 0x4993EAFF,
|
||||
0x3F7EC9FF, 0x3C79C1FF, 0x4488D8FF, 0x4A94EDFF,
|
||||
0x50A0FFFF, 0x4F9EFCFF, 0x0000003F, 0x00000015 };
|
||||
|
||||
/* 30, 70, 180 */
|
||||
static uint32_t kBlue4[] =
|
||||
{ 0x11296AFF, 0x1B3FA3FF, 0x1D43AEFF, 0x1B40A5FF,
|
||||
0x17378EFF, 0x163588FF, 0x193B99FF, 0x1B41A7FF,
|
||||
0x1E46B4FF, 0x1D45B2FF, 0x0000003F, 0x00000015 };
|
||||
|
||||
/* 130, 130, 130 */
|
||||
static uint32_t kGray[] =
|
||||
{ 0x4C4C4CFF, 0x767676FF, 0x7E7E7EFF, 0x777777FF,
|
||||
0x666666FF, 0x626262FF, 0x6E6E6EFF, 0x787878FF,
|
||||
0x828282FF, 0x808080FF, 0x0000003F, 0x00000015 };
|
||||
|
||||
/* 0, 255, 0 */
|
||||
static uint32_t kGreen[] =
|
||||
{ 0x009600FF, 0x00E800FF, 0x00F700FF, 0x00EA00FF,
|
||||
0x00C900FF, 0x00C100FF, 0x00D800FF, 0x00ED00FF,
|
||||
0x00FF00FF, 0x00FC00FF, 0x0000003F, 0x00000015 };
|
||||
- (id) init
|
||||
{
|
||||
if ((self = [super init]))
|
||||
{
|
||||
NSSize startSize = NSMakeSize(100.0, BAR_HEIGHT);
|
||||
if (!fProgressWhite)
|
||||
{
|
||||
fProgressWhite = [NSImage imageNamed: @"ProgressBarWhite.png"];
|
||||
[fProgressWhite setScalesWhenResized: YES];
|
||||
[fProgressWhite setSize: startSize];
|
||||
}
|
||||
if (!fProgressBlue)
|
||||
{
|
||||
fProgressBlue = [NSImage imageNamed: @"ProgressBarBlue.png"];
|
||||
[fProgressBlue setScalesWhenResized: YES];
|
||||
[fProgressBlue setSize: startSize];
|
||||
}
|
||||
if (!fProgressGray)
|
||||
{
|
||||
fProgressGray = [NSImage imageNamed: @"ProgressBarGray.png"];
|
||||
[fProgressGray setScalesWhenResized: YES];
|
||||
[fProgressGray setSize: startSize];
|
||||
}
|
||||
if (!fProgressGreen)
|
||||
{
|
||||
fProgressGreen = [NSImage imageNamed: @"ProgressBarGreen.png"];
|
||||
[fProgressGreen setScalesWhenResized: YES];
|
||||
[fProgressGreen setSize: startSize];
|
||||
}
|
||||
if (!fProgressAdvanced)
|
||||
{
|
||||
fProgressAdvanced = [NSImage imageNamed: @"ProgressBarAdvanced.png"];
|
||||
[fProgressAdvanced setScalesWhenResized: YES];
|
||||
[fProgressAdvanced setSize: startSize];
|
||||
}
|
||||
|
||||
if (!fProgressEndWhite)
|
||||
fProgressEndWhite = [NSImage imageNamed: @"ProgressBarEndWhite.png"];
|
||||
if (!fProgressEndBlue)
|
||||
fProgressEndBlue = [NSImage imageNamed: @"ProgressBarEndBlue.png"];
|
||||
if (!fProgressEndGray)
|
||||
fProgressEndGray = [NSImage imageNamed: @"ProgressBarEndGray.png"];
|
||||
if (!fProgressEndGreen)
|
||||
fProgressEndGreen = [NSImage imageNamed: @"ProgressBarEndGreen.png"];
|
||||
if (!fProgressEndAdvanced)
|
||||
fProgressEndAdvanced = [NSImage imageNamed: @"ProgressBarEndAdvanced.png"];
|
||||
}
|
||||
return self;
|
||||
}
|
||||
|
||||
- (void) setTorrent: (Torrent *) torrent
|
||||
{
|
||||
fTorrent = torrent;
|
||||
}
|
||||
|
||||
- (void) buildSimpleBar: (int) width bitmap: (NSBitmapImageRep *) bitmap
|
||||
- (void) placeBar: (NSImage *) barImage width: (float) width point: (NSPoint) point
|
||||
{
|
||||
int h, w, end, pixelsPerRow;
|
||||
uint32_t * p;
|
||||
uint32_t * colors;
|
||||
if ([barImage size].width < width)
|
||||
[barImage setSize: NSMakeSize(width * 1.5, BAR_HEIGHT)];
|
||||
|
||||
pixelsPerRow = [bitmap bytesPerRow] / 4;
|
||||
[barImage compositeToPoint: point fromRect: NSMakeRect(0, 0, width, BAR_HEIGHT)
|
||||
operation: NSCompositeSourceOver];
|
||||
}
|
||||
|
||||
p = (uint32_t *) [bitmap bitmapData] + 1;
|
||||
end = lrintf( floor( [fTorrent progress] * ( width - 2 ) ) );
|
||||
|
||||
if( [fTorrent isSeeding] )
|
||||
colors = kGreen;
|
||||
else if( [fTorrent isActive] )
|
||||
colors = kBlue2;
|
||||
else
|
||||
colors = kGray;
|
||||
|
||||
for( h = 0; h < BAR_HEIGHT; h++ )
|
||||
- (void) buildSimpleBar: (int) width point: (NSPoint) point
|
||||
{
|
||||
width -= 2.0;
|
||||
if ([fTorrent isSeeding])
|
||||
{
|
||||
for( w = 0; w < end; w++ )
|
||||
[fProgressEndGreen compositeToPoint: point operation: NSCompositeSourceOver];
|
||||
|
||||
point.x += 1.0;
|
||||
[self placeBar: fProgressGreen width: width point: point];
|
||||
|
||||
point.x += width;
|
||||
[fProgressEndGreen compositeToPoint: point operation: NSCompositeSourceOver];
|
||||
}
|
||||
else
|
||||
{
|
||||
NSImage * barActiveEnd, * barActive;
|
||||
if ([fTorrent isActive])
|
||||
{
|
||||
p[w] = htonl( colors[h] );
|
||||
barActiveEnd = fProgressEndBlue;
|
||||
barActive = fProgressBlue;
|
||||
}
|
||||
for( w = end; w < width - 2; w++ )
|
||||
else
|
||||
{
|
||||
p[w] = htonl( kBack[h] );
|
||||
barActiveEnd = fProgressEndGray;
|
||||
barActive = fProgressGray;
|
||||
}
|
||||
p += pixelsPerRow;
|
||||
|
||||
float completedWidth = [fTorrent progress] * width,
|
||||
remainingWidth = width - completedWidth;
|
||||
|
||||
if (completedWidth >= 1.0)
|
||||
[barActiveEnd compositeToPoint: point operation: NSCompositeSourceOver];
|
||||
else
|
||||
[fProgressEndWhite compositeToPoint: point operation: NSCompositeSourceOver];
|
||||
|
||||
point.x += 1.0;
|
||||
[self placeBar: barActive width: completedWidth point: point];
|
||||
|
||||
point.x += completedWidth;
|
||||
[self placeBar: fProgressWhite width: remainingWidth point: point];
|
||||
|
||||
point.x += remainingWidth;
|
||||
[fProgressEndWhite compositeToPoint: point operation: NSCompositeSourceOver];
|
||||
}
|
||||
}
|
||||
|
||||
- (void) buildAdvancedBar: (int) width bitmap: (NSBitmapImageRep *) bitmap
|
||||
- (void) buildAdvancedBar: (int) width point: (NSPoint) point
|
||||
{
|
||||
int h, w, end, pixelsPerRow;
|
||||
uint32_t * p, * colors;
|
||||
uint8_t * bitmapData = [bitmap bitmapData];
|
||||
int bytesPerRow = [bitmap bytesPerRow];
|
||||
//if seeding, there's no need for the advanced bar
|
||||
if ([fTorrent isSeeding])
|
||||
{
|
||||
[self buildSimpleBar: width point: point];
|
||||
return;
|
||||
}
|
||||
|
||||
NSBitmapImageRep * bitmap = [[NSBitmapImageRep alloc]
|
||||
initWithBitmapDataPlanes: nil pixelsWide: width
|
||||
pixelsHigh: BAR_HEIGHT bitsPerSample: 8 samplesPerPixel: 4
|
||||
hasAlpha: YES isPlanar: NO colorSpaceName:
|
||||
NSCalibratedRGBColorSpace bytesPerRow: 0 bitsPerPixel: 0];
|
||||
|
||||
int h, w;
|
||||
uint32_t * p;
|
||||
uint8_t * bitmapData = [bitmap bitmapData];
|
||||
int bytesPerRow = [bitmap bytesPerRow];
|
||||
|
||||
/* Left and right borders */
|
||||
p = (uint32_t *) bitmapData;
|
||||
for( h = 0; h < BAR_HEIGHT; h++ )
|
||||
{
|
||||
p[0] = htonl( kBorder[h] );
|
||||
p[width - 1] = htonl( kBorder[h] );
|
||||
p += bytesPerRow / 4;
|
||||
}
|
||||
|
||||
int8_t * pieces = malloc( width );
|
||||
[fTorrent getAvailability: pieces size: width];
|
||||
|
||||
if( [fTorrent isSeeding] )
|
||||
{
|
||||
/* All green, same as the simple bar */
|
||||
[self buildSimpleBar: width bitmap: bitmap];
|
||||
return;
|
||||
}
|
||||
|
||||
pixelsPerRow = bytesPerRow / 4;
|
||||
|
||||
/* First two lines: dark blue to show progression */
|
||||
end = lrintf( floor( [fTorrent progress] * ( width - 2 ) ) );
|
||||
int end = lrintf( floor( [fTorrent progress] * ( width - 2 ) ) );
|
||||
for( h = 0; h < 2; h++ )
|
||||
{
|
||||
p = (uint32_t *) ( bitmapData + h * bytesPerRow ) + 1;
|
||||
for( w = 0; w < end; w++ )
|
||||
{
|
||||
p[w] = htonl( kBlue4[h] );
|
||||
}
|
||||
p[w] = htonl( kBlue4 );
|
||||
for( w = end; w < width - 2; w++ )
|
||||
{
|
||||
p[w] = htonl( kBack[h] );
|
||||
}
|
||||
}
|
||||
|
||||
/* Lines 2 to 14: blue or grey depending on whether
|
||||
we have the piece or not */
|
||||
uint32_t color;
|
||||
for( w = 0; w < width - 2; w++ )
|
||||
{
|
||||
/* Point to pixel ( 2 + w, 2 ). We will then draw
|
||||
"vertically" */
|
||||
p = (uint32_t *) ( bitmapData + 2 * bytesPerRow ) + 1 + w;
|
||||
p = (uint32_t *) ( bitmapData + 2 * bytesPerRow ) + 1 + w;
|
||||
|
||||
if( pieces[w] < 0 )
|
||||
{
|
||||
colors = kGray;
|
||||
}
|
||||
else if( pieces[w] < 1 )
|
||||
{
|
||||
colors = kRed;
|
||||
}
|
||||
else if( pieces[w] < 2 )
|
||||
{
|
||||
colors = kBlue1;
|
||||
}
|
||||
else if( pieces[w] < 3 )
|
||||
{
|
||||
colors = kBlue2;
|
||||
}
|
||||
if (pieces[w] < 0)
|
||||
color = kGray;
|
||||
else if (pieces[w] == 0)
|
||||
color = kRed;
|
||||
else if (pieces[w] == 1)
|
||||
color = kBlue1;
|
||||
else if (pieces[w] == 2)
|
||||
color = kBlue2;
|
||||
else
|
||||
{
|
||||
colors = kBlue3;
|
||||
}
|
||||
color = kBlue3;
|
||||
|
||||
for( h = 2; h < BAR_HEIGHT; h++ )
|
||||
{
|
||||
p[0] = htonl( colors[h] );
|
||||
p = (uint32_t *) ( (uint8_t *) p + bytesPerRow );
|
||||
p[0] = htonl( color );
|
||||
p = (uint32_t *) ( (uint8_t *) p + bytesPerRow );
|
||||
}
|
||||
}
|
||||
|
||||
free( pieces );
|
||||
}
|
||||
|
||||
- (void) buildBarWithWidth: (int) width bitmap: (NSBitmapImageRep *) bitmap
|
||||
{
|
||||
int h;
|
||||
uint32_t * p;
|
||||
|
||||
/* Left and right borders */
|
||||
p = (uint32_t *) [bitmap bitmapData];
|
||||
for( h = 0; h < BAR_HEIGHT; h++ )
|
||||
{
|
||||
p[0] = htonl( kBorder[h] );
|
||||
p[width - 1] = htonl( kBorder[h] );
|
||||
p += [bitmap bytesPerRow] / 4;
|
||||
}
|
||||
|
||||
/* ...and redraw the progress bar on the top of it */
|
||||
if ([[NSUserDefaults standardUserDefaults] boolForKey: @"UseAdvancedBar"])
|
||||
[self buildAdvancedBar: width bitmap: bitmap];
|
||||
else
|
||||
[self buildSimpleBar: width bitmap: bitmap];
|
||||
|
||||
//actually draw image
|
||||
NSImage * img = [[NSImage alloc] initWithSize: [bitmap size]];
|
||||
[img addRepresentation: bitmap];
|
||||
[img compositeToPoint: point operation: NSCompositeSourceOver];
|
||||
[img release];
|
||||
[bitmap release];
|
||||
|
||||
//draw overlay over advanced bar
|
||||
[self placeBar: fProgressAdvanced width: width point: point];
|
||||
}
|
||||
|
||||
- (void) drawWithFrame: (NSRect) cellFrame inView: (NSView *) view
|
||||
|
@ -245,9 +273,8 @@ static uint32_t kGreen[] =
|
|||
pen.x += padding;
|
||||
pen.y += (cellFrame.size.height - iconSize.height) * 0.5;
|
||||
|
||||
[icon drawAtPoint: pen fromRect:
|
||||
NSMakeRect( 0, 0, iconSize.width, iconSize.height )
|
||||
operation: NSCompositeSourceOver fraction: 1.0];
|
||||
[icon drawAtPoint: pen fromRect: NSMakeRect( 0, 0, iconSize.width, iconSize.height )
|
||||
operation: NSCompositeSourceOver fraction: 1.0];
|
||||
|
||||
float extraNameShift = 1.0,
|
||||
mainWidth = cellFrame.size.width - iconSize.width - 3.0 * padding - extraNameShift;
|
||||
|
@ -268,30 +295,18 @@ static uint32_t kGreen[] =
|
|||
|
||||
//progress bar
|
||||
pen.x -= extraNameShift;
|
||||
pen.y += [progressString size].height + linePadding;
|
||||
pen.y += [progressString size].height + linePadding + BAR_HEIGHT;
|
||||
|
||||
float barWidth = mainWidth + extraNameShift - BUTTONS_TOTAL_WIDTH + padding;
|
||||
|
||||
NSBitmapImageRep * bitmap = [[NSBitmapImageRep alloc]
|
||||
initWithBitmapDataPlanes: nil pixelsWide: barWidth
|
||||
pixelsHigh: BAR_HEIGHT bitsPerSample: 8 samplesPerPixel: 4
|
||||
hasAlpha: YES isPlanar: NO colorSpaceName:
|
||||
NSCalibratedRGBColorSpace bytesPerRow: 0 bitsPerPixel: 0];
|
||||
NSImage * img = [[NSImage alloc] initWithSize: [bitmap size]];
|
||||
[img addRepresentation: bitmap];
|
||||
[img setFlipped: YES];
|
||||
|
||||
[self buildBarWithWidth: barWidth bitmap: bitmap];
|
||||
|
||||
[img drawAtPoint: pen fromRect: NSMakeRect( 0, 0,
|
||||
[img size].width, [img size].height )
|
||||
operation: NSCompositeSourceOver fraction: 1.0];
|
||||
[img release];
|
||||
[bitmap release];
|
||||
if ([[NSUserDefaults standardUserDefaults] boolForKey: @"UseAdvancedBar"])
|
||||
[self buildAdvancedBar: barWidth point: pen];
|
||||
else
|
||||
[self buildSimpleBar: barWidth point: pen];
|
||||
|
||||
//status strings
|
||||
pen.x += extraNameShift;
|
||||
pen.y += BAR_HEIGHT + linePadding;
|
||||
pen.y += linePadding;
|
||||
NSAttributedString * statusString = [[fTorrent statusString]
|
||||
attributedStringFittingInWidth: mainWidth attributes: statusAttributes];
|
||||
[statusString drawAtPoint: pen];
|
||||
|
|