|
@@ -6,6 +6,7 @@
|
6
|
6
|
// Copyright (c) 2015 xythobuz. All rights reserved.
|
7
|
7
|
//
|
8
|
8
|
|
|
9
|
+#import "MainView.h"
|
9
|
10
|
#import "MainWindow.h"
|
10
|
11
|
|
11
|
12
|
#define RESIZE_START 1
|
|
@@ -16,10 +17,22 @@
|
16
|
17
|
#define CONFIG_KEEP_POSITION @"keep_position"
|
17
|
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
|
29
|
@interface MainWindow ()
|
20
|
30
|
|
21
|
31
|
@property (assign) NSSize defaultSize;
|
22
|
32
|
@property (assign) NSInteger startScale;
|
|
33
|
+@property (assign) NSInteger lastEyeState;
|
|
34
|
+
|
|
35
|
+@property (weak) IBOutlet MainView *mainView;
|
23
|
36
|
|
24
|
37
|
@property (weak) IBOutlet NSMenuItem *lockPositionItem;
|
25
|
38
|
@property (weak) IBOutlet NSMenuItem *keepOnTopItem;
|
|
@@ -39,8 +52,7 @@
|
39
|
52
|
|
40
|
53
|
@synthesize defaultSize;
|
41
|
54
|
@synthesize startScale;
|
42
|
|
-
|
43
|
|
-// TODO window position should be remembered!
|
|
55
|
+@synthesize lastEyeState;
|
44
|
56
|
|
45
|
57
|
- (id)initWithContentRect:(NSRect)contentRect
|
46
|
58
|
styleMask:(NSUInteger)aStyle
|
|
@@ -50,6 +62,7 @@
|
50
|
62
|
if (self != nil) {
|
51
|
63
|
[self setAlphaValue:1.0];
|
52
|
64
|
[self setOpaque:NO];
|
|
65
|
+ lastEyeState = EYE_TOP_LEFT;
|
53
|
66
|
|
54
|
67
|
NSUserDefaults *defaults = [NSUserDefaults standardUserDefaults];
|
55
|
68
|
|
|
@@ -74,6 +87,10 @@
|
74
|
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
|
94
|
return self;
|
78
|
95
|
}
|
79
|
96
|
|
|
@@ -94,6 +111,8 @@
|
94
|
111
|
if (startScale == 4) [self.changeSize4 setState:NSOnState];
|
95
|
112
|
if (startScale == 5) [self.changeSize5 setState:NSOnState];
|
96
|
113
|
|
|
114
|
+ [[self.mainView render] drawWith:lastEyeState]; // Initialize render image
|
|
115
|
+
|
97
|
116
|
[self setFrame:frame display:YES];
|
98
|
117
|
}
|
99
|
118
|
|
|
@@ -181,7 +200,7 @@
|
181
|
200
|
}
|
182
|
201
|
|
183
|
202
|
- (void)mouseDown:(NSEvent *)theEvent {
|
184
|
|
- self.dragStart = [theEvent locationInWindow];
|
|
203
|
+ dragStart = [theEvent locationInWindow];
|
185
|
204
|
}
|
186
|
205
|
|
187
|
206
|
- (void)mouseDragged:(NSEvent *)theEvent {
|
|
@@ -202,4 +221,28 @@
|
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
|
248
|
@end
|