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/view.cpp CHANGED
@@ -948,7 +948,7 @@ namespace Reflex
948
948
 
949
949
  View::Data* self = view->self.get();
950
950
 
951
- fire_timers(view, event.now);
951
+ fire_timers(view, event.now());
952
952
 
953
953
  View::ChildList* pchildren = self->pchildren.get();
954
954
  if (pchildren)
@@ -958,9 +958,9 @@ namespace Reflex
958
958
  }
959
959
 
960
960
  update_view_shapes(view);
961
- update_child_world(view, event.dt);
961
+ update_child_world(view, event.dt());
962
962
 
963
- UpdateEvent e = event;
963
+ UpdateEvent e = event.dup();
964
964
  view->on_update(&e);
965
965
 
966
966
  update_views_for_selectors(view);
@@ -1024,7 +1024,10 @@ namespace Reflex
1024
1024
  static void
1025
1025
  draw_default_shape (View* view, DrawEvent* event)
1026
1026
  {
1027
- assert(view && event && event->painter);
1027
+ assert(view && event);
1028
+
1029
+ Painter* painter = event->painter();
1030
+ assert(painter);
1028
1031
 
1029
1032
  const Style& style = View_get_style(view);
1030
1033
  const Color& back_fill = style.background_fill();
@@ -1033,26 +1036,26 @@ namespace Reflex
1033
1036
  Shape* shape = view->shape(false);
1034
1037
  if (shape)
1035
1038
  {
1036
- setup_painter(event->painter, back_fill, back_stroke);
1039
+ setup_painter(painter, back_fill, back_stroke);
1037
1040
  shape->on_draw(event);
1038
1041
  }
1039
1042
  else if (back_fill || back_stroke)
1040
1043
  {
1041
- setup_painter(event->painter, back_fill, back_stroke);
1042
- event->painter->rect(event->bounds);
1044
+ setup_painter(painter, back_fill, back_stroke);
1045
+ painter->rect(event->bounds());
1043
1046
  }
1044
1047
  }
1045
1048
 
1046
1049
  static void
1047
1050
  draw_content (View* view, DrawEvent* event)
1048
1051
  {
1049
- assert(view && event && event->painter);
1052
+ assert(view && event && event->painter());
1050
1053
 
1051
1054
  draw_default_shape(view, event);
1052
1055
 
1053
1056
  const Style& style = View_get_style(view);
1054
1057
  setup_painter(
1055
- event->painter, style.foreground_fill(), style.foreground_stroke());
1058
+ event->painter(), style.foreground_fill(), style.foreground_stroke());
1056
1059
 
1057
1060
  View::ShapeList* pshapes = view->self->pshapes.get();
1058
1061
  if (pshapes && !pshapes->empty())
@@ -1068,10 +1071,10 @@ namespace Reflex
1068
1071
  draw_view (
1069
1072
  View* view, DrawEvent* event, const Point& offset, const Bounds& clip)
1070
1073
  {
1071
- assert(view && event && event->painter);
1074
+ assert(view && event && event->painter());
1072
1075
  View::Data* self = view->self.get();
1073
1076
 
1074
- Painter* p = event->painter;
1077
+ Painter* p = event->painter();
1075
1078
  p->push_state();
1076
1079
 
1077
1080
  if (self->has_flag(View::FLAG_CLIP) && !self->pbody)
@@ -1088,8 +1091,8 @@ namespace Reflex
1088
1091
  {
1089
1092
  for (auto& pchild : *pchildren)
1090
1093
  {
1091
- if (event->bounds & pchild->self->frame)
1092
- View_draw_tree(pchild.get(), *event, offset, clip);
1094
+ if (event->bounds() & pchild->self->frame)
1095
+ View_draw_tree(pchild.get(), event, offset, clip);
1093
1096
  }
1094
1097
  }
1095
1098
 
@@ -1105,23 +1108,24 @@ namespace Reflex
1105
1108
  static void
1106
1109
  draw_view_to_cache (View* view, DrawEvent* event)
1107
1110
  {
1108
- assert(view && event && event->painter && view->self->pcache_image);
1111
+ assert(view && event && event->painter() && view->self->pcache_image);
1109
1112
 
1110
- Painter* view_painter = event->painter;
1113
+ Painter* view_painter = event->painter();
1111
1114
  Painter cache_painter = view->self->pcache_image->painter();
1112
- event->painter = &cache_painter;
1115
+
1116
+ DrawEvent_set_painter(event, &cache_painter);
1113
1117
 
1114
1118
  cache_painter.begin();
1115
- draw_view(view, event, 0, event->bounds);
1119
+ draw_view(view, event, 0, event->bounds());
1116
1120
  cache_painter.end();
1117
1121
 
1118
- event->painter = view_painter;
1122
+ DrawEvent_set_painter(event, view_painter);
1119
1123
  }
1120
1124
 
1121
1125
  static bool
1122
1126
  draw_view_with_cache (View* view, DrawEvent* event, bool redraw)
1123
1127
  {
1124
- assert(view && event && event->painter);
1128
+ assert(view && event && event->painter());
1125
1129
  View::Data* self = view->self.get();
1126
1130
 
1127
1131
  if (!use_cache(view))
@@ -1130,7 +1134,7 @@ namespace Reflex
1130
1134
  return false;
1131
1135
  }
1132
1136
 
1133
- Painter* painter = event->painter;
1137
+ Painter* painter = event->painter();
1134
1138
 
1135
1139
  if (reset_cache_image(view, *painter) || redraw)
1136
1140
  {
@@ -1148,7 +1152,7 @@ namespace Reflex
1148
1152
  if (self->pfilter && *self->pfilter)
1149
1153
  self->pfilter->apply(painter, *self->pcache_image);
1150
1154
  else
1151
- painter->image(*self->pcache_image, event->bounds);
1155
+ painter->image(*self->pcache_image, event->bounds());
1152
1156
 
1153
1157
  painter->pop_state();
1154
1158
 
@@ -1157,7 +1161,7 @@ namespace Reflex
1157
1161
 
1158
1162
  void
1159
1163
  View_draw_tree (
1160
- View* view, const DrawEvent& event, const Point& offset, const Bounds& clip)
1164
+ View* view, DrawEvent* event, const Point& offset, const Bounds& clip)
1161
1165
  {
1162
1166
  if (!view)
1163
1167
  argument_error(__FILE__, __LINE__);
@@ -1166,26 +1170,24 @@ namespace Reflex
1166
1170
 
1167
1171
  bool redraw = self->check_and_remove_flag(View::Data::REDRAW);
1168
1172
 
1169
- if (event.is_blocked() || view->hidden())
1173
+ if (view->hidden() || event->is_blocked())
1170
1174
  return;
1171
1175
 
1172
1176
  if (self->frame.width <= 0 || self->frame.height <= 0)
1173
1177
  return;
1174
1178
 
1175
- Point pos = self->frame.position();
1176
- Bounds clip2 = self->frame.dup().move_by(offset) & clip;
1177
- DrawEvent e = event;
1178
- e.view = view;
1179
- e.bounds = self->frame;
1180
- e.bounds.move_to(0, 0, e.bounds.z);
1179
+ Bounds bounds = self->frame;
1180
+ Point pos = bounds.position();
1181
+ Bounds clip2 = bounds.dup().move_by(offset) & clip;
1181
1182
 
1183
+ bounds.move_to(0, 0, bounds.z);
1182
1184
  if (self->pscroll)
1183
1185
  {
1184
- pos .move_by( *self->pscroll);
1185
- e.bounds.move_by(-*self->pscroll);
1186
+ bounds.move_by(-*self->pscroll);
1187
+ pos .move_by( *self->pscroll);
1186
1188
  }
1187
1189
 
1188
- Painter* p = event.painter;
1190
+ Painter* p = event->painter();
1189
1191
  p->push_matrix();
1190
1192
  p->translate(pos);
1191
1193
 
@@ -1197,9 +1199,15 @@ namespace Reflex
1197
1199
  if (zoom != 1 && zoom > 0)
1198
1200
  p->scale(zoom, zoom);
1199
1201
 
1200
- pos += offset;
1202
+ DrawEvent e = event->dup();
1203
+ DrawEvent_set_view(&e, view);
1204
+ DrawEvent_set_bounds(&e, bounds);
1205
+
1201
1206
  if (!draw_view_with_cache(view, &e, redraw))
1207
+ {
1208
+ pos += offset;
1202
1209
  draw_view(view, &e, pos, clip2);
1210
+ }
1203
1211
 
1204
1212
  p->pop_matrix();
1205
1213
  }
@@ -1227,127 +1235,167 @@ namespace Reflex
1227
1235
  view->self->add_flag(View::Data::UPDATE_SHAPES);
1228
1236
  }
1229
1237
 
1230
- template <typename FUN, typename EVENT>
1238
+ void
1239
+ View_call_key_event (View* view, KeyEvent* event)
1240
+ {
1241
+ if (!view || !event)
1242
+ argument_error(__FILE__, __LINE__);
1243
+
1244
+ if (view->hidden()) return;
1245
+
1246
+ KeyEvent e = event->dup();
1247
+ view->on_key(&e);
1248
+
1249
+ switch (e.action())
1250
+ {
1251
+ case KeyEvent::DOWN: view->on_key_down(&e); break;
1252
+ case KeyEvent::UP: view->on_key_up(&e); break;
1253
+ default: break;
1254
+ }
1255
+ }
1256
+
1231
1257
  static void
1232
- call_children (View* parent, const EVENT& event, FUN fun)
1258
+ call_children (View* parent, std::function<bool(View*)> fun)
1233
1259
  {
1234
1260
  assert(parent);
1235
1261
 
1236
1262
  auto* pchildren = parent->self->pchildren.get();
1237
1263
  if (!pchildren) return;
1238
1264
 
1239
- for (auto& pchild : *pchildren)
1240
- fun(pchild.get(), event);
1265
+ auto end = pchildren->rend();
1266
+ for (auto it = pchildren->rbegin(); it != end; ++it)
1267
+ {
1268
+ if (!fun(it->get()))
1269
+ break;
1270
+ }
1241
1271
  }
1242
1272
 
1243
- void
1244
- View_call_key_event (View* view, const KeyEvent& event)
1273
+ static void
1274
+ call_pointer_events_for_each_child (View* parent, PointerEvent* event)
1245
1275
  {
1246
- if (!view)
1247
- argument_error(__FILE__, __LINE__);
1276
+ assert(parent && event);
1248
1277
 
1249
- KeyEvent e = event;
1250
- view->on_key(&e);
1278
+ call_children(parent, [&](View* child) {
1279
+ PointerEvent e = event->dup();
1280
+ PointerEvent_update_for_child_view(&e, child);
1281
+ View_call_pointer_event(child, &e);
1282
+ return !e.is_blocked();
1283
+ });
1284
+ }
1285
+
1286
+ static void
1287
+ call_pointer_events (View* view, PointerEvent* event)
1288
+ {
1289
+ assert(view && event);
1290
+
1291
+ view->on_pointer(event);
1251
1292
 
1252
- switch (e.type)
1293
+ switch ((*event)[0].action())
1253
1294
  {
1254
- case KeyEvent::DOWN: view->on_key_down(&e); break;
1255
- case KeyEvent::UP: view->on_key_up(&e); break;
1256
- case KeyEvent::NONE: break;
1295
+ case Pointer::DOWN: view->on_pointer_down(event); break;
1296
+ case Pointer::UP: view->on_pointer_up(event); break;
1297
+ case Pointer::MOVE: view->on_pointer_move(event); break;
1298
+ case Pointer::CANCEL: view->on_pointer_cancel(event); break;
1299
+ default: break;
1257
1300
  }
1258
1301
  }
1259
1302
 
1260
1303
  static void
1261
- update_captures (View* view, PointerEvent* event)
1304
+ register_captures (View* view, const PointerEvent& event)
1262
1305
  {
1306
+ assert(view);
1307
+
1263
1308
  Window* win = view->window();
1264
1309
  if (!win)
1265
1310
  invalid_state_error(__FILE__, __LINE__);
1266
1311
 
1267
- PointerEvent_each_pointer(event, [&](const auto& pointer)
1312
+ PointerEvent_each_pointer(&event, [&](const auto& pointer)
1268
1313
  {
1269
- auto action = pointer.action();
1270
- if (action == Pointer::DOWN)
1271
- {
1314
+ if (pointer.action() == Pointer::DOWN)
1272
1315
  Window_register_capture(win, view, pointer.id());
1273
- }
1274
- else if (action == Pointer::UP || action == Pointer::CANCEL)
1275
- {
1276
- Window_unregister_capture(win, view, pointer.id());
1277
- }
1278
1316
  });
1279
1317
  }
1280
1318
 
1281
1319
  static void
1282
- call_pointer_event_for_each_child (View* parent, const PointerEvent& event)
1320
+ unregister_captures (View* view, const PointerEvent& event)
1283
1321
  {
1284
- call_children(parent, event, [](View* child, const PointerEvent& e) {
1285
- PointerEvent e2 = e;
1286
- PointerEvent_update_for_child_view(&e2, child);
1287
- View_call_pointer_event(child, e2);
1322
+ assert(view);
1323
+
1324
+ Window* win = view->window();
1325
+ if (!win)
1326
+ invalid_state_error(__FILE__, __LINE__);
1327
+
1328
+ PointerEvent_each_pointer(&event, [&](const auto& pointer)
1329
+ {
1330
+ auto action = pointer.action();
1331
+ if (action == Pointer::UP || action == Pointer::CANCEL)
1332
+ Window_unregister_capture(win, view, pointer.id());
1288
1333
  });
1289
1334
  }
1290
1335
 
1291
1336
  void
1292
- View_call_pointer_event (View* view, const PointerEvent& event)
1337
+ View_call_pointer_event (View* view, PointerEvent* event)
1293
1338
  {
1294
- if (!view)
1339
+ if (!view || !event)
1295
1340
  argument_error(__FILE__, __LINE__);
1296
1341
 
1297
- if (event.empty())
1342
+ if (view->hidden() || event->empty())
1298
1343
  return;
1299
1344
 
1300
- PointerEvent e = event;
1301
- view->on_pointer(&e);
1345
+ PointerEvent e = event->dup();
1302
1346
 
1303
- switch (e[0].action())
1347
+ if (!e.is_captured())
1348
+ call_pointer_events_for_each_child(view, &e);
1349
+
1350
+ if (!e.is_blocked())
1304
1351
  {
1305
- case Pointer::DOWN: view->on_pointer_down(&e); break;
1306
- case Pointer::UP: view->on_pointer_up(&e); break;
1307
- case Pointer::MOVE: view->on_pointer_move(&e); break;
1308
- case Pointer::CANCEL: view->on_pointer_cancel(&e); break;
1309
- default: break;
1352
+ register_captures(view, e);
1353
+ call_pointer_events(view, &e);
1310
1354
  }
1311
1355
 
1312
- update_captures(view, &e);
1313
-
1314
- if (!e.is_captured())
1315
- call_pointer_event_for_each_child(view, e);
1356
+ unregister_captures(view, e);
1316
1357
  }
1317
1358
 
1318
1359
  void
1319
- View_call_wheel_event (View* view, const WheelEvent& event)
1360
+ View_call_wheel_event (View* view, WheelEvent* event)
1320
1361
  {
1321
- if (!view)
1362
+ if (!view || !event)
1322
1363
  argument_error(__FILE__, __LINE__);
1323
1364
 
1365
+ if (view->hidden()) return;
1366
+
1324
1367
  const Bounds& frame = view->frame();
1325
1368
 
1326
- if (!frame.is_include(event.x, event.y, event.z))
1369
+ if (!frame.is_include(event->position()))
1327
1370
  return;
1328
1371
 
1329
- WheelEvent e = event;
1330
- e.position() -= frame.position();
1372
+ WheelEvent e = event->dup();
1373
+ WheelEvent_set_position(&e, e.position() - frame.position());
1331
1374
 
1332
- view->on_wheel(&e);
1375
+ call_children(view, [&](View* child) {
1376
+ View_call_wheel_event(child, &e);
1377
+ return !e.is_blocked();
1378
+ });
1333
1379
 
1334
- call_children(view, e, View_call_wheel_event);
1380
+ if (e.is_blocked()) return;
1381
+
1382
+ view->on_wheel(&e);
1335
1383
  }
1336
1384
 
1337
1385
  void
1338
- View_call_contact_event (View* view, const ContactEvent& event)
1386
+ View_call_contact_event (View* view, ContactEvent* event)
1339
1387
  {
1340
- if (!view)
1388
+ if (!view || !event)
1341
1389
  argument_error(__FILE__, __LINE__);
1342
1390
 
1343
- ContactEvent e = event;
1391
+ ContactEvent e = event->dup();
1344
1392
  view->on_contact(&e);
1345
1393
 
1346
- switch (e.type)
1394
+ switch (e.action())
1347
1395
  {
1348
1396
  case ContactEvent::BEGIN: view->on_contact_begin(&e); break;
1349
1397
  case ContactEvent::END: view->on_contact_end(&e); break;
1350
- case ContactEvent::NONE: break;
1398
+ default: break;
1351
1399
  }
1352
1400
  }
1353
1401
 
data/src/view.h CHANGED
@@ -30,20 +30,19 @@ namespace Reflex
30
30
  void View_update_tree (View* view, const UpdateEvent& event);
31
31
 
32
32
  void View_draw_tree (
33
- View* view, const DrawEvent& event,
34
- const Point& offset, const Bounds& clip);
33
+ View* view, DrawEvent* event, const Point& offset, const Bounds& clip);
35
34
 
36
35
  void View_update_styles (View* view, const Selector& selector);
37
36
 
38
37
  void View_update_shapes (View* view);
39
38
 
40
- void View_call_key_event (View* view, const KeyEvent& event);
39
+ void View_call_key_event (View* view, KeyEvent* event);
41
40
 
42
- void View_call_pointer_event (View* view, const PointerEvent& event);
41
+ void View_call_pointer_event (View* view, PointerEvent* event);
43
42
 
44
- void View_call_wheel_event (View* view, const WheelEvent& event);
43
+ void View_call_wheel_event (View* view, WheelEvent* event);
45
44
 
46
- void View_call_contact_event (View* view, const ContactEvent& event);
45
+ void View_call_contact_event (View* view, ContactEvent* event);
47
46
 
48
47
 
49
48
  }// Reflex
data/src/window.cpp CHANGED
@@ -31,17 +31,16 @@ namespace Reflex
31
31
 
32
32
  window->self->focus.reset(view);
33
33
 
34
- FocusEvent e(FocusEvent::BLUR, view, current);
35
-
36
34
  if (current)
37
35
  {
36
+ FocusEvent e(FocusEvent::BLUR, view, current);
38
37
  current->on_focus(&e);
39
38
  current->redraw();
40
39
  }
41
40
 
42
41
  if (view)
43
42
  {
44
- e.type = FocusEvent::FOCUS;
43
+ FocusEvent e(FocusEvent::FOCUS, view, current);
45
44
  view->on_focus(&e);
46
45
  view->redraw();
47
46
  }
@@ -133,8 +132,8 @@ namespace Reflex
133
132
 
134
133
  Rays::Bounds frame = window->frame();
135
134
 
136
- event->painter = painter;
137
- 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));
138
137
 
139
138
  painter->begin();
140
139
  painter->push_state();
@@ -142,7 +141,7 @@ namespace Reflex
142
141
 
143
142
  window->on_draw(event);
144
143
  if (!event->is_blocked())
145
- 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));
146
145
 
147
146
  painter->pop_state();
148
147
  painter->end();
@@ -168,7 +167,7 @@ namespace Reflex
168
167
 
169
168
  window->on_key(event);
170
169
 
171
- switch (event->type)
170
+ switch (event->action())
172
171
  {
173
172
  case KeyEvent::DOWN: window->on_key_down(event); break;
174
173
  case KeyEvent::UP: window->on_key_up(event); break;
@@ -180,13 +179,13 @@ namespace Reflex
180
179
  if (!is_capturing(view.get(), targets, View::CAPTURE_KEY))
181
180
  continue;
182
181
 
183
- KeyEvent e = *event;
184
- e.captured = true;
185
- View_call_key_event(const_cast<View*>(view.get()), e);
182
+ KeyEvent e = event->dup();
183
+ KeyEvent_set_captured(&e, true);
184
+ View_call_key_event(const_cast<View*>(view.get()), &e);
186
185
  }
187
186
 
188
187
  if (window->self->focus)
189
- View_call_key_event(window->self->focus.get(), *event);
188
+ View_call_key_event(window->self->focus.get(), event);
190
189
 
191
190
  cleanup_captures(window);
192
191
  }
@@ -259,12 +258,13 @@ namespace Reflex
259
258
  {
260
259
  if (targets.empty()) continue;
261
260
 
262
- PointerEvent e(true);
263
- extract_targeted_pointers(&e, extracteds, targets, pointers);
264
- if (e.empty()) continue;
261
+ PointerEvent event;
262
+ PointerEvent_set_captured(&event, true);
263
+ extract_targeted_pointers(&event, extracteds, targets, pointers);
264
+ if (event.empty()) continue;
265
265
 
266
- PointerEvent_update_for_capturing_view(&e, view);
267
- View_call_pointer_event(const_cast<View*>(view.get()), e);
266
+ PointerEvent_update_for_capturing_view(&event, view);
267
+ View_call_pointer_event(const_cast<View*>(view.get()), &event);
268
268
  }
269
269
  }
270
270
 
@@ -293,15 +293,16 @@ namespace Reflex
293
293
 
294
294
  if (views_capturing_all.empty()) return;
295
295
 
296
- PointerEvent event(true);
296
+ PointerEvent event;
297
+ PointerEvent_set_captured(&event, true);
297
298
  extract_hovering_pointers(&event, extracteds, pointers);
298
299
  if (event.empty()) return;
299
300
 
300
301
  for (auto& view : views_capturing_all)
301
302
  {
302
- PointerEvent e = event;
303
+ PointerEvent e = event.dup();
303
304
  PointerEvent_update_for_capturing_view(&e, view);
304
- View_call_pointer_event(const_cast<View*>(view.get()), e);
305
+ View_call_pointer_event(const_cast<View*>(view.get()), &e);
305
306
  }
306
307
  }
307
308
 
@@ -375,7 +376,7 @@ namespace Reflex
375
376
  if (!event->empty())
376
377
  {
377
378
  PointerEvent_update_for_child_view(event, window->root());
378
- View_call_pointer_event(window->root(), *event);
379
+ View_call_pointer_event(window->root(), event);
379
380
  }
380
381
 
381
382
  cleanup_captures(window);
@@ -391,7 +392,7 @@ namespace Reflex
391
392
 
392
393
  window->on_wheel(event);
393
394
 
394
- View_call_wheel_event(window->root(), *event);
395
+ View_call_wheel_event(window->root(), event);
395
396
  }
396
397
 
397
398
 
@@ -409,9 +410,7 @@ namespace Reflex
409
410
 
410
411
  Window::~Window ()
411
412
  {
412
- //close();
413
-
414
- View_set_window(self->root.get(), NULL);
413
+ //close(true);
415
414
  }
416
415
 
417
416
  void
@@ -447,11 +446,14 @@ namespace Reflex
447
446
  }
448
447
 
449
448
  void
450
- Window::close ()
449
+ Window::close (bool force)
451
450
  {
452
451
  Event e;
453
452
  on_close(&e);
454
- if (e.is_blocked()) return;
453
+ if (!force && e.is_blocked()) return;
454
+
455
+ View_set_window(self->root.get(), NULL);
456
+ self->root.reset();
455
457
 
456
458
  Window_close(this);
457
459
  }
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
 
@@ -12,6 +12,22 @@ class TestCaptureEvent < Test::Unit::TestCase
12
12
  })
13
13
  end
14
14
 
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
+
15
31
  def test_begin()
16
32
  c = event [:key, :pointer], []
17
33
  assert_equal [:key, :pointer], c.begin
@@ -0,0 +1,40 @@
1
+ # -*- coding: utf-8 -*-
2
+
3
+
4
+ require_relative 'helper'
5
+
6
+
7
+ class TestContactEvent < Test::Unit::TestCase
8
+
9
+ def event(*args)
10
+ Reflex::ContactEvent.new(*args)
11
+ end
12
+
13
+ def shape()
14
+ Reflex::RectShape.new
15
+ end
16
+
17
+ def view(*args)
18
+ Reflex::View.new(*args)
19
+ end
20
+
21
+ def test_initialize()
22
+ s, v = shape, view
23
+ v.shape = s# attach to view
24
+ e = event Reflex::ContactEvent::BEGIN, s
25
+ assert_equal :begin, e.action
26
+ assert_equal s, e.shape
27
+ assert_equal v, e.view
28
+ end
29
+
30
+ def test_dup()
31
+ e1 = event Reflex::ContactEvent::BEGIN, shape
32
+ e2 = e1.dup
33
+ e1.block
34
+ e3 = e1.dup
35
+ assert_true e1.blocked?
36
+ assert_false e2.blocked?
37
+ assert_true e3.blocked?
38
+ end
39
+
40
+ end# TestContactEvent