Browse Source

Otacons eyes properly follow the mouse cursor

Thomas Buck 8 years ago
parent
commit
7245d17686
5 changed files with 52 additions and 9 deletions
  1. 1
    0
      OtaClock/Base.lproj/MainMenu.xib
  2. 1
    1
      OtaClock/Info.plist
  3. 4
    0
      OtaClock/MainView.h
  4. 0
    5
      OtaClock/MainView.m
  5. 46
    3
      OtaClock/MainWindow.m

+ 1
- 0
OtaClock/Base.lproj/MainMenu.xib View File

90
                 <outlet property="changeSize5" destination="Qji-aB-KLD" id="a79-d3-RIN"/>
90
                 <outlet property="changeSize5" destination="Qji-aB-KLD" id="a79-d3-RIN"/>
91
                 <outlet property="keepOnTopItem" destination="bk2-WG-9eq" id="vBf-vA-eXc"/>
91
                 <outlet property="keepOnTopItem" destination="bk2-WG-9eq" id="vBf-vA-eXc"/>
92
                 <outlet property="lockPositionItem" destination="YfQ-b7-bXC" id="CYs-rk-6GP"/>
92
                 <outlet property="lockPositionItem" destination="YfQ-b7-bXC" id="CYs-rk-6GP"/>
93
+                <outlet property="mainView" destination="EiT-Mj-1SZ" id="sQZ-BE-YrX"/>
93
             </connections>
94
             </connections>
94
             <point key="canvasLocation" x="129.5" y="81"/>
95
             <point key="canvasLocation" x="129.5" y="81"/>
95
         </window>
96
         </window>

+ 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>107</string>
22
+	<string>140</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>

+ 4
- 0
OtaClock/MainView.h View File

8
 
8
 
9
 #import <Cocoa/Cocoa.h>
9
 #import <Cocoa/Cocoa.h>
10
 
10
 
11
+#import "Render.h"
12
+
11
 @interface MainView : NSView
13
 @interface MainView : NSView
12
 
14
 
15
+@property (strong) Render *render;
16
+
13
 @end
17
 @end

+ 0
- 5
OtaClock/MainView.m View File

7
 //
7
 //
8
 
8
 
9
 #import "MainWindow.h"
9
 #import "MainWindow.h"
10
-#import "Render.h"
11
 #import "MainView.h"
10
 #import "MainView.h"
12
 
11
 
13
 @interface MainView ()
12
 @interface MainView ()
14
 
13
 
15
-@property (strong) Render *render;
16
-
17
 @end
14
 @end
18
 
15
 
19
 @implementation MainView
16
 @implementation MainView
29
     // Clear background
26
     // Clear background
30
     [[NSColor clearColor] set];
27
     [[NSColor clearColor] set];
31
     NSRectFill([self frame]);
28
     NSRectFill([self frame]);
32
-    
33
-    [render drawWith:0]; // Should be done somewhere else!
34
     [render drawInto:self]; // Draw composite image
29
     [render drawInto:self]; // Draw composite image
35
 }
30
 }
36
 
31
 

+ 46
- 3
OtaClock/MainWindow.m View File

6
 //  Copyright (c) 2015 xythobuz. All rights reserved.
6
 //  Copyright (c) 2015 xythobuz. All rights reserved.
7
 //
7
 //
8
 
8
 
9
+#import "MainView.h"
9
 #import "MainWindow.h"
10
 #import "MainWindow.h"
10
 
11
 
11
 #define RESIZE_START 1
12
 #define RESIZE_START 1
16
 #define CONFIG_KEEP_POSITION @"keep_position"
17
 #define CONFIG_KEEP_POSITION @"keep_position"
17
 #define CONFIG_KEEP_ON_TOP @"keep_on_top"
18
 #define CONFIG_KEEP_ON_TOP @"keep_on_top"
18
 
19
 
20
+#define MOUSE_CENTER_X 337
21
+#define MOUSE_CENTER_Y 237
22
+
23
+#define EYE_BLINK 0
24
+#define EYE_TOP_RIGHT 4
25
+#define EYE_TOP_LEFT 2
26
+#define EYE_BOTTOM_RIGHT 3
27
+#define EYE_BOTTOM_LEFT 1
28
+
19
 @interface MainWindow ()
29
 @interface MainWindow ()
20
 
30
 
21
 @property (assign) NSSize defaultSize;
31
 @property (assign) NSSize defaultSize;
22
 @property (assign) NSInteger startScale;
32
 @property (assign) NSInteger startScale;
33
+@property (assign) NSInteger lastEyeState;
34
+
35
+@property (weak) IBOutlet MainView *mainView;
23
 
36
 
24
 @property (weak) IBOutlet NSMenuItem *lockPositionItem;
37
 @property (weak) IBOutlet NSMenuItem *lockPositionItem;
25
 @property (weak) IBOutlet NSMenuItem *keepOnTopItem;
38
 @property (weak) IBOutlet NSMenuItem *keepOnTopItem;
39
 
52
 
40
 @synthesize defaultSize;
53
 @synthesize defaultSize;
41
 @synthesize startScale;
54
 @synthesize startScale;
42
-
43
-// TODO window position should be remembered!
55
+@synthesize lastEyeState;
44
 
56
 
45
 - (id)initWithContentRect:(NSRect)contentRect
57
 - (id)initWithContentRect:(NSRect)contentRect
46
                styleMask:(NSUInteger)aStyle
58
                styleMask:(NSUInteger)aStyle
50
     if (self != nil) {
62
     if (self != nil) {
51
         [self setAlphaValue:1.0];
63
         [self setAlphaValue:1.0];
52
         [self setOpaque:NO];
64
         [self setOpaque:NO];
65
+        lastEyeState = EYE_TOP_LEFT;
53
         
66
         
54
         NSUserDefaults *defaults = [NSUserDefaults standardUserDefaults];
67
         NSUserDefaults *defaults = [NSUserDefaults standardUserDefaults];
55
         
68
         
74
             startScale = [defaults integerForKey:CONFIG_START_SCALE];
87
             startScale = [defaults integerForKey:CONFIG_START_SCALE];
75
         }
88
         }
76
     }
89
     }
90
+    
91
+    [self setAcceptsMouseMovedEvents:YES];
92
+    [NSEvent addGlobalMonitorForEventsMatchingMask:NSMouseMovedMask handler:^(NSEvent *mouseMovedEvent) { [self mouseMoved:mouseMovedEvent]; }];
93
+    
77
     return self;
94
     return self;
78
 }
95
 }
79
 
96
 
94
     if (startScale == 4) [self.changeSize4 setState:NSOnState];
111
     if (startScale == 4) [self.changeSize4 setState:NSOnState];
95
     if (startScale == 5) [self.changeSize5 setState:NSOnState];
112
     if (startScale == 5) [self.changeSize5 setState:NSOnState];
96
     
113
     
114
+    [[self.mainView render] drawWith:lastEyeState]; // Initialize render image
115
+    
97
     [self setFrame:frame display:YES];
116
     [self setFrame:frame display:YES];
98
 }
117
 }
99
 
118
 
181
 }
200
 }
182
 
201
 
183
 - (void)mouseDown:(NSEvent *)theEvent {
202
 - (void)mouseDown:(NSEvent *)theEvent {
184
-    self.dragStart = [theEvent locationInWindow];
203
+    dragStart = [theEvent locationInWindow];
185
 }
204
 }
186
 
205
 
187
 - (void)mouseDragged:(NSEvent *)theEvent {
206
 - (void)mouseDragged:(NSEvent *)theEvent {
202
     }
221
     }
203
 }
222
 }
204
 
223
 
224
+- (void)mouseMoved:(NSEvent *)theEvent {
225
+    NSPoint mousePoint = [NSEvent mouseLocation];
226
+    mousePoint.x -= [self frame].origin.x;
227
+    mousePoint.y -= [self frame].origin.y;
228
+    
229
+    BOOL top = (mousePoint.y > MOUSE_CENTER_Y);
230
+    BOOL right = (mousePoint.x > MOUSE_CENTER_X);
231
+    
232
+    NSInteger eyeState = EYE_BOTTOM_LEFT;
233
+    if (top && right) {
234
+        eyeState = EYE_TOP_RIGHT;
235
+    } else if (top && (!right)) {
236
+        eyeState = EYE_TOP_LEFT;
237
+    } else if ((!top) && right) {
238
+        eyeState = EYE_BOTTOM_RIGHT;
239
+    }
240
+    
241
+    if (eyeState != lastEyeState) {
242
+        lastEyeState = eyeState;
243
+        [[self.mainView render] drawWith:lastEyeState];
244
+        self.mainView.needsDisplay = YES;
245
+    }
246
+}
247
+
205
 @end
248
 @end

Loading…
Cancel
Save