Browse Source

Implemented random eye blinking

Thomas Buck 8 years ago
parent
commit
9177040541
2 changed files with 32 additions and 3 deletions
  1. 1
    1
      OtaClock/Info.plist
  2. 31
    2
      OtaClock/MainWindow.m

+ 1
- 1
OtaClock/Info.plist View File

19
 	<key>CFBundleSignature</key>
19
 	<key>CFBundleSignature</key>
20
 	<string>????</string>
20
 	<string>????</string>
21
 	<key>CFBundleVersion</key>
21
 	<key>CFBundleVersion</key>
22
-	<string>142</string>
22
+	<string>147</string>
23
 	<key>LSApplicationCategoryType</key>
23
 	<key>LSApplicationCategoryType</key>
24
 	<string>public.app-category.utilities</string>
24
 	<string>public.app-category.utilities</string>
25
 	<key>LSMinimumSystemVersion</key>
25
 	<key>LSMinimumSystemVersion</key>

+ 31
- 2
OtaClock/MainWindow.m View File

26
 #define EYE_BOTTOM_RIGHT 3
26
 #define EYE_BOTTOM_RIGHT 3
27
 #define EYE_BOTTOM_LEFT 1
27
 #define EYE_BOTTOM_LEFT 1
28
 
28
 
29
+#define MAX_BLINK_DELAY 5.0
30
+#define UNBLINK_DELAY 0.1
31
+
29
 @interface MainWindow ()
32
 @interface MainWindow ()
30
 
33
 
31
 @property (assign) NSSize defaultSize;
34
 @property (assign) NSSize defaultSize;
32
 @property (assign) NSInteger startScale;
35
 @property (assign) NSInteger startScale;
33
 @property (assign) NSInteger lastEyeState;
36
 @property (assign) NSInteger lastEyeState;
37
+@property (assign) BOOL currentlyBlinking;
34
 
38
 
35
 @property (weak) IBOutlet MainView *mainView;
39
 @property (weak) IBOutlet MainView *mainView;
36
 
40
 
53
 @synthesize defaultSize;
57
 @synthesize defaultSize;
54
 @synthesize startScale;
58
 @synthesize startScale;
55
 @synthesize lastEyeState;
59
 @synthesize lastEyeState;
60
+@synthesize currentlyBlinking;
56
 
61
 
57
 - (id)initWithContentRect:(NSRect)contentRect
62
 - (id)initWithContentRect:(NSRect)contentRect
58
                styleMask:(NSUInteger)aStyle
63
                styleMask:(NSUInteger)aStyle
63
         [self setAlphaValue:1.0];
68
         [self setAlphaValue:1.0];
64
         [self setOpaque:NO];
69
         [self setOpaque:NO];
65
         lastEyeState = EYE_TOP_LEFT;
70
         lastEyeState = EYE_TOP_LEFT;
71
+        currentlyBlinking = NO;
66
         
72
         
67
         NSUserDefaults *defaults = [NSUserDefaults standardUserDefaults];
73
         NSUserDefaults *defaults = [NSUserDefaults standardUserDefaults];
68
         
74
         
112
     if (startScale == 5) [self.changeSize5 setState:NSOnState];
118
     if (startScale == 5) [self.changeSize5 setState:NSOnState];
113
     
119
     
114
     [[self.mainView render] drawWith:lastEyeState]; // Initialize render image
120
     [[self.mainView render] drawWith:lastEyeState]; // Initialize render image
121
+    [self unblink]; // Schedule next blinking
115
     
122
     
116
     [self setFrame:frame display:YES];
123
     [self setFrame:frame display:YES];
117
 }
124
 }
118
 
125
 
126
+- (void)blink {
127
+    if (currentlyBlinking == NO) {
128
+        currentlyBlinking = YES;
129
+        [[self.mainView render] drawWith:EYE_BLINK];
130
+        self.mainView.needsDisplay = YES;
131
+    }
132
+    
133
+    [self performSelector:@selector(unblink) withObject:nil afterDelay:UNBLINK_DELAY];
134
+}
135
+
136
+- (void)unblink {
137
+    if (currentlyBlinking == YES) {
138
+        currentlyBlinking = NO;
139
+        [[self.mainView render] drawWith:lastEyeState];
140
+        self.mainView.needsDisplay = YES;
141
+    }
142
+    
143
+    [self performSelector:@selector(blink) withObject:nil afterDelay:(((float)rand() / RAND_MAX) * MAX_BLINK_DELAY)];
144
+}
145
+
119
 - (IBAction)changeSize:(NSMenuItem *)sender {
146
 - (IBAction)changeSize:(NSMenuItem *)sender {
120
     NSRect frame = [self frame];
147
     NSRect frame = [self frame];
121
     
148
     
243
     
270
     
244
     if (eyeState != lastEyeState) {
271
     if (eyeState != lastEyeState) {
245
         lastEyeState = eyeState;
272
         lastEyeState = eyeState;
246
-        [[self.mainView render] drawWith:lastEyeState];
247
-        self.mainView.needsDisplay = YES;
273
+        if (currentlyBlinking == NO) {
274
+            [[self.mainView render] drawWith:lastEyeState];
275
+            self.mainView.needsDisplay = YES;
276
+        }
248
     }
277
     }
249
 }
278
 }
250
 
279
 

Loading…
Cancel
Save