reflexion 0.1.23 → 0.1.26

Sign up to get free protection for your applications and to get access to all the features.
Files changed (71) hide show
  1. checksums.yaml +4 -4
  2. data/.doc/ext/reflex/capture_event.cpp +6 -5
  3. data/.doc/ext/reflex/contact_event.cpp +14 -12
  4. data/.doc/ext/reflex/draw_event.cpp +10 -8
  5. data/.doc/ext/reflex/event.cpp +2 -10
  6. data/.doc/ext/reflex/focus_event.cpp +14 -13
  7. data/.doc/ext/reflex/frame_event.cpp +17 -17
  8. data/.doc/ext/reflex/key_event.cpp +20 -19
  9. data/.doc/ext/reflex/pointer_event.cpp +1 -1
  10. data/.doc/ext/reflex/scroll_event.cpp +14 -17
  11. data/.doc/ext/reflex/timer.cpp +9 -1
  12. data/.doc/ext/reflex/timer_event.cpp +4 -13
  13. data/.doc/ext/reflex/update_event.cpp +6 -5
  14. data/.doc/ext/reflex/wheel_event.cpp +39 -22
  15. data/VERSION +1 -1
  16. data/ext/reflex/capture_event.cpp +6 -5
  17. data/ext/reflex/contact_event.cpp +16 -14
  18. data/ext/reflex/draw_event.cpp +9 -7
  19. data/ext/reflex/event.cpp +2 -11
  20. data/ext/reflex/focus_event.cpp +14 -13
  21. data/ext/reflex/frame_event.cpp +16 -16
  22. data/ext/reflex/key_event.cpp +20 -19
  23. data/ext/reflex/pointer_event.cpp +1 -1
  24. data/ext/reflex/scroll_event.cpp +15 -18
  25. data/ext/reflex/timer.cpp +15 -6
  26. data/ext/reflex/timer_event.cpp +9 -19
  27. data/ext/reflex/update_event.cpp +6 -5
  28. data/ext/reflex/wheel_event.cpp +40 -21
  29. data/include/reflex/event.h +224 -115
  30. data/include/reflex/shape.h +2 -2
  31. data/include/reflex/window.h +1 -1
  32. data/lib/reflex/contact_event.rb +7 -7
  33. data/lib/reflex/focus_event.rb +8 -8
  34. data/lib/reflex/key_event.rb +8 -8
  35. data/lib/reflex/pointer.rb +3 -3
  36. data/lib/reflex/pointer_event.rb +2 -2
  37. data/lib/reflex/timer_event.rb +2 -1
  38. data/lib/reflex/wheel_event.rb +1 -9
  39. data/lib/reflex/window.rb +1 -1
  40. data/reflex.gemspec +4 -4
  41. data/src/event.cpp +630 -76
  42. data/src/event.h +15 -0
  43. data/src/image_view.cpp +2 -2
  44. data/src/ios/app_delegate.h +0 -6
  45. data/src/ios/app_delegate.mm +1 -0
  46. data/src/ios/application.mm +6 -0
  47. data/src/ios/view_controller.mm +15 -9
  48. data/src/ios/window.mm +2 -4
  49. data/src/osx/event.h +1 -1
  50. data/src/osx/event.mm +9 -9
  51. data/src/osx/native_window.mm +23 -5
  52. data/src/shape.cpp +11 -13
  53. data/src/shape.h +1 -1
  54. data/src/view.cpp +137 -89
  55. data/src/view.h +5 -6
  56. data/src/window.cpp +28 -26
  57. data/src/world.cpp +6 -4
  58. data/test/test_capture_event.rb +16 -0
  59. data/test/test_contact_event.rb +40 -0
  60. data/test/test_draw_event.rb +35 -0
  61. data/test/test_event.rb +20 -6
  62. data/test/test_focus_event.rb +34 -0
  63. data/test/test_frame_event.rb +38 -0
  64. data/test/test_key_event.rb +33 -0
  65. data/test/test_pointer.rb +14 -14
  66. data/test/test_pointer_event.rb +1 -1
  67. data/test/test_scroll_event.rb +39 -0
  68. data/test/test_timer_event.rb +38 -0
  69. data/test/test_update_event.rb +29 -0
  70. data/test/test_wheel_event.rb +40 -0
  71. metadata +29 -11
data/src/event.h CHANGED
@@ -12,6 +12,16 @@ namespace Reflex
12
12
  {
13
13
 
14
14
 
15
+ void DrawEvent_set_view (DrawEvent* pthis, View* view);
16
+
17
+ void DrawEvent_set_painter (DrawEvent* pthis, Painter* painter);
18
+
19
+ void DrawEvent_set_bounds (DrawEvent* pthis, const Bounds& bounds);
20
+
21
+
22
+ void KeyEvent_set_captured (KeyEvent* pthis, bool captured);
23
+
24
+
15
25
  void PointerEvent_add_pointer (PointerEvent* pthis, const Pointer& pointer);
16
26
 
17
27
  void PointerEvent_erase_pointer (PointerEvent* pthis, Pointer::ID id);
@@ -21,11 +31,16 @@ namespace Reflex
21
31
  void PointerEvent_each_pointer (
22
32
  const PointerEvent* pthis, std::function<void(const Pointer&)> fun);
23
33
 
34
+ void PointerEvent_set_captured (PointerEvent* pthis, bool captured);
35
+
24
36
  void PointerEvent_update_for_child_view (PointerEvent* pthis, const View* view);
25
37
 
26
38
  void PointerEvent_update_for_capturing_view (PointerEvent* pthis, const View* view);
27
39
 
28
40
 
41
+ void WheelEvent_set_position (WheelEvent* pthis, const Point& position);
42
+
43
+
29
44
  }// Reflex
30
45
 
31
46
 
data/src/image_view.cpp CHANGED
@@ -53,8 +53,8 @@ namespace Reflex
53
53
  {
54
54
  if (!self->image) return;
55
55
 
56
- assert(e && e->painter);
57
- Painter* p = e->painter;
56
+ assert(e && e->painter());
57
+ Painter* p = e->painter();
58
58
 
59
59
  Color f = p->fill(), s = p->stroke();
60
60
  p->set_fill(1);
@@ -1,12 +1,6 @@
1
1
  // -*- objc -*-
2
2
  #import <UIKit/UIApplication.h>
3
- #include "application.h"
4
3
 
5
4
 
6
5
  @interface ReflexAppDelegate : UIResponder <UIApplicationDelegate>
7
-
8
- - (void) bind: (Reflex::Application*) application;
9
-
10
- - (BOOL) callOnStart;
11
-
12
6
  @end// ReflexAppDelegate
@@ -6,6 +6,7 @@
6
6
  #import <CoreMotion/CoreMotion.h>
7
7
  #include "reflex/event.h"
8
8
  #include "reflex/exception.h"
9
+ #include "application.h"
9
10
 
10
11
 
11
12
  @implementation ReflexAppDelegate
@@ -13,6 +13,12 @@ extern "C" {
13
13
  }
14
14
 
15
15
 
16
+ @interface ReflexAppDelegate (Bind)
17
+ - (void) bind: (Reflex::Application*) application;
18
+ - (BOOL) callOnStart;
19
+ @end
20
+
21
+
16
22
  namespace Reflex
17
23
  {
18
24
 
@@ -16,7 +16,7 @@
16
16
  static ReflexViewController*
17
17
  create_reflex_view_controller ()
18
18
  {
19
- return [[ReflexViewController alloc] init];
19
+ return [[[ReflexViewController alloc] init] autorelease];
20
20
  }
21
21
 
22
22
  static UIViewController*
@@ -102,7 +102,7 @@ ReflexViewController_get_show_fun ()
102
102
 
103
103
  @interface ReflexView ()
104
104
 
105
- @property(nonatomic, strong) ReflexViewController* reflexViewController;
105
+ @property(nonatomic, unsafe_unretained) ReflexViewController* reflexViewController;
106
106
 
107
107
  @end
108
108
 
@@ -112,7 +112,9 @@ ReflexViewController_get_show_fun ()
112
112
  - (void) layoutSubviews
113
113
  {
114
114
  [super layoutSubviews];
115
- [self.reflexViewController viewDidResize];
115
+
116
+ if (self.reflexViewController)
117
+ [self.reflexViewController viewDidResize];
116
118
  }
117
119
 
118
120
  @end
@@ -153,6 +155,9 @@ ReflexViewController_get_show_fun ()
153
155
 
154
156
  - (void) dealloc
155
157
  {
158
+ Reflex::Window* win = self.window;
159
+ if (win) win->close(true);
160
+
156
161
  [self cleanup];
157
162
  [super dealloc];
158
163
  }
@@ -227,6 +232,11 @@ ReflexViewController_get_show_fun ()
227
232
  [self setupReflexView];
228
233
  }
229
234
 
235
+ - (ReflexView*) createReflexView
236
+ {
237
+ return [[[ReflexView alloc] initWithFrame: self.view.bounds] autorelease];
238
+ }
239
+
230
240
  - (void) setupReflexView
231
241
  {
232
242
  ReflexView* view = [self createReflexView];
@@ -256,11 +266,6 @@ ReflexViewController_get_show_fun ()
256
266
  self.reflexView = view;
257
267
  }
258
268
 
259
- - (ReflexView*) createReflexView
260
- {
261
- return [[[ReflexView alloc] initWithFrame: self.view.bounds] autorelease];
262
- }
263
-
264
269
  - (void) cleanupReflexView
265
270
  {
266
271
  ReflexView* view = self.reflexView;
@@ -270,6 +275,7 @@ ReflexViewController_get_show_fun ()
270
275
  if (context && context == [EAGLContext currentContext])
271
276
  [EAGLContext setCurrentContext: (EAGLContext*) Rays::get_offscreen_context()];
272
277
 
278
+ view.reflexViewController = nil;
273
279
  [view removeFromSuperview];
274
280
 
275
281
  self.reflexView = nil;
@@ -376,7 +382,7 @@ ReflexViewController_get_show_fun ()
376
382
 
377
383
  if (dpos != 0 || dsize != 0)
378
384
  {
379
- Reflex::FrameEvent e(b, dpos.x, dpos.y, dsize.x, dsize.y);
385
+ Reflex::FrameEvent e(b, dpos.x, dpos.y, dsize.x, dsize.y, 0, 0);
380
386
  if (dpos != 0) win->on_move(&e);
381
387
  if (dsize != 0)
382
388
  {
data/src/ios/window.mm CHANGED
@@ -51,8 +51,7 @@ namespace Reflex
51
51
  void
52
52
  Window_initialize (Window* window)
53
53
  {
54
- ReflexViewController* vc =
55
- [ReflexViewController_get_create_fun()() autorelease];
54
+ ReflexViewController* vc = ReflexViewController_get_create_fun()();
56
55
  if (!vc)
57
56
  reflex_error(__FILE__, __LINE__);
58
57
 
@@ -95,7 +94,6 @@ namespace Reflex
95
94
  void
96
95
  Window_close (Window* window)
97
96
  {
98
- not_implemented_error(__FILE__, __LINE__);
99
97
  }
100
98
 
101
99
  void
@@ -104,7 +102,7 @@ namespace Reflex
104
102
  if (!title)
105
103
  argument_error(__FILE__, __LINE__);
106
104
 
107
- get_vc(window).title = [[NSString alloc] initWithUTF8String: title];
105
+ get_vc(window).title = [NSString stringWithUTF8String: title];
108
106
  }
109
107
 
110
108
  const char*
data/src/osx/event.h CHANGED
@@ -15,7 +15,7 @@ namespace Reflex
15
15
  struct NativeKeyEvent : public KeyEvent
16
16
  {
17
17
 
18
- NativeKeyEvent (NSEvent* event, Type type);
18
+ NativeKeyEvent (NSEvent* event, Action action);
19
19
 
20
20
  };// NativeKeyEvent
21
21
 
data/src/osx/event.mm CHANGED
@@ -169,11 +169,11 @@ namespace Reflex
169
169
  return 0;
170
170
  }
171
171
 
172
- static KeyEvent::Type
173
- get_flag_key_event_type(const NSEvent* e)
172
+ static KeyEvent::Action
173
+ get_flag_key_event_action (const NSEvent* e)
174
174
  {
175
175
  uint mask = get_modifier_flag_mask(e);
176
- if (mask == 0) return Reflex::KeyEvent::NONE;
176
+ if (mask == 0) return Reflex::KeyEvent::ACTION_NONE;
177
177
 
178
178
  return [e modifierFlags] & mask
179
179
  ? Reflex::KeyEvent::DOWN
@@ -251,18 +251,18 @@ namespace Reflex
251
251
  }
252
252
 
253
253
 
254
- NativeKeyEvent::NativeKeyEvent (NSEvent* e, Type type)
254
+ NativeKeyEvent::NativeKeyEvent (NSEvent* e, Action action)
255
255
  : KeyEvent(
256
- type, get_chars(e), get_code([e keyCode]), get_modifiers(e),
257
- [e isARepeat] ? 1 : 0)
256
+ action, get_chars(e), get_code([e keyCode]),
257
+ get_modifiers(e), [e isARepeat] ? 1 : 0)
258
258
  {
259
259
  }
260
260
 
261
261
 
262
262
  NativeFlagKeyEvent::NativeFlagKeyEvent (NSEvent* e)
263
263
  : KeyEvent(
264
- get_flag_key_event_type(e), "", get_code([e keyCode]), get_modifiers(e),
265
- 0)
264
+ get_flag_key_event_action(e), "", get_code([e keyCode]),
265
+ get_modifiers(e), 0)
266
266
  {
267
267
  }
268
268
 
@@ -295,7 +295,7 @@ namespace Reflex
295
295
  NativeWheelEvent::NativeWheelEvent (NSEvent* e, NSView* view)
296
296
  : WheelEvent(0, 0, 0, [e deltaX], [e deltaY], [e deltaZ], get_modifiers(e))
297
297
  {
298
- position_ = get_pointer_position(e, view);
298
+ WheelEvent_set_position(this, get_pointer_position(e, view));
299
299
  }
300
300
 
301
301
 
@@ -34,6 +34,20 @@ count_mouse_buttons (const Reflex::PointerEvent& e)
34
34
  return nbuttons;
35
35
  }
36
36
 
37
+ static void
38
+ update_pixel_density (Reflex::Window* window)
39
+ {
40
+ assert(window);
41
+
42
+ Rays::Painter* painter = window->painter();
43
+ if (!painter) return;
44
+
45
+ float pd = Window_get_pixel_density(*window);
46
+ if (painter->pixel_density() != pd)
47
+ painter->canvas(window->frame().dup().move_to(0, 0), pd);
48
+ }
49
+
50
+
37
51
  @implementation NativeWindow
38
52
 
39
53
  {
@@ -43,7 +57,7 @@ count_mouse_buttons (const Reflex::PointerEvent& e)
43
57
  int update_count;
44
58
  int clicking_count;
45
59
  Reflex::Pointer::ID pointer_id;
46
- Reflex::Pointer prevPointer;
60
+ Reflex::Pointer prev_pointer;
47
61
  }
48
62
 
49
63
  - (id) init
@@ -196,6 +210,8 @@ count_mouse_buttons (const Reflex::PointerEvent& e)
196
210
  Reflex::Window* win = self.window;
197
211
  if (!win) return;
198
212
 
213
+ update_pixel_density(win);
214
+
199
215
  if (update_count == 0)
200
216
  [self update];
201
217
 
@@ -269,7 +285,7 @@ count_mouse_buttons (const Reflex::PointerEvent& e)
269
285
 
270
286
  if (dpos != 0 || dsize != 0)
271
287
  {
272
- Reflex::FrameEvent e(b, dpos.x, dpos.y, dsize.x, dsize.y);
288
+ Reflex::FrameEvent e(b, dpos.x, dpos.y, dsize.x, dsize.y, 0, 0);
273
289
  if (dpos != 0) win->on_move(&e);
274
290
  if (dsize != 0)
275
291
  {
@@ -381,9 +397,11 @@ count_mouse_buttons (const Reflex::PointerEvent& e)
381
397
  assert(e->size() == 1);
382
398
 
383
399
  Reflex::Pointer& pointer = Reflex::PointerEvent_pointer_at(e, 0);
384
- if (prevPointer)
385
- Reflex::Pointer_set_prev(&pointer, &prevPointer);
386
- prevPointer = pointer;
400
+ if (prev_pointer)
401
+ Reflex::Pointer_set_prev(&pointer, &prev_pointer);
402
+
403
+ prev_pointer = pointer;
404
+ Reflex::Pointer_set_prev(&prev_pointer, NULL);
387
405
  }
388
406
 
389
407
  - (void) scrollWheel: (NSEvent*) event
data/src/shape.cpp CHANGED
@@ -432,25 +432,23 @@ namespace Reflex
432
432
  }
433
433
 
434
434
  void
435
- Shape_call_contact_event (Shape* shape, const ContactEvent& event)
435
+ Shape_call_contact_event (Shape* shape, ContactEvent* event)
436
436
  {
437
- if (!shape)
437
+ if (!shape || !event)
438
438
  argument_error(__FILE__, __LINE__);
439
439
 
440
- ContactEvent e = event;
441
- shape->on_contact(&e);
440
+ shape->on_contact(event);
442
441
 
443
- switch (e.type)
442
+ switch (event->action())
444
443
  {
445
- case ContactEvent::BEGIN: shape->on_contact_begin(&e); break;
446
- case ContactEvent::END: shape->on_contact_end(&e); break;
447
- case ContactEvent::NONE: break;
444
+ case ContactEvent::BEGIN: shape->on_contact_begin(event); break;
445
+ case ContactEvent::END: shape->on_contact_end(event); break;
446
+ default: break;
448
447
  }
449
448
 
450
- if (e.is_blocked())
451
- return;
449
+ if (event->is_blocked()) return;
452
450
 
453
- View_call_contact_event(shape->owner(), e);
451
+ View_call_contact_event(shape->owner(), event);
454
452
  }
455
453
 
456
454
 
@@ -587,9 +585,9 @@ namespace Reflex
587
585
  void
588
586
  Shape::on_draw (DrawEvent* e)
589
587
  {
590
- assert(e && e->painter);
588
+ assert(e && e->painter());
591
589
 
592
- e->painter->polygon(self->polygon);
590
+ e->painter()->polygon(self->polygon);
593
591
  }
594
592
 
595
593
  void
data/src/shape.h CHANGED
@@ -52,7 +52,7 @@ namespace Reflex
52
52
 
53
53
  void Shape_update (Shape* shape, bool force = false);
54
54
 
55
- void Shape_call_contact_event (Shape* shape, const ContactEvent& event);
55
+ void Shape_call_contact_event (Shape* shape, ContactEvent* event);
56
56
 
57
57
 
58
58
  }// Reflex