reflexion 0.1.21 → 0.1.25

Sign up to get free protection for your applications and to get access to all the features.
Files changed (129) 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 +18 -16
  4. data/.doc/ext/reflex/draw_event.cpp +10 -8
  5. data/.doc/ext/reflex/event.cpp +10 -10
  6. data/.doc/ext/reflex/focus_event.cpp +18 -17
  7. data/.doc/ext/reflex/frame_event.cpp +17 -17
  8. data/.doc/ext/reflex/key_event.cpp +227 -28
  9. data/.doc/ext/reflex/native.cpp +2 -0
  10. data/.doc/ext/reflex/pointer.cpp +158 -0
  11. data/.doc/ext/reflex/pointer_event.cpp +32 -91
  12. data/.doc/ext/reflex/scroll_event.cpp +14 -17
  13. data/.doc/ext/reflex/selector.cpp +8 -0
  14. data/.doc/ext/reflex/timer.cpp +9 -1
  15. data/.doc/ext/reflex/timer_event.cpp +4 -13
  16. data/.doc/ext/reflex/update_event.cpp +6 -5
  17. data/.doc/ext/reflex/view.cpp +57 -0
  18. data/.doc/ext/reflex/wheel_event.cpp +39 -22
  19. data/.doc/ext/reflex/window.cpp +24 -0
  20. data/VERSION +1 -1
  21. data/ext/reflex/capture_event.cpp +6 -5
  22. data/ext/reflex/contact_event.cpp +18 -16
  23. data/ext/reflex/draw_event.cpp +9 -7
  24. data/ext/reflex/event.cpp +11 -11
  25. data/ext/reflex/focus_event.cpp +18 -17
  26. data/ext/reflex/frame_event.cpp +16 -16
  27. data/ext/reflex/key_event.cpp +228 -28
  28. data/ext/reflex/native.cpp +2 -0
  29. data/ext/reflex/pointer.cpp +170 -0
  30. data/ext/reflex/pointer_event.cpp +31 -96
  31. data/ext/reflex/scroll_event.cpp +15 -18
  32. data/ext/reflex/selector.cpp +9 -0
  33. data/ext/reflex/timer.cpp +15 -6
  34. data/ext/reflex/timer_event.cpp +9 -19
  35. data/ext/reflex/update_event.cpp +6 -5
  36. data/ext/reflex/view.cpp +67 -3
  37. data/ext/reflex/wheel_event.cpp +40 -21
  38. data/ext/reflex/window.cpp +30 -3
  39. data/include/reflex/defs.h +140 -106
  40. data/include/reflex/event.h +232 -124
  41. data/include/reflex/pointer.h +107 -0
  42. data/include/reflex/ruby/pointer.h +41 -0
  43. data/include/reflex/ruby/view.h +9 -0
  44. data/include/reflex/ruby/window.h +9 -0
  45. data/include/reflex/selector.h +1 -1
  46. data/include/reflex/shape.h +2 -2
  47. data/include/reflex/view.h +6 -4
  48. data/include/reflex/window.h +10 -8
  49. data/lib/reflex/application.rb +3 -3
  50. data/lib/reflex/autoinit.rb +1 -1
  51. data/lib/reflex/button.rb +7 -7
  52. data/lib/reflex/capture_event.rb +7 -7
  53. data/lib/reflex/contact_event.rb +10 -10
  54. data/lib/reflex/draw_event.rb +2 -2
  55. data/lib/reflex/ellipse_shape.rb +2 -2
  56. data/lib/reflex/focus_event.rb +11 -11
  57. data/lib/reflex/frame_event.rb +5 -5
  58. data/lib/reflex/helper.rb +20 -20
  59. data/lib/reflex/image_view.rb +2 -2
  60. data/lib/reflex/key_event.rb +12 -12
  61. data/lib/reflex/model.rb +22 -22
  62. data/lib/reflex/model_owner.rb +7 -7
  63. data/lib/reflex/model_view.rb +1 -1
  64. data/lib/reflex/module.rb +5 -5
  65. data/lib/reflex/pointer.rb +107 -0
  66. data/lib/reflex/pointer_event.rb +16 -54
  67. data/lib/reflex/polygon_shape.rb +2 -2
  68. data/lib/reflex/reflex.rb +3 -3
  69. data/lib/reflex/scroll_event.rb +1 -1
  70. data/lib/reflex/selector.rb +4 -4
  71. data/lib/reflex/shape.rb +13 -13
  72. data/lib/reflex/style.rb +11 -11
  73. data/lib/reflex/style_length.rb +1 -1
  74. data/lib/reflex/text_view.rb +2 -2
  75. data/lib/reflex/timer.rb +2 -2
  76. data/lib/reflex/timer_event.rb +3 -2
  77. data/lib/reflex/update_event.rb +1 -1
  78. data/lib/reflex/view.rb +32 -32
  79. data/lib/reflex/wheel_event.rb +2 -10
  80. data/lib/reflex/window.rb +6 -6
  81. data/lib/reflex.rb +1 -0
  82. data/lib/reflexion.rb +17 -17
  83. data/reflex.gemspec +5 -5
  84. data/samples/reflexion/noise.rb +1 -1
  85. data/samples/tree.rb +1 -1
  86. data/src/event.cpp +792 -86
  87. data/src/event.h +47 -0
  88. data/src/image_view.cpp +2 -2
  89. data/src/ios/event.h +15 -3
  90. data/src/ios/event.mm +126 -11
  91. data/src/ios/view_controller.mm +50 -22
  92. data/src/ios/window.mm +1 -1
  93. data/src/osx/event.h +15 -4
  94. data/src/osx/event.mm +214 -24
  95. data/src/osx/native_window.mm +84 -17
  96. data/src/pointer.cpp +203 -0
  97. data/src/pointer.h +26 -0
  98. data/src/selector.cpp +1 -1
  99. data/src/shape.cpp +11 -13
  100. data/src/shape.h +1 -1
  101. data/src/view.cpp +205 -118
  102. data/src/view.h +5 -10
  103. data/src/window.cpp +334 -104
  104. data/src/window.h +22 -3
  105. data/src/world.cpp +6 -4
  106. data/test/helper.rb +3 -3
  107. data/test/test_application.rb +1 -1
  108. data/test/test_capture_event.rb +22 -6
  109. data/test/test_contact_event.rb +40 -0
  110. data/test/test_draw_event.rb +35 -0
  111. data/test/test_event.rb +33 -5
  112. data/test/test_focus_event.rb +34 -0
  113. data/test/test_frame_event.rb +38 -0
  114. data/test/test_has_frame.rb +11 -11
  115. data/test/test_key_event.rb +33 -0
  116. data/test/test_pointer.rb +149 -0
  117. data/test/test_pointer_event.rb +70 -104
  118. data/test/test_reflex.rb +1 -1
  119. data/test/test_scroll_event.rb +39 -0
  120. data/test/test_selector.rb +15 -8
  121. data/test/test_shape.rb +8 -8
  122. data/test/test_style.rb +13 -13
  123. data/test/test_style_length.rb +5 -5
  124. data/test/test_timer_event.rb +38 -0
  125. data/test/test_update_event.rb +29 -0
  126. data/test/test_view.rb +57 -30
  127. data/test/test_wheel_event.rb +40 -0
  128. data/test/test_window.rb +29 -27
  129. metadata +64 -35
data/src/window.cpp CHANGED
@@ -1,14 +1,25 @@
1
1
  #include "window.h"
2
2
 
3
3
 
4
+ #include <set>
4
5
  #include "reflex/exception.h"
5
6
  #include "view.h"
7
+ #include "event.h"
6
8
 
7
9
 
8
10
  namespace Reflex
9
11
  {
10
12
 
11
13
 
14
+ using ViewList = std::vector<View::Ref>;
15
+
16
+ using PointerMap = std::map<Pointer::ID, Pointer>;
17
+
18
+ using ExtractedPointerIDSet = std::set<Pointer::ID>;
19
+
20
+ using CaptureTargetIDList = Window::Data::CaptureTargetIDList;
21
+
22
+
12
23
  void
13
24
  Window_set_focus (Window* window, View* view)
14
25
  {
@@ -20,22 +31,95 @@ namespace Reflex
20
31
 
21
32
  window->self->focus.reset(view);
22
33
 
23
- FocusEvent e(FocusEvent::BLUR, view, current);
24
-
25
34
  if (current)
26
35
  {
36
+ FocusEvent e(FocusEvent::BLUR, view, current);
27
37
  current->on_focus(&e);
28
38
  current->redraw();
29
39
  }
30
40
 
31
41
  if (view)
32
42
  {
33
- e.type = FocusEvent::FOCUS;
43
+ FocusEvent e(FocusEvent::FOCUS, view, current);
34
44
  view->on_focus(&e);
35
45
  view->redraw();
36
46
  }
37
47
  }
38
48
 
49
+ namespace global
50
+ {
51
+
52
+ static Window_CreateRootViewFun create_root_view_fun = NULL;
53
+
54
+ }// global
55
+
56
+ void
57
+ Window_set_create_root_view_fun (Window_CreateRootViewFun fun)
58
+ {
59
+ global::create_root_view_fun = fun;
60
+ }
61
+
62
+ static View*
63
+ create_root_view ()
64
+ {
65
+ return global::create_root_view_fun
66
+ ? global::create_root_view_fun()
67
+ : new View();
68
+ }
69
+
70
+ void
71
+ Window_register_capture (Window* window, View* view, Pointer::ID target)
72
+ {
73
+ assert(window);
74
+
75
+ if (!view)
76
+ argument_error(__FILE__, __LINE__);
77
+
78
+ if (view->window() != window)
79
+ invalid_state_error(__FILE__, __LINE__);
80
+
81
+ if (target < 0) return;
82
+
83
+ auto& targets = window->self->captures[view];
84
+ if (std::find(targets.begin(), targets.end(), target) != targets.end())
85
+ return;
86
+
87
+ targets.insert(
88
+ target == CAPTURE_ALL ? targets.begin() : targets.end(),
89
+ target);
90
+ }
91
+
92
+ void
93
+ Window_unregister_capture (Window* window, View* view, Pointer::ID target)
94
+ {
95
+ assert(window);
96
+
97
+ if (!view)
98
+ argument_error(__FILE__, __LINE__);
99
+
100
+ auto captures_it = window->self->captures.find(view);
101
+ if (captures_it == window->self->captures.end()) return;
102
+
103
+ auto& targets = captures_it->second;
104
+ auto targets_it = std::find(targets.begin(), targets.end(), target);
105
+ if (targets_it == targets.end()) return;
106
+
107
+ targets.erase(targets_it);
108
+ }
109
+
110
+ static void
111
+ cleanup_captures (Window* window)
112
+ {
113
+ assert(window);
114
+
115
+ auto& caps = window->self->captures;
116
+ for (auto it = caps.begin(), end = caps.end(); it != end;)
117
+ {
118
+ auto t = it++;
119
+ if (t->second.empty()) caps.erase(t);
120
+ }
121
+ }
122
+
39
123
  void
40
124
  Window_call_draw_event (Window* window, DrawEvent* event)
41
125
  {
@@ -48,8 +132,8 @@ namespace Reflex
48
132
 
49
133
  Rays::Bounds frame = window->frame();
50
134
 
51
- event->painter = painter;
52
- event->bounds.reset(0, 0, frame.width, frame.height);
135
+ DrawEvent_set_painter(event, painter);
136
+ DrawEvent_set_bounds(event, Bounds(0, 0, frame.width, frame.height));
53
137
 
54
138
  painter->begin();
55
139
  painter->push_state();
@@ -57,72 +141,265 @@ namespace Reflex
57
141
 
58
142
  window->on_draw(event);
59
143
  if (!event->is_blocked())
60
- Reflex::View_draw_tree(window->root(), *event, 0, frame.move_to(0));
144
+ Reflex::View_draw_tree(window->root(), event, 0, frame.move_to(0));
61
145
 
62
146
  painter->pop_state();
63
147
  painter->end();
64
148
  }
65
149
 
66
- namespace global
150
+ static bool
151
+ is_capturing (
152
+ const View* view, const CaptureTargetIDList& targets, View::Capture type)
67
153
  {
154
+ return
155
+ !targets.empty() &&
156
+ targets[0] == CAPTURE_ALL &&
157
+ (view->capture() & type) == type;
158
+ }
68
159
 
69
- static Window_CreateRootViewFun create_root_view_fun = NULL;
160
+ void
161
+ Window_call_key_event (Window* window, KeyEvent* event)
162
+ {
163
+ assert(window);
70
164
 
71
- }// global
165
+ if (!event)
166
+ argument_error(__FILE__, __LINE__);
72
167
 
73
- void
74
- Window_set_create_root_view_fun (Window_CreateRootViewFun fun)
168
+ for (auto& [view, targets] : window->self->captures)
169
+ {
170
+ if (!is_capturing(view.get(), targets, View::CAPTURE_KEY))
171
+ continue;
172
+
173
+ KeyEvent e = event->dup();
174
+ KeyEvent_set_captured(&e, true);
175
+ View_call_key_event(const_cast<View*>(view.get()), &e);
176
+ }
177
+
178
+ if (window->self->focus)
179
+ View_call_key_event(window->self->focus.get(), event);
180
+
181
+ cleanup_captures(window);
182
+
183
+ if (event->is_blocked()) return;
184
+
185
+ window->on_key(event);
186
+
187
+ switch (event->action())
188
+ {
189
+ case KeyEvent::DOWN: window->on_key_down(event); break;
190
+ case KeyEvent::UP: window->on_key_up(event); break;
191
+ default: break;
192
+ }
193
+ }
194
+
195
+ static void
196
+ get_views_capturing_all_pointers (Window* window, ViewList* result)
75
197
  {
76
- global::create_root_view_fun = fun;
198
+ assert(window && result);
199
+
200
+ result->clear();
201
+ for (const auto& [view, targets] : window->self->captures)
202
+ {
203
+ if (is_capturing(view.get(), targets, View::CAPTURE_POINTER))
204
+ result->emplace_back(view);
205
+ }
77
206
  }
78
207
 
79
- static View*
80
- create_root_view ()
208
+ static void
209
+ capture_all_pointers (
210
+ Window* window, const PointerEvent& event, ViewList& views_capturing_all)
81
211
  {
82
- return global::create_root_view_fun
83
- ? global::create_root_view_fun()
84
- : new View();
212
+ assert(window);
213
+
214
+ if (views_capturing_all.empty()) return;
215
+
216
+ PointerEvent_each_pointer(&event, [&](const auto& pointer)
217
+ {
218
+ if (pointer.action() == Pointer::DOWN)
219
+ {
220
+ for (auto& view : views_capturing_all)
221
+ Window_register_capture(window, view, pointer.id());
222
+ }
223
+ });
85
224
  }
86
225
 
87
- void
88
- View_register_capture (View* view)
226
+ static void
227
+ extract_pointer (
228
+ PointerEvent* event, ExtractedPointerIDSet* extracteds,
229
+ const Pointer& pointer)
89
230
  {
90
- if (!view)
91
- argument_error(__FILE__, __LINE__);
231
+ assert(event && extracteds);
92
232
 
93
- const Window* window = view->window();
94
- if (!window)
95
- invalid_state_error(__FILE__, __LINE__, "this view does not belong to any Window.");
233
+ PointerEvent_add_pointer(event, pointer);
234
+ extracteds->insert(pointer.id());
235
+ }
96
236
 
97
- window->self->capturing_views[view] = true;
237
+ static void
238
+ extract_targeted_pointers (
239
+ PointerEvent* event, ExtractedPointerIDSet* extracteds,
240
+ const CaptureTargetIDList& targets, const PointerMap& pointers)
241
+ {
242
+ assert(event && event->empty() && extracteds);
243
+
244
+ for (auto pointer_id : targets)
245
+ {
246
+ auto it = pointers.find(pointer_id);
247
+ if (it != pointers.end())
248
+ extract_pointer(event, extracteds, it->second);
249
+ }
98
250
  }
99
251
 
100
- void
101
- View_unregister_capture (View* view)
252
+ static void
253
+ capture_targeted_pointers_and_call_events (
254
+ ExtractedPointerIDSet* extracteds,
255
+ Window* window, const PointerMap& pointers)
102
256
  {
103
- if (!view)
104
- argument_error(__FILE__, __LINE__);
257
+ assert(extracteds && window);
105
258
 
106
- const Window* window = view->window();
107
- if (!window) return;
259
+ for (auto& [view, targets] : window->self->captures)
260
+ {
261
+ if (targets.empty()) continue;
108
262
 
109
- auto it = window->self->capturing_views.find(view);
110
- if (it == window->self->capturing_views.end()) return;
263
+ PointerEvent event;
264
+ PointerEvent_set_captured(&event, true);
265
+ extract_targeted_pointers(&event, extracteds, targets, pointers);
266
+ if (event.empty()) continue;
111
267
 
112
- it->second = false;
268
+ PointerEvent_update_for_capturing_view(&event, view);
269
+ View_call_pointer_event(const_cast<View*>(view.get()), &event);
270
+ }
113
271
  }
114
272
 
115
273
  static void
116
- cleanup_capturing_views (Window* window)
274
+ extract_hovering_pointers (
275
+ PointerEvent* event, ExtractedPointerIDSet* extracteds,
276
+ const PointerMap& pointers)
117
277
  {
118
- auto end = window->self->capturing_views.end();
119
- for (auto it = window->self->capturing_views.begin(); it != end;)
278
+ assert(event && event->empty() && extracteds);
279
+
280
+ for (const auto& [_, pointer] : pointers)
120
281
  {
121
- auto t = it++;
122
- if (!t->second) window->self->capturing_views.erase(t);
282
+ // dragging pointers is captured as a targeted
283
+ if (pointer.is_drag()) continue;
284
+
285
+ extract_pointer(event, extracteds, pointer);
286
+ }
287
+ }
288
+
289
+ static void
290
+ capture_hovering_pointers_and_call_events (
291
+ ExtractedPointerIDSet* extracteds,
292
+ const ViewList& views_capturing_all, const PointerMap& pointers)
293
+ {
294
+ assert(extracteds);
295
+
296
+ if (views_capturing_all.empty()) return;
297
+
298
+ PointerEvent event;
299
+ PointerEvent_set_captured(&event, true);
300
+ extract_hovering_pointers(&event, extracteds, pointers);
301
+ if (event.empty()) return;
302
+
303
+ for (auto& view : views_capturing_all)
304
+ {
305
+ PointerEvent e = event.dup();
306
+ PointerEvent_update_for_capturing_view(&e, view);
307
+ View_call_pointer_event(const_cast<View*>(view.get()), &e);
308
+ }
309
+ }
310
+
311
+ static void
312
+ erase_extracted_pointers (
313
+ PointerMap* pointers, const ExtractedPointerIDSet& extracteds)
314
+ {
315
+ assert(pointers);
316
+
317
+ for (auto id : extracteds)
318
+ {
319
+ auto it = pointers->find(id);
320
+ if (it != pointers->end()) pointers->erase(it);
321
+ }
322
+ }
323
+
324
+ static void
325
+ erase_extracted_pointers (
326
+ PointerEvent* event, const ExtractedPointerIDSet& extracteds)
327
+ {
328
+ assert(event);
329
+
330
+ for (auto id : extracteds)
331
+ PointerEvent_erase_pointer(event, id);
332
+ }
333
+
334
+ static void
335
+ call_captured_pointer_events (Window* window, PointerEvent* event)
336
+ {
337
+ assert(window && event);
338
+
339
+ ViewList views_capturing_all;
340
+ get_views_capturing_all_pointers(window, &views_capturing_all);
341
+ capture_all_pointers(window, *event, views_capturing_all);
342
+
343
+ PointerMap pointers;
344
+ PointerEvent_each_pointer(event, [&](const auto& pointer)
345
+ {
346
+ if (pointer.id() >= 0) pointers[pointer.id()] = pointer;
347
+ });
348
+
349
+ ExtractedPointerIDSet extracteds;
350
+ capture_targeted_pointers_and_call_events(&extracteds, window, pointers);
351
+ erase_extracted_pointers(&pointers, extracteds);
352
+
353
+ capture_hovering_pointers_and_call_events(&extracteds, views_capturing_all, pointers);
354
+ erase_extracted_pointers(event, extracteds);
355
+ }
356
+
357
+ void
358
+ Window_call_pointer_event (Window* window, PointerEvent* event)
359
+ {
360
+ assert(window);
361
+
362
+ if (!event)
363
+ argument_error(__FILE__, __LINE__);
364
+
365
+ call_captured_pointer_events(window, event);
366
+
367
+ if (!event->empty())
368
+ {
369
+ PointerEvent_update_for_child_view(event, window->root());
370
+ View_call_pointer_event(window->root(), event);
371
+ }
372
+
373
+ cleanup_captures(window);
374
+
375
+ if (event->empty() || event->is_blocked())
376
+ return;
377
+
378
+ window->on_pointer(event);
379
+
380
+ switch ((*event)[0].action())
381
+ {
382
+ case Pointer::DOWN: window->on_pointer_down(event); break;
383
+ case Pointer::UP: window->on_pointer_up(event); break;
384
+ case Pointer::MOVE: window->on_pointer_move(event); break;
385
+ case Pointer::CANCEL: window->on_pointer_cancel(event); break;
386
+ default: break;
123
387
  }
124
388
  }
125
389
 
390
+ void
391
+ Window_call_wheel_event (Window* window, WheelEvent* event)
392
+ {
393
+ assert(window);
394
+
395
+ if (!event)
396
+ argument_error(__FILE__, __LINE__);
397
+
398
+ window->on_wheel(event);
399
+
400
+ View_call_wheel_event(window->root(), event);
401
+ }
402
+
126
403
 
127
404
  Window::Window ()
128
405
  : self(Window_create_data())
@@ -191,6 +468,18 @@ namespace Reflex
191
468
  self->redraw = true;
192
469
  }
193
470
 
471
+ Point
472
+ Window::from_screen (const Point& point) const
473
+ {
474
+ return point - frame().position();
475
+ }
476
+
477
+ Point
478
+ Window::to_screen (const Point& point) const
479
+ {
480
+ return point + frame().position();
481
+ }
482
+
194
483
  void
195
484
  Window::set_title (const char* title)
196
485
  {
@@ -230,7 +519,7 @@ namespace Reflex
230
519
  bool
231
520
  Window::is_resizable () const
232
521
  {
233
- Window_is_resizable(*this);
522
+ return Window_is_resizable(*this);
234
523
  }
235
524
 
236
525
  bool
@@ -275,20 +564,6 @@ namespace Reflex
275
564
  return const_cast<Window*>(this)->painter();
276
565
  }
277
566
 
278
- Point
279
- Window::from_screen (const Point& point) const
280
- {
281
- not_implemented_error(__FILE__, __LINE__);
282
- return 0;
283
- }
284
-
285
- Point
286
- Window::to_screen (const Point& point) const
287
- {
288
- not_implemented_error(__FILE__, __LINE__);
289
- return 0;
290
- }
291
-
292
567
  void
293
568
  Window::on_show (Event* e)
294
569
  {
@@ -327,28 +602,6 @@ namespace Reflex
327
602
  void
328
603
  Window::on_key (KeyEvent* e)
329
604
  {
330
- if (!e)
331
- argument_error(__FILE__, __LINE__);
332
-
333
- switch (e->type)
334
- {
335
- case KeyEvent::DOWN: on_key_down(e); break;
336
- case KeyEvent::UP: on_key_up(e); break;
337
- case KeyEvent::NONE: break;
338
- }
339
-
340
- auto end = self->capturing_views.end();
341
- for (auto it = self->capturing_views.begin(); it != end; ++it)
342
- {
343
- KeyEvent event = *e;
344
- event.capture = true;
345
- View_call_key_event(const_cast<View*>(it->first.get()), event);
346
- }
347
-
348
- if (self->focus)
349
- View_call_key_event(self->focus.get(), *e);
350
-
351
- cleanup_capturing_views(this);
352
605
  }
353
606
 
354
607
  void
@@ -364,30 +617,6 @@ namespace Reflex
364
617
  void
365
618
  Window::on_pointer (PointerEvent* e)
366
619
  {
367
- if (!e)
368
- argument_error(__FILE__, __LINE__);
369
-
370
- switch (e->type)
371
- {
372
- case PointerEvent::DOWN: on_pointer_down(e); break;
373
- case PointerEvent::UP: on_pointer_up(e); break;
374
- case PointerEvent::MOVE: on_pointer_move(e); break;
375
- case PointerEvent::NONE: break;
376
- }
377
-
378
- auto end = self->capturing_views.end();
379
- for (auto it = self->capturing_views.begin(); it != end; ++it)
380
- {
381
- PointerEvent event = *e;
382
- event.capture = true;
383
- for (size_t i = 0; i < event.size; ++i)
384
- event[i] = it->first.get()->from_window(event[i]);
385
- View_call_pointer_event(const_cast<View*>(it->first.get()), event);
386
- }
387
-
388
- View_call_pointer_event(root(), *e);
389
-
390
- cleanup_capturing_views(this);
391
620
  }
392
621
 
393
622
  void
@@ -406,12 +635,13 @@ namespace Reflex
406
635
  }
407
636
 
408
637
  void
409
- Window::on_wheel (WheelEvent* e)
638
+ Window::on_pointer_cancel (PointerEvent* e)
410
639
  {
411
- if (!e)
412
- argument_error(__FILE__, __LINE__);
640
+ }
413
641
 
414
- View_call_wheel_event(root(), *e);
642
+ void
643
+ Window::on_wheel (WheelEvent* e)
644
+ {
415
645
  }
416
646
 
417
647
  Window::operator bool () const
data/src/window.h CHANGED
@@ -4,22 +4,29 @@
4
4
  #define __REFLEX_SRC_WINDOW_H__
5
5
 
6
6
 
7
+ #include <vector>
7
8
  #include <map>
8
9
  #include <xot/time.h>
9
10
  #include <rays/point.h>
10
11
  #include <rays/painter.h>
11
12
  #include <reflex/window.h>
12
13
  #include <reflex/view.h>
14
+ #include "pointer.h"
13
15
 
14
16
 
15
17
  namespace Reflex
16
18
  {
17
19
 
18
20
 
21
+ enum {CAPTURE_ALL = INT_MAX};
22
+
23
+
19
24
  struct Window::Data
20
25
  {
21
26
 
22
- typedef std::map<View::Ref, bool> CapturingViews;
27
+ typedef std::vector<Pointer::ID> CaptureTargetIDList;
28
+
29
+ typedef std::map<View::Ref, CaptureTargetIDList> CaptureMap;
23
30
 
24
31
  int hide_count = 1;
25
32
 
@@ -33,7 +40,7 @@ namespace Reflex
33
40
 
34
41
  double prev_time_update, prev_time_draw, prev_fps = 0;
35
42
 
36
- CapturingViews capturing_views;
43
+ CaptureMap captures;
37
44
 
38
45
  Data ()
39
46
  {
@@ -84,7 +91,19 @@ namespace Reflex
84
91
 
85
92
  void Window_set_focus (Window* window, View* view);
86
93
 
87
- void Window_call_draw_event (Window* window, DrawEvent* event);
94
+ void Window_register_capture (
95
+ Window* window, View* view, Pointer::ID target = CAPTURE_ALL);
96
+
97
+ void Window_unregister_capture (
98
+ Window* window, View* view, Pointer::ID target = CAPTURE_ALL);
99
+
100
+ void Window_call_draw_event (Window* window, DrawEvent* event);
101
+
102
+ void Window_call_key_event (Window* window, KeyEvent* event);
103
+
104
+ void Window_call_pointer_event (Window* window, PointerEvent* event);
105
+
106
+ void Window_call_wheel_event (Window* window, WheelEvent* event);
88
107
 
89
108
  float Window_get_pixel_density (const Window& window);
90
109
 
data/src/world.cpp CHANGED
@@ -251,8 +251,9 @@ namespace Reflex
251
251
  if (!View_is_active(*s1->owner()) || !View_is_active(*s2->owner()))
252
252
  return;
253
253
 
254
- Shape_call_contact_event(s1, ContactEvent(ContactEvent::BEGIN, s2));
255
- Shape_call_contact_event(s2, ContactEvent(ContactEvent::BEGIN, s1));
254
+ ContactEvent e1(ContactEvent::BEGIN, s2), e2(ContactEvent::BEGIN, s1);
255
+ Shape_call_contact_event(s1, &e1);
256
+ Shape_call_contact_event(s2, &e2);
256
257
  }
257
258
 
258
259
  void
@@ -267,8 +268,9 @@ namespace Reflex
267
268
  if (!View_is_active(*s1->owner()) || !View_is_active(*s2->owner()))
268
269
  return;
269
270
 
270
- Shape_call_contact_event(s1, ContactEvent(ContactEvent::END, s2));
271
- Shape_call_contact_event(s2, ContactEvent(ContactEvent::END, s1));
271
+ ContactEvent e1(ContactEvent::END, s2), e2(ContactEvent::END, s1);
272
+ Shape_call_contact_event(s1, &e1);
273
+ Shape_call_contact_event(s2, &e2);
272
274
  }
273
275
 
274
276
 
data/test/helper.rb CHANGED
@@ -12,7 +12,7 @@ require 'reflex'
12
12
  include Xot::Test
13
13
 
14
14
 
15
- unless $REFLEX_NOAUTOINIT
16
- def Rays.fin! () end
17
- def Reflex.fin! () end
15
+ unless defined?($REFLEX_NOAUTOINIT) && $REFLEX_NOAUTOINIT
16
+ def Rays.fin!() end
17
+ def Reflex.fin!() end
18
18
  end
@@ -8,7 +8,7 @@ class TestApplication < Test::Unit::TestCase
8
8
 
9
9
  @@app = Reflex::Application.new
10
10
 
11
- def test_name ()
11
+ def test_name()
12
12
  assert_equal '', @@app.name
13
13
  @@app.name = 'AppName'
14
14
  assert_equal 'AppName', @@app.name
@@ -6,13 +6,29 @@ require_relative 'helper'
6
6
 
7
7
  class TestCaptureEvent < Test::Unit::TestCase
8
8
 
9
- def event (*args)
10
- Reflex::CaptureEvent.new *args.map {|arg|
11
- Reflex::View.capture_flag.symbols2bits *arg
12
- }
9
+ def event(*args)
10
+ Reflex::CaptureEvent.new(*args.map {|arg|
11
+ Reflex::View.capture_flag.symbols2bits(*arg)
12
+ })
13
13
  end
14
14
 
15
- def test_begin ()
15
+ def test_initialize()
16
+ e = event :key, :pointer
17
+ assert_equal [:key], e.begin
18
+ assert_equal [:pointer], e.end
19
+ end
20
+
21
+ def test_dup()
22
+ e1 = event :key, :pointer
23
+ e2 = e1.dup
24
+ e1.block
25
+ e3 = e1.dup
26
+ assert_true e1.blocked?
27
+ assert_false e2.blocked?
28
+ assert_true e3.blocked?
29
+ end
30
+
31
+ def test_begin()
16
32
  c = event [:key, :pointer], []
17
33
  assert_equal [:key, :pointer], c.begin
18
34
  assert_equal true, c.begin?(:key)
@@ -26,7 +42,7 @@ class TestCaptureEvent < Test::Unit::TestCase
26
42
  assert_equal false, c.begin?(:all)
27
43
  end
28
44
 
29
- def test_end ()
45
+ def test_end()
30
46
  c = event [], [:key, :pointer]
31
47
  assert_equal [:key, :pointer], c.end
32
48
  assert_equal true, c.end?(:key)