rays 0.1.1

Sign up to get free protection for your applications and to get access to all the features.
Files changed (66) hide show
  1. data/ChangeLog +8 -0
  2. data/README +4 -0
  3. data/Rakefile +72 -0
  4. data/VERSION +1 -0
  5. data/ext/rays/bitmap.cpp +322 -0
  6. data/ext/rays/extconf.rb +61 -0
  7. data/ext/rays/font.cpp +125 -0
  8. data/ext/rays/image.cpp +166 -0
  9. data/ext/rays/native.cpp +24 -0
  10. data/ext/rays/painter.cpp +573 -0
  11. data/ext/rays/rays.cpp +61 -0
  12. data/ext/rays/rays.h +39 -0
  13. data/ext/rays/texture.cpp +130 -0
  14. data/include/rays.h +20 -0
  15. data/include/rays/bitmap.h +80 -0
  16. data/include/rays/colorspace.h +101 -0
  17. data/include/rays/defs.h +33 -0
  18. data/include/rays/font.h +49 -0
  19. data/include/rays/helpers.h +37 -0
  20. data/include/rays/image.h +68 -0
  21. data/include/rays/opengl.h +15 -0
  22. data/include/rays/painter.h +179 -0
  23. data/include/rays/rays.h +19 -0
  24. data/include/rays/ruby.h +15 -0
  25. data/include/rays/ruby/bitmap.h +39 -0
  26. data/include/rays/ruby/font.h +39 -0
  27. data/include/rays/ruby/image.h +39 -0
  28. data/include/rays/ruby/painter.h +39 -0
  29. data/include/rays/ruby/rays.h +21 -0
  30. data/include/rays/ruby/texture.h +39 -0
  31. data/include/rays/texture.h +56 -0
  32. data/include/rays/transform.h +35 -0
  33. data/lib/rays.rb +9 -0
  34. data/lib/rays/autoinit.rb +10 -0
  35. data/lib/rays/bitmap.rb +25 -0
  36. data/lib/rays/image.rb +15 -0
  37. data/lib/rays/module.rb +30 -0
  38. data/lib/rays/painter.rb +99 -0
  39. data/lib/rays/texture.rb +15 -0
  40. data/rays.gemspec +54 -0
  41. data/src/cocoa/bitmap.mm +286 -0
  42. data/src/cocoa/font.mm +193 -0
  43. data/src/cocoa/helpers.h +26 -0
  44. data/src/cocoa/helpers.mm +25 -0
  45. data/src/cocoa/rays.mm +40 -0
  46. data/src/colorspace.cpp +183 -0
  47. data/src/helpers.cpp +22 -0
  48. data/src/image.cpp +133 -0
  49. data/src/painter.cpp +769 -0
  50. data/src/texture.cpp +360 -0
  51. data/src/transform.cpp +88 -0
  52. data/src/win32/bitmap.cpp +212 -0
  53. data/src/win32/font.cpp +99 -0
  54. data/src/win32/gdi.cpp +771 -0
  55. data/src/win32/gdi.h +226 -0
  56. data/src/win32/rays.cpp +36 -0
  57. data/support.rb +58 -0
  58. data/task/ext.rake +41 -0
  59. data/task/gem.rake +33 -0
  60. data/task/git.rake +22 -0
  61. data/task/lib.rake +54 -0
  62. data/test/helpers.rb +15 -0
  63. data/test/test_painter.rb +11 -0
  64. data/test/test_rays.rb +19 -0
  65. data/test/test_texture.rb +11 -0
  66. metadata +153 -0
data/ext/rays/font.cpp ADDED
@@ -0,0 +1,125 @@
1
+ #include "rays/ruby/font.h"
2
+
3
+
4
+ #include <rucy.h>
5
+ #include "rays.h"
6
+
7
+
8
+ using namespace Rucy;
9
+
10
+ using Rays::coord;
11
+
12
+
13
+ namespace Rays
14
+ {
15
+
16
+
17
+ Class
18
+ font_class ()
19
+ {
20
+ static Class c = rays_module().define_class("Font");
21
+ return c;
22
+ }
23
+
24
+
25
+ }// Rays
26
+
27
+
28
+ namespace Rucy
29
+ {
30
+
31
+
32
+ Value
33
+ value (const Rays::Font& font)
34
+ {
35
+ return new_type<Rays::Font>(
36
+ Rays::font_class(), new Rays::Font(font));
37
+ }
38
+
39
+
40
+ }// Rucy
41
+
42
+
43
+ #define this to<Rays::Font*>(self)
44
+
45
+ #define CHECK CHECK_OBJECT(self, Rays::Font, Rays::font_class())
46
+
47
+
48
+ static
49
+ RUBY_DEF_ALLOC(alloc, klass)
50
+ {
51
+ return new_type<Rays::Font>(klass, new Rays::Font);
52
+ }
53
+ RUBY_END
54
+
55
+ static
56
+ RUBY_DEFN(initialize)
57
+ {
58
+ CHECK_OBJ(self, Rays::Font, Rays::font_class());
59
+ if (argc < 0 || 2 < argc)
60
+ arg_count_error("Font#initialize", argc, 0, 1, 2);
61
+
62
+ const char* name = (argc >= 1) ? argv[0].c_str() : NULL;
63
+ float size = (argc >= 2) ? to<float>(argv[1]) : 0;
64
+ *this = Rays::Font(name, size);
65
+
66
+ return self;
67
+ }
68
+ RUBY_END
69
+
70
+ static
71
+ RUBY_DEF0(name)
72
+ {
73
+ CHECK;
74
+
75
+ return value(this->name().c_str());
76
+ }
77
+ RUBY_END
78
+
79
+ static
80
+ RUBY_DEF0(size)
81
+ {
82
+ CHECK;
83
+
84
+ return value(this->size());
85
+ }
86
+ RUBY_END
87
+
88
+ static
89
+ RUBY_DEF1(width, str)
90
+ {
91
+ CHECK;
92
+
93
+ coord width = 0;
94
+ if (!this->get_extent(&width, NULL, str.c_str()))
95
+ error("Font#width(%s) failed.", str.inspect().c_str());
96
+
97
+ return value(width);
98
+ }
99
+ RUBY_END
100
+
101
+ static
102
+ RUBY_DEF0(height)
103
+ {
104
+ CHECK;
105
+
106
+ coord height = 0;
107
+ if (!this->get_extent(NULL, &height, NULL))
108
+ error("Font#height() failed.");
109
+
110
+ return value(height);
111
+ }
112
+ RUBY_END
113
+
114
+
115
+ void
116
+ Init_font ()
117
+ {
118
+ Rays::font_class()
119
+ .define_alloc_func(alloc)
120
+ .define_method("initialize", initialize)
121
+ .define_method("name", name)
122
+ .define_method("size", size)
123
+ .define_method("width", width)
124
+ .define_method("height", height);
125
+ }
@@ -0,0 +1,166 @@
1
+ #include "rays/ruby/image.h"
2
+
3
+
4
+ #include <rucy.h>
5
+ #include "rays.h"
6
+ #include "rays/ruby/bitmap.h"
7
+ #include "rays/ruby/texture.h"
8
+
9
+
10
+ using namespace Rucy;
11
+
12
+ using Rays::coord;
13
+
14
+
15
+ namespace Rays
16
+ {
17
+
18
+
19
+ Class
20
+ image_class ()
21
+ {
22
+ static Class c = rays_module().define_class("Image");
23
+ return c;
24
+ }
25
+
26
+
27
+ }// Rays
28
+
29
+
30
+ namespace Rucy
31
+ {
32
+
33
+
34
+ Value
35
+ value (const Rays::Image& image)
36
+ {
37
+ return new_type<Rays::Image>(
38
+ Rays::image_class(), new Rays::Image(image));
39
+ }
40
+
41
+
42
+ }// Rucy
43
+
44
+
45
+ #define this to<Rays::Image*>(self)
46
+
47
+ #define CHECK CHECK_OBJECT(self, Rays::Image, Rays::image_class())
48
+
49
+
50
+ static
51
+ RUBY_DEF_ALLOC(alloc, klass)
52
+ {
53
+ return new_type<Rays::Image>(klass, new Rays::Image);
54
+ }
55
+ RUBY_END
56
+
57
+ static
58
+ RUBY_DEFN(initialize)
59
+ {
60
+ CHECK_OBJ(self, Rays::Image, Rays::image_class());
61
+ if (argc != 0 && argc != 1 && argc != 2 && argc != 3)
62
+ arg_count_error("Image#initialize", argc, 0, 1, 2, 3);
63
+
64
+ if (argc == 0) return self;
65
+
66
+ if (argv[1].is_kind_of(Rays::bitmap_class()))
67
+ {
68
+ if (argc != 1 && argc != 2)
69
+ arg_count_error("Image#initialize", argc, 0, 1, 2, 3);
70
+
71
+ const Rays::Bitmap& bitmap = *to<Rays::Bitmap*>(argv[1]);
72
+ bool alphaonly = (argc == 2) ? to<bool>(argv[2]) : false;
73
+ *this = Rays::Image(bitmap, alphaonly);
74
+ }
75
+ else
76
+ {
77
+ int width = to<int>(argv[0]);
78
+ int height = to<int>(argv[1]);
79
+ uint colorspace = (argc == 3) ? to<uint>(argv[2]) : (uint) Rays::RGBA;
80
+ *this = Rays::Image(width, height, (Rays::ColorSpaceType) colorspace);
81
+ }
82
+
83
+ return self;
84
+ }
85
+ RUBY_END
86
+
87
+ static
88
+ RUBY_DEF0(width)
89
+ {
90
+ CHECK;
91
+
92
+ return value(this->width());
93
+ }
94
+ RUBY_END
95
+
96
+ static
97
+ RUBY_DEF0(height)
98
+ {
99
+ CHECK;
100
+
101
+ return value(this->height());
102
+ }
103
+ RUBY_END
104
+
105
+ static
106
+ RUBY_DEF0(color_space)
107
+ {
108
+ CHECK;
109
+
110
+ return value(this->color_space().type());
111
+ }
112
+ RUBY_END
113
+
114
+ static
115
+ RUBY_DEF0(bitmap)
116
+ {
117
+ CHECK;
118
+
119
+ return value(this->bitmap());
120
+ }
121
+ RUBY_END
122
+
123
+ static
124
+ RUBY_DEF0(texture)
125
+ {
126
+ CHECK;
127
+
128
+ return value(this->texture());
129
+ }
130
+ RUBY_END
131
+
132
+
133
+ static
134
+ RUBY_DEFN(load)
135
+ {
136
+ if (argc != 1 && argc != 2) arg_count_error("Image.load", argc, 1, 2);
137
+
138
+ Rays::String path = argv[0].c_str();
139
+ bool alphaonly = (argc == 2) ? to<bool>(argv[1]) : false;
140
+
141
+ Rays::Image img;
142
+ if (!Rays::load_image(&img, path.c_str(), alphaonly))
143
+ {
144
+ error(
145
+ "Image.load('%s', %s) failed.",
146
+ path.c_str(), alphaonly ? "true" : "false");
147
+ }
148
+
149
+ return value(img);
150
+ }
151
+ RUBY_END
152
+
153
+
154
+ void
155
+ Init_image ()
156
+ {
157
+ Rays::image_class()
158
+ .define_alloc_func(alloc)
159
+ .define_method("initialize", initialize)
160
+ .define_method("width", width)
161
+ .define_method("height", height)
162
+ .define_method("color_space", color_space)
163
+ .define_method("bitmap", bitmap)
164
+ .define_method("texture", texture)
165
+ .define_function("load", load);
166
+ }
@@ -0,0 +1,24 @@
1
+ #include <rucy.h>
2
+
3
+
4
+ void Init_rays ();
5
+ void Init_bitmap ();
6
+ void Init_texture ();
7
+ void Init_image ();
8
+ void Init_font ();
9
+ void Init_painter ();
10
+
11
+
12
+ extern "C" void
13
+ Init_native ()
14
+ {
15
+ if (!Rucy::init())
16
+ Rucy::raise(rb_eLoadError, "Rucy::init() failed.");
17
+
18
+ Init_rays();
19
+ Init_bitmap();
20
+ Init_texture();
21
+ Init_image();
22
+ Init_font();
23
+ Init_painter();
24
+ }
@@ -0,0 +1,573 @@
1
+ #include "rays/ruby/painter.h"
2
+
3
+
4
+ #include <rucy.h>
5
+ #include "rays.h"
6
+ #include "rays/ruby/image.h"
7
+ #include "rays/ruby/font.h"
8
+
9
+
10
+ using namespace Rucy;
11
+
12
+ using Rays::coord;
13
+
14
+
15
+ namespace Rays
16
+ {
17
+
18
+
19
+ Class
20
+ painter_class ()
21
+ {
22
+ static Class c = rays_module().define_class("Painter");
23
+ return c;
24
+ }
25
+
26
+
27
+ }// Rays
28
+
29
+
30
+ namespace Rucy
31
+ {
32
+
33
+
34
+ Value
35
+ value (const Rays::Painter& painter)
36
+ {
37
+ return new_type<Rays::Painter>(
38
+ Rays::painter_class(), new Rays::Painter(painter));
39
+ }
40
+
41
+
42
+ }// Rucy
43
+
44
+
45
+ #define this to<Rays::Painter*>(self)
46
+
47
+ #define CHECK CHECK_OBJECT(self, Rays::Painter, Rays::painter_class())
48
+
49
+
50
+ static
51
+ RUBY_DEF_ALLOC(alloc, klass)
52
+ {
53
+ return new_type<Rays::Painter>(klass, new Rays::Painter);
54
+ }
55
+ RUBY_END
56
+
57
+ static
58
+ RUBY_DEF4(canvas, x, y, width, height)
59
+ {
60
+ CHECK;
61
+
62
+ coord xx = to<coord>(x);
63
+ coord yy = to<coord>(y);
64
+ coord ww = to<coord>(width);
65
+ coord hh = to<coord>(height);
66
+ if (!this->canvas(xx, yy, ww, hh))
67
+ error("Painter#canvas(%f, %f, %f, %f) failed.", xx, yy, ww, hh);
68
+
69
+ return self;
70
+ }
71
+ RUBY_END
72
+
73
+ static
74
+ RUBY_DEF0(begin)
75
+ {
76
+ CHECK;
77
+
78
+ if (!this->begin())
79
+ error("Painter#begin() failed.");
80
+
81
+ return self;
82
+ }
83
+ RUBY_END
84
+
85
+ static
86
+ RUBY_DEF0(end)
87
+ {
88
+ CHECK;
89
+
90
+ if (!this->end())
91
+ error("Painter#end() failed.");
92
+
93
+ return self;
94
+ }
95
+ RUBY_END
96
+
97
+ static
98
+ RUBY_DEF0(push)
99
+ {
100
+ CHECK;
101
+
102
+ if (!this->push())
103
+ error("Painter#push() failed.");
104
+
105
+ return self;
106
+ }
107
+ RUBY_END
108
+
109
+ static
110
+ RUBY_DEF0(pop)
111
+ {
112
+ CHECK;
113
+
114
+ if (!this->pop())
115
+ error("Painter#pop() failed.");
116
+
117
+ return self;
118
+ }
119
+ RUBY_END
120
+
121
+
122
+ static
123
+ RUBY_DEF4(line, x1_, y1_, x2_, y2_)
124
+ {
125
+ CHECK;
126
+
127
+ coord x1 = to<coord>(x1_);
128
+ coord y1 = to<coord>(y1_);
129
+ coord x2 = to<coord>(x2_);
130
+ coord y2 = to<coord>(y2_);
131
+ if (!this->line(x1, y1, x2, y2))
132
+ error("Painter#line(%f, %f, %f, %f) failed.", x1, y1, x2, y2);
133
+
134
+ return self;
135
+ }
136
+ RUBY_END
137
+
138
+ static
139
+ RUBY_DEF4(rect, x, y, width, height)
140
+ {
141
+ CHECK;
142
+
143
+ coord xx = to<coord>(x);
144
+ coord yy = to<coord>(y);
145
+ coord ww = to<coord>(width);
146
+ coord hh = to<coord>(height);
147
+ if (!this->rect(xx, yy, ww, hh))
148
+ error("Painter#rect(%f, %f, %f, %f) failed.", xx, yy, ww, hh);
149
+
150
+ return self;
151
+ }
152
+ RUBY_END
153
+
154
+ static
155
+ RUBY_DEFN(ellipse)
156
+ {
157
+ CHECK;
158
+ if (argc < 3 || 6 < argc)
159
+ arg_count_error("Painter#ellipse", argc, 4, 5, 6);
160
+
161
+ coord xx = to<coord>(argv[0]);
162
+ coord yy = to<coord>(argv[1]);
163
+ coord ww = to<coord>(argv[2]);
164
+ coord hh = (argc >= 4) ? to<coord>(argv[3]) : 0;
165
+ coord min_ = (argc >= 5) ? to<coord>(argv[4]) : 0;
166
+ uint nseg = (argc >= 6) ? to<uint>(argv[5]) : 0;
167
+ if (!this->ellipse(xx, yy, ww, hh, min_, nseg))
168
+ {
169
+ error(
170
+ "Painter#ellipse(%f, %f, %f, %f, %f, %d) failed.",
171
+ xx, yy, ww, hh, min_, nseg);
172
+ }
173
+
174
+ return self;
175
+ }
176
+ RUBY_END
177
+
178
+ static
179
+ RUBY_DEFN(arc)
180
+ {
181
+ CHECK;
182
+ if (argc < 3 || 8 < argc)
183
+ arg_count_error("Painter#ellipse", argc, 4, 5, 6, 7, 8);
184
+
185
+ coord xx = to<coord>(argv[0]);
186
+ coord yy = to<coord>(argv[1]);
187
+ coord ww = to<coord>(argv[2]);
188
+ coord hh = (argc >= 4) ? to<coord>(argv[3]) : 0;
189
+ float from = (argc >= 5) ? to<float>(argv[4]) : 0;
190
+ float to_ = (argc >= 6) ? to<float>(argv[5]) : 360;
191
+ coord min_ = (argc >= 7) ? to<coord>(argv[6]) : 0;
192
+ uint nseg = (argc >= 8) ? to<uint>(argv[7]) : 0;
193
+ if (!this->arc(xx, yy, ww, hh, from, to_, min_, nseg))
194
+ {
195
+ error(
196
+ "Painter#arc(%f, %f, %f, %f, %f, %f, %f, %d) failed.",
197
+ xx, yy, ww, hh, from, to_, min_, nseg);
198
+ }
199
+
200
+ return self;
201
+ }
202
+ RUBY_END
203
+
204
+ static
205
+ RUBY_DEFN(image)
206
+ {
207
+ CHECK;
208
+ if (argc != 1 && argc != 3 && argc != 5 && argc != 7 && argc != 9)
209
+ arg_count_error("Painter#image", argc, 1, 3, 5, 7, 9);
210
+
211
+ const Rays::Image* image = to<Rays::Image*>(argv[0]);
212
+ if (!image)
213
+ argument_error("%s is not an image.", argv[0].inspect().c_str());
214
+
215
+ if (argc == 1)
216
+ {
217
+ if (!this->image(*image))
218
+ error("Painter#image(%s) failed.", argv[0].inspect().c_str());
219
+ }
220
+ else if (argc == 3)
221
+ {
222
+ coord x = to<coord>(argv[1]), y = to<coord>(argv[2]);
223
+ if (!this->image(*image, x, y))
224
+ {
225
+ error(
226
+ "Painter#image(%s, %f, %f) failed.",
227
+ argv[0].inspect().c_str(), x, y);
228
+ }
229
+ }
230
+ else if (argc == 5)
231
+ {
232
+ coord x = to<coord>(argv[1]), w = to<coord>(argv[3]);
233
+ coord y = to<coord>(argv[2]), h = to<coord>(argv[4]);
234
+ if (!this->image(*image, x, y, w, h))
235
+ {
236
+ error(
237
+ "Painter#image(%s, %f, %f, %f, %f) failed.",
238
+ argv[0].inspect().c_str(), x, y, w, h);
239
+ }
240
+ }
241
+ else if (argc == 7)
242
+ {
243
+ coord sx = to<coord>(argv[1]), dx = to<coord>(argv[5]);
244
+ coord sy = to<coord>(argv[2]), dy = to<coord>(argv[6]);
245
+ coord sw = to<coord>(argv[3]);
246
+ coord sh = to<coord>(argv[4]);
247
+ if (!this->image(*image, sx, sy, sw, sh, dx, dy))
248
+ {
249
+ error(
250
+ "Painter#image(%s, %f, %f, %f, %f, %f, %f) failed.",
251
+ argv[0].inspect().c_str(), sx, sy, sw, sh, dx, dy);
252
+ }
253
+ }
254
+ else if (argc == 9)
255
+ {
256
+ coord sx = to<coord>(argv[1]), dx = to<coord>(argv[5]);
257
+ coord sy = to<coord>(argv[2]), dy = to<coord>(argv[6]);
258
+ coord sw = to<coord>(argv[3]), dw = to<coord>(argv[7]);
259
+ coord sh = to<coord>(argv[4]), dh = to<coord>(argv[8]);
260
+ if (!this->image(*image, sx, sy, sw, sh, dx, dy, dw, dh))
261
+ {
262
+ error(
263
+ "Painter#image(%s, %f, %f, %f, %f, %f, %f, %f, %f) failed.",
264
+ argv[0].inspect().c_str(), sx, sy, sw, sh, dx, dy, dw, dh);
265
+ }
266
+ }
267
+
268
+ return self;
269
+ }
270
+ RUBY_END
271
+
272
+ static
273
+ RUBY_DEFN(text)
274
+ {
275
+ CHECK;
276
+ if (argc != 1 && argc != 3 && argc != 4 && argc != 5 && argc != 7)
277
+ arg_count_error("Painter#text", argc, 1, 3, 4, 5, 7);
278
+
279
+ if (argc == 1)
280
+ {
281
+ if (!this->text(argv[0].c_str()))
282
+ error("Painter#text(%s) failed.", argv[0].inspect().c_str());
283
+ }
284
+ else if (argc == 3)
285
+ {
286
+ coord x = to<coord>(argv[1]), y = to<coord>(argv[2]);
287
+ if (!this->text(argv[0].c_str(), x, y))
288
+ {
289
+ error(
290
+ "Painter#text(%s, %f, %f) failed.",
291
+ argv[0].inspect().c_str(), x, y);
292
+ }
293
+ }
294
+ else if (argc == 4)
295
+ {
296
+ const Rays::Font* font = to<Rays::Font*>(argv[3]);
297
+ if (!font || !*font)
298
+ error("Painter#text: invalid font.");
299
+
300
+ coord x = to<coord>(argv[1]), y = to<coord>(argv[2]);
301
+ if (!this->text(argv[0].c_str(), x, y, *font))
302
+ {
303
+ error(
304
+ "Painter#image(%s, %f, %f, %s) failed.",
305
+ argv[0].inspect().c_str(), x, y, argv[3].inspect().c_str());
306
+ }
307
+ }
308
+ else if (argc == 5)
309
+ {
310
+ coord x = to<coord>(argv[1]), w = to<coord>(argv[3]);
311
+ coord y = to<coord>(argv[2]), h = to<coord>(argv[4]);
312
+ if (!this->text(argv[0].c_str(), x, y, w, h))
313
+ {
314
+ error(
315
+ "Painter#text(%s, %f, %f, %f, %f) failed.",
316
+ argv[0].inspect().c_str(), x, y, w, h);
317
+ }
318
+ }
319
+ else if (argc == 7)
320
+ {
321
+ const Rays::Font* font = to<Rays::Font*>(argv[3]);
322
+ if (!font || !*font)
323
+ error("Painter#text: invalid font.");
324
+
325
+ coord x = to<coord>(argv[1]), w = to<coord>(argv[3]);
326
+ coord y = to<coord>(argv[2]), h = to<coord>(argv[4]);
327
+ if (!this->text(argv[0].c_str(), x, y, w, h, *font))
328
+ {
329
+ error(
330
+ "Painter#image(%s, %f, %f, %f, %f, %s) failed.",
331
+ argv[0].inspect().c_str(), x, y, w, h, argv[3].inspect().c_str());
332
+ }
333
+ }
334
+
335
+ return self;
336
+ }
337
+ RUBY_END
338
+
339
+ static
340
+ RUBY_DEF0(get_clear)
341
+ {
342
+ CHECK;
343
+
344
+ coord red = 0, green = 0, blue = 0, alpha = 0;
345
+ if (!this->get_clear(&red, &green, &blue, &alpha))
346
+ error("failed to get color for clear.");
347
+
348
+ Value ret[] = {red, green, blue, alpha};
349
+ return value(4, ret);
350
+ }
351
+ RUBY_END
352
+
353
+ static
354
+ RUBY_DEFN(set_clear)
355
+ {
356
+ CHECK;
357
+ if (argc < 1 || 4 < argc)
358
+ arg_count_error("Painter#set_clear", argc, 1, 2, 3, 4);
359
+
360
+ if (argc == 1 || argc == 2)
361
+ {
362
+ float v = to<float>(argv[0]);
363
+ float a = (argc >= 2) ? to<float>(argv[1]) : 1;
364
+ if (!this->set_clear(v, v, v, a))
365
+ error("Painter#set_clear(%f, %f) failed.", v, a);
366
+ }
367
+ else
368
+ {
369
+ float r = to<float>(argv[0]);
370
+ float g = to<float>(argv[1]);
371
+ float b = to<float>(argv[2]);
372
+ float a = (argc == 4) ? to<float>(argv[3]) : 1;
373
+ if (!this->set_clear(r, g, b, a))
374
+ error("Painter#set_clear(%f, %f, %f, %f) failed.", r, g, b, a);
375
+ }
376
+
377
+ return self;
378
+ }
379
+ RUBY_END
380
+
381
+ static
382
+ RUBY_DEF0(no_clear)
383
+ {
384
+ CHECK;
385
+
386
+ if (!this->no_clear())
387
+ error("Painter#no_clear() failed.");
388
+
389
+ return self;
390
+ }
391
+ RUBY_END
392
+
393
+ static
394
+ RUBY_DEF0(get_fill)
395
+ {
396
+ CHECK;
397
+
398
+ coord red = 0, green = 0, blue = 0, alpha = 0;
399
+ if (!this->get_fill(&red, &green, &blue, &alpha))
400
+ error("failed to get color for fill.");
401
+
402
+ Value ret[] = {red, green, blue, alpha};
403
+ return value(4, ret);
404
+ }
405
+ RUBY_END
406
+
407
+ static
408
+ RUBY_DEFN(set_fill)
409
+ {
410
+ CHECK;
411
+ if (argc < 1 || 4 < argc)
412
+ arg_count_error("Painter#set_fill", argc, 1, 2, 3, 4);
413
+
414
+ if (argc == 1 || argc == 2)
415
+ {
416
+ float v = to<float>(argv[0]);
417
+ float a = (argc >= 2) ? to<float>(argv[1]) : 1;
418
+ if (!this->set_fill(v, v, v, a))
419
+ error("Painter#set_fill(%f, %f) failed.", v, a);
420
+ }
421
+ else
422
+ {
423
+ float r = to<float>(argv[0]);
424
+ float g = to<float>(argv[1]);
425
+ float b = to<float>(argv[2]);
426
+ float a = (argc == 4) ? to<float>(argv[3]) : 1;
427
+ if (!this->set_fill(r, g, b, a))
428
+ error("Painter#set_fill(%f, %f, %f, %f) failed.", r, g, b, a);
429
+ }
430
+
431
+ return self;
432
+ }
433
+ RUBY_END
434
+
435
+ static
436
+ RUBY_DEF0(no_fill)
437
+ {
438
+ CHECK;
439
+
440
+ if (!this->no_fill())
441
+ error("Painter#no_fill() failed.");
442
+
443
+ return self;
444
+ }
445
+ RUBY_END
446
+
447
+ static
448
+ RUBY_DEF0(get_stroke)
449
+ {
450
+ CHECK;
451
+
452
+ coord red = 0, green = 0, blue = 0, alpha = 0;
453
+ if (!this->get_stroke(&red, &green, &blue, &alpha))
454
+ error("failed to get color for stroke.");
455
+
456
+ Value ret[] = {red, green, blue, alpha};
457
+ return value(4, ret);
458
+ }
459
+ RUBY_END
460
+
461
+ static
462
+ RUBY_DEFN(set_stroke)
463
+ {
464
+ CHECK;
465
+ if (argc < 1 || 4 < argc)
466
+ arg_count_error("Painter#set_stroke", argc, 1, 2, 3, 4);
467
+
468
+ if (argc == 1 || argc == 2)
469
+ {
470
+ float v = to<float>(argv[0]);
471
+ float a = (argc >= 2) ? to<float>(argv[1]) : 1;
472
+ if (!this->set_stroke(v, v, v, a))
473
+ error("Painter#set_stroke(%f, %f) failed.", v, a);
474
+ }
475
+ else
476
+ {
477
+ float r = to<float>(argv[0]);
478
+ float g = to<float>(argv[1]);
479
+ float b = to<float>(argv[2]);
480
+ float a = (argc == 4) ? to<float>(argv[3]) : 1;
481
+ if (!this->set_stroke(r, g, b, a))
482
+ error("Painter#set_stroke(%f, %f, %f, %f) failed.", r, g, b, a);
483
+ }
484
+
485
+ return self;
486
+ }
487
+ RUBY_END
488
+
489
+ static
490
+ RUBY_DEF0(no_stroke)
491
+ {
492
+ CHECK;
493
+
494
+ if (!this->no_stroke())
495
+ error("Painter#no_stroke() failed.");
496
+
497
+ return self;
498
+ }
499
+ RUBY_END
500
+
501
+ static
502
+ RUBY_DEF0(get_clip)
503
+ {
504
+ CHECK;
505
+
506
+ coord x = 0, y = 0, width = 0, height = 0;
507
+ if (!this->get_clip(&x, &y, &width, &height))
508
+ error("failed to get clip rect.");
509
+
510
+ Value ret[] = {x, y, width, height};
511
+ return value(4, ret);
512
+ }
513
+ RUBY_END
514
+
515
+ static
516
+ RUBY_DEF4(set_clip, x, y, width, height)
517
+ {
518
+ CHECK;
519
+
520
+ coord xx = to<coord>(x), ww = to<coord>(width);
521
+ coord yy = to<coord>(y), hh = to<coord>(height);
522
+ if (!this->set_clip(xx, yy, ww, hh))
523
+ error("Painter#set_clip(%f, %f, %f, %f) failed.", xx, yy, ww, hh);
524
+
525
+ return self;
526
+ }
527
+ RUBY_END
528
+
529
+ static
530
+ RUBY_DEF0(no_clip)
531
+ {
532
+ CHECK;
533
+
534
+ if (!this->no_clip())
535
+ error("Painter#no_clip() failed.");
536
+
537
+ return self;
538
+ }
539
+ RUBY_END
540
+
541
+
542
+ void
543
+ Init_painter ()
544
+ {
545
+ Rays::painter_class()
546
+ .define_alloc_func(alloc)
547
+
548
+ .define_method("canvas", canvas)
549
+ .define_method("begin", begin)
550
+ .define_method("end", end)
551
+ .define_method("push", push)
552
+ .define_method("pop", pop)
553
+
554
+ .define_private_method("draw_line", line)
555
+ .define_private_method("draw_rect", rect)
556
+ .define_private_method("draw_ellipse", ellipse)
557
+ .define_private_method("draw_arc", arc)
558
+ .define_private_method("draw_image", image)
559
+ .define_private_method("draw_text", text)
560
+
561
+ .define_method("get_fill", get_fill)
562
+ .define_method("set_fill", set_fill)
563
+ .define_method("no_fill", no_fill)
564
+ .define_method("get_stroke", get_stroke)
565
+ .define_method("set_stroke", set_stroke)
566
+ .define_method("no_stroke", no_stroke)
567
+ .define_method("get_clear", get_clear)
568
+ .define_method("set_clear", set_clear)
569
+ .define_method("no_clear", no_clear)
570
+ .define_method("get_clip", get_clip)
571
+ .define_method("set_clip", set_clip)
572
+ .define_method("no_clip", no_clip);
573
+ }