]> Dogcows Code - chaz/thecheat/blob - StatusTextField.m
The Cheat 1.2.3
[chaz/thecheat] / StatusTextField.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 #import "StatusTextField.h"
22
23
24 @interface StatusTextField ( Private )
25
26 - (void)doTimer:(NSTimer *)timer;
27
28 @end
29
30
31 @implementation StatusTextField
32
33
34 - (id)init
35 {
36 if ( self = [super init] ) {
37 myTimer = nil;
38 }
39 return self;
40 }
41
42 - (void)dealloc
43 {
44 [myDefaultStatus release];
45 [myTimer invalidate];
46 [myTimer release];
47
48 [super dealloc];
49 }
50
51
52 - (void)setDefaultStatus:(NSString *)message
53 {
54 [self setDefaultStatus:message color:[NSColor blackColor]];
55 }
56
57 - (void)setDefaultStatus:(NSString *)message color:(NSColor *)color
58 {
59 if ( !message ) {
60 message = [NSString stringWithString:@""];
61 }
62 if ( !color ) {
63 color = [NSColor blackColor];
64 }
65 // save the new values
66 [message retain];
67 [myDefaultStatus release];
68 myDefaultStatus = message;
69 // save the new values
70 [color retain];
71 [myDefaultColor release];
72 myDefaultColor = color;
73 // set the new default if there isn't already a temp showing
74 if ( !myTimer ) {
75 [self setStringValue:myDefaultStatus];
76 [self setTextColor:myDefaultColor];
77 }
78 }
79
80
81 - (void)setTemporaryStatus:(NSString *)message
82 {
83 [self setTemporaryStatus:message color:[NSColor blackColor]];
84 }
85
86 - (void)setTemporaryStatus:(NSString *)message color:(NSColor *)color
87 {
88 [self setTemporaryStatus:message color:color duration:4.0];
89 }
90
91 - (void)setTemporaryStatus:(NSString *)message duration:(NSTimeInterval)duration
92 {
93 [self setTemporaryStatus:message color:[NSColor blackColor] duration:duration];
94 }
95
96 - (void)setTemporaryStatus:(NSString *)message color:(NSColor *)color duration:(NSTimeInterval)duration
97 {
98 // stop any current temporary status
99 [myTimer invalidate];
100 [myTimer release];
101
102 if ( !message ) {
103 message = [NSString stringWithString:@""];
104 }
105 if ( !color ) {
106 color = [NSColor blackColor];
107 }
108 // set the new temporary status
109 [self setStringValue:message];
110 [self setTextColor:color];
111 // start the timer
112 myTimer = [[NSTimer scheduledTimerWithTimeInterval:duration target:self selector:@selector(doTimer:) userInfo:nil repeats:NO] retain];
113 }
114
115
116 - (void)doTimer:(NSTimer *)timer
117 {
118 // kill the timer
119 [myTimer release];
120 myTimer = nil;
121
122 // set the default status
123 if ( myDefaultStatus ) {
124 [self setStringValue:myDefaultStatus];
125 }
126 if ( myDefaultColor ) {
127 [self setTextColor:myDefaultColor];
128 }
129 }
130
131
132 @end
This page took 0.032149 seconds and 4 git commands to generate.