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/src/style.cpp CHANGED
@@ -1,44 +1,24 @@
1
- #include "reflex/style.h"
1
+ #include "style.h"
2
2
 
3
3
 
4
- #include <boost/noncopyable.hpp>
5
- #include "reflex/view.h"
6
4
  #include "reflex/exception.h"
5
+ #include "reflex/debug.h"
6
+ #include "view.h"
7
+ #include "selector.h"
7
8
 
8
9
 
9
10
  namespace Reflex
10
11
  {
11
12
 
12
13
 
13
- template <typename T>
14
+ template <typename T, typename DefaultValue = T>
14
15
  class StyleValue
15
16
  {
16
17
 
17
- typedef StyleValue<T> This;
18
+ typedef StyleValue<T, DefaultValue> This;
18
19
 
19
20
  typedef T Value;
20
21
 
21
- class Wrapper : public boost::noncopyable, public Xot::RefCountable<>
22
- {
23
-
24
- public:
25
-
26
- Wrapper () {}
27
-
28
- Wrapper (const Value& value) : value(value) {}
29
-
30
- void reset (const Value& value_) {value = value_;}
31
-
32
- Value& get () {return value;}
33
-
34
- const Value& get () const {return value;}
35
-
36
- private:
37
-
38
- Value value;
39
-
40
- };// Wrapper
41
-
42
22
  public:
43
23
 
44
24
  StyleValue ()
@@ -60,13 +40,15 @@ namespace Reflex
60
40
 
61
41
  This& operator = (const Value& value)
62
42
  {
63
- reset(new Wrapper(value));
43
+ set_wrapper(new ValueWrapper(value));
64
44
  return *this;
65
45
  }
66
46
 
67
47
  This& operator = (const This& obj)
68
48
  {
69
- if (&obj != this) reset(obj.pwrapper);
49
+ if (&obj == this) return *this;
50
+ const ValueWrapper* p = obj.wrapper();
51
+ set_wrapper(p ? new ValueWrapper(*p) : NULL);
70
52
  return *this;
71
53
  }
72
54
 
@@ -75,46 +57,44 @@ namespace Reflex
75
57
  clear();
76
58
  }
77
59
 
78
- void clear ()
60
+ bool clear ()
79
61
  {
80
- reset();
62
+ return set_wrapper(NULL);
81
63
  }
82
64
 
83
- Value& value (bool create = false)
65
+ bool set (const Value& value)
84
66
  {
85
- Wrapper* p = pointer();
86
- if (!p)
87
- {
88
- if (!create)
89
- invalid_state_error(__FILE__, __LINE__);
67
+ const ValueWrapper* p = wrapper();
68
+ if (p && p->value() == value)
69
+ return false;
90
70
 
91
- p = reset(new Wrapper());
92
- }
93
- return p->get();
71
+ set_wrapper(new ValueWrapper(value));
72
+ return true;
94
73
  }
95
74
 
96
- const Value& get (const Value& defval) const
75
+ const Value& get () const
97
76
  {
98
- Wrapper* p = pointer();
99
- return p ? p->get() : defval;
77
+ static const Value DEFVAL = DefaultValue();
78
+
79
+ const ValueWrapper* p = wrapper();
80
+ return p ? p->value() : DEFVAL;
100
81
  }
101
82
 
102
- bool set (const Value& val)
83
+ const Value& get (const Value& defval) const
103
84
  {
104
- Value& current = value(true);
105
- if (current == val)
106
- return false;
107
-
108
- current = val;
109
- return true;
85
+ const ValueWrapper* p = wrapper();
86
+ return p ? p->value() : defval;
110
87
  }
111
88
 
112
- void override (const This& value)
89
+ void override (const This& obj)
113
90
  {
114
- if (!value || (*this && !is_inherited()))
91
+ if (!obj)
92
+ return;
93
+
94
+ if (*this && !is_inherited())
115
95
  return;
116
96
 
117
- reset(value.pointer());
97
+ set_wrapper(obj.wrapper());
118
98
  set_inherited();
119
99
  }
120
100
 
@@ -123,17 +103,42 @@ namespace Reflex
123
103
  return get_pointer_flag(pwrapper);
124
104
  }
125
105
 
126
- operator bool () const {return pointer() != NULL;}
106
+ operator bool () const
107
+ {
108
+ return wrapper() != NULL;
109
+ }
127
110
 
128
- bool operator ! () const {return !operator bool();}
111
+ bool operator ! () const
112
+ {
113
+ return !operator bool();
114
+ }
129
115
 
130
116
  private:
131
117
 
132
- Wrapper* pwrapper;
118
+ class ValueWrapper : public Xot::RefCountable<>
119
+ {
120
+
121
+ public:
122
+
123
+ ValueWrapper () : value_(DefaultValue()) {}
124
+
125
+ ValueWrapper (const Value& value) : value_(value) {}
126
+
127
+ ValueWrapper (const ValueWrapper& obj) : value_(obj.value_) {}
133
128
 
134
- Wrapper* reset (Wrapper* ptr = NULL)
129
+ const Value& value () const {return value_;}
130
+
131
+ private:
132
+
133
+ Value value_;
134
+
135
+ };// ValueWrapper
136
+
137
+ const ValueWrapper* pwrapper;
138
+
139
+ const ValueWrapper* set_wrapper (const ValueWrapper* ptr)
135
140
  {
136
- Wrapper* p = pointer();
141
+ const ValueWrapper* p = wrapper();
137
142
  if (ptr != p)
138
143
  {
139
144
  if (p) p->release();
@@ -149,7 +154,10 @@ namespace Reflex
149
154
  pwrapper = Xot::set_pointer_flag(pwrapper, state);
150
155
  }
151
156
 
152
- Wrapper* pointer () const {return Xot::set_pointer_flag(pwrapper, false);}
157
+ const ValueWrapper* wrapper () const
158
+ {
159
+ return Xot::set_pointer_flag(pwrapper, false);
160
+ }
153
161
 
154
162
  };// StyleValue
155
163
 
@@ -157,79 +165,56 @@ namespace Reflex
157
165
  struct StyleLength::Data
158
166
  {
159
167
 
168
+ Type type;
169
+
160
170
  Value value;
161
171
 
162
- Unit unit;
172
+ Data ()
173
+ : type(NONE), value(0)
174
+ {
175
+ }
163
176
 
164
- Data () : value(0), unit(NONE) {}
177
+ bool is_variable () const
178
+ {
179
+ return type == PERCENT || type == FILL || type == FIT;
180
+ }
165
181
 
166
182
  friend bool operator == (const Data& lhs, const Data& rhs)
167
183
  {
168
- return lhs.value == rhs.value && lhs.unit == rhs.unit;
184
+ return lhs.type == rhs.type && lhs.value == rhs.value;
169
185
  }
170
186
 
171
187
  };// StyleLength::Data
172
188
 
173
189
 
174
- StyleLength::StyleLength ()
175
- {
176
- }
177
-
178
- StyleLength::StyleLength (Value value, Unit unit)
179
- {
180
- reset(value, unit);
181
- }
182
-
183
- StyleLength::StyleLength (const char* str)
190
+ StyleLength::StyleLength (Type type, Value value)
184
191
  {
185
- reset(str);
192
+ reset(type, value);
186
193
  }
187
194
 
188
195
  StyleLength
189
196
  StyleLength::copy () const
190
197
  {
191
- return StyleLength(value(), unit());
198
+ return StyleLength(type(), value());
192
199
  }
193
200
 
194
201
  void
195
- StyleLength::reset (Value value, Unit unit)
202
+ StyleLength::reset (Type type, Value value)
196
203
  {
197
- if (unit < NONE || UNIT_LAST <= unit)
204
+ if (type < NONE || TYPE_LAST <= type)
198
205
  argument_error(__FILE__, __LINE__);
199
206
 
200
- self->value = value;
201
- self->unit = unit;
202
- }
203
-
204
- static StyleLength::Unit
205
- str2unit (const char* s)
206
- {
207
- if (strcasecmp(s, "px") == 0) return StyleLength::PIXEL;
208
- else if (strcasecmp(s, "%") == 0) return StyleLength::PERCENT;
209
- else return StyleLength::NONE;
210
- }
207
+ if (type == FIT && value != 1)
208
+ argument_error(__FILE__, __LINE__);
211
209
 
212
- static const char*
213
- unit2str (StyleLength::Unit unit)
214
- {
215
- switch (unit)
216
- {
217
- case StyleLength::PIXEL: return "px";
218
- case StyleLength::PERCENT: return "%";
219
- default: return NULL;
220
- }
210
+ self->type = type;
211
+ self->value = value;
221
212
  }
222
213
 
223
- void
224
- StyleLength::reset (const char* str)
214
+ StyleLength::Type
215
+ StyleLength::type () const
225
216
  {
226
- Value num;
227
- char suffix[256];
228
- int count = sscanf(str, "%f%s", &num, suffix);
229
- if (count != 2)
230
- argument_error(__FILE__, __LINE__);
231
-
232
- reset(num, str2unit(suffix));
217
+ return self->type;
233
218
  }
234
219
 
235
220
  StyleLength::Value
@@ -238,34 +223,9 @@ namespace Reflex
238
223
  return self->value;
239
224
  }
240
225
 
241
- StyleLength::Unit
242
- StyleLength::unit () const
243
- {
244
- return self->unit;
245
- }
246
-
247
- String
248
- StyleLength::to_s () const
249
- {
250
- if (!*this)
251
- return "";
252
-
253
- String num;
254
- if (fmod(self->value, 1) == 0)
255
- num = Xot::stringf("%d", (long) self->value);
256
- else
257
- num = Xot::stringf("%g", self->value);
258
-
259
- const char* suffix = unit2str(self->unit);;
260
- if (!suffix)
261
- invalid_state_error(__FILE__, __LINE__);
262
-
263
- return num + suffix;
264
- }
265
-
266
226
  StyleLength::operator bool () const
267
227
  {
268
- return NONE < self->unit && self->unit < UNIT_LAST;
228
+ return NONE < self->type && self->type < TYPE_LAST;
269
229
  }
270
230
 
271
231
  bool
@@ -287,56 +247,73 @@ namespace Reflex
287
247
  }
288
248
 
289
249
 
290
- void
291
- get_default_flow (Style::Flow* main, Style::Flow* sub)
250
+ struct Style::Data
292
251
  {
293
- assert(main || sub);
294
252
 
295
- if (main) *main = Style::FLOW_RIGHT;
296
- if (sub) *sub = Style::FLOW_DOWN;
297
- }
253
+ struct WhiteColor : public Color
254
+ {
255
+ WhiteColor () : Color(1, 1) {}
256
+ };
298
257
 
258
+ struct TransparentColor : public Color
259
+ {
260
+ TransparentColor () : Color(0, 0) {}
261
+ };
299
262
 
300
- struct Style::Data
301
- {
263
+ struct MaxLength : public StyleLength
264
+ {
265
+ MaxLength () : StyleLength(PERCENT, 100) {}
266
+ };
302
267
 
303
- typedef StyleValue<bool> Bool;
268
+ typedef StyleValue<bool> BoolValue;
304
269
 
305
- typedef StyleValue<int> Int;
270
+ typedef StyleValue<int> IntValue;
306
271
 
307
- typedef StyleValue<double> Float;
272
+ typedef StyleValue<double> FloatValue;
308
273
 
309
- typedef StyleValue<Color> Color;
274
+ typedef StyleValue<coord> CoordValue;
310
275
 
311
- typedef StyleValue<Image> Image;
276
+ typedef StyleValue<Color> ColorValue;
312
277
 
313
- typedef StyleValue<StyleLength> Length;
278
+ typedef StyleValue<Image> ImageValue;
279
+
280
+ typedef StyleValue<StyleLength> LengthValue;
314
281
 
315
282
  View* owner;
316
283
 
317
- Selector selector;
284
+ SelectorPtr pselector;
285
+
286
+ IntValue flow;
287
+
288
+ StyleValue<StyleLength, MaxLength> width, height;
318
289
 
319
- Int flow;
290
+ LengthValue left, top, right, bottom;
320
291
 
321
- Length width, height;
292
+ LengthValue margin_left, margin_top, margin_right, margin_bottom;
322
293
 
323
- Length left, top, right, bottom;
294
+ LengthValue padding_left, padding_top, padding_right, padding_bottom;
324
295
 
325
- Length offset_left, offset_top, offset_right, offset_bottom;
296
+ LengthValue center_x, center_y;
326
297
 
327
- Length margin_left, margin_top, margin_right, margin_bottom;
298
+ StyleValue<Color, WhiteColor> fore_fill;
328
299
 
329
- Length padding_left, padding_top, padding_right, padding_bottom;
300
+ StyleValue<Color, TransparentColor> fore_stroke, back_fill, back_stroke;
330
301
 
331
- Color fill, stroke;
302
+ CoordValue fore_stroke_width, back_stroke_width;
332
303
 
333
- Image image;
304
+ ImageValue image;
334
305
 
335
306
  Data ()
336
307
  : owner(NULL)
337
308
  {
338
309
  }
339
310
 
311
+ Selector& selector ()
312
+ {
313
+ if (!pselector) pselector.reset(new Selector);
314
+ return *pselector;
315
+ }
316
+
340
317
  enum FlowOffset {FLOW_MASK = 0xffff, FLOW_SHIFT = 16};
341
318
 
342
319
  bool set_flow (Flow main, Flow sub)
@@ -346,57 +323,110 @@ namespace Reflex
346
323
 
347
324
  Flow flow_main () const
348
325
  {
349
- Flow defval = FLOW_NONE;
350
- get_default_flow(&defval, NULL);
351
- return (Flow) (flow.get(defval) & FLOW_MASK);
326
+ return (Flow) (flow.get(FLOW_NONE) & FLOW_MASK);
352
327
  }
353
328
 
354
329
  Flow flow_sub () const
355
330
  {
356
- Flow defval = FLOW_NONE;
357
- get_default_flow(NULL, &defval);
358
- return (Flow) ((flow.get(defval << FLOW_SHIFT) >> FLOW_SHIFT) & FLOW_MASK);
331
+ return (Flow) ((flow.get(FLOW_NONE << FLOW_SHIFT) >> FLOW_SHIFT) & FLOW_MASK);
359
332
  }
360
333
 
361
334
  };// Data
362
335
 
363
336
 
364
- namespace Zero
337
+ bool
338
+ Style_set_owner (Style* style, View* owner)
365
339
  {
340
+ assert(style);
366
341
 
367
- static const Color color;
368
-
369
- static const Image image;
370
-
371
- static const StyleLength length;
342
+ if (!!style->self->owner == !!owner)
343
+ return false;
372
344
 
373
- }// Zero
345
+ style->self->owner = owner;
346
+ return true;
347
+ }
374
348
 
349
+ template <typename T>
350
+ static bool
351
+ is_variable (const T& length)
352
+ {
353
+ return length.get().self->is_variable();
354
+ }
375
355
 
376
356
  bool
377
- set_style_owner (Style* style, View* owner)
357
+ Style_has_variable_lengths (const Style& style)
378
358
  {
379
- assert(style);
359
+ Style::Data* s = style.self.get();
360
+ if (!s) return false;
380
361
 
381
- if (style->self->owner)
382
- return false;
362
+ return
363
+ is_variable(s->width) ||
364
+ is_variable(s->height) ||
383
365
 
384
- style->self->owner = owner;
385
- return true;
366
+ is_variable(s->left) ||
367
+ is_variable(s->top) ||
368
+ is_variable(s->right) ||
369
+ is_variable(s->bottom) ||
370
+
371
+ is_variable(s->margin_left) ||
372
+ is_variable(s->margin_top) ||
373
+ is_variable(s->margin_right) ||
374
+ is_variable(s->margin_bottom) ||
375
+
376
+ is_variable(s->padding_left) ||
377
+ is_variable(s->padding_top) ||
378
+ is_variable(s->padding_right) ||
379
+ is_variable(s->padding_bottom) ||
380
+
381
+ is_variable(s->center_x) ||
382
+ is_variable(s->center_y);
386
383
  }
387
384
 
385
+ template <typename T>
388
386
  static void
389
- update_owner (const Style& style)
387
+ clear_inherited_value (T* value)
390
388
  {
391
- View* owner = style.self->owner;
392
- if (!owner) return;
389
+ assert(value);
390
+
391
+ if (value->is_inherited())
392
+ value->clear();
393
+ }
394
+
395
+ void
396
+ Style_clear_inherited_values (Style* style)
397
+ {
398
+ assert(style);
393
399
 
394
- void update_styles_for_selector (View*, const Selector&);
395
- update_styles_for_selector(owner, style.self->selector);
400
+ Style::Data* self = style->self.get();
401
+
402
+ clear_inherited_value(&self->flow);
403
+ clear_inherited_value(&self->width);
404
+ clear_inherited_value(&self->height);
405
+ clear_inherited_value(&self->left);
406
+ clear_inherited_value(&self->top);
407
+ clear_inherited_value(&self->right);
408
+ clear_inherited_value(&self->bottom);
409
+ clear_inherited_value(&self->margin_left);
410
+ clear_inherited_value(&self->margin_top);
411
+ clear_inherited_value(&self->margin_right);
412
+ clear_inherited_value(&self->margin_bottom);
413
+ clear_inherited_value(&self->padding_left);
414
+ clear_inherited_value(&self->padding_top);
415
+ clear_inherited_value(&self->padding_right);
416
+ clear_inherited_value(&self->padding_bottom);
417
+ clear_inherited_value(&self->center_x);
418
+ clear_inherited_value(&self->center_y);
419
+ clear_inherited_value(&self->fore_fill);
420
+ clear_inherited_value(&self->fore_stroke);
421
+ clear_inherited_value(&self->fore_stroke_width);
422
+ clear_inherited_value(&self->back_fill);
423
+ clear_inherited_value(&self->back_stroke);
424
+ clear_inherited_value(&self->back_stroke_width);
425
+ clear_inherited_value(&self->image);
396
426
  }
397
427
 
398
428
  void
399
- override_style (Style* overridden, const Style& overrides)
429
+ Style_override (Style* overridden, const Style& overrides)
400
430
  {
401
431
  assert(overridden);
402
432
 
@@ -404,120 +434,166 @@ namespace Reflex
404
434
  Style::Data* to = overridden->self.get();
405
435
  if (!from || !to) return;
406
436
 
407
- to->flow .override(from->flow);
408
- to->width .override(from->width);
409
- to->height .override(from->height);
410
- to->left .override(from->left);
411
- to->top .override(from->top);
412
- to->right .override(from->right);
413
- to->bottom .override(from->bottom);
414
- to->offset_left .override(from->offset_left);
415
- to->offset_top .override(from->offset_top);
416
- to->offset_right .override(from->offset_right);
417
- to->offset_bottom .override(from->offset_bottom);
418
- to->margin_left .override(from->margin_left);
419
- to->margin_top .override(from->margin_top);
420
- to->margin_right .override(from->margin_right);
421
- to->margin_bottom .override(from->margin_bottom);
422
- to->padding_left .override(from->padding_left);
423
- to->padding_top .override(from->padding_top);
424
- to->padding_right .override(from->padding_right);
425
- to->padding_bottom.override(from->padding_bottom);
426
- to->fill .override(from->fill);
427
- to->stroke .override(from->stroke);
428
- to->image .override(from->image);
437
+ to->flow .override(from->flow);
438
+ to->width .override(from->width);
439
+ to->height .override(from->height);
440
+ to->left .override(from->left);
441
+ to->top .override(from->top);
442
+ to->right .override(from->right);
443
+ to->bottom .override(from->bottom);
444
+ to->margin_left .override(from->margin_left);
445
+ to->margin_top .override(from->margin_top);
446
+ to->margin_right .override(from->margin_right);
447
+ to->margin_bottom .override(from->margin_bottom);
448
+ to->padding_left .override(from->padding_left);
449
+ to->padding_top .override(from->padding_top);
450
+ to->padding_right .override(from->padding_right);
451
+ to->padding_bottom .override(from->padding_bottom);
452
+ to->center_x .override(from->center_x);
453
+ to->center_y .override(from->center_y);
454
+ to->fore_fill .override(from->fore_fill);
455
+ to->fore_stroke .override(from->fore_stroke);
456
+ to->fore_stroke_width.override(from->fore_stroke_width);
457
+ to->back_fill .override(from->back_fill);
458
+ to->back_stroke .override(from->back_stroke);
459
+ to->back_stroke_width.override(from->back_stroke_width);
460
+ to->image .override(from->image);
429
461
  }
430
462
 
431
-
432
- Style::Style (const char* name)
463
+ bool
464
+ StyleLength_get_pixel_length (
465
+ coord* pixel_length, const StyleLength& style_length, coord parent_size)
433
466
  {
434
- if (name) set_name(name);
435
- }
467
+ assert(pixel_length);
436
468
 
437
- Style::~Style ()
438
- {
439
- }
469
+ if (!style_length)
470
+ return false;
440
471
 
441
- void
442
- Style::set_name (const char* name)
443
- {
444
- update_owner(*this);
472
+ coord old_length = *pixel_length;
445
473
 
446
- self->selector.set_name(name);
474
+ StyleLength::Value value = style_length.value();
475
+ switch (style_length.type())
476
+ {
477
+ case StyleLength::PIXEL:
478
+ *pixel_length = value;
479
+ break;
447
480
 
448
- update_owner(*this);
449
- }
481
+ case StyleLength::PERCENT:
482
+ *pixel_length =
483
+ (value == 100) ? parent_size : floor(parent_size * value / 100);
484
+ break;
450
485
 
451
- const char*
452
- Style::name () const
453
- {
454
- return self->selector.name();
486
+ case StyleLength::FILL:
487
+ break;
488
+
489
+ default:
490
+ invalid_state_error(__FILE__, __LINE__);
491
+ }
492
+
493
+ return *pixel_length != old_length;
455
494
  }
456
495
 
457
- void
458
- Style::add_tag (const char* tag)
496
+ static void
497
+ update_frame (View* view, const Style& style)
459
498
  {
460
- update_owner(*this);
499
+ assert(view);
461
500
 
462
- self->selector.add_tag(tag);
501
+ View* parent = view->parent();
502
+ if (!parent) return;
463
503
 
464
- update_owner(*this);
504
+ Bounds frame = view->frame();
505
+ const Bounds& parent_frame = parent->frame();
506
+
507
+ bool update = false;
508
+ update |=
509
+ StyleLength_get_pixel_length(&frame.w, style.width(), parent_frame.w);
510
+ update |=
511
+ StyleLength_get_pixel_length(&frame.h, style.height(), parent_frame.h);
512
+
513
+ if (update)
514
+ View_set_frame(view, frame);
465
515
  }
466
516
 
467
517
  void
468
- Style::remove_tag (const char* tag)
518
+ Style_apply_to (const Style& style, View* view)
469
519
  {
470
- update_owner(*this);
520
+ assert(view);
471
521
 
472
- self->selector.remove_tag(tag);
522
+ //update_margin(view, values);
523
+ //update_padding(view, values);
524
+ update_frame(view, style);
525
+ //update_background(view, values);
526
+ }
473
527
 
474
- update_owner(*this);
528
+ bool
529
+ Style_has_width (const Style& style)
530
+ {
531
+ return style.self->width;
475
532
  }
476
533
 
477
- Selector::iterator
478
- Style::tag_begin ()
534
+ bool
535
+ Style_has_height (const Style& style)
479
536
  {
480
- return self->selector.begin();
537
+ return style.self->height;
481
538
  }
482
539
 
483
- Selector::const_iterator
484
- Style::tag_begin () const
540
+ static void
541
+ update_owner (const Style& style)
485
542
  {
486
- return self->selector.begin();
543
+ View* owner = style.self->owner;
544
+ if (!owner) return;
545
+
546
+ View_update_styles(owner, style.selector());
487
547
  }
488
548
 
489
- Selector::iterator
490
- Style::tag_end ()
549
+
550
+ Style::Style (const char* name)
491
551
  {
492
- return self->selector.end();
552
+ if (name) set_name(name);
493
553
  }
494
554
 
495
- Selector::const_iterator
496
- Style::tag_end () const
555
+ Style::~Style ()
497
556
  {
498
- return self->selector.end();
499
557
  }
500
558
 
501
559
  void
502
- Style::set_selector (const Selector& selector)
560
+ Style::set_name (const char* name)
503
561
  {
504
562
  update_owner(*this);
563
+ HasSelector::set_name(name);
564
+ update_owner(*this);
565
+ }
505
566
 
506
- self->selector = selector;
567
+ void
568
+ Style::add_tag (const char* tag)
569
+ {
570
+ update_owner(*this);
571
+ HasSelector::add_tag(tag);
572
+ update_owner(*this);
573
+ }
507
574
 
575
+ void
576
+ Style::remove_tag (const char* tag)
577
+ {
578
+ update_owner(*this);
579
+ HasSelector::remove_tag(tag);
508
580
  update_owner(*this);
509
581
  }
510
582
 
511
- Selector&
512
- Style::selector ()
583
+ void
584
+ Style::clear_tags ()
513
585
  {
514
- return self->selector;
586
+ update_owner(*this);
587
+ HasSelector::clear_tags();
588
+ update_owner(*this);
515
589
  }
516
590
 
517
- const Selector&
518
- Style::selector () const
591
+ void
592
+ Style::set_selector (const Selector& selector)
519
593
  {
520
- return self->selector;
594
+ update_owner(*this);
595
+ HasSelector::set_selector(selector);
596
+ update_owner(*this);
521
597
  }
522
598
 
523
599
  enum FlowDir {FLOW_INVALID = 0, FLOW_H, FLOW_V};
@@ -552,6 +628,13 @@ namespace Reflex
552
628
  update_owner(*this);
553
629
  }
554
630
 
631
+ void
632
+ Style::clear_flow ()
633
+ {
634
+ if (self->flow.clear())
635
+ update_owner(*this);
636
+ }
637
+
555
638
  void
556
639
  Style::get_flow (Flow* main, Flow* sub) const
557
640
  {
@@ -576,16 +659,30 @@ namespace Reflex
576
659
  update_owner(*this);
577
660
  }
578
661
 
662
+ void
663
+ Style::clear_width ()
664
+ {
665
+ if (self->width.clear())
666
+ update_owner(*this);
667
+ }
668
+
669
+ void
670
+ Style::clear_height ()
671
+ {
672
+ if (self->height.clear())
673
+ update_owner(*this);
674
+ }
675
+
579
676
  const StyleLength&
580
677
  Style::width () const
581
678
  {
582
- return self->width.get(Zero::length);
679
+ return self->width.get();
583
680
  }
584
681
 
585
682
  const StyleLength&
586
683
  Style::height () const
587
684
  {
588
- return self->height.get(Zero::length);
685
+ return self->height.get();
589
686
  }
590
687
 
591
688
  void
@@ -616,80 +713,56 @@ namespace Reflex
616
713
  update_owner(*this);
617
714
  }
618
715
 
619
- const StyleLength&
620
- Style::left () const
621
- {
622
- return self->left.get(Zero::length);
623
- }
624
-
625
- const StyleLength&
626
- Style::top () const
627
- {
628
- return self->top.get(Zero::length);
629
- }
630
-
631
- const StyleLength&
632
- Style::right () const
633
- {
634
- return self->right.get(Zero::length);
635
- }
636
-
637
- const StyleLength&
638
- Style::bottom () const
639
- {
640
- return self->bottom.get(Zero::length);
641
- }
642
-
643
716
  void
644
- Style::set_offset_left (const StyleLength& left)
717
+ Style::clear_left ()
645
718
  {
646
- if (self->offset_left.set(left))
719
+ if (self->left.clear())
647
720
  update_owner(*this);
648
721
  }
649
722
 
650
723
  void
651
- Style::set_offset_top (const StyleLength& top)
724
+ Style::clear_top ()
652
725
  {
653
- if (self->offset_top.set(top))
726
+ if (self->top.clear())
654
727
  update_owner(*this);
655
728
  }
656
729
 
657
730
  void
658
- Style::set_offset_right (const StyleLength& right)
731
+ Style::clear_right ()
659
732
  {
660
- if (self->offset_right.set(right))
733
+ if (self->right.clear())
661
734
  update_owner(*this);
662
735
  }
663
736
 
664
737
  void
665
- Style::set_offset_bottom (const StyleLength& bottom)
738
+ Style::clear_bottom ()
666
739
  {
667
- if (self->offset_bottom.set(bottom))
740
+ if (self->bottom.clear())
668
741
  update_owner(*this);
669
742
  }
670
743
 
671
744
  const StyleLength&
672
- Style::offset_left () const
745
+ Style::left () const
673
746
  {
674
- return self->offset_left.get(Zero::length);
747
+ return self->left.get();
675
748
  }
676
749
 
677
750
  const StyleLength&
678
- Style::offset_top () const
751
+ Style::top () const
679
752
  {
680
- return self->offset_top.get(Zero::length);
753
+ return self->top.get();
681
754
  }
682
755
 
683
756
  const StyleLength&
684
- Style::offset_right () const
757
+ Style::right () const
685
758
  {
686
- return self->offset_right.get(Zero::length);
759
+ return self->right.get();
687
760
  }
688
761
 
689
762
  const StyleLength&
690
- Style::offset_bottom () const
763
+ Style::bottom () const
691
764
  {
692
- return self->offset_bottom.get(Zero::length);
765
+ return self->bottom.get();
693
766
  }
694
767
 
695
768
  void
@@ -720,28 +793,56 @@ namespace Reflex
720
793
  update_owner(*this);
721
794
  }
722
795
 
796
+ void
797
+ Style::clear_margin_left ()
798
+ {
799
+ if (self->margin_left.clear())
800
+ update_owner(*this);
801
+ }
802
+
803
+ void
804
+ Style::clear_margin_top ()
805
+ {
806
+ if (self->margin_top.clear())
807
+ update_owner(*this);
808
+ }
809
+
810
+ void
811
+ Style::clear_margin_right ()
812
+ {
813
+ if (self->margin_right.clear())
814
+ update_owner(*this);
815
+ }
816
+
817
+ void
818
+ Style::clear_margin_bottom ()
819
+ {
820
+ if (self->margin_bottom.clear())
821
+ update_owner(*this);
822
+ }
823
+
723
824
  const StyleLength&
724
825
  Style::margin_left () const
725
826
  {
726
- return self->margin_left.get(Zero::length);
827
+ return self->margin_left.get();
727
828
  }
728
829
 
729
830
  const StyleLength&
730
831
  Style::margin_top () const
731
832
  {
732
- return self->margin_top.get(Zero::length);
833
+ return self->margin_top.get();
733
834
  }
734
835
 
735
836
  const StyleLength&
736
837
  Style::margin_right () const
737
838
  {
738
- return self->margin_right.get(Zero::length);
839
+ return self->margin_right.get();
739
840
  }
740
841
 
741
842
  const StyleLength&
742
843
  Style::margin_bottom () const
743
844
  {
744
- return self->margin_bottom.get(Zero::length);
845
+ return self->margin_bottom.get();
745
846
  }
746
847
 
747
848
  void
@@ -772,158 +873,254 @@ namespace Reflex
772
873
  update_owner(*this);
773
874
  }
774
875
 
876
+ void
877
+ Style::clear_padding_left ()
878
+ {
879
+ if (self->padding_left.clear())
880
+ update_owner(*this);
881
+ }
882
+
883
+ void
884
+ Style::clear_padding_top ()
885
+ {
886
+ if (self->padding_top.clear())
887
+ update_owner(*this);
888
+ }
889
+
890
+ void
891
+ Style::clear_padding_right ()
892
+ {
893
+ if (self->padding_right.clear())
894
+ update_owner(*this);
895
+ }
896
+
897
+ void
898
+ Style::clear_padding_bottom ()
899
+ {
900
+ if (self->padding_bottom.clear())
901
+ update_owner(*this);
902
+ }
903
+
775
904
  const StyleLength&
776
905
  Style::padding_left () const
777
906
  {
778
- return self->padding_left.get(Zero::length);
907
+ return self->padding_left.get();
779
908
  }
780
909
 
781
910
  const StyleLength&
782
911
  Style::padding_top () const
783
912
  {
784
- return self->padding_top.get(Zero::length);
913
+ return self->padding_top.get();
785
914
  }
786
915
 
787
916
  const StyleLength&
788
917
  Style::padding_right () const
789
918
  {
790
- return self->padding_right.get(Zero::length);
919
+ return self->padding_right.get();
791
920
  }
792
921
 
793
922
  const StyleLength&
794
923
  Style::padding_bottom () const
795
924
  {
796
- return self->padding_bottom.get(Zero::length);
925
+ return self->padding_bottom.get();
797
926
  }
798
927
 
799
928
  void
800
- Style::set_fill (const Color& fill)
929
+ Style::set_center_x (const StyleLength& x)
801
930
  {
802
- if (self->fill.set(fill))
931
+ if (self->center_x.set(x))
803
932
  update_owner(*this);
804
933
  }
805
934
 
806
- const Color&
807
- Style::fill () const
935
+ void
936
+ Style::set_center_y (const StyleLength& y)
808
937
  {
809
- return self->fill.get(Zero::color);
938
+ if (self->center_y.set(y))
939
+ update_owner(*this);
810
940
  }
811
941
 
812
942
  void
813
- Style::set_stroke (const Color& stroke)
943
+ Style::clear_center_x ()
814
944
  {
815
- if (self->stroke.set(stroke))
945
+ if (self->center_x.clear())
816
946
  update_owner(*this);
817
947
  }
818
948
 
819
- const Color&
820
- Style::stroke () const
949
+ void
950
+ Style::clear_center_y ()
821
951
  {
822
- return self->stroke.get(Zero::color);
952
+ if (self->center_y.clear())
953
+ update_owner(*this);
954
+ }
955
+
956
+ const StyleLength&
957
+ Style::center_x () const
958
+ {
959
+ return self->center_x.get();
960
+ }
961
+
962
+ const StyleLength&
963
+ Style::center_y () const
964
+ {
965
+ return self->center_y.get();
823
966
  }
824
967
 
825
968
  void
826
- Style::set_image (const Image& image)
969
+ Style::set_foreground_fill (const Color& fill)
827
970
  {
828
- if (self->image.set(image))
971
+ if (self->fore_fill.set(fill))
829
972
  update_owner(*this);
830
973
  }
831
974
 
832
- const Image&
833
- Style::image () const
975
+ void
976
+ Style::set_foreground_stroke (const Color& stroke)
834
977
  {
835
- return self->image.get(Zero::image);
978
+ if (self->fore_stroke.set(stroke))
979
+ update_owner(*this);
836
980
  }
837
981
 
838
- bool
839
- operator == (const Style& lhs, const Style& rhs)
982
+ void
983
+ Style::set_foreground_stroke_width (coord width)
840
984
  {
841
- return lhs.self.get() == rhs.self.get();
985
+ if (self->fore_stroke_width.set(width))
986
+ update_owner(*this);
842
987
  }
843
988
 
844
- bool
845
- operator != (const Style& lhs, const Style& rhs)
989
+ void
990
+ Style::set_background_fill (const Color& fill)
846
991
  {
847
- return !operator==(lhs, rhs);
992
+ if (self->back_fill.set(fill))
993
+ update_owner(*this);
848
994
  }
849
995
 
996
+ void
997
+ Style::set_background_stroke (const Color& stroke)
998
+ {
999
+ if (self->back_stroke.set(stroke))
1000
+ update_owner(*this);
1001
+ }
850
1002
 
851
- static bool
852
- get_pixel_length (
853
- coord* pixel_length,
854
- const StyleLength& style_length, const coord* parent_size)
1003
+ void
1004
+ Style::set_background_stroke_width (coord width)
855
1005
  {
856
- if (!pixel_length)
857
- argument_error(__FILE__, __LINE__);
1006
+ if (self->back_stroke_width.set(width))
1007
+ update_owner(*this);
1008
+ }
858
1009
 
859
- if (!style_length)
860
- return false;
1010
+ void
1011
+ Style::clear_foreground_fill ()
1012
+ {
1013
+ if (self->fore_fill.clear())
1014
+ update_owner(*this);
1015
+ }
861
1016
 
862
- coord length = 0;
863
- StyleLength::Value value = style_length.value();
864
- switch (style_length.unit())
865
- {
866
- case StyleLength::PIXEL:
867
- length = value;
868
- break;
1017
+ void
1018
+ Style::clear_foreground_stroke ()
1019
+ {
1020
+ if (self->fore_stroke.clear())
1021
+ update_owner(*this);
1022
+ }
869
1023
 
870
- case StyleLength::PERCENT:
871
- {
872
- if (!parent_size)
873
- argument_error(__FILE__, __LINE__);
1024
+ void
1025
+ Style::clear_foreground_stroke_width ()
1026
+ {
1027
+ if (self->fore_stroke_width.clear())
1028
+ update_owner(*this);
1029
+ }
874
1030
 
875
- length = (value == 100) ?
876
- *parent_size : floor(*parent_size * value / 100);
877
- break;
878
- }
1031
+ void
1032
+ Style::clear_background_fill ()
1033
+ {
1034
+ if (self->back_fill.clear())
1035
+ update_owner(*this);
1036
+ }
879
1037
 
880
- default:
881
- invalid_state_error(__FILE__, __LINE__);
882
- }
1038
+ void
1039
+ Style::clear_background_stroke ()
1040
+ {
1041
+ if (self->back_stroke.clear())
1042
+ update_owner(*this);
1043
+ }
883
1044
 
884
- if (length == *pixel_length)
885
- return false;
1045
+ void
1046
+ Style::clear_background_stroke_width ()
1047
+ {
1048
+ if (self->back_stroke_width.clear())
1049
+ update_owner(*this);
1050
+ }
886
1051
 
887
- *pixel_length = length;
888
- return true;
1052
+ const Color&
1053
+ Style::foreground_fill () const
1054
+ {
1055
+ return self->fore_fill.get();
889
1056
  }
890
1057
 
891
- static void
892
- update_frame (View* view, const Style& style)
1058
+ const Color&
1059
+ Style::foreground_stroke () const
893
1060
  {
894
- assert(view);
895
- Style::Data* s = style.self.get();
1061
+ return self->fore_stroke.get();
1062
+ }
896
1063
 
897
- Bounds frame = view->frame();
898
- View* parent_view = view->parent();
899
- const Bounds* parent = parent_view ? &parent_view->frame() : NULL;
900
- bool update = false;
1064
+ coord
1065
+ Style::foreground_stroke_width () const
1066
+ {
1067
+ return self->fore_stroke_width.get();
1068
+ }
901
1069
 
902
- if (s->width)
903
- {
904
- update |= get_pixel_length(
905
- &frame.width, s->width.value(), parent ? &parent->width : NULL);
906
- }
1070
+ const Color&
1071
+ Style::background_fill () const
1072
+ {
1073
+ return self->back_fill.get();
1074
+ }
907
1075
 
908
- if (s->height) {
909
- update |= get_pixel_length(
910
- &frame.height, s->height.value(), parent ? &parent->height : NULL);
911
- }
1076
+ const Color&
1077
+ Style::background_stroke () const
1078
+ {
1079
+ return self->back_stroke.get();
1080
+ }
912
1081
 
913
- if (update)
914
- view->set_frame(frame);
1082
+ coord
1083
+ Style::background_stroke_width () const
1084
+ {
1085
+ return self->back_stroke_width.get();
915
1086
  }
916
1087
 
917
1088
  void
918
- apply_style (View* view, const Style& style)
1089
+ Style::set_image (const Image& image)
919
1090
  {
920
- if (!view)
921
- argument_error(__FILE__, __LINE__);
1091
+ if (self->image.set(image))
1092
+ update_owner(*this);
1093
+ }
922
1094
 
923
- //update_margin(view, values);
924
- //update_padding(view, values);
925
- update_frame(view, style);
926
- //update_background(view, values);
1095
+ void
1096
+ Style::clear_image ()
1097
+ {
1098
+ if (self->image.clear())
1099
+ update_owner(*this);
1100
+ }
1101
+
1102
+ const Image&
1103
+ Style::image () const
1104
+ {
1105
+ return self->image.get();
1106
+ }
1107
+
1108
+ bool
1109
+ operator == (const Style& lhs, const Style& rhs)
1110
+ {
1111
+ return lhs.self.get() == rhs.self.get();
1112
+ }
1113
+
1114
+ bool
1115
+ operator != (const Style& lhs, const Style& rhs)
1116
+ {
1117
+ return !operator==(lhs, rhs);
1118
+ }
1119
+
1120
+ SelectorPtr*
1121
+ Style::get_selector_ptr ()
1122
+ {
1123
+ return &self->pselector;
927
1124
  }
928
1125
 
929
1126