reflexion 0.1.2 → 0.1.3

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.
@@ -0,0 +1,343 @@
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 "defs.h"
8
+
9
+
10
+ using namespace Rucy;
11
+
12
+ using Reflex::coord;
13
+
14
+
15
+ namespace Reflex
16
+ {
17
+
18
+
19
+ static Class cWindow;
20
+
21
+ Class
22
+ window_class ()
23
+ {
24
+ return cWindow;
25
+ }
26
+
27
+
28
+ }// Reflex
29
+
30
+
31
+ namespace Rucy
32
+ {
33
+
34
+
35
+ Value
36
+ value (const Reflex::Window& window)
37
+ {
38
+ return new_type<Reflex::Window>(
39
+ Reflex::window_class(), new Reflex::Window(window));
40
+ }
41
+
42
+
43
+ }// Rucy
44
+
45
+
46
+ class RubyWindow : public Reflex::Window
47
+ {
48
+
49
+ public:
50
+
51
+ typedef Reflex::Window Super;
52
+
53
+ Value self;
54
+
55
+ void mark ()
56
+ {
57
+ self.mark();
58
+ }
59
+
60
+ virtual bool close ()
61
+ {
62
+ SYM(close);
63
+ return self.call(close);
64
+ }
65
+
66
+ virtual bool show ()
67
+ {
68
+ SYM(show);
69
+ return self.call(show);
70
+ }
71
+
72
+ virtual bool hide ()
73
+ {
74
+ SYM(hide);
75
+ return self.call(hide);
76
+ }
77
+
78
+ virtual void update ()
79
+ {
80
+ SYM(update);
81
+ self.call(update);
82
+ }
83
+
84
+ virtual void draw ()
85
+ {
86
+ SYM(draw);
87
+ self.call(draw);
88
+ }
89
+
90
+ virtual void moved (coord x, coord y)
91
+ {
92
+ SYM(moved);
93
+ self.call(moved, x, y);
94
+ }
95
+
96
+ virtual void resized (coord width, coord height)
97
+ {
98
+ SYM(resized);
99
+ self.call(resized, width, height);
100
+ }
101
+
102
+ virtual void key_down (const Reflex::Key& key)
103
+ {
104
+ SYM(key_down);
105
+ self.call(key_down, value(key));
106
+ }
107
+
108
+ virtual void key_up (const Reflex::Key& key)
109
+ {
110
+ SYM(key_up);
111
+ self.call(key_up, value(key));
112
+ }
113
+
114
+ virtual void points_down (const Reflex::Points& points)
115
+ {
116
+ SYM(points_down);
117
+ self.call(points_down, value(points));
118
+ }
119
+
120
+ virtual void points_up (const Reflex::Points& points)
121
+ {
122
+ SYM(points_up);
123
+ self.call(points_up, value(points));
124
+ }
125
+
126
+ virtual void points_moved (const Reflex::Points& points)
127
+ {
128
+ SYM(points_moved);
129
+ self.call(points_moved, value(points));
130
+ }
131
+
132
+ };// RubyWindow
133
+
134
+
135
+ #define this ((RubyWindow*) to<Reflex::Window*>(self))
136
+
137
+ #define CHECK CHECK_OBJECT(self, RubyWindow, Reflex::window_class())
138
+
139
+
140
+ static
141
+ VALUE alloc(VALUE klass)
142
+ {
143
+ RubyWindow* win = new RubyWindow;
144
+ return win->self = new_type<RubyWindow>(klass, win, mark_type<RubyWindow>);
145
+ }
146
+
147
+ static
148
+ VALUE close(VALUE self)
149
+ {
150
+ CHECK;
151
+ if (!this->Super::close())
152
+ system_error("failed to close window.");
153
+ return self;
154
+ }
155
+
156
+ static
157
+ VALUE show(VALUE self)
158
+ {
159
+ CHECK;
160
+ if (!this->Super::show())
161
+ system_error("failed to show window.");
162
+ return self;
163
+ }
164
+
165
+ static
166
+ VALUE hide(VALUE self)
167
+ {
168
+ CHECK;
169
+ if (!this->Super::hide())
170
+ system_error("failed to hide window.");
171
+ return self;
172
+ }
173
+
174
+ static
175
+ VALUE hidden(VALUE self)
176
+ {
177
+ CHECK;
178
+ return value(this->hidden());
179
+ }
180
+
181
+ static
182
+ VALUE update(VALUE self)
183
+ {
184
+ CHECK;
185
+ this->Super::update();
186
+ return self;
187
+ }
188
+
189
+ static
190
+ VALUE draw(VALUE self)
191
+ {
192
+ CHECK;
193
+ this->Super::draw();
194
+ return self;
195
+ }
196
+
197
+ static
198
+ VALUE redraw(VALUE self)
199
+ {
200
+ CHECK;
201
+ if (!this->Super::redraw())
202
+ system_error("failed to redraw window.");
203
+ return self;
204
+ }
205
+
206
+ static
207
+ VALUE get_title(VALUE self)
208
+ {
209
+ CHECK;
210
+ String s;
211
+ if (!this->get_title(&s))
212
+ system_error("failed to get title of window.");
213
+ return value(s.c_str());
214
+ }
215
+
216
+ static
217
+ VALUE set_title(VALUE self, VALUE title)
218
+ {
219
+ CHECK;
220
+ if (!this->set_title(title.c_str()))
221
+ system_error("failed to set title of window.");
222
+ return title;
223
+ }
224
+
225
+ static
226
+ VALUE get_bounds(VALUE self)
227
+ {
228
+ CHECK;
229
+ coord x = 0, y = 0, width = 0, height = 0;
230
+ if (!this->get_bounds(&x, &y, &width, &height))
231
+ system_error("failed to get bounds of window.");
232
+ Value ret[] = {x, y, width, height};
233
+ return value(4, ret);
234
+ }
235
+
236
+ static
237
+ VALUE set_bounds(VALUE self, VALUE x, VALUE y, VALUE width, VALUE height)
238
+ {
239
+ CHECK;
240
+ if (!this->set_bounds(
241
+ to<coord>(x), to<coord>(y), to<coord>(width), to<coord>(height)))
242
+ {
243
+ system_error("failed to set bounds of window.");
244
+ }
245
+ Value ret[] = {x, y, width, height};
246
+ return value(4, ret);
247
+ }
248
+
249
+ static
250
+ VALUE moved(VALUE self, VALUE x, VALUE y)
251
+ {
252
+ CHECK;
253
+ this->Super::moved(to<coord>(x), to<coord>(y));
254
+ return self;
255
+ }
256
+
257
+ static
258
+ VALUE resized(VALUE self, VALUE width, VALUE height)
259
+ {
260
+ CHECK;
261
+ this->Super::resized(to<coord>(width), to<coord>(height));
262
+ return self;
263
+ }
264
+
265
+ static
266
+ VALUE key_down(VALUE self, VALUE key)
267
+ {
268
+ CHECK;
269
+ Reflex::Key* k = to<Reflex::Key*>(key);
270
+ if (!k) argument_error();
271
+ this->Super::key_down(*k);
272
+ return self;
273
+ }
274
+
275
+ static
276
+ VALUE key_up(VALUE self, VALUE key)
277
+ {
278
+ CHECK;
279
+ Reflex::Key* k = to<Reflex::Key*>(key);
280
+ if (!k) argument_error();
281
+ this->Super::key_up(*k);
282
+ return self;
283
+ }
284
+
285
+ static
286
+ VALUE points_down(VALUE self, VALUE points)
287
+ {
288
+ CHECK;
289
+ Reflex::Points* p = to<Reflex::Points*>(points);
290
+ if (!p) argument_error();
291
+ this->Super::points_down(*p);
292
+ return self;
293
+ }
294
+
295
+ static
296
+ VALUE points_up(VALUE self, VALUE points)
297
+ {
298
+ CHECK;
299
+ Reflex::Points* p = to<Reflex::Points*>(points);
300
+ if (!p) argument_error();
301
+ this->Super::points_up(*p);
302
+ return self;
303
+ }
304
+
305
+ static
306
+ VALUE points_moved(VALUE self, VALUE points)
307
+ {
308
+ CHECK;
309
+ Reflex::Points* p = to<Reflex::Points*>(points);
310
+ if (!p) argument_error();
311
+ this->Super::points_moved(*p);
312
+ return self;
313
+ }
314
+
315
+
316
+ void
317
+ Init_window ()
318
+ {
319
+ Module m = rb_define_module("Reflex");
320
+
321
+ Class c = rb_define_class_under(m, "Window", rb_cObject);
322
+ Reflex::cWindow = c;
323
+
324
+ rb_define_alloc_func(c, alloc);
325
+ rb_define_method(c, "close", RUBY_METHOD_FUNC(close), 0);
326
+ rb_define_method(c, "show", RUBY_METHOD_FUNC(show), 0);
327
+ rb_define_method(c, "hide", RUBY_METHOD_FUNC(hide), 0);
328
+ rb_define_method(c, "hidden", RUBY_METHOD_FUNC(hidden), 0);
329
+ rb_define_method(c, "update", RUBY_METHOD_FUNC(update), 0);
330
+ rb_define_method(c, "draw", RUBY_METHOD_FUNC(draw), 0);
331
+ rb_define_method(c, "redraw", RUBY_METHOD_FUNC(redraw), 0);
332
+ rb_define_method(c, "title", RUBY_METHOD_FUNC(get_title), 0);
333
+ rb_define_method(c, "title=", RUBY_METHOD_FUNC(set_title), 1);
334
+ rb_define_private_method(c, "get_bounds", RUBY_METHOD_FUNC(get_bounds), 0);
335
+ rb_define_private_method(c, "set_bounds", RUBY_METHOD_FUNC(set_bounds), 4);
336
+ rb_define_method(c, "moved", RUBY_METHOD_FUNC(moved), 2);
337
+ rb_define_method(c, "resized", RUBY_METHOD_FUNC(resized), 2);
338
+ rb_define_method(c, "key_down", RUBY_METHOD_FUNC(key_down), 1);
339
+ rb_define_method(c, "key_up", RUBY_METHOD_FUNC(key_up), 1);
340
+ rb_define_method(c, "points_down", RUBY_METHOD_FUNC(points_down), 1);
341
+ rb_define_method(c, "points_up", RUBY_METHOD_FUNC(points_up), 1);
342
+ rb_define_method(c, "points_moved", RUBY_METHOD_FUNC(points_moved), 1);
343
+ }
data/Rakefile CHANGED
@@ -1,48 +1,23 @@
1
1
  # -*- mode: ruby; coding: utf-8 -*-
2
2
 
3
3
 
4
- %w[. ./lib ../rucy/lib ../rays/lib].each do |path|
4
+ %w[. ../xot ../rucy ../rays].map {|s| "#{s}/lib"}.each do |path|
5
5
  $: << File.expand_path(File.join File.dirname(__FILE__), *path.split('/'))
6
6
  end
7
7
 
8
8
  require 'rubygems'
9
- require 'rbconfig'
10
- require 'support'
9
+ require 'xot/rake/helpers'
10
+ require 'xot/module'
11
+ require 'rucy/module'
11
12
  require 'rays/module'
12
13
  require 'reflex/module'
13
14
 
15
+ include Xot::Rake
14
16
 
15
- MODULE = Reflex
16
- NAME = MODULE.name.downcase
17
17
 
18
- SRCDIR = 'src'
19
- INCDIR = 'include'
20
- LIBDIR = 'lib'
21
- EXTDIR = 'ext'
22
- TASKDIR = 'task'
23
-
24
- EXTEXT = RbConfig::CONFIG['DLEXT'] || 'so'
25
-
26
- DEFS = %w[]
27
- DEFS << 'WIN32' if win32?
28
- DEFS << 'COCOA' if cocoa?
29
-
30
- incroot = RbConfig::CONFIG['rubyhdrdir']
31
- INCDIRS = Reflex.include_dirs + Rays.include_dirs + [
32
- incroot,
33
- "#{incroot}/#{RUBY_PLATFORM}",
34
- '/opt/local/include',
35
- '/opt/include'
36
- ]
37
-
38
- RUBY = ENV['RUBY'] || 'ruby'
39
- GEM = ENV['GEM'] || 'gem'
40
- GIT = ENV['GIT'] || 'git'
41
- MAKE = ENV['MAKE'] || 'make'
42
- CC = RbConfig::CONFIG['CC'] || ENV['CC'] || 'g++'
43
- CFLAGS = '-Wall -O' + DEFS.map{|s| " -D#{s}"}.join
44
- AR = ENV['AR'] || 'ar'
45
- ARFLAGS = 'crs'
18
+ MODULE = Reflex
19
+ GEMNAME = 'reflexion'
20
+ INCDIRS = [Reflex, Rays, Rucy].map {|m| m.include_dirs}.flatten
46
21
 
47
22
 
48
23
  task :default => :build
@@ -55,6 +30,8 @@ task :lib => 'lib:build'
55
30
 
56
31
  task :ext => 'ext:build'
57
32
 
33
+ task :doc => 'ext:doc'
34
+
58
35
  task :gem => 'gem:build'
59
36
 
60
37
  task :install => 'gem:install'
@@ -70,4 +47,4 @@ task :test => :ext do
70
47
  end
71
48
 
72
49
 
73
- Dir["#{TASKDIR}/**/*.rake"].each {|path| load path}
50
+ [Xot, Rucy, Rays, Reflex].each {|m| m.load_tasks}
data/VERSION CHANGED
@@ -1 +1 @@
1
- 0.1.2
1
+ 0.1.3
@@ -2,7 +2,7 @@
2
2
 
3
3
 
4
4
  #include <rucy.h>
5
- #include "reflex.h"
5
+ #include "defs.h"
6
6
 
7
7
 
8
8
  using namespace Rucy;
@@ -12,11 +12,12 @@ namespace Reflex
12
12
  {
13
13
 
14
14
 
15
+ static Class cApplication;
16
+
15
17
  Class
16
18
  application_class ()
17
19
  {
18
- static Class c = reflex_module().define_class("Application");
19
- return c;
20
+ return cApplication;
20
21
  }
21
22
 
22
23
 
@@ -141,11 +142,15 @@ RUBY_END
141
142
  void
142
143
  Init_application ()
143
144
  {
144
- Reflex::application_class()
145
- .define_alloc_func(alloc)
146
- .define_method("run", run)
147
- .define_method("quit", quit)
148
- .define_method("about", about)
149
- .define_method("name", get_name)
150
- .define_method("name=", set_name);
145
+ Module m = define_module("Reflex");
146
+
147
+ Class c = m.define_class("Application");
148
+ Reflex::cApplication = c;
149
+
150
+ c.define_alloc_func(alloc);
151
+ c.define_method("run", run);
152
+ c.define_method("quit", quit);
153
+ c.define_method("about", about);
154
+ c.define_method("name", get_name);
155
+ c.define_method("name=", set_name);
151
156
  }
@@ -1,22 +1,13 @@
1
1
  // -*- c++ -*-
2
2
  #pragma once
3
- #ifndef __REFLEX_EXT_REFLEX_H__
4
- #define __REFLEX_EXT_REFLEX_H__
3
+ #ifndef __REFLEX_EXT_DEFS_H__
4
+ #define __REFLEX_EXT_DEFS_H__
5
5
 
6
6
 
7
- #include <rucy/class.h>
8
- #include "reflex/ruby/reflex.h"
7
+ #include <reflex/exception.h>
9
8
 
10
9
 
11
- namespace Reflex
12
- {
13
-
14
-
15
- Rucy::Class reflex_error_class ();
16
- // class Reflex::ReflexError < Rucy::NativeError
17
-
18
-
19
- }// Reflex
10
+ using Reflex::error;
20
11
 
21
12
 
22
13
  #define CHECK_OBJ(obj, type, klass) \
@@ -1,41 +1,52 @@
1
1
  # -*- coding: utf-8 -*-
2
2
 
3
3
 
4
- %w[../../../rucy/lib ../../lib].each do |path|
4
+ %w[. ../xot ../rucy].map {|s| "../../#{s}/lib"}.each do |path|
5
5
  $: << File.expand_path(File.join File.dirname(__FILE__), *path.split('/'))
6
6
  end
7
7
 
8
8
  require 'rubygems'
9
9
  require 'mkmf'
10
+ require 'xot/rake/helpers'
11
+ require 'xot/module'
10
12
  require 'rucy/module'
11
13
  require 'reflex/module'
12
14
 
15
+ include Xot::Rake
13
16
 
14
- DEBUG = ENV['DEBUG'] || false
17
+
18
+ DEBUG = env :DEBUG, false
15
19
 
16
20
  DEFS = []
17
- INCDIRS = %w[/opt/local/include /opt/include] +
18
- Rucy.include_dirs + Reflex.include_dirs
19
- LIBDIRS = %w[] +
20
- Rucy.library_dirs + Reflex.library_dirs
21
+ INCDIRS = %w[
22
+ /opt/local/include
23
+ /opt/include
24
+ ]
25
+ LIBDIRS = []
21
26
 
22
27
  HEADERS = %w[
23
28
  boost/shared_ptr.hpp
29
+ boost/scoped_array.hpp
24
30
  ruby.h
31
+ xot.h
25
32
  rucy.h
26
33
  reflex.h
27
34
  ]
28
- LIBS = %w[stdc++ rucy reflex]
29
- FRAMEWORKS = %w[]
35
+ LIBS = %w[
36
+ stdc++
37
+ xot
38
+ rucy
39
+ reflex
40
+ ]
41
+ FRAMEWORKS = []
30
42
 
31
43
 
32
44
  DEFS << '_DEBUG' if DEBUG
33
-
34
- case RUBY_PLATFORM
35
- when /mswin|ming|cygwin/
36
- DEFS << 'WINDOWS' << 'WIN32' << $~[0].upcase
45
+ DEFS << $~[0].upcase if RUBY_PLATFORM =~ /mswin|ming|cygwin|darwin/i
46
+ if win32?
47
+ DEFS << 'WINDOWS' << 'WIN32'
37
48
  LIBS.unshift 'gdi32', 'opengl32'
38
- when /darwin/
49
+ elsif cocoa?
39
50
  DEFS << 'COCOA'
40
51
  FRAMEWORKS << 'Cocoa'# << 'OpenGL'
41
52
  end
@@ -46,12 +57,13 @@ $LDFLAGS << LIBDIRS.map {|s| " -L#{s}"}.join
46
57
  $LDFLAGS << FRAMEWORKS.map {|s| " -framework #{s}"}.join
47
58
  $LOCAL_LIBS << ' -lrucy'
48
59
 
49
- dir_config 'boost'
50
- dir_config 'rucy', Rucy.root_dir
51
- dir_config 'reflex', Reflex.root_dir
60
+ Config::CONFIG.each {|key, val| val.gsub!(/gcc/, 'g++')}
52
61
 
53
62
 
54
- Config::CONFIG.each {|key, val| val.gsub!(/gcc/, 'g++')}
63
+ dir_config 'boost'
64
+ dir_config 'xot', Xot.root_dir
65
+ dir_config 'rucy', Rucy.root_dir
66
+ dir_config 'reflex', Reflex.root_dir
55
67
 
56
68
  exit 1 unless HEADERS.all? {|s| have_header(s)}
57
69
  exit 1 unless LIBS.all? {|s| have_library(s)}
data/ext/reflex/key.cpp CHANGED
@@ -2,7 +2,7 @@
2
2
 
3
3
 
4
4
  #include <rucy.h>
5
- #include "reflex.h"
5
+ #include "defs.h"
6
6
 
7
7
 
8
8
  using namespace Rucy;
@@ -12,11 +12,12 @@ namespace Reflex
12
12
  {
13
13
 
14
14
 
15
+ static Class cKey;
16
+
15
17
  Class
16
18
  key_class ()
17
19
  {
18
- static Class c = reflex_module().define_class("Key");
19
- return c;
20
+ return cKey;
20
21
  }
21
22
 
22
23
 
@@ -118,11 +119,15 @@ RUBY_END
118
119
  void
119
120
  Init_key ()
120
121
  {
121
- Reflex::key_class()
122
- .define_alloc_func(alloc)
123
- .define_method("initialize", initialize)
124
- .define_method("chars", chars)
125
- .define_method("code", code)
126
- .define_method("repeat", repeat)
127
- .define_method("modifiers", modifiers);
122
+ Module m = define_module("Reflex");
123
+
124
+ Class c = m.define_class("Key");
125
+ Reflex::cKey = c;
126
+
127
+ c.define_alloc_func(alloc);
128
+ c.define_method("initialize", initialize);
129
+ c.define_method("chars", chars);
130
+ c.define_method("code", code);
131
+ c.define_method("repeat", repeat);
132
+ c.define_method("modifiers", modifiers);
128
133
  }
@@ -1,4 +1,8 @@
1
1
  #include <rucy.h>
2
+ #include "defs.h"
3
+
4
+
5
+ using namespace Rucy;
2
6
 
3
7
 
4
8
  void Init_reflex ();
@@ -12,7 +16,7 @@ extern "C" void
12
16
  Init_native ()
13
17
  {
14
18
  if (!Rucy::init())
15
- Rucy::raise(rb_eLoadError, "Rucy::init() failed.");
19
+ raise(rb_eLoadError, "Rucy::init() failed.");
16
20
 
17
21
  Init_reflex();
18
22
  Init_application();
@@ -2,7 +2,7 @@
2
2
 
3
3
 
4
4
  #include <rucy.h>
5
- #include "reflex.h"
5
+ #include "defs.h"
6
6
 
7
7
 
8
8
  using namespace Rucy;
@@ -14,11 +14,12 @@ namespace Reflex
14
14
  {
15
15
 
16
16
 
17
+ static Class cPoints;
18
+
17
19
  Class
18
20
  points_class ()
19
21
  {
20
- static Class c = reflex_module().define_class("Points");
21
- return c;
22
+ return cPoints;
22
23
  }
23
24
 
24
25
 
@@ -147,14 +148,18 @@ RUBY_END
147
148
  void
148
149
  Init_points ()
149
150
  {
150
- Reflex::points_class()
151
- .define_alloc_func(alloc)
152
- .define_method("initialize", initialize)
153
- .define_method("type", type)
154
- .define_method("x", x)
155
- .define_method("y", y)
156
- .define_method("size", size)
157
- .define_method("modifiers", modifiers)
158
- .define_method("count", count)
159
- .define_method("drag", drag);
151
+ Module m = define_module("Reflex");
152
+
153
+ Class c = m.define_class("Points");
154
+ Reflex::cPoints = c;
155
+
156
+ c.define_alloc_func(alloc);
157
+ c.define_method("initialize", initialize);
158
+ c.define_method("type", type);
159
+ c.define_method("x", x);
160
+ c.define_method("y", y);
161
+ c.define_method("size", size);
162
+ c.define_method("modifiers", modifiers);
163
+ c.define_method("count", count);
164
+ c.define_method("drag", drag);
160
165
  }