reflexion 0.5.3 → 0.7.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 (309) hide show
  1. checksums.yaml +4 -4
  2. data/.doc/ext/reflex/application.cpp +56 -7
  3. data/.doc/ext/reflex/capture_event.cpp +1 -1
  4. data/.doc/ext/reflex/chase_constraint.cpp +84 -0
  5. data/.doc/ext/reflex/clipboard.cpp +65 -0
  6. data/.doc/ext/reflex/color_event.cpp +76 -0
  7. data/.doc/ext/reflex/color_picker.cpp +113 -0
  8. data/.doc/ext/reflex/constraint.cpp +135 -0
  9. data/.doc/ext/reflex/contact_event.cpp +1 -1
  10. data/.doc/ext/reflex/control_change_event.cpp +1 -1
  11. data/.doc/ext/reflex/device.cpp +1 -1
  12. data/.doc/ext/reflex/device_event.cpp +1 -1
  13. data/.doc/ext/reflex/draw_event.cpp +1 -1
  14. data/.doc/ext/reflex/ellipse_shape.cpp +1 -1
  15. data/.doc/ext/reflex/event.cpp +1 -1
  16. data/.doc/ext/reflex/file_dialog.cpp +181 -0
  17. data/.doc/ext/reflex/file_event.cpp +103 -0
  18. data/.doc/ext/reflex/filter.cpp +1 -1
  19. data/.doc/ext/reflex/focus_event.cpp +1 -1
  20. data/.doc/ext/reflex/frame_event.cpp +1 -1
  21. data/.doc/ext/reflex/gamepad.cpp +48 -0
  22. data/.doc/ext/reflex/image_view.cpp +1 -1
  23. data/.doc/ext/reflex/key_event.cpp +1 -274
  24. data/.doc/ext/reflex/line_shape.cpp +1 -1
  25. data/.doc/ext/reflex/link_constraint.cpp +178 -0
  26. data/.doc/ext/reflex/menu.cpp +303 -0
  27. data/.doc/ext/reflex/midi.cpp +9 -2
  28. data/.doc/ext/reflex/midi_event.cpp +1 -1
  29. data/.doc/ext/reflex/motion_event.cpp +1 -1
  30. data/.doc/ext/reflex/native.cpp +40 -10
  31. data/.doc/ext/reflex/note_event.cpp +1 -1
  32. data/.doc/ext/reflex/pin.cpp +156 -0
  33. data/.doc/ext/reflex/pointer.cpp +3 -1
  34. data/.doc/ext/reflex/pointer_event.cpp +3 -3
  35. data/.doc/ext/reflex/polygon_shape.cpp +1 -1
  36. data/.doc/ext/reflex/rect_shape.cpp +1 -1
  37. data/.doc/ext/reflex/reflex.cpp +606 -237
  38. data/.doc/ext/reflex/screen.cpp +27 -1
  39. data/.doc/ext/reflex/scroll_event.cpp +1 -1
  40. data/.doc/ext/reflex/selector.cpp +5 -5
  41. data/.doc/ext/reflex/shape.cpp +1 -1
  42. data/.doc/ext/reflex/snap_constraint.cpp +125 -0
  43. data/.doc/ext/reflex/style.cpp +1 -1
  44. data/.doc/ext/reflex/style_length.cpp +4 -3
  45. data/.doc/ext/reflex/text_event.cpp +104 -0
  46. data/.doc/ext/reflex/timer.cpp +1 -1
  47. data/.doc/ext/reflex/timer_event.cpp +1 -1
  48. data/.doc/ext/reflex/update_event.cpp +1 -1
  49. data/.doc/ext/reflex/view.cpp +206 -79
  50. data/.doc/ext/reflex/wheel_constraint.cpp +142 -0
  51. data/.doc/ext/reflex/wheel_event.cpp +1 -1
  52. data/.doc/ext/reflex/window.cpp +282 -31
  53. data/.github/workflows/release-gem.yml +2 -40
  54. data/.github/workflows/tag.yml +5 -28
  55. data/.github/workflows/test.yml +1 -28
  56. data/ChangeLog.md +79 -0
  57. data/Gemfile.lock +13 -8
  58. data/README.md +1 -0
  59. data/Rakefile +13 -2
  60. data/Reflex.podspec +2 -2
  61. data/VERSION +1 -1
  62. data/ext/reflex/application.cpp +62 -7
  63. data/ext/reflex/capture_event.cpp +1 -1
  64. data/ext/reflex/chase_constraint.cpp +89 -0
  65. data/ext/reflex/clipboard.cpp +69 -0
  66. data/ext/reflex/color_event.cpp +80 -0
  67. data/ext/reflex/color_picker.cpp +121 -0
  68. data/ext/reflex/constraint.cpp +146 -0
  69. data/ext/reflex/contact_event.cpp +1 -1
  70. data/ext/reflex/control_change_event.cpp +1 -1
  71. data/ext/reflex/device.cpp +1 -1
  72. data/ext/reflex/device_event.cpp +1 -1
  73. data/ext/reflex/draw_event.cpp +1 -1
  74. data/ext/reflex/ellipse_shape.cpp +1 -1
  75. data/ext/reflex/event.cpp +1 -1
  76. data/ext/reflex/extconf.rb +4 -2
  77. data/ext/reflex/file_dialog.cpp +194 -0
  78. data/ext/reflex/file_event.cpp +108 -0
  79. data/ext/reflex/filter.cpp +1 -1
  80. data/ext/reflex/focus_event.cpp +1 -1
  81. data/ext/reflex/frame_event.cpp +1 -1
  82. data/ext/reflex/gamepad.cpp +50 -0
  83. data/ext/reflex/image_view.cpp +1 -1
  84. data/ext/reflex/key_event.cpp +1 -275
  85. data/ext/reflex/line_shape.cpp +1 -1
  86. data/ext/reflex/link_constraint.cpp +194 -0
  87. data/ext/reflex/menu.cpp +331 -0
  88. data/ext/reflex/midi.cpp +11 -3
  89. data/ext/reflex/midi_event.cpp +1 -1
  90. data/ext/reflex/motion_event.cpp +1 -1
  91. data/ext/reflex/native.cpp +40 -10
  92. data/ext/reflex/note_event.cpp +1 -1
  93. data/ext/reflex/pin.cpp +165 -0
  94. data/ext/reflex/pointer.cpp +3 -1
  95. data/ext/reflex/pointer_event.cpp +3 -3
  96. data/ext/reflex/polygon_shape.cpp +1 -1
  97. data/ext/reflex/rect_shape.cpp +1 -1
  98. data/ext/reflex/reflex.cpp +608 -237
  99. data/ext/reflex/screen.cpp +31 -2
  100. data/ext/reflex/scroll_event.cpp +1 -1
  101. data/ext/reflex/selector.cpp +5 -5
  102. data/ext/reflex/selector.h +10 -10
  103. data/ext/reflex/shape.cpp +1 -1
  104. data/ext/reflex/snap_constraint.cpp +135 -0
  105. data/ext/reflex/style.cpp +1 -1
  106. data/ext/reflex/style_length.cpp +4 -3
  107. data/ext/reflex/text_event.cpp +111 -0
  108. data/ext/reflex/timer.cpp +1 -1
  109. data/ext/reflex/timer_event.cpp +1 -1
  110. data/ext/reflex/update_event.cpp +1 -1
  111. data/ext/reflex/view.cpp +236 -96
  112. data/ext/reflex/wheel_constraint.cpp +154 -0
  113. data/ext/reflex/wheel_event.cpp +1 -1
  114. data/ext/reflex/window.cpp +318 -40
  115. data/include/reflex/application.h +19 -0
  116. data/include/reflex/clipboard.h +53 -0
  117. data/include/reflex/color_picker.h +65 -0
  118. data/include/reflex/constraint.h +275 -0
  119. data/include/reflex/defs.h +204 -195
  120. data/include/reflex/event.h +180 -88
  121. data/include/reflex/file_dialog.h +73 -0
  122. data/include/reflex/gamepad.h +3 -0
  123. data/include/reflex/menu.h +120 -0
  124. data/include/reflex/midi.h +3 -0
  125. data/include/reflex/pin.h +68 -0
  126. data/include/reflex/pointer.h +4 -0
  127. data/include/reflex/reflex.h +2 -0
  128. data/include/reflex/ruby/application.h +6 -1
  129. data/include/reflex/ruby/clipboard.h +23 -0
  130. data/include/reflex/ruby/color_picker.h +89 -0
  131. data/include/reflex/ruby/constraint.h +94 -0
  132. data/include/reflex/ruby/event.h +62 -29
  133. data/include/reflex/ruby/file_dialog.h +89 -0
  134. data/include/reflex/ruby/gamepad.h +46 -0
  135. data/include/reflex/ruby/menu.h +103 -0
  136. data/include/reflex/ruby/pin.h +40 -0
  137. data/include/reflex/ruby/reflex.h +3 -0
  138. data/include/reflex/ruby/view.h +123 -39
  139. data/include/reflex/ruby/window.h +96 -19
  140. data/include/reflex/ruby.h +3 -0
  141. data/include/reflex/screen.h +11 -2
  142. data/include/reflex/view.h +66 -27
  143. data/include/reflex/window.h +57 -12
  144. data/include/reflex.h +8 -0
  145. data/lib/reflex/application.rb +5 -5
  146. data/lib/reflex/autoinit.rb +3 -1
  147. data/lib/reflex/button.rb +3 -3
  148. data/lib/reflex/chase_constraint.rb +15 -0
  149. data/lib/reflex/clipboard.rb +19 -0
  150. data/lib/reflex/color_event.rb +16 -0
  151. data/lib/reflex/color_picker.rb +45 -0
  152. data/lib/reflex/constraint.rb +29 -0
  153. data/lib/reflex/control_change_event.rb +17 -0
  154. data/lib/reflex/extension.rb +1 -1
  155. data/lib/reflex/file_dialog.rb +70 -0
  156. data/lib/reflex/file_event.rb +37 -0
  157. data/lib/reflex/helper.rb +79 -0
  158. data/lib/reflex/key_event.rb +14 -14
  159. data/lib/reflex/link_constraint.rb +31 -0
  160. data/lib/reflex/menu.rb +92 -0
  161. data/lib/reflex/model.rb +19 -19
  162. data/lib/reflex/note_event.rb +1 -1
  163. data/lib/reflex/pin.rb +39 -0
  164. data/lib/reflex/pointer.rb +30 -1
  165. data/lib/reflex/pointer_event.rb +13 -2
  166. data/lib/reflex/reflex.rb +5 -0
  167. data/lib/reflex/shape.rb +14 -14
  168. data/lib/reflex/snap_constraint.rb +28 -0
  169. data/lib/reflex/style.rb +16 -16
  170. data/lib/reflex/text_event.rb +40 -0
  171. data/lib/reflex/timer.rb +3 -3
  172. data/lib/reflex/view.rb +85 -18
  173. data/lib/reflex/wheel_constraint.rb +28 -0
  174. data/lib/reflex/wheel_event.rb +19 -1
  175. data/lib/reflex/window.rb +25 -13
  176. data/lib/reflex.rb +23 -8
  177. data/pod.rake +1 -1
  178. data/reflex.gemspec +4 -4
  179. data/samples/constraint.rb +152 -0
  180. data/samples/ime.rb +100 -0
  181. data/samples/ios/hello/hello.xcodeproj/project.pbxproj +236 -224
  182. data/samples/menu.rb +32 -0
  183. data/samples/model.rb +3 -3
  184. data/samples/test/alert.rb +93 -0
  185. data/samples/test/always_on.rb +76 -0
  186. data/samples/test/app_background.rb +51 -0
  187. data/samples/test/boundary.rb +75 -0
  188. data/samples/test/callback_exception.rb +101 -0
  189. data/samples/test/cancel.rb +53 -0
  190. data/samples/test/color_picker.rb +63 -0
  191. data/samples/test/file_dialog.rb +102 -0
  192. data/samples/window_style.rb +156 -0
  193. data/src/application.cpp +180 -20
  194. data/src/application.h +95 -5
  195. data/src/clipboard.cpp +81 -0
  196. data/src/color_picker.cpp +113 -0
  197. data/src/color_picker.h +36 -0
  198. data/src/constraint.cpp +1662 -0
  199. data/src/constraint.h +64 -0
  200. data/src/event.cpp +416 -252
  201. data/src/event.h +13 -2
  202. data/src/file_dialog.cpp +163 -0
  203. data/src/file_dialog.h +52 -0
  204. data/src/gamepad.cpp +42 -5
  205. data/src/gamepad.h +4 -0
  206. data/src/ios/app_delegate.mm +5 -3
  207. data/src/ios/application.mm +29 -0
  208. data/src/ios/clipboard.mm +44 -0
  209. data/src/ios/color_picker.mm +19 -0
  210. data/src/ios/event.h +6 -2
  211. data/src/ios/event.mm +31 -12
  212. data/src/ios/file_dialog.mm +21 -0
  213. data/src/ios/gamepad.mm +4 -4
  214. data/src/ios/menu.mm +41 -0
  215. data/src/ios/reflex.mm +8 -0
  216. data/src/ios/screen.mm +26 -0
  217. data/src/ios/view_controller.mm +47 -42
  218. data/src/ios/window.mm +44 -9
  219. data/src/menu.cpp +387 -0
  220. data/src/menu.h +81 -0
  221. data/src/midi.cpp +61 -31
  222. data/src/osx/app_delegate.h +4 -0
  223. data/src/osx/app_delegate.mm +168 -139
  224. data/src/osx/application.mm +103 -5
  225. data/src/osx/clipboard.mm +45 -0
  226. data/src/osx/color_picker.mm +112 -0
  227. data/src/osx/event.h +10 -0
  228. data/src/osx/event.mm +114 -30
  229. data/src/osx/file_dialog.mm +168 -0
  230. data/src/osx/gamepad.mm +2 -2
  231. data/src/osx/gamepad_hid.mm +1 -1
  232. data/src/osx/menu.h +25 -0
  233. data/src/osx/menu.mm +516 -0
  234. data/src/osx/native_window.h +16 -2
  235. data/src/osx/native_window.mm +141 -57
  236. data/src/osx/opengl_view.h +2 -1
  237. data/src/osx/opengl_view.mm +229 -37
  238. data/src/osx/reflex.mm +38 -0
  239. data/src/osx/screen.mm +36 -0
  240. data/src/osx/window.mm +117 -24
  241. data/src/pin.cpp +137 -0
  242. data/src/pointer.cpp +36 -16
  243. data/src/pointer.h +10 -0
  244. data/src/rays.h +46 -0
  245. data/src/sdl/application.cpp +73 -8
  246. data/src/sdl/clipboard.cpp +39 -0
  247. data/src/sdl/color_picker.cpp +18 -0
  248. data/src/sdl/event.cpp +44 -6
  249. data/src/sdl/event.h +18 -3
  250. data/src/sdl/file_dialog.cpp +20 -0
  251. data/src/sdl/gamepad.cpp +3 -7
  252. data/src/sdl/menu.cpp +40 -0
  253. data/src/sdl/reflex.cpp +20 -0
  254. data/src/sdl/screen.cpp +36 -0
  255. data/src/sdl/window.cpp +168 -37
  256. data/src/shape.cpp +15 -10
  257. data/src/view.cpp +583 -233
  258. data/src/view.h +22 -4
  259. data/src/vk.h +416 -0
  260. data/src/win32/application.cpp +167 -12
  261. data/src/win32/application.h +20 -0
  262. data/src/win32/clipboard.cpp +210 -0
  263. data/src/win32/color_picker.cpp +82 -0
  264. data/src/win32/event.cpp +123 -11
  265. data/src/win32/event.h +22 -3
  266. data/src/win32/file_dialog.cpp +226 -0
  267. data/src/win32/gamepad.cpp +9 -2
  268. data/src/win32/menu.cpp +490 -0
  269. data/src/win32/menu.h +35 -0
  270. data/src/win32/opengl.cpp +2 -9
  271. data/src/win32/reflex.cpp +44 -3
  272. data/src/win32/screen.cpp +164 -3
  273. data/src/win32/screen.h +8 -0
  274. data/src/win32/tray.cpp +191 -0
  275. data/src/win32/tray.h +22 -0
  276. data/src/win32/vk.cpp +11 -0
  277. data/src/win32/window.cpp +858 -135
  278. data/src/win32/window.h +9 -0
  279. data/src/window.cpp +929 -183
  280. data/src/window.h +77 -33
  281. data/src/world.cpp +86 -15
  282. data/src/world.h +9 -2
  283. data/test/helper.rb +24 -0
  284. data/test/test_application.rb +101 -1
  285. data/test/test_chase_constraint.rb +122 -0
  286. data/test/test_clipboard.rb +54 -0
  287. data/test/test_color_event.rb +36 -0
  288. data/test/test_color_picker.rb +62 -0
  289. data/test/test_constraint.rb +184 -0
  290. data/test/test_event.rb +1 -1
  291. data/test/test_file_dialog.rb +48 -0
  292. data/test/test_file_event.rb +43 -0
  293. data/test/test_has_text_preedit.rb +54 -0
  294. data/test/test_key_event.rb +23 -2
  295. data/test/test_link_constraint.rb +237 -0
  296. data/test/test_menu.rb +237 -0
  297. data/test/test_pin.rb +65 -0
  298. data/test/test_pointer.rb +50 -26
  299. data/test/test_pointer_event.rb +25 -10
  300. data/test/test_reflex.rb +36 -0
  301. data/test/test_screen.rb +24 -2
  302. data/test/test_snap_constraint.rb +140 -0
  303. data/test/test_text_event.rb +54 -0
  304. data/test/test_view.rb +152 -25
  305. data/test/test_wheel_constraint.rb +125 -0
  306. data/test/test_wheel_event.rb +24 -10
  307. data/test/test_window.rb +205 -43
  308. metadata +154 -10
  309. data/.github/workflows/utils.rb +0 -127
@@ -0,0 +1,92 @@
1
+ require 'forwardable'
2
+ require 'xot/setter'
3
+ require 'xot/bit_flag_accessor'
4
+ require 'xot/universal_accessor'
5
+ require 'xot/hookable'
6
+ require 'xot/block_util'
7
+ require 'reflex/ext'
8
+ require 'reflex/helper'
9
+
10
+
11
+ module Reflex
12
+
13
+
14
+ class Menu
15
+
16
+ include Enumerable
17
+ include Xot::Setter
18
+ include Xot::Hookable
19
+
20
+ def initialize(label = nil, **options, &block)
21
+ super()
22
+ self.label = label if label
23
+ set(**options) unless options.empty?
24
+ Xot::BlockUtil.instance_eval_or_block_call self, &block if block
25
+ end
26
+
27
+ def add_child(child, index: nil)
28
+ add_child! child, index
29
+ end
30
+
31
+ alias add add_child
32
+ alias remove remove_child
33
+
34
+ def enable(bool = true)
35
+ enable! bool
36
+ end
37
+
38
+ def disable()
39
+ enable! false
40
+ end
41
+
42
+ def check(bool = true)
43
+ check! bool
44
+ end
45
+
46
+ def uncheck()
47
+ check! false
48
+ end
49
+
50
+ def shortcut=(key_and_modifiers)
51
+ key, *mods = key_and_modifiers
52
+ self.shortcut_key = key
53
+ self.shortcut_modifiers = mods
54
+ end
55
+
56
+ bit_flag_accessor :shortcut_modifiers, **SHORTCUT_MODIFIER_SYMBOLS
57
+
58
+ def shortcut_key=(key)
59
+ key = sym2key(key) if key.is_a? Symbol
60
+ set_shortcut_key! key
61
+ end
62
+
63
+ def shortcut_key()
64
+ Reflex.get_key_symbol! shortcut_key!
65
+ end
66
+
67
+ universal_accessor :label, :image, :shortcut_key, :shortcut_modifiers
68
+
69
+ def each(&block)
70
+ return enum_for :each unless block
71
+ each!(&block)
72
+ end
73
+
74
+ def children()
75
+ to_a
76
+ end
77
+
78
+ def inspect()
79
+ "#<Reflex::Menu label:#{label.inspect} size:#{size}>"
80
+ end
81
+
82
+ private
83
+
84
+ def sym2key(sym)
85
+ KEYS.find {sym == Reflex.get_key_symbol!(_1)} ||
86
+ raise(ArgumentError, "unknown shortcut key: #{sym.inspect}")
87
+ end
88
+
89
+ end# Menu
90
+
91
+
92
+ end# Reflex
data/lib/reflex/model.rb CHANGED
@@ -110,35 +110,35 @@ module Reflex
110
110
 
111
111
  private
112
112
 
113
- INT_SYMS = [:to_i, :to_int]
113
+ INT_SYMS = [:to_i, :to_int]
114
114
 
115
- FLOAT_SYMS = [:to_f, :to_float]
115
+ FLOAT_SYMS = [:to_f, :to_float]
116
116
 
117
- STRING_SYMS = [:to_s, :to_str, :to_string]
117
+ STRING_SYMS = [:to_s, :to_str, :to_string]
118
118
 
119
- ARRAY_GET_SYMS = [:[], :at]
119
+ ARRAY_GET_SYMS = [:[], :at]
120
120
 
121
- ARRAY_SET_SYMS = [:[]=, :set_at]
121
+ ARRAY_SET_SYMS = [:[]=, :set_at]
122
122
 
123
- ARRAY_SIZE_SYMS = [:size, :length]
123
+ ARRAY_SIZE_SYMS = [:size, :length]
124
124
 
125
- def apply_filters(data)
126
- return data unless @filters
127
- @filters.each do |filter|
128
- break if data.nil?
129
- data = filter.call data
130
- end
131
- data
125
+ def apply_filters(data)
126
+ return data unless @filters
127
+ @filters.each do |filter|
128
+ break if data.nil?
129
+ data = filter.call data
132
130
  end
131
+ data
132
+ end
133
133
 
134
- def call_symbols(symbols, *args)
135
- if dat = data
136
- symbols.each do |symbol|
137
- return dat.send symbol, *args if dat.respond_to? symbol
138
- end
134
+ def call_symbols(symbols, *args)
135
+ if dat = data
136
+ symbols.each do |symbol|
137
+ return dat.send symbol, *args if dat.respond_to? symbol
139
138
  end
140
- nil
141
139
  end
140
+ nil
141
+ end
142
142
 
143
143
  end# Model
144
144
 
@@ -24,7 +24,7 @@ module Reflex
24
24
  end
25
25
 
26
26
  def inspect()
27
- "#<Reflex::NoteEvent action:%s channel:%d note:%d vel:0f time:%f captured?:%s>" %
27
+ "#<Reflex::NoteEvent action:%s channel:%d note:%d vel:%f time:%f captured?:%s>" %
28
28
  [action, channel, note, velocity, time, captured?]
29
29
  end
30
30
 
data/lib/reflex/pin.rb ADDED
@@ -0,0 +1,39 @@
1
+ require 'xot/block_util'
2
+ require 'reflex/ext'
3
+
4
+
5
+ module Reflex
6
+
7
+
8
+ class Pin
9
+
10
+ def snap(*args, **options, &block)
11
+ setup__ snap!(*args), options, block
12
+ end
13
+
14
+ def link(*args, **options, &block)
15
+ setup__ link!(*args), options, block
16
+ end
17
+
18
+ def wheel(*args, **options, &block)
19
+ setup__ wheel!(*args), options, block
20
+ end
21
+
22
+ def chase(*args, **options, &block)
23
+ setup__ chase!(*args), options, block
24
+ end
25
+
26
+ alias pos position
27
+
28
+ private
29
+
30
+ def setup__(constraint, options, block)
31
+ constraint.set options unless options.empty?
32
+ Xot::BlockUtil.instance_eval_or_block_call constraint, &block if block
33
+ constraint
34
+ end
35
+
36
+ end# Pin
37
+
38
+
39
+ end# Reflex
@@ -1,6 +1,7 @@
1
1
  require 'xot/bit_flag_accessor'
2
2
  require 'xot/const_symbol_accessor'
3
3
  require 'reflex/ext'
4
+ require 'reflex/helper'
4
5
 
5
6
 
6
7
  module Reflex
@@ -29,9 +30,18 @@ module Reflex
29
30
  up: UP,
30
31
  move: MOVE,
31
32
  cancel: CANCEL,
33
+ enter: ENTER,
34
+ leave: LEAVE,
32
35
  stay: STAY
33
36
  }
34
37
 
38
+ bit_flag_reader :modifiers, **MODIFIER_SYMBOLS
39
+ private alias_method :get_modifiers!, :modifiers
40
+
41
+ def modifiers(all: false)
42
+ all ? get_modifiers! : (get_modifiers!.select {SHORTCUT_MODIFIER_SYMBOLS.key? _1})
43
+ end
44
+
35
45
  def mouse?()
36
46
  (get_types & MOUSE) != 0
37
47
  end
@@ -76,6 +86,14 @@ module Reflex
76
86
  get_action == CANCEL
77
87
  end
78
88
 
89
+ def enter?()
90
+ get_action == ENTER
91
+ end
92
+
93
+ def leave?()
94
+ get_action == LEAVE
95
+ end
96
+
79
97
  def stay?()
80
98
  get_action == STAY
81
99
  end
@@ -95,7 +113,18 @@ module Reflex
95
113
  end
96
114
 
97
115
  def inspect()
98
- "#<Reflex::Pointer id:#{id} #{types} #{action} (#{x.round 2}, #{y.round 2}) mod:#{modifiers} click:#{click_count} drag:#{drag?} time:#{time.round 2}>"
116
+ "#<Reflex::Pointer id:%d %p %p (%p, %p) mod:%p click:%d drag:%p time:%p>" %
117
+ [
118
+ id,
119
+ types,
120
+ action,
121
+ x.round(2),
122
+ y.round(2),
123
+ modifiers(all: true),
124
+ click_count,
125
+ drag?,
126
+ time.round(2)
127
+ ]
99
128
  end
100
129
 
101
130
  end# Pointer
@@ -15,7 +15,7 @@ module Reflex
15
15
  :id,
16
16
  :types, :mouse?, :touch?, :pen?,
17
17
  :mouse_left?, :left?, :mouse_right?, :right?, :mouse_middle?, :middle?,
18
- :action, :down?, :up?, :move?, :cancel?, :stay?,
18
+ :action, :down?, :up?, :move?, :cancel?, :enter?, :leave?, :stay?,
19
19
  :position, :pos, :x, :y, :modifiers, :click_count, :drag?,
20
20
  :time, :prev, :down
21
21
 
@@ -24,7 +24,18 @@ module Reflex
24
24
  end
25
25
 
26
26
  def inspect()
27
- "#<Reflex::PointerEvent id:#{id} #{types} #{action} (#{x.round 2}, #{y.round 2}) mod:#{modifiers} click:#{click_count} drag:#{drag?} time:#{time.round 2}>"
27
+ "#<Reflex::PointerEvent id:%d %p %p (%p, %p) mod:%p click:%d drag:%p time:%p>" %
28
+ [
29
+ id,
30
+ types,
31
+ action,
32
+ x.round(2),
33
+ y.round(2),
34
+ modifiers(all: true),
35
+ click_count,
36
+ drag?,
37
+ time.round(2)
38
+ ]
28
39
  end
29
40
 
30
41
  end# PointerEvent
data/lib/reflex/reflex.rb CHANGED
@@ -19,6 +19,11 @@ module Reflex
19
19
  Window.new(*args, &block).tap {|w| w.show}
20
20
  end
21
21
 
22
+ def alert(message, title: nil)
23
+ utf8 = -> s {s.to_s.encode Encoding::UTF_8, invalid: :replace, undef: :replace}
24
+ alert! utf8[message], title&.then(&utf8)
25
+ end
26
+
22
27
  self
23
28
 
24
29
  end# ClassMethods
data/lib/reflex/shape.rb CHANGED
@@ -39,20 +39,20 @@ module Reflex
39
39
 
40
40
  private
41
41
 
42
- def on_contact!(*args)
43
- call_contact!(*args)
44
- owner&.delay {on_contact(*args)}# delay to avoid physics world lock
45
- end
46
-
47
- def on_contact_begin!(*args)
48
- call_contact_begin!(*args)
49
- owner&.delay {on_contact_begin(*args)}
50
- end
51
-
52
- def on_contact_end!(*args)
53
- call_contact_end!(*args)
54
- owner&.delay {on_contact_end(*args)}
55
- end
42
+ def on_contact!(*args)
43
+ call_contact!(*args)
44
+ owner&.delay {on_contact(*args)}# delay to avoid physics world lock
45
+ end
46
+
47
+ def on_contact_begin!(*args)
48
+ call_contact_begin!(*args)
49
+ owner&.delay {on_contact_begin(*args)}
50
+ end
51
+
52
+ def on_contact_end!(*args)
53
+ call_contact_end!(*args)
54
+ owner&.delay {on_contact_end(*args)}
55
+ end
56
56
 
57
57
  end# Shape
58
58
 
@@ -0,0 +1,28 @@
1
+ require 'reflex/ext'
2
+ require 'reflex/constraint'
3
+
4
+
5
+ module Reflex
6
+
7
+
8
+ class SnapConstraint < Constraint
9
+
10
+ def angle=(angle)
11
+ case angle
12
+ when nil then clear_angle!
13
+ when Range then set_angle! angle.begin, angle.end
14
+ when Numeric then set_angle! angle, angle
15
+ else raise ArgumentError, "invalid angle: #{angle.inspect}"
16
+ end
17
+ end
18
+
19
+ def angle()
20
+ has_angle! ? Range.new(angle_min!, angle_max!) : nil
21
+ end
22
+
23
+ universal_accessor :angle, :motor, :force
24
+
25
+ end# SnapConstraint
26
+
27
+
28
+ end# Reflex
data/lib/reflex/style.rb CHANGED
@@ -110,23 +110,23 @@ module Reflex
110
110
 
111
111
  private
112
112
 
113
- SYM2FLOW = {
114
- none: FLOW_NONE,
115
- down: FLOW_DOWN,
116
- right: FLOW_RIGHT,
117
- up: FLOW_UP,
118
- left: FLOW_LEFT,
119
- }
120
-
121
- FLOW2SYM = SYM2FLOW.inject({}) {|h, (k, v)| h[v] = k; h}
122
-
123
- def sym2flow(sym)
124
- SYM2FLOW[sym] || FLOW_NONE
125
- end
113
+ SYM2FLOW = {
114
+ none: FLOW_NONE,
115
+ down: FLOW_DOWN,
116
+ right: FLOW_RIGHT,
117
+ up: FLOW_UP,
118
+ left: FLOW_LEFT,
119
+ }
120
+
121
+ FLOW2SYM = SYM2FLOW.inject({}) {|h, (k, v)| h[v] = k; h}
122
+
123
+ def sym2flow(sym)
124
+ SYM2FLOW[sym] || FLOW_NONE
125
+ end
126
126
 
127
- def flow2sym(flow)
128
- FLOW2SYM[flow] || :none
129
- end
127
+ def flow2sym(flow)
128
+ FLOW2SYM[flow] || :none
129
+ end
130
130
 
131
131
  end# Style
132
132
 
@@ -0,0 +1,40 @@
1
+ require 'xot/const_symbol_accessor'
2
+ require 'reflex/ext'
3
+
4
+
5
+ module Reflex
6
+
7
+
8
+ class TextEvent < Event
9
+
10
+ alias get_action action
11
+
12
+ const_symbol_reader :action, **{
13
+ none: ACTION_NONE,
14
+ preedit: PREEDIT,
15
+ commit: COMMIT
16
+ }
17
+
18
+ def preedit?()
19
+ get_action == PREEDIT
20
+ end
21
+
22
+ def commit?()
23
+ get_action == COMMIT
24
+ end
25
+
26
+ def selection()
27
+ offset = selection_offset!
28
+ return nil if offset < 0
29
+ offset...(offset + selection_size!)
30
+ end
31
+
32
+ def inspect()
33
+ "#<Reflex::TextEvent action:%s text:'%s' selection:%s>" %
34
+ [action, text, selection || :nil]
35
+ end
36
+
37
+ end# TextEvent
38
+
39
+
40
+ end# Reflex
data/lib/reflex/timer.rb CHANGED
@@ -17,9 +17,9 @@ module Reflex
17
17
 
18
18
  private
19
19
 
20
- def call_timer_block()
21
- @block.call self if @block
22
- end
20
+ def call_timer_block()
21
+ @block.call self if @block
22
+ end
23
23
 
24
24
  end# Timer
25
25
 
data/lib/reflex/view.rb CHANGED
@@ -60,7 +60,7 @@ module Reflex
60
60
  end
61
61
 
62
62
  def timeout(seconds = 0, count: 1, &block)
63
- timer = start_timer seconds, count
63
+ timer = start_timer! seconds, count
64
64
  timer.block = block if block
65
65
  timer
66
66
  end
@@ -73,6 +73,10 @@ module Reflex
73
73
  timeout seconds, &block
74
74
  end
75
75
 
76
+ def add_child(child, index: nil)
77
+ add_child! child, index
78
+ end
79
+
76
80
  def remove_self()
77
81
  parent.remove self if parent
78
82
  end
@@ -81,12 +85,22 @@ module Reflex
81
85
  find_children(*args).first
82
86
  end
83
87
 
88
+ def each_child(&block)
89
+ return enum_for :each_child unless block
90
+ each_child!(&block)
91
+ end
92
+
84
93
  def children()
85
- to_enum :each_child
94
+ each_child.to_a
95
+ end
96
+
97
+ def each_style(&block)
98
+ return enum_for :each_style unless block
99
+ each_style!(&block)
86
100
  end
87
101
 
88
102
  def styles()
89
- to_enum :each_style
103
+ each_style.to_a
90
104
  end
91
105
 
92
106
  def style(*args, &block)
@@ -95,8 +109,46 @@ module Reflex
95
109
  s
96
110
  end
97
111
 
112
+ def each_shape(&block)
113
+ return enum_for :each_shape unless block
114
+ each_shape!(&block)
115
+ end
116
+
117
+ def add_shape(shape, index: nil)
118
+ add_shape! shape, index
119
+ end
120
+
98
121
  def shapes()
99
- to_enum :each_shape
122
+ each_shape.to_a
123
+ end
124
+
125
+ def pin(*args)
126
+ Pin.new self, *args
127
+ end
128
+
129
+ def snap(*args, **options, &block)
130
+ pin.snap(*args, **options, &block)
131
+ end
132
+
133
+ def link(*args, **options, &block)
134
+ pin.link(*args, **options, &block)
135
+ end
136
+
137
+ def wheel(*args, **options, &block)
138
+ pin.wheel(*args, **options, &block)
139
+ end
140
+
141
+ def chase(*args, **options, &block)
142
+ pin.chase(*args, **options, &block)
143
+ end
144
+
145
+ def each_constraint(&block)
146
+ return enum_for :each_constraint unless block
147
+ each_constraint!(&block)
148
+ end
149
+
150
+ def constraints()
151
+ each_constraint.to_a
100
152
  end
101
153
 
102
154
  def capturing?(*args)
@@ -110,6 +162,21 @@ module Reflex
110
162
  end
111
163
  end
112
164
 
165
+ # true or false to force, nil to decide by the presence of an on_text handler.
166
+ def text_input=(state)
167
+ @text_input = state
168
+ set_text_input_flag! !!state
169
+ end
170
+
171
+ attr_reader :text_input
172
+
173
+ def accepts_text_input?()
174
+ return false if hidden?
175
+ return text_input_flag! unless @text_input.nil?
176
+ %i[on_text on_text_preedit on_text_commit]
177
+ .any? {|name| method(name).owner != Reflex::View}
178
+ end
179
+
113
180
  def on_contact(e)
114
181
  end
115
182
 
@@ -120,12 +187,12 @@ module Reflex
120
187
  end
121
188
 
122
189
  universal_accessor :shape, :name, :selector,
123
- :frame, :angle, :pivot, :zoom, :capture,
190
+ :frame, :angle, :pivot, :zoom, :capture, :text_input,
124
191
  :density, :friction, :restitution,
125
192
  :linear_velocity, :angular_velocity, :gravity_scale,
126
193
  :gravity, :time_scale,
127
194
  clip: {reader: :clip?},
128
- cache: {reader: :cache?},
195
+ draw_cache: {reader: :draw_cache?},
129
196
  resize_to_fit: {reader: :resize_to_fit?},
130
197
  scroll_to_fit: {reader: :scroll_to_fit?},
131
198
  fix_angle: {reader: :fix_angle?},
@@ -150,20 +217,20 @@ module Reflex
150
217
 
151
218
  private
152
219
 
153
- def on_contact!(*args)
154
- call_contact!(*args)
155
- delay {on_contact(*args)}# delay to avoid physics world lock
156
- end
220
+ def on_contact!(*args)
221
+ call_contact!(*args)
222
+ delay {on_contact(*args)}# delay to avoid physics world lock
223
+ end
157
224
 
158
- def on_contact_begin!(*args)
159
- call_contact_begin!(*args)
160
- delay {on_contact_begin(*args)}
161
- end
225
+ def on_contact_begin!(*args)
226
+ call_contact_begin!(*args)
227
+ delay {on_contact_begin(*args)}
228
+ end
162
229
 
163
- def on_contact_end!(*args)
164
- call_contact_end!(*args)
165
- delay {on_contact_end(*args)}
166
- end
230
+ def on_contact_end!(*args)
231
+ call_contact_end!(*args)
232
+ delay {on_contact_end(*args)}
233
+ end
167
234
 
168
235
  end# View
169
236
 
@@ -0,0 +1,28 @@
1
+ require 'reflex/ext'
2
+ require 'reflex/constraint'
3
+
4
+
5
+ module Reflex
6
+
7
+
8
+ class WheelConstraint < Constraint
9
+
10
+ def range=(range)
11
+ case range
12
+ when nil then clear_range!
13
+ when Range then set_range! range.begin, range.end
14
+ when Numeric then set_range! range, range
15
+ else raise ArgumentError, "invalid range: #{range.inspect}"
16
+ end
17
+ end
18
+
19
+ def range()
20
+ has_range! ? Range.new(range_min!, range_max!) : nil
21
+ end
22
+
23
+ universal_accessor :axis, :range, :motor, :force
24
+
25
+ end# WheelConstraint
26
+
27
+
28
+ end# Reflex
@@ -1,4 +1,6 @@
1
+ require 'xot/bit_flag_accessor'
1
2
  require 'reflex/ext'
3
+ require 'reflex/helper'
2
4
 
3
5
 
4
6
  module Reflex
@@ -6,8 +8,24 @@ module Reflex
6
8
 
7
9
  class WheelEvent < Event
8
10
 
11
+ bit_flag_reader :modifiers, **MODIFIER_SYMBOLS
12
+ private alias_method :get_modifiers!, :modifiers
13
+
14
+ def modifiers(all: false)
15
+ all ? get_modifiers! : (get_modifiers!.select {SHORTCUT_MODIFIER_SYMBOLS.key? _1})
16
+ end
17
+
9
18
  def inspect()
10
- "#<Reflex::WheelEvent x:#{x} y:#{y} z:#{z} dx:#{dx} dy:#{dy} dz:#{dz} mod:#{modifiers}>"
19
+ "#<Reflex::WheelEvent x:%p y:%p z:%p dx:%p dy:%p dz:%p mod:%p>" %
20
+ [
21
+ x.round(2),
22
+ y.round(2),
23
+ z.round(2),
24
+ dx.round(2),
25
+ dy.round(2),
26
+ dz.round(2),
27
+ modifiers(all: true)
28
+ ]
11
29
  end
12
30
 
13
31
  end# WheelEvent