reflexion 0.1.6 → 0.1.7

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (225) hide show
  1. checksums.yaml +7 -0
  2. data/.doc/ext/reflex/application.cpp +54 -39
  3. data/.doc/ext/reflex/capture_event.cpp +87 -0
  4. data/.doc/ext/reflex/draw_event.cpp +103 -0
  5. data/.doc/ext/reflex/event.cpp +73 -0
  6. data/.doc/ext/reflex/focus_event.cpp +98 -0
  7. data/.doc/ext/reflex/frame_event.cpp +133 -0
  8. data/.doc/ext/reflex/image_view.cpp +74 -0
  9. data/.doc/ext/reflex/key_event.cpp +124 -0
  10. data/.doc/ext/reflex/native.cpp +45 -6
  11. data/.doc/ext/reflex/pointer_event.cpp +181 -0
  12. data/.doc/ext/reflex/reflex.cpp +17 -41
  13. data/.doc/ext/reflex/scroll_event.cpp +141 -0
  14. data/.doc/ext/reflex/selector.cpp +135 -0
  15. data/.doc/ext/reflex/style.cpp +253 -0
  16. data/.doc/ext/reflex/style_length.cpp +133 -0
  17. data/.doc/ext/reflex/style_length2.cpp +149 -0
  18. data/.doc/ext/reflex/style_length4.cpp +192 -0
  19. data/.doc/ext/reflex/update_event.cpp +77 -0
  20. data/.doc/ext/reflex/view.cpp +408 -88
  21. data/.doc/ext/reflex/wheel_event.cpp +146 -0
  22. data/.doc/ext/reflex/window.cpp +95 -92
  23. data/Rakefile +6 -5
  24. data/VERSION +1 -1
  25. data/ext/reflex/application.cpp +67 -49
  26. data/ext/reflex/capture_event.cpp +92 -0
  27. data/ext/reflex/draw_event.cpp +110 -0
  28. data/ext/reflex/event.cpp +77 -0
  29. data/ext/reflex/extconf.rb +18 -68
  30. data/ext/reflex/focus_event.cpp +104 -0
  31. data/ext/reflex/frame_event.cpp +143 -0
  32. data/ext/reflex/image_view.cpp +77 -0
  33. data/ext/reflex/key_event.cpp +133 -0
  34. data/ext/reflex/native.cpp +45 -6
  35. data/ext/reflex/pointer_event.cpp +195 -0
  36. data/ext/reflex/reflex.cpp +21 -47
  37. data/ext/reflex/scroll_event.cpp +152 -0
  38. data/ext/reflex/selector.cpp +144 -0
  39. data/ext/reflex/style.cpp +277 -0
  40. data/ext/reflex/style_length.cpp +140 -0
  41. data/ext/reflex/style_length2.cpp +157 -0
  42. data/ext/reflex/style_length4.cpp +204 -0
  43. data/ext/reflex/update_event.cpp +81 -0
  44. data/ext/reflex/view.cpp +469 -114
  45. data/ext/reflex/wheel_event.cpp +158 -0
  46. data/ext/reflex/window.cpp +130 -123
  47. data/include/reflex/application.h +12 -7
  48. data/include/reflex/defs.h +13 -89
  49. data/include/reflex/event.h +260 -0
  50. data/include/reflex/exception.h +17 -11
  51. data/include/reflex/image_view.h +45 -0
  52. data/include/reflex/reflex.h +2 -6
  53. data/include/reflex/ruby/application.h +40 -13
  54. data/include/reflex/ruby/event.h +72 -0
  55. data/include/reflex/ruby/image_view.h +25 -0
  56. data/include/reflex/ruby/selector.h +27 -0
  57. data/include/reflex/ruby/style.h +27 -0
  58. data/include/reflex/ruby/style_length.h +37 -0
  59. data/include/reflex/ruby/view.h +193 -38
  60. data/include/reflex/ruby/window.h +123 -39
  61. data/include/reflex/ruby.h +3 -2
  62. data/include/reflex/selector.h +64 -0
  63. data/include/reflex/style.h +144 -0
  64. data/include/reflex/style_length.h +147 -0
  65. data/include/reflex/view.h +182 -19
  66. data/include/reflex/window.h +35 -19
  67. data/include/reflex.h +7 -0
  68. data/lib/reflex/application.rb +14 -5
  69. data/lib/reflex/arc_shape.rb +20 -0
  70. data/lib/reflex/button.rb +75 -0
  71. data/lib/reflex/capture_event.rb +37 -0
  72. data/lib/reflex/color.rb +13 -0
  73. data/lib/reflex/color_space.rb +13 -0
  74. data/lib/reflex/draw_event.rb +19 -0
  75. data/lib/reflex/ellipse_shape.rb +20 -0
  76. data/lib/reflex/ext.rb +1 -1
  77. data/lib/reflex/flags.rb +18 -0
  78. data/lib/reflex/focus_event.rb +38 -0
  79. data/lib/reflex/font.rb +13 -0
  80. data/lib/reflex/frame_event.rb +42 -0
  81. data/lib/reflex/helper.rb +87 -30
  82. data/lib/reflex/image_view.rb +25 -0
  83. data/lib/reflex/key_event.rb +38 -0
  84. data/lib/reflex/line_shape.rb +20 -0
  85. data/lib/reflex/list_view.rb +15 -0
  86. data/lib/reflex/model.rb +149 -0
  87. data/lib/reflex/model_owner.rb +57 -0
  88. data/lib/reflex/model_view.rb +22 -0
  89. data/lib/reflex/module.rb +11 -7
  90. data/lib/reflex/pointer_event.rb +85 -0
  91. data/lib/reflex/rect_shape.rb +20 -0
  92. data/lib/reflex/reflex.rb +13 -2
  93. data/lib/reflex/scroll_event.rb +19 -0
  94. data/lib/reflex/selector.rb +31 -0
  95. data/lib/reflex/shader.rb +13 -0
  96. data/lib/reflex/shape.rb +34 -0
  97. data/lib/reflex/style.rb +55 -0
  98. data/lib/reflex/style_length.rb +30 -0
  99. data/lib/reflex/style_length2.rb +34 -0
  100. data/lib/reflex/style_length4.rb +38 -0
  101. data/lib/reflex/text_view.rb +55 -0
  102. data/lib/reflex/update_event.rb +19 -0
  103. data/lib/reflex/view.rb +38 -4
  104. data/lib/reflex/wheel_event.rb +19 -0
  105. data/lib/reflex/window.rb +7 -5
  106. data/lib/reflex.rb +38 -1
  107. data/lib/reflexion/include.rb +5 -0
  108. data/lib/reflexion.rb +100 -0
  109. data/reflex.gemspec +3 -4
  110. data/samples/app.rb +13 -0
  111. data/samples/bats.rb +91 -0
  112. data/samples/checker.rb +36 -0
  113. data/{examples/ruby/shapes.rb → samples/fans.rb} +12 -16
  114. data/samples/fps.rb +46 -0
  115. data/samples/grid.rb +60 -0
  116. data/{examples/ruby → samples}/hello.rb +14 -16
  117. data/samples/image.rb +44 -0
  118. data/samples/ios/hello/hello/Images.xcassets/AppIcon.appiconset/Contents.json +53 -0
  119. data/samples/ios/hello/hello/Images.xcassets/LaunchImage.launchimage/Contents.json +51 -0
  120. data/samples/ios/hello/hello/en.lproj/InfoPlist.strings +2 -0
  121. data/samples/ios/hello/hello/hello-Info.plist +47 -0
  122. data/samples/ios/hello/hello/hello-Prefix.pch +10 -0
  123. data/samples/ios/hello/hello/main.cpp +79 -0
  124. data/samples/ios/hello/hello.xcodeproj/project.pbxproj +725 -0
  125. data/{examples/ruby → samples}/key.rb +11 -14
  126. data/samples/layout.rb +89 -0
  127. data/samples/model.rb +86 -0
  128. data/samples/osx/hello/hello/Images.xcassets/AppIcon.appiconset/Contents.json +58 -0
  129. data/samples/osx/hello/hello/en.lproj/Credits.rtf +29 -0
  130. data/samples/osx/hello/hello/en.lproj/InfoPlist.strings +2 -0
  131. data/samples/osx/hello/hello/hello-Info.plist +32 -0
  132. data/samples/osx/hello/hello/hello-Prefix.pch +3 -0
  133. data/samples/osx/hello/hello/main.cpp +79 -0
  134. data/samples/osx/hello/hello.xcodeproj/project.pbxproj +725 -0
  135. data/samples/reflexion/hello.rb +24 -0
  136. data/samples/reflexion/paint.rb +40 -0
  137. data/samples/reflexion/pulse.rb +34 -0
  138. data/samples/repl.rb +69 -0
  139. data/samples/shader.rb +41 -0
  140. data/samples/shapes.rb +30 -0
  141. data/{examples/ruby → samples}/text.rb +7 -8
  142. data/samples/tree.rb +71 -0
  143. data/samples/views.rb +41 -0
  144. data/samples/visuals.rb +22 -0
  145. data/src/event.cpp +225 -0
  146. data/src/exception.cpp +24 -15
  147. data/src/image_view.cpp +70 -0
  148. data/src/ios/app_delegate.h +17 -0
  149. data/src/ios/app_delegate.mm +120 -0
  150. data/src/ios/application.mm +116 -0
  151. data/src/{cocoa/applicationdata.h → ios/application_data.h} +6 -6
  152. data/src/ios/event.h +26 -0
  153. data/src/ios/event.mm +31 -0
  154. data/src/ios/native_window.h +37 -0
  155. data/src/ios/native_window.mm +220 -0
  156. data/src/ios/opengl_view.h +13 -0
  157. data/src/ios/opengl_view.mm +131 -0
  158. data/src/{cocoa → ios}/reflex.mm +8 -12
  159. data/src/ios/window.mm +303 -0
  160. data/src/ios/window_data.h +75 -0
  161. data/src/osx/app_delegate.h +17 -0
  162. data/src/{cocoa/cocoaapplication.mm → osx/app_delegate.mm} +90 -48
  163. data/src/osx/application.mm +132 -0
  164. data/src/osx/application_data.h +45 -0
  165. data/src/osx/event.h +42 -0
  166. data/src/osx/event.mm +112 -0
  167. data/src/osx/native_window.h +26 -0
  168. data/src/osx/native_window.mm +322 -0
  169. data/src/{cocoa/openglview.h → osx/opengl_view.h} +0 -4
  170. data/src/{cocoa/openglview.mm → osx/opengl_view.mm} +66 -23
  171. data/src/osx/reflex.mm +50 -0
  172. data/src/osx/window.mm +308 -0
  173. data/src/osx/window_data.h +75 -0
  174. data/src/selector.cpp +121 -0
  175. data/src/style.cpp +576 -0
  176. data/src/style_length.cpp +341 -0
  177. data/src/view.cpp +1228 -129
  178. data/src/win32/application.cpp +1 -1
  179. data/src/window.cpp +54 -26
  180. data/test/helper.rb +8 -4
  181. data/test/test_capture_event.rb +41 -0
  182. data/test/test_event.rb +20 -0
  183. data/test/test_has_frame.rb +45 -0
  184. data/test/test_model.rb +9 -0
  185. data/test/test_model_owner.rb +9 -0
  186. data/test/test_selector.rb +75 -0
  187. data/test/test_style.rb +70 -0
  188. data/test/test_style_length.rb +38 -0
  189. data/test/test_style_length2.rb +50 -0
  190. data/test/test_style_length4.rb +56 -0
  191. data/test/test_view.rb +97 -23
  192. data/test/test_window.rb +54 -46
  193. metadata +205 -84
  194. data/.doc/ext/reflex/defs.cpp +0 -8
  195. data/.doc/ext/reflex/key.cpp +0 -122
  196. data/.doc/ext/reflex/points.cpp +0 -151
  197. data/.gitignore +0 -14
  198. data/ChangeLog +0 -8
  199. data/examples/hello/.gitignore +0 -2
  200. data/examples/hello/Rakefile +0 -41
  201. data/examples/hello/main.cpp +0 -18
  202. data/examples/ruby/app.rb +0 -13
  203. data/examples/ruby/checker.rb +0 -41
  204. data/examples/ruby/fps.rb +0 -49
  205. data/examples/ruby/grid.rb +0 -65
  206. data/examples/ruby/views.rb +0 -88
  207. data/examples/ruby/visuals.rb +0 -27
  208. data/ext/reflex/defs.cpp +0 -8
  209. data/ext/reflex/key.cpp +0 -129
  210. data/ext/reflex/points.cpp +0 -161
  211. data/include/reflex/ruby/key.h +0 -39
  212. data/include/reflex/ruby/points.h +0 -39
  213. data/lib/reflex/visuals/string.rb +0 -53
  214. data/src/cocoa/application.mm +0 -101
  215. data/src/cocoa/cocoaapplication.h +0 -21
  216. data/src/cocoa/cocoawindow.h +0 -46
  217. data/src/cocoa/cocoawindow.mm +0 -230
  218. data/src/cocoa/defs.h +0 -34
  219. data/src/cocoa/defs.mm +0 -87
  220. data/src/cocoa/window.mm +0 -148
  221. data/src/cocoa/windowdata.h +0 -56
  222. data/src/defs.cpp +0 -47
  223. data/src/helper.h +0 -12
  224. data/src/reflex.cpp +0 -43
  225. /data/{README → README.md} +0 -0
@@ -0,0 +1,341 @@
1
+ #include "reflex/style_length.h"
2
+
3
+
4
+ #include <math.h>
5
+ #include <boost/array.hpp>
6
+ #include "reflex/exception.h"
7
+
8
+
9
+ namespace Reflex
10
+ {
11
+
12
+
13
+ struct StyleLength::Data
14
+ {
15
+
16
+ Value value;
17
+
18
+ Unit unit;
19
+
20
+ Data () : value(0), unit(NONE) {}
21
+
22
+ };// StyleLength::Data
23
+
24
+
25
+ StyleLength::StyleLength ()
26
+ {
27
+ }
28
+
29
+ StyleLength::StyleLength (Value value, Unit unit)
30
+ {
31
+ reset(value, unit);
32
+ }
33
+
34
+ StyleLength::StyleLength (const char* str)
35
+ {
36
+ reset(str);
37
+ }
38
+
39
+ StyleLength
40
+ StyleLength::copy () const
41
+ {
42
+ return StyleLength(value(), unit());
43
+ }
44
+
45
+ void
46
+ StyleLength::reset (Value value, Unit unit)
47
+ {
48
+ if (unit != PIXEL) //unit < NONE || UNIT_LAST <= unit)
49
+ argument_error(__FILE__, __LINE__);
50
+
51
+ self->value = value;
52
+ self->unit = unit;
53
+ }
54
+
55
+ static StyleLength::Unit
56
+ str2unit (const char* s)
57
+ {
58
+ if (strcasecmp(s, "px") == 0) return StyleLength::PIXEL;
59
+ else if (strcasecmp(s, "%") == 0) return StyleLength::PERCENT;
60
+ else return StyleLength::NONE;
61
+ }
62
+
63
+ static const char*
64
+ unit2str (StyleLength::Unit unit)
65
+ {
66
+ switch (unit)
67
+ {
68
+ case StyleLength::PIXEL: return "px";
69
+ case StyleLength::PERCENT: return "%";
70
+ default: return NULL;
71
+ }
72
+ }
73
+
74
+ void
75
+ StyleLength::reset (const char* str)
76
+ {
77
+ Value num;
78
+ char suffix[256];
79
+ int count = sscanf(str, "%f%s", &num, suffix);
80
+ if (count != 2)
81
+ argument_error(__FILE__, __LINE__);
82
+
83
+ reset(num, str2unit(suffix));
84
+ }
85
+
86
+ StyleLength::Value
87
+ StyleLength::value () const
88
+ {
89
+ return self->value;
90
+ }
91
+
92
+ StyleLength::Unit
93
+ StyleLength::unit () const
94
+ {
95
+ return self->unit;
96
+ }
97
+
98
+ bool
99
+ StyleLength::get_pixel (coord* pixel, coord parent_size) const
100
+ {
101
+ if (!pixel)
102
+ argument_error(__FILE__, __LINE__);
103
+
104
+ switch (self->unit)
105
+ {
106
+ case PIXEL: *pixel = self->value; break;
107
+ case PERCENT: *pixel = parent_size * self->value; break;
108
+ default: return false;
109
+ }
110
+
111
+ return true;
112
+ }
113
+
114
+ String
115
+ StyleLength::to_s () const
116
+ {
117
+ if (!*this)
118
+ invalid_state_error(__FILE__, __LINE__);
119
+
120
+ String num;
121
+ if (fmod(self->value, 1) == 0)
122
+ num = Xot::stringf("%d", (long) self->value);
123
+ else
124
+ num = Xot::stringf("%g", self->value);
125
+
126
+ const char* suffix = unit2str(self->unit);;
127
+ if (!suffix)
128
+ invalid_state_error(__FILE__, __LINE__);
129
+
130
+ return num + suffix;
131
+ }
132
+
133
+ StyleLength::operator bool () const
134
+ {
135
+ return NONE < self->unit && self->unit < UNIT_LAST;
136
+ }
137
+
138
+ bool
139
+ StyleLength::operator ! () const
140
+ {
141
+ return !operator bool();
142
+ }
143
+
144
+
145
+ struct StyleLength2::Data
146
+ {
147
+
148
+ boost::array<StyleLength, 2> array;
149
+
150
+ };// StyleLength2::Data
151
+
152
+
153
+ StyleLength2::StyleLength2 ()
154
+ {
155
+ }
156
+
157
+ StyleLength2::StyleLength2 (const StyleLength& all)
158
+ {
159
+ StyleLength2& a = *this;
160
+ a[0] = a[1] = all;
161
+ }
162
+
163
+ StyleLength2::StyleLength2 (const StyleLength& width, const StyleLength& height)
164
+ {
165
+ StyleLength2& a = *this;
166
+ a[0] = width;
167
+ a[1] = height;
168
+ }
169
+
170
+ StyleLength2
171
+ StyleLength2::copy () const
172
+ {
173
+ return StyleLength2(width().copy(), height().copy());
174
+ }
175
+
176
+ void
177
+ StyleLength2::set_width (const StyleLength& width)
178
+ {
179
+ (*this)[0] = width;
180
+ }
181
+
182
+ const StyleLength&
183
+ StyleLength2::width () const
184
+ {
185
+ return (*this)[0];
186
+ }
187
+
188
+ void
189
+ StyleLength2::set_height (const StyleLength& height)
190
+ {
191
+ (*this)[1] = height;
192
+ }
193
+
194
+ const StyleLength&
195
+ StyleLength2::height () const
196
+ {
197
+ return (*this)[1];
198
+ }
199
+
200
+ size_t
201
+ StyleLength2::size () const
202
+ {
203
+ return self->array.size();
204
+ }
205
+
206
+ StyleLength&
207
+ StyleLength2::operator [] (size_t i)
208
+ {
209
+ return self->array[i];
210
+ }
211
+
212
+ const StyleLength&
213
+ StyleLength2::operator [] (size_t i) const
214
+ {
215
+ return const_cast<StyleLength2*>(this)->operator[](i);
216
+ }
217
+
218
+
219
+ struct StyleLength4::Data
220
+ {
221
+
222
+ boost::array<StyleLength, 4> array;
223
+
224
+ };// StyleLength4::Data
225
+
226
+
227
+ StyleLength4::StyleLength4 ()
228
+ {
229
+ }
230
+
231
+ StyleLength4::StyleLength4 (const StyleLength& all)
232
+ {
233
+ StyleLength4& a = *this;
234
+ a[0] = a[1] = a[2] = a[3] = all;
235
+ }
236
+
237
+ StyleLength4::StyleLength4 (const StyleLength& horizontal, const StyleLength& vertical)
238
+ {
239
+ StyleLength4& a = *this;
240
+ a[0] = a[2] = horizontal;
241
+ a[1] = a[3] = vertical;
242
+ }
243
+
244
+ StyleLength4::StyleLength4 (
245
+ const StyleLength& left,
246
+ const StyleLength& vertical,
247
+ const StyleLength& right)
248
+ {
249
+ StyleLength4& a = *this;
250
+ a[0] = left;
251
+ a[2] = right;
252
+ a[1] = a[3] = vertical;
253
+ }
254
+
255
+ StyleLength4::StyleLength4 (
256
+ const StyleLength& left,
257
+ const StyleLength& top,
258
+ const StyleLength& right,
259
+ const StyleLength& bottom)
260
+ {
261
+ StyleLength4& a = *this;
262
+ a[0] = left;
263
+ a[1] = top;
264
+ a[2] = right;
265
+ a[3] = bottom;
266
+ }
267
+
268
+ StyleLength4
269
+ StyleLength4::copy () const
270
+ {
271
+ return StyleLength4(left().copy(), top().copy(), right().copy(), bottom().copy());
272
+ }
273
+
274
+ void
275
+ StyleLength4::set_left (const StyleLength& left)
276
+ {
277
+ (*this)[0] = left;
278
+ }
279
+
280
+ const StyleLength&
281
+ StyleLength4::left () const
282
+ {
283
+ return (*this)[0];
284
+ }
285
+
286
+ void
287
+ StyleLength4::set_top (const StyleLength& top)
288
+ {
289
+ (*this)[1] = top;
290
+ }
291
+
292
+ const StyleLength&
293
+ StyleLength4::top () const
294
+ {
295
+ return (*this)[1];
296
+ }
297
+
298
+ void
299
+ StyleLength4::set_right (const StyleLength& right)
300
+ {
301
+ (*this)[2] = right;
302
+ }
303
+
304
+ const StyleLength&
305
+ StyleLength4::right () const
306
+ {
307
+ return (*this)[2];
308
+ }
309
+
310
+ void
311
+ StyleLength4::set_bottom (const StyleLength& bottom)
312
+ {
313
+ (*this)[3] = bottom;
314
+ }
315
+
316
+ const StyleLength&
317
+ StyleLength4::bottom () const
318
+ {
319
+ return (*this)[3];
320
+ }
321
+
322
+ size_t
323
+ StyleLength4::size () const
324
+ {
325
+ return self->array.size();
326
+ }
327
+
328
+ StyleLength&
329
+ StyleLength4::operator [] (size_t i)
330
+ {
331
+ return self->array[i];
332
+ }
333
+
334
+ const StyleLength&
335
+ StyleLength4::operator [] (size_t i) const
336
+ {
337
+ return const_cast<StyleLength4*>(this)->operator[](i);
338
+ }
339
+
340
+
341
+ }// Reflex