1 /* ----====----====----====----====----====----====----====----====----====----
2 MyTimerView.m (jeweltoy)
4 JewelToy is a simple game played against the clock.
5 Copyright (C) 2001 Giles Williams
7 This program is free software; you can redistribute it and/or
8 modify it under the terms of the GNU General Public License
9 as published by the Free Software Foundation; either version 2
10 of the License, or (at your option) any later version.
12 This program is distributed in the hope that it will be useful,
13 but WITHOUT ANY WARRANTY; without even the implied warranty of
14 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 GNU General Public License for more details.
17 You should have received a copy of the GNU General Public License
18 along with this program; if not, write to the Free Software
19 Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
20 ----====----====----====----====----====----====----====----====----====---- */
24 @implementation TimerView
26 @synthesize meter = _meter;
28 - (id)initWithFrame:(NSRect)frame {
29 [super initWithFrame:frame];
32 color1 = [[NSColor redColor] retain];
33 color2 = [[NSColor yellowColor] retain];
34 colorOK = [[NSColor greenColor] retain];
35 backColor = [[NSColor blackColor] retain];
41 // dealloc is the method called when objects are being freed. (Note that "release"
42 // is called to release objects; when the number of release calls reduce the
43 // total reference count on an object to zero, dealloc is called to free
44 // the object. dealloc should free any memory allocated by the subclass
45 // and then call super to get the superclass to do additional cleanup.
55 - (void)drawRect:(NSRect)rect
62 NSRectFill([self bounds]); // Equiv to [[NSBezierPath bezierPathWithRect:[self bounds]] fill]
66 dotRect.size.width = _meter * ([self bounds].size.width - 8);
67 dotRect.size.height = [self bounds].size.height - 8;
71 // another MW change...
74 // TODO: reverse and add else?
75 if (_meter < 0.3) [color2 set];
76 if (_meter < 0.1) [color1 set];
79 NSRectFill(dotRect); // Equiv to [[NSBezierPath bezierPathWithRect:dotRect] fill]
87 - (void) setPaused:(BOOL) value
92 - (void) incrementMeter:(float) value
95 if (_meter > 1) _meter = 1;
96 [self setNeedsDisplay:YES];
99 - (void) setDecrement:(float) value
104 - (void) decrementMeter:(float) value
111 [self setNeedsDisplay:YES];
114 - (void) setTimerRunningEvery:(NSTimeInterval) timeInterval
115 decrement:(float) value
117 whenRunOut:(SEL) runOutSel
118 whenRunOver:(SEL) runOverSel
122 runOutSelector = runOutSel;
123 runOverSelector = runOverSel;
128 timer = [NSTimer scheduledTimerWithTimeInterval:timeInterval
130 selector:@selector(runTimer)
143 [target performSelector:runOverSelector];
146 [self decrementMeter:decrement];
147 if (_meter == 0 && decrement!=0) // MW change added '&& decrement'
150 [target performSelector:runOutSelector];
156 - (void) setTimer:(float)value
161 [self setNeedsDisplay:YES];