28
28
#import "NSApplicationAdditions.h"
29
29
#import "NSStringAdditions.h"
30
30
#import "NSBezierPathAdditions.h"
31
#import "CTGradientAdditions.h"
33
#define BAR_HEIGHT 12.0
35
#define IMAGE_SIZE_REG 32.0
36
#define IMAGE_SIZE_MIN 16.0
38
#define NORMAL_BUTTON_WIDTH 14.0
39
#define ACTION_BUTTON_WIDTH 16.0
31
#import "ProgressGradients.h"
32
#import "CTGradient.h"
34
#define BAR_HEIGHT 12.0f
36
#define IMAGE_SIZE_REG 32.0f
37
#define IMAGE_SIZE_MIN 16.0f
39
#define NORMAL_BUTTON_WIDTH 14.0f
40
#define ACTION_BUTTON_WIDTH 16.0f
41
42
//ends up being larger than font height
42
#define HEIGHT_TITLE 16.0
43
#define HEIGHT_STATUS 12.0
45
#define PADDING_HORIZONTAL 3.0
46
#define PADDING_BETWEEN_IMAGE_AND_TITLE 5.0
47
#define PADDING_BETWEEN_IMAGE_AND_BAR 7.0
48
#define PADDING_ABOVE_TITLE 4.0
49
#define PADDING_ABOVE_MIN_STATUS 4.0
50
#define PADDING_BETWEEN_TITLE_AND_MIN_STATUS 2.0
51
#define PADDING_BETWEEN_TITLE_AND_PROGRESS 1.0
52
#define PADDING_BETWEEN_PROGRESS_AND_BAR 2.0
53
#define PADDING_BETWEEN_TITLE_AND_BAR_MIN 3.0
54
#define PADDING_BETWEEN_BAR_AND_STATUS 2.0
56
#define PIECES_TOTAL_PERCENT 0.6
43
#define HEIGHT_TITLE 16.0f
44
#define HEIGHT_STATUS 12.0f
46
#define PADDING_HORIZONTAL 3.0f
47
#define PADDING_BETWEEN_IMAGE_AND_TITLE 5.0f
48
#define PADDING_BETWEEN_IMAGE_AND_BAR 7.0f
49
#define PADDING_ABOVE_TITLE 4.0f
50
#define PADDING_ABOVE_MIN_STATUS 4.0f
51
#define PADDING_BETWEEN_TITLE_AND_MIN_STATUS 2.0f
52
#define PADDING_BETWEEN_TITLE_AND_PROGRESS 1.0f
53
#define PADDING_BETWEEN_PROGRESS_AND_BAR 2.0f
54
#define PADDING_BETWEEN_TITLE_AND_BAR_MIN 3.0f
55
#define PADDING_BETWEEN_BAR_AND_STATUS 2.0f
57
#define PIECES_TOTAL_PERCENT 0.6f
58
59
#define MAX_PIECES (18*18)
91
92
[paragraphStyle setLineBreakMode: NSLineBreakByTruncatingTail];
93
94
fTitleAttributes = [[NSMutableDictionary alloc] initWithObjectsAndKeys:
94
[NSFont messageFontOfSize: 12.0], NSFontAttributeName,
95
[NSFont messageFontOfSize: 12.0f], NSFontAttributeName,
95
96
paragraphStyle, NSParagraphStyleAttributeName, nil];
96
97
fStatusAttributes = [[NSMutableDictionary alloc] initWithObjectsAndKeys:
97
[NSFont messageFontOfSize: 9.0], NSFontAttributeName,
98
[NSFont messageFontOfSize: 9.0f], NSFontAttributeName,
98
99
paragraphStyle, NSParagraphStyleAttributeName, nil];
99
100
[paragraphStyle release];
101
fBluePieceColor = [[NSColor colorWithCalibratedRed: 0.0 green: 0.4 blue: 0.8 alpha: 1.0] retain];
102
fBarBorderColor = [[NSColor colorWithDeviceWhite: 0.0 alpha: 0.2] retain];
102
fBluePieceColor = [[NSColor colorWithCalibratedRed: 0.0f green: 0.4f blue: 0.8f alpha: 1.0f] retain];
103
fBarBorderColor = [[NSColor colorWithDeviceWhite: 0.0f alpha: 0.2f] retain];
107
108
- (NSRect) iconRectForBounds: (NSRect) bounds
109
float imageSize = [fDefaults boolForKey: @"SmallView"] ? IMAGE_SIZE_MIN : IMAGE_SIZE_REG;
110
CGFloat imageSize = [fDefaults boolForKey: @"SmallView"] ? IMAGE_SIZE_MIN : IMAGE_SIZE_REG;
111
112
NSRect result = bounds;
112
113
result.origin.x += PADDING_HORIZONTAL;
113
result.origin.y += floorf((result.size.height - imageSize) * 0.5);
114
result.origin.y += floorf((result.size.height - imageSize) * 0.5f);
114
115
result.size = NSMakeSize(imageSize, imageSize);
172
173
NSRect result = bounds;
173
174
result.size.height = NORMAL_BUTTON_WIDTH;
174
175
result.size.width = NORMAL_BUTTON_WIDTH;
175
result.origin.x = NSMaxX(bounds) - 2.0 * (PADDING_HORIZONTAL + NORMAL_BUTTON_WIDTH);
176
result.origin.x = NSMaxX(bounds) - 2.0f * (PADDING_HORIZONTAL + NORMAL_BUTTON_WIDTH);
177
result.origin.y += PADDING_ABOVE_TITLE + HEIGHT_TITLE - (NORMAL_BUTTON_WIDTH - BAR_HEIGHT) * 0.5;
178
result.origin.y += PADDING_ABOVE_TITLE + HEIGHT_TITLE - (NORMAL_BUTTON_WIDTH - BAR_HEIGHT) * 0.5f;
178
179
if ([fDefaults boolForKey: @"SmallView"])
179
180
result.origin.y += PADDING_BETWEEN_TITLE_AND_BAR_MIN;
190
191
result.size.width = NORMAL_BUTTON_WIDTH;
191
192
result.origin.x = NSMaxX(bounds) - (PADDING_HORIZONTAL + NORMAL_BUTTON_WIDTH);
193
result.origin.y += PADDING_ABOVE_TITLE + HEIGHT_TITLE - (NORMAL_BUTTON_WIDTH - BAR_HEIGHT) * 0.5;
194
result.origin.y += PADDING_ABOVE_TITLE + HEIGHT_TITLE - (NORMAL_BUTTON_WIDTH - BAR_HEIGHT) * 0.5f;
194
195
if ([fDefaults boolForKey: @"SmallView"])
195
196
result.origin.y += PADDING_BETWEEN_TITLE_AND_BAR_MIN;
204
205
NSRect result = [self iconRectForBounds: bounds];
205
206
if (![fDefaults boolForKey: @"SmallView"])
207
result.origin.x += (result.size.width - ACTION_BUTTON_WIDTH) * 0.5;
208
result.origin.y += (result.size.height - ACTION_BUTTON_WIDTH) * 0.5;
208
result.origin.x += (result.size.width - ACTION_BUTTON_WIDTH) * 0.5f;
209
result.origin.y += (result.size.height - ACTION_BUTTON_WIDTH) * 0.5f;
209
210
result.size.width = ACTION_BUTTON_WIDTH;
210
211
result.size.height = ACTION_BUTTON_WIDTH;
384
385
NSRect iconRect = [self iconRectForBounds: cellFrame];
386
int groupValue = [torrent groupValue];
387
NSInteger groupValue = [torrent groupValue];
387
388
if (groupValue != -1)
389
NSRect groupRect = NSInsetRect(iconRect, -1.0, -2.0);
390
NSRect groupRect = NSInsetRect(iconRect, -1.0f, -2.0f);
392
393
groupRect.size.height--;
393
394
groupRect.origin.y--;
395
float radius = minimal ? 3.0 : 6.0;
396
const CGFloat radius = minimal ? 3.0f : 6.0f;
397
398
NSColor * groupColor = [[GroupsController groups] colorForIndex: groupValue],
398
* darkGroupColor = [groupColor blendedColorWithFraction: 0.2 ofColor: [NSColor whiteColor]];
399
* darkGroupColor = [groupColor blendedColorWithFraction: 0.2f ofColor: [NSColor whiteColor]];
401
402
NSBezierPath * bp = [NSBezierPath bezierPathWithRoundedRect: groupRect radius: radius];
402
403
[darkGroupColor set];
403
[bp setLineWidth: 2.0];
404
[bp setLineWidth: 2.0f];
407
408
bp = [NSBezierPath bezierPathWithRoundedRect: groupRect radius: radius];
408
CTGradient * gradient = [CTGradient gradientWithBeginningColor: [groupColor blendedColorWithFraction: 0.7
409
CTGradient * gradient = [CTGradient gradientWithBeginningColor: [groupColor blendedColorWithFraction: 0.7f
409
410
ofColor: [NSColor whiteColor]] endingColor: darkGroupColor];
410
[gradient fillBezierPath: bp angle: 90.0];
411
[gradient fillBezierPath: bp angle: 90.0f];
422
423
if (!minimal || !(!fTracking && fHoverAction)) //don't show in minimal mode when hovered over
424
425
NSImage * icon = (minimal && error) ? fErrorImage : [torrent icon];
425
[icon drawInRect: iconRect fromRect: NSZeroRect operation: NSCompositeSourceOver fraction: 1.0];
426
[icon drawInRect: iconRect fromRect: NSZeroRect operation: NSCompositeSourceOver fraction: 1.0f];
428
429
if (error && !minimal)
430
431
NSRect errorRect = NSMakeRect(NSMaxX(iconRect) - IMAGE_SIZE_MIN, NSMaxY(iconRect) - IMAGE_SIZE_MIN,
431
432
IMAGE_SIZE_MIN, IMAGE_SIZE_MIN);
432
[fErrorImage drawInRect: errorRect fromRect: NSZeroRect operation: NSCompositeSourceOver fraction: 1.0];
433
[fErrorImage drawInRect: errorRect fromRect: NSZeroRect operation: NSCompositeSourceOver fraction: 1.0f];
545
546
- (void) drawBar: (NSRect) barRect
547
float piecesBarPercent = [(TorrentTableView *)[self controlView] piecesBarPercent];
548
if (piecesBarPercent > 0.0)
548
CGFloat piecesBarPercent = [(TorrentTableView *)[self controlView] piecesBarPercent];
549
if (piecesBarPercent > 0.0f)
550
551
NSRect regularBarRect = barRect, piecesBarRect = barRect;
551
552
piecesBarRect.size.height *= PIECES_TOTAL_PERCENT * piecesBarPercent;
565
566
[fBarBorderColor set];
566
[NSBezierPath strokeRect: NSInsetRect(barRect, 0.5, 0.5)];
567
[NSBezierPath strokeRect: NSInsetRect(barRect, 0.5f, 0.5f)];
569
570
- (void) drawRegularBar: (NSRect) barRect
571
572
Torrent * torrent = [self representedObject];
573
int leftWidth = barRect.size.width;
574
float progress = [torrent progress];
574
NSInteger leftWidth = barRect.size.width;
575
CGFloat progress = [torrent progress];
578
float rightProgress = 1.0 - progress, progressLeft = [torrent progressLeft];
579
int rightWidth = leftWidth * rightProgress;
579
CGFloat rightProgress = 1.0f - progress, progressLeft = [torrent progressLeft];
580
NSInteger rightWidth = leftWidth * rightProgress;
580
581
leftWidth -= rightWidth;
582
583
if (progressLeft < rightProgress)
584
int rightNoIncludeWidth = rightWidth * ((rightProgress - progressLeft) / rightProgress);
585
NSInteger rightNoIncludeWidth = rightWidth * ((rightProgress - progressLeft) / rightProgress);
585
586
rightWidth -= rightNoIncludeWidth;
587
588
NSRect noIncludeRect = barRect;
588
589
noIncludeRect.origin.x += barRect.size.width - rightNoIncludeWidth;
589
590
noIncludeRect.size.width = rightNoIncludeWidth;
591
[[CTGradient progressLightGrayGradient] fillRect: noIncludeRect angle: 90];
592
[[ProgressGradients progressLightGrayGradient] fillRect: noIncludeRect angle: 90];
594
595
if (rightWidth > 0)
596
597
if ([torrent isActive] && ![torrent allDownloaded] && ![torrent isChecking]
597
598
&& [fDefaults boolForKey: @"DisplayProgressBarAvailable"])
599
int notAvailableWidth = ceil(rightWidth * [torrent notAvailableDesired]);
600
NSInteger notAvailableWidth = ceil(rightWidth * [torrent notAvailableDesired]);
600
601
if (notAvailableWidth > 0)
602
603
rightWidth -= notAvailableWidth;
628
629
if ([torrent isActive])
630
631
if ([torrent isChecking])
631
[[CTGradient progressYellowGradient] fillRect: completeRect angle: 90];
632
[[ProgressGradients progressYellowGradient] fillRect: completeRect angle: 90];
632
633
else if ([torrent isSeeding])
634
int ratioLeftWidth = leftWidth * (1.0 - [torrent progressStopRatio]);
635
NSInteger ratioLeftWidth = leftWidth * (1.0f - [torrent progressStopRatio]);
635
636
leftWidth -= ratioLeftWidth;
637
638
if (ratioLeftWidth > 0)
640
641
ratioLeftRect.origin.x += leftWidth;
641
642
ratioLeftRect.size.width = ratioLeftWidth;
643
[[CTGradient progressLightGreenGradient] fillRect: ratioLeftRect angle: 90];
644
[[ProgressGradients progressLightGreenGradient] fillRect: ratioLeftRect angle: 90];
646
647
if (leftWidth > 0)
648
649
completeRect.size.width = leftWidth;
650
[[CTGradient progressGreenGradient] fillRect: completeRect angle: 90];
651
[[ProgressGradients progressGreenGradient] fillRect: completeRect angle: 90];
654
[[CTGradient progressBlueGradient] fillRect: completeRect angle: 90];
655
[[ProgressGradients progressBlueGradient] fillRect: completeRect angle: 90];
658
659
if ([torrent waitingToStart])
660
if ([torrent progressLeft] <= 0.0)
661
[[CTGradient progressDarkGreenGradient] fillRect: completeRect angle: 90];
661
if ([torrent progressLeft] <= 0.0f)
662
[[ProgressGradients progressDarkGreenGradient] fillRect: completeRect angle: 90];
663
[[CTGradient progressDarkBlueGradient] fillRect: completeRect angle: 90];
664
[[ProgressGradients progressDarkBlueGradient] fillRect: completeRect angle: 90];
666
[[CTGradient progressGrayGradient] fillRect: completeRect angle: 90];
667
[[ProgressGradients progressGrayGradient] fillRect: completeRect angle: 90];
673
674
Torrent * torrent = [self representedObject];
675
int pieceCount = MIN([torrent pieceCount], MAX_PIECES);
676
NSInteger pieceCount = MIN([torrent pieceCount], MAX_PIECES);
676
677
float * piecesPercent = malloc(pieceCount * sizeof(float));
677
678
[torrent getAmountFinished: piecesPercent size: pieceCount];
683
684
NSIndexSet * previousFinishedIndexes = [torrent previousFinishedPieces];
684
685
NSMutableIndexSet * finishedIndexes = [NSMutableIndexSet indexSet];
687
for (i = 0; i < pieceCount; i++)
687
for (NSInteger i = 0; i < pieceCount; i++)
689
689
NSColor * pieceColor;
690
if (piecesPercent[i] == 1.0)
690
if (piecesPercent[i] == 1.0f)
692
692
if (previousFinishedIndexes && ![previousFinishedIndexes containsIndex: i])
693
693
pieceColor = [NSColor orangeColor];