reflexion 0.1.6 → 0.1.7

Sign up to get free protection for your applications and to get access to all the features.
Files changed (225) hide show
  1. checksums.yaml +7 -0
  2. data/.doc/ext/reflex/application.cpp +54 -39
  3. data/.doc/ext/reflex/capture_event.cpp +87 -0
  4. data/.doc/ext/reflex/draw_event.cpp +103 -0
  5. data/.doc/ext/reflex/event.cpp +73 -0
  6. data/.doc/ext/reflex/focus_event.cpp +98 -0
  7. data/.doc/ext/reflex/frame_event.cpp +133 -0
  8. data/.doc/ext/reflex/image_view.cpp +74 -0
  9. data/.doc/ext/reflex/key_event.cpp +124 -0
  10. data/.doc/ext/reflex/native.cpp +45 -6
  11. data/.doc/ext/reflex/pointer_event.cpp +181 -0
  12. data/.doc/ext/reflex/reflex.cpp +17 -41
  13. data/.doc/ext/reflex/scroll_event.cpp +141 -0
  14. data/.doc/ext/reflex/selector.cpp +135 -0
  15. data/.doc/ext/reflex/style.cpp +253 -0
  16. data/.doc/ext/reflex/style_length.cpp +133 -0
  17. data/.doc/ext/reflex/style_length2.cpp +149 -0
  18. data/.doc/ext/reflex/style_length4.cpp +192 -0
  19. data/.doc/ext/reflex/update_event.cpp +77 -0
  20. data/.doc/ext/reflex/view.cpp +408 -88
  21. data/.doc/ext/reflex/wheel_event.cpp +146 -0
  22. data/.doc/ext/reflex/window.cpp +95 -92
  23. data/Rakefile +6 -5
  24. data/VERSION +1 -1
  25. data/ext/reflex/application.cpp +67 -49
  26. data/ext/reflex/capture_event.cpp +92 -0
  27. data/ext/reflex/draw_event.cpp +110 -0
  28. data/ext/reflex/event.cpp +77 -0
  29. data/ext/reflex/extconf.rb +18 -68
  30. data/ext/reflex/focus_event.cpp +104 -0
  31. data/ext/reflex/frame_event.cpp +143 -0
  32. data/ext/reflex/image_view.cpp +77 -0
  33. data/ext/reflex/key_event.cpp +133 -0
  34. data/ext/reflex/native.cpp +45 -6
  35. data/ext/reflex/pointer_event.cpp +195 -0
  36. data/ext/reflex/reflex.cpp +21 -47
  37. data/ext/reflex/scroll_event.cpp +152 -0
  38. data/ext/reflex/selector.cpp +144 -0
  39. data/ext/reflex/style.cpp +277 -0
  40. data/ext/reflex/style_length.cpp +140 -0
  41. data/ext/reflex/style_length2.cpp +157 -0
  42. data/ext/reflex/style_length4.cpp +204 -0
  43. data/ext/reflex/update_event.cpp +81 -0
  44. data/ext/reflex/view.cpp +469 -114
  45. data/ext/reflex/wheel_event.cpp +158 -0
  46. data/ext/reflex/window.cpp +130 -123
  47. data/include/reflex/application.h +12 -7
  48. data/include/reflex/defs.h +13 -89
  49. data/include/reflex/event.h +260 -0
  50. data/include/reflex/exception.h +17 -11
  51. data/include/reflex/image_view.h +45 -0
  52. data/include/reflex/reflex.h +2 -6
  53. data/include/reflex/ruby/application.h +40 -13
  54. data/include/reflex/ruby/event.h +72 -0
  55. data/include/reflex/ruby/image_view.h +25 -0
  56. data/include/reflex/ruby/selector.h +27 -0
  57. data/include/reflex/ruby/style.h +27 -0
  58. data/include/reflex/ruby/style_length.h +37 -0
  59. data/include/reflex/ruby/view.h +193 -38
  60. data/include/reflex/ruby/window.h +123 -39
  61. data/include/reflex/ruby.h +3 -2
  62. data/include/reflex/selector.h +64 -0
  63. data/include/reflex/style.h +144 -0
  64. data/include/reflex/style_length.h +147 -0
  65. data/include/reflex/view.h +182 -19
  66. data/include/reflex/window.h +35 -19
  67. data/include/reflex.h +7 -0
  68. data/lib/reflex/application.rb +14 -5
  69. data/lib/reflex/arc_shape.rb +20 -0
  70. data/lib/reflex/button.rb +75 -0
  71. data/lib/reflex/capture_event.rb +37 -0
  72. data/lib/reflex/color.rb +13 -0
  73. data/lib/reflex/color_space.rb +13 -0
  74. data/lib/reflex/draw_event.rb +19 -0
  75. data/lib/reflex/ellipse_shape.rb +20 -0
  76. data/lib/reflex/ext.rb +1 -1
  77. data/lib/reflex/flags.rb +18 -0
  78. data/lib/reflex/focus_event.rb +38 -0
  79. data/lib/reflex/font.rb +13 -0
  80. data/lib/reflex/frame_event.rb +42 -0
  81. data/lib/reflex/helper.rb +87 -30
  82. data/lib/reflex/image_view.rb +25 -0
  83. data/lib/reflex/key_event.rb +38 -0
  84. data/lib/reflex/line_shape.rb +20 -0
  85. data/lib/reflex/list_view.rb +15 -0
  86. data/lib/reflex/model.rb +149 -0
  87. data/lib/reflex/model_owner.rb +57 -0
  88. data/lib/reflex/model_view.rb +22 -0
  89. data/lib/reflex/module.rb +11 -7
  90. data/lib/reflex/pointer_event.rb +85 -0
  91. data/lib/reflex/rect_shape.rb +20 -0
  92. data/lib/reflex/reflex.rb +13 -2
  93. data/lib/reflex/scroll_event.rb +19 -0
  94. data/lib/reflex/selector.rb +31 -0
  95. data/lib/reflex/shader.rb +13 -0
  96. data/lib/reflex/shape.rb +34 -0
  97. data/lib/reflex/style.rb +55 -0
  98. data/lib/reflex/style_length.rb +30 -0
  99. data/lib/reflex/style_length2.rb +34 -0
  100. data/lib/reflex/style_length4.rb +38 -0
  101. data/lib/reflex/text_view.rb +55 -0
  102. data/lib/reflex/update_event.rb +19 -0
  103. data/lib/reflex/view.rb +38 -4
  104. data/lib/reflex/wheel_event.rb +19 -0
  105. data/lib/reflex/window.rb +7 -5
  106. data/lib/reflex.rb +38 -1
  107. data/lib/reflexion/include.rb +5 -0
  108. data/lib/reflexion.rb +100 -0
  109. data/reflex.gemspec +3 -4
  110. data/samples/app.rb +13 -0
  111. data/samples/bats.rb +91 -0
  112. data/samples/checker.rb +36 -0
  113. data/{examples/ruby/shapes.rb → samples/fans.rb} +12 -16
  114. data/samples/fps.rb +46 -0
  115. data/samples/grid.rb +60 -0
  116. data/{examples/ruby → samples}/hello.rb +14 -16
  117. data/samples/image.rb +44 -0
  118. data/samples/ios/hello/hello/Images.xcassets/AppIcon.appiconset/Contents.json +53 -0
  119. data/samples/ios/hello/hello/Images.xcassets/LaunchImage.launchimage/Contents.json +51 -0
  120. data/samples/ios/hello/hello/en.lproj/InfoPlist.strings +2 -0
  121. data/samples/ios/hello/hello/hello-Info.plist +47 -0
  122. data/samples/ios/hello/hello/hello-Prefix.pch +10 -0
  123. data/samples/ios/hello/hello/main.cpp +79 -0
  124. data/samples/ios/hello/hello.xcodeproj/project.pbxproj +725 -0
  125. data/{examples/ruby → samples}/key.rb +11 -14
  126. data/samples/layout.rb +89 -0
  127. data/samples/model.rb +86 -0
  128. data/samples/osx/hello/hello/Images.xcassets/AppIcon.appiconset/Contents.json +58 -0
  129. data/samples/osx/hello/hello/en.lproj/Credits.rtf +29 -0
  130. data/samples/osx/hello/hello/en.lproj/InfoPlist.strings +2 -0
  131. data/samples/osx/hello/hello/hello-Info.plist +32 -0
  132. data/samples/osx/hello/hello/hello-Prefix.pch +3 -0
  133. data/samples/osx/hello/hello/main.cpp +79 -0
  134. data/samples/osx/hello/hello.xcodeproj/project.pbxproj +725 -0
  135. data/samples/reflexion/hello.rb +24 -0
  136. data/samples/reflexion/paint.rb +40 -0
  137. data/samples/reflexion/pulse.rb +34 -0
  138. data/samples/repl.rb +69 -0
  139. data/samples/shader.rb +41 -0
  140. data/samples/shapes.rb +30 -0
  141. data/{examples/ruby → samples}/text.rb +7 -8
  142. data/samples/tree.rb +71 -0
  143. data/samples/views.rb +41 -0
  144. data/samples/visuals.rb +22 -0
  145. data/src/event.cpp +225 -0
  146. data/src/exception.cpp +24 -15
  147. data/src/image_view.cpp +70 -0
  148. data/src/ios/app_delegate.h +17 -0
  149. data/src/ios/app_delegate.mm +120 -0
  150. data/src/ios/application.mm +116 -0
  151. data/src/{cocoa/applicationdata.h → ios/application_data.h} +6 -6
  152. data/src/ios/event.h +26 -0
  153. data/src/ios/event.mm +31 -0
  154. data/src/ios/native_window.h +37 -0
  155. data/src/ios/native_window.mm +220 -0
  156. data/src/ios/opengl_view.h +13 -0
  157. data/src/ios/opengl_view.mm +131 -0
  158. data/src/{cocoa → ios}/reflex.mm +8 -12
  159. data/src/ios/window.mm +303 -0
  160. data/src/ios/window_data.h +75 -0
  161. data/src/osx/app_delegate.h +17 -0
  162. data/src/{cocoa/cocoaapplication.mm → osx/app_delegate.mm} +90 -48
  163. data/src/osx/application.mm +132 -0
  164. data/src/osx/application_data.h +45 -0
  165. data/src/osx/event.h +42 -0
  166. data/src/osx/event.mm +112 -0
  167. data/src/osx/native_window.h +26 -0
  168. data/src/osx/native_window.mm +322 -0
  169. data/src/{cocoa/openglview.h → osx/opengl_view.h} +0 -4
  170. data/src/{cocoa/openglview.mm → osx/opengl_view.mm} +66 -23
  171. data/src/osx/reflex.mm +50 -0
  172. data/src/osx/window.mm +308 -0
  173. data/src/osx/window_data.h +75 -0
  174. data/src/selector.cpp +121 -0
  175. data/src/style.cpp +576 -0
  176. data/src/style_length.cpp +341 -0
  177. data/src/view.cpp +1228 -129
  178. data/src/win32/application.cpp +1 -1
  179. data/src/window.cpp +54 -26
  180. data/test/helper.rb +8 -4
  181. data/test/test_capture_event.rb +41 -0
  182. data/test/test_event.rb +20 -0
  183. data/test/test_has_frame.rb +45 -0
  184. data/test/test_model.rb +9 -0
  185. data/test/test_model_owner.rb +9 -0
  186. data/test/test_selector.rb +75 -0
  187. data/test/test_style.rb +70 -0
  188. data/test/test_style_length.rb +38 -0
  189. data/test/test_style_length2.rb +50 -0
  190. data/test/test_style_length4.rb +56 -0
  191. data/test/test_view.rb +97 -23
  192. data/test/test_window.rb +54 -46
  193. metadata +205 -84
  194. data/.doc/ext/reflex/defs.cpp +0 -8
  195. data/.doc/ext/reflex/key.cpp +0 -122
  196. data/.doc/ext/reflex/points.cpp +0 -151
  197. data/.gitignore +0 -14
  198. data/ChangeLog +0 -8
  199. data/examples/hello/.gitignore +0 -2
  200. data/examples/hello/Rakefile +0 -41
  201. data/examples/hello/main.cpp +0 -18
  202. data/examples/ruby/app.rb +0 -13
  203. data/examples/ruby/checker.rb +0 -41
  204. data/examples/ruby/fps.rb +0 -49
  205. data/examples/ruby/grid.rb +0 -65
  206. data/examples/ruby/views.rb +0 -88
  207. data/examples/ruby/visuals.rb +0 -27
  208. data/ext/reflex/defs.cpp +0 -8
  209. data/ext/reflex/key.cpp +0 -129
  210. data/ext/reflex/points.cpp +0 -161
  211. data/include/reflex/ruby/key.h +0 -39
  212. data/include/reflex/ruby/points.h +0 -39
  213. data/lib/reflex/visuals/string.rb +0 -53
  214. data/src/cocoa/application.mm +0 -101
  215. data/src/cocoa/cocoaapplication.h +0 -21
  216. data/src/cocoa/cocoawindow.h +0 -46
  217. data/src/cocoa/cocoawindow.mm +0 -230
  218. data/src/cocoa/defs.h +0 -34
  219. data/src/cocoa/defs.mm +0 -87
  220. data/src/cocoa/window.mm +0 -148
  221. data/src/cocoa/windowdata.h +0 -56
  222. data/src/defs.cpp +0 -47
  223. data/src/helper.h +0 -12
  224. data/src/reflex.cpp +0 -43
  225. /data/{README → README.md} +0 -0
@@ -1,24 +1,24 @@
1
1
  // -*- objc -*-
2
- #import "cocoaapplication.h"
2
+ #import "app_delegate.h"
3
3
 
4
4
 
5
5
  #include <assert.h>
6
6
  #import <Cocoa/Cocoa.h>
7
- #include <reflex/reflex.h>
8
- #include "applicationdata.h"
7
+ #include "reflex/event.h"
8
+ #include "reflex/exception.h"
9
+ #include "application_data.h"
9
10
 
10
11
 
11
- @implementation CocoaApplication
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
- [self unbind];
29
+ assert(pref && !REF);
30
+
30
31
  delete pref;
31
32
 
32
33
  [super dealloc];
33
34
  }
34
35
 
35
- - (BOOL) bind: (Reflex::Application*) instance
36
+ - (void) bind: (Reflex::Application*) instance
36
37
  {
37
- if (instance && instance->self->cocoa)
38
- return NO;
38
+ assert(pref);
39
39
 
40
- [self unbind];
40
+ if (instance && instance->self->delegate)
41
+ Reflex::argument_error(__FILE__, __LINE__);
41
42
 
42
- assert(pref);
43
- Reflex::Application::Ref& ref = *pref;
43
+ if (REF)
44
+ Reflex::invalid_state_error(__FILE__, __LINE__);
44
45
 
45
- ref = instance;
46
- if (ref) ref->self->cocoa = [self retain];
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 (ref->self->cocoa) [ref->self->cocoa release];
57
- ref->self->cocoa = nil;
58
- ref.reset();
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 (*pref)
66
- (*pref)->quit();
68
+ if (REF)
69
+ REF->quit();
67
70
  else
68
- Reflex::quit();
71
+ [NSApp terminate: nil];
69
72
  }
70
73
 
71
- - (void) about
74
+ - (void) showPreference
72
75
  {
73
76
  assert(pref);
74
77
 
75
- if (*pref)
76
- (*pref)->about();
77
- else
78
- [self orderFrontStandardAboutPanel: nil];
78
+ if (REF)
79
+ {
80
+ Reflex::Event e;
81
+ REF->on_preference(&e);
82
+ }
79
83
  }
80
84
 
81
- - (BOOL) applicationShouldTerminateAfterLastWindowClosed: (NSApplication*) app
85
+ - (void) showAbout
82
86
  {
83
- return YES;
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 ([self respondsToSelector: @selector(setAppleMenu:)])
106
- [self performSelector: @selector(setAppleMenu:) withObject: menu];
147
+ if ([NSApp respondsToSelector: @selector(setAppleMenu:)])
148
+ [NSApp performSelector: @selector(setAppleMenu:) withObject: menu];
107
149
 
108
- NSString* name = !(*pref)->self->name.empty() ?
109
- [NSString stringWithUTF8String: (*pref)->self->name.c_str()] : @"";
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(about)
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(preference:)
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
- [self setServicesMenu: submenu];
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
- [self setWindowsMenu: menu];
241
+ [NSApp setWindowsMenu: menu];
200
242
 
201
243
  return YES;
202
244
  }
203
245
 
204
246
  - (BOOL) setupMenu
205
247
  {
206
- if ([self mainMenu]) return NO;
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
- [self setMainMenu: menu];
259
+ [NSApp setMainMenu: menu];
218
260
 
219
261
  return YES;
220
262
  }
221
263
 
222
- @end// CocoaApplication
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