rays 0.1.3 → 0.1.4

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 (88) hide show
  1. data/.doc/ext/rays/bitmap.cpp +76 -53
  2. data/.doc/ext/rays/font.cpp +31 -27
  3. data/.doc/ext/rays/image.cpp +44 -37
  4. data/.doc/ext/rays/native.cpp +6 -0
  5. data/.doc/ext/rays/painter.cpp +276 -160
  6. data/.doc/ext/rays/rays.cpp +8 -9
  7. data/.doc/ext/rays/texture.cpp +50 -28
  8. data/.gitignore +14 -0
  9. data/Rakefile +5 -30
  10. data/VERSION +1 -1
  11. data/ext/rays/bitmap.cpp +77 -53
  12. data/ext/rays/bounds.cpp +426 -0
  13. data/ext/rays/color.cpp +199 -0
  14. data/ext/rays/defs.h +1 -18
  15. data/ext/rays/extconf.rb +10 -8
  16. data/ext/rays/font.cpp +31 -27
  17. data/ext/rays/image.cpp +44 -37
  18. data/ext/rays/matrix.cpp +154 -0
  19. data/ext/rays/native.cpp +6 -0
  20. data/ext/rays/painter.cpp +288 -163
  21. data/ext/rays/point.cpp +175 -0
  22. data/ext/rays/rays.cpp +8 -9
  23. data/ext/rays/texture.cpp +52 -28
  24. data/include/rays.h +1 -2
  25. data/include/rays/bitmap.h +5 -3
  26. data/include/rays/bounds.h +94 -0
  27. data/include/rays/color.h +53 -0
  28. data/include/rays/colorspace.h +2 -2
  29. data/include/rays/exception.h +1 -1
  30. data/include/rays/font.h +7 -3
  31. data/include/rays/image.h +6 -2
  32. data/include/rays/matrix.h +63 -0
  33. data/include/rays/opengl.h +1 -1
  34. data/include/rays/painter.h +138 -39
  35. data/include/rays/point.h +39 -0
  36. data/include/rays/ruby.h +3 -0
  37. data/include/rays/ruby/bitmap.h +5 -3
  38. data/include/rays/ruby/bounds.h +41 -0
  39. data/include/rays/ruby/color.h +41 -0
  40. data/include/rays/ruby/font.h +5 -3
  41. data/include/rays/ruby/image.h +5 -3
  42. data/include/rays/ruby/matrix.h +41 -0
  43. data/include/rays/ruby/painter.h +5 -3
  44. data/include/rays/ruby/point.h +41 -0
  45. data/include/rays/ruby/texture.h +5 -3
  46. data/include/rays/texture.h +6 -2
  47. data/lib/rays.rb +3 -0
  48. data/lib/rays/autoinit.rb +1 -1
  49. data/lib/rays/bitmap.rb +15 -1
  50. data/lib/rays/bounds.rb +138 -0
  51. data/lib/rays/color.rb +52 -0
  52. data/lib/rays/ext.rb +4 -0
  53. data/lib/rays/image.rb +1 -1
  54. data/lib/rays/module.rb +9 -2
  55. data/lib/rays/painter.rb +40 -41
  56. data/lib/rays/point.rb +82 -0
  57. data/lib/rays/texture.rb +1 -1
  58. data/rays.gemspec +16 -37
  59. data/src/bounds.cpp +234 -0
  60. data/src/cocoa/bitmap.mm +4 -4
  61. data/src/cocoa/font.mm +35 -30
  62. data/src/cocoa/rays.mm +2 -0
  63. data/src/color.cpp +77 -0
  64. data/src/colorspace.cpp +3 -3
  65. data/src/exception.cpp +3 -18
  66. data/src/image.cpp +9 -2
  67. data/src/matrix.cpp +103 -0
  68. data/src/painter.cpp +475 -224
  69. data/src/point.cpp +52 -0
  70. data/src/texture.cpp +14 -2
  71. data/src/win32/bitmap.cpp +2 -2
  72. data/src/win32/gdi.cpp +22 -13
  73. data/src/win32/gdi.h +7 -7
  74. data/test/helpers.rb +1 -5
  75. data/test/test_bitmap.rb +9 -0
  76. data/test/test_bounds.rb +246 -0
  77. data/test/test_color.rb +88 -0
  78. data/test/test_font.rb +28 -0
  79. data/test/test_image.rb +9 -0
  80. data/test/test_painter.rb +1 -3
  81. data/test/test_point.rb +121 -0
  82. data/test/test_rays.rb +2 -3
  83. data/test/test_texture.rb +1 -3
  84. metadata +146 -75
  85. data/include/rays/helpers.h +0 -37
  86. data/include/rays/transform.h +0 -35
  87. data/src/helpers.cpp +0 -22
  88. data/src/transform.cpp +0 -88
data/ext/rays/native.cpp CHANGED
@@ -6,6 +6,9 @@ using namespace Rucy;
6
6
 
7
7
 
8
8
  void Init_rays ();
9
+ void Init_point ();
10
+ void Init_bounds ();
11
+ void Init_color ();
9
12
  void Init_bitmap ();
10
13
  void Init_texture ();
11
14
  void Init_image ();
@@ -20,6 +23,9 @@ Init_native ()
20
23
  raise(rb_eLoadError, "Rucy::init() failed.");
21
24
 
22
25
  Init_rays();
26
+ Init_point();
27
+ Init_bounds();
28
+ Init_color();
23
29
  Init_bitmap();
24
30
  Init_texture();
25
31
  Init_image();
data/ext/rays/painter.cpp CHANGED
@@ -2,8 +2,11 @@
2
2
 
3
3
 
4
4
  #include <rucy.h>
5
- #include <rays/ruby/image.h>
5
+ #include <rays/ruby/bounds.h>
6
+ #include <rays/ruby/color.h>
7
+ #include <rays/ruby/matrix.h>
6
8
  #include <rays/ruby/font.h>
9
+ #include <rays/ruby/image.h>
7
10
  #include "defs.h"
8
11
 
9
12
 
@@ -12,12 +15,13 @@ using namespace Rucy;
12
15
  using Rays::coord;
13
16
 
14
17
 
18
+ static Class cPainter;
19
+
20
+
15
21
  namespace Rays
16
22
  {
17
23
 
18
24
 
19
- static Class cPainter;
20
-
21
25
  Class
22
26
  painter_class ()
23
27
  {
@@ -33,25 +37,30 @@ namespace Rucy
33
37
 
34
38
 
35
39
  Value
36
- value (const Rays::Painter& painter)
40
+ value (const Rays::Painter& obj)
37
41
  {
38
- return new_type<Rays::Painter>(
39
- Rays::painter_class(), new Rays::Painter(painter));
42
+ return new_type(cPainter, new Rays::Painter(obj));
43
+ }
44
+
45
+ Value
46
+ value (const Rays::Painter* obj)
47
+ {
48
+ return obj ? value(*obj) : nil();
40
49
  }
41
50
 
42
51
 
43
52
  }// Rucy
44
53
 
45
54
 
46
- #define this to<Rays::Painter*>(self)
55
+ #define THIS to<Rays::Painter*>(self)
47
56
 
48
- #define CHECK CHECK_OBJECT(self, Rays::Painter, Rays::painter_class())
57
+ #define CHECK RUCY_CHECK_OBJECT(self, Rays::Painter, cPainter)
49
58
 
50
59
 
51
60
  static
52
61
  RUBY_DEF_ALLOC(alloc, klass)
53
62
  {
54
- return new_type<Rays::Painter>(klass, new Rays::Painter);
63
+ return new_type<Rays::Painter>(klass);
55
64
  }
56
65
  RUBY_END
57
66
 
@@ -64,56 +73,32 @@ RUBY_DEF4(canvas, x, y, width, height)
64
73
  coord yy = to<coord>(y);
65
74
  coord ww = to<coord>(width);
66
75
  coord hh = to<coord>(height);
67
- if (!this->canvas(xx, yy, ww, hh))
68
- error("Painter#canvas(%f, %f, %f, %f) failed.", xx, yy, ww, hh);
76
+ if (!THIS->canvas(xx, yy, ww, hh))
77
+ rays_error("Painter#canvas(%f, %f, %f, %f) failed.", xx, yy, ww, hh);
69
78
 
70
79
  return self;
71
80
  }
72
81
  RUBY_END
73
82
 
74
83
  static
75
- RUBY_DEF0(begin)
84
+ RUBY_DEF0(begin_paint)
76
85
  {
77
86
  CHECK;
78
87
 
79
- if (!this->begin())
80
- error("Painter#begin() failed.");
88
+ if (!THIS->begin())
89
+ rays_error("Painter#begin_paint() failed.");
81
90
 
82
91
  return self;
83
92
  }
84
93
  RUBY_END
85
94
 
86
95
  static
87
- RUBY_DEF0(end)
96
+ RUBY_DEF0(end_paint)
88
97
  {
89
98
  CHECK;
90
99
 
91
- if (!this->end())
92
- error("Painter#end() failed.");
93
-
94
- return self;
95
- }
96
- RUBY_END
97
-
98
- static
99
- RUBY_DEF0(push_matrix)
100
- {
101
- CHECK;
102
-
103
- if (!this->push_matrix())
104
- error("Painter#push_matrix() failed.");
105
-
106
- return self;
107
- }
108
- RUBY_END
109
-
110
- static
111
- RUBY_DEF0(pop_matrix)
112
- {
113
- CHECK;
114
-
115
- if (!this->pop_matrix())
116
- error("Painter#pop_matrix() failed.");
100
+ if (!THIS->end())
101
+ rays_error("Painter#end_paint() failed.");
117
102
 
118
103
  return self;
119
104
  }
@@ -129,8 +114,8 @@ RUBY_DEF4(line, x1_, y1_, x2_, y2_)
129
114
  coord y1 = to<coord>(y1_);
130
115
  coord x2 = to<coord>(x2_);
131
116
  coord y2 = to<coord>(y2_);
132
- if (!this->line(x1, y1, x2, y2))
133
- error("Painter#line(%f, %f, %f, %f) failed.", x1, y1, x2, y2);
117
+ if (!THIS->line(x1, y1, x2, y2))
118
+ rays_error("Painter#line(%f, %f, %f, %f) failed.", x1, y1, x2, y2);
134
119
 
135
120
  return self;
136
121
  }
@@ -145,8 +130,8 @@ RUBY_DEF4(rect, x, y, width, height)
145
130
  coord yy = to<coord>(y);
146
131
  coord ww = to<coord>(width);
147
132
  coord hh = to<coord>(height);
148
- if (!this->rect(xx, yy, ww, hh))
149
- error("Painter#rect(%f, %f, %f, %f) failed.", xx, yy, ww, hh);
133
+ if (!THIS->rect(xx, yy, ww, hh))
134
+ rays_error("Painter#rect(%f, %f, %f, %f) failed.", xx, yy, ww, hh);
150
135
 
151
136
  return self;
152
137
  }
@@ -165,9 +150,9 @@ RUBY_DEFN(ellipse)
165
150
  coord hh = (argc >= 4) ? to<coord>(argv[3]) : 0;
166
151
  coord min_ = (argc >= 5) ? to<coord>(argv[4]) : 0;
167
152
  uint nseg = (argc >= 6) ? to<uint>(argv[5]) : 0;
168
- if (!this->ellipse(xx, yy, ww, hh, min_, nseg))
153
+ if (!THIS->ellipse(xx, yy, ww, hh, min_, nseg))
169
154
  {
170
- error(
155
+ rays_error(
171
156
  "Painter#ellipse(%f, %f, %f, %f, %f, %d) failed.",
172
157
  xx, yy, ww, hh, min_, nseg);
173
158
  }
@@ -191,9 +176,9 @@ RUBY_DEFN(arc)
191
176
  float to_ = (argc >= 6) ? to<float>(argv[5]) : 360;
192
177
  coord min_ = (argc >= 7) ? to<coord>(argv[6]) : 0;
193
178
  uint nseg = (argc >= 8) ? to<uint>(argv[7]) : 0;
194
- if (!this->arc(xx, yy, ww, hh, from, to_, min_, nseg))
179
+ if (!THIS->arc(xx, yy, ww, hh, from, to_, min_, nseg))
195
180
  {
196
- error(
181
+ rays_error(
197
182
  "Painter#arc(%f, %f, %f, %f, %f, %f, %f, %d) failed.",
198
183
  xx, yy, ww, hh, from, to_, min_, nseg);
199
184
  }
@@ -215,15 +200,15 @@ RUBY_DEFN(image)
215
200
 
216
201
  if (argc == 1)
217
202
  {
218
- if (!this->image(*image))
219
- error("Painter#image(%s) failed.", argv[0].inspect().c_str());
203
+ if (!THIS->image(*image))
204
+ rays_error("Painter#image(%s) failed.", argv[0].inspect().c_str());
220
205
  }
221
206
  else if (argc == 3)
222
207
  {
223
208
  coord x = to<coord>(argv[1]), y = to<coord>(argv[2]);
224
- if (!this->image(*image, x, y))
209
+ if (!THIS->image(*image, x, y))
225
210
  {
226
- error(
211
+ rays_error(
227
212
  "Painter#image(%s, %f, %f) failed.",
228
213
  argv[0].inspect().c_str(), x, y);
229
214
  }
@@ -232,9 +217,9 @@ RUBY_DEFN(image)
232
217
  {
233
218
  coord x = to<coord>(argv[1]), w = to<coord>(argv[3]);
234
219
  coord y = to<coord>(argv[2]), h = to<coord>(argv[4]);
235
- if (!this->image(*image, x, y, w, h))
220
+ if (!THIS->image(*image, x, y, w, h))
236
221
  {
237
- error(
222
+ rays_error(
238
223
  "Painter#image(%s, %f, %f, %f, %f) failed.",
239
224
  argv[0].inspect().c_str(), x, y, w, h);
240
225
  }
@@ -245,9 +230,9 @@ RUBY_DEFN(image)
245
230
  coord sy = to<coord>(argv[2]), dy = to<coord>(argv[6]);
246
231
  coord sw = to<coord>(argv[3]);
247
232
  coord sh = to<coord>(argv[4]);
248
- if (!this->image(*image, sx, sy, sw, sh, dx, dy))
233
+ if (!THIS->image(*image, sx, sy, sw, sh, dx, dy))
249
234
  {
250
- error(
235
+ rays_error(
251
236
  "Painter#image(%s, %f, %f, %f, %f, %f, %f) failed.",
252
237
  argv[0].inspect().c_str(), sx, sy, sw, sh, dx, dy);
253
238
  }
@@ -258,9 +243,9 @@ RUBY_DEFN(image)
258
243
  coord sy = to<coord>(argv[2]), dy = to<coord>(argv[6]);
259
244
  coord sw = to<coord>(argv[3]), dw = to<coord>(argv[7]);
260
245
  coord sh = to<coord>(argv[4]), dh = to<coord>(argv[8]);
261
- if (!this->image(*image, sx, sy, sw, sh, dx, dy, dw, dh))
246
+ if (!THIS->image(*image, sx, sy, sw, sh, dx, dy, dw, dh))
262
247
  {
263
- error(
248
+ rays_error(
264
249
  "Painter#image(%s, %f, %f, %f, %f, %f, %f, %f, %f) failed.",
265
250
  argv[0].inspect().c_str(), sx, sy, sw, sh, dx, dy, dw, dh);
266
251
  }
@@ -279,15 +264,15 @@ RUBY_DEFN(text)
279
264
 
280
265
  if (argc == 1)
281
266
  {
282
- if (!this->text(argv[0].c_str()))
283
- error("Painter#text(%s) failed.", argv[0].inspect().c_str());
267
+ if (!THIS->text(argv[0].c_str()))
268
+ rays_error("Painter#text(%s) failed.", argv[0].inspect().c_str());
284
269
  }
285
270
  else if (argc == 3)
286
271
  {
287
272
  coord x = to<coord>(argv[1]), y = to<coord>(argv[2]);
288
- if (!this->text(argv[0].c_str(), x, y))
273
+ if (!THIS->text(argv[0].c_str(), x, y))
289
274
  {
290
- error(
275
+ rays_error(
291
276
  "Painter#text(%s, %f, %f) failed.",
292
277
  argv[0].inspect().c_str(), x, y);
293
278
  }
@@ -296,12 +281,12 @@ RUBY_DEFN(text)
296
281
  {
297
282
  const Rays::Font* font = to<Rays::Font*>(argv[3]);
298
283
  if (!font || !*font)
299
- error("Painter#text: invalid font.");
284
+ rays_error("Painter#text: invalid font.");
300
285
 
301
286
  coord x = to<coord>(argv[1]), y = to<coord>(argv[2]);
302
- if (!this->text(argv[0].c_str(), x, y, *font))
287
+ if (!THIS->text(argv[0].c_str(), x, y, font))
303
288
  {
304
- error(
289
+ rays_error(
305
290
  "Painter#image(%s, %f, %f, %s) failed.",
306
291
  argv[0].inspect().c_str(), x, y, argv[3].inspect().c_str());
307
292
  }
@@ -310,9 +295,9 @@ RUBY_DEFN(text)
310
295
  {
311
296
  coord x = to<coord>(argv[1]), w = to<coord>(argv[3]);
312
297
  coord y = to<coord>(argv[2]), h = to<coord>(argv[4]);
313
- if (!this->text(argv[0].c_str(), x, y, w, h))
298
+ if (!THIS->text(argv[0].c_str(), x, y, w, h))
314
299
  {
315
- error(
300
+ rays_error(
316
301
  "Painter#text(%s, %f, %f, %f, %f) failed.",
317
302
  argv[0].inspect().c_str(), x, y, w, h);
318
303
  }
@@ -321,13 +306,13 @@ RUBY_DEFN(text)
321
306
  {
322
307
  const Rays::Font* font = to<Rays::Font*>(argv[3]);
323
308
  if (!font || !*font)
324
- error("Painter#text: invalid font.");
309
+ rays_error("Painter#text: invalid font.");
325
310
 
326
311
  coord x = to<coord>(argv[1]), w = to<coord>(argv[3]);
327
312
  coord y = to<coord>(argv[2]), h = to<coord>(argv[4]);
328
- if (!this->text(argv[0].c_str(), x, y, w, h, *font))
313
+ if (!THIS->text(argv[0].c_str(), x, y, w, h, font))
329
314
  {
330
- error(
315
+ rays_error(
331
316
  "Painter#image(%s, %f, %f, %f, %f, %s) failed.",
332
317
  argv[0].inspect().c_str(), x, y, w, h, argv[3].inspect().c_str());
333
318
  }
@@ -338,32 +323,18 @@ RUBY_DEFN(text)
338
323
  RUBY_END
339
324
 
340
325
  static
341
- RUBY_DEF0(get_clear)
342
- {
343
- CHECK;
344
-
345
- coord red = 0, green = 0, blue = 0, alpha = 0;
346
- if (!this->get_clear(&red, &green, &blue, &alpha))
347
- error("failed to get color for clear.");
348
-
349
- Value ret[] = {red, green, blue, alpha};
350
- return value(4, ret);
351
- }
352
- RUBY_END
353
-
354
- static
355
- RUBY_DEFN(set_clear)
326
+ RUBY_DEFN(set_background)
356
327
  {
357
328
  CHECK;
358
329
  if (argc < 1 || 4 < argc)
359
- arg_count_error("Painter#set_clear", argc, 1, 2, 3, 4);
330
+ arg_count_error("Painter#set_background", argc, 1, 2, 3, 4);
360
331
 
361
332
  if (argc == 1 || argc == 2)
362
333
  {
363
334
  float v = to<float>(argv[0]);
364
335
  float a = (argc >= 2) ? to<float>(argv[1]) : 1;
365
- if (!this->set_clear(v, v, v, a))
366
- error("Painter#set_clear(%f, %f) failed.", v, a);
336
+ if (!THIS->set_background(v, v, v, a))
337
+ rays_error("Painter#set_background(%f, %f) failed.", v, a);
367
338
  }
368
339
  else
369
340
  {
@@ -371,8 +342,8 @@ RUBY_DEFN(set_clear)
371
342
  float g = to<float>(argv[1]);
372
343
  float b = to<float>(argv[2]);
373
344
  float a = (argc == 4) ? to<float>(argv[3]) : 1;
374
- if (!this->set_clear(r, g, b, a))
375
- error("Painter#set_clear(%f, %f, %f, %f) failed.", r, g, b, a);
345
+ if (!THIS->set_background(r, g, b, a))
346
+ rays_error("Painter#set_background(%f, %f, %f, %f) failed.", r, g, b, a);
376
347
  }
377
348
 
378
349
  return self;
@@ -380,28 +351,23 @@ RUBY_DEFN(set_clear)
380
351
  RUBY_END
381
352
 
382
353
  static
383
- RUBY_DEF0(no_clear)
354
+ RUBY_DEF0(no_background)
384
355
  {
385
356
  CHECK;
386
357
 
387
- if (!this->no_clear())
388
- error("Painter#no_clear() failed.");
358
+ if (!THIS->no_background())
359
+ rays_error("Painter#no_clear() failed.");
389
360
 
390
361
  return self;
391
362
  }
392
363
  RUBY_END
393
364
 
394
365
  static
395
- RUBY_DEF0(get_fill)
366
+ RUBY_DEF0(get_background)
396
367
  {
397
368
  CHECK;
398
369
 
399
- coord red = 0, green = 0, blue = 0, alpha = 0;
400
- if (!this->get_fill(&red, &green, &blue, &alpha))
401
- error("failed to get color for fill.");
402
-
403
- Value ret[] = {red, green, blue, alpha};
404
- return value(4, ret);
370
+ return value(THIS->background());
405
371
  }
406
372
  RUBY_END
407
373
 
@@ -416,8 +382,8 @@ RUBY_DEFN(set_fill)
416
382
  {
417
383
  float v = to<float>(argv[0]);
418
384
  float a = (argc >= 2) ? to<float>(argv[1]) : 1;
419
- if (!this->set_fill(v, v, v, a))
420
- error("Painter#set_fill(%f, %f) failed.", v, a);
385
+ if (!THIS->set_fill(v, v, v, a))
386
+ rays_error("Painter#set_fill(%f, %f) failed.", v, a);
421
387
  }
422
388
  else
423
389
  {
@@ -425,8 +391,8 @@ RUBY_DEFN(set_fill)
425
391
  float g = to<float>(argv[1]);
426
392
  float b = to<float>(argv[2]);
427
393
  float a = (argc == 4) ? to<float>(argv[3]) : 1;
428
- if (!this->set_fill(r, g, b, a))
429
- error("Painter#set_fill(%f, %f, %f, %f) failed.", r, g, b, a);
394
+ if (!THIS->set_fill(r, g, b, a))
395
+ rays_error("Painter#set_fill(%f, %f, %f, %f) failed.", r, g, b, a);
430
396
  }
431
397
 
432
398
  return self;
@@ -438,24 +404,19 @@ RUBY_DEF0(no_fill)
438
404
  {
439
405
  CHECK;
440
406
 
441
- if (!this->no_fill())
442
- error("Painter#no_fill() failed.");
407
+ if (!THIS->no_fill())
408
+ rays_error("Painter#no_fill() failed.");
443
409
 
444
410
  return self;
445
411
  }
446
412
  RUBY_END
447
413
 
448
414
  static
449
- RUBY_DEF0(get_stroke)
415
+ RUBY_DEF0(get_fill)
450
416
  {
451
417
  CHECK;
452
418
 
453
- coord red = 0, green = 0, blue = 0, alpha = 0;
454
- if (!this->get_stroke(&red, &green, &blue, &alpha))
455
- error("failed to get color for stroke.");
456
-
457
- Value ret[] = {red, green, blue, alpha};
458
- return value(4, ret);
419
+ return value(THIS->fill());
459
420
  }
460
421
  RUBY_END
461
422
 
@@ -470,8 +431,8 @@ RUBY_DEFN(set_stroke)
470
431
  {
471
432
  float v = to<float>(argv[0]);
472
433
  float a = (argc >= 2) ? to<float>(argv[1]) : 1;
473
- if (!this->set_stroke(v, v, v, a))
474
- error("Painter#set_stroke(%f, %f) failed.", v, a);
434
+ if (!THIS->set_stroke(v, v, v, a))
435
+ rays_error("Painter#set_stroke(%f, %f) failed.", v, a);
475
436
  }
476
437
  else
477
438
  {
@@ -479,8 +440,8 @@ RUBY_DEFN(set_stroke)
479
440
  float g = to<float>(argv[1]);
480
441
  float b = to<float>(argv[2]);
481
442
  float a = (argc == 4) ? to<float>(argv[3]) : 1;
482
- if (!this->set_stroke(r, g, b, a))
483
- error("Painter#set_stroke(%f, %f, %f, %f) failed.", r, g, b, a);
443
+ if (!THIS->set_stroke(r, g, b, a))
444
+ rays_error("Painter#set_stroke(%f, %f, %f, %f) failed.", r, g, b, a);
484
445
  }
485
446
 
486
447
  return self;
@@ -492,24 +453,19 @@ RUBY_DEF0(no_stroke)
492
453
  {
493
454
  CHECK;
494
455
 
495
- if (!this->no_stroke())
496
- error("Painter#no_stroke() failed.");
456
+ if (!THIS->no_stroke())
457
+ rays_error("Painter#no_stroke() failed.");
497
458
 
498
459
  return self;
499
460
  }
500
461
  RUBY_END
501
462
 
502
463
  static
503
- RUBY_DEF0(get_clip)
464
+ RUBY_DEF0(get_stroke)
504
465
  {
505
466
  CHECK;
506
467
 
507
- coord x = 0, y = 0, width = 0, height = 0;
508
- if (!this->get_clip(&x, &y, &width, &height))
509
- error("failed to get clip rect.");
510
-
511
- Value ret[] = {x, y, width, height};
512
- return value(4, ret);
468
+ return value(THIS->stroke());
513
469
  }
514
470
  RUBY_END
515
471
 
@@ -520,8 +476,8 @@ RUBY_DEF4(set_clip, x, y, width, height)
520
476
 
521
477
  coord xx = to<coord>(x), ww = to<coord>(width);
522
478
  coord yy = to<coord>(y), hh = to<coord>(height);
523
- if (!this->set_clip(xx, yy, ww, hh))
524
- error("Painter#set_clip(%f, %f, %f, %f) failed.", xx, yy, ww, hh);
479
+ if (!THIS->set_clip(xx, yy, ww, hh))
480
+ rays_error("Painter#set_clip(%f, %f, %f, %f) failed.", xx, yy, ww, hh);
525
481
 
526
482
  return self;
527
483
  }
@@ -532,8 +488,169 @@ RUBY_DEF0(no_clip)
532
488
  {
533
489
  CHECK;
534
490
 
535
- if (!this->no_clip())
536
- error("Painter#no_clip() failed.");
491
+ if (!THIS->no_clip())
492
+ rays_error("Painter#no_clip() failed.");
493
+
494
+ return self;
495
+ }
496
+ RUBY_END
497
+
498
+ static
499
+ RUBY_DEF0(get_clip)
500
+ {
501
+ CHECK;
502
+
503
+ return value(THIS->clip());
504
+ }
505
+ RUBY_END
506
+
507
+ static
508
+ RUBY_DEF1(set_font, font)
509
+ {
510
+ CHECK;
511
+
512
+ const Rays::Font* f = font.is_nil()
513
+ ? &Rays::default_font()
514
+ : to<Rays::Font*>(font);
515
+ if (!f || !*f) argument_error();
516
+
517
+ if (!THIS->set_font(*f))
518
+ rays_error("Painter#set_font(%s) failed.", font.inspect().c_str());
519
+
520
+ return self;
521
+ }
522
+ RUBY_END
523
+
524
+ static
525
+ RUBY_DEF0(get_font)
526
+ {
527
+ CHECK;
528
+
529
+ return value(THIS->font());
530
+ }
531
+ RUBY_END
532
+
533
+ static
534
+ RUBY_DEF0(push_attrs)
535
+ {
536
+ CHECK;
537
+
538
+ if (!THIS->push_attrs())
539
+ rays_error("Painter#push_attrs() failed.");
540
+
541
+ return self;
542
+ }
543
+ RUBY_END
544
+
545
+ static
546
+ RUBY_DEF0(pop_attrs)
547
+ {
548
+ CHECK;
549
+
550
+ if (!THIS->pop_attrs())
551
+ rays_error("Painter#pop_attrs() failed.");
552
+
553
+ return self;
554
+ }
555
+ RUBY_END
556
+
557
+
558
+ static
559
+ RUBY_DEFN(translate)
560
+ {
561
+ CHECK;
562
+ if (argc < 2 || 3 < argc)
563
+ arg_count_error("Painter#translate", argc, 2, 3);
564
+
565
+ coord xx = to<coord>(argv[0]);
566
+ coord yy = to<coord>(argv[1]);
567
+ coord zz = (argc >= 3) ? to<coord>(argv[2]) : 0;
568
+ if (!THIS->translate(xx, yy, zz))
569
+ rays_error("Painter#translate(%f %f %f) failed.", xx, yy, zz);
570
+
571
+ return self;
572
+ }
573
+ RUBY_END
574
+
575
+ static
576
+ RUBY_DEFN(scale)
577
+ {
578
+ CHECK;
579
+ if (argc < 2 || 3 < argc)
580
+ arg_count_error("Painter#scale", argc, 2, 3);
581
+
582
+ coord xx = to<coord>(argv[0]);
583
+ coord yy = to<coord>(argv[1]);
584
+ coord zz = (argc >= 3) ? to<coord>(argv[2]) : 1;
585
+ if (!THIS->scale(xx, yy, zz))
586
+ rays_error("Painter#scale(%f %f %f) failed.", xx, yy, zz);
587
+
588
+ return self;
589
+ }
590
+ RUBY_END
591
+
592
+ static
593
+ RUBY_DEFN(rotate)
594
+ {
595
+ CHECK;
596
+ if (argc != 1 && argc != 3 && argc != 4)
597
+ arg_count_error("Painter#rotate", argc, 1, 3, 4);
598
+
599
+ coord aa = to<coord>(argv[0]), xx = 0, yy = 0, zz = 1;
600
+ if (argc >= 3)
601
+ {
602
+ xx = to<coord>(argv[1]);
603
+ yy = to<coord>(argv[2]);
604
+ zz = argc >= 4 ? to<coord>(argv[3]) : 0;
605
+ }
606
+
607
+ if (!THIS->rotate(aa, xx, yy, zz))
608
+ rays_error("Painter#rotate(%f %f %f %f) failed.", aa, xx, yy, zz);
609
+
610
+ return self;
611
+ }
612
+ RUBY_END
613
+
614
+ static
615
+ RUBY_DEFN(set_matrix)
616
+ {
617
+ CHECK;
618
+
619
+ if (!THIS->set_matrix())
620
+ rays_error("Painter#set_matrix() failed.");
621
+
622
+ return self;
623
+ }
624
+ RUBY_END
625
+
626
+ static
627
+ RUBY_DEF0(get_matrix)
628
+ {
629
+ CHECK;
630
+
631
+ return value(THIS->matrix());
632
+ }
633
+ RUBY_END
634
+
635
+ static
636
+ RUBY_DEF0(push_matrix)
637
+ {
638
+ CHECK;
639
+
640
+ if (!THIS->push_matrix())
641
+ rays_error("Painter#push_matrix() failed.");
642
+
643
+ return self;
644
+ }
645
+ RUBY_END
646
+
647
+ static
648
+ RUBY_DEF0(pop_matrix)
649
+ {
650
+ CHECK;
651
+
652
+ if (!THIS->pop_matrix())
653
+ rays_error("Painter#pop_matrix() failed.");
537
654
 
538
655
  return self;
539
656
  }
@@ -543,36 +660,44 @@ RUBY_END
543
660
  void
544
661
  Init_painter ()
545
662
  {
546
- Module m = define_module("Rays");
547
-
548
- Class c = m.define_class("Painter");
549
- Rays::cPainter = c;
550
-
551
- c.define_alloc_func(alloc);
552
-
553
- c.define_method("canvas", canvas);
554
- c.define_method("begin", begin);
555
- c.define_method("end", end);
556
- c.define_method("push_matrix", push_matrix);
557
- c.define_method("pop_matrix", pop_matrix);
558
-
559
- c.define_private_method("draw_line", line);
560
- c.define_private_method("draw_rect", rect);
561
- c.define_private_method("draw_ellipse", ellipse);
562
- c.define_private_method("draw_arc", arc);
563
- c.define_private_method("draw_image", image);
564
- c.define_private_method("draw_text", text);
565
-
566
- c.define_method("get_fill", get_fill);
567
- c.define_method("set_fill", set_fill);
568
- c.define_method("no_fill", no_fill);
569
- c.define_method("get_stroke", get_stroke);
570
- c.define_method("set_stroke", set_stroke);
571
- c.define_method("no_stroke", no_stroke);
572
- c.define_method("get_clear", get_clear);
573
- c.define_method("set_clear", set_clear);
574
- c.define_method("no_clear", no_clear);
575
- c.define_method("get_clip", get_clip);
576
- c.define_method("set_clip", set_clip);
577
- c.define_method("no_clip", no_clip);
663
+ Module mRays = define_module("Rays");
664
+
665
+ cPainter= mRays.define_class("Painter");
666
+ cPainter.define_alloc_func(alloc);
667
+
668
+ cPainter.define_method("canvas", canvas);
669
+ cPainter.define_method("begin_paint", begin_paint);
670
+ cPainter.define_method("end_paint", end_paint);
671
+
672
+ cPainter.define_method("line", line);
673
+ cPainter.define_method("rect", rect);
674
+ cPainter.define_method("ellipse", ellipse);
675
+ cPainter.define_method("arc", arc);
676
+ cPainter.define_method("image", image);
677
+ cPainter.define_method("text", text);
678
+
679
+ cPainter.define_method("set_background", set_background);
680
+ cPainter.define_method("no_background", no_background);
681
+ cPainter.define_method("get_background", get_background);
682
+ cPainter.define_method("set_fill", set_fill);
683
+ cPainter.define_method("no_fill", no_fill);
684
+ cPainter.define_method("get_fill", get_fill);
685
+ cPainter.define_method("set_stroke", set_stroke);
686
+ cPainter.define_method("no_stroke", no_stroke);
687
+ cPainter.define_method("get_stroke", get_stroke);
688
+ cPainter.define_method("set_clip", set_clip);
689
+ cPainter.define_method("no_clip", no_clip);
690
+ cPainter.define_method("get_clip", get_clip);
691
+ cPainter.define_method("set_font", set_font);
692
+ cPainter.define_method("get_font", get_font);
693
+ cPainter.define_method("push_attrs", push_attrs);
694
+ cPainter.define_method("pop_attrs", pop_attrs);
695
+
696
+ cPainter.define_method("translate", translate);
697
+ cPainter.define_method("scale", push_matrix);
698
+ cPainter.define_method("rotate", push_matrix);
699
+ cPainter.define_method("set_matrix", push_matrix);
700
+ cPainter.define_method("get_matrix", push_matrix);
701
+ cPainter.define_method("push_matrix", push_matrix);
702
+ cPainter.define_method("pop_matrix", pop_matrix);
578
703
  }