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.
- checksums.yaml +4 -4
- data/.doc/ext/reflex/application.cpp +56 -7
- data/.doc/ext/reflex/capture_event.cpp +1 -1
- data/.doc/ext/reflex/chase_constraint.cpp +84 -0
- data/.doc/ext/reflex/clipboard.cpp +65 -0
- data/.doc/ext/reflex/color_event.cpp +76 -0
- data/.doc/ext/reflex/color_picker.cpp +113 -0
- data/.doc/ext/reflex/constraint.cpp +135 -0
- data/.doc/ext/reflex/contact_event.cpp +1 -1
- data/.doc/ext/reflex/control_change_event.cpp +1 -1
- data/.doc/ext/reflex/device.cpp +1 -1
- data/.doc/ext/reflex/device_event.cpp +1 -1
- data/.doc/ext/reflex/draw_event.cpp +1 -1
- data/.doc/ext/reflex/ellipse_shape.cpp +1 -1
- data/.doc/ext/reflex/event.cpp +1 -1
- data/.doc/ext/reflex/file_dialog.cpp +181 -0
- data/.doc/ext/reflex/file_event.cpp +103 -0
- data/.doc/ext/reflex/filter.cpp +1 -1
- data/.doc/ext/reflex/focus_event.cpp +1 -1
- data/.doc/ext/reflex/frame_event.cpp +1 -1
- data/.doc/ext/reflex/gamepad.cpp +48 -0
- data/.doc/ext/reflex/image_view.cpp +1 -1
- data/.doc/ext/reflex/key_event.cpp +1 -274
- data/.doc/ext/reflex/line_shape.cpp +1 -1
- data/.doc/ext/reflex/link_constraint.cpp +178 -0
- data/.doc/ext/reflex/menu.cpp +303 -0
- data/.doc/ext/reflex/midi.cpp +9 -2
- data/.doc/ext/reflex/midi_event.cpp +1 -1
- data/.doc/ext/reflex/motion_event.cpp +1 -1
- data/.doc/ext/reflex/native.cpp +40 -10
- data/.doc/ext/reflex/note_event.cpp +1 -1
- data/.doc/ext/reflex/pin.cpp +156 -0
- data/.doc/ext/reflex/pointer.cpp +3 -1
- data/.doc/ext/reflex/pointer_event.cpp +3 -3
- data/.doc/ext/reflex/polygon_shape.cpp +1 -1
- data/.doc/ext/reflex/rect_shape.cpp +1 -1
- data/.doc/ext/reflex/reflex.cpp +606 -237
- data/.doc/ext/reflex/screen.cpp +27 -1
- data/.doc/ext/reflex/scroll_event.cpp +1 -1
- data/.doc/ext/reflex/selector.cpp +5 -5
- data/.doc/ext/reflex/shape.cpp +1 -1
- data/.doc/ext/reflex/snap_constraint.cpp +125 -0
- data/.doc/ext/reflex/style.cpp +1 -1
- data/.doc/ext/reflex/style_length.cpp +4 -3
- data/.doc/ext/reflex/text_event.cpp +104 -0
- data/.doc/ext/reflex/timer.cpp +1 -1
- data/.doc/ext/reflex/timer_event.cpp +1 -1
- data/.doc/ext/reflex/update_event.cpp +1 -1
- data/.doc/ext/reflex/view.cpp +206 -79
- data/.doc/ext/reflex/wheel_constraint.cpp +142 -0
- data/.doc/ext/reflex/wheel_event.cpp +1 -1
- data/.doc/ext/reflex/window.cpp +282 -31
- data/.github/workflows/release-gem.yml +2 -40
- data/.github/workflows/tag.yml +5 -28
- data/.github/workflows/test.yml +1 -28
- data/ChangeLog.md +79 -0
- data/Gemfile.lock +13 -8
- data/README.md +1 -0
- data/Rakefile +13 -2
- data/Reflex.podspec +2 -2
- data/VERSION +1 -1
- data/ext/reflex/application.cpp +62 -7
- data/ext/reflex/capture_event.cpp +1 -1
- data/ext/reflex/chase_constraint.cpp +89 -0
- data/ext/reflex/clipboard.cpp +69 -0
- data/ext/reflex/color_event.cpp +80 -0
- data/ext/reflex/color_picker.cpp +121 -0
- data/ext/reflex/constraint.cpp +146 -0
- data/ext/reflex/contact_event.cpp +1 -1
- data/ext/reflex/control_change_event.cpp +1 -1
- data/ext/reflex/device.cpp +1 -1
- data/ext/reflex/device_event.cpp +1 -1
- data/ext/reflex/draw_event.cpp +1 -1
- data/ext/reflex/ellipse_shape.cpp +1 -1
- data/ext/reflex/event.cpp +1 -1
- data/ext/reflex/extconf.rb +4 -2
- data/ext/reflex/file_dialog.cpp +194 -0
- data/ext/reflex/file_event.cpp +108 -0
- data/ext/reflex/filter.cpp +1 -1
- data/ext/reflex/focus_event.cpp +1 -1
- data/ext/reflex/frame_event.cpp +1 -1
- data/ext/reflex/gamepad.cpp +50 -0
- data/ext/reflex/image_view.cpp +1 -1
- data/ext/reflex/key_event.cpp +1 -275
- data/ext/reflex/line_shape.cpp +1 -1
- data/ext/reflex/link_constraint.cpp +194 -0
- data/ext/reflex/menu.cpp +331 -0
- data/ext/reflex/midi.cpp +11 -3
- data/ext/reflex/midi_event.cpp +1 -1
- data/ext/reflex/motion_event.cpp +1 -1
- data/ext/reflex/native.cpp +40 -10
- data/ext/reflex/note_event.cpp +1 -1
- data/ext/reflex/pin.cpp +165 -0
- data/ext/reflex/pointer.cpp +3 -1
- data/ext/reflex/pointer_event.cpp +3 -3
- data/ext/reflex/polygon_shape.cpp +1 -1
- data/ext/reflex/rect_shape.cpp +1 -1
- data/ext/reflex/reflex.cpp +608 -237
- data/ext/reflex/screen.cpp +31 -2
- data/ext/reflex/scroll_event.cpp +1 -1
- data/ext/reflex/selector.cpp +5 -5
- data/ext/reflex/selector.h +10 -10
- data/ext/reflex/shape.cpp +1 -1
- data/ext/reflex/snap_constraint.cpp +135 -0
- data/ext/reflex/style.cpp +1 -1
- data/ext/reflex/style_length.cpp +4 -3
- data/ext/reflex/text_event.cpp +111 -0
- data/ext/reflex/timer.cpp +1 -1
- data/ext/reflex/timer_event.cpp +1 -1
- data/ext/reflex/update_event.cpp +1 -1
- data/ext/reflex/view.cpp +236 -96
- data/ext/reflex/wheel_constraint.cpp +154 -0
- data/ext/reflex/wheel_event.cpp +1 -1
- data/ext/reflex/window.cpp +318 -40
- data/include/reflex/application.h +19 -0
- data/include/reflex/clipboard.h +53 -0
- data/include/reflex/color_picker.h +65 -0
- data/include/reflex/constraint.h +275 -0
- data/include/reflex/defs.h +204 -195
- data/include/reflex/event.h +180 -88
- data/include/reflex/file_dialog.h +73 -0
- data/include/reflex/gamepad.h +3 -0
- data/include/reflex/menu.h +120 -0
- data/include/reflex/midi.h +3 -0
- data/include/reflex/pin.h +68 -0
- data/include/reflex/pointer.h +4 -0
- data/include/reflex/reflex.h +2 -0
- data/include/reflex/ruby/application.h +6 -1
- data/include/reflex/ruby/clipboard.h +23 -0
- data/include/reflex/ruby/color_picker.h +89 -0
- data/include/reflex/ruby/constraint.h +94 -0
- data/include/reflex/ruby/event.h +62 -29
- data/include/reflex/ruby/file_dialog.h +89 -0
- data/include/reflex/ruby/gamepad.h +46 -0
- data/include/reflex/ruby/menu.h +103 -0
- data/include/reflex/ruby/pin.h +40 -0
- data/include/reflex/ruby/reflex.h +3 -0
- data/include/reflex/ruby/view.h +123 -39
- data/include/reflex/ruby/window.h +96 -19
- data/include/reflex/ruby.h +3 -0
- data/include/reflex/screen.h +11 -2
- data/include/reflex/view.h +66 -27
- data/include/reflex/window.h +57 -12
- data/include/reflex.h +8 -0
- data/lib/reflex/application.rb +5 -5
- data/lib/reflex/autoinit.rb +3 -1
- data/lib/reflex/button.rb +3 -3
- data/lib/reflex/chase_constraint.rb +15 -0
- data/lib/reflex/clipboard.rb +19 -0
- data/lib/reflex/color_event.rb +16 -0
- data/lib/reflex/color_picker.rb +45 -0
- data/lib/reflex/constraint.rb +29 -0
- data/lib/reflex/control_change_event.rb +17 -0
- data/lib/reflex/extension.rb +1 -1
- data/lib/reflex/file_dialog.rb +70 -0
- data/lib/reflex/file_event.rb +37 -0
- data/lib/reflex/helper.rb +79 -0
- data/lib/reflex/key_event.rb +14 -14
- data/lib/reflex/link_constraint.rb +31 -0
- data/lib/reflex/menu.rb +92 -0
- data/lib/reflex/model.rb +19 -19
- data/lib/reflex/note_event.rb +1 -1
- data/lib/reflex/pin.rb +39 -0
- data/lib/reflex/pointer.rb +30 -1
- data/lib/reflex/pointer_event.rb +13 -2
- data/lib/reflex/reflex.rb +5 -0
- data/lib/reflex/shape.rb +14 -14
- data/lib/reflex/snap_constraint.rb +28 -0
- data/lib/reflex/style.rb +16 -16
- data/lib/reflex/text_event.rb +40 -0
- data/lib/reflex/timer.rb +3 -3
- data/lib/reflex/view.rb +85 -18
- data/lib/reflex/wheel_constraint.rb +28 -0
- data/lib/reflex/wheel_event.rb +19 -1
- data/lib/reflex/window.rb +25 -13
- data/lib/reflex.rb +23 -8
- data/pod.rake +1 -1
- data/reflex.gemspec +4 -4
- data/samples/constraint.rb +152 -0
- data/samples/ime.rb +100 -0
- data/samples/ios/hello/hello.xcodeproj/project.pbxproj +236 -224
- data/samples/menu.rb +32 -0
- data/samples/model.rb +3 -3
- data/samples/test/alert.rb +93 -0
- data/samples/test/always_on.rb +76 -0
- data/samples/test/app_background.rb +51 -0
- data/samples/test/boundary.rb +75 -0
- data/samples/test/callback_exception.rb +101 -0
- data/samples/test/cancel.rb +53 -0
- data/samples/test/color_picker.rb +63 -0
- data/samples/test/file_dialog.rb +102 -0
- data/samples/window_style.rb +156 -0
- data/src/application.cpp +180 -20
- data/src/application.h +95 -5
- data/src/clipboard.cpp +81 -0
- data/src/color_picker.cpp +113 -0
- data/src/color_picker.h +36 -0
- data/src/constraint.cpp +1662 -0
- data/src/constraint.h +64 -0
- data/src/event.cpp +416 -252
- data/src/event.h +13 -2
- data/src/file_dialog.cpp +163 -0
- data/src/file_dialog.h +52 -0
- data/src/gamepad.cpp +42 -5
- data/src/gamepad.h +4 -0
- data/src/ios/app_delegate.mm +5 -3
- data/src/ios/application.mm +29 -0
- data/src/ios/clipboard.mm +44 -0
- data/src/ios/color_picker.mm +19 -0
- data/src/ios/event.h +6 -2
- data/src/ios/event.mm +31 -12
- data/src/ios/file_dialog.mm +21 -0
- data/src/ios/gamepad.mm +4 -4
- data/src/ios/menu.mm +41 -0
- data/src/ios/reflex.mm +8 -0
- data/src/ios/screen.mm +26 -0
- data/src/ios/view_controller.mm +47 -42
- data/src/ios/window.mm +44 -9
- data/src/menu.cpp +387 -0
- data/src/menu.h +81 -0
- data/src/midi.cpp +61 -31
- data/src/osx/app_delegate.h +4 -0
- data/src/osx/app_delegate.mm +168 -139
- data/src/osx/application.mm +103 -5
- data/src/osx/clipboard.mm +45 -0
- data/src/osx/color_picker.mm +112 -0
- data/src/osx/event.h +10 -0
- data/src/osx/event.mm +114 -30
- data/src/osx/file_dialog.mm +168 -0
- data/src/osx/gamepad.mm +2 -2
- data/src/osx/gamepad_hid.mm +1 -1
- data/src/osx/menu.h +25 -0
- data/src/osx/menu.mm +516 -0
- data/src/osx/native_window.h +16 -2
- data/src/osx/native_window.mm +141 -57
- data/src/osx/opengl_view.h +2 -1
- data/src/osx/opengl_view.mm +229 -37
- data/src/osx/reflex.mm +38 -0
- data/src/osx/screen.mm +36 -0
- data/src/osx/window.mm +117 -24
- data/src/pin.cpp +137 -0
- data/src/pointer.cpp +36 -16
- data/src/pointer.h +10 -0
- data/src/rays.h +46 -0
- data/src/sdl/application.cpp +73 -8
- data/src/sdl/clipboard.cpp +39 -0
- data/src/sdl/color_picker.cpp +18 -0
- data/src/sdl/event.cpp +44 -6
- data/src/sdl/event.h +18 -3
- data/src/sdl/file_dialog.cpp +20 -0
- data/src/sdl/gamepad.cpp +3 -7
- data/src/sdl/menu.cpp +40 -0
- data/src/sdl/reflex.cpp +20 -0
- data/src/sdl/screen.cpp +36 -0
- data/src/sdl/window.cpp +168 -37
- data/src/shape.cpp +15 -10
- data/src/view.cpp +583 -233
- data/src/view.h +22 -4
- data/src/vk.h +416 -0
- data/src/win32/application.cpp +167 -12
- data/src/win32/application.h +20 -0
- data/src/win32/clipboard.cpp +210 -0
- data/src/win32/color_picker.cpp +82 -0
- data/src/win32/event.cpp +123 -11
- data/src/win32/event.h +22 -3
- data/src/win32/file_dialog.cpp +226 -0
- data/src/win32/gamepad.cpp +9 -2
- data/src/win32/menu.cpp +490 -0
- data/src/win32/menu.h +35 -0
- data/src/win32/opengl.cpp +2 -9
- data/src/win32/reflex.cpp +44 -3
- data/src/win32/screen.cpp +164 -3
- data/src/win32/screen.h +8 -0
- data/src/win32/tray.cpp +191 -0
- data/src/win32/tray.h +22 -0
- data/src/win32/vk.cpp +11 -0
- data/src/win32/window.cpp +858 -135
- data/src/win32/window.h +9 -0
- data/src/window.cpp +929 -183
- data/src/window.h +77 -33
- data/src/world.cpp +86 -15
- data/src/world.h +9 -2
- data/test/helper.rb +24 -0
- data/test/test_application.rb +101 -1
- data/test/test_chase_constraint.rb +122 -0
- data/test/test_clipboard.rb +54 -0
- data/test/test_color_event.rb +36 -0
- data/test/test_color_picker.rb +62 -0
- data/test/test_constraint.rb +184 -0
- data/test/test_event.rb +1 -1
- data/test/test_file_dialog.rb +48 -0
- data/test/test_file_event.rb +43 -0
- data/test/test_has_text_preedit.rb +54 -0
- data/test/test_key_event.rb +23 -2
- data/test/test_link_constraint.rb +237 -0
- data/test/test_menu.rb +237 -0
- data/test/test_pin.rb +65 -0
- data/test/test_pointer.rb +50 -26
- data/test/test_pointer_event.rb +25 -10
- data/test/test_reflex.rb +36 -0
- data/test/test_screen.rb +24 -2
- data/test/test_snap_constraint.rb +140 -0
- data/test/test_text_event.rb +54 -0
- data/test/test_view.rb +152 -25
- data/test/test_wheel_constraint.rb +125 -0
- data/test/test_wheel_event.rb +24 -10
- data/test/test_window.rb +205 -43
- metadata +154 -10
- data/.github/workflows/utils.rb +0 -127
data/lib/reflex/menu.rb
ADDED
|
@@ -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
|
-
|
|
113
|
+
INT_SYMS = [:to_i, :to_int]
|
|
114
114
|
|
|
115
|
-
|
|
115
|
+
FLOAT_SYMS = [:to_f, :to_float]
|
|
116
116
|
|
|
117
|
-
|
|
117
|
+
STRING_SYMS = [:to_s, :to_str, :to_string]
|
|
118
118
|
|
|
119
|
-
|
|
119
|
+
ARRAY_GET_SYMS = [:[], :at]
|
|
120
120
|
|
|
121
|
-
|
|
121
|
+
ARRAY_SET_SYMS = [:[]=, :set_at]
|
|
122
122
|
|
|
123
|
-
|
|
123
|
+
ARRAY_SIZE_SYMS = [:size, :length]
|
|
124
124
|
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
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
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
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
|
|
data/lib/reflex/note_event.rb
CHANGED
|
@@ -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
|
|
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
|
data/lib/reflex/pointer.rb
CHANGED
|
@@ -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
|
|
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
|
data/lib/reflex/pointer_event.rb
CHANGED
|
@@ -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
|
|
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
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
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
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
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
|
-
|
|
128
|
-
|
|
129
|
-
|
|
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
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
|
-
|
|
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
|
-
|
|
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
|
-
|
|
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
|
-
|
|
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
|
-
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
|
|
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
|
-
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
|
|
225
|
+
def on_contact_begin!(*args)
|
|
226
|
+
call_contact_begin!(*args)
|
|
227
|
+
delay {on_contact_begin(*args)}
|
|
228
|
+
end
|
|
162
229
|
|
|
163
|
-
|
|
164
|
-
|
|
165
|
-
|
|
166
|
-
|
|
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
|
data/lib/reflex/wheel_event.rb
CHANGED
|
@@ -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
|
|
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
|