Quellcode durchsuchen

Implemented random eye blinking

Thomas Buck vor 9 Jahren
Ursprung
Commit
9177040541
2 geänderte Dateien mit 32 neuen und 3 gelöschten Zeilen
  1. 1
    1
      OtaClock/Info.plist
  2. 31
    2
      OtaClock/MainWindow.m

+ 1
- 1
OtaClock/Info.plist Datei anzeigen

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

+ 31
- 2
OtaClock/MainWindow.m Datei anzeigen

@@ -26,11 +26,15 @@
26 26
 #define EYE_BOTTOM_RIGHT 3
27 27
 #define EYE_BOTTOM_LEFT 1
28 28
 
29
+#define MAX_BLINK_DELAY 5.0
30
+#define UNBLINK_DELAY 0.1
31
+
29 32
 @interface MainWindow ()
30 33
 
31 34
 @property (assign) NSSize defaultSize;
32 35
 @property (assign) NSInteger startScale;
33 36
 @property (assign) NSInteger lastEyeState;
37
+@property (assign) BOOL currentlyBlinking;
34 38
 
35 39
 @property (weak) IBOutlet MainView *mainView;
36 40
 
@@ -53,6 +57,7 @@
53 57
 @synthesize defaultSize;
54 58
 @synthesize startScale;
55 59
 @synthesize lastEyeState;
60
+@synthesize currentlyBlinking;
56 61
 
57 62
 - (id)initWithContentRect:(NSRect)contentRect
58 63
                styleMask:(NSUInteger)aStyle
@@ -63,6 +68,7 @@
63 68
         [self setAlphaValue:1.0];
64 69
         [self setOpaque:NO];
65 70
         lastEyeState = EYE_TOP_LEFT;
71
+        currentlyBlinking = NO;
66 72
         
67 73
         NSUserDefaults *defaults = [NSUserDefaults standardUserDefaults];
68 74
         
@@ -112,10 +118,31 @@
112 118
     if (startScale == 5) [self.changeSize5 setState:NSOnState];
113 119
     
114 120
     [[self.mainView render] drawWith:lastEyeState]; // Initialize render image
121
+    [self unblink]; // Schedule next blinking
115 122
     
116 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 146
 - (IBAction)changeSize:(NSMenuItem *)sender {
120 147
     NSRect frame = [self frame];
121 148
     
@@ -243,8 +270,10 @@
243 270
     
244 271
     if (eyeState != lastEyeState) {
245 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
 

Laden…
Abbrechen
Speichern