reflexion 0.1.6 → 0.1.7
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +7 -0
- data/.doc/ext/reflex/application.cpp +54 -39
- data/.doc/ext/reflex/capture_event.cpp +87 -0
- data/.doc/ext/reflex/draw_event.cpp +103 -0
- data/.doc/ext/reflex/event.cpp +73 -0
- data/.doc/ext/reflex/focus_event.cpp +98 -0
- data/.doc/ext/reflex/frame_event.cpp +133 -0
- data/.doc/ext/reflex/image_view.cpp +74 -0
- data/.doc/ext/reflex/key_event.cpp +124 -0
- data/.doc/ext/reflex/native.cpp +45 -6
- data/.doc/ext/reflex/pointer_event.cpp +181 -0
- data/.doc/ext/reflex/reflex.cpp +17 -41
- data/.doc/ext/reflex/scroll_event.cpp +141 -0
- data/.doc/ext/reflex/selector.cpp +135 -0
- data/.doc/ext/reflex/style.cpp +253 -0
- data/.doc/ext/reflex/style_length.cpp +133 -0
- data/.doc/ext/reflex/style_length2.cpp +149 -0
- data/.doc/ext/reflex/style_length4.cpp +192 -0
- data/.doc/ext/reflex/update_event.cpp +77 -0
- data/.doc/ext/reflex/view.cpp +408 -88
- data/.doc/ext/reflex/wheel_event.cpp +146 -0
- data/.doc/ext/reflex/window.cpp +95 -92
- data/Rakefile +6 -5
- data/VERSION +1 -1
- data/ext/reflex/application.cpp +67 -49
- data/ext/reflex/capture_event.cpp +92 -0
- data/ext/reflex/draw_event.cpp +110 -0
- data/ext/reflex/event.cpp +77 -0
- data/ext/reflex/extconf.rb +18 -68
- data/ext/reflex/focus_event.cpp +104 -0
- data/ext/reflex/frame_event.cpp +143 -0
- data/ext/reflex/image_view.cpp +77 -0
- data/ext/reflex/key_event.cpp +133 -0
- data/ext/reflex/native.cpp +45 -6
- data/ext/reflex/pointer_event.cpp +195 -0
- data/ext/reflex/reflex.cpp +21 -47
- data/ext/reflex/scroll_event.cpp +152 -0
- data/ext/reflex/selector.cpp +144 -0
- data/ext/reflex/style.cpp +277 -0
- data/ext/reflex/style_length.cpp +140 -0
- data/ext/reflex/style_length2.cpp +157 -0
- data/ext/reflex/style_length4.cpp +204 -0
- data/ext/reflex/update_event.cpp +81 -0
- data/ext/reflex/view.cpp +469 -114
- data/ext/reflex/wheel_event.cpp +158 -0
- data/ext/reflex/window.cpp +130 -123
- data/include/reflex/application.h +12 -7
- data/include/reflex/defs.h +13 -89
- data/include/reflex/event.h +260 -0
- data/include/reflex/exception.h +17 -11
- data/include/reflex/image_view.h +45 -0
- data/include/reflex/reflex.h +2 -6
- data/include/reflex/ruby/application.h +40 -13
- data/include/reflex/ruby/event.h +72 -0
- data/include/reflex/ruby/image_view.h +25 -0
- data/include/reflex/ruby/selector.h +27 -0
- data/include/reflex/ruby/style.h +27 -0
- data/include/reflex/ruby/style_length.h +37 -0
- data/include/reflex/ruby/view.h +193 -38
- data/include/reflex/ruby/window.h +123 -39
- data/include/reflex/ruby.h +3 -2
- data/include/reflex/selector.h +64 -0
- data/include/reflex/style.h +144 -0
- data/include/reflex/style_length.h +147 -0
- data/include/reflex/view.h +182 -19
- data/include/reflex/window.h +35 -19
- data/include/reflex.h +7 -0
- data/lib/reflex/application.rb +14 -5
- data/lib/reflex/arc_shape.rb +20 -0
- data/lib/reflex/button.rb +75 -0
- data/lib/reflex/capture_event.rb +37 -0
- data/lib/reflex/color.rb +13 -0
- data/lib/reflex/color_space.rb +13 -0
- data/lib/reflex/draw_event.rb +19 -0
- data/lib/reflex/ellipse_shape.rb +20 -0
- data/lib/reflex/ext.rb +1 -1
- data/lib/reflex/flags.rb +18 -0
- data/lib/reflex/focus_event.rb +38 -0
- data/lib/reflex/font.rb +13 -0
- data/lib/reflex/frame_event.rb +42 -0
- data/lib/reflex/helper.rb +87 -30
- data/lib/reflex/image_view.rb +25 -0
- data/lib/reflex/key_event.rb +38 -0
- data/lib/reflex/line_shape.rb +20 -0
- data/lib/reflex/list_view.rb +15 -0
- data/lib/reflex/model.rb +149 -0
- data/lib/reflex/model_owner.rb +57 -0
- data/lib/reflex/model_view.rb +22 -0
- data/lib/reflex/module.rb +11 -7
- data/lib/reflex/pointer_event.rb +85 -0
- data/lib/reflex/rect_shape.rb +20 -0
- data/lib/reflex/reflex.rb +13 -2
- data/lib/reflex/scroll_event.rb +19 -0
- data/lib/reflex/selector.rb +31 -0
- data/lib/reflex/shader.rb +13 -0
- data/lib/reflex/shape.rb +34 -0
- data/lib/reflex/style.rb +55 -0
- data/lib/reflex/style_length.rb +30 -0
- data/lib/reflex/style_length2.rb +34 -0
- data/lib/reflex/style_length4.rb +38 -0
- data/lib/reflex/text_view.rb +55 -0
- data/lib/reflex/update_event.rb +19 -0
- data/lib/reflex/view.rb +38 -4
- data/lib/reflex/wheel_event.rb +19 -0
- data/lib/reflex/window.rb +7 -5
- data/lib/reflex.rb +38 -1
- data/lib/reflexion/include.rb +5 -0
- data/lib/reflexion.rb +100 -0
- data/reflex.gemspec +3 -4
- data/samples/app.rb +13 -0
- data/samples/bats.rb +91 -0
- data/samples/checker.rb +36 -0
- data/{examples/ruby/shapes.rb → samples/fans.rb} +12 -16
- data/samples/fps.rb +46 -0
- data/samples/grid.rb +60 -0
- data/{examples/ruby → samples}/hello.rb +14 -16
- data/samples/image.rb +44 -0
- data/samples/ios/hello/hello/Images.xcassets/AppIcon.appiconset/Contents.json +53 -0
- data/samples/ios/hello/hello/Images.xcassets/LaunchImage.launchimage/Contents.json +51 -0
- data/samples/ios/hello/hello/en.lproj/InfoPlist.strings +2 -0
- data/samples/ios/hello/hello/hello-Info.plist +47 -0
- data/samples/ios/hello/hello/hello-Prefix.pch +10 -0
- data/samples/ios/hello/hello/main.cpp +79 -0
- data/samples/ios/hello/hello.xcodeproj/project.pbxproj +725 -0
- data/{examples/ruby → samples}/key.rb +11 -14
- data/samples/layout.rb +89 -0
- data/samples/model.rb +86 -0
- data/samples/osx/hello/hello/Images.xcassets/AppIcon.appiconset/Contents.json +58 -0
- data/samples/osx/hello/hello/en.lproj/Credits.rtf +29 -0
- data/samples/osx/hello/hello/en.lproj/InfoPlist.strings +2 -0
- data/samples/osx/hello/hello/hello-Info.plist +32 -0
- data/samples/osx/hello/hello/hello-Prefix.pch +3 -0
- data/samples/osx/hello/hello/main.cpp +79 -0
- data/samples/osx/hello/hello.xcodeproj/project.pbxproj +725 -0
- data/samples/reflexion/hello.rb +24 -0
- data/samples/reflexion/paint.rb +40 -0
- data/samples/reflexion/pulse.rb +34 -0
- data/samples/repl.rb +69 -0
- data/samples/shader.rb +41 -0
- data/samples/shapes.rb +30 -0
- data/{examples/ruby → samples}/text.rb +7 -8
- data/samples/tree.rb +71 -0
- data/samples/views.rb +41 -0
- data/samples/visuals.rb +22 -0
- data/src/event.cpp +225 -0
- data/src/exception.cpp +24 -15
- data/src/image_view.cpp +70 -0
- data/src/ios/app_delegate.h +17 -0
- data/src/ios/app_delegate.mm +120 -0
- data/src/ios/application.mm +116 -0
- data/src/{cocoa/applicationdata.h → ios/application_data.h} +6 -6
- data/src/ios/event.h +26 -0
- data/src/ios/event.mm +31 -0
- data/src/ios/native_window.h +37 -0
- data/src/ios/native_window.mm +220 -0
- data/src/ios/opengl_view.h +13 -0
- data/src/ios/opengl_view.mm +131 -0
- data/src/{cocoa → ios}/reflex.mm +8 -12
- data/src/ios/window.mm +303 -0
- data/src/ios/window_data.h +75 -0
- data/src/osx/app_delegate.h +17 -0
- data/src/{cocoa/cocoaapplication.mm → osx/app_delegate.mm} +90 -48
- data/src/osx/application.mm +132 -0
- data/src/osx/application_data.h +45 -0
- data/src/osx/event.h +42 -0
- data/src/osx/event.mm +112 -0
- data/src/osx/native_window.h +26 -0
- data/src/osx/native_window.mm +322 -0
- data/src/{cocoa/openglview.h → osx/opengl_view.h} +0 -4
- data/src/{cocoa/openglview.mm → osx/opengl_view.mm} +66 -23
- data/src/osx/reflex.mm +50 -0
- data/src/osx/window.mm +308 -0
- data/src/osx/window_data.h +75 -0
- data/src/selector.cpp +121 -0
- data/src/style.cpp +576 -0
- data/src/style_length.cpp +341 -0
- data/src/view.cpp +1228 -129
- data/src/win32/application.cpp +1 -1
- data/src/window.cpp +54 -26
- data/test/helper.rb +8 -4
- data/test/test_capture_event.rb +41 -0
- data/test/test_event.rb +20 -0
- data/test/test_has_frame.rb +45 -0
- data/test/test_model.rb +9 -0
- data/test/test_model_owner.rb +9 -0
- data/test/test_selector.rb +75 -0
- data/test/test_style.rb +70 -0
- data/test/test_style_length.rb +38 -0
- data/test/test_style_length2.rb +50 -0
- data/test/test_style_length4.rb +56 -0
- data/test/test_view.rb +97 -23
- data/test/test_window.rb +54 -46
- metadata +205 -84
- data/.doc/ext/reflex/defs.cpp +0 -8
- data/.doc/ext/reflex/key.cpp +0 -122
- data/.doc/ext/reflex/points.cpp +0 -151
- data/.gitignore +0 -14
- data/ChangeLog +0 -8
- data/examples/hello/.gitignore +0 -2
- data/examples/hello/Rakefile +0 -41
- data/examples/hello/main.cpp +0 -18
- data/examples/ruby/app.rb +0 -13
- data/examples/ruby/checker.rb +0 -41
- data/examples/ruby/fps.rb +0 -49
- data/examples/ruby/grid.rb +0 -65
- data/examples/ruby/views.rb +0 -88
- data/examples/ruby/visuals.rb +0 -27
- data/ext/reflex/defs.cpp +0 -8
- data/ext/reflex/key.cpp +0 -129
- data/ext/reflex/points.cpp +0 -161
- data/include/reflex/ruby/key.h +0 -39
- data/include/reflex/ruby/points.h +0 -39
- data/lib/reflex/visuals/string.rb +0 -53
- data/src/cocoa/application.mm +0 -101
- data/src/cocoa/cocoaapplication.h +0 -21
- data/src/cocoa/cocoawindow.h +0 -46
- data/src/cocoa/cocoawindow.mm +0 -230
- data/src/cocoa/defs.h +0 -34
- data/src/cocoa/defs.mm +0 -87
- data/src/cocoa/window.mm +0 -148
- data/src/cocoa/windowdata.h +0 -56
- data/src/defs.cpp +0 -47
- data/src/helper.h +0 -12
- data/src/reflex.cpp +0 -43
- /data/{README → README.md} +0 -0
|
@@ -1,24 +1,24 @@
|
|
|
1
1
|
// -*- objc -*-
|
|
2
|
-
#import "
|
|
2
|
+
#import "app_delegate.h"
|
|
3
3
|
|
|
4
4
|
|
|
5
5
|
#include <assert.h>
|
|
6
6
|
#import <Cocoa/Cocoa.h>
|
|
7
|
-
#include
|
|
8
|
-
#include "
|
|
7
|
+
#include "reflex/event.h"
|
|
8
|
+
#include "reflex/exception.h"
|
|
9
|
+
#include "application_data.h"
|
|
9
10
|
|
|
10
11
|
|
|
11
|
-
|
|
12
|
+
#define REF (*pref)
|
|
13
|
+
|
|
14
|
+
|
|
15
|
+
@implementation AppDelegate
|
|
12
16
|
|
|
13
17
|
- (id) init
|
|
14
18
|
{
|
|
15
19
|
self = [super init];
|
|
16
20
|
if (!self) return nil;
|
|
17
21
|
|
|
18
|
-
[self setDelegate: self];
|
|
19
|
-
[self setActivationPolicy: NSApplicationActivationPolicyRegular];
|
|
20
|
-
[self activateIgnoringOtherApps: YES];
|
|
21
|
-
|
|
22
22
|
pref = new Reflex::Application::Ref;
|
|
23
23
|
|
|
24
24
|
return self;
|
|
@@ -26,87 +26,129 @@
|
|
|
26
26
|
|
|
27
27
|
- (void) dealloc
|
|
28
28
|
{
|
|
29
|
-
|
|
29
|
+
assert(pref && !REF);
|
|
30
|
+
|
|
30
31
|
delete pref;
|
|
31
32
|
|
|
32
33
|
[super dealloc];
|
|
33
34
|
}
|
|
34
35
|
|
|
35
|
-
- (
|
|
36
|
+
- (void) bind: (Reflex::Application*) instance
|
|
36
37
|
{
|
|
37
|
-
|
|
38
|
-
return NO;
|
|
38
|
+
assert(pref);
|
|
39
39
|
|
|
40
|
-
|
|
40
|
+
if (instance && instance->self->delegate)
|
|
41
|
+
Reflex::argument_error(__FILE__, __LINE__);
|
|
41
42
|
|
|
42
|
-
|
|
43
|
-
|
|
43
|
+
if (REF)
|
|
44
|
+
Reflex::invalid_state_error(__FILE__, __LINE__);
|
|
44
45
|
|
|
45
|
-
|
|
46
|
-
if (
|
|
47
|
-
return YES;
|
|
46
|
+
REF = instance;
|
|
47
|
+
if (REF) REF->self->delegate = [self retain];
|
|
48
48
|
}
|
|
49
49
|
|
|
50
|
-
- (void) unbind
|
|
50
|
+
- (void) unbind: (Reflex::Application*) instance
|
|
51
51
|
{
|
|
52
52
|
assert(pref);
|
|
53
|
-
Reflex::Application::Ref& ref = *pref;
|
|
54
|
-
if (!ref) return;
|
|
55
53
|
|
|
56
|
-
if (
|
|
57
|
-
|
|
58
|
-
|
|
54
|
+
if (!REF) return;
|
|
55
|
+
|
|
56
|
+
if (instance && instance != REF.get())
|
|
57
|
+
Reflex::invalid_state_error(__FILE__, __LINE__);
|
|
58
|
+
|
|
59
|
+
if (REF->self->delegate) [REF->self->delegate release];
|
|
60
|
+
REF->self->delegate = nil;
|
|
61
|
+
REF.reset();
|
|
59
62
|
}
|
|
60
63
|
|
|
61
64
|
- (void) quit
|
|
62
65
|
{
|
|
63
66
|
assert(pref);
|
|
64
67
|
|
|
65
|
-
if (
|
|
66
|
-
|
|
68
|
+
if (REF)
|
|
69
|
+
REF->quit();
|
|
67
70
|
else
|
|
68
|
-
|
|
71
|
+
[NSApp terminate: nil];
|
|
69
72
|
}
|
|
70
73
|
|
|
71
|
-
- (void)
|
|
74
|
+
- (void) showPreference
|
|
72
75
|
{
|
|
73
76
|
assert(pref);
|
|
74
77
|
|
|
75
|
-
if (
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
78
|
+
if (REF)
|
|
79
|
+
{
|
|
80
|
+
Reflex::Event e;
|
|
81
|
+
REF->on_preference(&e);
|
|
82
|
+
}
|
|
79
83
|
}
|
|
80
84
|
|
|
81
|
-
- (
|
|
85
|
+
- (void) showAbout
|
|
82
86
|
{
|
|
83
|
-
|
|
87
|
+
assert(pref);
|
|
88
|
+
|
|
89
|
+
if (REF)
|
|
90
|
+
{
|
|
91
|
+
Reflex::Event e;
|
|
92
|
+
REF->on_about(&e);
|
|
93
|
+
}
|
|
94
|
+
else
|
|
95
|
+
[NSApp orderFrontStandardAboutPanel: nil];
|
|
84
96
|
}
|
|
85
97
|
|
|
86
98
|
- (void) applicationDidFinishLaunching: (NSNotification*) notification
|
|
87
99
|
{
|
|
100
|
+
[NSApp setActivationPolicy: NSApplicationActivationPolicyRegular];
|
|
101
|
+
[NSApp activateIgnoringOtherApps: YES];
|
|
102
|
+
|
|
103
|
+
if (REF)
|
|
104
|
+
{
|
|
105
|
+
Reflex::Event e;
|
|
106
|
+
REF->on_start(&e);
|
|
107
|
+
if (e.is_blocked())
|
|
108
|
+
{
|
|
109
|
+
[self quit];
|
|
110
|
+
return;
|
|
111
|
+
}
|
|
112
|
+
}
|
|
113
|
+
|
|
88
114
|
[self setupMenu];
|
|
89
115
|
}
|
|
90
116
|
|
|
117
|
+
- (NSApplicationTerminateReply) applicationShouldTerminate: (NSApplication*) application
|
|
118
|
+
{
|
|
119
|
+
if (REF)
|
|
120
|
+
{
|
|
121
|
+
Reflex::Event e;
|
|
122
|
+
REF->on_quit(&e);
|
|
123
|
+
if (e.is_blocked()) return NSTerminateCancel;
|
|
124
|
+
}
|
|
125
|
+
|
|
126
|
+
return NSTerminateNow;
|
|
127
|
+
}
|
|
128
|
+
|
|
129
|
+
- (BOOL) applicationShouldTerminateAfterLastWindowClosed: (NSApplication*) application
|
|
130
|
+
{
|
|
131
|
+
return YES;
|
|
132
|
+
}
|
|
133
|
+
|
|
91
134
|
- (void) applicationWillTerminate: (NSNotification*) notification
|
|
92
135
|
{
|
|
93
|
-
[self unbind];
|
|
136
|
+
[self unbind: NULL];
|
|
94
137
|
}
|
|
95
138
|
|
|
96
139
|
- (BOOL) setupApplicationMenu: (NSMenu*) parent
|
|
97
140
|
{
|
|
98
141
|
assert(pref);
|
|
99
|
-
|
|
100
|
-
if (!parent) return NO;
|
|
142
|
+
if (!REF || !parent) return NO;
|
|
101
143
|
|
|
102
144
|
NSMenu* menu = [[[NSMenu alloc]
|
|
103
145
|
initWithTitle: @"Application"]
|
|
104
146
|
autorelease];
|
|
105
|
-
if ([
|
|
106
|
-
[
|
|
147
|
+
if ([NSApp respondsToSelector: @selector(setAppleMenu:)])
|
|
148
|
+
[NSApp performSelector: @selector(setAppleMenu:) withObject: menu];
|
|
107
149
|
|
|
108
|
-
NSString* name = !
|
|
109
|
-
[NSString stringWithUTF8String:
|
|
150
|
+
NSString* name = !REF->self->name.empty() ?
|
|
151
|
+
[NSString stringWithUTF8String: REF->self->name.c_str()] : @"";
|
|
110
152
|
if ([name length] > 0)
|
|
111
153
|
name = [@" " stringByAppendingString: name];
|
|
112
154
|
|
|
@@ -115,14 +157,14 @@
|
|
|
115
157
|
|
|
116
158
|
[menu
|
|
117
159
|
addItemWithTitle: [@"About" stringByAppendingString: name]
|
|
118
|
-
action: @selector(
|
|
160
|
+
action: @selector(showAbout)
|
|
119
161
|
keyEquivalent: @""];
|
|
120
162
|
|
|
121
163
|
[menu addItem: [NSMenuItem separatorItem]];
|
|
122
164
|
|
|
123
165
|
[menu
|
|
124
166
|
addItemWithTitle: @"Preferences"
|
|
125
|
-
action: @selector(
|
|
167
|
+
action: @selector(showPreference)
|
|
126
168
|
keyEquivalent: @","];
|
|
127
169
|
|
|
128
170
|
[menu addItem: [NSMenuItem separatorItem]];
|
|
@@ -133,7 +175,7 @@
|
|
|
133
175
|
keyEquivalent: @""];
|
|
134
176
|
submenu = [[[NSMenu alloc] initWithTitle: @"Services"] autorelease];
|
|
135
177
|
[item setSubmenu: submenu];
|
|
136
|
-
[
|
|
178
|
+
[NSApp setServicesMenu: submenu];
|
|
137
179
|
|
|
138
180
|
[menu addItem: [NSMenuItem separatorItem]];
|
|
139
181
|
|
|
@@ -196,14 +238,14 @@
|
|
|
196
238
|
[parent addItemWithTitle: @"Window" action: nil keyEquivalent: @""];
|
|
197
239
|
[parent setSubmenu: menu forItem: item];
|
|
198
240
|
|
|
199
|
-
[
|
|
241
|
+
[NSApp setWindowsMenu: menu];
|
|
200
242
|
|
|
201
243
|
return YES;
|
|
202
244
|
}
|
|
203
245
|
|
|
204
246
|
- (BOOL) setupMenu
|
|
205
247
|
{
|
|
206
|
-
if ([
|
|
248
|
+
if ([NSApp mainMenu]) return NO;
|
|
207
249
|
|
|
208
250
|
NSMenu* menu = [[[NSMenu alloc] initWithTitle: @"MainMenu"] autorelease];
|
|
209
251
|
|
|
@@ -214,9 +256,9 @@
|
|
|
214
256
|
return NO;
|
|
215
257
|
}
|
|
216
258
|
|
|
217
|
-
[
|
|
259
|
+
[NSApp setMainMenu: menu];
|
|
218
260
|
|
|
219
261
|
return YES;
|
|
220
262
|
}
|
|
221
263
|
|
|
222
|
-
@end//
|
|
264
|
+
@end// AppDelegate
|
|
@@ -0,0 +1,132 @@
|
|
|
1
|
+
// -*- objc -*-
|
|
2
|
+
#include "reflex/application.h"
|
|
3
|
+
|
|
4
|
+
|
|
5
|
+
#include <assert.h>
|
|
6
|
+
#import <AppKit/NSApplication.h>
|
|
7
|
+
#include "reflex/exception.h"
|
|
8
|
+
#include "application_data.h"
|
|
9
|
+
#import "app_delegate.h"
|
|
10
|
+
|
|
11
|
+
|
|
12
|
+
namespace Reflex
|
|
13
|
+
{
|
|
14
|
+
|
|
15
|
+
|
|
16
|
+
bool initialized ();
|
|
17
|
+
|
|
18
|
+
|
|
19
|
+
static Application* instance = NULL;
|
|
20
|
+
|
|
21
|
+
|
|
22
|
+
Application*
|
|
23
|
+
app ()
|
|
24
|
+
{
|
|
25
|
+
return instance;
|
|
26
|
+
}
|
|
27
|
+
|
|
28
|
+
|
|
29
|
+
Application::Application ()
|
|
30
|
+
{
|
|
31
|
+
if (!initialized() || !NSApp)
|
|
32
|
+
reflex_error(__FILE__, __LINE__, "not initialized.");
|
|
33
|
+
|
|
34
|
+
if (instance)
|
|
35
|
+
reflex_error(__FILE__, __LINE__, "multiple application instances.");
|
|
36
|
+
|
|
37
|
+
AppDelegate* delegate = (AppDelegate*) [NSApp delegate];
|
|
38
|
+
if (!delegate)
|
|
39
|
+
invalid_state_error(__FILE__, __LINE__);
|
|
40
|
+
|
|
41
|
+
[delegate bind: this];
|
|
42
|
+
|
|
43
|
+
instance = this;
|
|
44
|
+
}
|
|
45
|
+
|
|
46
|
+
Application::~Application ()
|
|
47
|
+
{
|
|
48
|
+
instance = NULL;
|
|
49
|
+
}
|
|
50
|
+
|
|
51
|
+
void
|
|
52
|
+
Application::start ()
|
|
53
|
+
{
|
|
54
|
+
if (!*this)
|
|
55
|
+
invalid_state_error(__FILE__, __LINE__);
|
|
56
|
+
|
|
57
|
+
[NSApp run];
|
|
58
|
+
}
|
|
59
|
+
|
|
60
|
+
void
|
|
61
|
+
Application::quit ()
|
|
62
|
+
{
|
|
63
|
+
if (!*this)
|
|
64
|
+
invalid_state_error(__FILE__, __LINE__);
|
|
65
|
+
|
|
66
|
+
[NSApp terminate: nil];
|
|
67
|
+
}
|
|
68
|
+
|
|
69
|
+
void
|
|
70
|
+
Application::set_name (const char* name)
|
|
71
|
+
{
|
|
72
|
+
if (!name)
|
|
73
|
+
argument_error(__FILE__, __LINE__);
|
|
74
|
+
|
|
75
|
+
if (!*this)
|
|
76
|
+
invalid_state_error(__FILE__, __LINE__);
|
|
77
|
+
|
|
78
|
+
self->name = name;
|
|
79
|
+
}
|
|
80
|
+
|
|
81
|
+
const char*
|
|
82
|
+
Application::name () const
|
|
83
|
+
{
|
|
84
|
+
if (!*this)
|
|
85
|
+
invalid_state_error(__FILE__, __LINE__);
|
|
86
|
+
|
|
87
|
+
return self->name.c_str();
|
|
88
|
+
}
|
|
89
|
+
|
|
90
|
+
void
|
|
91
|
+
Application::on_start (Event* e)
|
|
92
|
+
{
|
|
93
|
+
if (!*this)
|
|
94
|
+
invalid_state_error(__FILE__, __LINE__);
|
|
95
|
+
}
|
|
96
|
+
|
|
97
|
+
void
|
|
98
|
+
Application::on_quit (Event* e)
|
|
99
|
+
{
|
|
100
|
+
if (!*this)
|
|
101
|
+
invalid_state_error(__FILE__, __LINE__);
|
|
102
|
+
}
|
|
103
|
+
|
|
104
|
+
void
|
|
105
|
+
Application::on_preference (Event* e)
|
|
106
|
+
{
|
|
107
|
+
if (!*this)
|
|
108
|
+
invalid_state_error(__FILE__, __LINE__);
|
|
109
|
+
}
|
|
110
|
+
|
|
111
|
+
void
|
|
112
|
+
Application::on_about (Event* e)
|
|
113
|
+
{
|
|
114
|
+
if (!*this)
|
|
115
|
+
invalid_state_error(__FILE__, __LINE__);
|
|
116
|
+
|
|
117
|
+
[NSApp orderFrontStandardAboutPanel: nil];
|
|
118
|
+
}
|
|
119
|
+
|
|
120
|
+
Application::operator bool () const
|
|
121
|
+
{
|
|
122
|
+
return self && *self;
|
|
123
|
+
}
|
|
124
|
+
|
|
125
|
+
bool
|
|
126
|
+
Application::operator ! () const
|
|
127
|
+
{
|
|
128
|
+
return !operator bool();
|
|
129
|
+
}
|
|
130
|
+
|
|
131
|
+
|
|
132
|
+
}// Reflex
|
|
@@ -0,0 +1,45 @@
|
|
|
1
|
+
// -*- c++ -*-
|
|
2
|
+
#pragma once
|
|
3
|
+
#ifndef __REFLEX_OSX_APPLICATION_DATA_H__
|
|
4
|
+
#define __REFLEX_OSX_APPLICATION_DATA_H__
|
|
5
|
+
|
|
6
|
+
|
|
7
|
+
#include <reflex/application.h>
|
|
8
|
+
|
|
9
|
+
|
|
10
|
+
@class AppDelegate;
|
|
11
|
+
|
|
12
|
+
|
|
13
|
+
namespace Reflex
|
|
14
|
+
{
|
|
15
|
+
|
|
16
|
+
|
|
17
|
+
struct Application::Data
|
|
18
|
+
{
|
|
19
|
+
|
|
20
|
+
AppDelegate* delegate;
|
|
21
|
+
|
|
22
|
+
String name;
|
|
23
|
+
|
|
24
|
+
Data ()
|
|
25
|
+
: delegate(nil)
|
|
26
|
+
{
|
|
27
|
+
}
|
|
28
|
+
|
|
29
|
+
operator bool () const
|
|
30
|
+
{
|
|
31
|
+
return delegate;
|
|
32
|
+
}
|
|
33
|
+
|
|
34
|
+
bool operator ! () const
|
|
35
|
+
{
|
|
36
|
+
return !operator bool();
|
|
37
|
+
}
|
|
38
|
+
|
|
39
|
+
};// Application::Data
|
|
40
|
+
|
|
41
|
+
|
|
42
|
+
}// Reflex
|
|
43
|
+
|
|
44
|
+
|
|
45
|
+
#endif//EOH
|
data/src/osx/event.h
ADDED
|
@@ -0,0 +1,42 @@
|
|
|
1
|
+
// -*- c++ -*-
|
|
2
|
+
#pragma once
|
|
3
|
+
#ifndef __REFLEX_OSX_EVENT_H__
|
|
4
|
+
#define __REFLEX_OSX_EVENT_H__
|
|
5
|
+
|
|
6
|
+
|
|
7
|
+
#import <AppKit/NSEvent.h>
|
|
8
|
+
#include <reflex/event.h>
|
|
9
|
+
|
|
10
|
+
|
|
11
|
+
namespace Reflex
|
|
12
|
+
{
|
|
13
|
+
|
|
14
|
+
|
|
15
|
+
struct NativeKeyEvent : public KeyEvent
|
|
16
|
+
{
|
|
17
|
+
|
|
18
|
+
NativeKeyEvent (NSEvent* event, Type type);
|
|
19
|
+
|
|
20
|
+
};// NativeKeyEvent
|
|
21
|
+
|
|
22
|
+
|
|
23
|
+
struct NativePointerEvent : public PointerEvent
|
|
24
|
+
{
|
|
25
|
+
|
|
26
|
+
NativePointerEvent (NSEvent* event, NSView* view, Type type);
|
|
27
|
+
|
|
28
|
+
};// NativePointerEvent
|
|
29
|
+
|
|
30
|
+
|
|
31
|
+
struct NativeWheelEvent : public WheelEvent
|
|
32
|
+
{
|
|
33
|
+
|
|
34
|
+
NativeWheelEvent (NSEvent* event, NSView* view);
|
|
35
|
+
|
|
36
|
+
};// NativeWheelEvent
|
|
37
|
+
|
|
38
|
+
|
|
39
|
+
}// Reflex
|
|
40
|
+
|
|
41
|
+
|
|
42
|
+
#endif//EOH
|
data/src/osx/event.mm
ADDED
|
@@ -0,0 +1,112 @@
|
|
|
1
|
+
// -*- c++ -*-
|
|
2
|
+
#include "event.h"
|
|
3
|
+
|
|
4
|
+
|
|
5
|
+
#include <assert.h>
|
|
6
|
+
#import <Cocoa/Cocoa.h>
|
|
7
|
+
|
|
8
|
+
|
|
9
|
+
namespace Reflex
|
|
10
|
+
{
|
|
11
|
+
|
|
12
|
+
|
|
13
|
+
static const char*
|
|
14
|
+
get_chars (NSEvent* e)
|
|
15
|
+
{
|
|
16
|
+
NSString* chars = [e characters];//charactersIgnoringModifiers];
|
|
17
|
+
return [chars UTF8String];
|
|
18
|
+
}
|
|
19
|
+
|
|
20
|
+
static uint
|
|
21
|
+
get_current_pointer_type ()
|
|
22
|
+
{
|
|
23
|
+
NSUInteger buttons = [NSEvent pressedMouseButtons];
|
|
24
|
+
uint ret = 0;
|
|
25
|
+
if (buttons & (1 << 0)) ret |= POINTER_MOUSE_LEFT;
|
|
26
|
+
if (buttons & (1 << 1)) ret |= POINTER_MOUSE_RIGHT;
|
|
27
|
+
if (buttons >= (1 << 2)) ret |= POINTER_MOUSE_MIDDLE;
|
|
28
|
+
return ret;
|
|
29
|
+
}
|
|
30
|
+
|
|
31
|
+
static uint
|
|
32
|
+
get_pointer_type (NSEvent* e)
|
|
33
|
+
{
|
|
34
|
+
switch ([e type])
|
|
35
|
+
{
|
|
36
|
+
case NSLeftMouseDown:
|
|
37
|
+
case NSLeftMouseUp:
|
|
38
|
+
case NSLeftMouseDragged:
|
|
39
|
+
return POINTER_MOUSE_LEFT;
|
|
40
|
+
|
|
41
|
+
case NSRightMouseDown:
|
|
42
|
+
case NSRightMouseUp:
|
|
43
|
+
case NSRightMouseDragged:
|
|
44
|
+
return POINTER_MOUSE_RIGHT;
|
|
45
|
+
|
|
46
|
+
case NSOtherMouseDown:
|
|
47
|
+
case NSOtherMouseUp:
|
|
48
|
+
case NSOtherMouseDragged:
|
|
49
|
+
return POINTER_MOUSE_MIDDLE;
|
|
50
|
+
|
|
51
|
+
case NSMouseMoved:
|
|
52
|
+
return get_current_pointer_type();
|
|
53
|
+
}
|
|
54
|
+
return 0;
|
|
55
|
+
}
|
|
56
|
+
|
|
57
|
+
static uint
|
|
58
|
+
get_modifiers (const NSEvent* e)
|
|
59
|
+
{
|
|
60
|
+
NSUInteger flags = [e modifierFlags];
|
|
61
|
+
return
|
|
62
|
+
(flags & NSAlphaShiftKeyMask) ? MOD_CAPS : 0 |
|
|
63
|
+
(flags & NSShiftKeyMask) ? MOD_SHIFT : 0 |
|
|
64
|
+
(flags & NSControlKeyMask) ? MOD_CONTROL : 0 |
|
|
65
|
+
(flags & NSAlternateKeyMask) ? MOD_ALT : 0 |
|
|
66
|
+
(flags & NSCommandKeyMask) ? MOD_COMMAND : 0 |
|
|
67
|
+
(flags & NSNumericPadKeyMask) ? MOD_NUMPAD : 0 |
|
|
68
|
+
(flags & NSHelpKeyMask) ? MOD_HELP : 0 |
|
|
69
|
+
(flags & NSFunctionKeyMask) ? MOD_FUNCTION : 0;
|
|
70
|
+
}
|
|
71
|
+
|
|
72
|
+
static NSPoint
|
|
73
|
+
correct_point (NSView* view, const NSPoint& point)
|
|
74
|
+
{
|
|
75
|
+
assert(view);
|
|
76
|
+
NSPoint p = [view convertPoint: point fromView: nil];
|
|
77
|
+
p.y = [view bounds].size.height - p.y;
|
|
78
|
+
return p;
|
|
79
|
+
}
|
|
80
|
+
|
|
81
|
+
|
|
82
|
+
NativeKeyEvent::NativeKeyEvent (NSEvent* e, Type type)
|
|
83
|
+
: KeyEvent(
|
|
84
|
+
type, get_chars(e), [e keyCode], get_modifiers(e), [e isARepeat] ? 1 : 0)
|
|
85
|
+
{
|
|
86
|
+
}
|
|
87
|
+
|
|
88
|
+
|
|
89
|
+
NativePointerEvent::NativePointerEvent (NSEvent* e, NSView* view, Type type)
|
|
90
|
+
: PointerEvent(
|
|
91
|
+
type, get_pointer_type(e), (coord) 0, (coord) 0,
|
|
92
|
+
get_modifiers(e), (uint) [e clickCount],
|
|
93
|
+
[e type] == NSLeftMouseDragged || [e type] == NSRightMouseDragged || [e type] == NSOtherMouseDragged)
|
|
94
|
+
{
|
|
95
|
+
NSPoint p = correct_point(view, [e locationInWindow]);
|
|
96
|
+
x = p.x;
|
|
97
|
+
y = p.y;
|
|
98
|
+
}
|
|
99
|
+
|
|
100
|
+
|
|
101
|
+
NativeWheelEvent::NativeWheelEvent (NSEvent* e, NSView* view)
|
|
102
|
+
: WheelEvent([e deltaX], [e deltaY], [e deltaZ])
|
|
103
|
+
{
|
|
104
|
+
NSPoint p = correct_point(view, [e locationInWindow]);
|
|
105
|
+
x = p.x;
|
|
106
|
+
y = p.y;
|
|
107
|
+
z = 0;
|
|
108
|
+
modifiers = get_modifiers(e);
|
|
109
|
+
}
|
|
110
|
+
|
|
111
|
+
|
|
112
|
+
};// Reflex
|
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
// -*- objc -*-
|
|
2
|
+
#import <AppKit/NSWindow.h>
|
|
3
|
+
#include <reflex/window.h>
|
|
4
|
+
|
|
5
|
+
|
|
6
|
+
@class OpenGLView;
|
|
7
|
+
|
|
8
|
+
|
|
9
|
+
@interface NativeWindow : NSWindow <NSWindowDelegate>
|
|
10
|
+
|
|
11
|
+
{
|
|
12
|
+
@private
|
|
13
|
+
Reflex::Window::Ref* pref;
|
|
14
|
+
OpenGLView* view;
|
|
15
|
+
NSTimer* timer;
|
|
16
|
+
}
|
|
17
|
+
|
|
18
|
+
- (void) bind: (Reflex::Window*) instance;
|
|
19
|
+
|
|
20
|
+
- (void) unbind: (Reflex::Window*) instance;
|
|
21
|
+
|
|
22
|
+
- (void) draw;
|
|
23
|
+
|
|
24
|
+
+ (NSRect) frameRectForContentRect: (NSRect) contentRect;
|
|
25
|
+
|
|
26
|
+
@end// NativeWindow
|