2 // ITChasingArrowsView.m
5 // Created by Doug Brown on Sat May 11 2002.
6 // Copyright (c) 2002 iThink Software. All rights reserved.
9 #import "ITChasingArrowsView.h"
12 @implementation ITChasingArrowsView
14 - (id)initWithCoder:(NSCoder *)decoder
16 self = [super initWithCoder:decoder];
20 images = [[decoder decodeObject] retain];
28 - (void)encodeWithCoder:(NSCoder *)coder
30 [super encodeWithCoder:coder];
32 [coder encodeObject:images];
35 - (id)initWithFrame:(NSRect)frame {
36 self = [super initWithFrame:frame];
38 NSBundle *bund = [NSBundle bundleForClass:[self class]];
40 images = [[NSArray alloc] initWithObjects:
41 [[[NSImage alloc] initWithContentsOfFile:[bund pathForImageResource:@"ITChasingArrow1.tiff"]] autorelease],
42 [[[NSImage alloc] initWithContentsOfFile:[bund pathForImageResource:@"ITChasingArrow2.tiff"]] autorelease],
43 [[[NSImage alloc] initWithContentsOfFile:[bund pathForImageResource:@"ITChasingArrow3.tiff"]] autorelease],
44 [[[NSImage alloc] initWithContentsOfFile:[bund pathForImageResource:@"ITChasingArrow4.tiff"]] autorelease],
45 [[[NSImage alloc] initWithContentsOfFile:[bund pathForImageResource:@"ITChasingArrow5.tiff"]] autorelease],
46 [[[NSImage alloc] initWithContentsOfFile:[bund pathForImageResource:@"ITChasingArrow6.tiff"]] autorelease],
47 [[[NSImage alloc] initWithContentsOfFile:[bund pathForImageResource:@"ITChasingArrow7.tiff"]] autorelease],
48 [[[NSImage alloc] initWithContentsOfFile:[bund pathForImageResource:@"ITChasingArrow8.tiff"]] autorelease],
49 [[[NSImage alloc] initWithContentsOfFile:[bund pathForImageResource:@"ITChasingArrow9.tiff"]] autorelease],
50 [[[NSImage alloc] initWithContentsOfFile:[bund pathForImageResource:@"ITChasingArrow10.tiff"]] autorelease],
71 - (void)drawRect:(NSRect)rect {
75 NSImage *curImage = [images objectAtIndex:curIndex];
85 [curImage compositeToPoint:NSMakePoint(0,0) operation:NSCompositeSourceOver fraction:amt];
93 - (IBAction)stop:(id)sender
99 NSNotificationCenter *nc = [NSNotificationCenter defaultCenter];
100 [nc removeObserver:self];
106 [self setNeedsDisplay:YES];
109 - (IBAction)start:(id)sender
113 NSNotificationCenter *nc = [NSNotificationCenter defaultCenter];
114 [nc addObserver:self selector:@selector(appWentToBackground:) name:NSApplicationWillResignActiveNotification object:nil];
115 [nc addObserver:self selector:@selector(appWentToForeground:) name:NSApplicationWillBecomeActiveNotification object:nil];
116 [nc addObserver:self selector:@selector(windowWentToBackground:) name:NSWindowDidResignMainNotification object:nil];
117 [nc addObserver:self selector:@selector(windowWentToForeground:) name:NSWindowDidBecomeMainNotification object:nil];
118 inForeground = ([NSApp isActive] && [[self window] isMainWindow]);
121 timer = [[NSTimer scheduledTimerWithTimeInterval:0.05
123 selector:@selector(showNewImage:)
125 repeats:YES] retain];
126 [[NSRunLoop currentRunLoop] addTimer:timer forMode:NSEventTrackingRunLoopMode];
130 - (void)showNewImage:(NSTimer *)t
132 [self setNeedsDisplay:YES];
144 - (void)appWentToBackground:(NSNotification *)note
149 - (void)appWentToForeground:(NSNotification *)note
154 - (void)windowWentToBackground:(NSNotification *)note
156 NSWindow *window = [note object];
157 if (window == [self window])
163 - (void)windowWentToForeground:(NSNotification *)note
165 NSWindow *window = [note object];
166 if (window == [self window])