reflexion 0.5.2 → 0.6.0

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 (145) hide show
  1. checksums.yaml +4 -4
  2. data/.doc/ext/reflex/application.cpp +19 -1
  3. data/.doc/ext/reflex/chase_constraint.cpp +84 -0
  4. data/.doc/ext/reflex/clipboard.cpp +65 -0
  5. data/.doc/ext/reflex/constraint.cpp +135 -0
  6. data/.doc/ext/reflex/key_event.cpp +6 -6
  7. data/.doc/ext/reflex/link_constraint.cpp +178 -0
  8. data/.doc/ext/reflex/menu.cpp +302 -0
  9. data/.doc/ext/reflex/native.cpp +22 -4
  10. data/.doc/ext/reflex/pin.cpp +156 -0
  11. data/.doc/ext/reflex/pointer.cpp +2 -0
  12. data/.doc/ext/reflex/pointer_event.cpp +1 -1
  13. data/.doc/ext/reflex/reflex.cpp +42 -7
  14. data/.doc/ext/reflex/selector.cpp +4 -4
  15. data/.doc/ext/reflex/snap_constraint.cpp +125 -0
  16. data/.doc/ext/reflex/style_length.cpp +3 -2
  17. data/.doc/ext/reflex/view.cpp +96 -23
  18. data/.doc/ext/reflex/wheel_constraint.cpp +142 -0
  19. data/.doc/ext/reflex/window.cpp +59 -17
  20. data/.github/workflows/release-gem.yml +10 -1
  21. data/.github/workflows/test.yml +9 -0
  22. data/ChangeLog.md +30 -0
  23. data/README.md +1 -0
  24. data/VERSION +1 -1
  25. data/ext/reflex/application.cpp +21 -1
  26. data/ext/reflex/chase_constraint.cpp +89 -0
  27. data/ext/reflex/clipboard.cpp +69 -0
  28. data/ext/reflex/constraint.cpp +146 -0
  29. data/ext/reflex/key_event.cpp +6 -6
  30. data/ext/reflex/link_constraint.cpp +194 -0
  31. data/ext/reflex/menu.cpp +330 -0
  32. data/ext/reflex/native.cpp +22 -4
  33. data/ext/reflex/pin.cpp +165 -0
  34. data/ext/reflex/pointer.cpp +2 -0
  35. data/ext/reflex/pointer_event.cpp +1 -1
  36. data/ext/reflex/reflex.cpp +42 -7
  37. data/ext/reflex/selector.cpp +4 -4
  38. data/ext/reflex/selector.h +1 -1
  39. data/ext/reflex/snap_constraint.cpp +135 -0
  40. data/ext/reflex/style_length.cpp +3 -2
  41. data/ext/reflex/view.cpp +117 -37
  42. data/ext/reflex/wheel_constraint.cpp +154 -0
  43. data/ext/reflex/window.cpp +65 -18
  44. data/include/reflex/application.h +9 -0
  45. data/include/reflex/clipboard.h +53 -0
  46. data/include/reflex/constraint.h +275 -0
  47. data/include/reflex/defs.h +204 -195
  48. data/include/reflex/event.h +2 -0
  49. data/include/reflex/menu.h +120 -0
  50. data/include/reflex/pin.h +68 -0
  51. data/include/reflex/pointer.h +4 -0
  52. data/include/reflex/ruby/clipboard.h +23 -0
  53. data/include/reflex/ruby/constraint.h +94 -0
  54. data/include/reflex/ruby/menu.h +103 -0
  55. data/include/reflex/ruby/pin.h +40 -0
  56. data/include/reflex/ruby/view.h +36 -0
  57. data/include/reflex/ruby/window.h +36 -18
  58. data/include/reflex/view.h +39 -12
  59. data/include/reflex/window.h +17 -4
  60. data/include/reflex.h +5 -0
  61. data/lib/reflex/chase_constraint.rb +15 -0
  62. data/lib/reflex/clipboard.rb +19 -0
  63. data/lib/reflex/constraint.rb +29 -0
  64. data/lib/reflex/extension.rb +1 -1
  65. data/lib/reflex/helper.rb +28 -0
  66. data/lib/reflex/key_event.rb +7 -12
  67. data/lib/reflex/link_constraint.rb +31 -0
  68. data/lib/reflex/menu.rb +76 -0
  69. data/lib/reflex/pin.rb +39 -0
  70. data/lib/reflex/pointer.rb +18 -0
  71. data/lib/reflex/pointer_event.rb +1 -1
  72. data/lib/reflex/snap_constraint.rb +28 -0
  73. data/lib/reflex/view.rb +56 -4
  74. data/lib/reflex/wheel_constraint.rb +28 -0
  75. data/lib/reflex/wheel_event.rb +9 -0
  76. data/lib/reflex.rb +15 -6
  77. data/pod.rake +4 -2
  78. data/reflex.gemspec +3 -3
  79. data/samples/constraint.rb +152 -0
  80. data/samples/menu.rb +29 -0
  81. data/src/application.cpp +21 -2
  82. data/src/application.h +5 -0
  83. data/src/clipboard.cpp +81 -0
  84. data/src/constraint.cpp +1662 -0
  85. data/src/constraint.h +64 -0
  86. data/src/event.cpp +7 -1
  87. data/src/event.h +1 -2
  88. data/src/ios/application.mm +5 -0
  89. data/src/ios/clipboard.mm +44 -0
  90. data/src/ios/event.h +6 -2
  91. data/src/ios/event.mm +31 -12
  92. data/src/ios/menu.mm +36 -0
  93. data/src/ios/view_controller.mm +45 -12
  94. data/src/ios/window.mm +6 -0
  95. data/src/menu.cpp +325 -0
  96. data/src/menu.h +65 -0
  97. data/src/osx/app_delegate.mm +74 -125
  98. data/src/osx/application.mm +16 -0
  99. data/src/osx/clipboard.mm +45 -0
  100. data/src/osx/event.mm +40 -10
  101. data/src/osx/menu.h +25 -0
  102. data/src/osx/menu.mm +372 -0
  103. data/src/osx/native_window.mm +27 -0
  104. data/src/osx/opengl_view.mm +51 -0
  105. data/src/osx/window.mm +11 -0
  106. data/src/pin.cpp +137 -0
  107. data/src/pointer.cpp +27 -16
  108. data/src/pointer.h +6 -0
  109. data/src/sdl/application.cpp +5 -0
  110. data/src/sdl/clipboard.cpp +39 -0
  111. data/src/sdl/event.cpp +20 -3
  112. data/src/sdl/event.h +6 -3
  113. data/src/sdl/menu.cpp +35 -0
  114. data/src/sdl/window.cpp +26 -8
  115. data/src/view.cpp +313 -52
  116. data/src/view.h +18 -2
  117. data/src/win32/application.cpp +5 -0
  118. data/src/win32/clipboard.cpp +210 -0
  119. data/src/win32/event.cpp +11 -1
  120. data/src/win32/event.h +2 -0
  121. data/src/win32/menu.cpp +352 -0
  122. data/src/win32/menu.h +27 -0
  123. data/src/win32/window.cpp +62 -0
  124. data/src/win32/window.h +3 -0
  125. data/src/window.cpp +235 -22
  126. data/src/window.h +13 -2
  127. data/src/world.cpp +77 -14
  128. data/src/world.h +9 -2
  129. data/test/helper.rb +7 -0
  130. data/test/test_application.rb +11 -0
  131. data/test/test_chase_constraint.rb +124 -0
  132. data/test/test_clipboard.rb +54 -0
  133. data/test/test_constraint.rb +186 -0
  134. data/test/test_key_event.rb +6 -0
  135. data/test/test_link_constraint.rb +239 -0
  136. data/test/test_menu.rb +207 -0
  137. data/test/test_pin.rb +65 -0
  138. data/test/test_pointer.rb +23 -9
  139. data/test/test_pointer_event.rb +1 -1
  140. data/test/test_snap_constraint.rb +142 -0
  141. data/test/test_view.rb +113 -23
  142. data/test/test_wheel_constraint.rb +127 -0
  143. data/test/test_wheel_event.rb +15 -9
  144. data/test/test_window.rb +10 -0
  145. metadata +82 -8
data/src/pin.cpp ADDED
@@ -0,0 +1,137 @@
1
+ #include "reflex/pin.h"
2
+
3
+
4
+ #include "reflex/exception.h"
5
+ #include "view.h"
6
+ #include "constraint.h"
7
+
8
+
9
+ namespace Reflex
10
+ {
11
+
12
+
13
+ struct Pin::Data
14
+ {
15
+
16
+ Xot::WeakRef<View> view;
17
+
18
+ std::unique_ptr<Point> pposition;
19
+
20
+ };// Pin::Data
21
+
22
+
23
+ template <typename T>
24
+ static T*
25
+ setup_constraint (
26
+ T* constraint,
27
+ View* view0, const Point* position0,
28
+ View* view1, const Point* position1)
29
+ {
30
+ if (!view0)
31
+ invalid_state_error(__FILE__, __LINE__, "the pin has no view");
32
+
33
+ Constraint_set_pins(constraint, view0, position0, view1, position1);
34
+ View_add_constraint(view0, constraint);
35
+ return constraint;
36
+ }
37
+
38
+
39
+ Pin::Pin ()
40
+ {
41
+ }
42
+
43
+ Pin::Pin (coord x, coord y)
44
+ : Pin(NULL, Point(x, y))
45
+ {
46
+ }
47
+
48
+ Pin::Pin (const Point& position)
49
+ : Pin(NULL, position)
50
+ {
51
+ }
52
+
53
+ Pin::Pin (View* view)
54
+ {
55
+ self->view = view;
56
+ }
57
+
58
+ Pin::Pin (View* view, coord x, coord y)
59
+ : Pin(view, Point(x, y))
60
+ {
61
+ }
62
+
63
+ Pin::Pin (View* view, const Point& position)
64
+ {
65
+ self->view = view;
66
+ self->pposition.reset(new Point(position));
67
+ }
68
+
69
+ SnapConstraint*
70
+ Pin::snap (Pin target)
71
+ {
72
+ return setup_constraint(
73
+ Xot::Ref<SnapConstraint>(SnapConstraint_create()).get(),
74
+ view(), position(), target.view(), target.position());
75
+ }
76
+
77
+ LinkConstraint*
78
+ Pin::link (Pin target)
79
+ {
80
+ return setup_constraint(
81
+ Xot::Ref<LinkConstraint>(LinkConstraint_create()).get(),
82
+ view(), position(), target.view(), target.position());
83
+ }
84
+
85
+ WheelConstraint*
86
+ Pin::wheel (Pin target)
87
+ {
88
+ return setup_constraint(
89
+ Xot::Ref<WheelConstraint>(WheelConstraint_create()).get(),
90
+ view(), position(), target.view(), target.position());
91
+ }
92
+
93
+ ChaseConstraint*
94
+ Pin::chase (Pin target)
95
+ {
96
+ if (target.view() && target.view() == view())
97
+ argument_error(__FILE__, __LINE__, "can not chase itself");
98
+
99
+ ChaseConstraint* chase = setup_constraint(
100
+ Xot::Ref<ChaseConstraint>(ChaseConstraint_create()).get(),
101
+ view(), position(), NULL, NULL);
102
+ chase->set_target(target);
103
+ return chase;
104
+ }
105
+
106
+ View*
107
+ Pin::view ()
108
+ {
109
+ return self->view.get();
110
+ }
111
+
112
+ const View*
113
+ Pin::view () const
114
+ {
115
+ return const_cast<Pin*>(this)->view();
116
+ }
117
+
118
+ const Point*
119
+ Pin::position () const
120
+ {
121
+ return self->pposition ? self->pposition.get() : NULL;
122
+ }
123
+
124
+ Pin::operator bool () const
125
+ {
126
+ return true;
127
+ }
128
+
129
+ bool
130
+ Pin::operator ! () const
131
+ {
132
+ return !operator bool();
133
+ }
134
+
135
+
136
+ }// Reflex
137
+
data/src/pointer.cpp CHANGED
@@ -29,13 +29,11 @@ namespace Reflex
29
29
 
30
30
  DRAG = Xot::bit(0, TYPE_LAST),
31
31
 
32
- ENTER = Xot::bit(1, TYPE_LAST),
32
+ FLOATABLE = Xot::bit(1, TYPE_LAST),
33
33
 
34
- EXIT = Xot::bit(2, TYPE_LAST),
34
+ HAS_SYSTEM_ID = Xot::bit(2, TYPE_LAST),
35
35
 
36
- HAS_SYSTEM_ID = Xot::bit(3, TYPE_LAST),
37
-
38
- HAS_PREV_POS = Xot::bit(4, TYPE_LAST),
36
+ HAS_PREV_POS = Xot::bit(3, TYPE_LAST),
39
37
 
40
38
  };// Flag
41
39
 
@@ -56,23 +54,15 @@ namespace Reflex
56
54
  Data (
57
55
  ID id = -1, uint types = TYPE_NONE, Action action = ACTION_NONE,
58
56
  const Point& position = 0, uint modifiers = 0, uint click_count = 0,
59
- bool drag = false, bool enter = false, bool exit = false,
57
+ bool drag = false,
60
58
  double time = 0)
61
59
  : id(id), types(types), action(action),
62
60
  position(position), modifiers(modifiers), click_count(click_count),
63
- flags(make_flags(drag, enter, exit)),
61
+ flags(drag ? DRAG : 0),
64
62
  time(time)
65
63
  {
66
64
  }
67
65
 
68
- uint make_flags (bool drag, bool enter, bool exit)
69
- {
70
- return
71
- (drag ? DRAG : 0) |
72
- (enter ? ENTER : 0) |
73
- (exit ? EXIT : 0);
74
- }
75
-
76
66
  bool is_valid () const
77
67
  {
78
68
  return id >= 0 && types != TYPE_NONE && action != ACTION_NONE;
@@ -96,6 +86,27 @@ namespace Reflex
96
86
  it->self->id = id;
97
87
  }
98
88
 
89
+ void
90
+ Pointer_set_action (Pointer* it, Pointer::Action action)
91
+ {
92
+ it->self->action = action;
93
+ }
94
+
95
+ void
96
+ Pointer_set_floatable (Pointer* it, bool floatable)
97
+ {
98
+ if (floatable)
99
+ Xot::add_flag(&it->self->flags, Pointer::Data::FLOATABLE);
100
+ else
101
+ Xot::remove_flag(&it->self->flags, Pointer::Data::FLOATABLE);
102
+ }
103
+
104
+ bool
105
+ Pointer_is_floatable (const Pointer& it)
106
+ {
107
+ return Xot::has_flag(it.self->flags, Pointer::Data::FLOATABLE);
108
+ }
109
+
99
110
  void
100
111
  Pointer_add_flag (Pointer* it, uint flag)
101
112
  {
@@ -167,7 +178,7 @@ namespace Reflex
167
178
  double time)
168
179
  : self(new Data(
169
180
  id, types, action,
170
- position, modifiers, click_count, drag, false, false,
181
+ position, modifiers, click_count, drag,
171
182
  time))
172
183
  {
173
184
  }
data/src/pointer.h CHANGED
@@ -16,6 +16,12 @@ namespace Reflex
16
16
 
17
17
  void Pointer_set_id (Pointer* it, Pointer::ID id);
18
18
 
19
+ void Pointer_set_action (Pointer* it, Pointer::Action action);
20
+
21
+ void Pointer_set_floatable (Pointer* it, bool floatable);
22
+
23
+ bool Pointer_is_floatable (const Pointer& it);
24
+
19
25
  void Pointer_add_flag (Pointer* it, uint flag);
20
26
 
21
27
  void Pointer_remove_flag (Pointer* it, uint flag);
@@ -41,6 +41,11 @@ namespace Reflex
41
41
  return new ApplicationData();
42
42
  }
43
43
 
44
+ void
45
+ Application_set_menu (Application* app, Menu* menu)
46
+ {
47
+ }
48
+
44
49
 
45
50
  static bool
46
51
  dispatch_window_event (const SDL_Event& event)
@@ -0,0 +1,39 @@
1
+ #include "reflex/clipboard.h"
2
+
3
+
4
+ #include <SDL.h>
5
+ #include "reflex/exception.h"
6
+
7
+
8
+ namespace Reflex
9
+ {
10
+
11
+
12
+ void
13
+ set_clipboard (const Clipboard& clipboard)
14
+ {
15
+ const char* text = clipboard.text();
16
+ if (SDL_SetClipboardText(text ? text : "") != 0)
17
+ reflex_error(__FILE__, __LINE__, SDL_GetError());
18
+ }
19
+
20
+ Clipboard
21
+ get_clipboard ()
22
+ {
23
+ Clipboard clipboard;
24
+
25
+ if (SDL_HasClipboardText() == SDL_TRUE)
26
+ {
27
+ char* text = SDL_GetClipboardText();
28
+ if (text)
29
+ {
30
+ clipboard.set_text(text);
31
+ SDL_free(text);
32
+ }
33
+ }
34
+
35
+ return clipboard;
36
+ }
37
+
38
+
39
+ }// Reflex
data/src/sdl/event.cpp CHANGED
@@ -94,7 +94,7 @@ namespace Reflex
94
94
  }
95
95
 
96
96
  NativePointerEvent::NativePointerEvent (
97
- const SDL_MouseButtonEvent& e, SDL_Window* window, Pointer::Action action)
97
+ SDL_Window* window, const SDL_MouseButtonEvent& e, Pointer::Action action)
98
98
  {
99
99
  PointerEvent_add_pointer(this, Pointer(
100
100
  0,
@@ -108,7 +108,7 @@ namespace Reflex
108
108
  }
109
109
 
110
110
  NativePointerEvent::NativePointerEvent (
111
- const SDL_MouseMotionEvent& e, SDL_Window* window)
111
+ SDL_Window* window, const SDL_MouseMotionEvent& e)
112
112
  {
113
113
  PointerEvent_add_pointer(this, Pointer(
114
114
  0,
@@ -122,7 +122,7 @@ namespace Reflex
122
122
  }
123
123
 
124
124
  NativePointerEvent::NativePointerEvent (
125
- const SDL_TouchFingerEvent& e, SDL_Window* window, Pointer::Action action)
125
+ SDL_Window* window, const SDL_TouchFingerEvent& e, Pointer::Action action)
126
126
  {
127
127
  uint mods = get_modifiers(SDL_GetModState());
128
128
  double t = time();
@@ -157,6 +157,23 @@ namespace Reflex
157
157
  }
158
158
  }
159
159
 
160
+ NativePointerEvent::NativePointerEvent (
161
+ SDL_Window* window, Pointer::Action action)
162
+ {
163
+ int x = 0, y = 0;
164
+ Uint32 state = SDL_GetMouseState(&x, &y);
165
+
166
+ PointerEvent_add_pointer(this, Pointer(
167
+ 0,
168
+ get_current_pointer_type(state),
169
+ action,
170
+ Point(x, y),
171
+ get_modifiers(SDL_GetModState()),
172
+ 0,
173
+ false,
174
+ time()));
175
+ }
176
+
160
177
 
161
178
  NativeWheelEvent::NativeWheelEvent (
162
179
  const SDL_MouseWheelEvent& e, SDL_Window* window)
data/src/sdl/event.h CHANGED
@@ -28,16 +28,19 @@ namespace Reflex
28
28
  public:
29
29
 
30
30
  NativePointerEvent (
31
- const SDL_MouseButtonEvent& event, SDL_Window* window,
31
+ SDL_Window* window, const SDL_MouseButtonEvent& event,
32
32
  Pointer::Action action);
33
33
 
34
34
  NativePointerEvent (
35
- const SDL_MouseMotionEvent& event, SDL_Window* window);
35
+ SDL_Window* window, const SDL_MouseMotionEvent& event);
36
36
 
37
37
  NativePointerEvent (
38
- const SDL_TouchFingerEvent& event, SDL_Window* window,
38
+ SDL_Window* window, const SDL_TouchFingerEvent& event,
39
39
  Pointer::Action action);
40
40
 
41
+ NativePointerEvent (
42
+ SDL_Window* window, Pointer::Action action);
43
+
41
44
  };// NativePointerEvent
42
45
 
43
46
 
data/src/sdl/menu.cpp ADDED
@@ -0,0 +1,35 @@
1
+ #include "../menu.h"
2
+
3
+
4
+ namespace Reflex
5
+ {
6
+
7
+
8
+ Menu::Data*
9
+ Menu_create_data ()
10
+ {
11
+ return new Menu::Data();
12
+ }
13
+
14
+ void
15
+ Menu_update (Menu* menu)
16
+ {
17
+ }
18
+
19
+ void
20
+ Menu_popup (Menu* menu, View* view, coord x, coord y)
21
+ {
22
+ }
23
+
24
+ void
25
+ Menu_child_added (Menu* parent, Menu* child, int index)
26
+ {
27
+ }
28
+
29
+ void
30
+ Menu_child_removed (Menu* parent, Menu* child)
31
+ {
32
+ }
33
+
34
+
35
+ }// Reflex
data/src/sdl/window.cpp CHANGED
@@ -283,6 +283,12 @@ namespace Reflex
283
283
  return Bounds(x, y, w, h);
284
284
  }
285
285
 
286
+ void
287
+ Window_set_menu (Window* window, Menu* menu)
288
+ {
289
+ not_implemented_error(__FILE__, __LINE__);
290
+ }
291
+
286
292
  Screen
287
293
  Window_get_screen (const Window& win)
288
294
  {
@@ -383,6 +389,20 @@ namespace Reflex
383
389
  case SDL_WINDOWEVENT_FOCUS_LOST:
384
390
  Window_call_deactivate_event(win);
385
391
  break;
392
+
393
+ case SDL_WINDOWEVENT_ENTER:
394
+ {
395
+ NativePointerEvent e(self->native, Pointer::ENTER);
396
+ Window_call_pointer_event(win, &e);
397
+ break;
398
+ }
399
+
400
+ case SDL_WINDOWEVENT_LEAVE:
401
+ {
402
+ NativePointerEvent e(self->native, Pointer::LEAVE);
403
+ Window_call_pointer_event(win, &e);
404
+ break;
405
+ }
386
406
  }
387
407
  break;
388
408
  }
@@ -403,23 +423,21 @@ namespace Reflex
403
423
 
404
424
  case SDL_MOUSEBUTTONDOWN:
405
425
  {
406
- NativePointerEvent e(
407
- event.button, self->native, Pointer::DOWN);
426
+ NativePointerEvent e(self->native, event.button, Pointer::DOWN);
408
427
  Window_call_pointer_event(win, &e);
409
428
  break;
410
429
  }
411
430
 
412
431
  case SDL_MOUSEBUTTONUP:
413
432
  {
414
- NativePointerEvent e(
415
- event.button, self->native, Pointer::UP);
433
+ NativePointerEvent e(self->native, event.button, Pointer::UP);
416
434
  Window_call_pointer_event(win, &e);
417
435
  break;
418
436
  }
419
437
 
420
438
  case SDL_MOUSEMOTION:
421
439
  {
422
- NativePointerEvent e(event.motion, self->native);
440
+ NativePointerEvent e(self->native, event.motion);
423
441
  Window_call_pointer_event(win, &e);
424
442
  break;
425
443
  }
@@ -433,21 +451,21 @@ namespace Reflex
433
451
 
434
452
  case SDL_FINGERDOWN:
435
453
  {
436
- NativePointerEvent e(event.tfinger, self->native, Pointer::DOWN);
454
+ NativePointerEvent e(self->native, event.tfinger, Pointer::DOWN);
437
455
  Window_call_pointer_event(win, &e);
438
456
  break;
439
457
  }
440
458
 
441
459
  case SDL_FINGERUP:
442
460
  {
443
- NativePointerEvent e(event.tfinger, self->native, Pointer::UP);
461
+ NativePointerEvent e(self->native, event.tfinger, Pointer::UP);
444
462
  Window_call_pointer_event(win, &e);
445
463
  break;
446
464
  }
447
465
 
448
466
  case SDL_FINGERMOTION:
449
467
  {
450
- NativePointerEvent e(event.tfinger, self->native, Pointer::MOVE);
468
+ NativePointerEvent e(self->native, event.tfinger, Pointer::MOVE);
451
469
  Window_call_pointer_event(win, &e);
452
470
  break;
453
471
  }