rays 0.1.15 → 0.1.20

Sign up to get free protection for your applications and to get access to all the features.
data/VERSION CHANGED
@@ -1 +1 @@
1
- 0.1.15
1
+ 0.1.20
@@ -110,7 +110,7 @@ Init_bitmap ()
110
110
  cBitmap.define_alloc_func(alloc);
111
111
  cBitmap.define_private_method("initialize", initialize);
112
112
  cBitmap.define_private_method("initialize_copy", initialize_copy);
113
- cBitmap.define_method("width", width);
113
+ cBitmap.define_method("width", width);
114
114
  cBitmap.define_method("height", height);
115
115
  cBitmap.define_method("color_space", color_space);
116
116
  cBitmap.define_method("[]=", set_at);
@@ -0,0 +1,186 @@
1
+ #include "rays/ruby/camera.h"
2
+
3
+
4
+ #include "rays/ruby/image.h"
5
+ #include "defs.h"
6
+
7
+
8
+ RUCY_DEFINE_VALUE_FROM_TO(Rays::Camera)
9
+
10
+ #define THIS to<Rays::Camera*>(self)
11
+
12
+ #define CHECK RUCY_CHECK_OBJECT(Rays::Camera, self)
13
+
14
+
15
+ static
16
+ RUCY_DEF_ALLOC(alloc, klass)
17
+ {
18
+ return new_type<Rays::Camera>(klass);
19
+ }
20
+ RUCY_END
21
+
22
+ static
23
+ RUCY_DEF5(setup, device_name, min_width, min_height, resize, crop)
24
+ {
25
+ RUCY_CHECK_OBJ(Rays::Camera, self);
26
+
27
+ *THIS = Rays::Camera(
28
+ device_name ? to<const char*>(device_name) : NULL,
29
+ to<int>(min_width), to<int>(min_height),
30
+ to<bool>(resize), to<bool>(crop));
31
+ return self;
32
+ }
33
+ RUCY_END
34
+
35
+ static
36
+ RUCY_DEF0(start)
37
+ {
38
+ CHECK;
39
+ return value(THIS->start());
40
+ }
41
+ RUCY_END
42
+
43
+ static
44
+ RUCY_DEF0(stop)
45
+ {
46
+ CHECK;
47
+ THIS->stop();
48
+ }
49
+ RUCY_END
50
+
51
+ static
52
+ RUCY_DEF0(is_active)
53
+ {
54
+ CHECK;
55
+ return value(THIS->is_active());
56
+ }
57
+ RUCY_END
58
+
59
+ static
60
+ RUCY_DEF1(set_min_width, width)
61
+ {
62
+ CHECK;
63
+ THIS->set_min_width(to<int>(width));
64
+ return value(THIS->min_width());
65
+ }
66
+ RUCY_END
67
+
68
+ static
69
+ RUCY_DEF0(min_width)
70
+ {
71
+ CHECK;
72
+ return value(THIS->min_width());
73
+ }
74
+ RUCY_END
75
+
76
+ static
77
+ RUCY_DEF1(set_min_height, height)
78
+ {
79
+ CHECK;
80
+ THIS->set_min_height(to<int>(height));
81
+ return value(THIS->min_height());
82
+ }
83
+ RUCY_END
84
+
85
+ static
86
+ RUCY_DEF0(min_height)
87
+ {
88
+ CHECK;
89
+ return value(THIS->min_height());
90
+ }
91
+ RUCY_END
92
+
93
+ static
94
+ RUCY_DEF1(set_resize, resize)
95
+ {
96
+ CHECK;
97
+ THIS->set_resize(to<bool>(resize));
98
+ return value(THIS->is_resize());
99
+ }
100
+ RUCY_END
101
+
102
+ static
103
+ RUCY_DEF0(is_resize)
104
+ {
105
+ CHECK;
106
+ return value(THIS->is_resize());
107
+ }
108
+ RUCY_END
109
+
110
+ static
111
+ RUCY_DEF1(set_crop, crop)
112
+ {
113
+ CHECK;
114
+ THIS->set_crop(to<bool>(crop));
115
+ return value(THIS->is_crop());
116
+ }
117
+ RUCY_END
118
+
119
+ static
120
+ RUCY_DEF0(is_crop)
121
+ {
122
+ CHECK;
123
+ return value(THIS->is_crop());
124
+ }
125
+ RUCY_END
126
+
127
+ static
128
+ RUCY_DEF0(image)
129
+ {
130
+ CHECK;
131
+ const Rays::Image* img = THIS->image();
132
+ return img ? value(*img) : nil();
133
+ }
134
+ RUCY_END
135
+
136
+ static
137
+ RUCY_DEF0(device_names)
138
+ {
139
+ auto names = Rays::get_camera_device_names();
140
+
141
+ std::vector<Value> v;
142
+ for (auto it = names.begin(), end = names.end(); it != end; ++it)
143
+ v.emplace_back(value(it->c_str()));
144
+ return value(v.size(), &v[0]);
145
+ }
146
+ RUCY_END
147
+
148
+
149
+ static Class cCamera;
150
+
151
+ void
152
+ Init_camera ()
153
+ {
154
+ Module mRays = define_module("Rays");
155
+
156
+ cCamera = mRays.define_class("Camera");
157
+ cCamera.define_alloc_func(alloc);
158
+ cCamera.define_private_method("setup", setup);
159
+ cCamera.define_method("start", start);
160
+ cCamera.define_method("stop", stop);
161
+ cCamera.define_method("active?", is_active);
162
+ cCamera.define_method("min_width=", set_min_width);
163
+ cCamera.define_method("min_width", min_width);
164
+ cCamera.define_method("min_height=", set_min_height);
165
+ cCamera.define_method("min_height", min_height);
166
+ cCamera.define_method("resize=", set_resize);
167
+ cCamera.define_method("resize?", is_resize);
168
+ cCamera.define_method("crop=", set_crop);
169
+ cCamera.define_method("crop?", is_crop);
170
+ cCamera.define_method("image", image);
171
+ cCamera.define_module_function("device_names", device_names);
172
+ }
173
+
174
+
175
+ namespace Rays
176
+ {
177
+
178
+
179
+ Class
180
+ camera_class ()
181
+ {
182
+ return cCamera;
183
+ }
184
+
185
+
186
+ }// Rays
@@ -211,9 +211,8 @@ Init_color ()
211
211
  cColor.define_method("blue", get_blue);
212
212
  cColor.define_method("alpha=", set_alpha);
213
213
  cColor.define_method("alpha", get_alpha);
214
-
215
- cColor.define_function("hsv", hsv);
216
- cColor.define_function("set_palette_color", set_palette_color);
214
+ cColor.define_module_function("hsv", hsv);
215
+ cColor.define_module_function("set_palette_color", set_palette_color);
217
216
  }
218
217
 
219
218
 
@@ -17,7 +17,7 @@ Xot::ExtConf.new Xot, Rucy, Rays do
17
17
  headers << 'ruby.h'
18
18
  local_libs << 'rucy'
19
19
  libs.unshift 'gdi21', 'opengl32' if win32?
20
- frameworks << 'AppKit' << 'OpenGL' if osx?
20
+ frameworks << 'AppKit' << 'OpenGL' << 'AVFoundation' if osx?
21
21
  $LDFLAGS << ' -Wl,--out-implib=native.dll.a' if cygwin?
22
22
  end
23
23
 
@@ -61,6 +61,36 @@ RUCY_DEF0(height)
61
61
  }
62
62
  RUCY_END
63
63
 
64
+ static
65
+ RUCY_DEF0(ascent)
66
+ {
67
+ CHECK;
68
+ coord ascent = 0;
69
+ THIS->get_height(&ascent);
70
+ return value(ascent);
71
+ }
72
+ RUCY_END
73
+
74
+ static
75
+ RUCY_DEF0(descent)
76
+ {
77
+ CHECK;
78
+ coord descent = 0;
79
+ THIS->get_height(NULL, &descent);
80
+ return value(descent);
81
+ }
82
+ RUCY_END
83
+
84
+ static
85
+ RUCY_DEF0(leading)
86
+ {
87
+ CHECK;
88
+ coord leading = 0;
89
+ THIS->get_height(NULL, NULL, &leading);
90
+ return value(leading);
91
+ }
92
+ RUCY_END
93
+
64
94
 
65
95
  static Class cFont;
66
96
 
@@ -74,8 +104,11 @@ Init_font ()
74
104
  cFont.define_private_method("initialize", initialize);
75
105
  cFont.define_method("name", name);
76
106
  cFont.define_method("size", size);
77
- cFont.define_method("width", width);
78
- cFont.define_method("height", height);
107
+ cFont.define_method("width", width);
108
+ cFont.define_method("height", height);
109
+ cFont.define_method("ascent", ascent);
110
+ cFont.define_method("descent", descent);
111
+ cFont.define_method("leading", leading);
79
112
  }
80
113
 
81
114
 
@@ -142,14 +142,14 @@ Init_image ()
142
142
  cImage.define_alloc_func(alloc);
143
143
  cImage.define_private_method("initialize", initialize);
144
144
  cImage.define_private_method("initialize_copy", initialize_copy);
145
- cImage.define_method("width", width);
145
+ cImage.define_method("width", width);
146
146
  cImage.define_method("height", height);
147
147
  cImage.define_method("color_space", color_space);
148
148
  cImage.define_method("pixel_density", pixel_density);
149
149
  cImage.define_method("painter", painter);
150
150
  cImage.define_method("bitmap", bitmap);
151
151
  cImage.define_method("save", save);
152
- cImage.define_function("load", load);
152
+ cImage.define_module_function("load", load);
153
153
  }
154
154
 
155
155
 
@@ -9,6 +9,7 @@ void Init_color ();
9
9
  void Init_color_space ();
10
10
  void Init_matrix ();
11
11
 
12
+ void Init_painter ();
12
13
  void Init_polyline ();
13
14
  void Init_polygon_line ();
14
15
  void Init_polygon ();
@@ -16,8 +17,7 @@ void Init_bitmap ();
16
17
  void Init_image ();
17
18
  void Init_font ();
18
19
  void Init_shader ();
19
-
20
- void Init_painter ();
20
+ void Init_camera ();
21
21
 
22
22
  void Init_noise ();
23
23
 
@@ -41,6 +41,7 @@ extern "C" void
41
41
  Init_color_space();
42
42
  Init_matrix();
43
43
 
44
+ Init_painter();
44
45
  Init_polyline();
45
46
  Init_polygon_line();
46
47
  Init_polygon();
@@ -48,8 +49,7 @@ extern "C" void
48
49
  Init_image();
49
50
  Init_font();
50
51
  Init_shader();
51
-
52
- Init_painter();
52
+ Init_camera();
53
53
 
54
54
  Init_noise();
55
55
 
@@ -353,12 +353,7 @@ static
353
353
  RUCY_DEF1(set_stroke_cap, cap)
354
354
  {
355
355
  CHECK;
356
-
357
- int type = to<int>(cap);
358
- if (type < 0 || Rays::CAP_MAX <= type)
359
- argument_error(__FILE__, __LINE__, "invalid stroke cap -- %d", type);
360
-
361
- THIS->set_stroke_cap((Rays::CapType) type);
356
+ THIS->set_stroke_cap(to<Rays::CapType>(cap));
362
357
  return self;
363
358
  }
364
359
  RUCY_END
@@ -375,12 +370,7 @@ static
375
370
  RUCY_DEF1(set_stroke_join, join)
376
371
  {
377
372
  CHECK;
378
-
379
- int type = to<int>(join);
380
- if (type < 0 || Rays::JOIN_MAX <= type)
381
- argument_error(__FILE__, __LINE__, "invalid stroke join -- %d", type);
382
-
383
- THIS->set_stroke_join((Rays::JoinType) type);
373
+ THIS->set_stroke_join(to<Rays::JoinType>(join));
384
374
  return self;
385
375
  }
386
376
  RUCY_END
@@ -262,6 +262,20 @@ RUCY_DEF0(inspect)
262
262
  }
263
263
  RUCY_END
264
264
 
265
+ static
266
+ RUCY_DEF2(dot, p1, p2)
267
+ {
268
+ return value(Rays::dot(to<Rays::Point>(p1), to<Rays::Point>(p2)));
269
+ }
270
+ RUCY_END
271
+
272
+ static
273
+ RUCY_DEF2(cross, p1, p2)
274
+ {
275
+ return value(Rays::cross(to<Rays::Point>(p1), to<Rays::Point>(p2)));
276
+ }
277
+ RUCY_END
278
+
265
279
 
266
280
  static Class cPoint;
267
281
 
@@ -295,6 +309,8 @@ Init_point ()
295
309
  cPoint.define_method("[]=", set_at);
296
310
  cPoint.define_method("[]", get_at);
297
311
  cPoint.define_method("inspect", inspect);
312
+ cPoint.define_module_function("dot", dot);
313
+ cPoint.define_module_function("cross", cross);
298
314
  }
299
315
 
300
316
 
@@ -80,7 +80,7 @@ RUCY_DEF0(empty)
80
80
  RUCY_END
81
81
 
82
82
  static
83
- RUCY_DEF1(at, index)
83
+ RUCY_DEF1(get_at, index)
84
84
  {
85
85
  CHECK;
86
86
 
@@ -100,7 +100,7 @@ RUCY_DEF0(each)
100
100
  {
101
101
  CHECK;
102
102
 
103
- Value ret;
103
+ Value ret = Qnil;
104
104
  for (const auto& line : *THIS)
105
105
  ret = rb_yield(value(line));
106
106
  return ret;
@@ -260,7 +260,7 @@ Init_polygon ()
260
260
  cPolygon.define_method("bounds", bounds);
261
261
  cPolygon.define_method("size", size);
262
262
  cPolygon.define_method("empty?", empty);
263
- cPolygon.define_method("[]", at);
263
+ cPolygon.define_method("[]", get_at);
264
264
  cPolygon.define_method("each", each);
265
265
  cPolygon.define_method("+", op_or);
266
266
  cPolygon.define_method("-", op_sub);
@@ -83,7 +83,7 @@ RUCY_DEF0(empty)
83
83
  RUCY_END
84
84
 
85
85
  static
86
- RUCY_DEF1(at, index)
86
+ RUCY_DEF1(get_at, index)
87
87
  {
88
88
  CHECK;
89
89
 
@@ -103,7 +103,7 @@ RUCY_DEF0(each)
103
103
  {
104
104
  CHECK;
105
105
 
106
- Value ret;
106
+ Value ret = Qnil;
107
107
  for (const auto& point : *THIS)
108
108
  ret = rb_yield(value(point));
109
109
  return ret;
@@ -126,7 +126,7 @@ Init_polyline ()
126
126
  cPolyline.define_method("loop?", loop);
127
127
  cPolyline.define_method("size", size);
128
128
  cPolyline.define_method("empty?", empty);
129
- cPolyline.define_method("[]", at);
129
+ cPolyline.define_method("[]", get_at);
130
130
  cPolyline.define_method("each", each);
131
131
  }
132
132
 
@@ -1,43 +1,33 @@
1
1
  #include "rays/ruby/rays.h"
2
2
 
3
3
 
4
+ #include <vector>
4
5
  #include "defs.h"
5
6
 
6
7
 
7
- RUCY_DEFINE_VALUE_OR_ARRAY_TO(Rays::CapType)
8
- RUCY_DEFINE_VALUE_OR_ARRAY_TO(Rays::JoinType)
8
+ RUCY_DEFINE_CONVERT_TO(Rays::CapType)
9
+ RUCY_DEFINE_CONVERT_TO(Rays::JoinType)
9
10
 
10
11
 
11
- static struct CapTypeEnum
12
+ template <typename T>
13
+ struct EnumType
12
14
  {
13
15
  const char* name;
14
- Rays::CapType type;
15
- }
16
- CAP_TYPES[] =
17
- {
18
- {"CAP_BUTT", Rays::CAP_BUTT},
19
- {"CAP_ROUND", Rays::CAP_ROUND},
20
- {"CAP_SQUARE", Rays::CAP_SQUARE},
16
+ const char* short_name;
17
+ T type;
21
18
  };
22
19
 
23
- static const size_t CAP_TYPES_SIZE =
24
- sizeof(CAP_TYPES) / sizeof(CAP_TYPES[0]);
25
-
26
-
27
- static struct JoinTypeEnum
28
- {
29
- const char* name;
30
- Rays::JoinType type;
31
- }
32
- JOIN_TYPES[] =
33
- {
34
- {"JOIN_MITER", Rays::JOIN_MITER},
35
- {"JOIN_ROUND", Rays::JOIN_ROUND},
36
- {"JOIN_SQUARE", Rays::JOIN_SQUARE},
37
- };
20
+ static std::vector<EnumType<Rays::CapType>> CAP_TYPES({
21
+ {"CAP_BUTT", "BUTT", Rays::CAP_BUTT},
22
+ {"CAP_ROUND", "ROUND", Rays::CAP_ROUND},
23
+ {"CAP_SQUARE", "SQUARE", Rays::CAP_SQUARE},
24
+ });
38
25
 
39
- static const size_t JOIN_TYPES_SIZE =
40
- sizeof(JOIN_TYPES) / sizeof(JOIN_TYPES[0]);
26
+ static std::vector<EnumType<Rays::JoinType>> JOIN_TYPES({
27
+ {"JOIN_MITER", "MITER", Rays::JOIN_MITER},
28
+ {"JOIN_ROUND", "ROUND", Rays::JOIN_ROUND},
29
+ {"JOIN_SQUARE", "SQUARE", Rays::JOIN_SQUARE},
30
+ });
41
31
 
42
32
 
43
33
  static
@@ -67,11 +57,11 @@ Init_rays ()
67
57
  mRays.define_singleton_method("init!", init);
68
58
  mRays.define_singleton_method("fin!", fin);
69
59
 
70
- for (size_t i = 0; i < CAP_TYPES_SIZE; ++i)
71
- mRays.define_const(CAP_TYPES[i].name, CAP_TYPES[i].type);
60
+ for (auto it = CAP_TYPES.begin(); it != CAP_TYPES.end(); ++it)
61
+ mRays.define_const(it->name, it->type);
72
62
 
73
- for (size_t i = 0; i < JOIN_TYPES_SIZE; ++i)
74
- mRays.define_const(JOIN_TYPES[i].name, JOIN_TYPES[i].type);
63
+ for (auto it = JOIN_TYPES.begin(); it != JOIN_TYPES.end(); ++it)
64
+ mRays.define_const(it->name, it->type);
75
65
  }
76
66
 
77
67
 
@@ -89,16 +79,21 @@ namespace Rucy
89
79
  if (argv->is_s() || argv->is_sym())
90
80
  {
91
81
  const char* str = argv->c_str();
92
- for (size_t i = 0; i < CAP_TYPES_SIZE; ++i)
82
+ for (auto it = CAP_TYPES.begin(); it != CAP_TYPES.end(); ++it)
93
83
  {
94
- if (strcasecmp(str, CAP_TYPES[i].name) == 0)
95
- return CAP_TYPES[i].type;
84
+ if (
85
+ strcasecmp(str, it->name) == 0 ||
86
+ strcasecmp(str, it->short_name) == 0)
87
+ {
88
+ return it->type;
89
+ }
96
90
  }
91
+ argument_error(__FILE__, __LINE__, "invalid cap type -- %s", str);
97
92
  }
98
93
  }
99
94
 
100
- uint type = value_to<uint>(*argv, convert);
101
- if (type >= Rays::CAP_MAX)
95
+ int type = value_to<int>(*argv, convert);
96
+ if (type < 0 || Rays::CAP_MAX <= type)
102
97
  argument_error(__FILE__, __LINE__, "invalid cap type -- %d", type);
103
98
 
104
99
  return (Rays::CapType) type;
@@ -115,16 +110,21 @@ namespace Rucy
115
110
  if (argv->is_s() || argv->is_sym())
116
111
  {
117
112
  const char* str = argv->c_str();
118
- for (size_t i = 0; i < JOIN_TYPES_SIZE; ++i)
113
+ for (auto it = JOIN_TYPES.begin(); it != JOIN_TYPES.end(); ++it)
119
114
  {
120
- if (strcasecmp(str, JOIN_TYPES[i].name) == 0)
121
- return JOIN_TYPES[i].type;
115
+ if (
116
+ strcasecmp(str, it->name) == 0 ||
117
+ strcasecmp(str, it->short_name) == 0)
118
+ {
119
+ return it->type;
120
+ }
122
121
  }
122
+ argument_error(__FILE__, __LINE__, "invalid join type -- %s", str);
123
123
  }
124
124
  }
125
125
 
126
- uint type = value_to<uint>(*argv, convert);
127
- if (type >= Rays::JOIN_MAX)
126
+ int type = value_to<int>(*argv, convert);
127
+ if (type < 0 || Rays::JOIN_MAX <= type)
128
128
  argument_error(__FILE__, __LINE__, "invalid join type -- %d", type);
129
129
 
130
130
  return (Rays::JoinType) type;