reflexion 0.1.20 → 0.1.24

Sign up to get free protection for your applications and to get access to all the features.
Files changed (130) 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 +41 -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 +49 -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 +14 -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 +8 -7
  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 +51 -23
  92. data/src/ios/window.mm +18 -0
  93. data/src/osx/event.h +15 -4
  94. data/src/osx/event.mm +214 -24
  95. data/src/osx/native_window.mm +85 -18
  96. data/src/osx/window.mm +22 -0
  97. data/src/pointer.cpp +203 -0
  98. data/src/pointer.h +26 -0
  99. data/src/selector.cpp +1 -1
  100. data/src/shape.cpp +11 -13
  101. data/src/shape.h +1 -1
  102. data/src/view.cpp +205 -118
  103. data/src/view.h +5 -10
  104. data/src/window.cpp +346 -104
  105. data/src/window.h +28 -3
  106. data/src/world.cpp +6 -4
  107. data/test/helper.rb +3 -3
  108. data/test/test_application.rb +1 -1
  109. data/test/test_capture_event.rb +22 -6
  110. data/test/test_contact_event.rb +40 -0
  111. data/test/test_draw_event.rb +35 -0
  112. data/test/test_event.rb +33 -5
  113. data/test/test_focus_event.rb +34 -0
  114. data/test/test_frame_event.rb +38 -0
  115. data/test/test_has_frame.rb +11 -11
  116. data/test/test_key_event.rb +33 -0
  117. data/test/test_pointer.rb +149 -0
  118. data/test/test_pointer_event.rb +70 -104
  119. data/test/test_reflex.rb +1 -1
  120. data/test/test_scroll_event.rb +39 -0
  121. data/test/test_selector.rb +15 -8
  122. data/test/test_shape.rb +8 -8
  123. data/test/test_style.rb +13 -13
  124. data/test/test_style_length.rb +5 -5
  125. data/test/test_timer_event.rb +38 -0
  126. data/test/test_update_event.rb +29 -0
  127. data/test/test_view.rb +57 -30
  128. data/test/test_wheel_event.rb +40 -0
  129. data/test/test_window.rb +45 -26
  130. 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
+ }
236
+
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);
96
243
 
97
- window->self->capturing_views[view] = true;
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);
258
+
259
+ for (auto& [view, targets] : window->self->captures)
260
+ {
261
+ if (targets.empty()) continue;
262
+
263
+ PointerEvent event;
264
+ PointerEvent_set_captured(&event, true);
265
+ extract_targeted_pointers(&event, extracteds, targets, pointers);
266
+ if (event.empty()) continue;
105
267
 
106
- const Window* window = view->window();
107
- if (!window) return;
268
+ PointerEvent_update_for_capturing_view(&event, view);
269
+ View_call_pointer_event(const_cast<View*>(view.get()), &event);
270
+ }
271
+ }
108
272
 
109
- auto it = window->self->capturing_views.find(view);
110
- if (it == window->self->capturing_views.end()) return;
273
+ static void
274
+ extract_hovering_pointers (
275
+ PointerEvent* event, ExtractedPointerIDSet* extracteds,
276
+ const PointerMap& pointers)
277
+ {
278
+ assert(event && event->empty() && extracteds);
111
279
 
112
- it->second = false;
280
+ for (const auto& [_, pointer] : pointers)
281
+ {
282
+ // dragging pointers is captured as a targeted
283
+ if (pointer.is_drag()) continue;
284
+
285
+ extract_pointer(event, extracteds, pointer);
286
+ }
113
287
  }
114
288
 
115
289
  static void
116
- cleanup_capturing_views (Window* window)
290
+ capture_hovering_pointers_and_call_events (
291
+ ExtractedPointerIDSet* extracteds,
292
+ const ViewList& views_capturing_all, const PointerMap& pointers)
117
293
  {
118
- auto end = window->self->capturing_views.end();
119
- for (auto it = window->self->capturing_views.begin(); it != end;)
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)
120
304
  {
121
- auto t = it++;
122
- if (!t->second) window->self->capturing_views.erase(t);
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())
@@ -133,7 +410,7 @@ namespace Reflex
133
410
  self->root->set_name(VIEW_TAG_ROOT);
134
411
  View_set_window(self->root.get(), this);
135
412
 
136
- self->painter.canvas(0, 0, 1, 1);
413
+ self->painter.canvas(0, 0, 1, 1, Window_get_pixel_density(*this));
137
414
  }
138
415
 
139
416
  Window::~Window ()
@@ -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
  {
@@ -221,6 +510,18 @@ namespace Reflex
221
510
  return Window_get_frame(*this);
222
511
  }
223
512
 
513
+ void
514
+ Window::set_resizable (bool state)
515
+ {
516
+ Window_set_resizable(this, state);
517
+ }
518
+
519
+ bool
520
+ Window::is_resizable () const
521
+ {
522
+ return Window_is_resizable(*this);
523
+ }
524
+
224
525
  bool
225
526
  Window::hidden () const
226
527
  {
@@ -263,20 +564,6 @@ namespace Reflex
263
564
  return const_cast<Window*>(this)->painter();
264
565
  }
265
566
 
266
- Point
267
- Window::from_screen (const Point& point) const
268
- {
269
- not_implemented_error(__FILE__, __LINE__);
270
- return 0;
271
- }
272
-
273
- Point
274
- Window::to_screen (const Point& point) const
275
- {
276
- not_implemented_error(__FILE__, __LINE__);
277
- return 0;
278
- }
279
-
280
567
  void
281
568
  Window::on_show (Event* e)
282
569
  {
@@ -315,28 +602,6 @@ namespace Reflex
315
602
  void
316
603
  Window::on_key (KeyEvent* e)
317
604
  {
318
- if (!e)
319
- argument_error(__FILE__, __LINE__);
320
-
321
- switch (e->type)
322
- {
323
- case KeyEvent::DOWN: on_key_down(e); break;
324
- case KeyEvent::UP: on_key_up(e); break;
325
- case KeyEvent::NONE: break;
326
- }
327
-
328
- auto end = self->capturing_views.end();
329
- for (auto it = self->capturing_views.begin(); it != end; ++it)
330
- {
331
- KeyEvent event = *e;
332
- event.capture = true;
333
- View_call_key_event(const_cast<View*>(it->first.get()), event);
334
- }
335
-
336
- if (self->focus)
337
- View_call_key_event(self->focus.get(), *e);
338
-
339
- cleanup_capturing_views(this);
340
605
  }
341
606
 
342
607
  void
@@ -352,30 +617,6 @@ namespace Reflex
352
617
  void
353
618
  Window::on_pointer (PointerEvent* e)
354
619
  {
355
- if (!e)
356
- argument_error(__FILE__, __LINE__);
357
-
358
- switch (e->type)
359
- {
360
- case PointerEvent::DOWN: on_pointer_down(e); break;
361
- case PointerEvent::UP: on_pointer_up(e); break;
362
- case PointerEvent::MOVE: on_pointer_move(e); break;
363
- case PointerEvent::NONE: break;
364
- }
365
-
366
- auto end = self->capturing_views.end();
367
- for (auto it = self->capturing_views.begin(); it != end; ++it)
368
- {
369
- PointerEvent event = *e;
370
- event.capture = true;
371
- for (size_t i = 0; i < event.size; ++i)
372
- event[i] = it->first.get()->from_window(event[i]);
373
- View_call_pointer_event(const_cast<View*>(it->first.get()), event);
374
- }
375
-
376
- View_call_pointer_event(root(), *e);
377
-
378
- cleanup_capturing_views(this);
379
620
  }
380
621
 
381
622
  void
@@ -394,12 +635,13 @@ namespace Reflex
394
635
  }
395
636
 
396
637
  void
397
- Window::on_wheel (WheelEvent* e)
638
+ Window::on_pointer_cancel (PointerEvent* e)
398
639
  {
399
- if (!e)
400
- argument_error(__FILE__, __LINE__);
640
+ }
401
641
 
402
- View_call_wheel_event(root(), *e);
642
+ void
643
+ Window::on_wheel (WheelEvent* e)
644
+ {
403
645
  }
404
646
 
405
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
  {
@@ -78,9 +85,27 @@ namespace Reflex
78
85
 
79
86
  Bounds Window_get_frame (const Window& window);
80
87
 
88
+ void Window_set_resizable (Window* window, bool state);
89
+
90
+ bool Window_is_resizable (const Window& window);
91
+
81
92
  void Window_set_focus (Window* window, View* view);
82
93
 
83
- 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);
107
+
108
+ float Window_get_pixel_density (const Window& window);
84
109
 
85
110
 
86
111
  typedef View* (*Window_CreateRootViewFun) ();
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