reflexion 0.1.22 → 0.1.23

Sign up to get free protection for your applications and to get access to all the features.
Files changed (54) hide show
  1. checksums.yaml +4 -4
  2. data/.doc/ext/reflex/event.cpp +9 -1
  3. data/.doc/ext/reflex/key_event.cpp +3 -3
  4. data/.doc/ext/reflex/native.cpp +2 -0
  5. data/.doc/ext/reflex/pointer.cpp +158 -0
  6. data/.doc/ext/reflex/pointer_event.cpp +29 -88
  7. data/.doc/ext/reflex/selector.cpp +8 -0
  8. data/.doc/ext/reflex/view.cpp +57 -0
  9. data/.doc/ext/reflex/window.cpp +24 -0
  10. data/VERSION +1 -1
  11. data/ext/reflex/event.cpp +11 -2
  12. data/ext/reflex/key_event.cpp +3 -3
  13. data/ext/reflex/native.cpp +2 -0
  14. data/ext/reflex/pointer.cpp +170 -0
  15. data/ext/reflex/pointer_event.cpp +29 -94
  16. data/ext/reflex/selector.cpp +9 -0
  17. data/ext/reflex/view.cpp +67 -3
  18. data/ext/reflex/window.cpp +30 -3
  19. data/include/reflex/defs.h +0 -18
  20. data/include/reflex/event.h +26 -27
  21. data/include/reflex/pointer.h +107 -0
  22. data/include/reflex/ruby/pointer.h +41 -0
  23. data/include/reflex/ruby/view.h +9 -0
  24. data/include/reflex/ruby/window.h +9 -0
  25. data/include/reflex/selector.h +1 -1
  26. data/include/reflex/view.h +6 -4
  27. data/include/reflex/window.h +10 -8
  28. data/lib/reflex/key_event.rb +1 -1
  29. data/lib/reflex/pointer.rb +107 -0
  30. data/lib/reflex/pointer_event.rb +16 -54
  31. data/lib/reflex.rb +1 -0
  32. data/reflex.gemspec +5 -5
  33. data/src/event.cpp +189 -37
  34. data/src/event.h +32 -0
  35. data/src/ios/event.h +15 -3
  36. data/src/ios/event.mm +126 -11
  37. data/src/ios/view_controller.mm +49 -21
  38. data/src/osx/event.h +6 -3
  39. data/src/osx/event.mm +40 -22
  40. data/src/osx/native_window.mm +79 -16
  41. data/src/pointer.cpp +203 -0
  42. data/src/pointer.h +26 -0
  43. data/src/selector.cpp +1 -1
  44. data/src/view.cpp +83 -72
  45. data/src/view.h +0 -4
  46. data/src/window.cpp +321 -97
  47. data/src/window.h +22 -3
  48. data/test/test_event.rb +16 -2
  49. data/test/test_pointer.rb +149 -0
  50. data/test/test_pointer_event.rb +70 -104
  51. data/test/test_selector.rb +7 -0
  52. data/test/test_view.rb +38 -11
  53. data/test/test_window.rb +27 -25
  54. metadata +46 -35
data/src/view.cpp CHANGED
@@ -9,6 +9,7 @@
9
9
  #include "reflex/exception.h"
10
10
  #include "reflex/debug.h"
11
11
  #include "window.h"
12
+ #include "event.h"
12
13
  #include "selector.h"
13
14
  #include "timer.h"
14
15
  #include "style.h"
@@ -877,7 +878,7 @@ namespace Reflex
877
878
  result->clear();
878
879
 
879
880
  Selector* sel = view->self->pselector.get();
880
- if (!sel || sel->is_empty())
881
+ if (!sel || sel->empty())
881
882
  return false;
882
883
 
883
884
  get_styles_for_selector(result, view, *sel);
@@ -1211,7 +1212,7 @@ namespace Reflex
1211
1212
 
1212
1213
  View::Data* self = view->self.get();
1213
1214
 
1214
- if (selector.is_empty())
1215
+ if (selector.empty())
1215
1216
  self->add_flag(View::Data::UPDATE_STYLE);
1216
1217
  else
1217
1218
  self->selectors_for_update().insert(selector);
@@ -1228,16 +1229,15 @@ namespace Reflex
1228
1229
 
1229
1230
  template <typename FUN, typename EVENT>
1230
1231
  static void
1231
- call_children (View* parent, FUN fun, const EVENT& e)
1232
+ call_children (View* parent, const EVENT& event, FUN fun)
1232
1233
  {
1233
1234
  assert(parent);
1234
1235
 
1235
- View::ChildList* pchildren = parent->self->pchildren.get();
1236
- if (pchildren)
1237
- {
1238
- for (auto& pchild : *pchildren)
1239
- fun(pchild.get(), e);
1240
- }
1236
+ auto* pchildren = parent->self->pchildren.get();
1237
+ if (!pchildren) return;
1238
+
1239
+ for (auto& pchild : *pchildren)
1240
+ fun(pchild.get(), event);
1241
1241
  }
1242
1242
 
1243
1243
  void
@@ -1246,9 +1246,6 @@ namespace Reflex
1246
1246
  if (!view)
1247
1247
  argument_error(__FILE__, __LINE__);
1248
1248
 
1249
- bool capturing = view->capture() & View::CAPTURE_KEY;
1250
- if (capturing != event.capture) return;
1251
-
1252
1249
  KeyEvent e = event;
1253
1250
  view->on_key(&e);
1254
1251
 
@@ -1261,40 +1258,34 @@ namespace Reflex
1261
1258
  }
1262
1259
 
1263
1260
  static void
1264
- filter_pointer_event (
1265
- PointerEvent* to, const PointerEvent& from, const Bounds& frame)
1261
+ update_captures (View* view, PointerEvent* event)
1266
1262
  {
1267
- assert(to);
1268
-
1269
- const Point& offset = frame.position();
1270
-
1271
- to->size = 0;
1272
- for (size_t i = 0; i < from.size; ++i) {
1273
- const Point& pos = from.position(i);
1274
- if (!frame.is_include(pos))
1275
- continue;
1263
+ Window* win = view->window();
1264
+ if (!win)
1265
+ invalid_state_error(__FILE__, __LINE__);
1276
1266
 
1277
- to->positions[i] = pos - offset;
1278
- ++to->size;
1279
- }
1267
+ PointerEvent_each_pointer(event, [&](const auto& pointer)
1268
+ {
1269
+ auto action = pointer.action();
1270
+ if (action == Pointer::DOWN)
1271
+ {
1272
+ 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
+ });
1280
1279
  }
1281
1280
 
1282
1281
  static void
1283
- scroll_and_zoom_positions (PointerEvent* e, const Point* scroll, float zoom)
1282
+ call_pointer_event_for_each_child (View* parent, const PointerEvent& event)
1284
1283
  {
1285
- static const Point ZERO = 0;
1286
-
1287
- assert(zoom != 0);
1288
-
1289
- if (!scroll) scroll = &ZERO;
1290
- if (*scroll == 0 && zoom == 1)
1291
- return;
1292
-
1293
- for (size_t i = 0; i < e->size; ++i)
1294
- {
1295
- e->position(i) -= *scroll;
1296
- e->position(i) /= zoom;
1297
- }
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);
1288
+ });
1298
1289
  }
1299
1290
 
1300
1291
  void
@@ -1303,29 +1294,25 @@ namespace Reflex
1303
1294
  if (!view)
1304
1295
  argument_error(__FILE__, __LINE__);
1305
1296
 
1306
- bool capturing = view->capture() & View::CAPTURE_POINTER;
1307
- if (capturing != event.capture) return;
1308
-
1309
- PointerEvent e = event;
1310
- filter_pointer_event(&e, event, view->frame());
1311
-
1312
- if (!capturing && e.size == 0)
1297
+ if (event.empty())
1313
1298
  return;
1314
1299
 
1315
- scroll_and_zoom_positions(&e, view->self->pscroll.get(), view->zoom());
1316
-
1300
+ PointerEvent e = event;
1317
1301
  view->on_pointer(&e);
1318
1302
 
1319
- switch (e.type)
1303
+ switch (e[0].action())
1320
1304
  {
1321
- case PointerEvent::DOWN: view->on_pointer_down(&e); break;
1322
- case PointerEvent::UP: view->on_pointer_up(&e); break;
1323
- case PointerEvent::MOVE: view->on_pointer_move(&e); break;
1324
- case PointerEvent::NONE: break;
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;
1325
1310
  }
1326
1311
 
1327
- if (!event.capture)
1328
- call_children(view, View_call_pointer_event, e);
1312
+ update_captures(view, &e);
1313
+
1314
+ if (!e.is_captured())
1315
+ call_pointer_event_for_each_child(view, e);
1329
1316
  }
1330
1317
 
1331
1318
  void
@@ -1344,7 +1331,7 @@ namespace Reflex
1344
1331
 
1345
1332
  view->on_wheel(&e);
1346
1333
 
1347
- call_children(view, View_call_wheel_event, e);
1334
+ call_children(view, e, View_call_wheel_event);
1348
1335
  }
1349
1336
 
1350
1337
  void
@@ -1480,22 +1467,29 @@ namespace Reflex
1480
1467
  Point
1481
1468
  View::from_parent (const Point& point) const
1482
1469
  {
1483
- not_implemented_error(__FILE__, __LINE__);
1484
- return 0;
1470
+ if (!parent())
1471
+ invalid_state_error(__FILE__, __LINE__);
1472
+
1473
+ return point - frame().position();
1485
1474
  }
1486
1475
 
1487
1476
  Point
1488
1477
  View::to_parent (const Point& point) const
1489
1478
  {
1490
- not_implemented_error(__FILE__, __LINE__);
1491
- return 0;
1479
+ if (!parent())
1480
+ invalid_state_error(__FILE__, __LINE__);
1481
+
1482
+ return point + frame().position();
1492
1483
  }
1493
1484
 
1494
1485
  Point
1495
1486
  View::from_window (const Point& point) const
1496
1487
  {
1488
+ if (!window())
1489
+ invalid_state_error(__FILE__, __LINE__);
1490
+
1497
1491
  Point p = point;
1498
- for (const View* v = parent(); v; v = v->parent())
1492
+ for (const View* v = this; v; v = v->parent())
1499
1493
  p -= v->frame().position();
1500
1494
  return p;
1501
1495
  }
@@ -1503,22 +1497,33 @@ namespace Reflex
1503
1497
  Point
1504
1498
  View::to_window (const Point& point) const
1505
1499
  {
1506
- not_implemented_error(__FILE__, __LINE__);
1507
- return 0;
1500
+ if (!window())
1501
+ invalid_state_error(__FILE__, __LINE__);
1502
+
1503
+ Point p = point;
1504
+ for (const View* v = this; v; v = v->parent())
1505
+ p += v->frame().position();
1506
+ return p;
1508
1507
  }
1509
1508
 
1510
1509
  Point
1511
1510
  View::from_screen (const Point& point) const
1512
1511
  {
1513
- not_implemented_error(__FILE__, __LINE__);
1514
- return 0;
1512
+ const Window* w = window();
1513
+ if (!w)
1514
+ invalid_state_error(__FILE__, __LINE__);
1515
+
1516
+ return w->from_screen(from_window(point));
1515
1517
  }
1516
1518
 
1517
1519
  Point
1518
1520
  View::to_screen (const Point& point) const
1519
1521
  {
1520
- not_implemented_error(__FILE__, __LINE__);
1521
- return 0;
1522
+ const Window* w = window();
1523
+ if (!w)
1524
+ invalid_state_error(__FILE__, __LINE__);
1525
+
1526
+ return w->to_screen(to_window(point));
1522
1527
  }
1523
1528
 
1524
1529
  static void
@@ -1700,7 +1705,7 @@ namespace Reflex
1700
1705
  Style*
1701
1706
  View::get_style (const Selector& selector, bool create)
1702
1707
  {
1703
- if (selector.is_empty())
1708
+ if (selector.empty())
1704
1709
  return style(create);
1705
1710
 
1706
1711
  StyleList* pstyles = self->pstyles.get();
@@ -2069,7 +2074,8 @@ namespace Reflex
2069
2074
  void
2070
2075
  View::set_capture (uint types)
2071
2076
  {
2072
- if (types == self->capture) return;
2077
+ Window* w = window();
2078
+ if (!w || types == self->capture) return;
2073
2079
 
2074
2080
  uint old = self->capture;
2075
2081
  self->capture = types;
@@ -2078,9 +2084,9 @@ namespace Reflex
2078
2084
  bool capture = types != CAPTURE_NONE;
2079
2085
 
2080
2086
  if (capture && !registered)
2081
- View_register_capture(this);
2087
+ Window_register_capture(w, this);
2082
2088
  else if (!capture && registered)
2083
- View_unregister_capture(this);
2089
+ Window_unregister_capture(w, this);
2084
2090
 
2085
2091
  CaptureEvent e(~old & types, old & ~types);
2086
2092
  on_capture(&e);
@@ -2536,6 +2542,11 @@ namespace Reflex
2536
2542
  {
2537
2543
  }
2538
2544
 
2545
+ void
2546
+ View::on_pointer_cancel (PointerEvent* e)
2547
+ {
2548
+ }
2549
+
2539
2550
  void
2540
2551
  View::on_wheel (WheelEvent* e)
2541
2552
  {
data/src/view.h CHANGED
@@ -37,10 +37,6 @@ namespace Reflex
37
37
 
38
38
  void View_update_shapes (View* view);
39
39
 
40
- void View_register_capture (View* view);
41
-
42
- void View_unregister_capture (View* view);
43
-
44
40
  void View_call_key_event (View* view, const KeyEvent& event);
45
41
 
46
42
  void View_call_pointer_event (View* view, const PointerEvent& event);