]> Dogcows Code - chaz/thecheat/blob - FadeView.m
The Cheat 1.2.1
[chaz/thecheat] / FadeView.m
1
2 // **********************************************************************
3 // The Cheat - A universal game cheater for Mac OS X
4 // (C) 2003-2005 Chaz McGarvey (BrokenZipper)
5 //
6 // This program is free software; you can redistribute it and/or modify
7 // it under the terms of the GNU General Public License as published by
8 // the Free Software Foundation; either version 1, or (at your option)
9 // any later version.
10 //
11 // This program is distributed in the hope that it will be useful,
12 // but WITHOUT ANY WARRANTY; without even the implied warranty of
13 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 // GNU General Public License for more details.
15 //
16 // You should have received a copy of the GNU General Public License
17 // along with this program; if not, write to the Free Software
18 // Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
19 //
20
21
22 #import "FadeView.h"
23
24
25 @interface FadeView ( PrivateAPI )
26
27 - (void)_fadeTimer:(NSTimer *)timer;
28
29 @end
30
31
32 @implementation FadeView
33
34
35 - (id)init
36 {
37 if ( self = [super init] ) {
38 [self setFadeDuration:1.0];
39 [self setFadeInterval:5.0/60.0];
40 }
41 return self;
42 }
43
44 - (id)initWithFrame:(NSRect)frame
45 {
46 if ( self = [super initWithFrame:frame] ) {
47 [self setFadeDuration:1.0];
48 [self setFadeInterval:5.0/60.0];
49 }
50 return self;
51 }
52
53 - (void)dealloc
54 {
55 [self stopFadeAnimation];
56 [_fadeImage release];
57 [super dealloc];
58 }
59
60
61 - (void)drawRect:(NSRect)rect
62 {
63 [_fadeImage dissolveToPoint:NSMakePoint(0,0) fraction:_fadeAlpha];
64 }
65
66
67 - (NSImage *)image
68 {
69 return _fadeImage;
70 }
71
72 - (NSTimeInterval)fadeDuration
73 {
74 return _fadeDuration;
75 }
76
77 - (NSTimeInterval)fadeInterval
78 {
79 return _fadeInterval;
80 }
81
82 - (double)alpha
83 {
84 return _fadeAlpha;
85 }
86
87
88 - (void)setImage:(NSImage *)image
89 {
90 [image retain];
91 [_fadeImage release];
92 _fadeImage = image;
93 }
94
95 - (void)setFadeDuration:(NSTimeInterval)seconds
96 {
97 if ( seconds != 0.0 ) {
98 _fadeDuration = seconds;
99 }
100 else {
101 _fadeDuration = 1.0;
102 }
103 }
104
105 - (void)setFadeInterval:(NSTimeInterval)seconds
106 {
107 _fadeInterval = seconds;
108 }
109
110 - (void)startFadeAnimation
111 {
112 [self stopFadeAnimation];
113
114 _fadeAlpha = 1.0;
115 [self setNeedsDisplay:YES];
116
117 _fadeTimer = [[NSTimer scheduledTimerWithTimeInterval:_fadeInterval target:self selector:@selector(_fadeTimer:) userInfo:nil repeats:YES] retain];
118 [[NSRunLoop currentRunLoop] addTimer:_fadeTimer forMode:NSEventTrackingRunLoopMode];
119 [[NSRunLoop currentRunLoop] addTimer:_fadeTimer forMode:NSModalPanelRunLoopMode];
120 [self release];
121 }
122
123 - (void)stopFadeAnimation
124 {
125 if ( _fadeTimer ) {
126 [self retain];
127 [_fadeTimer invalidate];
128 [_fadeTimer release];
129 _fadeTimer = nil;
130 }
131 }
132
133 - (void)_fadeTimer:(NSTimer *)timer
134 {
135 _fadeAlpha -= [timer timeInterval] / _fadeDuration;
136 [self setNeedsDisplay:YES];
137
138 if ( _fadeAlpha <= 0.0 ) {
139 [self stopFadeAnimation];
140 if ( [_delegate respondsToSelector:@selector(fadeViewFinishedAnimation:)] ) {
141 [_delegate fadeViewFinishedAnimation:self];
142 }
143 }
144 }
145
146
147 - (id)delegate
148 {
149 return _delegate;
150 }
151
152 - (void)setDelegate:(id)delegate
153 {
154 _delegate = delegate;
155 }
156
157
158 @end
This page took 0.041246 seconds and 5 git commands to generate.