reflexion 0.1.7 → 0.1.8

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 (223) hide show
  1. checksums.yaml +4 -4
  2. data/.doc/ext/reflex/application.cpp +5 -5
  3. data/.doc/ext/reflex/body.cpp +167 -0
  4. data/.doc/ext/reflex/capture_event.cpp +4 -4
  5. data/.doc/ext/reflex/draw_event.cpp +4 -4
  6. data/.doc/ext/reflex/event.cpp +4 -4
  7. data/.doc/ext/reflex/fixture.cpp +101 -0
  8. data/.doc/ext/reflex/focus_event.cpp +4 -4
  9. data/.doc/ext/reflex/frame_event.cpp +4 -4
  10. data/.doc/ext/reflex/image_view.cpp +22 -5
  11. data/.doc/ext/reflex/key_event.cpp +4 -4
  12. data/.doc/ext/reflex/native.cpp +6 -0
  13. data/.doc/ext/reflex/pointer_event.cpp +4 -4
  14. data/.doc/ext/reflex/reflex.cpp +2 -3
  15. data/.doc/ext/reflex/scroll_event.cpp +4 -4
  16. data/.doc/ext/reflex/selector.cpp +4 -4
  17. data/.doc/ext/reflex/style.cpp +4 -4
  18. data/.doc/ext/reflex/style_length.cpp +4 -4
  19. data/.doc/ext/reflex/style_length2.cpp +4 -4
  20. data/.doc/ext/reflex/style_length4.cpp +4 -4
  21. data/.doc/ext/reflex/update_event.cpp +4 -4
  22. data/.doc/ext/reflex/view.cpp +110 -8
  23. data/.doc/ext/reflex/wheel_event.cpp +4 -4
  24. data/.doc/ext/reflex/window.cpp +36 -12
  25. data/README.md +2 -2
  26. data/Rakefile +2 -1
  27. data/VERSION +1 -1
  28. data/ext/reflex/application.cpp +8 -8
  29. data/ext/reflex/body.cpp +181 -0
  30. data/ext/reflex/capture_event.cpp +4 -4
  31. data/ext/reflex/draw_event.cpp +4 -4
  32. data/ext/reflex/event.cpp +4 -4
  33. data/ext/reflex/fixture.cpp +108 -0
  34. data/ext/reflex/focus_event.cpp +4 -4
  35. data/ext/reflex/frame_event.cpp +4 -4
  36. data/ext/reflex/image_view.cpp +24 -5
  37. data/ext/reflex/key_event.cpp +4 -4
  38. data/ext/reflex/native.cpp +6 -0
  39. data/ext/reflex/pointer_event.cpp +4 -4
  40. data/ext/reflex/reflex.cpp +2 -3
  41. data/ext/reflex/scroll_event.cpp +4 -4
  42. data/ext/reflex/selector.cpp +4 -4
  43. data/ext/reflex/style.cpp +4 -4
  44. data/ext/reflex/style_length.cpp +4 -4
  45. data/ext/reflex/style_length2.cpp +4 -4
  46. data/ext/reflex/style_length4.cpp +4 -4
  47. data/ext/reflex/update_event.cpp +4 -4
  48. data/ext/reflex/view.cpp +126 -12
  49. data/ext/reflex/wheel_event.cpp +4 -4
  50. data/ext/reflex/window.cpp +39 -12
  51. data/include/reflex/bitmap.h +20 -0
  52. data/include/reflex/body.h +82 -0
  53. data/include/reflex/bounds.h +20 -0
  54. data/include/reflex/color.h +20 -0
  55. data/include/reflex/color_space.h +20 -0
  56. data/include/reflex/defs.h +5 -1
  57. data/include/reflex/event.h +16 -25
  58. data/include/reflex/fixture.h +116 -0
  59. data/include/reflex/font.h +20 -0
  60. data/include/reflex/image.h +20 -0
  61. data/include/reflex/image_view.h +1 -1
  62. data/include/reflex/matrix.h +20 -0
  63. data/include/reflex/painter.h +20 -0
  64. data/include/reflex/point.h +24 -0
  65. data/include/reflex/ruby/application.h +6 -0
  66. data/include/reflex/ruby/body.h +41 -0
  67. data/include/reflex/ruby/event.h +68 -0
  68. data/include/reflex/ruby/fixture.h +41 -0
  69. data/include/reflex/ruby/image_view.h +14 -0
  70. data/include/reflex/ruby/selector.h +14 -0
  71. data/include/reflex/ruby/style.h +14 -0
  72. data/include/reflex/ruby/style_length.h +26 -0
  73. data/include/reflex/ruby/view.h +43 -39
  74. data/include/reflex/ruby/window.h +27 -21
  75. data/include/reflex/ruby.h +2 -0
  76. data/include/reflex/shader.h +20 -0
  77. data/include/reflex/style.h +2 -3
  78. data/include/reflex/texture.h +20 -0
  79. data/include/reflex/view.h +45 -24
  80. data/include/reflex/window.h +11 -14
  81. data/include/reflex.h +3 -0
  82. data/lib/reflex/application.rb +6 -2
  83. data/lib/reflex/body.rb +17 -0
  84. data/lib/reflex/fixture.rb +17 -0
  85. data/lib/reflex/view.rb +16 -1
  86. data/lib/reflex/window.rb +13 -1
  87. data/lib/reflex.rb +2 -0
  88. data/reflex.gemspec +1 -1
  89. data/samples/bats.rb +4 -3
  90. data/samples/checker.rb +4 -3
  91. data/samples/fans.rb +4 -3
  92. data/samples/fps.rb +5 -3
  93. data/samples/grid.rb +5 -4
  94. data/samples/hello.rb +1 -1
  95. data/samples/image.rb +3 -2
  96. data/samples/ios/hello/hello/main.cpp +12 -3
  97. data/samples/ios/hello/hello.xcodeproj/project.pbxproj +376 -123
  98. data/samples/key.rb +5 -4
  99. data/samples/layout.rb +3 -2
  100. data/samples/model.rb +3 -2
  101. data/samples/osx/hello/hello/main.cpp +12 -3
  102. data/samples/osx/hello/hello.xcodeproj/project.pbxproj +375 -120
  103. data/samples/physics.rb +37 -0
  104. data/samples/repl.rb +3 -2
  105. data/samples/shader.rb +4 -4
  106. data/samples/shapes.rb +4 -4
  107. data/samples/text.rb +6 -4
  108. data/samples/tree.rb +5 -4
  109. data/samples/views.rb +3 -2
  110. data/samples/visuals.rb +1 -2
  111. data/src/body.cpp +244 -0
  112. data/src/event.cpp +18 -18
  113. data/src/fixture.cpp +108 -0
  114. data/src/image_view.cpp +1 -1
  115. data/src/ios/native_window.h +2 -0
  116. data/src/ios/native_window.mm +18 -1
  117. data/src/ios/opengl_view.mm +8 -0
  118. data/src/ios/window.mm +24 -3
  119. data/src/ios/window_data.h +3 -3
  120. data/src/osx/native_window.mm +17 -1
  121. data/src/osx/window.mm +24 -3
  122. data/src/osx/window_data.h +3 -3
  123. data/src/physics/Box2D/Box2D.h +68 -0
  124. data/src/physics/Box2D/Collision/Shapes/b2ChainShape.cpp +193 -0
  125. data/src/physics/Box2D/Collision/Shapes/b2ChainShape.h +105 -0
  126. data/src/physics/Box2D/Collision/Shapes/b2CircleShape.cpp +99 -0
  127. data/src/physics/Box2D/Collision/Shapes/b2CircleShape.h +91 -0
  128. data/src/physics/Box2D/Collision/Shapes/b2EdgeShape.cpp +138 -0
  129. data/src/physics/Box2D/Collision/Shapes/b2EdgeShape.h +74 -0
  130. data/src/physics/Box2D/Collision/Shapes/b2PolygonShape.cpp +467 -0
  131. data/src/physics/Box2D/Collision/Shapes/b2PolygonShape.h +101 -0
  132. data/src/physics/Box2D/Collision/Shapes/b2Shape.h +101 -0
  133. data/src/physics/Box2D/Collision/b2BroadPhase.cpp +119 -0
  134. data/src/physics/Box2D/Collision/b2BroadPhase.h +257 -0
  135. data/src/physics/Box2D/Collision/b2CollideCircle.cpp +154 -0
  136. data/src/physics/Box2D/Collision/b2CollideEdge.cpp +698 -0
  137. data/src/physics/Box2D/Collision/b2CollidePolygon.cpp +239 -0
  138. data/src/physics/Box2D/Collision/b2Collision.cpp +252 -0
  139. data/src/physics/Box2D/Collision/b2Collision.h +277 -0
  140. data/src/physics/Box2D/Collision/b2Distance.cpp +603 -0
  141. data/src/physics/Box2D/Collision/b2Distance.h +141 -0
  142. data/src/physics/Box2D/Collision/b2DynamicTree.cpp +778 -0
  143. data/src/physics/Box2D/Collision/b2DynamicTree.h +289 -0
  144. data/src/physics/Box2D/Collision/b2TimeOfImpact.cpp +486 -0
  145. data/src/physics/Box2D/Collision/b2TimeOfImpact.h +58 -0
  146. data/src/physics/Box2D/Common/b2BlockAllocator.cpp +215 -0
  147. data/src/physics/Box2D/Common/b2BlockAllocator.h +62 -0
  148. data/src/physics/Box2D/Common/b2Draw.cpp +44 -0
  149. data/src/physics/Box2D/Common/b2Draw.h +86 -0
  150. data/src/physics/Box2D/Common/b2GrowableStack.h +85 -0
  151. data/src/physics/Box2D/Common/b2Math.cpp +94 -0
  152. data/src/physics/Box2D/Common/b2Math.h +720 -0
  153. data/src/physics/Box2D/Common/b2Settings.cpp +44 -0
  154. data/src/physics/Box2D/Common/b2Settings.h +151 -0
  155. data/src/physics/Box2D/Common/b2StackAllocator.cpp +83 -0
  156. data/src/physics/Box2D/Common/b2StackAllocator.h +60 -0
  157. data/src/physics/Box2D/Common/b2Timer.cpp +101 -0
  158. data/src/physics/Box2D/Common/b2Timer.h +50 -0
  159. data/src/physics/Box2D/Dynamics/Contacts/b2ChainAndCircleContact.cpp +53 -0
  160. data/src/physics/Box2D/Dynamics/Contacts/b2ChainAndCircleContact.h +39 -0
  161. data/src/physics/Box2D/Dynamics/Contacts/b2ChainAndPolygonContact.cpp +53 -0
  162. data/src/physics/Box2D/Dynamics/Contacts/b2ChainAndPolygonContact.h +39 -0
  163. data/src/physics/Box2D/Dynamics/Contacts/b2CircleContact.cpp +52 -0
  164. data/src/physics/Box2D/Dynamics/Contacts/b2CircleContact.h +39 -0
  165. data/src/physics/Box2D/Dynamics/Contacts/b2Contact.cpp +247 -0
  166. data/src/physics/Box2D/Dynamics/Contacts/b2Contact.h +349 -0
  167. data/src/physics/Box2D/Dynamics/Contacts/b2ContactSolver.cpp +838 -0
  168. data/src/physics/Box2D/Dynamics/Contacts/b2ContactSolver.h +95 -0
  169. data/src/physics/Box2D/Dynamics/Contacts/b2EdgeAndCircleContact.cpp +49 -0
  170. data/src/physics/Box2D/Dynamics/Contacts/b2EdgeAndCircleContact.h +39 -0
  171. data/src/physics/Box2D/Dynamics/Contacts/b2EdgeAndPolygonContact.cpp +49 -0
  172. data/src/physics/Box2D/Dynamics/Contacts/b2EdgeAndPolygonContact.h +39 -0
  173. data/src/physics/Box2D/Dynamics/Contacts/b2PolygonAndCircleContact.cpp +49 -0
  174. data/src/physics/Box2D/Dynamics/Contacts/b2PolygonAndCircleContact.h +38 -0
  175. data/src/physics/Box2D/Dynamics/Contacts/b2PolygonContact.cpp +52 -0
  176. data/src/physics/Box2D/Dynamics/Contacts/b2PolygonContact.h +39 -0
  177. data/src/physics/Box2D/Dynamics/Joints/b2DistanceJoint.cpp +260 -0
  178. data/src/physics/Box2D/Dynamics/Joints/b2DistanceJoint.h +169 -0
  179. data/src/physics/Box2D/Dynamics/Joints/b2FrictionJoint.cpp +251 -0
  180. data/src/physics/Box2D/Dynamics/Joints/b2FrictionJoint.h +119 -0
  181. data/src/physics/Box2D/Dynamics/Joints/b2GearJoint.cpp +419 -0
  182. data/src/physics/Box2D/Dynamics/Joints/b2GearJoint.h +125 -0
  183. data/src/physics/Box2D/Dynamics/Joints/b2Joint.cpp +211 -0
  184. data/src/physics/Box2D/Dynamics/Joints/b2Joint.h +226 -0
  185. data/src/physics/Box2D/Dynamics/Joints/b2MotorJoint.cpp +304 -0
  186. data/src/physics/Box2D/Dynamics/Joints/b2MotorJoint.h +133 -0
  187. data/src/physics/Box2D/Dynamics/Joints/b2MouseJoint.cpp +222 -0
  188. data/src/physics/Box2D/Dynamics/Joints/b2MouseJoint.h +129 -0
  189. data/src/physics/Box2D/Dynamics/Joints/b2PrismaticJoint.cpp +629 -0
  190. data/src/physics/Box2D/Dynamics/Joints/b2PrismaticJoint.h +196 -0
  191. data/src/physics/Box2D/Dynamics/Joints/b2PulleyJoint.cpp +348 -0
  192. data/src/physics/Box2D/Dynamics/Joints/b2PulleyJoint.h +152 -0
  193. data/src/physics/Box2D/Dynamics/Joints/b2RevoluteJoint.cpp +502 -0
  194. data/src/physics/Box2D/Dynamics/Joints/b2RevoluteJoint.h +204 -0
  195. data/src/physics/Box2D/Dynamics/Joints/b2RopeJoint.cpp +241 -0
  196. data/src/physics/Box2D/Dynamics/Joints/b2RopeJoint.h +114 -0
  197. data/src/physics/Box2D/Dynamics/Joints/b2WeldJoint.cpp +344 -0
  198. data/src/physics/Box2D/Dynamics/Joints/b2WeldJoint.h +126 -0
  199. data/src/physics/Box2D/Dynamics/Joints/b2WheelJoint.cpp +419 -0
  200. data/src/physics/Box2D/Dynamics/Joints/b2WheelJoint.h +210 -0
  201. data/src/physics/Box2D/Dynamics/b2Body.cpp +549 -0
  202. data/src/physics/Box2D/Dynamics/b2Body.h +860 -0
  203. data/src/physics/Box2D/Dynamics/b2ContactManager.cpp +296 -0
  204. data/src/physics/Box2D/Dynamics/b2ContactManager.h +52 -0
  205. data/src/physics/Box2D/Dynamics/b2Fixture.cpp +303 -0
  206. data/src/physics/Box2D/Dynamics/b2Fixture.h +345 -0
  207. data/src/physics/Box2D/Dynamics/b2Island.cpp +539 -0
  208. data/src/physics/Box2D/Dynamics/b2Island.h +93 -0
  209. data/src/physics/Box2D/Dynamics/b2TimeStep.h +70 -0
  210. data/src/physics/Box2D/Dynamics/b2World.cpp +1339 -0
  211. data/src/physics/Box2D/Dynamics/b2World.h +354 -0
  212. data/src/physics/Box2D/Dynamics/b2WorldCallbacks.cpp +36 -0
  213. data/src/physics/Box2D/Dynamics/b2WorldCallbacks.h +155 -0
  214. data/src/physics/Box2D/Rope/b2Rope.cpp +259 -0
  215. data/src/physics/Box2D/Rope/b2Rope.h +115 -0
  216. data/src/style.cpp +2 -2
  217. data/src/view.cpp +217 -17
  218. data/src/window.cpp +25 -15
  219. data/src/world.cpp +206 -0
  220. data/src/world.h +96 -0
  221. data/task/box2d.rake +25 -0
  222. data/test/test_view.rb +5 -5
  223. metadata +125 -3
@@ -0,0 +1,37 @@
1
+ # -*- coding: utf-8 -*-
2
+
3
+
4
+ %w[xot rays reflex]
5
+ .map {|s| File.expand_path "../../../#{s}/lib", __FILE__}
6
+ .each {|s| $:.unshift s if !$:.include?(s) && File.directory?(s)}
7
+
8
+ require 'reflex'
9
+
10
+
11
+ Reflex.start name: "Physics" do |app|
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
+ image = Reflex::Image.new(32, 32).paint do |p, img|
16
+ p.fill :green
17
+ p.ellipse img.bounds
18
+ end
19
+
20
+ add Reflex::RectShape.new {
21
+ set color: :blue, frame: [5, 300, 300, 10]
22
+ body.set static: true
23
+ }
24
+
25
+ 10.times do |n|
26
+ add Reflex::ImageView.new {
27
+ set image: image, size: image.size, pos: [40 * n, 20 * n]
28
+ body.set dynamic: true, density: 1
29
+ }
30
+ end
31
+
32
+ after :draw do |e|
33
+ e.painter.fill :white
34
+ e.painter.text "#{e.fps.to_i} FPS", 10, 10
35
+ end
36
+ end
37
+ end
data/samples/repl.rb CHANGED
@@ -65,5 +65,6 @@ class PrimaryWindow < Reflex::Window
65
65
  end# PrimaryWindow
66
66
 
67
67
 
68
- $window = PrimaryWindow.new.show
69
- Reflex.start
68
+ Reflex.start do
69
+ $window = PrimaryWindow.new.show
70
+ end
data/samples/shader.rb CHANGED
@@ -8,7 +8,7 @@
8
8
  require 'reflex'
9
9
 
10
10
 
11
- Reflex::Window.new do
11
+ win = Reflex::Window.new do
12
12
  set :title, "Shader Sample"
13
13
  set :frame, 100, 100, 300, 300
14
14
 
@@ -33,9 +33,9 @@ Reflex::Window.new do
33
33
  on :update do
34
34
  redraw
35
35
  end
36
-
37
- show
38
36
  end
39
37
 
40
38
 
41
- Reflex.start name: "Shader Sample"
39
+ Reflex.start name: "Shader Sample" do
40
+ win.show
41
+ end
data/samples/shapes.rb CHANGED
@@ -10,7 +10,7 @@ require 'reflex'
10
10
  include Reflex
11
11
 
12
12
 
13
- Window.new do
13
+ win = Window.new do
14
14
  set title: 'Shape Sample', frame: [100, 100, 500, 400]
15
15
 
16
16
  p = painter
@@ -22,9 +22,9 @@ Window.new do
22
22
  set frame: [32 + 64 * i, 32, 50, 50], color: :gray, border: :white
23
23
  }
24
24
  end
25
-
26
- show
27
25
  end
28
26
 
29
27
 
30
- Reflex.start
28
+ Reflex.start do
29
+ win.show
30
+ end
data/samples/text.rb CHANGED
@@ -11,10 +11,10 @@ require 'reflex'
11
11
  lines = File.readlines(__FILE__)
12
12
 
13
13
 
14
- Reflex::Window.new do
14
+ win = Reflex::Window.new do
15
15
  set title: "Rays/Reflex Text Test", frame: [100, 100, 600, 400]
16
16
  painter.background 0.1
17
- painter.font Rays::Font.new 'Menlo', 12
17
+ painter.font Reflex::Font.new 'Menlo', 12
18
18
  on :draw do |e|
19
19
  e.painter.push do
20
20
  linenum = "%5d "
@@ -31,7 +31,9 @@ Reflex::Window.new do
31
31
  end
32
32
  end
33
33
  end
34
- show
35
34
  end
36
35
 
37
- Reflex.start
36
+
37
+ Reflex.start do
38
+ win.show
39
+ end
data/samples/tree.rb CHANGED
@@ -64,8 +64,9 @@ def setup (parent, level)
64
64
  end
65
65
  end
66
66
 
67
- w = W.new
68
- setup w, 5
69
- w.show
70
67
 
71
- Reflex.start
68
+ Reflex.start do
69
+ w = W.new
70
+ setup w, 5
71
+ w.show
72
+ end
data/samples/views.rb CHANGED
@@ -34,8 +34,9 @@ win = Window.new do
34
34
  end
35
35
 
36
36
  set title: 'Many View Sample', frame: [100, 100, 500, 400]
37
- show
38
37
  end
39
38
 
40
39
 
41
- Reflex.start
40
+ Reflex.start do
41
+ win.show
42
+ end
data/samples/visuals.rb CHANGED
@@ -17,6 +17,5 @@ Reflex::Application.start name: 'Visuals' do |app|
17
17
  win.add v
18
18
  end
19
19
  end
20
- win.show
21
- end
20
+ end.show
22
21
  end
data/src/body.cpp ADDED
@@ -0,0 +1,244 @@
1
+ #include "reflex/body.h"
2
+
3
+
4
+ #include <assert.h>
5
+ #include <vector>
6
+ #include <Box2D/Common/b2Math.h>
7
+ #include <Box2D/Dynamics/b2Body.h>
8
+ #include <Box2D/Dynamics/b2Fixture.h>
9
+ #include <Box2D/Collision/Shapes/b2CircleShape.h>
10
+ #include <Box2D/Collision/Shapes/b2EdgeShape.h>
11
+ #include <Box2D/Collision/Shapes/b2ChainShape.h>
12
+ #include <Box2D/Collision/Shapes/b2PolygonShape.h>
13
+ #include "reflex/exception.h"
14
+ #include "world.h"
15
+
16
+
17
+ #define PTR ((b2Body*) handle)
18
+
19
+
20
+ namespace Reflex
21
+ {
22
+
23
+
24
+ Body::Body (Handle h, float scale)
25
+ : handle(h), scale(scale)
26
+ {
27
+ assert(h);
28
+ }
29
+
30
+ Fixture
31
+ Body::add_box (float width, float height)
32
+ {
33
+ assert(PTR);
34
+
35
+ b2Vec2 size(width / scale / 2, height / scale / 2);
36
+
37
+ b2PolygonShape shape;
38
+ shape.SetAsBox(size.x, size.y);
39
+ for (int i = 0; i < 4; ++i)
40
+ shape.m_vertices[i] += size;
41
+
42
+ b2FixtureDef fixture;
43
+ fixture.shape = &shape;
44
+
45
+ return PTR->CreateFixture(&fixture);
46
+ }
47
+
48
+ Fixture
49
+ Body::add_circle (float size)
50
+ {
51
+ assert(PTR);
52
+
53
+ float radius = size / scale / 2.f;
54
+
55
+ b2CircleShape shape;
56
+ shape.m_radius = radius;
57
+ shape.m_p.Set(radius, radius);
58
+
59
+ b2FixtureDef fixture;
60
+ fixture.shape = &shape;
61
+
62
+ return PTR->CreateFixture(&fixture);
63
+ }
64
+
65
+ Fixture
66
+ Body::add_edge (const Point& begin, const Point& end)
67
+ {
68
+ assert(PTR);
69
+
70
+ b2EdgeShape shape;
71
+ shape.Set(to_box2d(begin, scale), to_box2d(end, scale));
72
+
73
+ b2FixtureDef fixture;
74
+ fixture.shape = &shape;
75
+
76
+ return PTR->CreateFixture(&fixture);
77
+ }
78
+
79
+ Fixture
80
+ Body::add_edge (const Point* points, size_t size, bool loop)
81
+ {
82
+ assert(PTR);
83
+
84
+ if (size == 2)
85
+ return add_edge(points[0], points[1]);
86
+
87
+ std::vector<b2Vec2> vecs;
88
+ vecs.reserve(size);
89
+ for (size_t i = 0; i < size; ++i)
90
+ vecs.push_back(to_box2d(points[i], scale));
91
+
92
+ b2ChainShape shape;
93
+ if (loop)
94
+ shape.CreateLoop(&vecs[0], (int32) size);
95
+ else
96
+ shape.CreateChain(&vecs[0], (int32) size);
97
+
98
+ b2FixtureDef fixture;
99
+ fixture.shape = &shape;
100
+
101
+ return PTR->CreateFixture(&fixture);
102
+ }
103
+
104
+ Fixture
105
+ Body::add_polygon (const Point* points, size_t size)
106
+ {
107
+ assert(PTR);
108
+
109
+ std::vector<b2Vec2> vecs;
110
+ vecs.reserve(size);
111
+ for (size_t i = 0; i < size; ++i)
112
+ vecs.push_back(to_box2d(points[i], scale));
113
+
114
+ b2PolygonShape shape;
115
+ shape.Set(&vecs[0], (int32) size);
116
+
117
+ b2FixtureDef fixture;
118
+ fixture.shape = &shape;
119
+
120
+ return PTR->CreateFixture(&fixture);
121
+ }
122
+
123
+ void
124
+ Body::clear_fixtures ()
125
+ {
126
+ assert(PTR);
127
+
128
+ b2Fixture* f;
129
+ while (f = PTR->GetFixtureList())
130
+ PTR->DestroyFixture(f);
131
+ }
132
+
133
+ Point
134
+ Body::position () const
135
+ {
136
+ assert(PTR);
137
+
138
+ return to_point(PTR->GetPosition(), scale);
139
+ }
140
+
141
+ float
142
+ Body::angle () const
143
+ {
144
+ assert(PTR);
145
+
146
+ return PTR->GetAngle();
147
+ }
148
+
149
+ void
150
+ Body::set_static (bool state)
151
+ {
152
+ assert(PTR);
153
+
154
+ PTR->SetType(state ? b2_staticBody : b2_dynamicBody);
155
+ }
156
+
157
+ bool
158
+ Body::is_static () const
159
+ {
160
+ assert(PTR);
161
+
162
+ return PTR->GetType() == b2_staticBody;
163
+ }
164
+
165
+ void
166
+ Body::set_dynamic (bool state)
167
+ {
168
+ assert(PTR);
169
+
170
+ PTR->SetType(state ? b2_dynamicBody : b2_staticBody);
171
+ }
172
+
173
+ bool
174
+ Body::is_dynamic () const
175
+ {
176
+ assert(PTR);
177
+
178
+ return PTR->GetType() == b2_dynamicBody;
179
+ }
180
+
181
+ void
182
+ Body::set_density (float density)
183
+ {
184
+ iterator first = begin();
185
+ if (!first)
186
+ invalid_state_error(__FILE__, __LINE__, "no fixture");
187
+
188
+ first->set_density(density);
189
+ }
190
+
191
+ void
192
+ Body::set_friction (float friction)
193
+ {
194
+ iterator first = begin();
195
+ if (!first)
196
+ invalid_state_error(__FILE__, __LINE__, "no fixture");
197
+
198
+ first->set_friction(friction);
199
+ }
200
+
201
+ void
202
+ Body::set_restitution (float restitution)
203
+ {
204
+ iterator first = begin();
205
+ if (!first)
206
+ invalid_state_error(__FILE__, __LINE__, "no fixture");
207
+
208
+ first->set_restitution(restitution);
209
+ }
210
+
211
+ Body::iterator
212
+ Body::begin ()
213
+ {
214
+ assert(PTR);
215
+
216
+ return Fixture(PTR->GetFixtureList());
217
+ }
218
+
219
+ Body::const_iterator
220
+ Body::begin () const
221
+ {
222
+ assert(PTR);
223
+
224
+ return Fixture(PTR->GetFixtureList());
225
+ }
226
+
227
+ Body::iterator
228
+ Body::end ()
229
+ {
230
+ assert(PTR);
231
+
232
+ return Fixture(NULL);
233
+ }
234
+
235
+ Body::const_iterator
236
+ Body::end () const
237
+ {
238
+ assert(PTR);
239
+
240
+ return Fixture(NULL);
241
+ }
242
+
243
+
244
+ }// Reflex
data/src/event.cpp CHANGED
@@ -66,25 +66,25 @@ namespace Reflex
66
66
  {
67
67
  }
68
68
 
69
- Rays::Point&
69
+ Point&
70
70
  ScrollEvent::scroll ()
71
71
  {
72
- return *(Rays::Point*) &scroll_;
72
+ return *(Point*) &scroll_;
73
73
  }
74
74
 
75
- const Rays::Point&
75
+ const Point&
76
76
  ScrollEvent::scroll () const
77
77
  {
78
78
  return const_cast<ScrollEvent*>(this)->scroll();
79
79
  }
80
80
 
81
- Rays::Point&
81
+ Point&
82
82
  ScrollEvent::delta ()
83
83
  {
84
- return *(Rays::Point*) &delta_;
84
+ return *(Point*) &delta_;
85
85
  }
86
86
 
87
- const Rays::Point&
87
+ const Point&
88
88
  ScrollEvent::delta () const
89
89
  {
90
90
  return const_cast<ScrollEvent*>(this)->delta();
@@ -130,7 +130,7 @@ namespace Reflex
130
130
  }
131
131
 
132
132
  PointerEvent::PointerEvent (
133
- Type type, uint pointer_type, const Rays::Point* positions_, size_t size,
133
+ Type type, uint pointer_type, const Point* positions_, size_t size,
134
134
  uint modifiers, uint count, bool drag)
135
135
  : type(type), pointer_type(pointer_type),
136
136
  size(size), modifiers(modifiers), count(count), drag(drag), capture(false)
@@ -147,28 +147,28 @@ namespace Reflex
147
147
  }
148
148
  }
149
149
 
150
- Rays::Point&
150
+ Point&
151
151
  PointerEvent::position (size_t i)
152
152
  {
153
153
  if (i >= size)
154
154
  index_error(__FILE__, __LINE__);
155
155
 
156
- return *(Rays::Point*) &positions[i];
156
+ return *(Point*) &positions[i];
157
157
  }
158
158
 
159
- const Rays::Point&
159
+ const Point&
160
160
  PointerEvent::position (size_t i) const
161
161
  {
162
162
  return const_cast<PointerEvent*>(this)->position(i);
163
163
  }
164
164
 
165
- Rays::Point&
165
+ Point&
166
166
  PointerEvent::operator [] (size_t i)
167
167
  {
168
168
  return position(i);
169
169
  }
170
170
 
171
- const Rays::Point&
171
+ const Point&
172
172
  PointerEvent::operator [] (size_t i) const
173
173
  {
174
174
  return position(i);
@@ -186,25 +186,25 @@ namespace Reflex
186
186
  {
187
187
  }
188
188
 
189
- Rays::Point&
189
+ Point&
190
190
  WheelEvent::delta ()
191
191
  {
192
- return *(Rays::Point*) &delta_;
192
+ return *(Point*) &delta_;
193
193
  }
194
194
 
195
- const Rays::Point&
195
+ const Point&
196
196
  WheelEvent::delta () const
197
197
  {
198
198
  return const_cast<WheelEvent*>(this)->delta();
199
199
  }
200
200
 
201
- Rays::Point&
201
+ Point&
202
202
  WheelEvent::position ()
203
203
  {
204
- return *(Rays::Point*) &position_;
204
+ return *(Point*) &position_;
205
205
  }
206
206
 
207
- const Rays::Point&
207
+ const Point&
208
208
  WheelEvent::position () const
209
209
  {
210
210
  return const_cast<WheelEvent*>(this)->position();
data/src/fixture.cpp ADDED
@@ -0,0 +1,108 @@
1
+ #include "reflex/fixture.h"
2
+
3
+
4
+ #include <assert.h>
5
+ #include <Box2D/Dynamics/b2Fixture.h>
6
+
7
+
8
+ #define PTR ((b2Fixture*) handle)
9
+
10
+
11
+ namespace Reflex
12
+ {
13
+
14
+
15
+ Fixture::Fixture (Handle h)
16
+ : handle(h)
17
+ {
18
+ }
19
+
20
+ Fixture&
21
+ Fixture::operator = (Handle h)
22
+ {
23
+ handle = h;
24
+ return *this;
25
+ }
26
+
27
+ void
28
+ Fixture::set_density (float density)
29
+ {
30
+ assert(PTR && PTR->GetBody());
31
+
32
+ PTR->SetDensity(density);
33
+ PTR->GetBody()->ResetMassData();
34
+ }
35
+
36
+ float
37
+ Fixture::density () const
38
+ {
39
+ assert(PTR);
40
+
41
+ return PTR->GetDensity();
42
+ }
43
+
44
+ void
45
+ Fixture::set_friction (float friction)
46
+ {
47
+ assert(PTR);
48
+
49
+ PTR->SetFriction(friction);
50
+ }
51
+
52
+ float
53
+ Fixture::friction () const
54
+ {
55
+ assert(PTR);
56
+
57
+ return PTR->GetFriction();
58
+ }
59
+
60
+ void
61
+ Fixture::set_restitution (float restitution)
62
+ {
63
+ assert(PTR);
64
+
65
+ PTR->SetRestitution(restitution);
66
+ }
67
+
68
+ float
69
+ Fixture::restitution () const
70
+ {
71
+ assert(PTR);
72
+
73
+ return PTR->GetRestitution();
74
+ }
75
+
76
+ Fixture::Handle
77
+ Fixture::next () const
78
+ {
79
+ assert(PTR);
80
+
81
+ return PTR->GetNext();
82
+ }
83
+
84
+ Fixture::operator bool () const
85
+ {
86
+ return PTR;
87
+ }
88
+
89
+ bool
90
+ Fixture::operator ! () const
91
+ {
92
+ return !operator bool();
93
+ }
94
+
95
+ bool
96
+ operator == (const Fixture& lhs, const Fixture& rhs)
97
+ {
98
+ return lhs.handle == rhs.handle;
99
+ }
100
+
101
+ bool
102
+ operator != (const Fixture& lhs, const Fixture& rhs)
103
+ {
104
+ return !(lhs == rhs);
105
+ }
106
+
107
+
108
+ }// Reflex
data/src/image_view.cpp CHANGED
@@ -39,7 +39,7 @@ namespace Reflex
39
39
  return self->image;
40
40
  }
41
41
 
42
- Rays::Point
42
+ Point
43
43
  ImageView::content_size () const
44
44
  {
45
45
  if (self->image)
@@ -18,6 +18,8 @@
18
18
 
19
19
  - (void) unbind: (Reflex::Window*) instance;
20
20
 
21
+ - (void) update;
22
+
21
23
  - (void) draw;
22
24
 
23
25
  - (void) keyDown: (UIEvent*) event;
@@ -3,7 +3,7 @@
3
3
 
4
4
 
5
5
  #include <assert.h>
6
- #include <rays/bounds.h>
6
+ #include "reflex/bounds.h"
7
7
  #include "reflex/window.h"
8
8
  #include "reflex/exception.h"
9
9
  #include "event.h"
@@ -14,6 +14,16 @@
14
14
  #define REF (*pref)
15
15
 
16
16
 
17
+ namespace Reflex
18
+ {
19
+
20
+ void update_view_tree (View* v, const UpdateEvent& e);
21
+
22
+ void draw_view_tree (View* v, const DrawEvent& e, const Point& offset, const Bounds& clip);
23
+
24
+ }// Reflex
25
+
26
+
17
27
  static CGRect device_frame ()
18
28
  {
19
29
  return [[UIScreen mainScreen] applicationFrame];
@@ -87,6 +97,8 @@ static CGRect device_frame ()
87
97
  REF->self->prev_time_update = now;
88
98
 
89
99
  REF->on_update(&e);
100
+ if (!e.is_blocked())
101
+ Reflex::update_view_tree(REF->root(), e);
90
102
  }
91
103
 
92
104
  - (void) draw
@@ -115,7 +127,12 @@ static CGRect device_frame ()
115
127
  e.bounds.reset(0, 0, b.width, b.height);
116
128
 
117
129
  e.painter->begin();
130
+ e.painter->clear();
131
+
118
132
  REF->on_draw(&e);
133
+ if (!e.is_blocked())
134
+ draw_view_tree(REF->root(), e, 0, REF->frame().dup().move_to(0));
135
+
119
136
  e.painter->end();
120
137
  }
121
138
 
@@ -69,6 +69,14 @@
69
69
  }
70
70
  }
71
71
 
72
+ - (void) update
73
+ {
74
+ NativeWindow* win = (NativeWindow*) self.view.window;
75
+ if (!win) return;
76
+
77
+ [win update];
78
+ }
79
+
72
80
  - (void) glkView: (GLKView*) view drawInRect: (CGRect) rect
73
81
  {
74
82
  NativeWindow* win = (NativeWindow*) self.view.window;