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
@@ -0,0 +1,322 @@
1
+ // -*- objc -*-
2
+ #import "native_window.h"
3
+
4
+
5
+ #include <assert.h>
6
+ #import <Cocoa/Cocoa.h>
7
+ #include <rays/bounds.h>
8
+ #include "reflex/window.h"
9
+ #include "reflex/exception.h"
10
+ #include "event.h"
11
+ #include "window_data.h"
12
+ #import "opengl_view.h"
13
+
14
+
15
+ #define REF (*pref)
16
+
17
+
18
+ static const NSUInteger WINDOW_STYLE_MASK =
19
+ NSTitledWindowMask |
20
+ NSClosableWindowMask |
21
+ NSMiniaturizableWindowMask |
22
+ NSResizableWindowMask |
23
+ 0;//NSTexturedBackgroundWindowMask
24
+
25
+
26
+ @implementation NativeWindow
27
+
28
+ - (id) init
29
+ {
30
+ self = [super
31
+ initWithContentRect: NSMakeRect(0, 0, 0, 0)
32
+ styleMask: WINDOW_STYLE_MASK
33
+ backing: NSBackingStoreBuffered
34
+ defer: NO];
35
+ if (!self) return nil;
36
+
37
+ pref = new Reflex::Window::Ref;
38
+ view = nil;
39
+ timer = nil;
40
+
41
+ [self setDelegate: self];
42
+ [self setupContentView];
43
+ [self startTimer: 60];
44
+
45
+ return self;
46
+ }
47
+
48
+ - (void) dealloc
49
+ {
50
+ assert(pref && !REF);
51
+
52
+ if (view) [view release];
53
+
54
+ delete pref;
55
+
56
+ [super dealloc];
57
+ }
58
+
59
+ - (void) bind: (Reflex::Window*) instance
60
+ {
61
+ assert(pref);
62
+
63
+ if (instance && instance->self->native)
64
+ Reflex::argument_error(__FILE__, __LINE__);
65
+
66
+ if (REF)
67
+ Reflex::invalid_state_error(__FILE__, __LINE__);
68
+
69
+ REF = instance;
70
+ if (REF) REF->self->native = [self retain];
71
+ }
72
+
73
+ - (void) unbind: (Reflex::Window*) instance
74
+ {
75
+ assert(pref);
76
+
77
+ if (!REF) return;
78
+
79
+ if (instance && instance != REF.get())
80
+ Reflex::invalid_state_error(__FILE__, __LINE__);
81
+
82
+ if (REF->self->native) [REF->self->native release];
83
+ REF->self->native = nil;
84
+ REF.reset();
85
+ }
86
+
87
+ - (void) setupContentView
88
+ {
89
+ NSRect rect = [self contentRectForFrameRect: [self frame]];
90
+ rect.origin.x = rect.origin.y = 0;
91
+ view = [[OpenGLView alloc] initWithFrame: rect];
92
+ [self setContentView: view];
93
+ }
94
+
95
+ - (void) startTimer: (int) fps
96
+ {
97
+ [self stopTimer];
98
+
99
+ if (fps <= 0) return;
100
+
101
+ timer = [[NSTimer
102
+ timerWithTimeInterval: 1. / (double) fps
103
+ target: self
104
+ selector: @selector(update:)
105
+ userInfo: nil
106
+ repeats: YES] retain];
107
+ if (!timer) return;
108
+
109
+ [[NSRunLoop currentRunLoop]
110
+ addTimer: timer forMode: NSDefaultRunLoopMode];
111
+ [[NSRunLoop currentRunLoop]
112
+ addTimer: timer forMode: NSEventTrackingRunLoopMode];
113
+ }
114
+
115
+ - (void) stopTimer
116
+ {
117
+ if (!timer) return;
118
+
119
+ [timer invalidate];
120
+ timer = nil;
121
+ }
122
+
123
+ - (void) update: (NSTimer*) t
124
+ {
125
+ assert(pref);
126
+
127
+ if (!REF) return;
128
+
129
+ double now = Xot::time();
130
+ Reflex::UpdateEvent e(now - REF->self->prev_time_update);
131
+ REF->self->prev_time_update = now;
132
+
133
+ REF->on_update(&e);
134
+
135
+ if (REF->self->redraw)
136
+ {
137
+ [self display];
138
+ REF->self->redraw = false;
139
+ }
140
+ }
141
+
142
+ - (void) draw
143
+ {
144
+ assert(pref);
145
+
146
+ if (!REF) return;
147
+
148
+ double now = Xot::time();
149
+ double dt = now - REF->self->prev_time_draw;
150
+ double fps = 1. / dt;
151
+
152
+ fps = REF->self->prev_fps * 0.9 + fps * 0.1;// LPF
153
+ REF->self->prev_time_draw = now;
154
+ REF->self->prev_fps = fps;
155
+
156
+ Reflex::DrawEvent e(dt, fps);
157
+
158
+ e.painter = REF->painter();
159
+ if (!e.painter)
160
+ Xot::invalid_state_error(__FILE__, __LINE__);
161
+
162
+ Rays::Bounds b = REF->frame();
163
+ e.bounds.reset(0, 0, b.width, b.height);
164
+
165
+ e.painter->begin();
166
+ e.painter->clear();
167
+ REF->on_draw(&e);
168
+ e.painter->end();
169
+ }
170
+
171
+ - (BOOL) windowShouldClose: (id) sender
172
+ {
173
+ assert(pref);
174
+
175
+ if (!REF) return YES;
176
+
177
+ REF->close();
178
+ return NO;
179
+ }
180
+
181
+ - (void) windowWillClose: (NSNotification*) notification
182
+ {
183
+ [self stopTimer];
184
+ [self unbind: NULL];
185
+ [self setDelegate: nil];
186
+ }
187
+
188
+ - (void) windowWillMove: (NSNotification*) notification
189
+ {
190
+ assert(pref);
191
+
192
+ if (!REF) return;
193
+
194
+ REF->self->prev_position = REF->frame().position();
195
+ }
196
+
197
+ - (void) windowDidMove: (NSNotification*) notification
198
+ {
199
+ [self frameChanged];
200
+ }
201
+
202
+ - (NSSize) windowWillResize: (NSWindow*) sender toSize: (NSSize) frameSize
203
+ {
204
+ assert(pref);
205
+
206
+ if (!REF) return frameSize;
207
+
208
+ REF->self->prev_size = REF->frame().size();
209
+
210
+ return frameSize;
211
+ }
212
+
213
+ - (void) windowDidResize: (NSNotification*) notification
214
+ {
215
+ [self frameChanged];
216
+ }
217
+
218
+ - (void) frameChanged
219
+ {
220
+ assert(pref);
221
+
222
+ if (!REF) return;
223
+
224
+ Rays::Bounds b = REF->frame();
225
+ Rays::Point dpos = b.position() - REF->self->prev_position;
226
+ Rays::Point dsize = b.size() - REF->self->prev_size;
227
+ REF->self->prev_position = b.position();
228
+ REF->self->prev_size = b.size();
229
+
230
+ if (dpos != 0 || dsize != 0)
231
+ {
232
+ Reflex::FrameEvent e(b, dpos.x, dpos.y, dsize.x, dsize.y);
233
+ if (dpos != 0) REF->on_move(&e);
234
+ if (dsize != 0)
235
+ {
236
+ Rays::Bounds b = REF->frame();
237
+ b.move_to(0, 0);
238
+ if (REF->painter()) REF->painter()->canvas(b);
239
+ if (REF->root()) REF->root()->set_frame(b);
240
+ REF->on_resize(&e);
241
+ }
242
+ }
243
+ }
244
+
245
+ - (void) keyDown: (NSEvent*) event
246
+ {
247
+ assert(pref);
248
+
249
+ if (!REF) return;
250
+
251
+ Reflex::NativeKeyEvent e(event, Reflex::KeyEvent::DOWN);
252
+ REF->on_key(&e);
253
+ }
254
+
255
+ - (void) keyUp: (NSEvent*) event
256
+ {
257
+ assert(pref);
258
+
259
+ if (!REF) return;
260
+
261
+ Reflex::NativeKeyEvent e(event, Reflex::KeyEvent::UP);
262
+ REF->on_key(&e);
263
+ }
264
+
265
+ - (void) mouseDown: (NSEvent*) event
266
+ {
267
+ assert(pref);
268
+
269
+ if (!REF) return;
270
+
271
+ Reflex::NativePointerEvent e(event, view, Reflex::PointerEvent::DOWN);
272
+ REF->on_pointer(&e);
273
+ }
274
+
275
+ - (void) mouseUp: (NSEvent*) event
276
+ {
277
+ assert(pref);
278
+
279
+ if (!REF) return;
280
+
281
+ Reflex::NativePointerEvent e(event, view, Reflex::PointerEvent::UP);
282
+ REF->on_pointer(&e);
283
+ }
284
+
285
+ - (void) mouseDragged: (NSEvent*) event
286
+ {
287
+ assert(pref);
288
+
289
+ if (!REF) return;
290
+
291
+ Reflex::NativePointerEvent e(event, view, Reflex::PointerEvent::MOVE);
292
+ REF->on_pointer(&e);
293
+ }
294
+
295
+ - (void) mouseMoved: (NSEvent*) event
296
+ {
297
+ assert(pref);
298
+
299
+ if (!REF) return;
300
+
301
+ Reflex::NativePointerEvent e(event, view, Reflex::PointerEvent::MOVE);
302
+ REF->on_pointer(&e);
303
+ }
304
+
305
+ - (void) scrollWheel: (NSEvent*) event
306
+ {
307
+ assert(pref);
308
+
309
+ if (!REF) return;
310
+
311
+ Reflex::NativeWheelEvent e(event, view);
312
+ REF->on_wheel(&e);
313
+ }
314
+
315
+ + (NSRect) frameRectForContentRect: (NSRect) contentRect
316
+ {
317
+ return [NSWindow
318
+ frameRectForContentRect: contentRect
319
+ styleMask: WINDOW_STYLE_MASK];
320
+ }
321
+
322
+ @end// NativeWindow
@@ -10,8 +10,4 @@
10
10
 
11
11
  - (id) initWithFrame: (NSRect) frame antiAlias: (int) nsample;
12
12
 
13
- - (void) makeCurrent;
14
-
15
- - (void) flushBuffer;
16
-
17
13
  @end// OpenGLView
@@ -1,11 +1,11 @@
1
1
  // -*- objc -*-
2
- #import "openglview.h"
2
+ #import "opengl_view.h"
3
3
 
4
4
 
5
5
  #include <vector>
6
6
  #import <Cocoa/Cocoa.h>
7
7
  #import <OpenGL/OpenGL.h>
8
- #import "cocoawindow.h"
8
+ #import "native_window.h"
9
9
 
10
10
 
11
11
  //#define TRANSPARENT_BACKGROUND
@@ -36,7 +36,7 @@ make_pixelformat (int antialias_nsample = 0)
36
36
  static const NSOpenGLPixelFormatAttribute ANTIALIAS[] =
37
37
  {
38
38
  NSOpenGLPFASampleBuffers, 1,
39
- NSOpenGLPFASamples, antialias_nsample,
39
+ NSOpenGLPFASamples, (NSOpenGLPixelFormatAttribute) antialias_nsample,
40
40
  };
41
41
  static const size_t DEFAULT_SIZE = sizeof(DEFAULT) / sizeof(DEFAULT[0]);
42
42
  static const size_t ANTIALIAS_SIZE = sizeof(ANTIALIAS) / sizeof(ANTIALIAS[0]);
@@ -63,7 +63,7 @@ make_pixelformat (int antialias_nsample = 0)
63
63
  self = [super initWithFrame: frame pixelFormat: make_pixelformat(nsample)];
64
64
  if (!self) return nil;
65
65
 
66
- [[self openGLContext] makeCurrentContext];
66
+ [self activateContext];
67
67
 
68
68
  GLint swapinterval = 1;
69
69
  [[self openGLContext]
@@ -80,16 +80,11 @@ make_pixelformat (int antialias_nsample = 0)
80
80
  return self;
81
81
  }
82
82
 
83
- - (void) makeCurrent
83
+ - (void) activateContext
84
84
  {
85
85
  [[self openGLContext] makeCurrentContext];
86
86
  }
87
87
 
88
- - (void) flushBuffer
89
- {
90
- [[NSOpenGLContext currentContext] flushBuffer];
91
- }
92
-
93
88
  - (BOOL) acceptsFirstResponder
94
89
  {
95
90
  return YES;
@@ -109,12 +104,12 @@ make_pixelformat (int antialias_nsample = 0)
109
104
 
110
105
  - (void) drawRect: (NSRect) rect
111
106
  {
112
- CocoaWindow* win = (CocoaWindow*) [self window];
107
+ NativeWindow* win = (NativeWindow*) [self window];
113
108
  if (!win) return;
114
109
 
115
- [self makeCurrent];
110
+ [self activateContext];
116
111
  [win draw];
117
- [self flushBuffer];
112
+ [[NSOpenGLContext currentContext] flushBuffer];
118
113
  }
119
114
 
120
115
  - (void) viewDidMoveToWindow
@@ -130,14 +125,14 @@ make_pixelformat (int antialias_nsample = 0)
130
125
 
131
126
  - (void) insertText: (id) str
132
127
  {
133
- NSLog(@"interText: %@", str);
128
+ //NSLog(@"interText: %@", str);
134
129
  }
135
130
 
136
131
  - (void) keyDown: (NSEvent*) event
137
132
  {
138
133
  [self interpretKeyEvents: [NSArray arrayWithObject: event]];
139
134
 
140
- CocoaWindow* win = (CocoaWindow*) [self window];
135
+ NativeWindow* win = (NativeWindow*) [self window];
141
136
  if (!win) return;
142
137
 
143
138
  [win keyDown: event];
@@ -145,7 +140,7 @@ make_pixelformat (int antialias_nsample = 0)
145
140
 
146
141
  - (void) keyUp: (NSEvent*) event
147
142
  {
148
- CocoaWindow* win = (CocoaWindow*) [self window];
143
+ NativeWindow* win = (NativeWindow*) [self window];
149
144
  if (!win) return;
150
145
 
151
146
  [win keyUp: event];
@@ -153,7 +148,7 @@ make_pixelformat (int antialias_nsample = 0)
153
148
 
154
149
  - (void) mouseDown: (NSEvent*) event
155
150
  {
156
- CocoaWindow* win = (CocoaWindow*) [self window];
151
+ NativeWindow* win = (NativeWindow*) [self window];
157
152
  if (!win) return;
158
153
 
159
154
  [win mouseDown: event];
@@ -161,26 +156,74 @@ make_pixelformat (int antialias_nsample = 0)
161
156
 
162
157
  - (void) mouseUp: (NSEvent*) event
163
158
  {
164
- CocoaWindow* win = (CocoaWindow*) [self window];
159
+ NativeWindow* win = (NativeWindow*) [self window];
165
160
  if (!win) return;
166
161
 
167
162
  [win mouseUp: event];
168
163
  }
169
164
 
170
- - (void) mouseMoved: (NSEvent*) event
165
+ - (void) mouseDragged: (NSEvent*) event
171
166
  {
172
- CocoaWindow* win = (CocoaWindow*) [self window];
167
+ NativeWindow* win = (NativeWindow*) [self window];
173
168
  if (!win) return;
174
169
 
175
- [win mouseMoved: event];
170
+ [win mouseDragged: event];
176
171
  }
177
172
 
178
- - (void) mouseDragged: (NSEvent*) event
173
+ - (void) rightMouseDown: (NSEvent*) event
174
+ {
175
+ NativeWindow* win = (NativeWindow*) [self window];
176
+ if (!win) return;
177
+
178
+ [win mouseDown: event];
179
+ }
180
+
181
+ - (void) rightMouseUp: (NSEvent*) event
182
+ {
183
+ NativeWindow* win = (NativeWindow*) [self window];
184
+ if (!win) return;
185
+
186
+ [win mouseUp: event];
187
+ }
188
+
189
+ - (void) rightMouseDragged: (NSEvent*) event
190
+ {
191
+ NativeWindow* win = (NativeWindow*) [self window];
192
+ if (!win) return;
193
+
194
+ [win mouseDragged: event];
195
+ }
196
+
197
+ - (void) otherMouseDown: (NSEvent*) event
198
+ {
199
+ NativeWindow* win = (NativeWindow*) [self window];
200
+ if (!win) return;
201
+
202
+ [win mouseDown: event];
203
+ }
204
+
205
+ - (void) otherMouseUp: (NSEvent*) event
206
+ {
207
+ NativeWindow* win = (NativeWindow*) [self window];
208
+ if (!win) return;
209
+
210
+ [win mouseUp: event];
211
+ }
212
+
213
+ - (void) otherMouseDragged: (NSEvent*) event
179
214
  {
180
- CocoaWindow* win = (CocoaWindow*) [self window];
215
+ NativeWindow* win = (NativeWindow*) [self window];
181
216
  if (!win) return;
182
217
 
183
218
  [win mouseDragged: event];
184
219
  }
185
220
 
221
+ - (void) mouseMoved: (NSEvent*) event
222
+ {
223
+ NativeWindow* win = (NativeWindow*) [self window];
224
+ if (!win) return;
225
+
226
+ [win mouseMoved: event];
227
+ }
228
+
186
229
  @end// OpenGLView
data/src/osx/reflex.mm ADDED
@@ -0,0 +1,50 @@
1
+ // -*- objc -*-
2
+ #include "reflex/reflex.h"
3
+
4
+
5
+ #import <Cocoa/Cocoa.h>
6
+ #include "reflex/exception.h"
7
+ #import "app_delegate.h"
8
+
9
+
10
+ namespace Reflex
11
+ {
12
+
13
+
14
+ namespace global
15
+ {
16
+
17
+ static NSAutoreleasePool* pool = nil;
18
+
19
+ }// global
20
+
21
+
22
+ bool
23
+ initialized ()
24
+ {
25
+ return global::pool;
26
+ }
27
+
28
+ void
29
+ init ()
30
+ {
31
+ if (global::pool)
32
+ reflex_error(__FILE__, __LINE__, "already initialized.");
33
+
34
+ global::pool = [[NSAutoreleasePool alloc] init];
35
+
36
+ [[NSApplication sharedApplication] setDelegate: [[[AppDelegate alloc] init] autorelease]];
37
+ }
38
+
39
+ void
40
+ fin ()
41
+ {
42
+ if (!global::pool)
43
+ reflex_error(__FILE__, __LINE__, "not initialized.");
44
+
45
+ [global::pool release];
46
+ global::pool = nil;
47
+ }
48
+
49
+
50
+ }// Reflex