reflexion 0.1.20 → 0.1.24

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
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/event.cpp CHANGED
@@ -1,96 +1,371 @@
1
- #include "reflex/event.h"
1
+ #include "event.h"
2
2
 
3
3
 
4
4
  #include "reflex/timer.h"
5
5
  #include "reflex/shape.h"
6
6
  #include "reflex/exception.h"
7
+ #include "view.h"
8
+ #include "pointer.h"
7
9
 
8
10
 
9
11
  namespace Reflex
10
12
  {
11
13
 
12
14
 
15
+ struct Event::Data
16
+ {
17
+
18
+ bool blocked;
19
+
20
+ double time;
21
+
22
+ Xot::PSharedImpl<Data> parent;
23
+
24
+ Data (bool blocked = false, double time = Xot::time())
25
+ : blocked(blocked), time(time), parent(NULL)
26
+ {
27
+ }
28
+
29
+ void block ()
30
+ {
31
+ blocked = true;
32
+ if (parent) parent->block();
33
+ }
34
+
35
+ };// Event::Data
36
+
37
+
13
38
  Event::Event ()
14
- : blocked(false)
39
+ {
40
+ }
41
+
42
+ Event::Event (const Event* src)
43
+ : self(new Data(*src->self))
44
+ {
45
+ self->parent = src->self;
46
+ }
47
+
48
+ Event::~Event ()
15
49
  {
16
50
  }
17
51
 
18
52
  void
19
53
  Event::block ()
20
54
  {
21
- blocked = true;
55
+ self->block();
22
56
  }
23
57
 
24
58
  bool
25
59
  Event::is_blocked () const
26
60
  {
27
- return blocked;
61
+ return self->blocked;
28
62
  }
29
63
 
64
+ double
65
+ Event::time () const
66
+ {
67
+ return self->time;
68
+ }
69
+
70
+
71
+ struct UpdateEvent::Data
72
+ {
73
+
74
+ double now;
75
+
76
+ float dt;
77
+
78
+ Data (double now = 0, float dt = 0)
79
+ : now(now), dt(dt)
80
+ {
81
+ }
82
+
83
+ };// UpdateEvent::Data
84
+
85
+
86
+ UpdateEvent::UpdateEvent ()
87
+ {
88
+ }
30
89
 
31
90
  UpdateEvent::UpdateEvent (double now, float dt)
32
- : now(now), dt(dt)
91
+ : self(new Data(now, dt))
92
+ {
93
+ }
94
+
95
+ UpdateEvent::UpdateEvent (const UpdateEvent* src)
96
+ : Event(src), self(new Data(*src->self))
97
+ {
98
+ }
99
+
100
+ UpdateEvent
101
+ UpdateEvent::dup () const
33
102
  {
103
+ return UpdateEvent(this);
34
104
  }
35
105
 
106
+ double
107
+ UpdateEvent::now () const
108
+ {
109
+ return self->now;
110
+ }
111
+
112
+ float
113
+ UpdateEvent::dt () const
114
+ {
115
+ return self->dt;
116
+ }
117
+
118
+
119
+ struct DrawEvent::Data
120
+ {
121
+
122
+ View* view;
123
+
124
+ Painter* painter;
125
+
126
+ Bounds bounds;
127
+
128
+ float dt, fps;
129
+
130
+ Data (float dt = 0, float fps = 0)
131
+ : view(NULL), painter(NULL), dt(dt), fps(fps)
132
+ {
133
+ }
134
+
135
+ };// DrawEvent::Data
136
+
137
+
138
+ void
139
+ DrawEvent_set_view (DrawEvent* pthis, View* view)
140
+ {
141
+ if (!pthis)
142
+ argument_error(__FILE__, __LINE__);
143
+
144
+ pthis->self->view = view;
145
+ }
146
+
147
+ void
148
+ DrawEvent_set_painter (DrawEvent* pthis, Painter* painter)
149
+ {
150
+ if (!pthis)
151
+ argument_error(__FILE__, __LINE__);
152
+
153
+ pthis->self->painter = painter;
154
+ }
155
+
156
+ void
157
+ DrawEvent_set_bounds (DrawEvent* pthis, const Bounds& bounds)
158
+ {
159
+ if (!pthis)
160
+ argument_error(__FILE__, __LINE__);
161
+
162
+ pthis->self->bounds = bounds;
163
+ }
164
+
165
+
166
+ DrawEvent::DrawEvent ()
167
+ {
168
+ }
36
169
 
37
170
  DrawEvent::DrawEvent (float dt, float fps)
38
- : view(NULL), painter(NULL), dt(dt), fps(fps)
171
+ : self(new Data(dt, fps))
172
+ {
173
+ }
174
+
175
+ DrawEvent::DrawEvent (const DrawEvent* src)
176
+ : Event(src), self(new Data(*src->self))
177
+ {
178
+ }
179
+
180
+ DrawEvent
181
+ DrawEvent::dup () const
182
+ {
183
+ return DrawEvent(this);
184
+ }
185
+
186
+ Painter*
187
+ DrawEvent::painter ()
188
+ {
189
+ return self->painter;
190
+ }
191
+
192
+ const Painter*
193
+ DrawEvent::painter () const
39
194
  {
195
+ return const_cast<DrawEvent*>(this)->painter();
40
196
  }
41
197
 
198
+ const Bounds&
199
+ DrawEvent::bounds () const
200
+ {
201
+ return self->bounds;
202
+ }
203
+
204
+ float
205
+ DrawEvent::dt () const
206
+ {
207
+ return self->dt;
208
+ }
209
+
210
+ float
211
+ DrawEvent::fps () const
212
+ {
213
+ return self->fps;
214
+ }
215
+
216
+
217
+ struct FrameEvent::Data
218
+ {
219
+
220
+ Bounds frame;
221
+
222
+ coord dx, dy, dw, dh;
223
+
224
+ float angle, dangle;
225
+
226
+ Data (
227
+ const Bounds& frame = 0,
228
+ coord dx = 0, coord dy = 0, coord dw = 0, coord dh = 0,
229
+ float angle = 0, float dangle = 0)
230
+ : frame(frame), dx(dx), dy(dy), dw(dw), dh(dh), angle(angle), dangle(dangle)
231
+ {
232
+ }
233
+
234
+ };// FrameEvent::Data
235
+
236
+
237
+ FrameEvent::FrameEvent ()
238
+ {
239
+ }
42
240
 
43
241
  FrameEvent::FrameEvent (
44
242
  const Bounds& frame, coord dx, coord dy, coord dwidth, coord dheight,
45
243
  float angle, float dangle)
46
- : frame(frame), dx(dx), dy(dy), dwidth(dwidth), dheight(dheight),
47
- angle(angle), dangle(dangle)
244
+ : self(new Data(frame, dx, dy, dwidth, dheight, angle, dangle))
48
245
  {
49
246
  }
50
247
 
51
248
  FrameEvent::FrameEvent (
52
249
  const Bounds& frame, const Bounds& prev_frame,
53
250
  float angle, float prev_angle)
54
- : frame(frame),
55
- dx( frame.x - prev_frame.x), dy( frame.y - prev_frame.y),
56
- dwidth(frame.w - prev_frame.w), dheight(frame.h - prev_frame.h),
57
- angle(angle), dangle(angle - prev_angle)
251
+ : self(new Data(
252
+ frame,
253
+ frame.x - prev_frame.x, frame.y - prev_frame.y,
254
+ frame.w - prev_frame.w, frame.h - prev_frame.h,
255
+ angle, angle - prev_angle))
256
+ {
257
+ }
258
+
259
+ FrameEvent::FrameEvent (const FrameEvent* src)
260
+ : Event(src), self(new Data(*src->self))
58
261
  {
59
262
  }
60
263
 
264
+ FrameEvent
265
+ FrameEvent::dup () const
266
+ {
267
+ return FrameEvent(this);
268
+ }
269
+
270
+ const Bounds&
271
+ FrameEvent::frame () const
272
+ {
273
+ return self->frame;
274
+ }
275
+
276
+ coord
277
+ FrameEvent::dx () const
278
+ {
279
+ return self->dx;
280
+ }
281
+
282
+ coord
283
+ FrameEvent::dy () const
284
+ {
285
+ return self->dy;
286
+ }
287
+
288
+ coord
289
+ FrameEvent::dwidth () const
290
+ {
291
+ return self->dw;
292
+ }
293
+
294
+ coord
295
+ FrameEvent::dheight () const
296
+ {
297
+ return self->dh;
298
+ }
299
+
300
+ float
301
+ FrameEvent::angle () const
302
+ {
303
+ return self->angle;
304
+ }
305
+
306
+ float
307
+ FrameEvent::dangle () const
308
+ {
309
+ return self->dangle;
310
+ }
311
+
61
312
  bool
62
313
  FrameEvent::is_move () const
63
314
  {
64
- return dx != 0 || dy != 0;
315
+ return self->dx != 0 || self->dy != 0;
65
316
  }
66
317
 
67
318
  bool
68
319
  FrameEvent::is_resize () const
69
320
  {
70
- return dwidth != 0 || dheight != 0;
321
+ return self->dw != 0 || self->dh != 0;
71
322
  }
72
323
 
73
324
  bool
74
325
  FrameEvent::is_rotate () const
75
326
  {
76
- return dangle != 0;
327
+ return self->dangle != 0;
77
328
  }
78
329
 
79
330
 
331
+ struct ScrollEvent::Data
332
+ {
333
+
334
+ Point scroll, dscroll;
335
+
336
+ Data (const Point& scroll, const Point& dscroll)
337
+ : scroll(scroll), dscroll(dscroll)
338
+ {
339
+ }
340
+
341
+ };// ScrollEvent::Data
342
+
343
+
80
344
  ScrollEvent::ScrollEvent ()
81
- : x(0), y(0), z(0), dx(0), dy(0), dz(0)
345
+ : self(new Data(0, 0))
82
346
  {
83
347
  }
84
348
 
85
349
  ScrollEvent::ScrollEvent (coord x, coord y, coord z, coord dx, coord dy, coord dz)
86
- : x(x), y(y), z(z), dx(dx), dy(dy), dz(dz)
350
+ : self(new Data(Point(x, y, z), Point(dx, dy, dz)))
351
+ {
352
+ }
353
+
354
+ ScrollEvent::ScrollEvent (const ScrollEvent* src)
355
+ : Event(src), self(new Data(*src->self))
87
356
  {
88
357
  }
89
358
 
359
+ ScrollEvent
360
+ ScrollEvent::dup () const
361
+ {
362
+ return ScrollEvent(this);
363
+ }
364
+
90
365
  Point&
91
366
  ScrollEvent::scroll ()
92
367
  {
93
- return *(Point*) &scroll_;
368
+ return self->scroll;
94
369
  }
95
370
 
96
371
  const Point&
@@ -100,117 +375,416 @@ namespace Reflex
100
375
  }
101
376
 
102
377
  Point&
103
- ScrollEvent::delta ()
378
+ ScrollEvent::dscroll ()
104
379
  {
105
- return *(Point*) &delta_;
380
+ return self->dscroll;
106
381
  }
107
382
 
108
383
  const Point&
109
- ScrollEvent::delta () const
384
+ ScrollEvent::dscroll () const
110
385
  {
111
- return const_cast<ScrollEvent*>(this)->delta();
386
+ return const_cast<ScrollEvent*>(this)->dscroll();
112
387
  }
113
388
 
114
389
 
390
+ struct FocusEvent::Data
391
+ {
392
+
393
+ Action action;
394
+
395
+ View *current, *last;
396
+
397
+ Data (Action action = ACTION_NONE, View* current = NULL, View* last = NULL)
398
+ : action(action), current(current), last(last)
399
+ {
400
+ }
401
+
402
+ };// FocusEvent::Data
403
+
404
+
115
405
  FocusEvent::FocusEvent ()
116
406
  {
117
407
  }
118
408
 
119
- FocusEvent::FocusEvent (Type type, View* current, View* last)
120
- : type(type), current(current), last(last)
409
+ FocusEvent::FocusEvent (Action action, View* current, View* last)
410
+ : self(new Data(action, current, last))
411
+ {
412
+ }
413
+
414
+ FocusEvent::FocusEvent (const FocusEvent* src)
415
+ : Event(src), self(new Data(*src->self))
416
+ {
417
+ }
418
+
419
+ FocusEvent
420
+ FocusEvent::dup () const
421
+ {
422
+ return FocusEvent(this);
423
+ }
424
+
425
+ FocusEvent::Action
426
+ FocusEvent::action () const
427
+ {
428
+ return self->action;
429
+ }
430
+
431
+ View*
432
+ FocusEvent::current () const
433
+ {
434
+ return self->current;
435
+ }
436
+
437
+ View*
438
+ FocusEvent::last () const
439
+ {
440
+ return self->last;
441
+ }
442
+
443
+
444
+ struct KeyEvent::Data
445
+ {
446
+
447
+ Action action;
448
+
449
+ String chars;
450
+
451
+ int code;
452
+
453
+ uint modifiers;
454
+
455
+ int repeat;
456
+
457
+ bool captured;
458
+
459
+ Data (
460
+ Action action = ACTION_NONE, const char* chars = NULL, int code = KEY_NONE,
461
+ uint modifiers = MOD_NONE, int repeat = 0, bool captured = false)
462
+ : action(action), chars(chars ? chars : ""), code(code),
463
+ modifiers(modifiers), repeat(repeat), captured(captured)
464
+ {
465
+ }
466
+
467
+ };// KeyEvent::Data
468
+
469
+
470
+ void
471
+ KeyEvent_set_captured (KeyEvent* pthis, bool captured)
121
472
  {
473
+ if (!pthis)
474
+ argument_error(__FILE__, __LINE__);
475
+
476
+ pthis->self->captured = captured;
122
477
  }
123
478
 
124
479
 
125
480
  KeyEvent::KeyEvent ()
126
- : type(NONE), code(KEY_NONE), modifiers(MOD_NONE), repeat(0), capture(false)
127
481
  {
128
482
  }
129
483
 
130
484
  KeyEvent::KeyEvent (
131
- Type type, const char* chars, int code, uint modifiers, int repeat)
132
- : type(type), chars(chars ? chars : ""), code(code), modifiers(modifiers),
133
- repeat(repeat), capture(false)
485
+ Action action, const char* chars, int code, uint modifiers, int repeat)
486
+ : self(new Data(action, chars, code, modifiers, repeat))
134
487
  {
135
488
  }
136
489
 
490
+ KeyEvent::KeyEvent (const KeyEvent* src)
491
+ : Event(src), self(new Data(*src->self))
492
+ {
493
+ }
137
494
 
138
- PointerEvent::PointerEvent ()
139
- : type(NONE), pointer_type(POINTER_NONE),
140
- size(0), modifiers(MOD_NONE), count(0), drag(false), capture(false),
141
- x(0), y(0), z(0)
495
+ KeyEvent
496
+ KeyEvent::dup () const
142
497
  {
498
+ return KeyEvent(this);
143
499
  }
144
500
 
145
- PointerEvent::PointerEvent (
146
- Type type, uint pointer_type, coord x, coord y, uint modifiers, uint count, bool drag)
147
- : type(type), pointer_type(pointer_type),
148
- size(1), modifiers(modifiers), count(count), drag(drag), capture(false),
149
- x(x), y(y), z(0)
501
+ KeyEvent::Action
502
+ KeyEvent::action () const
150
503
  {
504
+ return self->action;
151
505
  }
152
506
 
153
- PointerEvent::PointerEvent (
154
- Type type, uint pointer_type, const Point* positions_, size_t size,
155
- uint modifiers, uint count, bool drag)
156
- : type(type), pointer_type(pointer_type),
157
- size(size), modifiers(modifiers), count(count), drag(drag), capture(false)
507
+ const char*
508
+ KeyEvent::chars () const
158
509
  {
159
- if (!positions_ && size > 0)
160
- argument_error(__FILE__, __LINE__);
510
+ return self->chars;
511
+ }
161
512
 
162
- if (size > MAX) size = MAX;
513
+ int
514
+ KeyEvent::code () const
515
+ {
516
+ return self->code;
517
+ }
518
+
519
+ uint
520
+ KeyEvent::modifiers () const
521
+ {
522
+ return self->modifiers;
523
+ }
524
+
525
+ int
526
+ KeyEvent::repeat () const
527
+ {
528
+ return self->repeat;
529
+ }
530
+
531
+ bool
532
+ KeyEvent::is_captured () const
533
+ {
534
+ return self->captured;
535
+ }
163
536
 
164
- if (positions_)
537
+
538
+ struct PointerEvent::Data
539
+ {
540
+
541
+ std::vector<Pointer> pointers;
542
+
543
+ bool captured;
544
+
545
+ Data (bool captured = false)
546
+ : captured(captured)
165
547
  {
166
- for (size_t i = 0; i < size; ++i)
167
- positions[i] = *(Coord3*) &positions_[i];
168
548
  }
549
+
550
+ };// PointerEvent::Data
551
+
552
+
553
+ void
554
+ PointerEvent_add_pointer (PointerEvent* pthis, const Pointer& pointer)
555
+ {
556
+ if (!pthis)
557
+ argument_error(__FILE__, __LINE__);
558
+
559
+ pthis->self->pointers.emplace_back(pointer);
169
560
  }
170
561
 
171
- Point&
172
- PointerEvent::position (size_t i)
562
+ void
563
+ PointerEvent_erase_pointer (PointerEvent* pthis, Pointer::ID id)
173
564
  {
174
- if (i >= size)
565
+ if (!pthis)
566
+ argument_error(__FILE__, __LINE__);
567
+
568
+ auto& pointers = pthis->self->pointers;
569
+ auto it = std::find_if(
570
+ pointers.begin(), pointers.end(),
571
+ [=](const auto& pointer)
572
+ {
573
+ return pointer.id() == id;
574
+ });
575
+
576
+ if (it == pointers.end()) return;
577
+
578
+ pointers.erase(it);
579
+ }
580
+
581
+ Pointer&
582
+ PointerEvent_pointer_at (PointerEvent* pthis, size_t index)
583
+ {
584
+ if (!pthis)
585
+ argument_error(__FILE__, __LINE__);
586
+
587
+ auto& pointers = pthis->self->pointers;
588
+ if (index >= pointers.size())
175
589
  index_error(__FILE__, __LINE__);
176
590
 
177
- return *(Point*) &positions[i];
591
+ return pointers[index];
178
592
  }
179
593
 
180
- const Point&
181
- PointerEvent::position (size_t i) const
594
+ void
595
+ PointerEvent_each_pointer (
596
+ const PointerEvent* pthis, std::function<void(const Pointer&)> fun)
182
597
  {
183
- return const_cast<PointerEvent*>(this)->position(i);
598
+ if (!pthis)
599
+ argument_error(__FILE__, __LINE__);
600
+
601
+ for (const auto& pointer : pthis->self->pointers)
602
+ fun(pointer);
184
603
  }
185
604
 
186
- Point&
187
- PointerEvent::operator [] (size_t i)
605
+ void
606
+ PointerEvent_set_captured (PointerEvent* pthis, bool captured)
188
607
  {
189
- return position(i);
608
+ if (!pthis)
609
+ argument_error(__FILE__, __LINE__);
610
+
611
+ pthis->self->captured = captured;
190
612
  }
191
613
 
192
- const Point&
193
- PointerEvent::operator [] (size_t i) const
614
+ static void
615
+ filter_and_offset_pointer_positions (PointerEvent* event, const Bounds& frame)
194
616
  {
195
- return position(i);
617
+ assert(event);
618
+
619
+ const Point& offset = frame.position();
620
+
621
+ std::vector<Pointer> pointers;
622
+ for (const auto& pointer : event->self->pointers)
623
+ {
624
+ if (!frame.is_include(pointer.position()))
625
+ continue;
626
+
627
+ pointers.emplace_back(pointer);
628
+ Pointer_update_positions(&pointers.back(), [&](Point* pos)
629
+ {
630
+ *pos -= offset;
631
+ });
632
+ }
633
+
634
+ event->self->pointers = pointers;
635
+ }
636
+
637
+ static void
638
+ scroll_and_zoom_pointer_positions (
639
+ PointerEvent* event, const Point& scroll, float zoom)
640
+ {
641
+ assert(event);
642
+
643
+ if (zoom == 0)
644
+ argument_error(__FILE__, __LINE__);
645
+
646
+ if (scroll == 0 && zoom == 1)
647
+ return;
648
+
649
+ for (auto& pointer : event->self->pointers)
650
+ {
651
+ Pointer_update_positions(&pointer, [=](Point* pos)
652
+ {
653
+ *pos -= scroll;
654
+ *pos /= zoom;
655
+ });
656
+ }
657
+ }
658
+
659
+ void
660
+ PointerEvent_update_for_child_view (PointerEvent* pthis, const View* view)
661
+ {
662
+ if (!pthis || !view)
663
+ argument_error(__FILE__, __LINE__);
664
+
665
+ filter_and_offset_pointer_positions(pthis, view->frame());
666
+ scroll_and_zoom_pointer_positions(pthis, view->scroll(), view->zoom());
667
+ }
668
+
669
+ void
670
+ PointerEvent_update_for_capturing_view (PointerEvent* pthis, const View* view)
671
+ {
672
+ if (!pthis || !view)
673
+ argument_error(__FILE__, __LINE__);
674
+
675
+ for (auto& pointer : pthis->self->pointers)
676
+ {
677
+ Pointer_update_positions(&pointer, [=](Point* pos)
678
+ {
679
+ *pos = view->from_window(*pos);
680
+ });
681
+ }
682
+
683
+ scroll_and_zoom_pointer_positions(pthis, view->scroll(), view->zoom());
684
+ }
685
+
686
+
687
+ PointerEvent::PointerEvent ()
688
+ {
689
+ }
690
+
691
+ PointerEvent::PointerEvent (const Pointer* pointers, size_t size)
692
+ {
693
+ for (size_t i = 0; i < size; ++i)
694
+ self->pointers.emplace_back(pointers[i]);
695
+ }
696
+
697
+ PointerEvent::PointerEvent (const PointerEvent* src)
698
+ : Event(src), self(new Data(*src->self))
699
+ {
700
+ }
701
+
702
+ PointerEvent
703
+ PointerEvent::dup () const
704
+ {
705
+ return PointerEvent(this);
706
+ }
707
+
708
+ size_t
709
+ PointerEvent::size () const
710
+ {
711
+ return self->pointers.size();
712
+ }
713
+
714
+ bool
715
+ PointerEvent::empty () const
716
+ {
717
+ return size() == 0;
718
+ }
719
+
720
+ bool
721
+ PointerEvent::is_captured () const
722
+ {
723
+ return self->captured;
724
+ }
725
+
726
+ const Pointer&
727
+ PointerEvent::operator [] (size_t index) const
728
+ {
729
+ if (index >= self->pointers.size())
730
+ index_error(__FILE__, __LINE__);
731
+
732
+ return self->pointers[index];
733
+ }
734
+
735
+
736
+ struct WheelEvent::Data
737
+ {
738
+
739
+ Point position, dposition;
740
+
741
+ uint modifiers;
742
+
743
+ Data (
744
+ const Point& position = 0, const Point& dposition = 0,
745
+ uint modifiers = 0)
746
+ : position(position), dposition(dposition), modifiers(modifiers)
747
+ {
748
+ }
749
+
750
+ };// WheelEvent::Data
751
+
752
+
753
+ void
754
+ WheelEvent_set_position (WheelEvent* pthis, const Point& position)
755
+ {
756
+ if (!pthis)
757
+ argument_error(__FILE__, __LINE__);
758
+
759
+ pthis->self->position = position;
196
760
  }
197
761
 
198
762
 
199
763
  WheelEvent::WheelEvent ()
200
- : dx(0), dy(0), dz(0), x(0), y(0), z(0), modifiers(0)
201
764
  {
202
765
  }
203
766
 
204
767
  WheelEvent::WheelEvent (
205
- coord dx, coord dy, coord dz, coord x, coord y, coord z, uint modifiers)
206
- : dx(dx), dy(dy), dz(dz), x(x), y(y), z(z), modifiers(modifiers)
768
+ coord x, coord y, coord z, coord dx, coord dy, coord dz, uint modifiers)
769
+ : self(new Data(Point(x, y, z), Point(dx, dy, dz), modifiers))
207
770
  {
208
771
  }
209
772
 
773
+ WheelEvent::WheelEvent (const WheelEvent* src)
774
+ : Event(src), self(new Data(*src->self))
775
+ {
776
+ }
777
+
778
+ WheelEvent
779
+ WheelEvent::dup () const
780
+ {
781
+ return WheelEvent(this);
782
+ }
783
+
210
784
  Point&
211
785
  WheelEvent::position ()
212
786
  {
213
- return *(Point*) &position_;
787
+ return self->position;
214
788
  }
215
789
 
216
790
  const Point&
@@ -220,79 +794,211 @@ namespace Reflex
220
794
  }
221
795
 
222
796
  Point&
223
- WheelEvent::delta ()
797
+ WheelEvent::dposition ()
224
798
  {
225
- return *(Point*) &delta_;
799
+ return self->dposition;
226
800
  }
227
801
 
228
802
  const Point&
229
- WheelEvent::delta () const
803
+ WheelEvent::dposition () const
804
+ {
805
+ return const_cast<WheelEvent*>(this)->dposition();
806
+ }
807
+
808
+ uint
809
+ WheelEvent::modifiers () const
230
810
  {
231
- return const_cast<WheelEvent*>(this)->delta();
811
+ return self->modifiers;
232
812
  }
233
813
 
234
814
 
815
+ struct CaptureEvent::Data
816
+ {
817
+
818
+ uint begin, end;
819
+
820
+ Data (uint begin = 0, uint end = 0)
821
+ : begin(begin), end(end)
822
+ {
823
+ }
824
+
825
+ };// CaptureEvent::Data
826
+
827
+
235
828
  CaptureEvent::CaptureEvent ()
236
- : begin(0), end(0)
237
829
  {
238
830
  }
239
831
 
240
832
  CaptureEvent::CaptureEvent (uint begin, uint end)
241
- : begin(begin), end(end)
833
+ : self(new Data(begin, end))
834
+ {
835
+ }
836
+
837
+ CaptureEvent::CaptureEvent (const CaptureEvent* src)
838
+ : Event(src), self(new Data(*src->self))
839
+ {
840
+ }
841
+
842
+ CaptureEvent
843
+ CaptureEvent::dup () const
242
844
  {
845
+ return CaptureEvent(this);
243
846
  }
244
847
 
848
+ uint
849
+ CaptureEvent::begin () const
850
+ {
851
+ return self->begin;
852
+ }
853
+
854
+ uint
855
+ CaptureEvent::end () const
856
+ {
857
+ return self->end;
858
+ }
859
+
860
+
861
+ struct TimerEvent::Data
862
+ {
863
+
864
+ Timer::Ref timer;
865
+
866
+ Data (Timer* timer = NULL)
867
+ : timer(timer)
868
+ {
869
+ }
870
+
871
+ };// TimerEvent::Data
872
+
873
+
874
+ TimerEvent::TimerEvent ()
875
+ {
876
+ }
245
877
 
246
878
  TimerEvent::TimerEvent (Timer* timer)
247
- : timer(timer)
879
+ : self(new Data(timer))
880
+ {
881
+ }
882
+
883
+ TimerEvent::TimerEvent (const TimerEvent* src)
884
+ : Event(src), self(new Data(*src->self))
885
+ {
886
+ }
887
+
888
+ TimerEvent
889
+ TimerEvent::dup () const
890
+ {
891
+ return TimerEvent(this);
892
+ }
893
+
894
+ Timer*
895
+ TimerEvent::timer ()
248
896
  {
897
+ return self->timer;
898
+ }
899
+
900
+ const Timer*
901
+ TimerEvent::timer () const
902
+ {
903
+ return const_cast<TimerEvent*>(this)->timer();
249
904
  }
250
905
 
251
906
  View*
252
907
  TimerEvent::owner () const
253
908
  {
254
- return timer ? timer->owner() : NULL;
909
+ return self->timer ? self->timer->owner() : NULL;
255
910
  }
256
911
 
257
912
  int
258
913
  TimerEvent::id () const
259
914
  {
260
- return timer ? timer->id() : Timer::ID_INVALID;
915
+ return self->timer ? self->timer->id() : Timer::ID_INVALID;
261
916
  }
262
917
 
263
918
  float
264
919
  TimerEvent::interval () const
265
920
  {
266
- return timer ? timer->interval() : -1;
267
- }
268
-
269
- void
270
- TimerEvent::set_count (int count)
271
- {
272
- if (timer) timer->set_count(count);
921
+ return self->timer ? self->timer->interval() : -1;
273
922
  }
274
923
 
275
924
  int
276
925
  TimerEvent::count () const
277
926
  {
278
- return timer ? timer->count() : 0;
927
+ return self->timer ? self->timer->count() : 0;
279
928
  }
280
929
 
281
930
  bool
282
931
  TimerEvent::is_finished () const
283
932
  {
284
- return timer ? timer->is_finished() : true;
933
+ return self->timer ? self->timer->is_finished() : true;
285
934
  }
286
935
 
287
936
 
937
+ struct ContactEvent::Data
938
+ {
939
+
940
+ Action action;
941
+
942
+ Shape* shape;
943
+
944
+ View* view;
945
+
946
+ Data (Action action = ACTION_NONE, Shape* shape = NULL, View* view = NULL)
947
+ : action(action), shape(shape), view(view)
948
+ {
949
+ }
950
+
951
+ };// ContactEvent::Data
952
+
953
+
288
954
  ContactEvent::ContactEvent ()
289
- : type(NONE), shape(NULL), view(NULL)
290
955
  {
291
956
  }
292
957
 
293
- ContactEvent::ContactEvent (Type type, Shape* shape)
294
- : type(type), shape(shape), view(shape ? shape->owner() : NULL)
958
+ ContactEvent::ContactEvent (Action action, Shape* shape)
959
+ : self(new Data(action, shape, shape ? shape->owner() : NULL))
960
+ {
961
+ }
962
+
963
+ ContactEvent::ContactEvent (const ContactEvent* src)
964
+ : Event(src), self(new Data(*src->self))
965
+ {
966
+ }
967
+
968
+ ContactEvent
969
+ ContactEvent::dup () const
970
+ {
971
+ return ContactEvent(this);
972
+ }
973
+
974
+ ContactEvent::Action
975
+ ContactEvent::action () const
976
+ {
977
+ return self->action;
978
+ }
979
+
980
+ Shape*
981
+ ContactEvent::shape ()
982
+ {
983
+ return self->shape;
984
+ }
985
+
986
+ const Shape*
987
+ ContactEvent::shape () const
988
+ {
989
+ return const_cast<ContactEvent*>(this)->shape();
990
+ }
991
+
992
+ View*
993
+ ContactEvent::view ()
994
+ {
995
+ return self->view;
996
+ }
997
+
998
+ const View*
999
+ ContactEvent::view () const
295
1000
  {
1001
+ return const_cast<ContactEvent*>(this)->view();
296
1002
  }
297
1003
 
298
1004