reflexion 0.1.14 → 0.1.20

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 (48) hide show
  1. checksums.yaml +4 -4
  2. data/.doc/ext/reflex/capture_event.cpp +4 -5
  3. data/.doc/ext/reflex/contact_event.cpp +4 -7
  4. data/.doc/ext/reflex/draw_event.cpp +3 -4
  5. data/.doc/ext/reflex/frame_event.cpp +7 -8
  6. data/.doc/ext/reflex/key_event.cpp +7 -8
  7. data/.doc/ext/reflex/motion_event.cpp +3 -5
  8. data/.doc/ext/reflex/pointer_event.cpp +23 -15
  9. data/.doc/ext/reflex/reflex.cpp +3 -1
  10. data/.doc/ext/reflex/scroll_event.cpp +8 -9
  11. data/.doc/ext/reflex/update_event.cpp +4 -5
  12. data/.doc/ext/reflex/wheel_event.cpp +5 -6
  13. data/VERSION +1 -1
  14. data/ext/reflex/capture_event.cpp +3 -4
  15. data/ext/reflex/contact_event.cpp +3 -6
  16. data/ext/reflex/draw_event.cpp +2 -3
  17. data/ext/reflex/frame_event.cpp +6 -7
  18. data/ext/reflex/key_event.cpp +6 -7
  19. data/ext/reflex/motion_event.cpp +2 -4
  20. data/ext/reflex/pointer_event.cpp +22 -14
  21. data/ext/reflex/reflex.cpp +3 -1
  22. data/ext/reflex/scroll_event.cpp +8 -9
  23. data/ext/reflex/update_event.cpp +3 -4
  24. data/ext/reflex/wheel_event.cpp +4 -5
  25. data/include/reflex/defs.h +0 -2
  26. data/include/reflex/event.h +15 -15
  27. data/include/reflex/exception.h +9 -3
  28. data/include/reflex/ruby/event.h +11 -11
  29. data/include/reflex/ruby/reflex.h +1 -0
  30. data/include/reflex/style.h +30 -4
  31. data/lib/reflex.rb +2 -1
  32. data/lib/reflex/camera.rb +13 -0
  33. data/lib/reflex/pointer_event.rb +4 -0
  34. data/reflex.gemspec +4 -4
  35. data/samples/camera.rb +45 -0
  36. data/samples/shapes.rb +16 -0
  37. data/src/event.cpp +7 -7
  38. data/src/ios/view_controller.h +4 -0
  39. data/src/ios/view_controller.mm +22 -34
  40. data/src/osx/native_window.mm +10 -26
  41. data/src/shape.cpp +4 -4
  42. data/src/style.cpp +4 -4
  43. data/src/timer.cpp +3 -6
  44. data/src/view.cpp +2 -2
  45. data/src/window.cpp +27 -0
  46. data/src/window.h +2 -0
  47. data/test/test_pointer_event.rb +79 -34
  48. metadata +15 -13
@@ -20,13 +20,11 @@ RUCY_DEF_ALLOC(alloc, klass)
20
20
  RUCY_END
21
21
 
22
22
  static
23
- RUCY_DEFN(initialize)
23
+ RUCY_DEF1(initialize, gravity)
24
24
  {
25
25
  CHECK;
26
- check_arg_count(__FILE__, __LINE__, "MotionEvent#initialize", argc, 0, 1);
27
26
 
28
- if (argc >= 1)
29
- THIS->gravity = to<Rays::Point>(argv[0]);
27
+ THIS->gravity = to<Rays::Point>(gravity);
30
28
 
31
29
  return rb_call_super(0, NULL);
32
30
  }
@@ -20,19 +20,23 @@ RUCY_DEF_ALLOC(alloc, klass)
20
20
  RUCY_END
21
21
 
22
22
  static
23
- RUCY_DEFN(initialize)
23
+ RUCY_DEF6(initialize, type, pointer_type, modifiers, count, drag, positions)
24
24
  {
25
25
  CHECK;
26
- check_arg_count(__FILE__, __LINE__, "PointerEvent#initialize", argc, 0, 1, 2, 3, 4, 5, 6, 7);
27
26
 
28
- THIS->type = (argc >= 1) ? (Reflex::PointerEvent::Type) to<int>(argv[0]) : Reflex::PointerEvent::NONE;
29
- THIS->pointer_type = (argc >= 2) ? to<uint>(argv[1]) : Reflex::POINTER_NONE;
30
- THIS->x = (argc >= 3) ? to<coord>(argv[2]) : 0;
31
- THIS->y = (argc >= 4) ? to<coord>(argv[3]) : 0;
32
- THIS->size = 1;
33
- THIS->modifiers = (argc >= 5) ? to<uint>(argv[4]) : (uint) Reflex::MOD_NONE;
34
- THIS->count = (argc >= 6) ? to<uint>(argv[5]) : 0;
35
- THIS->drag = (argc >= 7) ? to<bool>(argv[6]) : false;
27
+ int size = positions.size();
28
+ if (size <= 0 || Reflex::PointerEvent::MAX < size)
29
+ argument_error(__FILE__, __LINE__);
30
+
31
+ THIS->type = (Reflex::PointerEvent::Type) to<int>(type);
32
+ THIS->pointer_type = to<uint>(pointer_type);
33
+ THIS->modifiers = to<uint>(modifiers);
34
+ THIS->count = to<uint>(count);
35
+ THIS->drag = to<bool>(drag);
36
+ THIS->size = (size_t) size;
37
+
38
+ for (int i = 0; i < size; ++i)
39
+ THIS->positions[i] = to<Rays::Point>(positions[i]);
36
40
 
37
41
  return rb_call_super(0, NULL);
38
42
  }
@@ -131,10 +135,15 @@ RUCY_DEFN(position)
131
135
  RUCY_END
132
136
 
133
137
  static
134
- RUCY_DEF1(array_get, index)
138
+ RUCY_DEF1(get_at, index)
135
139
  {
136
140
  CHECK;
137
- return value((*THIS)[to<int>(index)]);
141
+
142
+ int i = to<int>(index);
143
+ if (i < 0 || THIS->size <= (size_t) i)
144
+ index_error(__FILE__, __LINE__);
145
+
146
+ return value((*THIS)[i]);
138
147
  }
139
148
  RUCY_END
140
149
 
@@ -160,7 +169,7 @@ Init_pointer_event ()
160
169
  cPointerEvent.define_method("x", x);
161
170
  cPointerEvent.define_method("y", y);
162
171
  cPointerEvent.define_method("position", position);
163
- cPointerEvent.define_method("[]", array_get);
172
+ cPointerEvent.define_method("[]", get_at);
164
173
  cPointerEvent.define_const("TYPE_NONE", Reflex::PointerEvent::NONE);
165
174
  cPointerEvent.define_const("TYPE_DOWN", Reflex::PointerEvent::DOWN);
166
175
  cPointerEvent.define_const("TYPE_UP", Reflex::PointerEvent::UP);
@@ -171,7 +180,6 @@ Init_pointer_event ()
171
180
  cPointerEvent.define_const("POINTER_MOUSE_MIDDLE", Reflex::POINTER_MOUSE_MIDDLE);
172
181
  cPointerEvent.define_const("POINTER_TOUCH", Reflex::POINTER_TOUCH);
173
182
  cPointerEvent.define_const("POINTER_PEN", Reflex::POINTER_PEN);
174
- cPointerEvent.define_const("POINTER_TYPE_LAST", Reflex::POINTER_TYPE_LAST);
175
183
  }
176
184
 
177
185
 
@@ -1,4 +1,6 @@
1
- #include "reflex/reflex.h"
1
+ #include "reflex/ruby/reflex.h"
2
+
3
+
2
4
  #include "reflex/ruby/view.h"
3
5
  #include "reflex/ruby/timer.h"
4
6
  #include "../../src/window.h"
@@ -20,17 +20,16 @@ RUCY_DEF_ALLOC(alloc, klass)
20
20
  RUCY_END
21
21
 
22
22
  static
23
- RUCY_DEFN(initialize)
23
+ RUCY_DEF6(initialize, x, y, z, dx, dy, dz)
24
24
  {
25
25
  CHECK;
26
- check_arg_count(__FILE__, __LINE__, "ScrollEvent#initialize", argc, 0, 1, 2, 3, 4, 5, 6);
27
-
28
- THIS->x = (argc >= 1) ? to<coord>(argv[0]) : 0;
29
- THIS->y = (argc >= 2) ? to<coord>(argv[1]) : 0;
30
- THIS->z = (argc >= 3) ? to<coord>(argv[2]) : 0;
31
- THIS->dx = (argc >= 4) ? to<coord>(argv[3]) : 0;
32
- THIS->dy = (argc >= 5) ? to<coord>(argv[4]) : 0;
33
- THIS->dz = (argc >= 6) ? to<coord>(argv[5]) : 0;
26
+
27
+ THIS->x = to<coord>(x);
28
+ THIS->y = to<coord>(y);
29
+ THIS->z = to<coord>(z);
30
+ THIS->dx = to<coord>(dx);
31
+ THIS->dy = to<coord>(dy);
32
+ THIS->dz = to<coord>(dz);
34
33
 
35
34
  return rb_call_super(0, NULL);
36
35
  }
@@ -19,13 +19,12 @@ RUCY_DEF_ALLOC(alloc, klass)
19
19
  RUCY_END
20
20
 
21
21
  static
22
- RUCY_DEFN(initialize)
22
+ RUCY_DEF2(initialize, now, dt)
23
23
  {
24
24
  CHECK;
25
- check_arg_count(__FILE__, __LINE__, "UpdateEvent#initialize", argc, 0, 1, 2);
26
25
 
27
- THIS->now = (argc >= 1) ? to<double>(argv[0]) : 0;
28
- THIS->dt = (argc >= 2) ? to<float>(argv[1]) : 0;
26
+ THIS->now = to<double>(now);
27
+ THIS->dt = to<float>(dt);
29
28
 
30
29
  return rb_call_super(0, NULL);
31
30
  }
@@ -20,14 +20,13 @@ RUCY_DEF_ALLOC(alloc, klass)
20
20
  RUCY_END
21
21
 
22
22
  static
23
- RUCY_DEFN(initialize)
23
+ RUCY_DEF3(initialize, dx, dy, dz)
24
24
  {
25
25
  CHECK;
26
- check_arg_count(__FILE__, __LINE__, "WheelEvent#initialize", argc, 0, 1, 2, 3);
27
26
 
28
- THIS->dx = (argc >= 1) ? to<coord>(argv[0]) : 0;
29
- THIS->dy = (argc >= 2) ? to<coord>(argv[1]) : 0;
30
- THIS->dz = (argc >= 3) ? to<coord>(argv[2]) : 0;
27
+ THIS->dx = to<coord>(dx);
28
+ THIS->dy = to<coord>(dy);
29
+ THIS->dz = to<coord>(dz);
31
30
 
32
31
  return rb_call_super(0, NULL);
33
32
  }
@@ -215,8 +215,6 @@ namespace Reflex
215
215
 
216
216
  POINTER_PEN = 0x1 << 4,
217
217
 
218
- POINTER_TYPE_LAST = POINTER_PEN,
219
-
220
218
  };// PointType
221
219
 
222
220
 
@@ -37,16 +37,6 @@ namespace Reflex
37
37
  };// Event
38
38
 
39
39
 
40
- struct MotionEvent : public Event
41
- {
42
-
43
- Point gravity;
44
-
45
- MotionEvent (const Point& gravity = Point(0, 9.8));
46
-
47
- };// MotionEvent
48
-
49
-
50
40
  struct UpdateEvent : public Event
51
41
  {
52
42
 
@@ -115,14 +105,14 @@ namespace Reflex
115
105
  {
116
106
  struct {coord x, y, z;};
117
107
 
118
- Rays::Coord3 scroll_;
108
+ Coord3 scroll_;
119
109
  };
120
110
 
121
111
  union
122
112
  {
123
113
  struct {coord dx, dy, dz;};
124
114
 
125
- Rays::Coord3 delta_;
115
+ Coord3 delta_;
126
116
  };
127
117
 
128
118
  ScrollEvent ();
@@ -203,7 +193,7 @@ namespace Reflex
203
193
  {
204
194
  struct {coord x, y, z;};
205
195
 
206
- Rays::Coord3 positions[MAX];
196
+ Coord3 positions[MAX];
207
197
  };
208
198
 
209
199
  PointerEvent ();
@@ -234,14 +224,14 @@ namespace Reflex
234
224
  {
235
225
  struct {coord dx, dy, dz;};
236
226
 
237
- Rays::Coord3 delta_;
227
+ Coord3 delta_;
238
228
  };
239
229
 
240
230
  union
241
231
  {
242
232
  struct {coord x, y, z;};
243
233
 
244
- Rays::Coord3 position_;
234
+ Coord3 position_;
245
235
  };
246
236
 
247
237
  uint modifiers;
@@ -315,6 +305,16 @@ namespace Reflex
315
305
  };// ContactEvent
316
306
 
317
307
 
308
+ struct MotionEvent : public Event
309
+ {
310
+
311
+ Point gravity;
312
+
313
+ MotionEvent (const Point& gravity = Point(0, 9.8));
314
+
315
+ };// MotionEvent
316
+
317
+
318
318
  }// Reflex
319
319
 
320
320
 
@@ -38,11 +38,17 @@ namespace Reflex
38
38
 
39
39
  using namespace Xot::ErrorFunctions;
40
40
 
41
- void reflex_error (const char* file, int line, const char* format = NULL, ...);
41
+ [[noreturn]]
42
+ void reflex_error (
43
+ const char* file, int line, const char* format = NULL, ...);
42
44
 
43
- void layout_error (const char* file, int line, const char* format = NULL, ...);
45
+ [[noreturn]]
46
+ void layout_error (
47
+ const char* file, int line, const char* format = NULL, ...);
44
48
 
45
- void physics_error (const char* file, int line, const char* format = NULL, ...);
49
+ [[noreturn]]
50
+ void physics_error (
51
+ const char* file, int line, const char* format = NULL, ...);
46
52
 
47
53
  }// ErrorFunctions
48
54
 
@@ -17,9 +17,6 @@ namespace Reflex
17
17
  Rucy::Class event_class ();
18
18
  // class Reflex::Event
19
19
 
20
- Rucy::Class motion_event_class ();
21
- // class Reflex::MotionEvent
22
-
23
20
  Rucy::Class update_event_class ();
24
21
  // class Reflex::UpdateEvent
25
22
 
@@ -53,14 +50,15 @@ namespace Reflex
53
50
  Rucy::Class contact_event_class ();
54
51
  // class Reflex::ContactEvent
55
52
 
53
+ Rucy::Class motion_event_class ();
54
+ // class Reflex::MotionEvent
55
+
56
56
 
57
57
  }// Reflex
58
58
 
59
59
 
60
60
  RUCY_DECLARE_VALUE_FROM_TO(Reflex::Event)
61
61
 
62
- RUCY_DECLARE_VALUE_FROM_TO(Reflex::MotionEvent)
63
-
64
62
  RUCY_DECLARE_VALUE_FROM_TO(Reflex::UpdateEvent)
65
63
 
66
64
  RUCY_DECLARE_VALUE_FROM_TO(Reflex::DrawEvent)
@@ -83,6 +81,8 @@ RUCY_DECLARE_VALUE_FROM_TO(Reflex::TimerEvent)
83
81
 
84
82
  RUCY_DECLARE_VALUE_FROM_TO(Reflex::ContactEvent)
85
83
 
84
+ RUCY_DECLARE_VALUE_FROM_TO(Reflex::MotionEvent)
85
+
86
86
 
87
87
  namespace Rucy
88
88
  {
@@ -94,12 +94,6 @@ namespace Rucy
94
94
  return Reflex::event_class();
95
95
  }
96
96
 
97
- template <> inline Class
98
- get_ruby_class<Reflex::MotionEvent> ()
99
- {
100
- return Reflex::motion_event_class();
101
- }
102
-
103
97
  template <> inline Class
104
98
  get_ruby_class<Reflex::UpdateEvent> ()
105
99
  {
@@ -166,6 +160,12 @@ namespace Rucy
166
160
  return Reflex::contact_event_class();
167
161
  }
168
162
 
163
+ template <> inline Class
164
+ get_ruby_class<Reflex::MotionEvent> ()
165
+ {
166
+ return Reflex::motion_event_class();
167
+ }
168
+
169
169
 
170
170
  }// Rucy
171
171
 
@@ -5,6 +5,7 @@
5
5
 
6
6
 
7
7
  #include <rucy/module.h>
8
+ #include <reflex/reflex.h>
8
9
 
9
10
 
10
11
  namespace Reflex
@@ -24,7 +24,22 @@ namespace Reflex
24
24
 
25
25
  typedef coord Value;
26
26
 
27
- enum Type {NONE = 0, PIXEL, PERCENT, FILL, FIT, TYPE_LAST};
27
+ enum Type
28
+ {
29
+
30
+ NONE = 0,
31
+
32
+ PIXEL,
33
+
34
+ PERCENT,
35
+
36
+ FILL,
37
+
38
+ FIT,
39
+
40
+ TYPE_MAX
41
+
42
+ };// Type
28
43
 
29
44
  StyleLength (Type type = NONE, Value value = 0);
30
45
 
@@ -60,9 +75,20 @@ namespace Reflex
60
75
 
61
76
  enum Flow
62
77
  {
63
- FLOW_NONE = 0, FLOW_RIGHT, FLOW_DOWN, FLOW_LEFT, FLOW_UP,
64
- FLOW_LAST
65
- };
78
+
79
+ FLOW_NONE = 0,
80
+
81
+ FLOW_RIGHT,
82
+
83
+ FLOW_DOWN,
84
+
85
+ FLOW_LEFT,
86
+
87
+ FLOW_UP,
88
+
89
+ FLOW_MAX
90
+
91
+ };// Flow
66
92
 
67
93
  Style (const char* name = NULL);
68
94
 
@@ -9,13 +9,14 @@ require 'reflex/bounds'
9
9
  require 'reflex/color'
10
10
  require 'reflex/color_space'
11
11
  require 'reflex/matrix'
12
+ require 'reflex/painter'
12
13
  require 'reflex/polyline'
13
14
  require 'reflex/polygon'
14
15
  require 'reflex/bitmap'
15
16
  require 'reflex/image'
16
17
  require 'reflex/font'
17
18
  require 'reflex/shader'
18
- require 'reflex/painter'
19
+ require 'reflex/camera'
19
20
 
20
21
  require 'reflex/reflex'
21
22
  require 'reflex/helper'
@@ -0,0 +1,13 @@
1
+ # -*- coding: utf-8 -*-
2
+
3
+
4
+ require 'rays/camera'
5
+
6
+
7
+ module Reflex
8
+
9
+
10
+ Camera = Rays::Camera
11
+
12
+
13
+ end# Reflex
@@ -64,6 +64,10 @@ module Reflex
64
64
  (get_pointer_type & POINTER_PEN) != 0
65
65
  end
66
66
 
67
+ def positions ()
68
+ size.times.map {|i| position i}
69
+ end
70
+
67
71
  def inspect ()
68
72
  "#<Reflex::PointerEvent type:#{type}/#{pointer_type} x:#{x} y:#{y} size:#{size} mod:#{modifiers} count:#{count} drag:#{drag?}>"
69
73
  end
@@ -28,10 +28,10 @@ Gem::Specification.new do |s|
28
28
  s.platform = Gem::Platform::RUBY
29
29
  s.required_ruby_version = '~> 2'
30
30
 
31
- s.add_runtime_dependency 'xot', '~> 0.1'
32
- s.add_runtime_dependency 'rucy', '~> 0.1'
33
- s.add_runtime_dependency 'beeps', '~> 0.1'
34
- s.add_runtime_dependency 'rays', '~> 0.1'
31
+ s.add_runtime_dependency 'xot', '~> 0.1.20'
32
+ s.add_runtime_dependency 'rucy', '~> 0.1.20'
33
+ s.add_runtime_dependency 'beeps', '~> 0.1.20'
34
+ s.add_runtime_dependency 'rays', '~> 0.1.20'
35
35
 
36
36
  s.files = `git ls-files`.split $/
37
37
  s.executables = s.files.grep(%r{^bin/}) {|f| File.basename f}
@@ -0,0 +1,45 @@
1
+ # -*- coding: utf-8 -*-
2
+
3
+
4
+ %w[xot rays reflex]
5
+ .map {|s| File.expand_path "../../../#{s}/lib", __FILE__}
6
+ .each {|s| $:.unshift s if !$:.include?(s) && File.directory?(s)}
7
+
8
+ require 'reflex'
9
+
10
+
11
+ class Win < Reflex::Window
12
+ def initialize ()
13
+ super title: "Camera Example", frame: [100, 100, 800, 600]
14
+
15
+ @w = 100
16
+ @h = 200
17
+ @resize_crop = Rays::Camera.new(@w, @h, resize: true, crop: true) {start}
18
+ @crop = Rays::Camera.new(@w, @h, resize: false, crop: true) {start}
19
+ @resize = Rays::Camera.new(@w, @h, resize: true, crop: false) {start}
20
+ @original = Rays::Camera.new(@w, @h, resize: false, crop: false) {start}
21
+ end
22
+
23
+ def on_draw (e)
24
+ p = e.painter
25
+
26
+ p.image @resize_crop.image, @w * 0, 0 if @resize_crop.image
27
+ p.image @crop.image, @w * 1, 0 if @crop.image
28
+ p.image @resize.image, @w * 2, 0 if @resize.image
29
+ p.image @original.image, 0, @h if @original.image
30
+
31
+ p.text "#{e.fps.to_i} FPS", 10, 10
32
+
33
+ p.fill nil
34
+ p.stroke 1
35
+ p.rect 0, 0, @w, @h
36
+ end
37
+
38
+ def on_update (e)
39
+ redraw
40
+ end
41
+ end
42
+
43
+ Reflex.start do
44
+ Win.new.show
45
+ end