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