]> Dogcows Code - chaz/thecheat/blob - FadeView.m
update contact information and project URL
[chaz/thecheat] / FadeView.m
1
2 /*
3 * The Cheat - The legendary universal game trainer for Mac OS X.
4 * http://www.brokenzipper.com/trac/wiki/TheCheat
5 *
6 * Copyright (c) 2003-2011, Charles McGarvey et al.
7 *
8 * Distributable under the terms and conditions of the 2-clause BSD
9 * license; see the file COPYING for the legal text of the license.
10 */
11
12
13 #import "FadeView.h"
14
15
16 @interface FadeView ( PrivateAPI )
17
18 - (void)_fadeTimer:(NSTimer *)timer;
19
20 @end
21
22
23 @implementation FadeView
24
25
26 - (id)init
27 {
28 if ( self = [super init] ) {
29 [self setFadeDuration:1.0];
30 [self setFadeInterval:5.0/60.0];
31 }
32 return self;
33 }
34
35 - (id)initWithFrame:(NSRect)frame
36 {
37 if ( self = [super initWithFrame:frame] ) {
38 [self setFadeDuration:1.0];
39 [self setFadeInterval:5.0/60.0];
40 }
41 return self;
42 }
43
44 - (void)dealloc
45 {
46 [self stopFadeAnimation];
47 [_fadeImage release];
48 [super dealloc];
49 }
50
51
52 - (void)drawRect:(NSRect)rect
53 {
54 [_fadeImage dissolveToPoint:NSMakePoint(0,0) fraction:_fadeAlpha];
55 }
56
57
58 - (NSImage *)image
59 {
60 return _fadeImage;
61 }
62
63 - (NSTimeInterval)fadeDuration
64 {
65 return _fadeDuration;
66 }
67
68 - (NSTimeInterval)fadeInterval
69 {
70 return _fadeInterval;
71 }
72
73 - (double)alpha
74 {
75 return _fadeAlpha;
76 }
77
78
79 - (void)setImage:(NSImage *)image
80 {
81 [image retain];
82 [_fadeImage release];
83 _fadeImage = image;
84 }
85
86 - (void)setFadeDuration:(NSTimeInterval)seconds
87 {
88 if ( seconds != 0.0 ) {
89 _fadeDuration = seconds;
90 }
91 else {
92 _fadeDuration = 1.0;
93 }
94 }
95
96 - (void)setFadeInterval:(NSTimeInterval)seconds
97 {
98 _fadeInterval = seconds;
99 }
100
101 - (void)startFadeAnimation
102 {
103 [self stopFadeAnimation];
104
105 _fadeAlpha = 1.0;
106 [self setNeedsDisplay:YES];
107
108 _fadeTimer = [[NSTimer scheduledTimerWithTimeInterval:_fadeInterval target:self selector:@selector(_fadeTimer:) userInfo:nil repeats:YES] retain];
109 [[NSRunLoop currentRunLoop] addTimer:_fadeTimer forMode:NSEventTrackingRunLoopMode];
110 [[NSRunLoop currentRunLoop] addTimer:_fadeTimer forMode:NSModalPanelRunLoopMode];
111 [self release];
112 }
113
114 - (void)stopFadeAnimation
115 {
116 if ( _fadeTimer ) {
117 [self retain];
118 [_fadeTimer invalidate];
119 [_fadeTimer release];
120 _fadeTimer = nil;
121 }
122 }
123
124 - (void)_fadeTimer:(NSTimer *)timer
125 {
126 _fadeAlpha -= [timer timeInterval] / _fadeDuration;
127 [self setNeedsDisplay:YES];
128
129 if ( _fadeAlpha <= 0.0 ) {
130 [self stopFadeAnimation];
131 if ( [_delegate respondsToSelector:@selector(fadeViewFinishedAnimation:)] ) {
132 [_delegate fadeViewFinishedAnimation:self];
133 }
134 }
135 }
136
137
138 - (id)delegate
139 {
140 return _delegate;
141 }
142
143 - (void)setDelegate:(id)delegate
144 {
145 _delegate = delegate;
146 }
147
148
149 @end
This page took 0.03501 seconds and 4 git commands to generate.