1 #import "ITChasingArrowsView.h"
4 @implementation ITChasingArrowsView
6 - (id)initWithCoder:(NSCoder *)decoder
8 self = [super initWithCoder:decoder];
12 images = [[decoder decodeObject] retain];
20 - (void)encodeWithCoder:(NSCoder *)coder
22 [super encodeWithCoder:coder];
24 [coder encodeObject:images];
27 - (id)initWithFrame:(NSRect)frame {
28 self = [super initWithFrame:frame];
30 NSBundle *bund = [NSBundle bundleForClass:[self class]];
32 images = [[NSArray alloc] initWithObjects:
33 [[[NSImage alloc] initWithContentsOfFile:[bund pathForImageResource:@"ITChasingArrow1.tiff"]] autorelease],
34 [[[NSImage alloc] initWithContentsOfFile:[bund pathForImageResource:@"ITChasingArrow2.tiff"]] autorelease],
35 [[[NSImage alloc] initWithContentsOfFile:[bund pathForImageResource:@"ITChasingArrow3.tiff"]] autorelease],
36 [[[NSImage alloc] initWithContentsOfFile:[bund pathForImageResource:@"ITChasingArrow4.tiff"]] autorelease],
37 [[[NSImage alloc] initWithContentsOfFile:[bund pathForImageResource:@"ITChasingArrow5.tiff"]] autorelease],
38 [[[NSImage alloc] initWithContentsOfFile:[bund pathForImageResource:@"ITChasingArrow6.tiff"]] autorelease],
39 [[[NSImage alloc] initWithContentsOfFile:[bund pathForImageResource:@"ITChasingArrow7.tiff"]] autorelease],
40 [[[NSImage alloc] initWithContentsOfFile:[bund pathForImageResource:@"ITChasingArrow8.tiff"]] autorelease],
41 [[[NSImage alloc] initWithContentsOfFile:[bund pathForImageResource:@"ITChasingArrow9.tiff"]] autorelease],
42 [[[NSImage alloc] initWithContentsOfFile:[bund pathForImageResource:@"ITChasingArrow10.tiff"]] autorelease],
63 - (void)drawRect:(NSRect)rect {
67 NSImage *curImage = [images objectAtIndex:curIndex];
77 [curImage compositeToPoint:NSMakePoint(0,0) operation:NSCompositeSourceOver fraction:amt];
85 - (IBAction)stop:(id)sender
91 NSNotificationCenter *nc = [NSNotificationCenter defaultCenter];
92 [nc removeObserver:self];
98 [self setNeedsDisplay:YES];
101 - (IBAction)start:(id)sender
105 NSNotificationCenter *nc = [NSNotificationCenter defaultCenter];
106 [nc addObserver:self selector:@selector(appWentToBackground:) name:NSApplicationWillResignActiveNotification object:nil];
107 [nc addObserver:self selector:@selector(appWentToForeground:) name:NSApplicationWillBecomeActiveNotification object:nil];
108 [nc addObserver:self selector:@selector(windowWentToBackground:) name:NSWindowDidResignMainNotification object:nil];
109 [nc addObserver:self selector:@selector(windowWentToForeground:) name:NSWindowDidBecomeMainNotification object:nil];
110 inForeground = ([NSApp isActive] && [[self window] isMainWindow]);
113 timer = [[NSTimer scheduledTimerWithTimeInterval:0.05
115 selector:@selector(showNewImage:)
117 repeats:YES] retain];
118 [[NSRunLoop currentRunLoop] addTimer:timer forMode:NSEventTrackingRunLoopMode];
122 - (void)showNewImage:(NSTimer *)t
124 [self setNeedsDisplay:YES];
136 - (void)appWentToBackground:(NSNotification *)note
141 - (void)appWentToForeground:(NSNotification *)note
146 - (void)windowWentToBackground:(NSNotification *)note
148 NSWindow *window = [note object];
149 if (window == [self window])
155 - (void)windowWentToForeground:(NSNotification *)note
157 NSWindow *window = [note object];
158 if (window == [self window])