reflexion 0.1.1

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 (74) hide show
  1. data/ChangeLog +8 -0
  2. data/README +4 -0
  3. data/Rakefile +70 -0
  4. data/VERSION +1 -0
  5. data/examples/hello/Rakefile +41 -0
  6. data/examples/hello/main.cpp +18 -0
  7. data/examples/ruby/app.rb +13 -0
  8. data/examples/ruby/checker.rb +41 -0
  9. data/examples/ruby/fps.rb +49 -0
  10. data/examples/ruby/hello.rb +38 -0
  11. data/examples/ruby/key.rb +44 -0
  12. data/examples/ruby/shapes.rb +124 -0
  13. data/examples/ruby/text.rb +35 -0
  14. data/ext/reflex/application.cpp +151 -0
  15. data/ext/reflex/extconf.rb +57 -0
  16. data/ext/reflex/key.cpp +128 -0
  17. data/ext/reflex/native.cpp +22 -0
  18. data/ext/reflex/points.cpp +160 -0
  19. data/ext/reflex/reflex.cpp +83 -0
  20. data/ext/reflex/reflex.h +39 -0
  21. data/ext/reflex/window.cpp +357 -0
  22. data/include/reflex/application.h +50 -0
  23. data/include/reflex/defs.h +258 -0
  24. data/include/reflex/helpers.h +32 -0
  25. data/include/reflex/reflex.h +26 -0
  26. data/include/reflex/ruby/application.h +39 -0
  27. data/include/reflex/ruby/key.h +39 -0
  28. data/include/reflex/ruby/points.h +39 -0
  29. data/include/reflex/ruby/reflex.h +21 -0
  30. data/include/reflex/ruby/window.h +39 -0
  31. data/include/reflex/ruby.h +14 -0
  32. data/include/reflex/window.h +79 -0
  33. data/include/reflex.h +13 -0
  34. data/lib/reflex/application.rb +25 -0
  35. data/lib/reflex/autoinit.rb +11 -0
  36. data/lib/reflex/bounds.rb +133 -0
  37. data/lib/reflex/helpers.rb +52 -0
  38. data/lib/reflex/module.rb +30 -0
  39. data/lib/reflex/point.rb +69 -0
  40. data/lib/reflex/reflex.rb +21 -0
  41. data/lib/reflex/window.rb +65 -0
  42. data/lib/reflex.rb +11 -0
  43. data/reflex.gemspec +57 -0
  44. data/src/cocoa/application.mm +90 -0
  45. data/src/cocoa/applicationdata.h +51 -0
  46. data/src/cocoa/cocoaapplication.h +19 -0
  47. data/src/cocoa/cocoaapplication.mm +180 -0
  48. data/src/cocoa/cocoawindow.h +44 -0
  49. data/src/cocoa/cocoawindow.mm +171 -0
  50. data/src/cocoa/defs.h +34 -0
  51. data/src/cocoa/defs.mm +84 -0
  52. data/src/cocoa/openglview.h +17 -0
  53. data/src/cocoa/openglview.mm +186 -0
  54. data/src/cocoa/reflex.mm +68 -0
  55. data/src/cocoa/window.mm +118 -0
  56. data/src/cocoa/windowdata.h +51 -0
  57. data/src/defs.cpp +47 -0
  58. data/src/win32/defs.cpp +150 -0
  59. data/src/win32/opengl.cpp +95 -0
  60. data/src/win32/opengl.h +50 -0
  61. data/src/win32/reflex.cpp +65 -0
  62. data/src/win32/window.cpp +480 -0
  63. data/src/window.cpp +60 -0
  64. data/support.rb +56 -0
  65. data/task/ext.rake +42 -0
  66. data/task/gem.rake +33 -0
  67. data/task/git.rake +22 -0
  68. data/task/lib.rake +54 -0
  69. data/test/helpers.rb +15 -0
  70. data/test/test_bounds.rb +163 -0
  71. data/test/test_point.rb +81 -0
  72. data/test/test_reflex.rb +17 -0
  73. data/test/test_window.rb +39 -0
  74. metadata +173 -0
@@ -0,0 +1,357 @@
1
+ #include "reflex/ruby/window.h"
2
+
3
+
4
+ #include <rucy.h>
5
+ #include <reflex/ruby/key.h>
6
+ #include <reflex/ruby/points.h>
7
+ #include "reflex.h"
8
+
9
+
10
+ using namespace Rucy;
11
+
12
+ using Reflex::coord;
13
+
14
+
15
+ namespace Reflex
16
+ {
17
+
18
+
19
+ Class
20
+ window_class ()
21
+ {
22
+ static Class c = reflex_module().define_class("Window");
23
+ return c;
24
+ }
25
+
26
+
27
+ }// Reflex
28
+
29
+
30
+ namespace Rucy
31
+ {
32
+
33
+
34
+ Value
35
+ value (const Reflex::Window& window)
36
+ {
37
+ return new_type<Reflex::Window>(
38
+ Reflex::window_class(), new Reflex::Window(window));
39
+ }
40
+
41
+
42
+ }// Rucy
43
+
44
+
45
+ class RubyWindow : public Reflex::Window
46
+ {
47
+
48
+ public:
49
+
50
+ typedef Reflex::Window Super;
51
+
52
+ Value self;
53
+
54
+ void mark ()
55
+ {
56
+ self.mark();
57
+ }
58
+
59
+ virtual bool close ()
60
+ {
61
+ SYM(close);
62
+ return self.call(close);
63
+ }
64
+
65
+ virtual bool show ()
66
+ {
67
+ SYM(show);
68
+ return self.call(show);
69
+ }
70
+
71
+ virtual bool hide ()
72
+ {
73
+ SYM(hide);
74
+ return self.call(hide);
75
+ }
76
+
77
+ virtual void update ()
78
+ {
79
+ SYM(update);
80
+ self.call(update);
81
+ }
82
+
83
+ virtual void draw ()
84
+ {
85
+ SYM(draw);
86
+ self.call(draw);
87
+ }
88
+
89
+ virtual void moved (coord x, coord y)
90
+ {
91
+ SYM(moved);
92
+ self.call(moved, x, y);
93
+ }
94
+
95
+ virtual void resized (coord width, coord height)
96
+ {
97
+ SYM(resized);
98
+ self.call(resized, width, height);
99
+ }
100
+
101
+ virtual void key_down (const Reflex::Key& key)
102
+ {
103
+ SYM(key_down);
104
+ self.call(key_down, value(key));
105
+ }
106
+
107
+ virtual void key_up (const Reflex::Key& key)
108
+ {
109
+ SYM(key_up);
110
+ self.call(key_up, value(key));
111
+ }
112
+
113
+ virtual void points_down (const Reflex::Points& points)
114
+ {
115
+ SYM(points_down);
116
+ self.call(points_down, value(points));
117
+ }
118
+
119
+ virtual void points_up (const Reflex::Points& points)
120
+ {
121
+ SYM(points_up);
122
+ self.call(points_up, value(points));
123
+ }
124
+
125
+ virtual void points_moved (const Reflex::Points& points)
126
+ {
127
+ SYM(points_moved);
128
+ self.call(points_moved, value(points));
129
+ }
130
+
131
+ };// RubyWindow
132
+
133
+
134
+ #define this ((RubyWindow*) to<Reflex::Window*>(self))
135
+
136
+ #define CHECK CHECK_OBJECT(self, RubyWindow, Reflex::window_class())
137
+
138
+
139
+ static
140
+ RUBY_DEF_ALLOC(alloc, klass)
141
+ {
142
+ RubyWindow* win = new RubyWindow;
143
+ return win->self = new_type<RubyWindow>(klass, win, mark_type<RubyWindow>);
144
+ }
145
+ RUBY_END
146
+
147
+ static
148
+ RUBY_DEF0(close)
149
+ {
150
+ CHECK;
151
+ if (!this->Super::close())
152
+ system_error("failed to close window.");
153
+ return self;
154
+ }
155
+ RUBY_END
156
+
157
+ static
158
+ RUBY_DEF0(show)
159
+ {
160
+ CHECK;
161
+ if (!this->Super::show())
162
+ system_error("failed to show window.");
163
+ return self;
164
+ }
165
+ RUBY_END
166
+
167
+ static
168
+ RUBY_DEF0(hide)
169
+ {
170
+ CHECK;
171
+ if (!this->Super::hide())
172
+ system_error("failed to hide window.");
173
+ return self;
174
+ }
175
+ RUBY_END
176
+
177
+ static
178
+ RUBY_DEF0(hidden)
179
+ {
180
+ CHECK;
181
+ return value(this->hidden());
182
+ }
183
+ RUBY_END
184
+
185
+ static
186
+ RUBY_DEF0(update)
187
+ {
188
+ CHECK;
189
+ this->Super::update();
190
+ return self;
191
+ }
192
+ RUBY_END
193
+
194
+ static
195
+ RUBY_DEF0(draw)
196
+ {
197
+ CHECK;
198
+ this->Super::draw();
199
+ return self;
200
+ }
201
+ RUBY_END
202
+
203
+ static
204
+ RUBY_DEF0(redraw)
205
+ {
206
+ CHECK;
207
+ if (!this->Super::redraw())
208
+ system_error("failed to redraw window.");
209
+ return self;
210
+ }
211
+ RUBY_END
212
+
213
+ static
214
+ RUBY_DEF0(get_title)
215
+ {
216
+ CHECK;
217
+ String s;
218
+ if (!this->get_title(&s))
219
+ system_error("failed to get title of window.");
220
+ return value(s.c_str());
221
+ }
222
+ RUBY_END
223
+
224
+ static
225
+ RUBY_DEF1(set_title, title)
226
+ {
227
+ CHECK;
228
+ if (!this->set_title(title.c_str()))
229
+ system_error("failed to set title of window.");
230
+ return title;
231
+ }
232
+ RUBY_END
233
+
234
+ static
235
+ RUBY_DEF0(get_bounds)
236
+ {
237
+ CHECK;
238
+ coord x = 0, y = 0, width = 0, height = 0;
239
+ if (!this->get_bounds(&x, &y, &width, &height))
240
+ system_error("failed to get bounds of window.");
241
+ Value ret[] = {x, y, width, height};
242
+ return value(4, ret);
243
+ }
244
+ RUBY_END
245
+
246
+ static
247
+ RUBY_DEF4(set_bounds, x, y, width, height)
248
+ {
249
+ CHECK;
250
+ if (!this->set_bounds(
251
+ to<coord>(x), to<coord>(y), to<coord>(width), to<coord>(height)))
252
+ {
253
+ system_error("failed to set bounds of window.");
254
+ }
255
+ Value ret[] = {x, y, width, height};
256
+ return value(4, ret);
257
+ }
258
+ RUBY_END
259
+
260
+ static
261
+ RUBY_DEF2(moved, x, y)
262
+ {
263
+ CHECK;
264
+ this->Super::moved(to<coord>(x), to<coord>(y));
265
+ return self;
266
+ }
267
+ RUBY_END
268
+
269
+ static
270
+ RUBY_DEF2(resized, width, height)
271
+ {
272
+ CHECK;
273
+ this->Super::resized(to<coord>(width), to<coord>(height));
274
+ return self;
275
+ }
276
+ RUBY_END
277
+
278
+ static
279
+ RUBY_DEF1(key_down, key)
280
+ {
281
+ CHECK;
282
+ Reflex::Key* k = to<Reflex::Key*>(key);
283
+ if (!k) argument_error();
284
+ this->Super::key_down(*k);
285
+ return self;
286
+ }
287
+ RUBY_END
288
+
289
+ static
290
+ RUBY_DEF1(key_up, key)
291
+ {
292
+ CHECK;
293
+ Reflex::Key* k = to<Reflex::Key*>(key);
294
+ if (!k) argument_error();
295
+ this->Super::key_up(*k);
296
+ return self;
297
+ }
298
+ RUBY_END
299
+
300
+ static
301
+ RUBY_DEF1(points_down, points)
302
+ {
303
+ CHECK;
304
+ Reflex::Points* p = to<Reflex::Points*>(points);
305
+ if (!p) argument_error();
306
+ this->Super::points_down(*p);
307
+ return self;
308
+ }
309
+ RUBY_END
310
+
311
+ static
312
+ RUBY_DEF1(points_up, points)
313
+ {
314
+ CHECK;
315
+ Reflex::Points* p = to<Reflex::Points*>(points);
316
+ if (!p) argument_error();
317
+ this->Super::points_up(*p);
318
+ return self;
319
+ }
320
+ RUBY_END
321
+
322
+ static
323
+ RUBY_DEF1(points_moved, points)
324
+ {
325
+ CHECK;
326
+ Reflex::Points* p = to<Reflex::Points*>(points);
327
+ if (!p) argument_error();
328
+ this->Super::points_moved(*p);
329
+ return self;
330
+ }
331
+ RUBY_END
332
+
333
+
334
+ void
335
+ Init_window ()
336
+ {
337
+ Reflex::window_class()
338
+ .define_alloc_func(alloc)
339
+ .define_method("close", close)
340
+ .define_method("show", show)
341
+ .define_method("hide", hide)
342
+ .define_method("hidden", hidden)
343
+ .define_method("update", update)
344
+ .define_method("draw", draw)
345
+ .define_method("redraw", redraw)
346
+ .define_method("title", get_title)
347
+ .define_method("title=", set_title)
348
+ .define_private_method("get_bounds", get_bounds)
349
+ .define_private_method("set_bounds", set_bounds)
350
+ .define_method("moved", moved)
351
+ .define_method("resized", resized)
352
+ .define_method("key_down", key_down)
353
+ .define_method("key_up", key_up)
354
+ .define_method("points_down", points_down)
355
+ .define_method("points_up", points_up)
356
+ .define_method("points_moved", points_moved);
357
+ }
@@ -0,0 +1,50 @@
1
+ // -*- c++ -*-
2
+ #pragma once
3
+ #ifndef __REFLEX_APPLICATION_H__
4
+ #define __REFLEX_APPLICATION_H__
5
+
6
+
7
+ #include <reflex/defs.h>
8
+ #include <reflex/helpers.h>
9
+
10
+
11
+ namespace Reflex
12
+ {
13
+
14
+
15
+ class Application
16
+ {
17
+
18
+ public:
19
+
20
+ Application ();
21
+
22
+ virtual ~Application ();
23
+
24
+ virtual bool run ();
25
+
26
+ virtual bool quit ();
27
+
28
+ virtual bool preference ();
29
+
30
+ virtual bool about ();
31
+
32
+ virtual bool get_name (String* name) const;
33
+
34
+ virtual bool set_name (const char* name);
35
+
36
+ operator bool () const;
37
+
38
+ bool operator ! () const;
39
+
40
+ struct Data;
41
+
42
+ Impl<Data> self;
43
+
44
+ };// Application
45
+
46
+
47
+ }// Reflex
48
+
49
+
50
+ #endif//EOH
@@ -0,0 +1,258 @@
1
+ // -*- c++ -*-
2
+ #pragma once
3
+ #ifndef __REFLEX_DEFS_H__
4
+ #define __REFLEX_DEFS_H__
5
+
6
+
7
+ #include <string>
8
+ #include <vector>
9
+
10
+
11
+ namespace Reflex
12
+ {
13
+
14
+
15
+ typedef unsigned char uchar;
16
+
17
+ typedef unsigned short ushort;
18
+
19
+ typedef unsigned int uint;
20
+
21
+ typedef unsigned long ulong;
22
+
23
+ typedef float coord;
24
+
25
+ typedef std::string String;
26
+
27
+
28
+ enum {UNKNOWN = 0};
29
+
30
+
31
+ enum KeyCodes
32
+ {
33
+
34
+ KEY_NONE = UNKNOWN,
35
+
36
+ KEY_RETURN,
37
+ KEY_ENTER = KEY_RETURN,
38
+ KEY_ESCAPE,
39
+ KEY_SPACE,
40
+ KEY_BACKSPACE,
41
+ KEY_TAB,
42
+
43
+ KEY_LEFT,
44
+ KEY_UP,
45
+ KEY_RIGHT,
46
+ KEY_DOWN,
47
+
48
+ KEY_INSERT,
49
+ KEY_DELETE,
50
+ KEY_HOME,
51
+ KEY_END,
52
+ KEY_PAGEUP,
53
+ KEY_PAGEDOWN,
54
+
55
+ KEY_SHIFT,
56
+ KEY_LSHIFT,
57
+ KEY_RSHIFT,
58
+
59
+ KEY_CONTROL,
60
+ KEY_LCONTROL,
61
+ KEY_RCONTROL,
62
+
63
+ KEY_ALT,
64
+ KEY_LALT,
65
+ KEY_RALT,
66
+
67
+ KEY_OPTION = KEY_ALT,
68
+ KEY_LOPTION = KEY_LALT,
69
+ KEY_ROPTION = KEY_RALT,
70
+
71
+ KEY_COMMAND,
72
+ KEY_LCOMMAND,
73
+ KEY_RCOMMAND,
74
+
75
+ KEY_WIN,
76
+ KEY_LWIN,
77
+ KEY_RWIN,
78
+
79
+ KEY_CAPSLOCK,
80
+ KEY_NUMLOCK,
81
+ KEY_SCROLLLOCK,
82
+
83
+ KEY_PRINTSCREEN,
84
+ KEY_PAUSE,
85
+
86
+ KEY_KANA,
87
+ KEY_KANJI,
88
+
89
+ KEY_SLEEP,
90
+ KEY_EXECUTE,
91
+ KEY_HELP,
92
+ KEY_PRINT,
93
+ KEY_APPS,
94
+ KEY_SELECT,
95
+ KEY_ACCEPT,
96
+ KEY_CANCEL,
97
+ KEY_CLEAR,
98
+ KEY_FINAL,
99
+ KEY_CONVERT,
100
+ KEY_NONCONVERT,
101
+ KEY_MODECHANGE,
102
+ KEY_JUNJA,
103
+
104
+ KEY_F1,
105
+ KEY_F2,
106
+ KEY_F3,
107
+ KEY_F4,
108
+ KEY_F5,
109
+ KEY_F6,
110
+ KEY_F7,
111
+ KEY_F8,
112
+ KEY_F9,
113
+ KEY_F10,
114
+ KEY_F11,
115
+ KEY_F12,
116
+ KEY_F13,
117
+ KEY_F14,
118
+ KEY_F15,
119
+ KEY_F16,
120
+ KEY_F17,
121
+ KEY_F18,
122
+ KEY_F19,
123
+ KEY_F20,
124
+ KEY_F21,
125
+ KEY_F22,
126
+ KEY_F23,
127
+ KEY_F24,
128
+ KEY_F25,
129
+ KEY_F26,
130
+ KEY_F27,
131
+ KEY_F28,
132
+ KEY_F29,
133
+ KEY_F30,
134
+ KEY_F31,
135
+ KEY_F32,
136
+ KEY_F33,
137
+ KEY_F34,
138
+ KEY_F35,
139
+
140
+ };// KeyCodes
141
+
142
+
143
+ enum PointTypes
144
+ {
145
+
146
+ POINT_NONE = UNKNOWN,
147
+
148
+ POINT_MOUSE_LEFT = 0x1 << 0,
149
+
150
+ POINT_MOUSE_RIGHT = 0x1 << 1,
151
+
152
+ POINT_MOUSE_MIDDLE = 0x1 << 2,
153
+
154
+ POINT_TOUCH = 0x1 << 3,
155
+
156
+ MOUSE_LEFT = POINT_MOUSE_LEFT,
157
+
158
+ MOUSE_RIGHT = POINT_MOUSE_RIGHT,
159
+
160
+ MOUSE_MIDDLE = POINT_MOUSE_MIDDLE
161
+
162
+ };// PointTypes
163
+
164
+
165
+ enum Modifiers
166
+ {
167
+
168
+ MOD_NONE = UNKNOWN,
169
+
170
+ MOD_SHIFT = 0x1 << 0,
171
+
172
+ MOD_CONTROL = 0x1 << 1,
173
+
174
+ MOD_ALT = 0x1 << 2,
175
+
176
+ MOD_OPTION = MOD_ALT,
177
+
178
+ MOD_COMMAND = 0x1 << 3,
179
+
180
+ MOD_HELP = 0x1 << 4,
181
+
182
+ MOD_FUNCTION = 0x1 << 5,
183
+
184
+ MOD_NUMPAD = 0x1 << 6,
185
+
186
+ MOD_CAPS = 0x1 << 7,
187
+
188
+ };// Modifiers
189
+
190
+
191
+ struct Key
192
+ {
193
+
194
+ String chars;
195
+
196
+ int code, repeat;
197
+
198
+ uint modifiers;
199
+
200
+ Key ();
201
+
202
+ Key (
203
+ const char* chars, int code,
204
+ uint modifiers = 0, int repeat = 0);
205
+
206
+ };// Key
207
+
208
+
209
+ struct Points
210
+ {
211
+
212
+ struct Point
213
+ {
214
+
215
+ coord x, y;
216
+
217
+ };// Point
218
+
219
+ enum {MAX = 10};
220
+
221
+ int type;
222
+
223
+ size_t size;
224
+
225
+ uint modifiers, count;
226
+
227
+ bool drag;
228
+
229
+ union
230
+ {
231
+
232
+ struct {coord x, y;};
233
+
234
+ Point points[MAX];
235
+
236
+ };
237
+
238
+ Points ();
239
+
240
+ Points (
241
+ int type, coord x, coord y,
242
+ uint modifiers = 0, uint count = 1, bool drag = false);
243
+
244
+ Points (
245
+ int type, const Point* points, size_t size,
246
+ uint modifiers = 0, uint count = 1, bool drag = false);
247
+
248
+ Point& operator [] (size_t i) {return points[i];}
249
+
250
+ const Point& operator [] (size_t i) const {return points[i];}
251
+
252
+ };// Points
253
+
254
+
255
+ }// Reflex
256
+
257
+
258
+ #endif//EOH
@@ -0,0 +1,32 @@
1
+ // -*- c++ -*-
2
+ #pragma once
3
+ #ifndef __REFLEX_HELPERS_H__
4
+ #define __REFLEX_HELPERS_H__
5
+
6
+
7
+ #include <boost/shared_ptr.hpp>
8
+
9
+
10
+ namespace Reflex
11
+ {
12
+
13
+
14
+ template <typename T>
15
+ class Impl : public boost::shared_ptr<T>
16
+ {
17
+
18
+ typedef boost::shared_ptr<T> Super;
19
+
20
+ public:
21
+
22
+ Impl () : Super(new T) {}
23
+
24
+ Impl (T* p) : Super(p) {}
25
+
26
+ };// Impl
27
+
28
+
29
+ }// Reflex
30
+
31
+
32
+ #endif//EOH
@@ -0,0 +1,26 @@
1
+ // -*- c++ -*-
2
+ #pragma once
3
+ #ifndef __REFLEX_REFLEX_H__
4
+ #define __REFLEX_REFLEX_H__
5
+
6
+
7
+ #include <stddef.h>
8
+
9
+
10
+ namespace Reflex
11
+ {
12
+
13
+
14
+ bool init ();
15
+
16
+ bool fin ();
17
+
18
+ bool run (const char* name = NULL);
19
+
20
+ bool quit ();
21
+
22
+
23
+ }// Reflex
24
+
25
+
26
+ #endif//EOH