reflexion 0.1.8 → 0.1.9

Sign up to get free protection for your applications and to get access to all the features.
Files changed (64) hide show
  1. checksums.yaml +4 -4
  2. data/.doc/ext/reflex/application.cpp +5 -1
  3. data/.doc/ext/reflex/arc_shape.cpp +89 -0
  4. data/.doc/ext/reflex/body.cpp +91 -12
  5. data/.doc/ext/reflex/contact_event.cpp +90 -0
  6. data/.doc/ext/reflex/ellipse_shape.cpp +89 -0
  7. data/.doc/ext/reflex/image_view.cpp +0 -16
  8. data/.doc/ext/reflex/native.cpp +18 -6
  9. data/.doc/ext/reflex/rect_shape.cpp +83 -0
  10. data/.doc/ext/reflex/shape_view.cpp +153 -0
  11. data/.doc/ext/reflex/view.cpp +63 -26
  12. data/.doc/ext/reflex/window.cpp +5 -1
  13. data/VERSION +1 -1
  14. data/ext/reflex/application.cpp +6 -2
  15. data/ext/reflex/arc_shape.cpp +94 -0
  16. data/ext/reflex/body.cpp +101 -13
  17. data/ext/reflex/contact_event.cpp +95 -0
  18. data/ext/reflex/ellipse_shape.cpp +94 -0
  19. data/ext/reflex/image_view.cpp +0 -18
  20. data/ext/reflex/native.cpp +18 -6
  21. data/ext/reflex/rect_shape.cpp +86 -0
  22. data/ext/reflex/shape_view.cpp +161 -0
  23. data/ext/reflex/view.cpp +71 -30
  24. data/ext/reflex/window.cpp +5 -1
  25. data/include/reflex/body.h +42 -12
  26. data/include/reflex/event.h +27 -1
  27. data/include/reflex/fixture.h +6 -5
  28. data/include/reflex/image_view.h +5 -5
  29. data/include/reflex/ruby/application.h +27 -6
  30. data/include/reflex/ruby/event.h +11 -0
  31. data/include/reflex/ruby/shape_view.h +96 -0
  32. data/include/reflex/ruby/view.h +60 -5
  33. data/include/reflex/ruby/window.h +12 -3
  34. data/include/reflex/shape_view.h +146 -0
  35. data/include/reflex/view.h +17 -5
  36. data/lib/reflex/application.rb +9 -9
  37. data/lib/reflex/body.rb +2 -0
  38. data/lib/reflex/contact_event.rb +38 -0
  39. data/lib/reflex/image_view.rb +1 -1
  40. data/lib/reflex/shape_view.rb +25 -0
  41. data/lib/reflex/view.rb +19 -9
  42. data/lib/reflex/window.rb +11 -10
  43. data/lib/reflex.rb +15 -13
  44. data/lib/reflexion.rb +25 -18
  45. data/samples/osx/hello/hello/main.cpp +6 -0
  46. data/samples/physics.rb +22 -12
  47. data/samples/reflexion/breakout.rb +52 -0
  48. data/samples/reflexion/hello.rb +5 -7
  49. data/samples/reflexion/paint.rb +10 -11
  50. data/samples/reflexion/physics.rb +28 -0
  51. data/samples/reflexion/pulse.rb +10 -8
  52. data/samples/shapes.rb +2 -2
  53. data/src/body.cpp +241 -40
  54. data/src/event.cpp +32 -2
  55. data/src/shape_view.cpp +306 -0
  56. data/src/view.cpp +232 -66
  57. data/src/world.cpp +110 -30
  58. data/src/world.h +61 -14
  59. metadata +24 -7
  60. data/lib/reflex/arc_shape.rb +0 -20
  61. data/lib/reflex/ellipse_shape.rb +0 -20
  62. data/lib/reflex/line_shape.rb +0 -20
  63. data/lib/reflex/rect_shape.rb +0 -20
  64. data/lib/reflex/shape.rb +0 -34
@@ -0,0 +1,306 @@
1
+ #include "reflex/shape_view.h"
2
+
3
+
4
+ #include <assert.h>
5
+ #include "reflex/exception.h"
6
+ #include "reflex/body.h"
7
+
8
+
9
+ namespace Reflex
10
+ {
11
+
12
+
13
+ struct ShapeView::Data
14
+ {
15
+
16
+ Color fill, stroke;
17
+
18
+ Data ()
19
+ : fill(1, 1), stroke(0, 0)
20
+ {
21
+ }
22
+
23
+ };// ShapeView::Data
24
+
25
+
26
+ ShapeView::ShapeView (const char* name)
27
+ : Super(name)
28
+ {
29
+ }
30
+
31
+ ShapeView::~ShapeView ()
32
+ {
33
+ }
34
+
35
+ void
36
+ ShapeView::set_fill (float red, float green, float blue, float alpha)
37
+ {
38
+ self->fill.reset(red, green, blue, alpha);
39
+ }
40
+
41
+ void
42
+ ShapeView::set_fill (const Color& color)
43
+ {
44
+ self->fill = color;
45
+ }
46
+
47
+ void
48
+ ShapeView::no_fill ()
49
+ {
50
+ self->fill.alpha = 0;
51
+ }
52
+
53
+ const Color&
54
+ ShapeView::fill () const
55
+ {
56
+ return self->fill;
57
+ }
58
+
59
+ void
60
+ ShapeView::set_stroke (float red, float green, float blue, float alpha)
61
+ {
62
+ self->stroke.reset(red, green, blue, alpha);
63
+ }
64
+
65
+ void
66
+ ShapeView::set_stroke (const Color& color)
67
+ {
68
+ self->stroke = color;
69
+ }
70
+
71
+ void
72
+ ShapeView::no_stroke ()
73
+ {
74
+ self->stroke.alpha = 0;
75
+ }
76
+
77
+ const Color&
78
+ ShapeView::stroke () const
79
+ {
80
+ return self->stroke;
81
+ }
82
+
83
+ Point
84
+ ShapeView::content_size () const
85
+ {
86
+ return frame().size();
87
+ }
88
+
89
+ void
90
+ ShapeView::on_draw (DrawEvent* e)
91
+ {
92
+ Color& fill = self->fill;
93
+ Color& stroke = self->stroke;
94
+ if (fill.a <= 0 && stroke.a <= 0) return;
95
+
96
+ assert(e && e->painter);
97
+ Painter* p = e->painter;
98
+
99
+ Color f = p->fill(), s = p->stroke();
100
+ p->set_fill(fill);
101
+ p->set_stroke(stroke);
102
+
103
+ on_draw_shape(e);
104
+
105
+ p->set_fill(f);
106
+ p->set_stroke(s);
107
+ }
108
+
109
+ void
110
+ ShapeView::on_draw_shape (DrawEvent* e)
111
+ {
112
+ }
113
+
114
+
115
+ struct RectShape::Data
116
+ {
117
+
118
+ Point round;
119
+
120
+ };// RectView::Data
121
+
122
+
123
+ RectShape::RectShape (const char* name)
124
+ : Super(name)
125
+ {
126
+ }
127
+
128
+ RectShape::~RectShape ()
129
+ {
130
+ }
131
+
132
+ void
133
+ RectShape::set_round (coord round)
134
+ {
135
+ set_round(round, round);
136
+ }
137
+
138
+ void
139
+ RectShape::set_round (coord width, coord height)
140
+ {
141
+ self->round.reset(width, height);
142
+ }
143
+
144
+ void
145
+ RectShape::set_round (const Point& round)
146
+ {
147
+ set_round(round.x, round.y);
148
+ }
149
+
150
+ const Point&
151
+ RectShape::round () const
152
+ {
153
+ return self->round;
154
+ }
155
+
156
+ void
157
+ RectShape::on_draw_shape (DrawEvent* e)
158
+ {
159
+ assert(e && e->painter);
160
+
161
+ const Point& r = self->round;
162
+ e->painter->rect(e->bounds, r.x, r.y);
163
+ }
164
+
165
+
166
+ struct EllipseShape::Data
167
+ {
168
+
169
+ coord radius_min;
170
+
171
+ uint nsegment;
172
+
173
+ Data ()
174
+ : radius_min(0), nsegment(0)
175
+ {
176
+ }
177
+
178
+ };// EllipseView::Data
179
+
180
+
181
+ EllipseShape::EllipseShape (const char* name)
182
+ : Super(name)
183
+ {
184
+ }
185
+
186
+ EllipseShape::~EllipseShape ()
187
+ {
188
+ }
189
+
190
+ void
191
+ EllipseShape::set_radius_min (coord radius)
192
+ {
193
+ self->radius_min = radius;
194
+ }
195
+
196
+ coord
197
+ EllipseShape::radius_min () const
198
+ {
199
+ return self->radius_min;
200
+ }
201
+
202
+ void
203
+ EllipseShape::set_nsegment (uint num_of_segments)
204
+ {
205
+ self->nsegment = num_of_segments;
206
+ }
207
+
208
+ uint
209
+ EllipseShape::nsegment () const
210
+ {
211
+ return self->nsegment;
212
+ }
213
+
214
+ void
215
+ EllipseShape::make_body ()
216
+ {
217
+ Body* b = body();
218
+ if (!b) return;
219
+
220
+ b->clear_fixtures();
221
+
222
+ const Point& size = frame().size();
223
+ b->add_ellipse(size.x, size.y, self->radius_min, self->nsegment);
224
+ }
225
+
226
+ void
227
+ EllipseShape::on_draw_shape (DrawEvent* e)
228
+ {
229
+ assert(e && e->painter);
230
+
231
+ e->painter->ellipse(e->bounds, self->radius_min, self->nsegment);
232
+ }
233
+
234
+
235
+ struct ArcShape::Data
236
+ {
237
+
238
+ float angle_from, angle_to;
239
+
240
+ Data ()
241
+ : angle_from(0), angle_to(360)
242
+ {
243
+ }
244
+
245
+ };// ArcView::Data
246
+
247
+
248
+ ArcShape::ArcShape (const char* name)
249
+ : Super(name)
250
+ {
251
+ }
252
+
253
+ ArcShape::~ArcShape ()
254
+ {
255
+ }
256
+
257
+ void
258
+ ArcShape::set_angle_from (float degree)
259
+ {
260
+ self->angle_from = degree;
261
+ }
262
+
263
+ float
264
+ ArcShape::angle_from () const
265
+ {
266
+ return self->angle_from;
267
+ }
268
+
269
+ void
270
+ ArcShape::set_angle_to (float degree)
271
+ {
272
+ self->angle_to = degree;
273
+ }
274
+
275
+ float
276
+ ArcShape::angle_to () const
277
+ {
278
+ return self->angle_to;
279
+ }
280
+
281
+ void
282
+ ArcShape::make_body ()
283
+ {
284
+ Body* b = body();
285
+ if (!b) return;
286
+
287
+ b->clear_fixtures();
288
+
289
+ const Point& size = frame().size();
290
+ b->add_arc(
291
+ size.x, size.y, self->angle_from, self->angle_to,
292
+ radius_min(), nsegment());
293
+ }
294
+
295
+ void
296
+ ArcShape::on_draw_shape (DrawEvent* e)
297
+ {
298
+ assert(e && e->painter);
299
+
300
+ e->painter->arc(
301
+ e->bounds, self->angle_from, self->angle_to,
302
+ radius_min(), nsegment());
303
+ }
304
+
305
+
306
+ }// Reflex