-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathUKDockProgressIndicator.m
142 lines (109 loc) · 3.38 KB
/
UKDockProgressIndicator.m
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
//
// UKDockProgressIndicator.m
// Doublette
// LICENSE: MIT License
//
// Created by Uli Kusterer on 30.04.05.
// Copyright 2005 M. Uli Kusterer. All rights reserved.
//
// -----------------------------------------------------------------------------
// Headers:
// -----------------------------------------------------------------------------
#import "UKDockProgressIndicator.h"
@implementation UKDockProgressIndicator
@synthesize progress;
@synthesize max;
@synthesize min;
@synthesize current;
- (void)dealloc
{
self.progress = nil;
[super dealloc];
}
// -----------------------------------------------------------------------------
// NSProgressIndicator-like methods:
// -----------------------------------------------------------------------------
-(void)setMinValue:(double)mn
{
min = mn;
[progress setMinValue: mn]; // Call through to associated view if user wants us to.
[self updateDockTile];
}
-(double)minValue
{
return min;
}
-(void)setMaxValue:(double)mn
{
max = mn;
[progress setMaxValue: mn]; // Call through to associated view if user wants us to.
[self updateDockTile];
}
-(double)maxValue
{
return max;
}
-(void)setDoubleValue:(double)mn
{
current = mn;
[progress setDoubleValue: mn]; // Call through to associated view if user wants us to.
[self updateDockTile];
}
-(double)doubleValue
{
return current;
}
-(void)setNeedsDisplay:(BOOL)mn
{
[progress setNeedsDisplay: mn]; // Call through to associated view if user wants us to.
}
-(void)display
{
[progress display]; // Call through to associated view if user wants us to.
}
-(void)setHidden:(BOOL)flag
{
[progress setHidden: flag]; // Call through to associated view if user wants us to.
if(flag) // Progress indicator is being hidden? Reset dock tile to regular icon again:
[NSApp setApplicationIconImage: [NSImage imageNamed: @"NSApplicationIcon"]];
}
-(BOOL)isHidden
{
return [progress isHidden];
}
// -----------------------------------------------------------------------------
// updateDockTile:
// Main drawing bottleneck. This takes our min, max and current values and
// draws them onto the dock tile. If the MiniProgressGradient.png image is
// present, this stretches that image to draw the progress bar.
//
// If no image is present this falls back on the knob color.
// -----------------------------------------------------------------------------
-(void)updateDockTile
{
NSImage * dockIcon = [[[NSImage alloc] initWithSize: NSMakeSize(128,128)] autorelease];
[dockIcon lockFocus];
NSRect box = { {4, 4}, {120, 16} };
// App icon:
[[NSImage imageNamed: @"NSApplicationIcon"] dissolveToPoint: NSZeroPoint fraction: 1.0];
// Track & Outline:
[[NSColor whiteColor] set];
[NSBezierPath fillRect: box];
[[NSColor blackColor] set];
[NSBezierPath strokeRect: box];
// State fill:
box = NSInsetRect( box, 1, 1 );
[[NSColor knobColor] set];
box.size.width = (box.size.width / (max -min)) * (current -min);
NSImage * prImg = [NSImage imageNamed: @"MiniProgressGradient"];
NSRect picBox = { { 0,0 }, { 0,0 } };
if(prImg)
{
picBox.size = [prImg size];
[prImg drawInRect: box fromRect: picBox operation: NSCompositeCopy fraction: 1.0];
}
else NSRectFill(box);
[dockIcon unlockFocus];
[NSApp setApplicationIconImage: dockIcon];
}
@end