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/window.rb
CHANGED
|
@@ -21,6 +21,11 @@ module Reflex
|
|
|
21
21
|
|
|
22
22
|
extend Forwardable
|
|
23
23
|
|
|
24
|
+
bit_flag_accessor :titlebar do
|
|
25
|
+
flag :buttons, TITLEBAR_BUTTONS
|
|
26
|
+
flag :background, TITLEBAR_BACKGROUND
|
|
27
|
+
end
|
|
28
|
+
|
|
24
29
|
bit_flag_accessor :orientations do
|
|
25
30
|
flag :portrait, ORIENTATION_PORTRAIT
|
|
26
31
|
flag :landscape, ORIENTATION_LANDSCAPE
|
|
@@ -35,11 +40,11 @@ module Reflex
|
|
|
35
40
|
:timeout, :delay, :interval,
|
|
36
41
|
:meter2pixel, :meter, :wall,
|
|
37
42
|
:zoom=, :zoom,
|
|
38
|
-
:clip=, :clip,
|
|
39
|
-
:
|
|
43
|
+
:clip=, :clip, :clip?,
|
|
44
|
+
:draw_cache=, :draw_cache, :draw_cache?,
|
|
40
45
|
:gravity=, :gravity,
|
|
41
46
|
:time_scale=, :time_scale,
|
|
42
|
-
:debug=, :debug,
|
|
47
|
+
:debug=, :debug, :debug?
|
|
43
48
|
|
|
44
49
|
def_delegators :style,
|
|
45
50
|
:flow=, :flow,
|
|
@@ -68,11 +73,18 @@ module Reflex
|
|
|
68
73
|
:friction=, :friction,
|
|
69
74
|
:restitution=, :restitution
|
|
70
75
|
|
|
71
|
-
universal_accessor :title, :frame,
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
+
universal_accessor :title, :frame, :titlebar,
|
|
77
|
+
:pointer_through_alpha, :orientations,
|
|
78
|
+
closable: {reader: :closable?},
|
|
79
|
+
minimizable: {reader: :minimizable?},
|
|
80
|
+
resizable: {reader: :resizable?},
|
|
81
|
+
unlisted: {reader: :unlisted?},
|
|
82
|
+
shadow: {reader: :shadow?},
|
|
83
|
+
transparent: {reader: :transparent?},
|
|
84
|
+
fullscreen: {reader: :fullscreen?},
|
|
85
|
+
always_on_top: {reader: :always_on_top?},
|
|
86
|
+
always_on_bottom: {reader: :always_on_bottom?},
|
|
87
|
+
pointer_through: {reader: :pointer_through?}
|
|
76
88
|
|
|
77
89
|
def initialize(options = nil, &block)
|
|
78
90
|
super()
|
|
@@ -90,11 +102,11 @@ module Reflex
|
|
|
90
102
|
|
|
91
103
|
private
|
|
92
104
|
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
105
|
+
def call_show_block()
|
|
106
|
+
return unless @show_block
|
|
107
|
+
Xot::BlockUtil.instance_eval_or_block_call self, &@show_block
|
|
108
|
+
@show_block = nil
|
|
109
|
+
end
|
|
98
110
|
|
|
99
111
|
end# Window
|
|
100
112
|
|
data/lib/reflex.rb
CHANGED
|
@@ -25,25 +25,36 @@ require 'reflex/style_length'
|
|
|
25
25
|
require 'reflex/timer'
|
|
26
26
|
require 'reflex/filter'
|
|
27
27
|
|
|
28
|
-
require 'reflex/shape'
|
|
29
|
-
require 'reflex/polygon_shape'
|
|
30
|
-
require 'reflex/line_shape'
|
|
31
|
-
require 'reflex/rect_shape'
|
|
32
|
-
require 'reflex/ellipse_shape'
|
|
33
|
-
|
|
34
28
|
require 'reflex/update_event'
|
|
35
29
|
require 'reflex/draw_event'
|
|
36
30
|
require 'reflex/frame_event'
|
|
37
31
|
require 'reflex/scroll_event'
|
|
38
32
|
require 'reflex/focus_event'
|
|
39
33
|
require 'reflex/key_event'
|
|
34
|
+
require 'reflex/text_event'
|
|
40
35
|
require 'reflex/pointer_event'
|
|
41
36
|
require 'reflex/wheel_event'
|
|
42
|
-
require 'reflex/midi_event'
|
|
43
|
-
require 'reflex/note_event'
|
|
44
37
|
require 'reflex/capture_event'
|
|
45
38
|
require 'reflex/timer_event'
|
|
46
39
|
require 'reflex/contact_event'
|
|
40
|
+
require 'reflex/file_event'
|
|
41
|
+
require 'reflex/color_event'
|
|
42
|
+
require 'reflex/midi_event'
|
|
43
|
+
require 'reflex/note_event'
|
|
44
|
+
require 'reflex/control_change_event'
|
|
45
|
+
|
|
46
|
+
require 'reflex/shape'
|
|
47
|
+
require 'reflex/polygon_shape'
|
|
48
|
+
require 'reflex/line_shape'
|
|
49
|
+
require 'reflex/rect_shape'
|
|
50
|
+
require 'reflex/ellipse_shape'
|
|
51
|
+
|
|
52
|
+
require 'reflex/pin'
|
|
53
|
+
require 'reflex/constraint'
|
|
54
|
+
require 'reflex/snap_constraint'
|
|
55
|
+
require 'reflex/link_constraint'
|
|
56
|
+
require 'reflex/wheel_constraint'
|
|
57
|
+
require 'reflex/chase_constraint'
|
|
47
58
|
|
|
48
59
|
require 'reflex/model'
|
|
49
60
|
require 'reflex/model_owner'
|
|
@@ -51,7 +62,11 @@ require 'reflex/model_owner'
|
|
|
51
62
|
require 'reflex/application'
|
|
52
63
|
require 'reflex/window'
|
|
53
64
|
require 'reflex/view'
|
|
65
|
+
require 'reflex/menu'
|
|
54
66
|
require 'reflex/screen'
|
|
67
|
+
require 'reflex/clipboard'
|
|
68
|
+
require 'reflex/file_dialog'
|
|
69
|
+
require 'reflex/color_picker'
|
|
55
70
|
|
|
56
71
|
require 'reflex/button'
|
|
57
72
|
require 'reflex/text_view'
|
data/pod.rake
CHANGED
|
@@ -3,7 +3,7 @@
|
|
|
3
3
|
|
|
4
4
|
github = 'https://github.com/xord'
|
|
5
5
|
renames = {reflexion: 'reflex'}
|
|
6
|
-
regexp = /add\w+dependency.*['"](\w+)['"].*['"]\s*~>\s*([\d\.]+)\s*['"]/
|
|
6
|
+
regexp = /add\w+dependency.*['"]([\w\-]+)['"].*['"]\s*~>\s*([\d\.]+)\s*['"]/
|
|
7
7
|
repos = File.readlines('reflex.gemspec', chomp: true)
|
|
8
8
|
.map {|s| regexp.match(s)&.values_at 1, 2}
|
|
9
9
|
.compact
|
data/reflex.gemspec
CHANGED
|
@@ -11,7 +11,7 @@ Gem::Specification.new do |s|
|
|
|
11
11
|
|
|
12
12
|
ext = Reflex::Extension
|
|
13
13
|
name = ext.name true
|
|
14
|
-
rdocs = glob.call
|
|
14
|
+
rdocs = glob.call(*%w[README .doc/ext/**/*.cpp])
|
|
15
15
|
|
|
16
16
|
s.name = "#{name}ion"
|
|
17
17
|
s.version = ext.version
|
|
@@ -25,9 +25,9 @@ Gem::Specification.new do |s|
|
|
|
25
25
|
s.platform = Gem::Platform::RUBY
|
|
26
26
|
s.required_ruby_version = '>= 3.0.0'
|
|
27
27
|
|
|
28
|
-
s.add_dependency 'xot', '~> 0.
|
|
29
|
-
s.add_dependency 'rucy', '~> 0.
|
|
30
|
-
s.add_dependency 'rays', '~> 0.
|
|
28
|
+
s.add_dependency 'xot', '~> 0.5.0'
|
|
29
|
+
s.add_dependency 'rucy', '~> 0.5.0'
|
|
30
|
+
s.add_dependency 'rays', '~> 0.5.0'
|
|
31
31
|
|
|
32
32
|
s.files = `git ls-files`.split $/
|
|
33
33
|
s.executables = s.files.grep(%r{^bin/}) {|f| File.basename f}
|
|
@@ -0,0 +1,152 @@
|
|
|
1
|
+
%w[xot rays reflex]
|
|
2
|
+
.map {|s| File.expand_path "../../#{s}/lib", __dir__}
|
|
3
|
+
.each {|s| $:.unshift s if !$:.include?(s) && File.directory?(s)}
|
|
4
|
+
|
|
5
|
+
require 'reflex'
|
|
6
|
+
|
|
7
|
+
|
|
8
|
+
Reflex.start name: "Constraint" do |app|
|
|
9
|
+
Reflex::Window.show title: app.name, frame: [100, 100, 500, 500] do
|
|
10
|
+
gravity 0, 9.8 * meter
|
|
11
|
+
#debug true
|
|
12
|
+
|
|
13
|
+
ball = -> x, y, size_ = 30, color = :red do
|
|
14
|
+
Reflex::View.new {
|
|
15
|
+
pos x, y
|
|
16
|
+
size size_
|
|
17
|
+
background color
|
|
18
|
+
dynamic true
|
|
19
|
+
shape Reflex::EllipseShape.new(density: 1)
|
|
20
|
+
}
|
|
21
|
+
end
|
|
22
|
+
|
|
23
|
+
anchor = -> x, y do
|
|
24
|
+
Reflex::View.new {
|
|
25
|
+
pos x, y
|
|
26
|
+
size 10
|
|
27
|
+
background :darkgray
|
|
28
|
+
static true
|
|
29
|
+
}
|
|
30
|
+
end
|
|
31
|
+
|
|
32
|
+
# pendulum: snap the hanging ball to the anchor center
|
|
33
|
+
pivot = add anchor.call(100, 100)
|
|
34
|
+
weight = add ball.call(160, 100, 30, :orange)
|
|
35
|
+
pivot.snap weight
|
|
36
|
+
|
|
37
|
+
# motored arm: snap with angle range and a motor
|
|
38
|
+
hinge = add anchor.call(250, 100)
|
|
39
|
+
arm = add ball.call(250, 140, 20, :peach)
|
|
40
|
+
hinge.snap arm, angle: -60..60, motor: 90
|
|
41
|
+
|
|
42
|
+
# ground: a bumpy line the car drives over
|
|
43
|
+
ground = [[0, 480], [70, 465], [140, 482], [210, 462],
|
|
44
|
+
[280, 480], [350, 465], [420, 482], [500, 470]]
|
|
45
|
+
add Reflex::View.new {
|
|
46
|
+
pos 0, 0; size 500, 500
|
|
47
|
+
static true
|
|
48
|
+
shape Reflex::LineShape.new.tap {|line| line.add_points(*ground.flatten)}
|
|
49
|
+
}
|
|
50
|
+
|
|
51
|
+
# car: each wheel rides on the body with a wheel joint -- a vertical rail
|
|
52
|
+
# gives suspension (spring) while the wheel spins freely, driven by a
|
|
53
|
+
# motor, so it rolls over the bumpy ground
|
|
54
|
+
body = add Reflex::View.new {
|
|
55
|
+
pos 50, 400; size 70, 16
|
|
56
|
+
background :white
|
|
57
|
+
dynamic true
|
|
58
|
+
shape Reflex::RectShape.new(density: 1)
|
|
59
|
+
}
|
|
60
|
+
wheels, axles = [], []
|
|
61
|
+
[14, 56].each do |x|
|
|
62
|
+
tire = add ball.call(40 + x, 415, 20, :gray)
|
|
63
|
+
wheels << tire
|
|
64
|
+
axles << tire.pin(10, 10).wheel(body.pin(x, 20),
|
|
65
|
+
axis: [0, 1], spring: 6, damping: 0.7, motor: 360)
|
|
66
|
+
end
|
|
67
|
+
|
|
68
|
+
# reverse the drive each time the car reaches a wall. a wheel or a body
|
|
69
|
+
# corner may touch first, so watch them all; the side check ignores the
|
|
70
|
+
# second touch when two parts hit the same wall together.
|
|
71
|
+
edge = wall
|
|
72
|
+
mid, side = body.parent.center.x, nil
|
|
73
|
+
reverse = lambda do |e|
|
|
74
|
+
left = body.center.x < mid
|
|
75
|
+
next if e.view != edge || left == side
|
|
76
|
+
side = left
|
|
77
|
+
axles.each {|a| a.motor = -a.motor}
|
|
78
|
+
end
|
|
79
|
+
[body, *wheels].each {|part| part.on :contact_begin, &reverse}
|
|
80
|
+
|
|
81
|
+
# spring chain: balls linked with springs
|
|
82
|
+
# (collide: true lets the nodes bump each other instead of overlapping)
|
|
83
|
+
top = add anchor.call(400, 50)
|
|
84
|
+
prev = top
|
|
85
|
+
4.times do |i|
|
|
86
|
+
node = add ball.call(400, 90 + i * 40, 20, :green)
|
|
87
|
+
node.link prev, spring: 4, damping: 0.5, collide: true
|
|
88
|
+
prev = node
|
|
89
|
+
end
|
|
90
|
+
|
|
91
|
+
# elevator: a platform rails up and down the world on a vertical axis
|
|
92
|
+
# (a link with an axis), ping-ponging between the ends of its range
|
|
93
|
+
elevator = add Reflex::View.new {
|
|
94
|
+
pos 220, 320; size 60, 10
|
|
95
|
+
background :brown
|
|
96
|
+
dynamic true
|
|
97
|
+
shape Reflex::RectShape.new(density: 1)
|
|
98
|
+
}
|
|
99
|
+
elevator.gravity_scale = 0# the motor moves it, not the gravity
|
|
100
|
+
lift = elevator.pin.link axis: [0, 1], range: -60..60, motor: 30
|
|
101
|
+
|
|
102
|
+
# chaser: follows the pendulum weight with a soft spring
|
|
103
|
+
chaser = add ball.call(100, 400, 25, :blue)
|
|
104
|
+
chaser.gravity_scale = 0
|
|
105
|
+
chaser.sensor = true# do not bump the pendulum
|
|
106
|
+
chaser.chase weight, spring: 2, damping: 1
|
|
107
|
+
|
|
108
|
+
# drag any ball with a chase constraint
|
|
109
|
+
drag = nil
|
|
110
|
+
on :pointer do |e|
|
|
111
|
+
case
|
|
112
|
+
when e.down?
|
|
113
|
+
# hit test in each view's local space to respect rotation, and
|
|
114
|
+
# prefer the topmost (= last added) view
|
|
115
|
+
hit = children.to_a.reverse.find do |c|
|
|
116
|
+
next false unless c.dynamic?
|
|
117
|
+
p = c.from_parent e.pos
|
|
118
|
+
p.x.between?(0, c.frame.w) && p.y.between?(0, c.frame.h)
|
|
119
|
+
end
|
|
120
|
+
if hit
|
|
121
|
+
# pause the elevator drive, or the motor overpowers the drag
|
|
122
|
+
lift.motor = nil if hit == elevator
|
|
123
|
+
# grab the view at the clicked point, not at its center
|
|
124
|
+
drag = hit.pin(hit.from_parent e.pos).chase e.pos,
|
|
125
|
+
spring: 5, damping: 0.7
|
|
126
|
+
end
|
|
127
|
+
when e.drag?
|
|
128
|
+
drag.target = e.pos if drag
|
|
129
|
+
when e.up?
|
|
130
|
+
drag&.remove
|
|
131
|
+
drag = nil
|
|
132
|
+
lift.motor ||= 30# resume the elevator drive
|
|
133
|
+
end
|
|
134
|
+
end
|
|
135
|
+
|
|
136
|
+
after :on_draw do |e|
|
|
137
|
+
# reverse the elevator at the ends of its range (nil while dragging)
|
|
138
|
+
if lift.motor
|
|
139
|
+
lift.motor = -lift.motor.abs if lift.current_distance >= 55
|
|
140
|
+
lift.motor = lift.motor.abs if lift.current_distance <= -55
|
|
141
|
+
end
|
|
142
|
+
|
|
143
|
+
e.painter.push do
|
|
144
|
+
stroke :gray
|
|
145
|
+
ground.each_cons(2) {|a, b| line a[0], a[1], b[0], b[1]}
|
|
146
|
+
no_stroke
|
|
147
|
+
fill :white
|
|
148
|
+
text "#{e.fps.to_i} FPS - drag a ball to chase the pointer", 10, 10
|
|
149
|
+
end
|
|
150
|
+
end
|
|
151
|
+
end
|
|
152
|
+
end
|
data/samples/ime.rb
ADDED
|
@@ -0,0 +1,100 @@
|
|
|
1
|
+
%w[xot rays reflex]
|
|
2
|
+
.map {|s| File.expand_path "../../#{s}/lib", __dir__}
|
|
3
|
+
.each {|s| $:.unshift s if !$:.include?(s) && File.directory?(s)}
|
|
4
|
+
|
|
5
|
+
require 'reflex'
|
|
6
|
+
|
|
7
|
+
include Reflex
|
|
8
|
+
|
|
9
|
+
|
|
10
|
+
MARGIN = 20
|
|
11
|
+
|
|
12
|
+
|
|
13
|
+
# text input is enabled automatically because the text handlers are defined.
|
|
14
|
+
class InputView < View
|
|
15
|
+
|
|
16
|
+
def initialize(*args, &block)
|
|
17
|
+
@text = @preedit = ''
|
|
18
|
+
@selection = nil
|
|
19
|
+
super
|
|
20
|
+
end
|
|
21
|
+
|
|
22
|
+
def on_text_preedit(e)
|
|
23
|
+
@preedit, @selection = e.text, e.selection
|
|
24
|
+
redraw
|
|
25
|
+
end
|
|
26
|
+
|
|
27
|
+
def on_text_commit(e)
|
|
28
|
+
@text += e.text
|
|
29
|
+
@preedit, @selection = '', nil
|
|
30
|
+
redraw
|
|
31
|
+
end
|
|
32
|
+
|
|
33
|
+
# tells the input method where to put the candidate window.
|
|
34
|
+
def text_input_bounds()
|
|
35
|
+
f = font
|
|
36
|
+
[MARGIN + f.width(@text), MARGIN, f.width(@preedit), f.height]
|
|
37
|
+
end
|
|
38
|
+
|
|
39
|
+
def on_draw(e)
|
|
40
|
+
f, p = font, e.painter
|
|
41
|
+
x, y = MARGIN, MARGIN
|
|
42
|
+
|
|
43
|
+
p.fill 1
|
|
44
|
+
p.text @text, x, y
|
|
45
|
+
x += f.width(@text)
|
|
46
|
+
|
|
47
|
+
unless @preedit.empty?
|
|
48
|
+
# keep the underlines just below the baseline, or the candidate window
|
|
49
|
+
# (which opens at the bottom of text_input_bounds) hides them.
|
|
50
|
+
uy = y + f.ascent + 2
|
|
51
|
+
|
|
52
|
+
p.text @preedit, x, y
|
|
53
|
+
underline p, x, uy, f.width(@preedit)
|
|
54
|
+
|
|
55
|
+
if @selection
|
|
56
|
+
# emphasize the clause being converted.
|
|
57
|
+
sx = x + f.width(@preedit[0...@selection.begin] || '')
|
|
58
|
+
underline p, sx, uy + 3, f.width(@preedit[@selection] || '')
|
|
59
|
+
end
|
|
60
|
+
end
|
|
61
|
+
|
|
62
|
+
p.text "|", caret_x(f, x), y
|
|
63
|
+
end
|
|
64
|
+
|
|
65
|
+
private
|
|
66
|
+
|
|
67
|
+
def font()
|
|
68
|
+
window.painter.font
|
|
69
|
+
end
|
|
70
|
+
|
|
71
|
+
# the caret follows the clause being converted, or the end of the preedit.
|
|
72
|
+
def caret_x(font, preedit_x)
|
|
73
|
+
return preedit_x if @preedit.empty?
|
|
74
|
+
|
|
75
|
+
count = @selection ? @selection.end : @preedit.size
|
|
76
|
+
preedit_x + font.width(@preedit[0...count] || '')
|
|
77
|
+
end
|
|
78
|
+
|
|
79
|
+
def underline(painter, x, y, width)
|
|
80
|
+
painter.push stroke: 1 do
|
|
81
|
+
painter.line x, y, x + width, y
|
|
82
|
+
end
|
|
83
|
+
end
|
|
84
|
+
|
|
85
|
+
end# InputView
|
|
86
|
+
|
|
87
|
+
|
|
88
|
+
win = Window.new do
|
|
89
|
+
set title: 'Reflex IME Sample', frame: [100, 100, 600, 200]
|
|
90
|
+
painter.background 0.1
|
|
91
|
+
painter.font = Font.new nil, 24
|
|
92
|
+
|
|
93
|
+
add input = InputView.new(name: :input)
|
|
94
|
+
input.focus
|
|
95
|
+
end
|
|
96
|
+
|
|
97
|
+
|
|
98
|
+
Reflex.start do
|
|
99
|
+
win.show
|
|
100
|
+
end
|