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/constraint.h ADDED
@@ -0,0 +1,64 @@
1
+ // -*- c++ -*-
2
+ #pragma once
3
+ #ifndef __REFLEX_SRC_CONSTRAINT_H__
4
+ #define __REFLEX_SRC_CONSTRAINT_H__
5
+
6
+
7
+ #include "reflex/constraint.h"
8
+
9
+
10
+ namespace Reflex
11
+ {
12
+
13
+
14
+ class View;
15
+ class World;
16
+
17
+
18
+ void Constraint_set_pins (
19
+ Constraint* constraint,
20
+ View* view0, const Point* position0,
21
+ View* view1, const Point* position1);
22
+
23
+ bool Constraint_activate (Constraint* constraint);
24
+
25
+ void Constraint_deactivate (Constraint* constraint);
26
+
27
+ void Constraint_sever (Constraint* constraint);
28
+
29
+ void Constraint_on_world_destroyed (Constraint* constraint);
30
+
31
+ void Constraint_on_world_update (Constraint* constraint);
32
+
33
+ bool Constraint_has_world_mismatch (const Constraint* constraint);
34
+
35
+
36
+ typedef SnapConstraint* (*SnapConstraint_CreateFun) ();
37
+
38
+ typedef LinkConstraint* (*LinkConstraint_CreateFun) ();
39
+
40
+ typedef WheelConstraint* (*WheelConstraint_CreateFun) ();
41
+
42
+ typedef ChaseConstraint* (*ChaseConstraint_CreateFun) ();
43
+
44
+ void SnapConstraint_set_create_fun (SnapConstraint_CreateFun fun);
45
+
46
+ void LinkConstraint_set_create_fun (LinkConstraint_CreateFun fun);
47
+
48
+ void WheelConstraint_set_create_fun (WheelConstraint_CreateFun fun);
49
+
50
+ void ChaseConstraint_set_create_fun (ChaseConstraint_CreateFun fun);
51
+
52
+ SnapConstraint* SnapConstraint_create ();
53
+
54
+ LinkConstraint* LinkConstraint_create ();
55
+
56
+ WheelConstraint* WheelConstraint_create ();
57
+
58
+ ChaseConstraint* ChaseConstraint_create ();
59
+
60
+
61
+ }// Reflex
62
+
63
+
64
+ #endif//EOH
data/src/event.cpp CHANGED
@@ -54,6 +54,12 @@ namespace Reflex
54
54
  {
55
55
  }
56
56
 
57
+ Event
58
+ Event::dup () const
59
+ {
60
+ return Event(this);
61
+ }
62
+
57
63
  void
58
64
  Event::block (bool parent)
59
65
  {
@@ -724,7 +730,7 @@ namespace Reflex
724
730
  }
725
731
 
726
732
  void
727
- PointerEvent_update_for_capturing_view (PointerEvent* pthis, const View* view)
733
+ PointerEvent_to_view_coord (PointerEvent* pthis, const View* view)
728
734
  {
729
735
  if (!pthis)
730
736
  argument_error(__FILE__, __LINE__);
data/src/event.h CHANGED
@@ -42,8 +42,7 @@ namespace Reflex
42
42
  void PointerEvent_update_for_child_view (
43
43
  PointerEvent* pthis, const View* view);
44
44
 
45
- void PointerEvent_update_for_capturing_view (
46
- PointerEvent* pthis, const View* view);
45
+ void PointerEvent_to_view_coord (PointerEvent* pthis, const View* view);
47
46
 
48
47
 
49
48
  void WheelEvent_set_position (WheelEvent* pthis, const Point& position);
@@ -28,6 +28,11 @@ namespace Reflex
28
28
  return new ApplicationData();
29
29
  }
30
30
 
31
+ void
32
+ Application_set_menu (Application* app, Menu* menu)
33
+ {
34
+ }
35
+
31
36
  ApplicationData&
32
37
  Application_get_data (Application* app)
33
38
  {
@@ -0,0 +1,44 @@
1
+ // -*- objc -*-
2
+ #include "reflex/clipboard.h"
3
+
4
+
5
+ #import <UIKit/UIKit.h>
6
+ #include "reflex/exception.h"
7
+
8
+
9
+ namespace Reflex
10
+ {
11
+
12
+
13
+ void
14
+ set_clipboard (const Clipboard& clipboard)
15
+ {
16
+ const char* text = clipboard.text();
17
+ NSString* nstext = nil;
18
+ if (text)
19
+ {
20
+ nstext = [NSString stringWithUTF8String: text];
21
+ if (!nstext)
22
+ argument_error(__FILE__, __LINE__);
23
+ }
24
+
25
+ UIPasteboard* pasteboard = UIPasteboard.generalPasteboard;
26
+ pasteboard.items = @[];
27
+
28
+ if (nstext) pasteboard.string = nstext;
29
+ }
30
+
31
+ Clipboard
32
+ get_clipboard ()
33
+ {
34
+ Clipboard clipboard;
35
+
36
+ NSString* nstext = UIPasteboard.generalPasteboard.string;
37
+ const char* text = nstext ? nstext.UTF8String : NULL;
38
+ if (text) clipboard.set_text(text);
39
+
40
+ return clipboard;
41
+ }
42
+
43
+
44
+ }// Reflex
data/src/ios/event.h CHANGED
@@ -28,9 +28,13 @@ namespace Reflex
28
28
 
29
29
  public:
30
30
 
31
- NativePointerEvent (NSSet* touches, UIEvent* event, UIView* view);
31
+ NativePointerEvent (
32
+ UIView* view, UIHoverGestureRecognizer* recognizer,
33
+ NSSet* touches, UIEvent* event);
32
34
 
33
- NativePointerEvent (UIHoverGestureRecognizer* recognizer, UIView* view);
35
+ NativePointerEvent (
36
+ UIView* view, UIHoverGestureRecognizer* recognizer,
37
+ Pointer::Action action, bool pen);
34
38
 
35
39
  };// NativePointerEvent
36
40
 
data/src/ios/event.mm CHANGED
@@ -79,12 +79,12 @@ namespace Reflex
79
79
  to_modifiers (NSInteger flags)
80
80
  {
81
81
  return
82
- (flags & UIKeyModifierAlphaShift) ? MOD_CAPS : 0 |
83
- (flags & UIKeyModifierShift) ? MOD_SHIFT : 0 |
84
- (flags & UIKeyModifierControl) ? MOD_CONTROL : 0 |
85
- (flags & UIKeyModifierAlternate) ? MOD_ALT : 0 |
86
- (flags & UIKeyModifierCommand) ? MOD_COMMAND : 0 |
87
- (flags & UIKeyModifierNumericPad) ? MOD_NUMPAD : 0;
82
+ (flags & UIKeyModifierAlphaShift ? MOD_CAPS : 0) |
83
+ (flags & UIKeyModifierShift ? MOD_SHIFT : 0) |
84
+ (flags & UIKeyModifierControl ? MOD_CONTROL : 0) |
85
+ (flags & UIKeyModifierAlternate ? MOD_ALT : 0) |
86
+ (flags & UIKeyModifierCommand ? MOD_COMMAND : 0) |
87
+ (flags & UIKeyModifierNumericPad ? MOD_NUMPAD : 0);
88
88
  }
89
89
 
90
90
  static uint
@@ -124,8 +124,11 @@ namespace Reflex
124
124
 
125
125
 
126
126
  NativePointerEvent::NativePointerEvent (
127
- NSSet* touches, UIEvent* event, UIView* view)
127
+ UIView* view, UIHoverGestureRecognizer* recognizer,
128
+ NSSet* touches, UIEvent* event)
128
129
  {
130
+ assert(view && recognizer);
131
+
129
132
  for (UITouch* touch in touches)
130
133
  {
131
134
  Pointer::Action action = get_action(touch);
@@ -141,7 +144,14 @@ namespace Reflex
141
144
  action == Pointer::MOVE,
142
145
  touch.timestamp);
143
146
 
144
- if (!(type & Pointer::MOUSE))
147
+ if ((type & Pointer::PEN))
148
+ {
149
+ // keying the pencil's touch on the hover recognizer unifies it with
150
+ // its hover pointer, so they act as one pointer across the
151
+ // hover <-> touch transitions.
152
+ Pointer_set_system_id(&pointer, (Pointer::ID) recognizer);
153
+ }
154
+ else if (!(type & Pointer::MOUSE))
145
155
  Pointer_set_system_id(&pointer, (Pointer::ID) touch);
146
156
 
147
157
  if (action != Pointer::DOWN)
@@ -156,20 +166,29 @@ namespace Reflex
156
166
  }
157
167
 
158
168
  NativePointerEvent::NativePointerEvent (
159
- UIHoverGestureRecognizer* recognizer, UIView* view)
169
+ UIView* view, UIHoverGestureRecognizer* recognizer,
170
+ Pointer::Action action, bool pen)
160
171
  {
161
- assert(recognizer && view);
172
+ assert(view && recognizer);
173
+
174
+ uint type = pen ? Pointer::PEN : Pointer::MOUSE;
162
175
 
163
176
  Pointer pointer(
164
177
  0,
165
- Pointer::MOUSE,
166
- Pointer::MOVE,
178
+ type,
179
+ action,
167
180
  to_point([recognizer locationInView: view]),
168
181
  get_modifiers(nil),
169
182
  0,
170
183
  false,
171
184
  Xot::time());
172
185
 
186
+ if (type & Pointer::PEN)
187
+ {
188
+ Pointer_set_system_id(&pointer, (Pointer::ID) recognizer);
189
+ Pointer_set_floatable(&pointer, true);
190
+ }
191
+
173
192
  if (pointer)
174
193
  PointerEvent_add_pointer(this, pointer);
175
194
  }
data/src/ios/menu.mm ADDED
@@ -0,0 +1,36 @@
1
+ // -*- objc -*-
2
+ #include "../menu.h"
3
+
4
+
5
+ namespace Reflex
6
+ {
7
+
8
+
9
+ Menu::Data*
10
+ Menu_create_data ()
11
+ {
12
+ return new Menu::Data();
13
+ }
14
+
15
+ void
16
+ Menu_update (Menu* menu)
17
+ {
18
+ }
19
+
20
+ void
21
+ Menu_popup (Menu* menu, View* view, coord x, coord y)
22
+ {
23
+ }
24
+
25
+ void
26
+ Menu_child_added (Menu* parent, Menu* child, int index)
27
+ {
28
+ }
29
+
30
+ void
31
+ Menu_child_removed (Menu* parent, Menu* child)
32
+ {
33
+ }
34
+
35
+
36
+ }// Reflex
@@ -151,6 +151,7 @@ ReflexViewController_get_show_fun ()
151
151
  int update_count;
152
152
  int touching_count;
153
153
  int repeating_key_count;
154
+ bool pen;
154
155
  }
155
156
 
156
157
  - (id) init
@@ -163,6 +164,7 @@ ReflexViewController_get_show_fun ()
163
164
  update_count = 0;
164
165
  touching_count = 0;
165
166
  repeating_key_count = 0;
167
+ pen = false;
166
168
 
167
169
  return self;
168
170
  }
@@ -529,10 +531,12 @@ ReflexViewController_get_show_fun ()
529
531
  Reflex::Window* win = self.window;
530
532
  if (!win) return;
531
533
 
532
- Reflex::NativePointerEvent e(touches, event, self.reflexView);
534
+ Reflex::NativePointerEvent e(self.reflexView, self.hoverRecognizer, touches, event);
535
+
536
+ int count = (int) e.size();
533
537
  Window_call_pointer_event(win, &e);
534
538
 
535
- touching_count += e.size();
539
+ touching_count += count;
536
540
  }
537
541
 
538
542
  - (void) touchesEnded: (NSSet*) touches withEvent: (UIEvent*) event
@@ -540,12 +544,19 @@ ReflexViewController_get_show_fun ()
540
544
  Reflex::Window* win = self.window;
541
545
  if (!win) return;
542
546
 
543
- Reflex::NativePointerEvent e(touches, event, self.reflexView);
547
+ Reflex::NativePointerEvent e(self.reflexView, self.hoverRecognizer, touches, event);
548
+
549
+ int count = (int) e.size();
544
550
  Window_call_pointer_event(win, &e);
545
551
 
546
- touching_count -= e.size();
552
+ touching_count -= count;
547
553
  if (touching_count == 0)
548
- win->self->prev_pointers.clear();
554
+ {
555
+ win->self->prev_pointers.remove_if([](const Reflex::Pointer& p)
556
+ {
557
+ return !Reflex::Pointer_is_floatable(p);
558
+ });
559
+ }
549
560
  else if (touching_count < 0)
550
561
  Reflex::invalid_state_error(__FILE__, __LINE__);
551
562
  }
@@ -560,7 +571,7 @@ ReflexViewController_get_show_fun ()
560
571
  Reflex::Window* win = self.window;
561
572
  if (!win) return;
562
573
 
563
- Reflex::NativePointerEvent e(touches, event, self.reflexView);
574
+ Reflex::NativePointerEvent e(self.reflexView, self.hoverRecognizer, touches, event);
564
575
  Window_call_pointer_event(win, &e);
565
576
  }
566
577
 
@@ -570,16 +581,38 @@ ReflexViewController_get_show_fun ()
570
581
  Reflex::Window* win = self.window;
571
582
  if (!win) return;
572
583
 
573
- if (touching_count > 0) return;
584
+ if (recognizer.state == UIGestureRecognizerStateBegan)
585
+ pen = false;
574
586
 
575
- if (
576
- recognizer.state != UIGestureRecognizerStateBegan &&
577
- recognizer.state != UIGestureRecognizerStateChanged)
587
+ Reflex::Pointer::Action action;
588
+ switch (recognizer.state)
578
589
  {
579
- return;
590
+ case UIGestureRecognizerStateBegan:
591
+ case UIGestureRecognizerStateChanged:
592
+ // suppress hover moves while a touch is active
593
+ if (touching_count > 0) return;
594
+ action = recognizer.state == UIGestureRecognizerStateBegan
595
+ ? Reflex::Pointer::ENTER
596
+ : Reflex::Pointer::MOVE;
597
+ if (@available(iOS 16.1, *))
598
+ {
599
+ // zOffset drops to 0 on the Ended state, so latch the pen-ness
600
+ // here and reuse it until the leave.
601
+ if (recognizer.zOffset > 0) pen = true;
602
+ }
603
+ break;
604
+
605
+ case UIGestureRecognizerStateEnded:
606
+ case UIGestureRecognizerStateCancelled:
607
+ case UIGestureRecognizerStateFailed:
608
+ action = Reflex::Pointer::LEAVE;
609
+ break;
610
+
611
+ default:
612
+ return;
580
613
  }
581
614
 
582
- Reflex::NativePointerEvent e(recognizer, self.reflexView);
615
+ Reflex::NativePointerEvent e(self.reflexView, recognizer, action, pen);
583
616
  if (e.size() > 0)
584
617
  Window_call_pointer_event(win, &e);
585
618
  }
data/src/ios/window.mm CHANGED
@@ -142,6 +142,12 @@ namespace Reflex
142
142
  return Bounds(b.origin.x, b.origin.y, b.size.width, b.size.height);
143
143
  }
144
144
 
145
+ void
146
+ Window_set_menu (Window* window, Menu* menu)
147
+ {
148
+ not_implemented_error(__FILE__, __LINE__);
149
+ }
150
+
145
151
  static UIScreen*
146
152
  get_screen (const Window& window)
147
153
  {