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.
Files changed (225) hide show
  1. checksums.yaml +7 -0
  2. data/.doc/ext/reflex/application.cpp +54 -39
  3. data/.doc/ext/reflex/capture_event.cpp +87 -0
  4. data/.doc/ext/reflex/draw_event.cpp +103 -0
  5. data/.doc/ext/reflex/event.cpp +73 -0
  6. data/.doc/ext/reflex/focus_event.cpp +98 -0
  7. data/.doc/ext/reflex/frame_event.cpp +133 -0
  8. data/.doc/ext/reflex/image_view.cpp +74 -0
  9. data/.doc/ext/reflex/key_event.cpp +124 -0
  10. data/.doc/ext/reflex/native.cpp +45 -6
  11. data/.doc/ext/reflex/pointer_event.cpp +181 -0
  12. data/.doc/ext/reflex/reflex.cpp +17 -41
  13. data/.doc/ext/reflex/scroll_event.cpp +141 -0
  14. data/.doc/ext/reflex/selector.cpp +135 -0
  15. data/.doc/ext/reflex/style.cpp +253 -0
  16. data/.doc/ext/reflex/style_length.cpp +133 -0
  17. data/.doc/ext/reflex/style_length2.cpp +149 -0
  18. data/.doc/ext/reflex/style_length4.cpp +192 -0
  19. data/.doc/ext/reflex/update_event.cpp +77 -0
  20. data/.doc/ext/reflex/view.cpp +408 -88
  21. data/.doc/ext/reflex/wheel_event.cpp +146 -0
  22. data/.doc/ext/reflex/window.cpp +95 -92
  23. data/Rakefile +6 -5
  24. data/VERSION +1 -1
  25. data/ext/reflex/application.cpp +67 -49
  26. data/ext/reflex/capture_event.cpp +92 -0
  27. data/ext/reflex/draw_event.cpp +110 -0
  28. data/ext/reflex/event.cpp +77 -0
  29. data/ext/reflex/extconf.rb +18 -68
  30. data/ext/reflex/focus_event.cpp +104 -0
  31. data/ext/reflex/frame_event.cpp +143 -0
  32. data/ext/reflex/image_view.cpp +77 -0
  33. data/ext/reflex/key_event.cpp +133 -0
  34. data/ext/reflex/native.cpp +45 -6
  35. data/ext/reflex/pointer_event.cpp +195 -0
  36. data/ext/reflex/reflex.cpp +21 -47
  37. data/ext/reflex/scroll_event.cpp +152 -0
  38. data/ext/reflex/selector.cpp +144 -0
  39. data/ext/reflex/style.cpp +277 -0
  40. data/ext/reflex/style_length.cpp +140 -0
  41. data/ext/reflex/style_length2.cpp +157 -0
  42. data/ext/reflex/style_length4.cpp +204 -0
  43. data/ext/reflex/update_event.cpp +81 -0
  44. data/ext/reflex/view.cpp +469 -114
  45. data/ext/reflex/wheel_event.cpp +158 -0
  46. data/ext/reflex/window.cpp +130 -123
  47. data/include/reflex/application.h +12 -7
  48. data/include/reflex/defs.h +13 -89
  49. data/include/reflex/event.h +260 -0
  50. data/include/reflex/exception.h +17 -11
  51. data/include/reflex/image_view.h +45 -0
  52. data/include/reflex/reflex.h +2 -6
  53. data/include/reflex/ruby/application.h +40 -13
  54. data/include/reflex/ruby/event.h +72 -0
  55. data/include/reflex/ruby/image_view.h +25 -0
  56. data/include/reflex/ruby/selector.h +27 -0
  57. data/include/reflex/ruby/style.h +27 -0
  58. data/include/reflex/ruby/style_length.h +37 -0
  59. data/include/reflex/ruby/view.h +193 -38
  60. data/include/reflex/ruby/window.h +123 -39
  61. data/include/reflex/ruby.h +3 -2
  62. data/include/reflex/selector.h +64 -0
  63. data/include/reflex/style.h +144 -0
  64. data/include/reflex/style_length.h +147 -0
  65. data/include/reflex/view.h +182 -19
  66. data/include/reflex/window.h +35 -19
  67. data/include/reflex.h +7 -0
  68. data/lib/reflex/application.rb +14 -5
  69. data/lib/reflex/arc_shape.rb +20 -0
  70. data/lib/reflex/button.rb +75 -0
  71. data/lib/reflex/capture_event.rb +37 -0
  72. data/lib/reflex/color.rb +13 -0
  73. data/lib/reflex/color_space.rb +13 -0
  74. data/lib/reflex/draw_event.rb +19 -0
  75. data/lib/reflex/ellipse_shape.rb +20 -0
  76. data/lib/reflex/ext.rb +1 -1
  77. data/lib/reflex/flags.rb +18 -0
  78. data/lib/reflex/focus_event.rb +38 -0
  79. data/lib/reflex/font.rb +13 -0
  80. data/lib/reflex/frame_event.rb +42 -0
  81. data/lib/reflex/helper.rb +87 -30
  82. data/lib/reflex/image_view.rb +25 -0
  83. data/lib/reflex/key_event.rb +38 -0
  84. data/lib/reflex/line_shape.rb +20 -0
  85. data/lib/reflex/list_view.rb +15 -0
  86. data/lib/reflex/model.rb +149 -0
  87. data/lib/reflex/model_owner.rb +57 -0
  88. data/lib/reflex/model_view.rb +22 -0
  89. data/lib/reflex/module.rb +11 -7
  90. data/lib/reflex/pointer_event.rb +85 -0
  91. data/lib/reflex/rect_shape.rb +20 -0
  92. data/lib/reflex/reflex.rb +13 -2
  93. data/lib/reflex/scroll_event.rb +19 -0
  94. data/lib/reflex/selector.rb +31 -0
  95. data/lib/reflex/shader.rb +13 -0
  96. data/lib/reflex/shape.rb +34 -0
  97. data/lib/reflex/style.rb +55 -0
  98. data/lib/reflex/style_length.rb +30 -0
  99. data/lib/reflex/style_length2.rb +34 -0
  100. data/lib/reflex/style_length4.rb +38 -0
  101. data/lib/reflex/text_view.rb +55 -0
  102. data/lib/reflex/update_event.rb +19 -0
  103. data/lib/reflex/view.rb +38 -4
  104. data/lib/reflex/wheel_event.rb +19 -0
  105. data/lib/reflex/window.rb +7 -5
  106. data/lib/reflex.rb +38 -1
  107. data/lib/reflexion/include.rb +5 -0
  108. data/lib/reflexion.rb +100 -0
  109. data/reflex.gemspec +3 -4
  110. data/samples/app.rb +13 -0
  111. data/samples/bats.rb +91 -0
  112. data/samples/checker.rb +36 -0
  113. data/{examples/ruby/shapes.rb → samples/fans.rb} +12 -16
  114. data/samples/fps.rb +46 -0
  115. data/samples/grid.rb +60 -0
  116. data/{examples/ruby → samples}/hello.rb +14 -16
  117. data/samples/image.rb +44 -0
  118. data/samples/ios/hello/hello/Images.xcassets/AppIcon.appiconset/Contents.json +53 -0
  119. data/samples/ios/hello/hello/Images.xcassets/LaunchImage.launchimage/Contents.json +51 -0
  120. data/samples/ios/hello/hello/en.lproj/InfoPlist.strings +2 -0
  121. data/samples/ios/hello/hello/hello-Info.plist +47 -0
  122. data/samples/ios/hello/hello/hello-Prefix.pch +10 -0
  123. data/samples/ios/hello/hello/main.cpp +79 -0
  124. data/samples/ios/hello/hello.xcodeproj/project.pbxproj +725 -0
  125. data/{examples/ruby → samples}/key.rb +11 -14
  126. data/samples/layout.rb +89 -0
  127. data/samples/model.rb +86 -0
  128. data/samples/osx/hello/hello/Images.xcassets/AppIcon.appiconset/Contents.json +58 -0
  129. data/samples/osx/hello/hello/en.lproj/Credits.rtf +29 -0
  130. data/samples/osx/hello/hello/en.lproj/InfoPlist.strings +2 -0
  131. data/samples/osx/hello/hello/hello-Info.plist +32 -0
  132. data/samples/osx/hello/hello/hello-Prefix.pch +3 -0
  133. data/samples/osx/hello/hello/main.cpp +79 -0
  134. data/samples/osx/hello/hello.xcodeproj/project.pbxproj +725 -0
  135. data/samples/reflexion/hello.rb +24 -0
  136. data/samples/reflexion/paint.rb +40 -0
  137. data/samples/reflexion/pulse.rb +34 -0
  138. data/samples/repl.rb +69 -0
  139. data/samples/shader.rb +41 -0
  140. data/samples/shapes.rb +30 -0
  141. data/{examples/ruby → samples}/text.rb +7 -8
  142. data/samples/tree.rb +71 -0
  143. data/samples/views.rb +41 -0
  144. data/samples/visuals.rb +22 -0
  145. data/src/event.cpp +225 -0
  146. data/src/exception.cpp +24 -15
  147. data/src/image_view.cpp +70 -0
  148. data/src/ios/app_delegate.h +17 -0
  149. data/src/ios/app_delegate.mm +120 -0
  150. data/src/ios/application.mm +116 -0
  151. data/src/{cocoa/applicationdata.h → ios/application_data.h} +6 -6
  152. data/src/ios/event.h +26 -0
  153. data/src/ios/event.mm +31 -0
  154. data/src/ios/native_window.h +37 -0
  155. data/src/ios/native_window.mm +220 -0
  156. data/src/ios/opengl_view.h +13 -0
  157. data/src/ios/opengl_view.mm +131 -0
  158. data/src/{cocoa → ios}/reflex.mm +8 -12
  159. data/src/ios/window.mm +303 -0
  160. data/src/ios/window_data.h +75 -0
  161. data/src/osx/app_delegate.h +17 -0
  162. data/src/{cocoa/cocoaapplication.mm → osx/app_delegate.mm} +90 -48
  163. data/src/osx/application.mm +132 -0
  164. data/src/osx/application_data.h +45 -0
  165. data/src/osx/event.h +42 -0
  166. data/src/osx/event.mm +112 -0
  167. data/src/osx/native_window.h +26 -0
  168. data/src/osx/native_window.mm +322 -0
  169. data/src/{cocoa/openglview.h → osx/opengl_view.h} +0 -4
  170. data/src/{cocoa/openglview.mm → osx/opengl_view.mm} +66 -23
  171. data/src/osx/reflex.mm +50 -0
  172. data/src/osx/window.mm +308 -0
  173. data/src/osx/window_data.h +75 -0
  174. data/src/selector.cpp +121 -0
  175. data/src/style.cpp +576 -0
  176. data/src/style_length.cpp +341 -0
  177. data/src/view.cpp +1228 -129
  178. data/src/win32/application.cpp +1 -1
  179. data/src/window.cpp +54 -26
  180. data/test/helper.rb +8 -4
  181. data/test/test_capture_event.rb +41 -0
  182. data/test/test_event.rb +20 -0
  183. data/test/test_has_frame.rb +45 -0
  184. data/test/test_model.rb +9 -0
  185. data/test/test_model_owner.rb +9 -0
  186. data/test/test_selector.rb +75 -0
  187. data/test/test_style.rb +70 -0
  188. data/test/test_style_length.rb +38 -0
  189. data/test/test_style_length2.rb +50 -0
  190. data/test/test_style_length4.rb +56 -0
  191. data/test/test_view.rb +97 -23
  192. data/test/test_window.rb +54 -46
  193. metadata +205 -84
  194. data/.doc/ext/reflex/defs.cpp +0 -8
  195. data/.doc/ext/reflex/key.cpp +0 -122
  196. data/.doc/ext/reflex/points.cpp +0 -151
  197. data/.gitignore +0 -14
  198. data/ChangeLog +0 -8
  199. data/examples/hello/.gitignore +0 -2
  200. data/examples/hello/Rakefile +0 -41
  201. data/examples/hello/main.cpp +0 -18
  202. data/examples/ruby/app.rb +0 -13
  203. data/examples/ruby/checker.rb +0 -41
  204. data/examples/ruby/fps.rb +0 -49
  205. data/examples/ruby/grid.rb +0 -65
  206. data/examples/ruby/views.rb +0 -88
  207. data/examples/ruby/visuals.rb +0 -27
  208. data/ext/reflex/defs.cpp +0 -8
  209. data/ext/reflex/key.cpp +0 -129
  210. data/ext/reflex/points.cpp +0 -161
  211. data/include/reflex/ruby/key.h +0 -39
  212. data/include/reflex/ruby/points.h +0 -39
  213. data/lib/reflex/visuals/string.rb +0 -53
  214. data/src/cocoa/application.mm +0 -101
  215. data/src/cocoa/cocoaapplication.h +0 -21
  216. data/src/cocoa/cocoawindow.h +0 -46
  217. data/src/cocoa/cocoawindow.mm +0 -230
  218. data/src/cocoa/defs.h +0 -34
  219. data/src/cocoa/defs.mm +0 -87
  220. data/src/cocoa/window.mm +0 -148
  221. data/src/cocoa/windowdata.h +0 -56
  222. data/src/defs.cpp +0 -47
  223. data/src/helper.h +0 -12
  224. data/src/reflex.cpp +0 -43
  225. /data/{README → README.md} +0 -0
@@ -0,0 +1,24 @@
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 'reflexion/include'
9
+
10
+
11
+ gray = 0
12
+ array = []
13
+
14
+ draw do
15
+ gray += 0.01
16
+ gray %= 1
17
+ painter.tap do |p|
18
+ p.background gray, gray, gray
19
+ array.unshift fps
20
+ array.slice! 32..-1
21
+ p.text "#{array.reduce(0) {|sum, n| sum + n}.tap {|n| break n / array.size}.to_i} FPS", 10, 30
22
+ p.text "#{fps} FPS", 10, 10
23
+ end
24
+ end
@@ -0,0 +1,40 @@
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 'reflexion/include'
9
+
10
+
11
+ FILENAME = 'paint.png'
12
+
13
+ canvas = Image.load(FILENAME) rescue nil || Image.new(512, 512).paint {
14
+ background :white
15
+ clear
16
+ }
17
+
18
+ setup do
19
+ size canvas.size
20
+ end
21
+
22
+ draw do
23
+ painter.image canvas
24
+ end
25
+
26
+ pointer do |e|
27
+ if e.down? || e.drag?
28
+ canvas.paint do
29
+ fill e.left? ? :red : e.right? ? :blue : :white
30
+ ellipse e.x - 10, e.y - 10, 20, 20
31
+ end
32
+ end
33
+ end
34
+
35
+ key do |e|
36
+ case e.chars
37
+ when /s/i then canvas.save FILENAME
38
+ when /q/i, "\e" then quit
39
+ end
40
+ end
@@ -0,0 +1,34 @@
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 'reflexion/include'
9
+
10
+
11
+ frame = 0
12
+ fps = 0
13
+
14
+
15
+ setup do
16
+ set width: 600, height: 300
17
+ painter.font = Font.new nil, 24
18
+ end
19
+
20
+ draw do |e|
21
+ frame += 1
22
+ fps = e.fps.to_i if (frame % 5) == 0
23
+ e.painter.text "#{fps} FPS | FRAME: #{frame}", 10, 10
24
+ end
25
+
26
+ key do |e|
27
+ quit if e.chars == 'q' || e.code == 53
28
+ end
29
+
30
+ pointer do |e|
31
+ if e.down? || e.drag?
32
+ window.add EllipseShape.new {set frame: [e.x - 10, e.y - 10, 20, 20], color: :red}
33
+ end
34
+ end
data/samples/repl.rb ADDED
@@ -0,0 +1,69 @@
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 'thread'
9
+ require 'reflex'
10
+
11
+
12
+ class Channel
13
+
14
+ def initialize ()
15
+ @c2s, @s2c = Queue.new, Queue.new
16
+ end
17
+
18
+ def send (obj, async = false)
19
+ @c2s.push obj
20
+ async ? obj : @s2c.pop
21
+ end
22
+
23
+ def receive ()
24
+ @s2c.pop
25
+ end
26
+
27
+ def process ()
28
+ reply eval @c2s.pop(true)
29
+ rescue ThreadError
30
+ rescue => e
31
+ reply e.backtrace
32
+ end
33
+
34
+ def reply (obj)
35
+ @s2c.push obj
36
+ end
37
+
38
+ end# Channel
39
+
40
+
41
+ class PrimaryWindow < Reflex::Window
42
+
43
+ attr_reader :channel
44
+
45
+ def initialize ()
46
+ super
47
+ set :title, "Reflex/REPL"
48
+ set :frame, 100, 100, 320, 240
49
+
50
+ @channel = Channel.new
51
+
52
+ Thread.new do
53
+ loop do
54
+ print '> '
55
+ puts @channel.send(gets).inspect
56
+ end
57
+ end
58
+ end
59
+
60
+ def on_update (dt)
61
+ super
62
+ @channel.process
63
+ end
64
+
65
+ end# PrimaryWindow
66
+
67
+
68
+ $window = PrimaryWindow.new.show
69
+ Reflex.start
data/samples/shader.rb ADDED
@@ -0,0 +1,41 @@
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, "Shader Sample"
13
+ set :frame, 100, 100, 300, 300
14
+
15
+ start = Time.now.to_f
16
+ shader = Reflex::Shader.new <<-END
17
+ uniform vec2 resolution;
18
+ uniform float time;
19
+ void main ()
20
+ {
21
+ vec2 pos = gl_FragCoord.xy / resolution;
22
+ gl_FragColor = vec4(pos, float(mod(time, 1.0)), 1);
23
+ }
24
+ END
25
+
26
+ on :draw do |e|
27
+ e.painter.push do
28
+ attach shader, resolution: bounds.size.to_a, time: Time.now.to_f - start
29
+ rect *bounds.to_a
30
+ end
31
+ end
32
+
33
+ on :update do
34
+ redraw
35
+ end
36
+
37
+ show
38
+ end
39
+
40
+
41
+ Reflex.start name: "Shader Sample"
data/samples/shapes.rb ADDED
@@ -0,0 +1,30 @@
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
+ include Reflex
11
+
12
+
13
+ Window.new do
14
+ set title: 'Shape Sample', frame: [100, 100, 500, 400]
15
+
16
+ p = painter
17
+ p.background 0
18
+ p.fill 1
19
+
20
+ %w[line rect ellipse arc].each.with_index do |shape, i|
21
+ add Reflex.const_get("#{shape.capitalize}Shape").new {
22
+ set frame: [32 + 64 * i, 32, 50, 50], color: :gray, border: :white
23
+ }
24
+ end
25
+
26
+ show
27
+ end
28
+
29
+
30
+ Reflex.start
@@ -1,10 +1,9 @@
1
1
  # -*- coding: utf-8 -*-
2
2
 
3
3
 
4
- %w[xot rays reflex].product(%w[ext lib]).each do |paths|
5
- $: << File.expand_path(
6
- File.join File.dirname(__FILE__), *%w[.. .. ..], *paths)
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
8
  require 'reflex'
10
9
 
@@ -13,11 +12,11 @@ lines = File.readlines(__FILE__)
13
12
 
14
13
 
15
14
  Reflex::Window.new do
16
- set title: "Rays/Reflex Text Test", bounds: [100, 100, 600, 400]
15
+ set title: "Rays/Reflex Text Test", frame: [100, 100, 600, 400]
17
16
  painter.background 0.1
18
17
  painter.font Rays::Font.new 'Menlo', 12
19
- on :draw do
20
- paint do
18
+ on :draw do |e|
19
+ e.painter.push do
21
20
  linenum = "%5d "
22
21
  linenum_width = font.width(linenum % 0).ceil
23
22
  line_height = (font.height * 1.0).ceil
@@ -35,4 +34,4 @@ Reflex::Window.new do
35
34
  show
36
35
  end
37
36
 
38
- Reflex.run
37
+ Reflex.start
data/samples/tree.rb ADDED
@@ -0,0 +1,71 @@
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 V < Reflex::View
12
+
13
+ def initialize (offset = [0, 0])
14
+ super()
15
+ frame *offset, 400, 200
16
+ end
17
+
18
+ def on_update (e)
19
+ scroll_to *$scroll if $scroll
20
+ end
21
+
22
+ def on_draw (e)
23
+ e.painter.push do
24
+ b = e.bounds.to_a
25
+
26
+ color [0.2, 0.1]
27
+ rect *b
28
+
29
+ color :green, :red
30
+ text e.fps.to_i.to_s + " FPS."
31
+
32
+ color :none, [1, 0, 0, 0.4]
33
+ rect *b
34
+ end
35
+ end
36
+
37
+ end# V
38
+
39
+
40
+ class W < Reflex::Window
41
+
42
+ def initialize ()
43
+ set :title, "View Tree Sample"
44
+ set :frame, 100, 100, 320, 240
45
+
46
+ painter.background 0
47
+ painter.fill 1
48
+ painter.font nil, 20
49
+ end
50
+
51
+ def on_pointer_move (e)
52
+ $scroll = [-e.x.floor, -e.y.floor]
53
+ end
54
+
55
+ end# W
56
+
57
+
58
+ def setup (parent, level)
59
+ return unless level > 0
60
+ 1.times do |i|
61
+ v = V.new [i * 10] * 2
62
+ parent.add v
63
+ setup v, level - 1
64
+ end
65
+ end
66
+
67
+ w = W.new
68
+ setup w, 5
69
+ w.show
70
+
71
+ Reflex.start
data/samples/views.rb ADDED
@@ -0,0 +1,41 @@
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
+ include Reflex
11
+
12
+
13
+ win = Window.new do
14
+ images = [:red, :blue].map do |col|
15
+ Image.new(32, 32).tap do |img|
16
+ img.paint do
17
+ color :white
18
+ rect img.bounds
19
+ color col
20
+ ellipse img.bounds.inset_by(2, 2)
21
+ end
22
+ end
23
+ end
24
+
25
+ add text = TextView.new {set name: :text, data: 'Text View'}
26
+ add image1 = ImageView.new {set name: :image, data: images.first}
27
+ add image2 = ImageView.new {set name: :image, model: image1.model}
28
+ add button = Button.new {set name: :button, text: 'push me!'}
29
+
30
+ count = 0
31
+ button.on :press do |e|
32
+ count += 1
33
+ image1.image = images[count % 2]
34
+ end
35
+
36
+ set title: 'Many View Sample', frame: [100, 100, 500, 400]
37
+ show
38
+ end
39
+
40
+
41
+ Reflex.start
@@ -0,0 +1,22 @@
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::Application.start name: 'Visuals' do |app|
12
+ Reflex::Window.new title: app.name, frame: [100, 100, 600, 500] do |win|
13
+ win.painter.background = 0.8
14
+ 10.times do |i|
15
+ Reflex::TextView.new name: 'hello', data: 'HELLO WORLD!' do |v|
16
+ v.move_to *([i * 5] * 2)
17
+ win.add v
18
+ end
19
+ end
20
+ win.show
21
+ end
22
+ end
data/src/event.cpp ADDED
@@ -0,0 +1,225 @@
1
+ #include "reflex/event.h"
2
+
3
+
4
+ #include "reflex/exception.h"
5
+
6
+
7
+ namespace Reflex
8
+ {
9
+
10
+
11
+ Event::Event ()
12
+ : blocked(false)
13
+ {
14
+ }
15
+
16
+ void
17
+ Event::block ()
18
+ {
19
+ blocked = true;
20
+ }
21
+
22
+ bool
23
+ Event::is_blocked () const
24
+ {
25
+ return blocked;
26
+ }
27
+
28
+
29
+ UpdateEvent::UpdateEvent (float dt)
30
+ : dt(dt)
31
+ {
32
+ }
33
+
34
+
35
+ DrawEvent::DrawEvent (float dt, float fps)
36
+ : view(NULL), painter(NULL), dt(dt), fps(fps)
37
+ {
38
+ }
39
+
40
+
41
+ FrameEvent::FrameEvent (const Bounds& frame, coord dx, coord dy, coord dwidth, coord dheight)
42
+ : frame(frame), dx(dx), dy(dy), dwidth(dwidth), dheight(dheight)
43
+ {
44
+ }
45
+
46
+ bool
47
+ FrameEvent::is_move () const
48
+ {
49
+ return dx != 0 || dy != 0;
50
+ }
51
+
52
+ bool
53
+ FrameEvent::is_resize () const
54
+ {
55
+ return dwidth != 0 || dheight != 0;
56
+ }
57
+
58
+
59
+ ScrollEvent::ScrollEvent ()
60
+ : x(0), y(0), z(0), dx(0), dy(0), dz(0)
61
+ {
62
+ }
63
+
64
+ ScrollEvent::ScrollEvent (coord x, coord y, coord z, coord dx, coord dy, coord dz)
65
+ : x(x), y(y), z(z), dx(dx), dy(dy), dz(dz)
66
+ {
67
+ }
68
+
69
+ Rays::Point&
70
+ ScrollEvent::scroll ()
71
+ {
72
+ return *(Rays::Point*) &scroll_;
73
+ }
74
+
75
+ const Rays::Point&
76
+ ScrollEvent::scroll () const
77
+ {
78
+ return const_cast<ScrollEvent*>(this)->scroll();
79
+ }
80
+
81
+ Rays::Point&
82
+ ScrollEvent::delta ()
83
+ {
84
+ return *(Rays::Point*) &delta_;
85
+ }
86
+
87
+ const Rays::Point&
88
+ ScrollEvent::delta () const
89
+ {
90
+ return const_cast<ScrollEvent*>(this)->delta();
91
+ }
92
+
93
+
94
+ FocusEvent::FocusEvent ()
95
+ {
96
+ }
97
+
98
+ FocusEvent::FocusEvent (Type type, View* focus, View* last)
99
+ : type(type), focus(focus), last(last)
100
+ {
101
+ }
102
+
103
+
104
+ KeyEvent::KeyEvent ()
105
+ : type(NONE), code(KEY_NONE), modifiers(MOD_NONE), repeat(0), capture(false)
106
+ {
107
+ }
108
+
109
+ KeyEvent::KeyEvent (
110
+ Type type, const char* chars, int code, uint modifiers, int repeat)
111
+ : type(type), chars(chars ? chars : ""), code(code), modifiers(modifiers),
112
+ repeat(repeat), capture(false)
113
+ {
114
+ }
115
+
116
+
117
+ PointerEvent::PointerEvent ()
118
+ : type(NONE), pointer_type(POINTER_NONE),
119
+ size(0), modifiers(MOD_NONE), count(0), drag(false), capture(false),
120
+ x(0), y(0), z(0)
121
+ {
122
+ }
123
+
124
+ PointerEvent::PointerEvent (
125
+ Type type, uint pointer_type, coord x, coord y, uint modifiers, uint count, bool drag)
126
+ : type(type), pointer_type(pointer_type),
127
+ size(1), modifiers(modifiers), count(count), drag(drag), capture(false),
128
+ x(x), y(y), z(0)
129
+ {
130
+ }
131
+
132
+ PointerEvent::PointerEvent (
133
+ Type type, uint pointer_type, const Rays::Point* positions_, size_t size,
134
+ uint modifiers, uint count, bool drag)
135
+ : type(type), pointer_type(pointer_type),
136
+ size(size), modifiers(modifiers), count(count), drag(drag), capture(false)
137
+ {
138
+ if (!positions_ && size > 0)
139
+ argument_error(__FILE__, __LINE__);
140
+
141
+ if (size > MAX) size = MAX;
142
+
143
+ if (positions_)
144
+ {
145
+ for (size_t i = 0; i < size; ++i)
146
+ positions[i] = *(Coord3*) &positions_[i];
147
+ }
148
+ }
149
+
150
+ Rays::Point&
151
+ PointerEvent::position (size_t i)
152
+ {
153
+ if (i >= size)
154
+ index_error(__FILE__, __LINE__);
155
+
156
+ return *(Rays::Point*) &positions[i];
157
+ }
158
+
159
+ const Rays::Point&
160
+ PointerEvent::position (size_t i) const
161
+ {
162
+ return const_cast<PointerEvent*>(this)->position(i);
163
+ }
164
+
165
+ Rays::Point&
166
+ PointerEvent::operator [] (size_t i)
167
+ {
168
+ return position(i);
169
+ }
170
+
171
+ const Rays::Point&
172
+ PointerEvent::operator [] (size_t i) const
173
+ {
174
+ return position(i);
175
+ }
176
+
177
+
178
+ WheelEvent::WheelEvent ()
179
+ : dx(0), dy(0), dz(0), x(0), y(0), z(0), modifiers(0)
180
+ {
181
+ }
182
+
183
+ WheelEvent::WheelEvent (
184
+ coord dx, coord dy, coord dz, coord x, coord y, coord z, uint modifiers)
185
+ : dx(dx), dy(dy), dz(dz), x(x), y(y), z(z), modifiers(modifiers)
186
+ {
187
+ }
188
+
189
+ Rays::Point&
190
+ WheelEvent::delta ()
191
+ {
192
+ return *(Rays::Point*) &delta_;
193
+ }
194
+
195
+ const Rays::Point&
196
+ WheelEvent::delta () const
197
+ {
198
+ return const_cast<WheelEvent*>(this)->delta();
199
+ }
200
+
201
+ Rays::Point&
202
+ WheelEvent::position ()
203
+ {
204
+ return *(Rays::Point*) &position_;
205
+ }
206
+
207
+ const Rays::Point&
208
+ WheelEvent::position () const
209
+ {
210
+ return const_cast<WheelEvent*>(this)->position();
211
+ }
212
+
213
+
214
+ CaptureEvent::CaptureEvent ()
215
+ : begin(0), end(0)
216
+ {
217
+ }
218
+
219
+ CaptureEvent::CaptureEvent (uint begin, uint end)
220
+ : begin(begin), end(end)
221
+ {
222
+ }
223
+
224
+
225
+ }// Reflex
data/src/exception.cpp CHANGED
@@ -1,34 +1,43 @@
1
1
  #include "reflex/exception.h"
2
2
 
3
3
 
4
+ #include "xot/string.h"
5
+
6
+
4
7
  namespace Reflex
5
8
  {
6
9
 
7
10
 
8
- ReflexException::ReflexException (const char* format, ...)
9
- : Super("")
11
+ ReflexError::ReflexError (const char* str)
12
+ : Super(str)
10
13
  {
11
- XOT_STRINGF(format, s);
12
- text = s;
13
14
  }
14
15
 
15
- ReflexException::~ReflexException () throw()
16
- {
17
- }
18
16
 
19
- const char*
20
- ReflexException::what () const throw()
17
+ LayoutError::LayoutError (const char* str)
18
+ : Super(str)
21
19
  {
22
- return text.c_str();
23
20
  }
24
21
 
25
22
 
26
- void
27
- reflex_error (const char* format, ...)
23
+ namespace ErrorFunctions
28
24
  {
29
- XOT_STRINGF(format, s);
30
- throw ReflexException(s.c_str());
31
- }
25
+
26
+ void
27
+ reflex_error (const char* file, int line, const char* format, ...)
28
+ {
29
+ XOT_STRINGF(format, s);
30
+ throw ReflexError(Xot::error_text(file, line, s));
31
+ }
32
+
33
+ void
34
+ layout_error (const char* file, int line, const char* format, ...)
35
+ {
36
+ XOT_STRINGF(format, s);
37
+ throw LayoutError(Xot::error_text(file, line, s));
38
+ }
39
+
40
+ }// ErrorFunctions
32
41
 
33
42
 
34
43
  }// Reflex