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
@@ -133,6 +133,10 @@ static
133
133
  RUCY_DEF1(on_show, event)
134
134
  {
135
135
  CHECK;
136
+
137
+ RUCY_SYM(call_show_block);
138
+ self.call(call_show_block);
139
+
136
140
  CALL(on_show(to<Reflex::Event*>(event)));
137
141
  }
138
142
  RUCY_END
@@ -274,7 +278,7 @@ Init_window ()
274
278
  cWindow.define_method("root", root);
275
279
  cWindow.define_method("focus", focus);
276
280
  cWindow.define_method("painter", painter);
277
- cWindow.define_method("on_show!", on_show);
281
+ cWindow.define_method("on_show", on_show);
278
282
  cWindow.define_method("on_hide", on_hide);
279
283
  cWindow.define_method("on_close", on_close);
280
284
  cWindow.define_method("on_update", on_update);
@@ -4,6 +4,7 @@
4
4
  #define __REFLEX_BODY_H__
5
5
 
6
6
 
7
+ #include <reflex/defs.h>
7
8
  #include <reflex/point.h>
8
9
  #include <reflex/fixture.h>
9
10
 
@@ -19,13 +20,20 @@ namespace Reflex
19
20
 
20
21
  typedef void* Handle;
21
22
 
22
- typedef FixtureIterator< Fixture> iterator;
23
+ typedef FixtureIterator< Fixture, Fixture> iterator;
23
24
 
24
- typedef FixtureIterator<const Fixture> const_iterator;
25
+ typedef FixtureIterator<const Fixture, Fixture> const_iterator;
25
26
 
26
- Fixture add_box (float width, float height);
27
+ Fixture add_box (coord width, coord height);
27
28
 
28
- Fixture add_circle (float size);
29
+ Fixture add_ellipse (
30
+ coord width, coord height,
31
+ coord radius_min = 0, uint nsegment = 0);
32
+
33
+ Fixture add_arc (
34
+ coord width, coord height,
35
+ float angle_from = 0, float angle_to = 360,
36
+ coord radius_min = 0, uint nsegment = 0);
29
37
 
30
38
  Fixture add_edge (const Point& begin, const Point& end);
31
39
 
@@ -35,24 +43,42 @@ namespace Reflex
35
43
 
36
44
  void clear_fixtures ();
37
45
 
38
- Point position () const;
39
-
40
- float angle () const;
46
+ float meter2pixel (float meter = 1) const;
41
47
 
42
48
  void set_static (bool state);
43
49
 
44
50
  bool is_static () const;
45
51
 
46
- void set_dynamic (bool state);
52
+ void set_dynamic (bool state = true);
47
53
 
48
54
  bool is_dynamic () const;
49
55
 
56
+ Point position () const;
57
+
58
+ float angle () const;
59
+
60
+ void set_linear_velocity (coord x, coord y);
61
+
62
+ void set_linear_velocity (const Point& velocity);
63
+
64
+ Point linear_velocity () const;
65
+
66
+ void set_angular_velocity (float velocity);
67
+
68
+ float angular_velocity () const;
69
+
50
70
  void set_density (float density);
51
71
 
72
+ float density () const;
73
+
52
74
  void set_friction (float friction);
53
75
 
76
+ float friction () const;
77
+
54
78
  void set_restitution (float restitution);
55
79
 
80
+ float restitution () const;
81
+
56
82
  iterator begin ();
57
83
 
58
84
  const_iterator begin () const;
@@ -63,15 +89,19 @@ namespace Reflex
63
89
 
64
90
  protected:
65
91
 
66
- Body (Handle h, float scale);
92
+ Body (Handle h, float pixels_per_meter);
67
93
 
68
94
  private:
69
95
 
70
- friend class World;
71
-
72
96
  Handle handle;
73
97
 
74
- float scale;
98
+ float ppm;
99
+
100
+ void set_transform (coord x, coord y, float degree);
101
+
102
+ friend class World;
103
+
104
+ friend class View;
75
105
 
76
106
  };// Body
77
107
 
@@ -74,12 +74,22 @@ namespace Reflex
74
74
  struct {coord dw, dh;};
75
75
  };
76
76
 
77
- FrameEvent (const Bounds& frame = 0, coord dx = 0, coord dy = 0, coord dwidth = 0, coord dheight = 0);
77
+ float angle, dangle;
78
+
79
+ FrameEvent (
80
+ const Bounds& frame = 0, coord dx = 0, coord dy = 0, coord dwidth = 0, coord dheight = 0,
81
+ float angle = 0, float dangle = 0);
82
+
83
+ FrameEvent (
84
+ const Bounds& frame, const Bounds& prev_frame,
85
+ float angle = 0, float prev_angle = 0);
78
86
 
79
87
  bool is_move () const;
80
88
 
81
89
  bool is_resize () const;
82
90
 
91
+ bool is_rotate () const;
92
+
83
93
  };// FrameEvent
84
94
 
85
95
 
@@ -245,6 +255,22 @@ namespace Reflex
245
255
  };// CaptureEvent
246
256
 
247
257
 
258
+ struct ContactEvent : public Event
259
+ {
260
+
261
+ enum Type {NONE = 0, BEGIN, END};
262
+
263
+ Type type;
264
+
265
+ View* view;
266
+
267
+ ContactEvent ();
268
+
269
+ ContactEvent (Type type, View* view);
270
+
271
+ };// ContactEvent
272
+
273
+
248
274
  }// Reflex
249
275
 
250
276
 
@@ -53,8 +53,9 @@ namespace Reflex
53
53
  };// Fixture
54
54
 
55
55
 
56
- template <typename FIXTURE>
57
- class FixtureIterator : public std::iterator<std::forward_iterator_tag, FIXTURE>
56
+ template <typename FIXTURE, typename RAW_FIXTURE>
57
+ class FixtureIterator :
58
+ public std::iterator<std::forward_iterator_tag, FIXTURE>
58
59
  {
59
60
 
60
61
  typedef FixtureIterator This;
@@ -95,17 +96,17 @@ namespace Reflex
95
96
 
96
97
  friend bool operator == (const This& lhs, const This& rhs)
97
98
  {
98
- return lhs == rhs;
99
+ return lhs.fixture == rhs.fixture;
99
100
  }
100
101
 
101
102
  friend bool operator != (const This& lhs, const This& rhs)
102
103
  {
103
- return lhs != rhs;
104
+ return !(lhs == rhs);
104
105
  }
105
106
 
106
107
  private:
107
108
 
108
- FIXTURE fixture;
109
+ RAW_FIXTURE fixture;
109
110
 
110
111
  };// FixtureIterator
111
112
 
@@ -22,15 +22,15 @@ namespace Reflex
22
22
 
23
23
  ImageView (const char* name = NULL);
24
24
 
25
- ~ImageView ();
25
+ virtual ~ImageView ();
26
26
 
27
- void set_image (Image image);
27
+ virtual void set_image (Image image);
28
28
 
29
- Image get_image () const;
29
+ virtual Image get_image () const;
30
30
 
31
- Point content_size () const;
31
+ virtual Point content_size () const;
32
32
 
33
- void on_draw (DrawEvent* e);
33
+ virtual void on_draw (DrawEvent* e);
34
34
 
35
35
  struct Data;
36
36
 
@@ -25,40 +25,61 @@ namespace Reflex
25
25
 
26
26
  public:
27
27
 
28
+ RUCY_OVERRIDE_BEGIN(Rucy::ClassWrapper<T>)
29
+ RUCY_OVERRIDE_END
30
+
28
31
  virtual void start ()
29
32
  {
30
33
  RUCY_SYM(start);
31
- this->value.call(start);
34
+ if (RUCY_IS_OVERRIDABLE())
35
+ this->value.call(start);
36
+ else
37
+ return Super::start();
32
38
  }
33
39
 
34
40
  virtual void quit ()
35
41
  {
36
42
  RUCY_SYM(quit);
37
- this->value.call(quit);
43
+ if (RUCY_IS_OVERRIDABLE())
44
+ this->value.call(quit);
45
+ else
46
+ return Super::quit();
38
47
  }
39
48
 
40
49
  virtual void on_start (Event* e)
41
50
  {
42
51
  RUCY_SYM(on_start);
43
- this->value.call(on_start, Rucy::value(e));
52
+ if (RUCY_IS_OVERRIDABLE())
53
+ this->value.call(on_start, Rucy::value(e));
54
+ else
55
+ return Super::on_start(e);
44
56
  }
45
57
 
46
58
  virtual void on_quit (Event* e)
47
59
  {
48
60
  RUCY_SYM(on_quit);
49
- this->value.call(on_quit, Rucy::value(e));
61
+ if (RUCY_IS_OVERRIDABLE())
62
+ this->value.call(on_quit, Rucy::value(e));
63
+ else
64
+ return Super::on_quit(e);
50
65
  }
51
66
 
52
67
  virtual void on_preference (Event* e)
53
68
  {
54
69
  RUCY_SYM(on_preference);
55
- this->value.call(on_preference, Rucy::value(e));
70
+ if (RUCY_IS_OVERRIDABLE())
71
+ this->value.call(on_preference, Rucy::value(e));
72
+ else
73
+ return Super::on_preference(e);
56
74
  }
57
75
 
58
76
  virtual void on_about (Event* e)
59
77
  {
60
78
  RUCY_SYM(on_about);
61
- this->value.call(on_about, Rucy::value(e));
79
+ if (RUCY_IS_OVERRIDABLE())
80
+ this->value.call(on_about, Rucy::value(e));
81
+ else
82
+ return Super::on_about(e);
62
83
  }
63
84
 
64
85
  };// RubyApplication
@@ -44,6 +44,9 @@ namespace Reflex
44
44
  Rucy::Class capture_event_class ();
45
45
  // class Reflex::CaptureEvent
46
46
 
47
+ Rucy::Class contact_event_class ();
48
+ // class Reflex::ContactEvent
49
+
47
50
 
48
51
  }// Reflex
49
52
 
@@ -68,6 +71,8 @@ RUCY_DECLARE_VALUE_FROM_TO(Reflex::WheelEvent)
68
71
 
69
72
  RUCY_DECLARE_VALUE_FROM_TO(Reflex::CaptureEvent)
70
73
 
74
+ RUCY_DECLARE_VALUE_FROM_TO(Reflex::ContactEvent)
75
+
71
76
 
72
77
  namespace Rucy
73
78
  {
@@ -133,6 +138,12 @@ namespace Rucy
133
138
  return Reflex::capture_event_class();
134
139
  }
135
140
 
141
+ template <> inline Class
142
+ get_ruby_class<Reflex::ContactEvent> ()
143
+ {
144
+ return Reflex::contact_event_class();
145
+ }
146
+
136
147
 
137
148
  }// Rucy
138
149
 
@@ -0,0 +1,96 @@
1
+ // -*- c++ -*-
2
+ #pragma once
3
+ #ifndef __REFLEX_RUBY_SHAPE_VIEW_H__
4
+ #define __REFLEX_RUBY_SHAPE_VIEW_H__
5
+
6
+
7
+ #include <reflex/shape_view.h>
8
+ #include <reflex/ruby/view.h>
9
+
10
+
11
+ namespace Reflex
12
+ {
13
+
14
+
15
+ Rucy::Class shape_view_class ();
16
+ // class Reflex::ShapeView
17
+
18
+ Rucy::Class rect_shape_class ();
19
+ // class Reflex::RectShape
20
+
21
+ Rucy::Class ellipse_shape_class ();
22
+ // class Reflex::EllipseShape
23
+
24
+ Rucy::Class arc_shape_class ();
25
+ // class Reflex::ArcShape
26
+
27
+
28
+ template <typename T>
29
+ class RubyShapeView : public RubyView<T>
30
+ {
31
+
32
+ public:
33
+
34
+ RUCY_OVERRIDE_BEGIN(RubyView<T>)
35
+
36
+ RUCY_OVERRIDE_ID(on_draw_shape)
37
+
38
+ RUCY_OVERRIDE_END
39
+
40
+ virtual void on_draw_shape (DrawEvent* e)
41
+ {
42
+ RUCY_SYM(on_draw_shape);
43
+ if (RUCY_IS_OVERRIDDEN(on_draw_shape))
44
+ this->value.call(on_draw_shape, Rucy::value(e));
45
+ else
46
+ Super::on_draw_shape(e);
47
+ }
48
+
49
+ };// RubyShapeView
50
+
51
+
52
+ }// Reflex
53
+
54
+
55
+ RUCY_DECLARE_WRAPPER_VALUE_FROM_TO(Reflex::ShapeView)
56
+
57
+ RUCY_DECLARE_WRAPPER_VALUE_FROM_TO(Reflex::RectShape)
58
+
59
+ RUCY_DECLARE_WRAPPER_VALUE_FROM_TO(Reflex::EllipseShape)
60
+
61
+ RUCY_DECLARE_WRAPPER_VALUE_FROM_TO(Reflex::ArcShape)
62
+
63
+
64
+ namespace Rucy
65
+ {
66
+
67
+
68
+ template <> inline Class
69
+ get_ruby_class<Reflex::ShapeView> ()
70
+ {
71
+ return Reflex::shape_view_class();
72
+ }
73
+
74
+ template <> inline Class
75
+ get_ruby_class<Reflex::RectShape> ()
76
+ {
77
+ return Reflex::rect_shape_class();
78
+ }
79
+
80
+ template <> inline Class
81
+ get_ruby_class<Reflex::EllipseShape> ()
82
+ {
83
+ return Reflex::ellipse_shape_class();
84
+ }
85
+
86
+ template <> inline Class
87
+ get_ruby_class<Reflex::ArcShape> ()
88
+ {
89
+ return Reflex::arc_shape_class();
90
+ }
91
+
92
+
93
+ }// Rucy
94
+
95
+
96
+ #endif//EOH
@@ -32,6 +32,7 @@ namespace Reflex
32
32
  RUCY_OVERRIDE_ID(on_draw)
33
33
  RUCY_OVERRIDE_ID(on_move)
34
34
  RUCY_OVERRIDE_ID(on_resize)
35
+ RUCY_OVERRIDE_ID(on_rotate)
35
36
  RUCY_OVERRIDE_ID(on_scroll)
36
37
  RUCY_OVERRIDE_ID(on_focus)
37
38
  RUCY_OVERRIDE_ID(on_blur)
@@ -44,6 +45,9 @@ namespace Reflex
44
45
  RUCY_OVERRIDE_ID(on_pointer_move)
45
46
  RUCY_OVERRIDE_ID(on_wheel)
46
47
  RUCY_OVERRIDE_ID(on_capture)
48
+ RUCY_OVERRIDE_ID(on_contact)
49
+ RUCY_OVERRIDE_ID(on_contact_begin)
50
+ RUCY_OVERRIDE_ID(on_contact_end)
47
51
 
48
52
  RUCY_OVERRIDE_END
49
53
 
@@ -62,31 +66,46 @@ namespace Reflex
62
66
  virtual void make_body ()
63
67
  {
64
68
  RUCY_SYM(make_body);
65
- this->value.call(make_body);
69
+ if (RUCY_IS_OVERRIDABLE())
70
+ this->value.call(make_body);
71
+ else
72
+ Super::make_body();
66
73
  }
67
74
 
68
75
  virtual void on_attach (Event* e)
69
76
  {
70
77
  RUCY_SYM(on_attach);
71
- this->value.call(on_attach, Rucy::value(e));
78
+ if (RUCY_IS_OVERRIDABLE())
79
+ this->value.call(on_attach, Rucy::value(e));
80
+ else
81
+ Super::on_attach(e);
72
82
  }
73
83
 
74
84
  virtual void on_detach (Event* e)
75
85
  {
76
86
  RUCY_SYM(on_detach);
77
- this->value.call(on_detach, Rucy::value(e));
87
+ if (RUCY_IS_OVERRIDABLE())
88
+ this->value.call(on_detach, Rucy::value(e));
89
+ else
90
+ Super::on_detach(e);
78
91
  }
79
92
 
80
93
  virtual void on_show (Event* e)
81
94
  {
82
95
  RUCY_SYM(on_show);
83
- this->value.call(on_show, Rucy::value(e));
96
+ if (RUCY_IS_OVERRIDABLE())
97
+ this->value.call(on_show, Rucy::value(e));
98
+ else
99
+ Super::on_show(e);
84
100
  }
85
101
 
86
102
  virtual void on_hide (Event* e)
87
103
  {
88
104
  RUCY_SYM(on_hide);
89
- this->value.call(on_hide, Rucy::value(e));
105
+ if (RUCY_IS_OVERRIDABLE())
106
+ this->value.call(on_hide, Rucy::value(e));
107
+ else
108
+ Super::on_hide(e);
90
109
  }
91
110
 
92
111
  virtual void on_update (UpdateEvent* e)
@@ -125,6 +144,15 @@ namespace Reflex
125
144
  Super::on_resize(e);
126
145
  }
127
146
 
147
+ virtual void on_rotate (FrameEvent* e)
148
+ {
149
+ RUCY_SYM(on_rotate);
150
+ if (RUCY_IS_OVERRIDDEN(on_rotate))
151
+ this->value.call(on_rotate, Rucy::value(e));
152
+ else
153
+ Super::on_rotate(e);
154
+ }
155
+
128
156
  virtual void on_scroll (ScrollEvent* e)
129
157
  {
130
158
  RUCY_SYM(on_scroll);
@@ -233,6 +261,33 @@ namespace Reflex
233
261
  Super::on_capture(e);
234
262
  }
235
263
 
264
+ virtual void on_contact (ContactEvent* e)
265
+ {
266
+ RUCY_SYM(on_contact);
267
+ if (RUCY_IS_OVERRIDDEN(on_contact))
268
+ this->value.call(on_contact, Rucy::value(e));
269
+ else
270
+ Super::on_contact(e);
271
+ }
272
+
273
+ virtual void on_contact_begin (ContactEvent* e)
274
+ {
275
+ RUCY_SYM(on_contact_begin);
276
+ if (RUCY_IS_OVERRIDDEN(on_contact_begin))
277
+ this->value.call(on_contact_begin, Rucy::value(e));
278
+ else
279
+ Super::on_contact_begin(e);
280
+ }
281
+
282
+ virtual void on_contact_end (ContactEvent* e)
283
+ {
284
+ RUCY_SYM(on_contact_end);
285
+ if (RUCY_IS_OVERRIDDEN(on_contact_end))
286
+ this->value.call(on_contact_end, Rucy::value(e));
287
+ else
288
+ Super::on_contact_end(e);
289
+ }
290
+
236
291
  };// RubyView
237
292
 
238
293
 
@@ -45,19 +45,28 @@ namespace Reflex
45
45
  virtual void on_show (Event* e)
46
46
  {
47
47
  RUCY_SYM(on_show);
48
- this->value.call(on_show, Rucy::value(e));
48
+ if (RUCY_IS_OVERRIDABLE())
49
+ this->value.call(on_show, Rucy::value(e));
50
+ else
51
+ return Super::on_show(e);
49
52
  }
50
53
 
51
54
  virtual void on_hide (Event* e)
52
55
  {
53
56
  RUCY_SYM(on_hide);
54
- this->value.call(on_hide, Rucy::value(e));
57
+ if (RUCY_IS_OVERRIDABLE())
58
+ this->value.call(on_hide, Rucy::value(e));
59
+ else
60
+ return Super::on_hide(e);
55
61
  }
56
62
 
57
63
  virtual void on_close (Event* e)
58
64
  {
59
65
  RUCY_SYM(on_close);
60
- this->value.call(on_close, Rucy::value(e));
66
+ if (RUCY_IS_OVERRIDABLE())
67
+ this->value.call(on_close, Rucy::value(e));
68
+ else
69
+ return Super::on_close(e);
61
70
  }
62
71
 
63
72
  virtual void on_update (UpdateEvent* e)