reflexion 0.1.12 → 0.1.13

Sign up to get free protection for your applications and to get access to all the features.
Files changed (329) hide show
  1. checksums.yaml +5 -5
  2. data/.doc/ext/reflex/application.cpp +9 -5
  3. data/.doc/ext/reflex/capture_event.cpp +0 -4
  4. data/.doc/ext/reflex/contact_event.cpp +17 -10
  5. data/.doc/ext/reflex/draw_event.cpp +1 -5
  6. data/.doc/ext/reflex/ellipse_shape.cpp +51 -24
  7. data/.doc/ext/reflex/event.cpp +0 -4
  8. data/.doc/ext/reflex/filter.cpp +81 -0
  9. data/.doc/ext/reflex/focus_event.cpp +9 -13
  10. data/.doc/ext/reflex/frame_event.cpp +40 -6
  11. data/.doc/ext/reflex/image_view.cpp +1 -10
  12. data/.doc/ext/reflex/key_event.cpp +2 -6
  13. data/.doc/ext/reflex/line_shape.cpp +99 -0
  14. data/.doc/ext/reflex/motion_event.cpp +75 -0
  15. data/.doc/ext/reflex/native.cpp +18 -18
  16. data/.doc/ext/reflex/pointer_event.cpp +5 -11
  17. data/.doc/ext/reflex/polygon_shape.cpp +65 -0
  18. data/.doc/ext/reflex/rect_shape.cpp +102 -23
  19. data/.doc/ext/reflex/reflex.cpp +21 -2
  20. data/.doc/ext/reflex/scroll_event.cpp +0 -6
  21. data/.doc/ext/reflex/selector.cpp +43 -15
  22. data/.doc/ext/reflex/shape.cpp +211 -0
  23. data/.doc/ext/reflex/style.cpp +359 -185
  24. data/.doc/ext/reflex/style_length.cpp +163 -35
  25. data/.doc/ext/reflex/timer.cpp +101 -0
  26. data/.doc/ext/reflex/timer_event.cpp +123 -0
  27. data/.doc/ext/reflex/update_event.cpp +11 -6
  28. data/.doc/ext/reflex/view.cpp +548 -144
  29. data/.doc/ext/reflex/wheel_event.cpp +0 -22
  30. data/.doc/ext/reflex/window.cpp +7 -15
  31. data/README.md +1 -1
  32. data/Rakefile +14 -12
  33. data/VERSION +1 -1
  34. data/ext/reflex/application.cpp +10 -5
  35. data/ext/reflex/capture_event.cpp +1 -5
  36. data/ext/reflex/contact_event.cpp +19 -11
  37. data/ext/reflex/defs.h +5 -2
  38. data/ext/reflex/draw_event.cpp +2 -6
  39. data/ext/reflex/ellipse_shape.cpp +56 -25
  40. data/ext/reflex/event.cpp +0 -4
  41. data/ext/reflex/extconf.rb +1 -2
  42. data/ext/reflex/filter.cpp +86 -0
  43. data/ext/reflex/focus_event.cpp +11 -15
  44. data/ext/reflex/frame_event.cpp +46 -7
  45. data/ext/reflex/image_view.cpp +1 -10
  46. data/ext/reflex/key_event.cpp +3 -7
  47. data/ext/reflex/line_shape.cpp +104 -0
  48. data/ext/reflex/motion_event.cpp +79 -0
  49. data/ext/reflex/native.cpp +18 -18
  50. data/ext/reflex/pointer_event.cpp +6 -12
  51. data/ext/reflex/polygon_shape.cpp +68 -0
  52. data/ext/reflex/rect_shape.cpp +113 -24
  53. data/ext/reflex/reflex.cpp +21 -2
  54. data/ext/reflex/scroll_event.cpp +1 -7
  55. data/ext/reflex/selector.cpp +46 -16
  56. data/ext/reflex/selector.h +130 -0
  57. data/ext/reflex/shape.cpp +231 -0
  58. data/ext/reflex/style.cpp +363 -192
  59. data/ext/reflex/style_length.cpp +164 -37
  60. data/ext/reflex/timer.cpp +108 -0
  61. data/ext/reflex/timer_event.cpp +133 -0
  62. data/ext/reflex/update_event.cpp +13 -7
  63. data/ext/reflex/view.cpp +594 -150
  64. data/ext/reflex/wheel_event.cpp +1 -25
  65. data/ext/reflex/window.cpp +7 -15
  66. data/include/reflex/application.h +2 -0
  67. data/include/reflex/debug.h +22 -0
  68. data/include/reflex/defs.h +45 -0
  69. data/include/reflex/event.h +60 -16
  70. data/include/reflex/exception.h +9 -0
  71. data/include/reflex/filter.h +56 -0
  72. data/include/reflex/image_view.h +1 -1
  73. data/include/reflex/ruby/application.h +17 -9
  74. data/include/reflex/ruby/event.h +22 -0
  75. data/include/reflex/ruby/filter.h +69 -0
  76. data/include/reflex/ruby/selector.h +1 -1
  77. data/include/reflex/ruby/shape.h +140 -0
  78. data/include/reflex/ruby/style.h +1 -1
  79. data/include/reflex/ruby/timer.h +69 -0
  80. data/include/reflex/ruby/view.h +43 -76
  81. data/include/reflex/ruby/window.h +17 -32
  82. data/include/reflex/ruby.h +6 -4
  83. data/include/reflex/selector.h +54 -2
  84. data/include/reflex/shape.h +211 -0
  85. data/include/reflex/style.h +111 -77
  86. data/include/reflex/timer.h +73 -0
  87. data/include/reflex/view.h +181 -59
  88. data/include/reflex/window.h +4 -3
  89. data/include/reflex.h +5 -4
  90. data/lib/reflex/application.rb +6 -3
  91. data/lib/reflex/button.rb +2 -2
  92. data/lib/reflex/capture_event.rb +7 -6
  93. data/lib/reflex/contact_event.rb +10 -12
  94. data/lib/reflex/draw_event.rb +6 -1
  95. data/lib/reflex/ellipse_shape.rb +27 -0
  96. data/lib/reflex/filter.rb +18 -0
  97. data/lib/reflex/fixture.rb +4 -0
  98. data/lib/reflex/focus_event.rb +10 -12
  99. data/lib/reflex/frame_event.rb +1 -1
  100. data/lib/reflex/helper.rb +17 -29
  101. data/lib/reflex/key_event.rb +13 -11
  102. data/lib/reflex/line_shape.rb +18 -0
  103. data/lib/reflex/{texture.rb → matrix.rb} +2 -2
  104. data/lib/reflex/module.rb +4 -19
  105. data/lib/reflex/pointer_event.rb +26 -37
  106. data/lib/reflex/polygon.rb +14 -0
  107. data/lib/reflex/polygon_shape.rb +23 -0
  108. data/lib/reflex/polyline.rb +13 -0
  109. data/lib/reflex/rect_shape.rb +20 -0
  110. data/lib/reflex/reflex.rb +1 -3
  111. data/lib/reflex/scroll_event.rb +1 -1
  112. data/lib/reflex/selector.rb +2 -2
  113. data/lib/reflex/shape.rb +62 -0
  114. data/lib/reflex/style.rb +78 -11
  115. data/lib/reflex/style_length.rb +0 -11
  116. data/lib/reflex/text_view.rb +7 -24
  117. data/lib/reflex/timer.rb +30 -0
  118. data/lib/reflex/timer_event.rb +29 -0
  119. data/lib/reflex/update_event.rb +1 -1
  120. data/lib/reflex/view.rb +127 -32
  121. data/lib/reflex/wheel_event.rb +9 -1
  122. data/lib/reflex/window.rb +29 -9
  123. data/lib/reflex.rb +11 -5
  124. data/lib/reflexion.rb +23 -7
  125. data/reflex.gemspec +8 -10
  126. data/samples/bats.rb +4 -4
  127. data/samples/fans.rb +1 -1
  128. data/samples/fps.rb +5 -3
  129. data/samples/hello.rb +4 -6
  130. data/samples/image.rb +5 -4
  131. data/samples/ios/hello/hello.xcodeproj/project.pbxproj +0 -2
  132. data/samples/layout.rb +16 -7
  133. data/samples/model.rb +10 -7
  134. data/samples/physics.rb +22 -20
  135. data/samples/reflexion/breakout.rb +4 -5
  136. data/samples/reflexion/hello.rb +2 -2
  137. data/samples/reflexion/jump_action.rb +191 -0
  138. data/samples/reflexion/noise.rb +23 -0
  139. data/samples/reflexion/paint.rb +7 -6
  140. data/samples/reflexion/physics.rb +15 -8
  141. data/samples/reflexion/pulse.rb +24 -10
  142. data/samples/shader.rb +8 -6
  143. data/samples/shapes.rb +63 -14
  144. data/samples/tree.rb +9 -10
  145. data/samples/views.rb +3 -3
  146. data/samples/visuals.rb +2 -5
  147. data/src/body.cpp +146 -345
  148. data/src/body.h +91 -0
  149. data/src/event.cpp +66 -16
  150. data/src/exception.cpp +13 -3
  151. data/src/filter.cpp +76 -0
  152. data/src/fixture.cpp +164 -39
  153. data/src/fixture.h +85 -0
  154. data/src/image_view.cpp +4 -4
  155. data/src/ios/app_delegate.h +5 -10
  156. data/src/ios/app_delegate.mm +79 -41
  157. data/src/ios/application.h +32 -0
  158. data/src/ios/application.mm +35 -25
  159. data/src/ios/event.mm +8 -4
  160. data/src/ios/reflex.mm +0 -7
  161. data/src/ios/view_controller.h +33 -0
  162. data/src/ios/view_controller.mm +436 -0
  163. data/src/ios/window.h +40 -0
  164. data/src/ios/window.mm +59 -250
  165. data/src/osx/app_delegate.h +5 -10
  166. data/src/osx/app_delegate.mm +52 -55
  167. data/src/osx/application.h +32 -0
  168. data/src/osx/application.mm +44 -39
  169. data/src/osx/native_window.h +0 -15
  170. data/src/osx/native_window.mm +131 -115
  171. data/src/osx/opengl_view.h +0 -2
  172. data/src/osx/opengl_view.mm +12 -3
  173. data/src/osx/reflex.mm +0 -9
  174. data/src/osx/window.h +42 -0
  175. data/src/osx/window.mm +45 -252
  176. data/src/selector.cpp +232 -7
  177. data/src/selector.h +52 -0
  178. data/src/shape.cpp +1191 -0
  179. data/src/shape.h +61 -0
  180. data/src/style.cpp +571 -374
  181. data/src/style.h +39 -0
  182. data/src/timer.cpp +291 -0
  183. data/src/timer.h +55 -0
  184. data/src/view.cpp +1624 -984
  185. data/src/view.h +56 -0
  186. data/src/win32/window.cpp +3 -4
  187. data/src/window.cpp +275 -20
  188. data/src/window.h +92 -0
  189. data/src/world.cpp +112 -111
  190. data/src/world.h +34 -53
  191. data/task/box2d.rake +31 -10
  192. data/test/test_capture_event.rb +8 -6
  193. data/test/test_pointer_event.rb +85 -0
  194. data/test/test_selector.rb +1 -1
  195. data/test/test_shape.rb +71 -0
  196. data/test/test_style.rb +77 -11
  197. data/test/test_style_length.rb +42 -13
  198. data/test/test_view.rb +138 -14
  199. metadata +109 -210
  200. data/.doc/ext/reflex/arc_shape.cpp +0 -89
  201. data/.doc/ext/reflex/body.cpp +0 -299
  202. data/.doc/ext/reflex/fixture.cpp +0 -101
  203. data/.doc/ext/reflex/shape_view.cpp +0 -153
  204. data/ext/reflex/arc_shape.cpp +0 -94
  205. data/ext/reflex/body.cpp +0 -328
  206. data/ext/reflex/fixture.cpp +0 -108
  207. data/ext/reflex/shape_view.cpp +0 -161
  208. data/include/reflex/bitmap.h +0 -20
  209. data/include/reflex/body.h +0 -128
  210. data/include/reflex/bounds.h +0 -20
  211. data/include/reflex/color.h +0 -20
  212. data/include/reflex/color_space.h +0 -20
  213. data/include/reflex/fixture.h +0 -117
  214. data/include/reflex/font.h +0 -20
  215. data/include/reflex/image.h +0 -20
  216. data/include/reflex/matrix.h +0 -20
  217. data/include/reflex/painter.h +0 -20
  218. data/include/reflex/point.h +0 -24
  219. data/include/reflex/ruby/body.h +0 -41
  220. data/include/reflex/ruby/fixture.h +0 -41
  221. data/include/reflex/ruby/shape_view.h +0 -96
  222. data/include/reflex/shader.h +0 -20
  223. data/include/reflex/shape_view.h +0 -146
  224. data/include/reflex/texture.h +0 -20
  225. data/lib/reflex/body.rb +0 -22
  226. data/lib/reflex/flags.rb +0 -18
  227. data/lib/reflex/shape_view.rb +0 -25
  228. data/src/ios/application_data.h +0 -45
  229. data/src/ios/native_window.h +0 -39
  230. data/src/ios/native_window.mm +0 -224
  231. data/src/ios/opengl_view.h +0 -13
  232. data/src/ios/opengl_view.mm +0 -139
  233. data/src/ios/window_data.h +0 -75
  234. data/src/osx/application_data.h +0 -45
  235. data/src/osx/window_data.h +0 -75
  236. data/src/physics/Box2D/Box2D.h +0 -68
  237. data/src/physics/Box2D/Collision/Shapes/b2ChainShape.cpp +0 -193
  238. data/src/physics/Box2D/Collision/Shapes/b2ChainShape.h +0 -105
  239. data/src/physics/Box2D/Collision/Shapes/b2CircleShape.cpp +0 -99
  240. data/src/physics/Box2D/Collision/Shapes/b2CircleShape.h +0 -91
  241. data/src/physics/Box2D/Collision/Shapes/b2EdgeShape.cpp +0 -138
  242. data/src/physics/Box2D/Collision/Shapes/b2EdgeShape.h +0 -74
  243. data/src/physics/Box2D/Collision/Shapes/b2PolygonShape.cpp +0 -467
  244. data/src/physics/Box2D/Collision/Shapes/b2PolygonShape.h +0 -101
  245. data/src/physics/Box2D/Collision/Shapes/b2Shape.h +0 -101
  246. data/src/physics/Box2D/Collision/b2BroadPhase.cpp +0 -119
  247. data/src/physics/Box2D/Collision/b2BroadPhase.h +0 -257
  248. data/src/physics/Box2D/Collision/b2CollideCircle.cpp +0 -154
  249. data/src/physics/Box2D/Collision/b2CollideEdge.cpp +0 -698
  250. data/src/physics/Box2D/Collision/b2CollidePolygon.cpp +0 -239
  251. data/src/physics/Box2D/Collision/b2Collision.cpp +0 -252
  252. data/src/physics/Box2D/Collision/b2Collision.h +0 -277
  253. data/src/physics/Box2D/Collision/b2Distance.cpp +0 -603
  254. data/src/physics/Box2D/Collision/b2Distance.h +0 -141
  255. data/src/physics/Box2D/Collision/b2DynamicTree.cpp +0 -778
  256. data/src/physics/Box2D/Collision/b2DynamicTree.h +0 -289
  257. data/src/physics/Box2D/Collision/b2TimeOfImpact.cpp +0 -486
  258. data/src/physics/Box2D/Collision/b2TimeOfImpact.h +0 -58
  259. data/src/physics/Box2D/Common/b2BlockAllocator.cpp +0 -215
  260. data/src/physics/Box2D/Common/b2BlockAllocator.h +0 -62
  261. data/src/physics/Box2D/Common/b2Draw.cpp +0 -44
  262. data/src/physics/Box2D/Common/b2Draw.h +0 -86
  263. data/src/physics/Box2D/Common/b2GrowableStack.h +0 -85
  264. data/src/physics/Box2D/Common/b2Math.cpp +0 -94
  265. data/src/physics/Box2D/Common/b2Math.h +0 -720
  266. data/src/physics/Box2D/Common/b2Settings.cpp +0 -44
  267. data/src/physics/Box2D/Common/b2Settings.h +0 -151
  268. data/src/physics/Box2D/Common/b2StackAllocator.cpp +0 -83
  269. data/src/physics/Box2D/Common/b2StackAllocator.h +0 -60
  270. data/src/physics/Box2D/Common/b2Timer.cpp +0 -101
  271. data/src/physics/Box2D/Common/b2Timer.h +0 -50
  272. data/src/physics/Box2D/Dynamics/Contacts/b2ChainAndCircleContact.cpp +0 -53
  273. data/src/physics/Box2D/Dynamics/Contacts/b2ChainAndCircleContact.h +0 -39
  274. data/src/physics/Box2D/Dynamics/Contacts/b2ChainAndPolygonContact.cpp +0 -53
  275. data/src/physics/Box2D/Dynamics/Contacts/b2ChainAndPolygonContact.h +0 -39
  276. data/src/physics/Box2D/Dynamics/Contacts/b2CircleContact.cpp +0 -52
  277. data/src/physics/Box2D/Dynamics/Contacts/b2CircleContact.h +0 -39
  278. data/src/physics/Box2D/Dynamics/Contacts/b2Contact.cpp +0 -247
  279. data/src/physics/Box2D/Dynamics/Contacts/b2Contact.h +0 -349
  280. data/src/physics/Box2D/Dynamics/Contacts/b2ContactSolver.cpp +0 -838
  281. data/src/physics/Box2D/Dynamics/Contacts/b2ContactSolver.h +0 -95
  282. data/src/physics/Box2D/Dynamics/Contacts/b2EdgeAndCircleContact.cpp +0 -49
  283. data/src/physics/Box2D/Dynamics/Contacts/b2EdgeAndCircleContact.h +0 -39
  284. data/src/physics/Box2D/Dynamics/Contacts/b2EdgeAndPolygonContact.cpp +0 -49
  285. data/src/physics/Box2D/Dynamics/Contacts/b2EdgeAndPolygonContact.h +0 -39
  286. data/src/physics/Box2D/Dynamics/Contacts/b2PolygonAndCircleContact.cpp +0 -49
  287. data/src/physics/Box2D/Dynamics/Contacts/b2PolygonAndCircleContact.h +0 -38
  288. data/src/physics/Box2D/Dynamics/Contacts/b2PolygonContact.cpp +0 -52
  289. data/src/physics/Box2D/Dynamics/Contacts/b2PolygonContact.h +0 -39
  290. data/src/physics/Box2D/Dynamics/Joints/b2DistanceJoint.cpp +0 -260
  291. data/src/physics/Box2D/Dynamics/Joints/b2DistanceJoint.h +0 -169
  292. data/src/physics/Box2D/Dynamics/Joints/b2FrictionJoint.cpp +0 -251
  293. data/src/physics/Box2D/Dynamics/Joints/b2FrictionJoint.h +0 -119
  294. data/src/physics/Box2D/Dynamics/Joints/b2GearJoint.cpp +0 -419
  295. data/src/physics/Box2D/Dynamics/Joints/b2GearJoint.h +0 -125
  296. data/src/physics/Box2D/Dynamics/Joints/b2Joint.cpp +0 -211
  297. data/src/physics/Box2D/Dynamics/Joints/b2Joint.h +0 -226
  298. data/src/physics/Box2D/Dynamics/Joints/b2MotorJoint.cpp +0 -304
  299. data/src/physics/Box2D/Dynamics/Joints/b2MotorJoint.h +0 -133
  300. data/src/physics/Box2D/Dynamics/Joints/b2MouseJoint.cpp +0 -222
  301. data/src/physics/Box2D/Dynamics/Joints/b2MouseJoint.h +0 -129
  302. data/src/physics/Box2D/Dynamics/Joints/b2PrismaticJoint.cpp +0 -629
  303. data/src/physics/Box2D/Dynamics/Joints/b2PrismaticJoint.h +0 -196
  304. data/src/physics/Box2D/Dynamics/Joints/b2PulleyJoint.cpp +0 -348
  305. data/src/physics/Box2D/Dynamics/Joints/b2PulleyJoint.h +0 -152
  306. data/src/physics/Box2D/Dynamics/Joints/b2RevoluteJoint.cpp +0 -502
  307. data/src/physics/Box2D/Dynamics/Joints/b2RevoluteJoint.h +0 -204
  308. data/src/physics/Box2D/Dynamics/Joints/b2RopeJoint.cpp +0 -241
  309. data/src/physics/Box2D/Dynamics/Joints/b2RopeJoint.h +0 -114
  310. data/src/physics/Box2D/Dynamics/Joints/b2WeldJoint.cpp +0 -344
  311. data/src/physics/Box2D/Dynamics/Joints/b2WeldJoint.h +0 -126
  312. data/src/physics/Box2D/Dynamics/Joints/b2WheelJoint.cpp +0 -419
  313. data/src/physics/Box2D/Dynamics/Joints/b2WheelJoint.h +0 -210
  314. data/src/physics/Box2D/Dynamics/b2Body.cpp +0 -549
  315. data/src/physics/Box2D/Dynamics/b2Body.h +0 -860
  316. data/src/physics/Box2D/Dynamics/b2ContactManager.cpp +0 -296
  317. data/src/physics/Box2D/Dynamics/b2ContactManager.h +0 -52
  318. data/src/physics/Box2D/Dynamics/b2Fixture.cpp +0 -303
  319. data/src/physics/Box2D/Dynamics/b2Fixture.h +0 -345
  320. data/src/physics/Box2D/Dynamics/b2Island.cpp +0 -539
  321. data/src/physics/Box2D/Dynamics/b2Island.h +0 -93
  322. data/src/physics/Box2D/Dynamics/b2TimeStep.h +0 -70
  323. data/src/physics/Box2D/Dynamics/b2World.cpp +0 -1339
  324. data/src/physics/Box2D/Dynamics/b2World.h +0 -354
  325. data/src/physics/Box2D/Dynamics/b2WorldCallbacks.cpp +0 -36
  326. data/src/physics/Box2D/Dynamics/b2WorldCallbacks.h +0 -155
  327. data/src/physics/Box2D/Rope/b2Rope.cpp +0 -259
  328. data/src/physics/Box2D/Rope/b2Rope.h +0 -115
  329. data/src/shape_view.cpp +0 -306
data/samples/model.rb CHANGED
@@ -15,8 +15,10 @@ class SliderView < View
15
15
  has_model
16
16
 
17
17
  def initialize ()
18
- add @back = RectShape.new {set name: :back, border: :white, follow: :all}
19
- add @knob = RectShape.new {set name: :knob, border: :white, follow: [:top, :bottom], color: :gray, width: 50, x: 50}
18
+ add @back = View.new(name: :back, background: :white)
19
+ add @knob = View.new(name: :knob, background: :gray, x: 50) {
20
+ style.width 50
21
+ }
20
22
 
21
23
  start = nil
22
24
  @knob.on :pointer do |e|
@@ -28,7 +30,7 @@ class SliderView < View
28
30
  start = nil
29
31
  @knob.capture :none
30
32
  when :move
31
- self.data = (@knob.x + e.x - start.x) / knob_left_max.to_f if start
33
+ self.data = (@knob.x + e.x - start.x) / knob_x_max.to_f if start
32
34
  end
33
35
  end
34
36
 
@@ -36,13 +38,13 @@ class SliderView < View
36
38
  end
37
39
 
38
40
  def on_data_update (e)
39
- @knob.x = knob_left_max * data.to_f
41
+ @knob.x = knob_x_max * data.to_f
40
42
  super
41
43
  end
42
44
 
43
45
  private
44
46
 
45
- def knob_left_max ()
47
+ def knob_x_max ()
46
48
  width - @knob.width
47
49
  end
48
50
 
@@ -72,13 +74,14 @@ end# ArrayView
72
74
 
73
75
 
74
76
  win = Window.new do
77
+ title 'Model View Sample'
78
+ frame 100, 100, 500, 400
79
+
75
80
  add @slider = SliderView.new {set name: :slider, frame: [50, 50, 300, 30]}
76
81
  add @text = LabelView.new {set name: :text, frame: [50, 150, 300, 30]}
77
82
  add @array = ArrayView.new {set name: :array, frame: [50, 250, 300, 30]}
78
83
 
79
84
  @slider.model = @text.model = @array.model = Model.new(0) {set minmax: 0..1}
80
-
81
- set title: 'Model View Sample', frame: [100, 100, 500, 400]
82
85
  end
83
86
 
84
87
 
data/samples/physics.rb CHANGED
@@ -10,38 +10,40 @@ require 'reflex'
10
10
 
11
11
  Reflex.start name: "Physics" do |app|
12
12
  Reflex::Window.show title: app.name, frame: [100, 100, 500, 500] do
13
- root.set gravity: Reflex::Point.new(0, 9.8), debug: true
14
-
15
- add_dynamic = -> size = 50, x = rand(10..400), y = rand(10..100) do
16
- add Reflex::EllipseShape.new {
17
- set :fill, [:red, :green, :blue, :yellow, :cyan, :magenta, :gray].sample
18
- set :pos, [x, y]
19
- set :size, [rand(5..size)] * 2
20
- body.set dynamic: true, density: 1
13
+ gravity 0, 9.8 * meter
14
+ #debug true
15
+
16
+ add_dynamic = -> x = rand(10..400), y = rand(10..100), size_ = 50 do
17
+ add Reflex::View.new {
18
+ pos x, y
19
+ size rand 5..size_
20
+ background [:red, :green, :blue, :yellow, :orange, :pink, :peach].sample
21
+ dynamic true
22
+ shape Reflex::EllipseShape.new(density: 1)
21
23
  }
22
24
  end
23
25
 
24
- add_static = -> size = 50 do
25
- add Reflex::RectShape.new {
26
- set :fill, :white
27
- set :pos, [rand(10..400), rand(200..400)]
28
- set :size, [rand(5..(size * 2)), rand(5..size)]
29
- body.set static: true
26
+ add_static = -> size_ = 50 do
27
+ add Reflex::View.new {
28
+ pos rand(10..400), rand(200..400)
29
+ size rand(5..(size_ * 2)), rand(5..size_)
30
+ background :darkgray
31
+ static true
30
32
  }
31
33
  end
32
34
 
33
35
  50.times {|n| add_dynamic.call}
34
- 5.times {|n| add_static.call}
36
+ 5.times {|n| add_static.call}
35
37
 
36
38
  after :draw do |e|
37
- e.painter.fill :white
38
- e.painter.text "#{e.fps.to_i} FPS", 10, 10
39
+ e.painter.push do
40
+ fill :white
41
+ text "#{e.fps.to_i} FPS", 10, 10
42
+ end
39
43
  end
40
44
 
41
45
  on :pointer do |e|
42
- if e.down? || e.drag?
43
- add_dynamic.call 50, *e.pos.to_a
44
- end
46
+ add_dynamic.call *e.pos.to_a if e.down? || e.drag?
45
47
  end
46
48
  end
47
49
  end
@@ -11,23 +11,22 @@ require 'reflexion/include'
11
11
  $hit, $bang = [880, 440].map {|n| Sound.new SineWave.new(freq: n), 0.1}
12
12
 
13
13
  def add_shape (klass: RectShape, frame: [0, 0, 100, 100], color: :white, type: :static)
14
- window.add klass.new {
15
- set frame: frame, fill: color, density: 1, friction: 0, restitution: 1, type => true
14
+ window.add View.new {
15
+ set frame: frame, background: color, type => true, shape: klass.new(density: 1, friction: 0, restitution: 1)
16
16
  }
17
17
  end
18
18
 
19
19
  setup do
20
- style.flow = :none
21
20
  set size: [600, 400], friction: 0
22
21
  5.times do |y|
23
22
  10.times do |x|
24
23
  shape = add_shape frame: [(x + 1) * 50, (y + 1) * 20, 30, 10], color: [:white, :red, :green, :blue, :yellow][y]
25
- shape.on(:contact) {$hit.play; shape.parent.remove shape}
24
+ shape.on(:contact) {$hit.play; shape.remove_self}
26
25
  end
27
26
  end
28
27
  $bar = add_shape frame: [0, 350, 100, 20], color: :blue
29
28
  bottom = add_shape frame: [0, window.h - 1, window.w, 1]
30
- bottom.on(:contact) {|e| $bang.play; e.view.parent.remove e.view}
29
+ bottom.on(:contact) {|e| $bang.play; e.view.remove_self}
31
30
  end
32
31
 
33
32
  pointer do |e|
@@ -1,7 +1,7 @@
1
1
  # -*- coding: utf-8 -*-
2
2
 
3
3
 
4
- %w[xot rays reflex]
4
+ %w[xot beeps rays reflex]
5
5
  .map {|s| File.expand_path "../../../../#{s}/lib", __FILE__}
6
6
  .each {|s| $:.unshift s if !$:.include?(s) && File.directory?(s)}
7
7
 
@@ -14,7 +14,7 @@ array = []
14
14
  draw do
15
15
  gray += 0.01
16
16
  gray %= 1
17
- background gray, gray, gray
17
+ background gray
18
18
  array.unshift event.fps
19
19
  array.slice! 32..-1
20
20
  text "#{array.reduce(0) {|sum, n| sum + n}.tap {|n| break n / array.size}.to_i} FPS", 10, 30
@@ -0,0 +1,191 @@
1
+ # -*- coding: utf-8 -*-
2
+
3
+
4
+ %w[xot beeps 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
+ $player =
12
+ $ground = nil
13
+ $score = 0
14
+ $gameover = false
15
+ $left =
16
+ $right = false
17
+
18
+ class View
19
+ alias center_noangle center
20
+ def center
21
+ p, c, a = pos, center_noangle, angle
22
+ a == 0 ? c : p + (c - p).rotate(a)
23
+ end
24
+ end
25
+
26
+ class KeyEvent
27
+ def left? ()
28
+ code == 123
29
+ end
30
+ def right? ()
31
+ code == 124
32
+ end
33
+ def space? ()
34
+ code == 49
35
+ end
36
+ end
37
+
38
+ setup do
39
+ size 640, 320
40
+ flow :none
41
+ gravity 0, 9.8 * meter
42
+
43
+ root.wall.clear_fixtures
44
+ add_ground
45
+ add_bricks
46
+ add_coins
47
+ add_enemies
48
+ add_player
49
+ end
50
+
51
+ def add_ground ()
52
+ $ground = window.add View.new {
53
+ width 10000
54
+ height parent.height
55
+ static true
56
+ }
57
+
58
+ w, h = $ground.width, $ground.height
59
+ edges = (0..w).step(5).map {|x|
60
+ [x, h + Rays.perlin(x / 100.0, 0) * 30 - 50]
61
+ }
62
+ edges = [[0, 0]] + edges + [[w, 0]]
63
+
64
+ $ground.body.clear_fixtures
65
+ $ground.body.add_edge *edges
66
+ $ground.on :draw do |e|
67
+ e.painter.push fill: nil, stroke: :white do
68
+ lines *edges
69
+ end
70
+ end
71
+ end
72
+
73
+ def add_bricks ()
74
+ range = place_range
75
+ 50.times do
76
+ window.add RectShape.new {
77
+ pos rand(range), 200
78
+ size *(0..1).map {rand(20..100)}
79
+ fill rand, rand, rand
80
+ dynamic true
81
+ density 1
82
+ }
83
+ end
84
+ end
85
+
86
+ def add_coins ()
87
+ range = place_range
88
+ 50.times do
89
+ window.add EllipseShape.new {
90
+ pos rand(range), 100
91
+ size 30
92
+ fill :yellow
93
+ static true
94
+ sensor true
95
+ on :contact do
96
+ remove_self
97
+ $score += 1
98
+ end
99
+ }
100
+ end
101
+ end
102
+
103
+ def add_enemies ()
104
+ range = place_range
105
+ 10.times do
106
+ window.add RectShape.new {
107
+ pos rand(range), 200
108
+ size 50
109
+ fill :red
110
+ static true
111
+ sensor true
112
+ on :contact do |e|
113
+ $gameover = true if e.view == $player
114
+ end
115
+ }
116
+ end
117
+ end
118
+
119
+ def place_range ()
120
+ $ground.frame.inset_by(100).tap {|f| break f.left .. f.right}
121
+ end
122
+
123
+ def add_player ()
124
+ $player = window.add EllipseShape.new {
125
+ @jump_count = 0
126
+
127
+ pos 50, 50
128
+ size 30
129
+ dynamic true
130
+ density 1
131
+ friction 1
132
+
133
+ player_image = Image.new(*size.to_a).paint do |p|
134
+ step, colors = 5, [:green, :blue]
135
+ (0..height).step step do |y|
136
+ (0..width).step step do |x|
137
+ p.fill colors[(x + y) % 2]
138
+ p.rect x, y, step, step
139
+ end
140
+ end
141
+ end
142
+
143
+ def self.jumpable? ()
144
+ @jump_count <= 1
145
+ end
146
+ def self.jump ()
147
+ return unless jumpable?
148
+ velocity velocity.tap {|v| v.y = -5 * meter}
149
+ @jump_count += 1
150
+ end
151
+
152
+ on :update do
153
+ dir = 0
154
+ dir -= 1 if $left
155
+ dir += 1 if $right
156
+ self.angular_velocity = 360 * 3 * dir
157
+ end
158
+ on :draw do |e|
159
+ e.painter.push fill: :white do
160
+ image player_image
161
+ end
162
+ end
163
+ on :contact_begin do
164
+ @jump_count = 0
165
+ end
166
+ }
167
+ end
168
+
169
+ update do
170
+ old_x, new_x = window.root.scroll.x, $player.center.x - window.width / 2
171
+ window.root.scroll_to (old_x + new_x) / 2, 0
172
+ end
173
+
174
+ draw do
175
+ fill :white
176
+ font nil, 30
177
+ text "SCORE: #{$score}", 10, 10
178
+ text "#{event.fps.to_i} FPS", 10, 50
179
+ if $gameover
180
+ fill :red
181
+ font nil, 100
182
+ text "GAMEOVER!", 100, 100
183
+ end
184
+ end
185
+
186
+ key do
187
+ next unless down? || up?
188
+ $left = down? if left?
189
+ $right = down? if right?
190
+ $player.jump if space? && down?
191
+ end
@@ -0,0 +1,23 @@
1
+ # -*- coding: utf-8 -*-
2
+
3
+
4
+ %w[xot beeps 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
+ y = 0
12
+
13
+ draw do
14
+ stroke :white
15
+ lines *(0..200).map {|x|
16
+ xx = x * 5
17
+ yy = 200 + Rays.perlin(x / 10.0, y / 100.0) * 100
18
+ [xx, yy]
19
+ }
20
+ y += 1
21
+
22
+ text "#{event.fps.to_i} FPS", 10, 10
23
+ end
@@ -1,7 +1,7 @@
1
1
  # -*- coding: utf-8 -*-
2
2
 
3
3
 
4
- %w[xot rays reflex]
4
+ %w[xot beeps rays reflex]
5
5
  .map {|s| File.expand_path "../../../../#{s}/lib", __FILE__}
6
6
  .each {|s| $:.unshift s if !$:.include?(s) && File.directory?(s)}
7
7
 
@@ -10,21 +10,22 @@ require 'reflexion/include'
10
10
 
11
11
  FILENAME = 'paint.png'
12
12
 
13
- canvas =
13
+ $canvas =
14
14
  Image.load(FILENAME) rescue nil ||
15
15
  Image.new(512, 512).paint {background :white}
16
16
 
17
+
17
18
  setup do
18
- size canvas.size
19
+ size $canvas.size
19
20
  end
20
21
 
21
22
  draw do
22
- image canvas
23
+ image $canvas
23
24
  end
24
25
 
25
26
  pointer do
26
27
  if down? || drag?
27
- canvas.paint do
28
+ $canvas.paint do
28
29
  fill event.left? ? :red : event.right? ? :blue : :white
29
30
  ellipse *(event.pos - 10).to_a, 20, 20
30
31
  end
@@ -33,7 +34,7 @@ end
33
34
 
34
35
  key do
35
36
  case chars
36
- when /s/i then canvas.save FILENAME
37
+ when /s/i then $canvas.save FILENAME
37
38
  when /q/i, "\e" then quit
38
39
  end
39
40
  end
@@ -1,28 +1,35 @@
1
1
  # -*- coding: utf-8 -*-
2
2
 
3
3
 
4
- %w[xot rays reflex]
4
+ %w[xot beeps rays reflex]
5
5
  .map {|s| File.expand_path "../../../../#{s}/lib", __FILE__}
6
6
  .each {|s| $:.unshift s if !$:.include?(s) && File.directory?(s)}
7
7
 
8
8
  require 'reflexion/include'
9
9
 
10
10
 
11
+ COLORS = [:red, :green, :blue, :orange, :yellow, :indigo, :pink, :peach, :brown]
12
+
13
+ count = 0
14
+
11
15
  setup do
12
- set size: [600, 400], gravity: Point.new(0, 9.8) * meter #, debug: true
16
+ size 600, 400
17
+ gravity 0, 9.8 * meter
13
18
  end
14
19
 
15
20
  draw do
16
- text "#{event.fps.to_i} FPS", 10, 10
21
+ text "#{event.fps.to_i} FPS | #{count} BLOCKS", 10, 10
17
22
  end
18
23
 
19
24
  pointer do
20
25
  if down? || drag?
21
- window.add [RectShape, EllipseShape].sample.new {
22
- size = rand 20..40
23
- color = event.right? ? :gray : [:red, :green, :blue].sample
24
- set frame: [*event.pos.to_a, size, size], fill: color
25
- set dynamic: event.left?, density: 1
26
+ count += 1 if window.add View.new {
27
+ pos event.pos
28
+ size rand 20..40
29
+ background event.right? ? :gray : COLORS.sample
30
+ dynamic event.left?
31
+ shape [RectShape, EllipseShape].sample.new(density: 1)
32
+ interval(1) {fill rand, rand, rand}
26
33
  }
27
34
  end
28
35
  end
@@ -1,36 +1,50 @@
1
1
  # -*- coding: utf-8 -*-
2
2
 
3
3
 
4
- %w[xot rays reflex]
4
+ %w[xot beeps rays reflex]
5
5
  .map {|s| File.expand_path "../../../../#{s}/lib", __FILE__}
6
6
  .each {|s| $:.unshift s if !$:.include?(s) && File.directory?(s)}
7
7
 
8
8
  require 'reflexion/include'
9
9
 
10
10
 
11
- frame = 0
12
- fps = 0
11
+ frame = fps = 0
13
12
 
14
13
 
15
14
  setup do
16
- set width: 600, height: 300
15
+ size 600, 300
17
16
  painter.font = Font.new nil, 24
17
+ interval do
18
+ 3.times {put $pos} if $pos
19
+ end
18
20
  end
19
21
 
20
22
  draw do
21
23
  frame += 1
22
24
  fps = event.fps.to_i if (frame % 5) == 0
23
- text "#{fps} FPS | FRAME: #{frame}", 10, 10
25
+ text "FRAME: #{frame} | #{fps} FPS", 10, 10
24
26
  end
25
27
 
26
28
  key do
27
29
  quit if chars == 'q' || code == 53
28
30
  end
29
31
 
32
+ def put (pos)
33
+ window.add View.new {
34
+ position pos
35
+ size 20
36
+ fill 1, rand(0.2..0.7), rand(0.2..0.4)
37
+ shape EllipseShape.new
38
+ interval do
39
+ self.pos += [rand(-1.0..1.0) * 4, rand(-1.0..0.0) * 8]
40
+ end
41
+ interval do
42
+ self.fill = fill.tap {|f| f.alpha -= 0.02}
43
+ parent.remove self if fill.alpha <= 0
44
+ end
45
+ }
46
+ end
47
+
30
48
  pointer do
31
- if down? || drag?
32
- window.add EllipseShape.new {
33
- set frame: [*(event.pos - 10).to_a, 20, 20], fill: :red
34
- }
35
- end
49
+ $pos = pos
36
50
  end
data/samples/shader.rb CHANGED
@@ -12,21 +12,23 @@ win = Reflex::Window.new do
12
12
  set :title, "Shader Sample"
13
13
  set :frame, 100, 100, 300, 300
14
14
 
15
- start = Time.now.to_f
16
- shader = Reflex::Shader.new <<-END
15
+ start = Time.now.to_f
16
+
17
+ painter.shader <<-END
18
+ varying vec4 v_TexCoord;
17
19
  uniform vec2 resolution;
18
20
  uniform float time;
19
21
  void main ()
20
22
  {
21
- vec2 pos = gl_FragCoord.xy / resolution;
23
+ vec2 pos = v_TexCoord.xy / resolution;
22
24
  gl_FragColor = vec4(pos, float(mod(time, 1.0)), 1);
23
25
  }
24
26
  END
25
27
 
26
28
  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
29
+ e.paint do
30
+ shader.uniform resolution: bounds.size.to_a, time: Time.now.to_f - start
31
+ rect bounds
30
32
  end
31
33
  end
32
34
 
data/samples/shapes.rb CHANGED
@@ -7,24 +7,73 @@
7
7
 
8
8
  require 'reflex'
9
9
 
10
- include Reflex
11
10
 
11
+ Reflex::Window.new do
12
+ title 'Shape Sample'
13
+ frame 100, 100, 800, 500
12
14
 
13
- win = Window.new do
14
- set title: 'Shape Sample', frame: [100, 100, 500, 400]
15
+ def on_draw (e)
16
+ e.painter.push do
17
+ fill :pink
18
+ stroke 1
19
+ stroke_width 2
15
20
 
16
- p = painter
17
- p.background 0
18
- p.fill 1
21
+ x, y, y2, w, h = 10, 10, 100, 50, 50
19
22
 
20
- %w[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], fill: :gray, stroke: :white
23
- }
23
+ push do
24
+ rect x, y, w, h
25
+ polygon Rays::Polygon.rect x, y2, w, h
26
+
27
+ translate 100, 0
28
+ rect x, y, w, h, 5
29
+ polygon Rays::Polygon.rect x, y2, w, h, 5
30
+
31
+ translate 100, 0
32
+ rect x, y, w, h, 5, 10, 15, 20
33
+ polygon Rays::Polygon.rect x, y2, w, h, 5, 10, 15, 20
34
+
35
+ translate 100, 0
36
+ ellipse x, y, w, h
37
+ polygon Rays::Polygon.ellipse x, y2, w, h
38
+
39
+ translate 100, 0
40
+ ellipse x, y, w, h, from: 45, to: 180
41
+ polygon Rays::Polygon.ellipse x, y2, w, h, from: 45, to: 180
42
+
43
+ translate 100, 0
44
+ ellipse x, y, w, h, hole: 10
45
+ polygon Rays::Polygon.ellipse x, y2, w, h, hole: 10
46
+
47
+ translate 100, 0
48
+ ellipse x, y, w, h, hole: 10, from: 200, to: 300
49
+ polygon Rays::Polygon.ellipse x, y2, w, h, hole: 10, from: 200, to: 300
50
+ end
51
+
52
+ translate 0, 200
53
+ push do
54
+ line x, y, x + w, y + h
55
+ line Rays::Polyline.new x, y2, x + w, y2 + h
56
+
57
+ translate 100, 0
58
+ line x, y, x + w, y + h, x, y + h
59
+ line Rays::Polyline.new x, y2, x + w, y2 + h, x, y2 + h
60
+
61
+ translate 100, 0
62
+ line x, y, x + w, y + h, x, y + h, loop: true
63
+ line Rays::Polyline.new x, y2, x + w, y2 + h, x, y2 + h, loop: true
64
+
65
+ translate 100, 0
66
+ polygon Rays::Polyline.new(x, y, x + w, y + h).expand 10
67
+
68
+ translate 100, 0
69
+ polygon Rays::Polyline.new(x, y, x + w, y + h, x, y + h).expand 10
70
+
71
+ translate 100, 0
72
+ polygon Rays::Polyline.new(x, y, x + w, y + h, x, y + h, loop: true).expand 10
73
+ end
74
+ end
24
75
  end
25
- end
76
+ end.show
26
77
 
27
78
 
28
- Reflex.start do
29
- win.show
30
- end
79
+ Reflex.start
data/samples/tree.rb CHANGED
@@ -10,9 +10,8 @@ require 'reflex'
10
10
 
11
11
  class V < Reflex::View
12
12
 
13
- def initialize (offset = [0, 0])
14
- super()
15
- frame *offset, 400, 200
13
+ def initialize (offset = 0)
14
+ super position: offset, size: [400, 200]
16
15
  end
17
16
 
18
17
  def on_update (e)
@@ -23,14 +22,14 @@ class V < Reflex::View
23
22
  e.painter.push do
24
23
  b = e.bounds.to_a
25
24
 
26
- color [0.2, 0.1]
25
+ fill 0.2
26
+ stroke 1
27
+ stroke_width 2
27
28
  rect *b
28
29
 
29
- color :green, :red
30
+ fill :green
31
+ stroke :red
30
32
  text e.fps.to_i.to_s + " FPS."
31
-
32
- color :none, [1, 0, 0, 0.4]
33
- rect *b
34
33
  end
35
34
  end
36
35
 
@@ -41,7 +40,7 @@ class W < Reflex::Window
41
40
 
42
41
  def initialize ()
43
42
  set :title, "View Tree Sample"
44
- set :frame, 100, 100, 320, 240
43
+ set :frame, 100, 100, 800, 600
45
44
 
46
45
  painter.background 0
47
46
  painter.fill 1
@@ -58,7 +57,7 @@ end# W
58
57
  def setup (parent, level)
59
58
  return unless level > 0
60
59
  1.times do |i|
61
- v = V.new [i * 10] * 2
60
+ v = V.new i * 10
62
61
  parent.add v
63
62
  setup v, level - 1
64
63
  end