reflexion 0.1.6 → 0.1.7
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 +7 -0
- data/.doc/ext/reflex/application.cpp +54 -39
- data/.doc/ext/reflex/capture_event.cpp +87 -0
- data/.doc/ext/reflex/draw_event.cpp +103 -0
- data/.doc/ext/reflex/event.cpp +73 -0
- data/.doc/ext/reflex/focus_event.cpp +98 -0
- data/.doc/ext/reflex/frame_event.cpp +133 -0
- data/.doc/ext/reflex/image_view.cpp +74 -0
- data/.doc/ext/reflex/key_event.cpp +124 -0
- data/.doc/ext/reflex/native.cpp +45 -6
- data/.doc/ext/reflex/pointer_event.cpp +181 -0
- data/.doc/ext/reflex/reflex.cpp +17 -41
- data/.doc/ext/reflex/scroll_event.cpp +141 -0
- data/.doc/ext/reflex/selector.cpp +135 -0
- data/.doc/ext/reflex/style.cpp +253 -0
- data/.doc/ext/reflex/style_length.cpp +133 -0
- data/.doc/ext/reflex/style_length2.cpp +149 -0
- data/.doc/ext/reflex/style_length4.cpp +192 -0
- data/.doc/ext/reflex/update_event.cpp +77 -0
- data/.doc/ext/reflex/view.cpp +408 -88
- data/.doc/ext/reflex/wheel_event.cpp +146 -0
- data/.doc/ext/reflex/window.cpp +95 -92
- data/Rakefile +6 -5
- data/VERSION +1 -1
- data/ext/reflex/application.cpp +67 -49
- data/ext/reflex/capture_event.cpp +92 -0
- data/ext/reflex/draw_event.cpp +110 -0
- data/ext/reflex/event.cpp +77 -0
- data/ext/reflex/extconf.rb +18 -68
- data/ext/reflex/focus_event.cpp +104 -0
- data/ext/reflex/frame_event.cpp +143 -0
- data/ext/reflex/image_view.cpp +77 -0
- data/ext/reflex/key_event.cpp +133 -0
- data/ext/reflex/native.cpp +45 -6
- data/ext/reflex/pointer_event.cpp +195 -0
- data/ext/reflex/reflex.cpp +21 -47
- data/ext/reflex/scroll_event.cpp +152 -0
- data/ext/reflex/selector.cpp +144 -0
- data/ext/reflex/style.cpp +277 -0
- data/ext/reflex/style_length.cpp +140 -0
- data/ext/reflex/style_length2.cpp +157 -0
- data/ext/reflex/style_length4.cpp +204 -0
- data/ext/reflex/update_event.cpp +81 -0
- data/ext/reflex/view.cpp +469 -114
- data/ext/reflex/wheel_event.cpp +158 -0
- data/ext/reflex/window.cpp +130 -123
- data/include/reflex/application.h +12 -7
- data/include/reflex/defs.h +13 -89
- data/include/reflex/event.h +260 -0
- data/include/reflex/exception.h +17 -11
- data/include/reflex/image_view.h +45 -0
- data/include/reflex/reflex.h +2 -6
- data/include/reflex/ruby/application.h +40 -13
- data/include/reflex/ruby/event.h +72 -0
- data/include/reflex/ruby/image_view.h +25 -0
- data/include/reflex/ruby/selector.h +27 -0
- data/include/reflex/ruby/style.h +27 -0
- data/include/reflex/ruby/style_length.h +37 -0
- data/include/reflex/ruby/view.h +193 -38
- data/include/reflex/ruby/window.h +123 -39
- data/include/reflex/ruby.h +3 -2
- data/include/reflex/selector.h +64 -0
- data/include/reflex/style.h +144 -0
- data/include/reflex/style_length.h +147 -0
- data/include/reflex/view.h +182 -19
- data/include/reflex/window.h +35 -19
- data/include/reflex.h +7 -0
- data/lib/reflex/application.rb +14 -5
- data/lib/reflex/arc_shape.rb +20 -0
- data/lib/reflex/button.rb +75 -0
- data/lib/reflex/capture_event.rb +37 -0
- data/lib/reflex/color.rb +13 -0
- data/lib/reflex/color_space.rb +13 -0
- data/lib/reflex/draw_event.rb +19 -0
- data/lib/reflex/ellipse_shape.rb +20 -0
- data/lib/reflex/ext.rb +1 -1
- data/lib/reflex/flags.rb +18 -0
- data/lib/reflex/focus_event.rb +38 -0
- data/lib/reflex/font.rb +13 -0
- data/lib/reflex/frame_event.rb +42 -0
- data/lib/reflex/helper.rb +87 -30
- data/lib/reflex/image_view.rb +25 -0
- data/lib/reflex/key_event.rb +38 -0
- data/lib/reflex/line_shape.rb +20 -0
- data/lib/reflex/list_view.rb +15 -0
- data/lib/reflex/model.rb +149 -0
- data/lib/reflex/model_owner.rb +57 -0
- data/lib/reflex/model_view.rb +22 -0
- data/lib/reflex/module.rb +11 -7
- data/lib/reflex/pointer_event.rb +85 -0
- data/lib/reflex/rect_shape.rb +20 -0
- data/lib/reflex/reflex.rb +13 -2
- data/lib/reflex/scroll_event.rb +19 -0
- data/lib/reflex/selector.rb +31 -0
- data/lib/reflex/shader.rb +13 -0
- data/lib/reflex/shape.rb +34 -0
- data/lib/reflex/style.rb +55 -0
- data/lib/reflex/style_length.rb +30 -0
- data/lib/reflex/style_length2.rb +34 -0
- data/lib/reflex/style_length4.rb +38 -0
- data/lib/reflex/text_view.rb +55 -0
- data/lib/reflex/update_event.rb +19 -0
- data/lib/reflex/view.rb +38 -4
- data/lib/reflex/wheel_event.rb +19 -0
- data/lib/reflex/window.rb +7 -5
- data/lib/reflex.rb +38 -1
- data/lib/reflexion/include.rb +5 -0
- data/lib/reflexion.rb +100 -0
- data/reflex.gemspec +3 -4
- data/samples/app.rb +13 -0
- data/samples/bats.rb +91 -0
- data/samples/checker.rb +36 -0
- data/{examples/ruby/shapes.rb → samples/fans.rb} +12 -16
- data/samples/fps.rb +46 -0
- data/samples/grid.rb +60 -0
- data/{examples/ruby → samples}/hello.rb +14 -16
- data/samples/image.rb +44 -0
- data/samples/ios/hello/hello/Images.xcassets/AppIcon.appiconset/Contents.json +53 -0
- data/samples/ios/hello/hello/Images.xcassets/LaunchImage.launchimage/Contents.json +51 -0
- data/samples/ios/hello/hello/en.lproj/InfoPlist.strings +2 -0
- data/samples/ios/hello/hello/hello-Info.plist +47 -0
- data/samples/ios/hello/hello/hello-Prefix.pch +10 -0
- data/samples/ios/hello/hello/main.cpp +79 -0
- data/samples/ios/hello/hello.xcodeproj/project.pbxproj +725 -0
- data/{examples/ruby → samples}/key.rb +11 -14
- data/samples/layout.rb +89 -0
- data/samples/model.rb +86 -0
- data/samples/osx/hello/hello/Images.xcassets/AppIcon.appiconset/Contents.json +58 -0
- data/samples/osx/hello/hello/en.lproj/Credits.rtf +29 -0
- data/samples/osx/hello/hello/en.lproj/InfoPlist.strings +2 -0
- data/samples/osx/hello/hello/hello-Info.plist +32 -0
- data/samples/osx/hello/hello/hello-Prefix.pch +3 -0
- data/samples/osx/hello/hello/main.cpp +79 -0
- data/samples/osx/hello/hello.xcodeproj/project.pbxproj +725 -0
- data/samples/reflexion/hello.rb +24 -0
- data/samples/reflexion/paint.rb +40 -0
- data/samples/reflexion/pulse.rb +34 -0
- data/samples/repl.rb +69 -0
- data/samples/shader.rb +41 -0
- data/samples/shapes.rb +30 -0
- data/{examples/ruby → samples}/text.rb +7 -8
- data/samples/tree.rb +71 -0
- data/samples/views.rb +41 -0
- data/samples/visuals.rb +22 -0
- data/src/event.cpp +225 -0
- data/src/exception.cpp +24 -15
- data/src/image_view.cpp +70 -0
- data/src/ios/app_delegate.h +17 -0
- data/src/ios/app_delegate.mm +120 -0
- data/src/ios/application.mm +116 -0
- data/src/{cocoa/applicationdata.h → ios/application_data.h} +6 -6
- data/src/ios/event.h +26 -0
- data/src/ios/event.mm +31 -0
- data/src/ios/native_window.h +37 -0
- data/src/ios/native_window.mm +220 -0
- data/src/ios/opengl_view.h +13 -0
- data/src/ios/opengl_view.mm +131 -0
- data/src/{cocoa → ios}/reflex.mm +8 -12
- data/src/ios/window.mm +303 -0
- data/src/ios/window_data.h +75 -0
- data/src/osx/app_delegate.h +17 -0
- data/src/{cocoa/cocoaapplication.mm → osx/app_delegate.mm} +90 -48
- data/src/osx/application.mm +132 -0
- data/src/osx/application_data.h +45 -0
- data/src/osx/event.h +42 -0
- data/src/osx/event.mm +112 -0
- data/src/osx/native_window.h +26 -0
- data/src/osx/native_window.mm +322 -0
- data/src/{cocoa/openglview.h → osx/opengl_view.h} +0 -4
- data/src/{cocoa/openglview.mm → osx/opengl_view.mm} +66 -23
- data/src/osx/reflex.mm +50 -0
- data/src/osx/window.mm +308 -0
- data/src/osx/window_data.h +75 -0
- data/src/selector.cpp +121 -0
- data/src/style.cpp +576 -0
- data/src/style_length.cpp +341 -0
- data/src/view.cpp +1228 -129
- data/src/win32/application.cpp +1 -1
- data/src/window.cpp +54 -26
- data/test/helper.rb +8 -4
- data/test/test_capture_event.rb +41 -0
- data/test/test_event.rb +20 -0
- data/test/test_has_frame.rb +45 -0
- data/test/test_model.rb +9 -0
- data/test/test_model_owner.rb +9 -0
- data/test/test_selector.rb +75 -0
- data/test/test_style.rb +70 -0
- data/test/test_style_length.rb +38 -0
- data/test/test_style_length2.rb +50 -0
- data/test/test_style_length4.rb +56 -0
- data/test/test_view.rb +97 -23
- data/test/test_window.rb +54 -46
- metadata +205 -84
- data/.doc/ext/reflex/defs.cpp +0 -8
- data/.doc/ext/reflex/key.cpp +0 -122
- data/.doc/ext/reflex/points.cpp +0 -151
- data/.gitignore +0 -14
- data/ChangeLog +0 -8
- data/examples/hello/.gitignore +0 -2
- data/examples/hello/Rakefile +0 -41
- data/examples/hello/main.cpp +0 -18
- data/examples/ruby/app.rb +0 -13
- data/examples/ruby/checker.rb +0 -41
- data/examples/ruby/fps.rb +0 -49
- data/examples/ruby/grid.rb +0 -65
- data/examples/ruby/views.rb +0 -88
- data/examples/ruby/visuals.rb +0 -27
- data/ext/reflex/defs.cpp +0 -8
- data/ext/reflex/key.cpp +0 -129
- data/ext/reflex/points.cpp +0 -161
- data/include/reflex/ruby/key.h +0 -39
- data/include/reflex/ruby/points.h +0 -39
- data/lib/reflex/visuals/string.rb +0 -53
- data/src/cocoa/application.mm +0 -101
- data/src/cocoa/cocoaapplication.h +0 -21
- data/src/cocoa/cocoawindow.h +0 -46
- data/src/cocoa/cocoawindow.mm +0 -230
- data/src/cocoa/defs.h +0 -34
- data/src/cocoa/defs.mm +0 -87
- data/src/cocoa/window.mm +0 -148
- data/src/cocoa/windowdata.h +0 -56
- data/src/defs.cpp +0 -47
- data/src/helper.h +0 -12
- data/src/reflex.cpp +0 -43
- /data/{README → README.md} +0 -0
|
@@ -0,0 +1,55 @@
|
|
|
1
|
+
# -*- coding: utf-8 -*-
|
|
2
|
+
|
|
3
|
+
|
|
4
|
+
require 'reflex/image'
|
|
5
|
+
require 'reflex/bitmap'
|
|
6
|
+
require 'reflex/view'
|
|
7
|
+
|
|
8
|
+
|
|
9
|
+
module Reflex
|
|
10
|
+
|
|
11
|
+
|
|
12
|
+
class TextView < View
|
|
13
|
+
|
|
14
|
+
has_model
|
|
15
|
+
|
|
16
|
+
attr_accessor :font
|
|
17
|
+
|
|
18
|
+
def initialize (*args, &block)
|
|
19
|
+
@outdated = false
|
|
20
|
+
super
|
|
21
|
+
end
|
|
22
|
+
|
|
23
|
+
def content_size ()
|
|
24
|
+
s = string
|
|
25
|
+
return 0, 0 unless s && window
|
|
26
|
+
font = @font || window.painter.font
|
|
27
|
+
[font.width(s), font.height].map &:ceil
|
|
28
|
+
end
|
|
29
|
+
|
|
30
|
+
def on_draw (e)
|
|
31
|
+
@image = create_text_image if @outdated
|
|
32
|
+
return unless @image
|
|
33
|
+
|
|
34
|
+
pa = e.painter
|
|
35
|
+
pa.color 1
|
|
36
|
+
pa.image @image
|
|
37
|
+
end
|
|
38
|
+
|
|
39
|
+
def on_data_update (e)
|
|
40
|
+
@outdated = true
|
|
41
|
+
super
|
|
42
|
+
end
|
|
43
|
+
|
|
44
|
+
private
|
|
45
|
+
|
|
46
|
+
def create_text_image ()
|
|
47
|
+
str, size = string, content_size
|
|
48
|
+
return nil unless str && size.all? {|n| n > 0}
|
|
49
|
+
Image.new Bitmap.new(*size, :GRAY).draw_string(str), true
|
|
50
|
+
end
|
|
51
|
+
|
|
52
|
+
end# TextView
|
|
53
|
+
|
|
54
|
+
|
|
55
|
+
end# Reflex
|
data/lib/reflex/view.rb
CHANGED
|
@@ -1,10 +1,11 @@
|
|
|
1
1
|
# -*- coding: utf-8 -*-
|
|
2
2
|
|
|
3
3
|
|
|
4
|
-
require 'xot/hookable'
|
|
5
4
|
require 'xot/setter'
|
|
6
5
|
require 'xot/block_util'
|
|
7
6
|
require 'reflex/ext'
|
|
7
|
+
require 'reflex/model_view'
|
|
8
|
+
require 'reflex/flags'
|
|
8
9
|
require 'reflex/helper'
|
|
9
10
|
|
|
10
11
|
|
|
@@ -13,13 +14,14 @@ module Reflex
|
|
|
13
14
|
|
|
14
15
|
class View
|
|
15
16
|
|
|
16
|
-
include Xot::Hookable
|
|
17
17
|
include Xot::Setter
|
|
18
|
-
include
|
|
18
|
+
include Hookable
|
|
19
|
+
include HasFrame
|
|
20
|
+
include HasTags
|
|
19
21
|
|
|
20
22
|
alias add add_child
|
|
21
23
|
alias remove remove_child
|
|
22
|
-
alias find
|
|
24
|
+
alias find find_children
|
|
23
25
|
|
|
24
26
|
def initialize (opts = {}, &block)
|
|
25
27
|
super()
|
|
@@ -27,6 +29,38 @@ module Reflex
|
|
|
27
29
|
Xot::BlockUtil.instance_eval_or_block_call self, &block if block
|
|
28
30
|
end
|
|
29
31
|
|
|
32
|
+
def children ()
|
|
33
|
+
to_enum :each_child
|
|
34
|
+
end
|
|
35
|
+
|
|
36
|
+
def styles ()
|
|
37
|
+
to_enum :each_style
|
|
38
|
+
end
|
|
39
|
+
|
|
40
|
+
def style (*args, &block)
|
|
41
|
+
s = get_style *args
|
|
42
|
+
Xot::BlockUtil.instance_eval_or_block_call s, &block if block
|
|
43
|
+
s
|
|
44
|
+
end
|
|
45
|
+
|
|
46
|
+
def capture= (*args)
|
|
47
|
+
set_capture CAPTURE_FLAG.symbols2bits(*args.flatten)
|
|
48
|
+
end
|
|
49
|
+
|
|
50
|
+
def capture (*args)
|
|
51
|
+
send :capture=, *args unless args.empty?
|
|
52
|
+
CAPTURE_FLAG.bits2symbols get_capture
|
|
53
|
+
end
|
|
54
|
+
|
|
55
|
+
def capturing? (*args)
|
|
56
|
+
cap = capture
|
|
57
|
+
args.all? {|type| cap.include? type}
|
|
58
|
+
end
|
|
59
|
+
|
|
60
|
+
def self.has_model ()
|
|
61
|
+
include ModelView
|
|
62
|
+
end
|
|
63
|
+
|
|
30
64
|
end# View
|
|
31
65
|
|
|
32
66
|
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
# -*- coding: utf-8 -*-
|
|
2
|
+
|
|
3
|
+
|
|
4
|
+
require 'reflex/ext'
|
|
5
|
+
|
|
6
|
+
|
|
7
|
+
module Reflex
|
|
8
|
+
|
|
9
|
+
|
|
10
|
+
class WheelEvent
|
|
11
|
+
|
|
12
|
+
def inspect ()
|
|
13
|
+
"#<Reflex::WheelEvent dx:#{dx} dy:#{dy} dz:#{dz} x:#{x} y:#{y} z:#{z} mod:#{modifiers}>"
|
|
14
|
+
end
|
|
15
|
+
|
|
16
|
+
end# WheelEvent
|
|
17
|
+
|
|
18
|
+
|
|
19
|
+
end# Reflex
|
data/lib/reflex/window.rb
CHANGED
|
@@ -2,11 +2,9 @@
|
|
|
2
2
|
|
|
3
3
|
|
|
4
4
|
require 'forwardable'
|
|
5
|
-
require 'xot/hookable'
|
|
6
5
|
require 'xot/setter'
|
|
7
6
|
require 'xot/block_util'
|
|
8
7
|
require 'reflex/ext'
|
|
9
|
-
require 'reflex/painter'
|
|
10
8
|
require 'reflex/helper'
|
|
11
9
|
|
|
12
10
|
|
|
@@ -15,14 +13,18 @@ module Reflex
|
|
|
15
13
|
|
|
16
14
|
class Window
|
|
17
15
|
|
|
18
|
-
include Xot::Hookable
|
|
19
16
|
include Xot::Setter
|
|
20
|
-
include
|
|
17
|
+
include Hookable
|
|
18
|
+
include HasFrame
|
|
21
19
|
|
|
22
20
|
extend Forwardable
|
|
23
21
|
|
|
24
22
|
def_delegators :root,
|
|
25
|
-
:
|
|
23
|
+
:add_child, :remove_child, :find_children, :style
|
|
24
|
+
|
|
25
|
+
alias add add_child
|
|
26
|
+
alias remove remove_child
|
|
27
|
+
alias find find_children
|
|
26
28
|
|
|
27
29
|
def initialize (opts = {}, &block)
|
|
28
30
|
super()
|
data/lib/reflex.rb
CHANGED
|
@@ -3,9 +3,46 @@
|
|
|
3
3
|
|
|
4
4
|
require 'reflex/autoinit'
|
|
5
5
|
require 'reflex/module'
|
|
6
|
+
|
|
7
|
+
require 'reflex/point'
|
|
8
|
+
require 'reflex/bounds'
|
|
9
|
+
require 'reflex/color'
|
|
10
|
+
require 'reflex/color_space'
|
|
11
|
+
require 'reflex/bitmap'
|
|
12
|
+
require 'reflex/texture'
|
|
13
|
+
require 'reflex/image'
|
|
14
|
+
require 'reflex/font'
|
|
15
|
+
require 'reflex/shader'
|
|
16
|
+
require 'reflex/painter'
|
|
17
|
+
|
|
6
18
|
require 'reflex/reflex'
|
|
19
|
+
require 'reflex/helper'
|
|
7
20
|
require 'reflex/application'
|
|
8
21
|
require 'reflex/window'
|
|
9
22
|
require 'reflex/view'
|
|
23
|
+
require 'reflex/selector'
|
|
24
|
+
require 'reflex/shape'
|
|
25
|
+
require 'reflex/line_shape'
|
|
26
|
+
require 'reflex/rect_shape'
|
|
27
|
+
require 'reflex/ellipse_shape'
|
|
28
|
+
require 'reflex/arc_shape'
|
|
29
|
+
require 'reflex/model'
|
|
30
|
+
require 'reflex/model_owner'
|
|
31
|
+
require 'reflex/selector'
|
|
32
|
+
require 'reflex/style'
|
|
33
|
+
require 'reflex/style_length'
|
|
34
|
+
require 'reflex/style_length2'
|
|
35
|
+
require 'reflex/style_length4'
|
|
36
|
+
require 'reflex/update_event'
|
|
37
|
+
require 'reflex/draw_event'
|
|
38
|
+
require 'reflex/frame_event'
|
|
39
|
+
require 'reflex/scroll_event'
|
|
40
|
+
require 'reflex/focus_event'
|
|
41
|
+
require 'reflex/key_event'
|
|
42
|
+
require 'reflex/pointer_event'
|
|
43
|
+
require 'reflex/wheel_event'
|
|
44
|
+
require 'reflex/capture_event'
|
|
10
45
|
|
|
11
|
-
require 'reflex/
|
|
46
|
+
require 'reflex/button'
|
|
47
|
+
require 'reflex/text_view'
|
|
48
|
+
require 'reflex/image_view'
|
data/lib/reflexion.rb
ADDED
|
@@ -0,0 +1,100 @@
|
|
|
1
|
+
# -*- coding: utf-8 -*-
|
|
2
|
+
|
|
3
|
+
|
|
4
|
+
require 'rays'
|
|
5
|
+
require 'reflex'
|
|
6
|
+
|
|
7
|
+
|
|
8
|
+
module Reflexion
|
|
9
|
+
|
|
10
|
+
|
|
11
|
+
include Rays, Reflex
|
|
12
|
+
|
|
13
|
+
|
|
14
|
+
DEFAULTS = {
|
|
15
|
+
title: 'Reflexion',
|
|
16
|
+
frame: [100, 100, 512, 512]
|
|
17
|
+
}
|
|
18
|
+
|
|
19
|
+
|
|
20
|
+
class Screen < Window
|
|
21
|
+
|
|
22
|
+
attr_accessor :update, :draw, :key, :pointer
|
|
23
|
+
|
|
24
|
+
attr_reader :setup
|
|
25
|
+
|
|
26
|
+
def setup= (block)
|
|
27
|
+
@setup = block
|
|
28
|
+
call_block self, &@setup
|
|
29
|
+
end
|
|
30
|
+
|
|
31
|
+
def on_update (e)
|
|
32
|
+
super
|
|
33
|
+
redraw
|
|
34
|
+
call_block e, &@update
|
|
35
|
+
end
|
|
36
|
+
|
|
37
|
+
def on_draw (e)
|
|
38
|
+
super
|
|
39
|
+
call_block e, &@draw
|
|
40
|
+
end
|
|
41
|
+
|
|
42
|
+
def on_key (e)
|
|
43
|
+
super
|
|
44
|
+
call_block e, &@key
|
|
45
|
+
end
|
|
46
|
+
|
|
47
|
+
def on_pointer (e)
|
|
48
|
+
super
|
|
49
|
+
call_block e, &@pointer
|
|
50
|
+
end
|
|
51
|
+
|
|
52
|
+
def call_block (*args, &block)
|
|
53
|
+
Xot::BlockUtil.instance_eval_or_block_call *args, &block if block
|
|
54
|
+
end
|
|
55
|
+
|
|
56
|
+
end# Screen
|
|
57
|
+
|
|
58
|
+
|
|
59
|
+
module_function
|
|
60
|
+
|
|
61
|
+
@@screen = Screen.new DEFAULTS
|
|
62
|
+
|
|
63
|
+
def screen ()
|
|
64
|
+
@@screen
|
|
65
|
+
end
|
|
66
|
+
|
|
67
|
+
def setup (&block)
|
|
68
|
+
screen.setup = block
|
|
69
|
+
end
|
|
70
|
+
|
|
71
|
+
def update (&block)
|
|
72
|
+
screen.update = block
|
|
73
|
+
end
|
|
74
|
+
|
|
75
|
+
def draw (&block)
|
|
76
|
+
screen.draw = block
|
|
77
|
+
end
|
|
78
|
+
|
|
79
|
+
def key (&block)
|
|
80
|
+
screen.key = block
|
|
81
|
+
end
|
|
82
|
+
|
|
83
|
+
def pointer (&block)
|
|
84
|
+
screen.pointer = block
|
|
85
|
+
end
|
|
86
|
+
|
|
87
|
+
def start ()
|
|
88
|
+
screen.show
|
|
89
|
+
Reflex.start
|
|
90
|
+
end
|
|
91
|
+
|
|
92
|
+
def quit ()
|
|
93
|
+
screen.close
|
|
94
|
+
end
|
|
95
|
+
|
|
96
|
+
|
|
97
|
+
end# Reflexion
|
|
98
|
+
|
|
99
|
+
|
|
100
|
+
at_exit {Reflexion.start}
|
data/reflex.gemspec
CHANGED
|
@@ -1,9 +1,8 @@
|
|
|
1
1
|
# -*- mode: ruby; coding: utf-8 -*-
|
|
2
2
|
|
|
3
3
|
|
|
4
|
-
|
|
5
|
-
$:.unshift
|
|
6
|
-
end
|
|
4
|
+
File.expand_path('../lib', __FILE__)
|
|
5
|
+
.tap {|s| $:.unshift s if !$:.include?(s) && File.directory?(s)}
|
|
7
6
|
|
|
8
7
|
require 'reflex/module'
|
|
9
8
|
|
|
@@ -13,7 +12,7 @@ Gem::Specification.new do |s|
|
|
|
13
12
|
patterns.map {|pat| Dir.glob(pat).to_a}.flatten
|
|
14
13
|
end
|
|
15
14
|
|
|
16
|
-
mod = Reflex
|
|
15
|
+
mod = Reflex::Module
|
|
17
16
|
name = mod.name.downcase
|
|
18
17
|
rdocs = glob.call *%w[README .doc/ext/**/*.cpp]
|
|
19
18
|
|
data/samples/app.rb
ADDED
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
# -*- coding: utf-8 -*-
|
|
2
|
+
|
|
3
|
+
|
|
4
|
+
%w[xot rays reflex]
|
|
5
|
+
.map {|s| File.expand_path "../../../#{s}/lib", __FILE__}
|
|
6
|
+
.each {|s| $:.unshift s if !$:.include?(s) && File.directory?(s)}
|
|
7
|
+
|
|
8
|
+
require 'reflex'
|
|
9
|
+
|
|
10
|
+
|
|
11
|
+
Reflex.start name: "AppName" do |app|
|
|
12
|
+
Reflex::Window.new(:title => app.name, :frame => [100, 100, 500, 500]).show
|
|
13
|
+
end
|
data/samples/bats.rb
ADDED
|
@@ -0,0 +1,91 @@
|
|
|
1
|
+
# -*- coding: utf-8 -*-
|
|
2
|
+
|
|
3
|
+
|
|
4
|
+
%w[xot rays reflex]
|
|
5
|
+
.map {|s| File.expand_path "../../../#{s}/lib", __FILE__}
|
|
6
|
+
.each {|s| $:.unshift s if !$:.include?(s) && File.directory?(s)}
|
|
7
|
+
|
|
8
|
+
require 'reflex'
|
|
9
|
+
|
|
10
|
+
|
|
11
|
+
Reflex::Window.new do
|
|
12
|
+
set title: "Bats", frame: [100, 100, 300, 300]
|
|
13
|
+
|
|
14
|
+
@children = []
|
|
15
|
+
@count = model = Reflex::Model.new(@children.size) {set min: 0}
|
|
16
|
+
|
|
17
|
+
def update_count ()
|
|
18
|
+
@count.data = @children.size
|
|
19
|
+
end
|
|
20
|
+
|
|
21
|
+
def spawn (x, y)
|
|
22
|
+
name = "bat_#{@count.data}"
|
|
23
|
+
@children.push add Reflex::View.new {
|
|
24
|
+
size = 16
|
|
25
|
+
set name: name, frame: [x - size, y - size, size * 2, size * 2]
|
|
26
|
+
|
|
27
|
+
angle = 0
|
|
28
|
+
speed = (rand * 2 - 1) * 30
|
|
29
|
+
|
|
30
|
+
on :update do
|
|
31
|
+
move_by rand(5) - 2, rand(5) - 2
|
|
32
|
+
angle += speed
|
|
33
|
+
angle %= 360
|
|
34
|
+
redraw
|
|
35
|
+
end
|
|
36
|
+
|
|
37
|
+
c = [rand, rand, rand]
|
|
38
|
+
on :draw do |e|
|
|
39
|
+
p, b = e.painter, e.bounds
|
|
40
|
+
p.fill *c
|
|
41
|
+
#p.rect *b.to_a
|
|
42
|
+
p.arc *b.to_a, angle, angle + 90
|
|
43
|
+
p.arc *b.to_a, angle + 180, angle + 270
|
|
44
|
+
end
|
|
45
|
+
}
|
|
46
|
+
update_count
|
|
47
|
+
end
|
|
48
|
+
|
|
49
|
+
on :key_down do |e|
|
|
50
|
+
case e.code
|
|
51
|
+
when 53 then close
|
|
52
|
+
end
|
|
53
|
+
|
|
54
|
+
case e.chars
|
|
55
|
+
when 'g'
|
|
56
|
+
GC.start
|
|
57
|
+
puts 'GC!'
|
|
58
|
+
when 'x'
|
|
59
|
+
remove @children.shift unless @children.empty?
|
|
60
|
+
update_count
|
|
61
|
+
end
|
|
62
|
+
end
|
|
63
|
+
|
|
64
|
+
on :pointer do |e|
|
|
65
|
+
case e.type
|
|
66
|
+
when :down
|
|
67
|
+
spawn e.x, e.y
|
|
68
|
+
@spawning = true
|
|
69
|
+
when :up
|
|
70
|
+
@spawning = false
|
|
71
|
+
when :move
|
|
72
|
+
spawn e.x, e.y if @spawning
|
|
73
|
+
end
|
|
74
|
+
end
|
|
75
|
+
|
|
76
|
+
add Reflex::TextView.new {
|
|
77
|
+
set name: :count, pos: [10, 10], model: model
|
|
78
|
+
}
|
|
79
|
+
|
|
80
|
+
root.on :draw do |e|
|
|
81
|
+
p = e.painter
|
|
82
|
+
p.fill 1
|
|
83
|
+
p.text "draw on root view.", 10, 30
|
|
84
|
+
end
|
|
85
|
+
|
|
86
|
+
#100.times {spawn *frame.move_to(0).center.to_a}
|
|
87
|
+
show
|
|
88
|
+
end
|
|
89
|
+
|
|
90
|
+
|
|
91
|
+
Reflex.start
|
data/samples/checker.rb
ADDED
|
@@ -0,0 +1,36 @@
|
|
|
1
|
+
# -*- coding: utf-8 -*-
|
|
2
|
+
|
|
3
|
+
|
|
4
|
+
%w[xot rays reflex]
|
|
5
|
+
.map {|s| File.expand_path "../../../#{s}/lib", __FILE__}
|
|
6
|
+
.each {|s| $:.unshift s if !$:.include?(s) && File.directory?(s)}
|
|
7
|
+
|
|
8
|
+
require 'reflex'
|
|
9
|
+
|
|
10
|
+
|
|
11
|
+
class CheckerWindow < Reflex::Window
|
|
12
|
+
|
|
13
|
+
def initialize ()
|
|
14
|
+
super
|
|
15
|
+
set :title, "Hello Reflex!"
|
|
16
|
+
set :frame, 100, 100, 320, 240
|
|
17
|
+
painter.font = Rays::Font.new nil, 32
|
|
18
|
+
painter.background = 1
|
|
19
|
+
end
|
|
20
|
+
|
|
21
|
+
def on_draw (e)
|
|
22
|
+
p, size, count = e.painter, 10, 16
|
|
23
|
+
count.times do |x|
|
|
24
|
+
count.times do |y|
|
|
25
|
+
next if (x + y) % 2 == 0
|
|
26
|
+
p.fill = x.to_f / count, y.to_f / count, 1
|
|
27
|
+
p.rect x * size, y * size, size - 1, size - 1
|
|
28
|
+
end
|
|
29
|
+
end
|
|
30
|
+
end
|
|
31
|
+
|
|
32
|
+
end# CheckerWindow
|
|
33
|
+
|
|
34
|
+
|
|
35
|
+
CheckerWindow.new.show
|
|
36
|
+
Reflex.start
|
|
@@ -1,12 +1,10 @@
|
|
|
1
1
|
# -*- coding: utf-8 -*-
|
|
2
2
|
|
|
3
3
|
|
|
4
|
-
%w[xot rays reflex]
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
end
|
|
4
|
+
%w[xot rays reflex]
|
|
5
|
+
.map {|s| File.expand_path "../../../#{s}/lib", __FILE__}
|
|
6
|
+
.each {|s| $:.unshift s if !$:.include?(s) && File.directory?(s)}
|
|
8
7
|
|
|
9
|
-
require 'rubygems'
|
|
10
8
|
require 'reflex'
|
|
11
9
|
|
|
12
10
|
|
|
@@ -47,7 +45,7 @@ class Ring
|
|
|
47
45
|
x, y, width, height, colors, rotation, 0, 0
|
|
48
46
|
end
|
|
49
47
|
|
|
50
|
-
def
|
|
48
|
+
def on_draw (p)
|
|
51
49
|
w = 45
|
|
52
50
|
p.fill = *@colors[0]
|
|
53
51
|
fin p, 0, w
|
|
@@ -57,7 +55,7 @@ class Ring
|
|
|
57
55
|
fin p, 270, w
|
|
58
56
|
end
|
|
59
57
|
|
|
60
|
-
def
|
|
58
|
+
def on_update (dt)
|
|
61
59
|
@angle = (@angle + @rot) % 360
|
|
62
60
|
end
|
|
63
61
|
|
|
@@ -77,7 +75,7 @@ class ShapesWindow < Reflex::Window
|
|
|
77
75
|
def initialize ()
|
|
78
76
|
super
|
|
79
77
|
set :title, "Shapes Sample"
|
|
80
|
-
set :
|
|
78
|
+
set :frame, 100, 400, 640, 240
|
|
81
79
|
painter.background = 1
|
|
82
80
|
@rings = []
|
|
83
81
|
setup
|
|
@@ -95,21 +93,19 @@ class ShapesWindow < Reflex::Window
|
|
|
95
93
|
end
|
|
96
94
|
end
|
|
97
95
|
|
|
98
|
-
def
|
|
99
|
-
|
|
100
|
-
each {|o| o.draw p}
|
|
101
|
-
end
|
|
96
|
+
def on_draw (e)
|
|
97
|
+
each {|o| o.on_draw e.painter}
|
|
102
98
|
end
|
|
103
99
|
|
|
104
|
-
def
|
|
105
|
-
each {|o| o.
|
|
100
|
+
def on_update (dt)
|
|
101
|
+
each {|o| o.on_update dt}
|
|
106
102
|
redraw
|
|
107
103
|
@count ||= 0
|
|
108
104
|
fps_ = fps
|
|
109
105
|
#puts "#{fps_} FPS, GC count: #{GC.stat[:count]}" if (@count += 1) % 100 == 0
|
|
110
106
|
end
|
|
111
107
|
|
|
112
|
-
def
|
|
108
|
+
def on_key_down (key)
|
|
113
109
|
close if key.code == 53 || key.chars =~ /q/i
|
|
114
110
|
end
|
|
115
111
|
|
|
@@ -121,4 +117,4 @@ end# ShapesWindow
|
|
|
121
117
|
|
|
122
118
|
|
|
123
119
|
ShapesWindow.new.show
|
|
124
|
-
Reflex.
|
|
120
|
+
Reflex.start name: "Shapes"
|
data/samples/fps.rb
ADDED
|
@@ -0,0 +1,46 @@
|
|
|
1
|
+
# -*- coding: utf-8 -*-
|
|
2
|
+
|
|
3
|
+
|
|
4
|
+
%w[xot rays reflex]
|
|
5
|
+
.map {|s| File.expand_path "../../../#{s}/lib", __FILE__}
|
|
6
|
+
.each {|s| $:.unshift s if !$:.include?(s) && File.directory?(s)}
|
|
7
|
+
|
|
8
|
+
require 'reflex'
|
|
9
|
+
|
|
10
|
+
|
|
11
|
+
x = 0
|
|
12
|
+
y = 0
|
|
13
|
+
font = Rays::Font.new "Osaka", 32
|
|
14
|
+
prev = Time.now
|
|
15
|
+
fps = 0
|
|
16
|
+
|
|
17
|
+
w = Reflex::Window
|
|
18
|
+
.new(:title => "Reflex on Ruby", :frame => [100, 100, 600, 400])
|
|
19
|
+
.before(:close) {w.hide; sleep 1; w.show; sleep 1}
|
|
20
|
+
.on(:move) {|x, y| p [x, y]}
|
|
21
|
+
.on(:resize) {|w, h| p [w, h]}
|
|
22
|
+
.on(:update) {w.redraw}
|
|
23
|
+
.on(:draw) do |e|
|
|
24
|
+
p, sz = e.painter, w.frame.size
|
|
25
|
+
p.fill = 1, 0.5, 0.5, 0.05
|
|
26
|
+
#p.stroke = 0.5, 0.5, 1
|
|
27
|
+
100.times do
|
|
28
|
+
n = rand * Math::PI * 2
|
|
29
|
+
xx = x + Math.sin(n) * 50
|
|
30
|
+
yy = y + Math.cos(n) * 50
|
|
31
|
+
p.rect xx, yy, 50, 50
|
|
32
|
+
end
|
|
33
|
+
p.fill = 1
|
|
34
|
+
p.text "hello Rays/Reflex!", x, y + 32, font
|
|
35
|
+
x = (x + 1) % 100
|
|
36
|
+
y = (y + 1) % 100
|
|
37
|
+
|
|
38
|
+
now = Time.now
|
|
39
|
+
fps = 1 / (now - prev) if x % 10 == 0
|
|
40
|
+
p.fill = 1, 1, 1, 1
|
|
41
|
+
p.text "#{fps.to_i} FPS", 0, sz.y - font.height, font
|
|
42
|
+
prev = now
|
|
43
|
+
end
|
|
44
|
+
|
|
45
|
+
w.show
|
|
46
|
+
Reflex.start
|
data/samples/grid.rb
ADDED
|
@@ -0,0 +1,60 @@
|
|
|
1
|
+
# -*- coding: utf-8 -*-
|
|
2
|
+
|
|
3
|
+
|
|
4
|
+
%w[xot rays reflex]
|
|
5
|
+
.map {|s| File.expand_path "../../../#{s}/lib", __FILE__}
|
|
6
|
+
.each {|s| $:.unshift s if !$:.include?(s) && File.directory?(s)}
|
|
7
|
+
|
|
8
|
+
require 'reflex'
|
|
9
|
+
|
|
10
|
+
|
|
11
|
+
Reflex::Window.new do
|
|
12
|
+
set title: "Grid Test", frame: [100, 100, 50, 50]
|
|
13
|
+
painter.background 0
|
|
14
|
+
|
|
15
|
+
on :draw do |e|
|
|
16
|
+
p = e.painter
|
|
17
|
+
p.push
|
|
18
|
+
|
|
19
|
+
w, h = frame.size.to_a
|
|
20
|
+
|
|
21
|
+
p.fill 1, 0, 0
|
|
22
|
+
|
|
23
|
+
p.rect 1, 1, 5, 5
|
|
24
|
+
|
|
25
|
+
p.stroke 0.3, 0.4
|
|
26
|
+
(0..frame.width) .step(2).each {|x| p.line x, 0, x, h}
|
|
27
|
+
(0..frame.height).step(2).each {|y| p.line 0, y, w, y}
|
|
28
|
+
p.stroke 0.5, 0.4
|
|
29
|
+
(0..frame.width) .step(10).each {|x| p.line x, 0, x, h}
|
|
30
|
+
(0..frame.height).step(10).each {|y| p.line 0, y, w, y}
|
|
31
|
+
|
|
32
|
+
p.translate 3, 10, 0
|
|
33
|
+
p.fill nil
|
|
34
|
+
p.stroke 1
|
|
35
|
+
|
|
36
|
+
p.line 0, 0, 5, 0
|
|
37
|
+
|
|
38
|
+
p.translate 0, 10, 0
|
|
39
|
+
|
|
40
|
+
p.rect 0, 0, 5, 5
|
|
41
|
+
|
|
42
|
+
p.translate 0, 10, 0
|
|
43
|
+
p.fill 0.5, 0.5, 1
|
|
44
|
+
p.stroke nil
|
|
45
|
+
|
|
46
|
+
p.rect 0, 0, 5, 5
|
|
47
|
+
|
|
48
|
+
p.translate 0, 10, 0
|
|
49
|
+
p.fill 0.5, 0.5, 1
|
|
50
|
+
p.stroke 0.5, 1, 0.5
|
|
51
|
+
|
|
52
|
+
p.rect 0, 0, 5, 5
|
|
53
|
+
|
|
54
|
+
p.pop
|
|
55
|
+
end
|
|
56
|
+
|
|
57
|
+
show
|
|
58
|
+
end
|
|
59
|
+
|
|
60
|
+
Reflex.start
|