reflexion 0.1.12 → 0.1.17

Sign up to get free protection for your applications and to get access to all the features.
Files changed (333) hide show
  1. checksums.yaml +5 -5
  2. data/.doc/ext/reflex/application.cpp +9 -5
  3. data/.doc/ext/reflex/capture_event.cpp +4 -9
  4. data/.doc/ext/reflex/contact_event.cpp +17 -13
  5. data/.doc/ext/reflex/draw_event.cpp +3 -8
  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 +47 -14
  11. data/.doc/ext/reflex/image_view.cpp +1 -10
  12. data/.doc/ext/reflex/key_event.cpp +9 -14
  13. data/.doc/ext/reflex/line_shape.cpp +99 -0
  14. data/.doc/ext/reflex/motion_event.cpp +73 -0
  15. data/.doc/ext/reflex/native.cpp +18 -18
  16. data/.doc/ext/reflex/pointer_event.cpp +27 -25
  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 +24 -3
  20. data/.doc/ext/reflex/scroll_event.cpp +8 -15
  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 +12 -8
  28. data/.doc/ext/reflex/view.cpp +548 -144
  29. data/.doc/ext/reflex/wheel_event.cpp +5 -28
  30. data/.doc/ext/reflex/window.cpp +7 -15
  31. data/LICENSE +21 -0
  32. data/README.md +1 -1
  33. data/Rakefile +14 -12
  34. data/VERSION +1 -1
  35. data/ext/reflex/application.cpp +10 -5
  36. data/ext/reflex/capture_event.cpp +4 -9
  37. data/ext/reflex/contact_event.cpp +18 -13
  38. data/ext/reflex/defs.h +5 -2
  39. data/ext/reflex/draw_event.cpp +3 -8
  40. data/ext/reflex/ellipse_shape.cpp +56 -25
  41. data/ext/reflex/event.cpp +0 -4
  42. data/ext/reflex/extconf.rb +1 -2
  43. data/ext/reflex/filter.cpp +86 -0
  44. data/ext/reflex/focus_event.cpp +11 -15
  45. data/ext/reflex/frame_event.cpp +52 -14
  46. data/ext/reflex/image_view.cpp +1 -10
  47. data/ext/reflex/key_event.cpp +9 -14
  48. data/ext/reflex/line_shape.cpp +104 -0
  49. data/ext/reflex/motion_event.cpp +77 -0
  50. data/ext/reflex/native.cpp +18 -18
  51. data/ext/reflex/pointer_event.cpp +27 -25
  52. data/ext/reflex/polygon_shape.cpp +68 -0
  53. data/ext/reflex/rect_shape.cpp +113 -24
  54. data/ext/reflex/reflex.cpp +24 -3
  55. data/ext/reflex/scroll_event.cpp +8 -15
  56. data/ext/reflex/selector.cpp +46 -16
  57. data/ext/reflex/selector.h +130 -0
  58. data/ext/reflex/shape.cpp +231 -0
  59. data/ext/reflex/style.cpp +363 -192
  60. data/ext/reflex/style_length.cpp +164 -37
  61. data/ext/reflex/timer.cpp +108 -0
  62. data/ext/reflex/timer_event.cpp +133 -0
  63. data/ext/reflex/update_event.cpp +13 -8
  64. data/ext/reflex/view.cpp +594 -150
  65. data/ext/reflex/wheel_event.cpp +5 -30
  66. data/ext/reflex/window.cpp +7 -15
  67. data/include/reflex.h +5 -4
  68. data/include/reflex/application.h +2 -0
  69. data/include/reflex/debug.h +22 -0
  70. data/include/reflex/defs.h +45 -2
  71. data/include/reflex/event.h +55 -11
  72. data/include/reflex/exception.h +17 -2
  73. data/include/reflex/filter.h +56 -0
  74. data/include/reflex/image_view.h +1 -1
  75. data/include/reflex/ruby.h +6 -4
  76. data/include/reflex/ruby/application.h +17 -9
  77. data/include/reflex/ruby/event.h +22 -0
  78. data/include/reflex/ruby/filter.h +69 -0
  79. data/include/reflex/ruby/reflex.h +1 -0
  80. data/include/reflex/ruby/selector.h +1 -1
  81. data/include/reflex/ruby/shape.h +140 -0
  82. data/include/reflex/ruby/style.h +1 -1
  83. data/include/reflex/ruby/timer.h +69 -0
  84. data/include/reflex/ruby/view.h +43 -76
  85. data/include/reflex/ruby/window.h +17 -32
  86. data/include/reflex/selector.h +54 -2
  87. data/include/reflex/shape.h +211 -0
  88. data/include/reflex/style.h +136 -76
  89. data/include/reflex/timer.h +73 -0
  90. data/include/reflex/view.h +181 -59
  91. data/include/reflex/window.h +4 -3
  92. data/lib/reflex.rb +13 -6
  93. data/lib/reflex/application.rb +6 -3
  94. data/lib/reflex/button.rb +2 -2
  95. data/lib/reflex/{texture.rb → camera.rb} +2 -2
  96. data/lib/reflex/capture_event.rb +7 -6
  97. data/lib/reflex/contact_event.rb +10 -12
  98. data/lib/reflex/draw_event.rb +6 -1
  99. data/lib/reflex/ellipse_shape.rb +27 -0
  100. data/lib/reflex/filter.rb +18 -0
  101. data/lib/reflex/fixture.rb +4 -0
  102. data/lib/reflex/focus_event.rb +10 -12
  103. data/lib/reflex/frame_event.rb +1 -1
  104. data/lib/reflex/helper.rb +17 -29
  105. data/lib/reflex/key_event.rb +13 -11
  106. data/lib/reflex/line_shape.rb +18 -0
  107. data/lib/reflex/matrix.rb +13 -0
  108. data/lib/reflex/module.rb +4 -19
  109. data/lib/reflex/pointer_event.rb +28 -35
  110. data/lib/reflex/polygon.rb +14 -0
  111. data/lib/reflex/polygon_shape.rb +23 -0
  112. data/lib/reflex/polyline.rb +13 -0
  113. data/lib/reflex/rect_shape.rb +20 -0
  114. data/lib/reflex/reflex.rb +1 -3
  115. data/lib/reflex/scroll_event.rb +1 -1
  116. data/lib/reflex/selector.rb +2 -2
  117. data/lib/reflex/shape.rb +62 -0
  118. data/lib/reflex/style.rb +78 -11
  119. data/lib/reflex/style_length.rb +0 -11
  120. data/lib/reflex/text_view.rb +7 -24
  121. data/lib/reflex/timer.rb +30 -0
  122. data/lib/reflex/timer_event.rb +29 -0
  123. data/lib/reflex/update_event.rb +1 -1
  124. data/lib/reflex/view.rb +127 -32
  125. data/lib/reflex/wheel_event.rb +9 -1
  126. data/lib/reflex/window.rb +29 -9
  127. data/lib/reflexion.rb +23 -7
  128. data/reflex.gemspec +8 -10
  129. data/samples/bats.rb +4 -4
  130. data/samples/camera.rb +45 -0
  131. data/samples/fans.rb +1 -1
  132. data/samples/fps.rb +5 -3
  133. data/samples/hello.rb +4 -6
  134. data/samples/image.rb +5 -4
  135. data/samples/ios/hello/hello.xcodeproj/project.pbxproj +0 -2
  136. data/samples/layout.rb +16 -7
  137. data/samples/model.rb +10 -7
  138. data/samples/physics.rb +22 -20
  139. data/samples/reflexion/breakout.rb +4 -5
  140. data/samples/reflexion/hello.rb +2 -2
  141. data/samples/reflexion/jump_action.rb +191 -0
  142. data/samples/reflexion/noise.rb +23 -0
  143. data/samples/reflexion/paint.rb +7 -6
  144. data/samples/reflexion/physics.rb +15 -8
  145. data/samples/reflexion/pulse.rb +24 -10
  146. data/samples/shader.rb +8 -6
  147. data/samples/shapes.rb +79 -14
  148. data/samples/tree.rb +9 -10
  149. data/samples/views.rb +3 -3
  150. data/samples/visuals.rb +2 -5
  151. data/src/body.cpp +146 -345
  152. data/src/body.h +91 -0
  153. data/src/event.cpp +65 -15
  154. data/src/exception.cpp +13 -3
  155. data/src/filter.cpp +76 -0
  156. data/src/fixture.cpp +164 -39
  157. data/src/fixture.h +85 -0
  158. data/src/image_view.cpp +4 -4
  159. data/src/ios/app_delegate.h +5 -10
  160. data/src/ios/app_delegate.mm +79 -41
  161. data/src/ios/application.h +32 -0
  162. data/src/ios/application.mm +35 -25
  163. data/src/ios/event.mm +8 -4
  164. data/src/ios/reflex.mm +0 -7
  165. data/src/ios/view_controller.h +37 -0
  166. data/src/ios/view_controller.mm +424 -0
  167. data/src/ios/window.h +40 -0
  168. data/src/ios/window.mm +59 -250
  169. data/src/osx/app_delegate.h +5 -10
  170. data/src/osx/app_delegate.mm +52 -55
  171. data/src/osx/application.h +32 -0
  172. data/src/osx/application.mm +44 -39
  173. data/src/osx/native_window.h +0 -15
  174. data/src/osx/native_window.mm +127 -127
  175. data/src/osx/opengl_view.h +0 -2
  176. data/src/osx/opengl_view.mm +12 -3
  177. data/src/osx/reflex.mm +0 -9
  178. data/src/osx/window.h +42 -0
  179. data/src/osx/window.mm +45 -252
  180. data/src/selector.cpp +232 -7
  181. data/src/selector.h +52 -0
  182. data/src/shape.cpp +1191 -0
  183. data/src/shape.h +61 -0
  184. data/src/style.cpp +573 -376
  185. data/src/style.h +39 -0
  186. data/src/timer.cpp +288 -0
  187. data/src/timer.h +55 -0
  188. data/src/view.cpp +1624 -984
  189. data/src/view.h +56 -0
  190. data/src/win32/window.cpp +3 -4
  191. data/src/window.cpp +302 -20
  192. data/src/window.h +94 -0
  193. data/src/world.cpp +112 -111
  194. data/src/world.h +34 -53
  195. data/task/box2d.rake +31 -10
  196. data/test/test_capture_event.rb +8 -6
  197. data/test/test_pointer_event.rb +130 -0
  198. data/test/test_selector.rb +1 -1
  199. data/test/test_shape.rb +71 -0
  200. data/test/test_style.rb +77 -11
  201. data/test/test_style_length.rb +42 -13
  202. data/test/test_view.rb +138 -14
  203. metadata +115 -213
  204. data/.doc/ext/reflex/arc_shape.cpp +0 -89
  205. data/.doc/ext/reflex/body.cpp +0 -299
  206. data/.doc/ext/reflex/fixture.cpp +0 -101
  207. data/.doc/ext/reflex/shape_view.cpp +0 -153
  208. data/ext/reflex/arc_shape.cpp +0 -94
  209. data/ext/reflex/body.cpp +0 -328
  210. data/ext/reflex/fixture.cpp +0 -108
  211. data/ext/reflex/shape_view.cpp +0 -161
  212. data/include/reflex/bitmap.h +0 -20
  213. data/include/reflex/body.h +0 -128
  214. data/include/reflex/bounds.h +0 -20
  215. data/include/reflex/color.h +0 -20
  216. data/include/reflex/color_space.h +0 -20
  217. data/include/reflex/fixture.h +0 -117
  218. data/include/reflex/font.h +0 -20
  219. data/include/reflex/image.h +0 -20
  220. data/include/reflex/matrix.h +0 -20
  221. data/include/reflex/painter.h +0 -20
  222. data/include/reflex/point.h +0 -24
  223. data/include/reflex/ruby/body.h +0 -41
  224. data/include/reflex/ruby/fixture.h +0 -41
  225. data/include/reflex/ruby/shape_view.h +0 -96
  226. data/include/reflex/shader.h +0 -20
  227. data/include/reflex/shape_view.h +0 -146
  228. data/include/reflex/texture.h +0 -20
  229. data/lib/reflex/body.rb +0 -22
  230. data/lib/reflex/flags.rb +0 -18
  231. data/lib/reflex/shape_view.rb +0 -25
  232. data/src/ios/application_data.h +0 -45
  233. data/src/ios/native_window.h +0 -39
  234. data/src/ios/native_window.mm +0 -224
  235. data/src/ios/opengl_view.h +0 -13
  236. data/src/ios/opengl_view.mm +0 -139
  237. data/src/ios/window_data.h +0 -75
  238. data/src/osx/application_data.h +0 -45
  239. data/src/osx/window_data.h +0 -75
  240. data/src/physics/Box2D/Box2D.h +0 -68
  241. data/src/physics/Box2D/Collision/Shapes/b2ChainShape.cpp +0 -193
  242. data/src/physics/Box2D/Collision/Shapes/b2ChainShape.h +0 -105
  243. data/src/physics/Box2D/Collision/Shapes/b2CircleShape.cpp +0 -99
  244. data/src/physics/Box2D/Collision/Shapes/b2CircleShape.h +0 -91
  245. data/src/physics/Box2D/Collision/Shapes/b2EdgeShape.cpp +0 -138
  246. data/src/physics/Box2D/Collision/Shapes/b2EdgeShape.h +0 -74
  247. data/src/physics/Box2D/Collision/Shapes/b2PolygonShape.cpp +0 -467
  248. data/src/physics/Box2D/Collision/Shapes/b2PolygonShape.h +0 -101
  249. data/src/physics/Box2D/Collision/Shapes/b2Shape.h +0 -101
  250. data/src/physics/Box2D/Collision/b2BroadPhase.cpp +0 -119
  251. data/src/physics/Box2D/Collision/b2BroadPhase.h +0 -257
  252. data/src/physics/Box2D/Collision/b2CollideCircle.cpp +0 -154
  253. data/src/physics/Box2D/Collision/b2CollideEdge.cpp +0 -698
  254. data/src/physics/Box2D/Collision/b2CollidePolygon.cpp +0 -239
  255. data/src/physics/Box2D/Collision/b2Collision.cpp +0 -252
  256. data/src/physics/Box2D/Collision/b2Collision.h +0 -277
  257. data/src/physics/Box2D/Collision/b2Distance.cpp +0 -603
  258. data/src/physics/Box2D/Collision/b2Distance.h +0 -141
  259. data/src/physics/Box2D/Collision/b2DynamicTree.cpp +0 -778
  260. data/src/physics/Box2D/Collision/b2DynamicTree.h +0 -289
  261. data/src/physics/Box2D/Collision/b2TimeOfImpact.cpp +0 -486
  262. data/src/physics/Box2D/Collision/b2TimeOfImpact.h +0 -58
  263. data/src/physics/Box2D/Common/b2BlockAllocator.cpp +0 -215
  264. data/src/physics/Box2D/Common/b2BlockAllocator.h +0 -62
  265. data/src/physics/Box2D/Common/b2Draw.cpp +0 -44
  266. data/src/physics/Box2D/Common/b2Draw.h +0 -86
  267. data/src/physics/Box2D/Common/b2GrowableStack.h +0 -85
  268. data/src/physics/Box2D/Common/b2Math.cpp +0 -94
  269. data/src/physics/Box2D/Common/b2Math.h +0 -720
  270. data/src/physics/Box2D/Common/b2Settings.cpp +0 -44
  271. data/src/physics/Box2D/Common/b2Settings.h +0 -151
  272. data/src/physics/Box2D/Common/b2StackAllocator.cpp +0 -83
  273. data/src/physics/Box2D/Common/b2StackAllocator.h +0 -60
  274. data/src/physics/Box2D/Common/b2Timer.cpp +0 -101
  275. data/src/physics/Box2D/Common/b2Timer.h +0 -50
  276. data/src/physics/Box2D/Dynamics/Contacts/b2ChainAndCircleContact.cpp +0 -53
  277. data/src/physics/Box2D/Dynamics/Contacts/b2ChainAndCircleContact.h +0 -39
  278. data/src/physics/Box2D/Dynamics/Contacts/b2ChainAndPolygonContact.cpp +0 -53
  279. data/src/physics/Box2D/Dynamics/Contacts/b2ChainAndPolygonContact.h +0 -39
  280. data/src/physics/Box2D/Dynamics/Contacts/b2CircleContact.cpp +0 -52
  281. data/src/physics/Box2D/Dynamics/Contacts/b2CircleContact.h +0 -39
  282. data/src/physics/Box2D/Dynamics/Contacts/b2Contact.cpp +0 -247
  283. data/src/physics/Box2D/Dynamics/Contacts/b2Contact.h +0 -349
  284. data/src/physics/Box2D/Dynamics/Contacts/b2ContactSolver.cpp +0 -838
  285. data/src/physics/Box2D/Dynamics/Contacts/b2ContactSolver.h +0 -95
  286. data/src/physics/Box2D/Dynamics/Contacts/b2EdgeAndCircleContact.cpp +0 -49
  287. data/src/physics/Box2D/Dynamics/Contacts/b2EdgeAndCircleContact.h +0 -39
  288. data/src/physics/Box2D/Dynamics/Contacts/b2EdgeAndPolygonContact.cpp +0 -49
  289. data/src/physics/Box2D/Dynamics/Contacts/b2EdgeAndPolygonContact.h +0 -39
  290. data/src/physics/Box2D/Dynamics/Contacts/b2PolygonAndCircleContact.cpp +0 -49
  291. data/src/physics/Box2D/Dynamics/Contacts/b2PolygonAndCircleContact.h +0 -38
  292. data/src/physics/Box2D/Dynamics/Contacts/b2PolygonContact.cpp +0 -52
  293. data/src/physics/Box2D/Dynamics/Contacts/b2PolygonContact.h +0 -39
  294. data/src/physics/Box2D/Dynamics/Joints/b2DistanceJoint.cpp +0 -260
  295. data/src/physics/Box2D/Dynamics/Joints/b2DistanceJoint.h +0 -169
  296. data/src/physics/Box2D/Dynamics/Joints/b2FrictionJoint.cpp +0 -251
  297. data/src/physics/Box2D/Dynamics/Joints/b2FrictionJoint.h +0 -119
  298. data/src/physics/Box2D/Dynamics/Joints/b2GearJoint.cpp +0 -419
  299. data/src/physics/Box2D/Dynamics/Joints/b2GearJoint.h +0 -125
  300. data/src/physics/Box2D/Dynamics/Joints/b2Joint.cpp +0 -211
  301. data/src/physics/Box2D/Dynamics/Joints/b2Joint.h +0 -226
  302. data/src/physics/Box2D/Dynamics/Joints/b2MotorJoint.cpp +0 -304
  303. data/src/physics/Box2D/Dynamics/Joints/b2MotorJoint.h +0 -133
  304. data/src/physics/Box2D/Dynamics/Joints/b2MouseJoint.cpp +0 -222
  305. data/src/physics/Box2D/Dynamics/Joints/b2MouseJoint.h +0 -129
  306. data/src/physics/Box2D/Dynamics/Joints/b2PrismaticJoint.cpp +0 -629
  307. data/src/physics/Box2D/Dynamics/Joints/b2PrismaticJoint.h +0 -196
  308. data/src/physics/Box2D/Dynamics/Joints/b2PulleyJoint.cpp +0 -348
  309. data/src/physics/Box2D/Dynamics/Joints/b2PulleyJoint.h +0 -152
  310. data/src/physics/Box2D/Dynamics/Joints/b2RevoluteJoint.cpp +0 -502
  311. data/src/physics/Box2D/Dynamics/Joints/b2RevoluteJoint.h +0 -204
  312. data/src/physics/Box2D/Dynamics/Joints/b2RopeJoint.cpp +0 -241
  313. data/src/physics/Box2D/Dynamics/Joints/b2RopeJoint.h +0 -114
  314. data/src/physics/Box2D/Dynamics/Joints/b2WeldJoint.cpp +0 -344
  315. data/src/physics/Box2D/Dynamics/Joints/b2WeldJoint.h +0 -126
  316. data/src/physics/Box2D/Dynamics/Joints/b2WheelJoint.cpp +0 -419
  317. data/src/physics/Box2D/Dynamics/Joints/b2WheelJoint.h +0 -210
  318. data/src/physics/Box2D/Dynamics/b2Body.cpp +0 -549
  319. data/src/physics/Box2D/Dynamics/b2Body.h +0 -860
  320. data/src/physics/Box2D/Dynamics/b2ContactManager.cpp +0 -296
  321. data/src/physics/Box2D/Dynamics/b2ContactManager.h +0 -52
  322. data/src/physics/Box2D/Dynamics/b2Fixture.cpp +0 -303
  323. data/src/physics/Box2D/Dynamics/b2Fixture.h +0 -345
  324. data/src/physics/Box2D/Dynamics/b2Island.cpp +0 -539
  325. data/src/physics/Box2D/Dynamics/b2Island.h +0 -93
  326. data/src/physics/Box2D/Dynamics/b2TimeStep.h +0 -70
  327. data/src/physics/Box2D/Dynamics/b2World.cpp +0 -1339
  328. data/src/physics/Box2D/Dynamics/b2World.h +0 -354
  329. data/src/physics/Box2D/Dynamics/b2WorldCallbacks.cpp +0 -36
  330. data/src/physics/Box2D/Dynamics/b2WorldCallbacks.h +0 -155
  331. data/src/physics/Box2D/Rope/b2Rope.cpp +0 -259
  332. data/src/physics/Box2D/Rope/b2Rope.h +0 -115
  333. data/src/shape_view.cpp +0 -306
@@ -21,19 +21,17 @@ Gem::Specification.new do |s|
21
21
  s.description = 'This library helps you to develop interactive graphical user interface.'
22
22
  s.version = mod.version
23
23
 
24
- s.authors = %w[snori]
25
- s.email = 'snori@xord.org'
24
+ s.authors = %w[xordog]
25
+ s.email = 'xordog@gmail.com'
26
26
  s.homepage = "https://github.com/xord/reflex"
27
27
 
28
28
  s.platform = Gem::Platform::RUBY
29
- s.required_ruby_version = '>=1.9.0'
30
-
31
- s.add_runtime_dependency 'rake'
32
- s.add_runtime_dependency 'xot'
33
- s.add_runtime_dependency 'rucy'
34
- s.add_runtime_dependency 'beeps'
35
- s.add_runtime_dependency 'rays'
36
- s.add_development_dependency 'gemcutter'
29
+ s.required_ruby_version = '~> 2'
30
+
31
+ s.add_runtime_dependency 'xot', '~> 0.1.16'
32
+ s.add_runtime_dependency 'rucy', '~> 0.1.16'
33
+ s.add_runtime_dependency 'beeps', '~> 0.1.16'
34
+ s.add_runtime_dependency 'rays', '~> 0.1.17'
37
35
 
38
36
  s.files = `git ls-files`.split $/
39
37
  s.executables = s.files.grep(%r{^bin/}) {|f| File.basename f}
@@ -38,9 +38,9 @@ win = Reflex::Window.new do
38
38
  on :draw do |e|
39
39
  p, b = e.painter, e.bounds
40
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
41
+ #p.rect b
42
+ p.ellipse b, from: angle, to: angle + 90
43
+ p.ellipse b, from: angle + 180, to: angle + 270
44
44
  end
45
45
  }
46
46
  update_count
@@ -80,7 +80,7 @@ win = Reflex::Window.new do
80
80
  root.on :draw do |e|
81
81
  p = e.painter
82
82
  p.fill 1
83
- p.text "draw on root view.", 10, 30
83
+ p.text "draw on root view. (#{e.fps.to_i} FPS)", 10, 30
84
84
  end
85
85
 
86
86
  #100.times {spawn *frame.move_to(0).center.to_a}
@@ -0,0 +1,45 @@
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 Win < Reflex::Window
12
+ def initialize ()
13
+ super title: "Camera Example", frame: [100, 100, 800, 600]
14
+
15
+ @w = 100
16
+ @h = 200
17
+ @resize_crop = Rays::Camera.new(@w, @h, resize: true, crop: true) {start}
18
+ @crop = Rays::Camera.new(@w, @h, resize: false, crop: true) {start}
19
+ @resize = Rays::Camera.new(@w, @h, resize: true, crop: false) {start}
20
+ @original = Rays::Camera.new(@w, @h, resize: false, crop: false) {start}
21
+ end
22
+
23
+ def on_draw (e)
24
+ p = e.painter
25
+
26
+ p.image @resize_crop.image, @w * 0, 0 if @resize_crop.image
27
+ p.image @crop.image, @w * 1, 0 if @crop.image
28
+ p.image @resize.image, @w * 2, 0 if @resize.image
29
+ p.image @original.image, 0, @h if @original.image
30
+
31
+ p.text "#{e.fps.to_i} FPS", 10, 10
32
+
33
+ p.fill nil
34
+ p.stroke 1
35
+ p.rect 0, 0, @w, @h
36
+ end
37
+
38
+ def on_update (e)
39
+ redraw
40
+ end
41
+ end
42
+
43
+ Reflex.start do
44
+ Win.new.show
45
+ end
@@ -61,7 +61,7 @@ class Ring
61
61
 
62
62
  def fin (p, angle, width)
63
63
  angle += @angle
64
- p.arc @x, @y, @width, @height, angle, angle + width, @min
64
+ p.ellipse @x, @y, @width, @height, from: angle, to: angle + width, hole: @min
65
65
  end
66
66
 
67
67
  end# Ring
@@ -30,19 +30,21 @@ w = Reflex::Window
30
30
  yy = y + Math.cos(n) * 50
31
31
  p.rect xx, yy, 50, 50
32
32
  end
33
+
34
+ p.font font
35
+
33
36
  p.fill = 1
34
- p.text "hello Rays/Reflex!", x, y + 32, font
37
+ p.text "hello Rays/Reflex!", x, y + 32
35
38
  x = (x + 1) % 100
36
39
  y = (y + 1) % 100
37
40
 
38
41
  now = Time.now
39
42
  fps = 1 / (now - prev) if x % 10 == 0
40
43
  p.fill = 1, 1, 1, 1
41
- p.text "#{fps.to_i} FPS", 0, sz.y - font.height, font
44
+ p.text "#{fps.to_i} FPS", 0, sz.y - font.height
42
45
  prev = now
43
46
  end
44
47
 
45
-
46
48
  Reflex.start do
47
49
  w.show
48
50
  end
@@ -11,9 +11,7 @@ require 'reflex'
11
11
  class HelloWindow < Reflex::Window
12
12
 
13
13
  def initialize ()
14
- super
15
- set :title, "Hello Reflex!"
16
- set :frame, 100, 100, 320, 240
14
+ super title: "Hello Reflex!", frame: [100, 100, 320, 240]
17
15
  p = painter
18
16
  p.font Reflex::Font.new "Menlo", 32
19
17
  p.background 0
@@ -26,13 +24,13 @@ class HelloWindow < Reflex::Window
26
24
  p.text "hello world!", 5, 5
27
25
  end
28
26
 
29
- def on_update_ (e)
27
+ def on_update (e)
30
28
  painter.background = rand, rand, rand
31
29
  redraw
32
30
  end
33
31
 
34
- def draw_grid (p)
35
- p.push do |_|
32
+ def draw_grid (painter)
33
+ painter.push do |p|
36
34
  w, h = frame.size.to_a
37
35
  p.stroke 0.5, 0.4
38
36
  (0..w).step(5).each {|x| p.line x, 0, x, h}
@@ -13,9 +13,9 @@ include Reflex
13
13
  win = Window.new do
14
14
  image = Image.new(32, 32).tap do |img|
15
15
  img.paint do
16
- color :white
16
+ fill :white
17
17
  rect img.bounds
18
- color :red
18
+ fill :red
19
19
  ellipse img.bounds.inset_by(2, 2)
20
20
  end
21
21
  end
@@ -29,14 +29,15 @@ win = Window.new do
29
29
  end
30
30
 
31
31
  after :draw do |e|
32
- e.painter.color :blank do
32
+ e.painter.push fill: :black do
33
33
  rect 0, 0, 100, 40
34
34
  fill :white
35
35
  text "#{e.fps.to_i} FPS", 10, 10
36
36
  end
37
37
  end
38
38
 
39
- set title: 'Many Image Views', frame: [100, 100, 500, 400]
39
+ title 'Many Image Views'
40
+ frame 100, 100, 500, 400
40
41
  end
41
42
 
42
43
 
@@ -915,7 +915,6 @@
915
915
  ../../../../reflex/include,
916
916
  ../../../../rays/include,
917
917
  ../../../../xot/include,
918
- /usr/local/Cellar/boost/1.53.0/include,
919
918
  "$(inherited)",
920
919
  /Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/include,
921
920
  );
@@ -940,7 +939,6 @@
940
939
  ../../../../reflex/include,
941
940
  ../../../../rays/include,
942
941
  ../../../../xot/include,
943
- /usr/local/Cellar/boost/1.53.0/include,
944
942
  "$(inherited)",
945
943
  /Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/include,
946
944
  );
@@ -11,11 +11,8 @@ include Reflex
11
11
 
12
12
  module Reflex
13
13
  class View
14
- def view (frame = [0, 0, rand(10..200), rand(10..200)], color = [rand, rand, rand], &block)
15
- v = RectShape.new &block
16
- v.set frame: frame, color: color
17
- add v
18
- v
14
+ def view (color: [rand, rand, rand], &block)
15
+ add View.new background: color, &block
19
16
  end
20
17
 
21
18
  alias text view
@@ -25,8 +22,20 @@ module Reflex
25
22
  end
26
23
 
27
24
  win = Window.new title: 'Layout Sample', frame: [100, 100, 500, 400] do
28
- 20.times do
29
- root.view
25
+ flow :right, :down
26
+ 100.times do |i|
27
+ root.view do
28
+ style {
29
+ width 100
30
+ height 200
31
+ left top '50%' if i == 5
32
+ }
33
+ end
34
+ end
35
+ root.view do
36
+ style {
37
+ left top right bottom '45%'
38
+ }
30
39
  end
31
40
  =begin
32
41
  lock_screen = View.new do
@@ -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
 
@@ -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