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 ----====----====----====----====----====----====----====----====----====---- */
22 /* kokomonds is a fork of JewelToy.
23 * repository: http://github.com/exterlulz/kokomonds
30 @implementation TimerView
32 - (id)initWithFrame:(NSRect)frame
34 self = [super initWithFrame:frame];
38 // TODO: replace color1 with [NSColor redColor], same thing for the rest...
39 _color1 = [[NSColor redColor] retain];
40 _color2 = [[NSColor yellowColor] retain];
41 _colorOK = [[NSColor greenColor] retain];
42 _backColor = [[NSColor blackColor] retain];
67 // drawRect: should be overridden in subclassers of NSView to do necessary
68 // drawing in order to recreate the the look of the view. It will be called
69 // to draw the whole view or parts of it (pay attention the rect argument);
71 - (void)drawRect:(NSRect)rect
78 NSRectFill([self bounds]); // Equiv to [[NSBezierPath bezierPathWithRect:[self bounds]] fill]
82 dotRect.size.width = _meter * ([self bounds].size.width - 8);
83 dotRect.size.height = [self bounds].size.height - 8;
87 // another MW change...
88 if (_decrement != 0) {
89 // TODO: refactor, inverse the ifs and replace if<0.3 with else if"
90 if (_meter < 0.3) [_color2 set];
91 if (_meter < 0.1) [_color1 set];
94 NSRectFill(dotRect); // Equiv to [[NSBezierPath bezierPathWithRect:dotRect] fill]
101 - (void)setPaused:(BOOL)value {
105 - (void)incrementMeter:(float)value
112 [self setNeedsDisplay:YES];
116 - (void)setDecrement:(float)decrement {
117 _decrement = decrement;
120 - (void)decrementMeter:(float)value
127 [self setNeedsDisplay:YES];
130 - (void)setTimerRunningEvery:(NSTimeInterval)timeInterval
131 decrement:(float)value
132 withTarget:(id)target
133 whenRunOut:(SEL)runOutSelector
134 whenRunOver:(SEL)runOverSelector
138 _runOutSelector = runOutSelector;
139 _runOverSelector = runOverSelector;
144 _timer = [NSTimer scheduledTimerWithTimeInterval:timeInterval
146 selector:@selector(runTimer)
157 [_target performSelector:_runOverSelector];
161 [self decrementMeter:_decrement];
163 // MW change added '&& decrement'
164 if (_meter == 0 && _decrement != 0) {
166 [_target performSelector:_runOutSelector];
172 - (void)setTimer:(float)value
177 [self setNeedsDisplay:YES];