Skip to content
This repository
Newer
Older
100644 88 lines (68 sloc) 2.036 kb
4000c2ed »
2010-04-17 Beta 3!
1 //
2 // IGKBackgroundProgressBar.m
3 // Ingredients
4 //
5 // Created by Alex Gordon on 17/04/2010.
f1097128 »
2010-07-03 Adjusted things
6 // Written in 2010 by Fileability.
4000c2ed »
2010-04-17 Beta 3!
7 //
8
9 #import "IGKBackgroundProgressBar.h"
10
11 //The number of pixels we phase every second
12 const CGFloat pixelsPerSecond = 60.0;
13 const CGFloat framesPerSecond = 30.0;
14
15 @implementation IGKBackgroundProgressBar
16
17 - (id)initWithFrame:(NSRect)frameRect
18 {
19 if (self = [super initWithFrame:frameRect])
20 {
21 shouldStop = YES;
22 }
23
24 return self;
25 }
26
27 - (BOOL)isFlipped
28 {
29 return YES;
30 }
31
32 - (void)drawRect:(NSRect)dirtyRect
33 {
34 if (shouldStop)
35 return;
36
37 NSRect rect = [self bounds];
38
39 NSBezierPath *bp = [NSBezierPath bezierPath];
40 NSInteger numX = ceil(rect.size.width / 25.0);
41
42 CGFloat bandWidth = 20;
43
44 CGFloat h = 0.0;
45
46 CGFloat modPhase = round(fmod(phase, rect.size.width));
47 CGFloat lastX = -27 + modPhase - rect.size.width;
48
49 NSInteger i;
50 for (i = -numX; i < numX; i++)
51 {
52 [bp moveToPoint:NSMakePoint(lastX +0.5, rect.size.height+0.5 - h)];
53 [bp lineToPoint:NSMakePoint(lastX + bandWidth+0.5, 0+0.5 + h)];
54 [bp lineToPoint:NSMakePoint(lastX + bandWidth + bandWidth+0.5, 0+0.5 + h)];
55 [bp lineToPoint:NSMakePoint(lastX + bandWidth+0.5, rect.size.height+0.5 - h)];
56 [bp lineToPoint:NSMakePoint(lastX+0.5, rect.size.height+0.5 - h)];
57
58 lastX += bandWidth * 2 - 1;
59 }
60
61 [[NSColor colorWithCalibratedWhite:0.0 alpha:0.06] set];
62 [bp fill];
63 }
64
65 //FIXME: It would be more reliable to use an NSTimer here
66 - (void)doAnimation
67 {
68 if (shouldStop)
69 return;
70
71 phase += pixelsPerSecond / framesPerSecond;
72
a36ea6ab »
2010-04-18 Now lets you search inside files and will cut your hair
73 [self display];
4000c2ed »
2010-04-17 Beta 3!
74 [self performSelector:@selector(doAnimation) withObject:nil afterDelay:1.0 / framesPerSecond];
75 }
76 - (IBAction)startAnimation:(id)sender
77 {
78 shouldStop = NO;
79 [self performSelector:@selector(doAnimation) withObject:nil afterDelay:1.0 / framesPerSecond];
80 }
81 - (IBAction)stopAnimation:(id)sender
82 {
83 shouldStop = YES;
a36ea6ab »
2010-04-18 Now lets you search inside files and will cut your hair
84 [self display]; //-display instead of -setNeedsDisplay: because the main thread may be blocked immediately after this call, so the drawing has to be done *now*
4000c2ed »
2010-04-17 Beta 3!
85 }
86
87 @end
Something went wrong with that request. Please try again.