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
@@ -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();
@@ -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)
41
+ {
42
+ return new_type(cPainter, new Rays::Painter(obj));
43
+ }
44
+
45
+ Value
46
+ value (const Rays::Painter* obj)
37
47
  {
38
- return new_type<Rays::Painter>(
39
- Rays::painter_class(), new Rays::Painter(painter));
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
  VALUE alloc(VALUE klass)
53
62
  {
54
- return new_type<Rays::Painter>(klass, new Rays::Painter);
63
+ return new_type<Rays::Painter>(klass);
55
64
  }
56
65
 
57
66
  static
@@ -63,52 +72,30 @@ VALUE canvas(VALUE self, VALUE x, VALUE y, VALUE width, VALUE height)
63
72
  coord yy = to<coord>(y);
64
73
  coord ww = to<coord>(width);
65
74
  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);
75
+ if (!THIS->canvas(xx, yy, ww, hh))
76
+ rays_error("Painter#canvas(%f, %f, %f, %f) failed.", xx, yy, ww, hh);
68
77
 
69
78
  return self;
70
79
  }
71
80
 
72
81
  static
73
- VALUE begin(VALUE self)
82
+ VALUE begin_paint(VALUE self)
74
83
  {
75
84
  CHECK;
76
85
 
77
- if (!this->begin())
78
- error("Painter#begin() failed.");
86
+ if (!THIS->begin())
87
+ rays_error("Painter#begin_paint() failed.");
79
88
 
80
89
  return self;
81
90
  }
82
91
 
83
92
  static
84
- VALUE end(VALUE self)
93
+ VALUE end_paint(VALUE self)
85
94
  {
86
95
  CHECK;
87
96
 
88
- if (!this->end())
89
- error("Painter#end() failed.");
90
-
91
- return self;
92
- }
93
-
94
- static
95
- VALUE push_matrix(VALUE self)
96
- {
97
- CHECK;
98
-
99
- if (!this->push_matrix())
100
- error("Painter#push_matrix() failed.");
101
-
102
- return self;
103
- }
104
-
105
- static
106
- VALUE pop_matrix(VALUE self)
107
- {
108
- CHECK;
109
-
110
- if (!this->pop_matrix())
111
- error("Painter#pop_matrix() failed.");
97
+ if (!THIS->end())
98
+ rays_error("Painter#end_paint() failed.");
112
99
 
113
100
  return self;
114
101
  }
@@ -123,8 +110,8 @@ VALUE line(VALUE self, VALUE x1_, VALUE y1_, VALUE x2_, VALUE y2_)
123
110
  coord y1 = to<coord>(y1_);
124
111
  coord x2 = to<coord>(x2_);
125
112
  coord y2 = to<coord>(y2_);
126
- if (!this->line(x1, y1, x2, y2))
127
- error("Painter#line(%f, %f, %f, %f) failed.", x1, y1, x2, y2);
113
+ if (!THIS->line(x1, y1, x2, y2))
114
+ rays_error("Painter#line(%f, %f, %f, %f) failed.", x1, y1, x2, y2);
128
115
 
129
116
  return self;
130
117
  }
@@ -138,8 +125,8 @@ VALUE rect(VALUE self, VALUE x, VALUE y, VALUE width, VALUE height)
138
125
  coord yy = to<coord>(y);
139
126
  coord ww = to<coord>(width);
140
127
  coord hh = to<coord>(height);
141
- if (!this->rect(xx, yy, ww, hh))
142
- error("Painter#rect(%f, %f, %f, %f) failed.", xx, yy, ww, hh);
128
+ if (!THIS->rect(xx, yy, ww, hh))
129
+ rays_error("Painter#rect(%f, %f, %f, %f) failed.", xx, yy, ww, hh);
143
130
 
144
131
  return self;
145
132
  }
@@ -157,9 +144,9 @@ VALUE ellipse(VALUE self)
157
144
  coord hh = (argc >= 4) ? to<coord>(argv[3]) : 0;
158
145
  coord min_ = (argc >= 5) ? to<coord>(argv[4]) : 0;
159
146
  uint nseg = (argc >= 6) ? to<uint>(argv[5]) : 0;
160
- if (!this->ellipse(xx, yy, ww, hh, min_, nseg))
147
+ if (!THIS->ellipse(xx, yy, ww, hh, min_, nseg))
161
148
  {
162
- error(
149
+ rays_error(
163
150
  "Painter#ellipse(%f, %f, %f, %f, %f, %d) failed.",
164
151
  xx, yy, ww, hh, min_, nseg);
165
152
  }
@@ -182,9 +169,9 @@ VALUE arc(VALUE self)
182
169
  float to_ = (argc >= 6) ? to<float>(argv[5]) : 360;
183
170
  coord min_ = (argc >= 7) ? to<coord>(argv[6]) : 0;
184
171
  uint nseg = (argc >= 8) ? to<uint>(argv[7]) : 0;
185
- if (!this->arc(xx, yy, ww, hh, from, to_, min_, nseg))
172
+ if (!THIS->arc(xx, yy, ww, hh, from, to_, min_, nseg))
186
173
  {
187
- error(
174
+ rays_error(
188
175
  "Painter#arc(%f, %f, %f, %f, %f, %f, %f, %d) failed.",
189
176
  xx, yy, ww, hh, from, to_, min_, nseg);
190
177
  }
@@ -205,15 +192,15 @@ VALUE image(VALUE self)
205
192
 
206
193
  if (argc == 1)
207
194
  {
208
- if (!this->image(*image))
209
- error("Painter#image(%s) failed.", argv[0].inspect().c_str());
195
+ if (!THIS->image(*image))
196
+ rays_error("Painter#image(%s) failed.", argv[0].inspect().c_str());
210
197
  }
211
198
  else if (argc == 3)
212
199
  {
213
200
  coord x = to<coord>(argv[1]), y = to<coord>(argv[2]);
214
- if (!this->image(*image, x, y))
201
+ if (!THIS->image(*image, x, y))
215
202
  {
216
- error(
203
+ rays_error(
217
204
  "Painter#image(%s, %f, %f) failed.",
218
205
  argv[0].inspect().c_str(), x, y);
219
206
  }
@@ -222,9 +209,9 @@ VALUE image(VALUE self)
222
209
  {
223
210
  coord x = to<coord>(argv[1]), w = to<coord>(argv[3]);
224
211
  coord y = to<coord>(argv[2]), h = to<coord>(argv[4]);
225
- if (!this->image(*image, x, y, w, h))
212
+ if (!THIS->image(*image, x, y, w, h))
226
213
  {
227
- error(
214
+ rays_error(
228
215
  "Painter#image(%s, %f, %f, %f, %f) failed.",
229
216
  argv[0].inspect().c_str(), x, y, w, h);
230
217
  }
@@ -235,9 +222,9 @@ VALUE image(VALUE self)
235
222
  coord sy = to<coord>(argv[2]), dy = to<coord>(argv[6]);
236
223
  coord sw = to<coord>(argv[3]);
237
224
  coord sh = to<coord>(argv[4]);
238
- if (!this->image(*image, sx, sy, sw, sh, dx, dy))
225
+ if (!THIS->image(*image, sx, sy, sw, sh, dx, dy))
239
226
  {
240
- error(
227
+ rays_error(
241
228
  "Painter#image(%s, %f, %f, %f, %f, %f, %f) failed.",
242
229
  argv[0].inspect().c_str(), sx, sy, sw, sh, dx, dy);
243
230
  }
@@ -248,9 +235,9 @@ VALUE image(VALUE self)
248
235
  coord sy = to<coord>(argv[2]), dy = to<coord>(argv[6]);
249
236
  coord sw = to<coord>(argv[3]), dw = to<coord>(argv[7]);
250
237
  coord sh = to<coord>(argv[4]), dh = to<coord>(argv[8]);
251
- if (!this->image(*image, sx, sy, sw, sh, dx, dy, dw, dh))
238
+ if (!THIS->image(*image, sx, sy, sw, sh, dx, dy, dw, dh))
252
239
  {
253
- error(
240
+ rays_error(
254
241
  "Painter#image(%s, %f, %f, %f, %f, %f, %f, %f, %f) failed.",
255
242
  argv[0].inspect().c_str(), sx, sy, sw, sh, dx, dy, dw, dh);
256
243
  }
@@ -268,15 +255,15 @@ VALUE text(VALUE self)
268
255
 
269
256
  if (argc == 1)
270
257
  {
271
- if (!this->text(argv[0].c_str()))
272
- error("Painter#text(%s) failed.", argv[0].inspect().c_str());
258
+ if (!THIS->text(argv[0].c_str()))
259
+ rays_error("Painter#text(%s) failed.", argv[0].inspect().c_str());
273
260
  }
274
261
  else if (argc == 3)
275
262
  {
276
263
  coord x = to<coord>(argv[1]), y = to<coord>(argv[2]);
277
- if (!this->text(argv[0].c_str(), x, y))
264
+ if (!THIS->text(argv[0].c_str(), x, y))
278
265
  {
279
- error(
266
+ rays_error(
280
267
  "Painter#text(%s, %f, %f) failed.",
281
268
  argv[0].inspect().c_str(), x, y);
282
269
  }
@@ -285,12 +272,12 @@ VALUE text(VALUE self)
285
272
  {
286
273
  const Rays::Font* font = to<Rays::Font*>(argv[3]);
287
274
  if (!font || !*font)
288
- error("Painter#text: invalid font.");
275
+ rays_error("Painter#text: invalid font.");
289
276
 
290
277
  coord x = to<coord>(argv[1]), y = to<coord>(argv[2]);
291
- if (!this->text(argv[0].c_str(), x, y, *font))
278
+ if (!THIS->text(argv[0].c_str(), x, y, font))
292
279
  {
293
- error(
280
+ rays_error(
294
281
  "Painter#image(%s, %f, %f, %s) failed.",
295
282
  argv[0].inspect().c_str(), x, y, argv[3].inspect().c_str());
296
283
  }
@@ -299,9 +286,9 @@ VALUE text(VALUE self)
299
286
  {
300
287
  coord x = to<coord>(argv[1]), w = to<coord>(argv[3]);
301
288
  coord y = to<coord>(argv[2]), h = to<coord>(argv[4]);
302
- if (!this->text(argv[0].c_str(), x, y, w, h))
289
+ if (!THIS->text(argv[0].c_str(), x, y, w, h))
303
290
  {
304
- error(
291
+ rays_error(
305
292
  "Painter#text(%s, %f, %f, %f, %f) failed.",
306
293
  argv[0].inspect().c_str(), x, y, w, h);
307
294
  }
@@ -310,13 +297,13 @@ VALUE text(VALUE self)
310
297
  {
311
298
  const Rays::Font* font = to<Rays::Font*>(argv[3]);
312
299
  if (!font || !*font)
313
- error("Painter#text: invalid font.");
300
+ rays_error("Painter#text: invalid font.");
314
301
 
315
302
  coord x = to<coord>(argv[1]), w = to<coord>(argv[3]);
316
303
  coord y = to<coord>(argv[2]), h = to<coord>(argv[4]);
317
- if (!this->text(argv[0].c_str(), x, y, w, h, *font))
304
+ if (!THIS->text(argv[0].c_str(), x, y, w, h, font))
318
305
  {
319
- error(
306
+ rays_error(
320
307
  "Painter#image(%s, %f, %f, %f, %f, %s) failed.",
321
308
  argv[0].inspect().c_str(), x, y, w, h, argv[3].inspect().c_str());
322
309
  }
@@ -326,31 +313,18 @@ VALUE text(VALUE self)
326
313
  }
327
314
 
328
315
  static
329
- VALUE get_clear(VALUE self)
330
- {
331
- CHECK;
332
-
333
- coord red = 0, green = 0, blue = 0, alpha = 0;
334
- if (!this->get_clear(&red, &green, &blue, &alpha))
335
- error("failed to get color for clear.");
336
-
337
- Value ret[] = {red, green, blue, alpha};
338
- return value(4, ret);
339
- }
340
-
341
- static
342
- VALUE set_clear(VALUE self)
316
+ VALUE set_background(VALUE self)
343
317
  {
344
318
  CHECK;
345
319
  if (argc < 1 || 4 < argc)
346
- arg_count_error("Painter#set_clear", argc, 1, 2, 3, 4);
320
+ arg_count_error("Painter#set_background", argc, 1, 2, 3, 4);
347
321
 
348
322
  if (argc == 1 || argc == 2)
349
323
  {
350
324
  float v = to<float>(argv[0]);
351
325
  float a = (argc >= 2) ? to<float>(argv[1]) : 1;
352
- if (!this->set_clear(v, v, v, a))
353
- error("Painter#set_clear(%f, %f) failed.", v, a);
326
+ if (!THIS->set_background(v, v, v, a))
327
+ rays_error("Painter#set_background(%f, %f) failed.", v, a);
354
328
  }
355
329
  else
356
330
  {
@@ -358,35 +332,30 @@ VALUE set_clear(VALUE self)
358
332
  float g = to<float>(argv[1]);
359
333
  float b = to<float>(argv[2]);
360
334
  float a = (argc == 4) ? to<float>(argv[3]) : 1;
361
- if (!this->set_clear(r, g, b, a))
362
- error("Painter#set_clear(%f, %f, %f, %f) failed.", r, g, b, a);
335
+ if (!THIS->set_background(r, g, b, a))
336
+ rays_error("Painter#set_background(%f, %f, %f, %f) failed.", r, g, b, a);
363
337
  }
364
338
 
365
339
  return self;
366
340
  }
367
341
 
368
342
  static
369
- VALUE no_clear(VALUE self)
343
+ VALUE no_background(VALUE self)
370
344
  {
371
345
  CHECK;
372
346
 
373
- if (!this->no_clear())
374
- error("Painter#no_clear() failed.");
347
+ if (!THIS->no_background())
348
+ rays_error("Painter#no_clear() failed.");
375
349
 
376
350
  return self;
377
351
  }
378
352
 
379
353
  static
380
- VALUE get_fill(VALUE self)
354
+ VALUE get_background(VALUE self)
381
355
  {
382
356
  CHECK;
383
357
 
384
- coord red = 0, green = 0, blue = 0, alpha = 0;
385
- if (!this->get_fill(&red, &green, &blue, &alpha))
386
- error("failed to get color for fill.");
387
-
388
- Value ret[] = {red, green, blue, alpha};
389
- return value(4, ret);
358
+ return value(THIS->background());
390
359
  }
391
360
 
392
361
  static
@@ -400,8 +369,8 @@ VALUE set_fill(VALUE self)
400
369
  {
401
370
  float v = to<float>(argv[0]);
402
371
  float a = (argc >= 2) ? to<float>(argv[1]) : 1;
403
- if (!this->set_fill(v, v, v, a))
404
- error("Painter#set_fill(%f, %f) failed.", v, a);
372
+ if (!THIS->set_fill(v, v, v, a))
373
+ rays_error("Painter#set_fill(%f, %f) failed.", v, a);
405
374
  }
406
375
  else
407
376
  {
@@ -409,8 +378,8 @@ VALUE set_fill(VALUE self)
409
378
  float g = to<float>(argv[1]);
410
379
  float b = to<float>(argv[2]);
411
380
  float a = (argc == 4) ? to<float>(argv[3]) : 1;
412
- if (!this->set_fill(r, g, b, a))
413
- error("Painter#set_fill(%f, %f, %f, %f) failed.", r, g, b, a);
381
+ if (!THIS->set_fill(r, g, b, a))
382
+ rays_error("Painter#set_fill(%f, %f, %f, %f) failed.", r, g, b, a);
414
383
  }
415
384
 
416
385
  return self;
@@ -421,23 +390,18 @@ VALUE no_fill(VALUE self)
421
390
  {
422
391
  CHECK;
423
392
 
424
- if (!this->no_fill())
425
- error("Painter#no_fill() failed.");
393
+ if (!THIS->no_fill())
394
+ rays_error("Painter#no_fill() failed.");
426
395
 
427
396
  return self;
428
397
  }
429
398
 
430
399
  static
431
- VALUE get_stroke(VALUE self)
400
+ VALUE get_fill(VALUE self)
432
401
  {
433
402
  CHECK;
434
403
 
435
- coord red = 0, green = 0, blue = 0, alpha = 0;
436
- if (!this->get_stroke(&red, &green, &blue, &alpha))
437
- error("failed to get color for stroke.");
438
-
439
- Value ret[] = {red, green, blue, alpha};
440
- return value(4, ret);
404
+ return value(THIS->fill());
441
405
  }
442
406
 
443
407
  static
@@ -451,8 +415,8 @@ VALUE set_stroke(VALUE self)
451
415
  {
452
416
  float v = to<float>(argv[0]);
453
417
  float a = (argc >= 2) ? to<float>(argv[1]) : 1;
454
- if (!this->set_stroke(v, v, v, a))
455
- error("Painter#set_stroke(%f, %f) failed.", v, a);
418
+ if (!THIS->set_stroke(v, v, v, a))
419
+ rays_error("Painter#set_stroke(%f, %f) failed.", v, a);
456
420
  }
457
421
  else
458
422
  {
@@ -460,8 +424,8 @@ VALUE set_stroke(VALUE self)
460
424
  float g = to<float>(argv[1]);
461
425
  float b = to<float>(argv[2]);
462
426
  float a = (argc == 4) ? to<float>(argv[3]) : 1;
463
- if (!this->set_stroke(r, g, b, a))
464
- error("Painter#set_stroke(%f, %f, %f, %f) failed.", r, g, b, a);
427
+ if (!THIS->set_stroke(r, g, b, a))
428
+ rays_error("Painter#set_stroke(%f, %f, %f, %f) failed.", r, g, b, a);
465
429
  }
466
430
 
467
431
  return self;
@@ -472,23 +436,18 @@ VALUE no_stroke(VALUE self)
472
436
  {
473
437
  CHECK;
474
438
 
475
- if (!this->no_stroke())
476
- error("Painter#no_stroke() failed.");
439
+ if (!THIS->no_stroke())
440
+ rays_error("Painter#no_stroke() failed.");
477
441
 
478
442
  return self;
479
443
  }
480
444
 
481
445
  static
482
- VALUE get_clip(VALUE self)
446
+ VALUE get_stroke(VALUE self)
483
447
  {
484
448
  CHECK;
485
449
 
486
- coord x = 0, y = 0, width = 0, height = 0;
487
- if (!this->get_clip(&x, &y, &width, &height))
488
- error("failed to get clip rect.");
489
-
490
- Value ret[] = {x, y, width, height};
491
- return value(4, ret);
450
+ return value(THIS->stroke());
492
451
  }
493
452
 
494
453
  static
@@ -498,8 +457,8 @@ VALUE set_clip(VALUE self, VALUE x, VALUE y, VALUE width, VALUE height)
498
457
 
499
458
  coord xx = to<coord>(x), ww = to<coord>(width);
500
459
  coord yy = to<coord>(y), hh = to<coord>(height);
501
- if (!this->set_clip(xx, yy, ww, hh))
502
- error("Painter#set_clip(%f, %f, %f, %f) failed.", xx, yy, ww, hh);
460
+ if (!THIS->set_clip(xx, yy, ww, hh))
461
+ rays_error("Painter#set_clip(%f, %f, %f, %f) failed.", xx, yy, ww, hh);
503
462
 
504
463
  return self;
505
464
  }
@@ -509,8 +468,157 @@ VALUE no_clip(VALUE self)
509
468
  {
510
469
  CHECK;
511
470
 
512
- if (!this->no_clip())
513
- error("Painter#no_clip() failed.");
471
+ if (!THIS->no_clip())
472
+ rays_error("Painter#no_clip() failed.");
473
+
474
+ return self;
475
+ }
476
+
477
+ static
478
+ VALUE get_clip(VALUE self)
479
+ {
480
+ CHECK;
481
+
482
+ return value(THIS->clip());
483
+ }
484
+
485
+ static
486
+ VALUE set_font(VALUE self, VALUE font)
487
+ {
488
+ CHECK;
489
+
490
+ const Rays::Font* f = font.is_nil()
491
+ ? &Rays::default_font()
492
+ : to<Rays::Font*>(font);
493
+ if (!f || !*f) argument_error();
494
+
495
+ if (!THIS->set_font(*f))
496
+ rays_error("Painter#set_font(%s) failed.", font.inspect().c_str());
497
+
498
+ return self;
499
+ }
500
+
501
+ static
502
+ VALUE get_font(VALUE self)
503
+ {
504
+ CHECK;
505
+
506
+ return value(THIS->font());
507
+ }
508
+
509
+ static
510
+ VALUE push_attrs(VALUE self)
511
+ {
512
+ CHECK;
513
+
514
+ if (!THIS->push_attrs())
515
+ rays_error("Painter#push_attrs() failed.");
516
+
517
+ return self;
518
+ }
519
+
520
+ static
521
+ VALUE pop_attrs(VALUE self)
522
+ {
523
+ CHECK;
524
+
525
+ if (!THIS->pop_attrs())
526
+ rays_error("Painter#pop_attrs() failed.");
527
+
528
+ return self;
529
+ }
530
+
531
+
532
+ static
533
+ VALUE translate(VALUE self)
534
+ {
535
+ CHECK;
536
+ if (argc < 2 || 3 < argc)
537
+ arg_count_error("Painter#translate", argc, 2, 3);
538
+
539
+ coord xx = to<coord>(argv[0]);
540
+ coord yy = to<coord>(argv[1]);
541
+ coord zz = (argc >= 3) ? to<coord>(argv[2]) : 0;
542
+ if (!THIS->translate(xx, yy, zz))
543
+ rays_error("Painter#translate(%f %f %f) failed.", xx, yy, zz);
544
+
545
+ return self;
546
+ }
547
+
548
+ static
549
+ VALUE scale(VALUE self)
550
+ {
551
+ CHECK;
552
+ if (argc < 2 || 3 < argc)
553
+ arg_count_error("Painter#scale", argc, 2, 3);
554
+
555
+ coord xx = to<coord>(argv[0]);
556
+ coord yy = to<coord>(argv[1]);
557
+ coord zz = (argc >= 3) ? to<coord>(argv[2]) : 1;
558
+ if (!THIS->scale(xx, yy, zz))
559
+ rays_error("Painter#scale(%f %f %f) failed.", xx, yy, zz);
560
+
561
+ return self;
562
+ }
563
+
564
+ static
565
+ VALUE rotate(VALUE self)
566
+ {
567
+ CHECK;
568
+ if (argc != 1 && argc != 3 && argc != 4)
569
+ arg_count_error("Painter#rotate", argc, 1, 3, 4);
570
+
571
+ coord aa = to<coord>(argv[0]), xx = 0, yy = 0, zz = 1;
572
+ if (argc >= 3)
573
+ {
574
+ xx = to<coord>(argv[1]);
575
+ yy = to<coord>(argv[2]);
576
+ zz = argc >= 4 ? to<coord>(argv[3]) : 0;
577
+ }
578
+
579
+ if (!THIS->rotate(aa, xx, yy, zz))
580
+ rays_error("Painter#rotate(%f %f %f %f) failed.", aa, xx, yy, zz);
581
+
582
+ return self;
583
+ }
584
+
585
+ static
586
+ VALUE set_matrix(VALUE self)
587
+ {
588
+ CHECK;
589
+
590
+ if (!THIS->set_matrix())
591
+ rays_error("Painter#set_matrix() failed.");
592
+
593
+ return self;
594
+ }
595
+
596
+ static
597
+ VALUE get_matrix(VALUE self)
598
+ {
599
+ CHECK;
600
+
601
+ return value(THIS->matrix());
602
+ }
603
+
604
+ static
605
+ VALUE push_matrix(VALUE self)
606
+ {
607
+ CHECK;
608
+
609
+ if (!THIS->push_matrix())
610
+ rays_error("Painter#push_matrix() failed.");
611
+
612
+ return self;
613
+ }
614
+
615
+ static
616
+ VALUE pop_matrix(VALUE self)
617
+ {
618
+ CHECK;
619
+
620
+ if (!THIS->pop_matrix())
621
+ rays_error("Painter#pop_matrix() failed.");
514
622
 
515
623
  return self;
516
624
  }
@@ -519,36 +627,44 @@ VALUE no_clip(VALUE self)
519
627
  void
520
628
  Init_painter ()
521
629
  {
522
- Module m = rb_define_module("Rays");
523
-
524
- Class c = rb_define_class_under(m, "Painter", rb_cObject);
525
- Rays::cPainter = c;
526
-
527
- rb_define_alloc_func(c, alloc);
528
-
529
- rb_define_method(c, "canvas", RUBY_METHOD_FUNC(canvas), 4);
530
- rb_define_method(c, "begin", RUBY_METHOD_FUNC(begin), 0);
531
- rb_define_method(c, "end", RUBY_METHOD_FUNC(end), 0);
532
- rb_define_method(c, "push_matrix", RUBY_METHOD_FUNC(push_matrix), 0);
533
- rb_define_method(c, "pop_matrix", RUBY_METHOD_FUNC(pop_matrix), 0);
534
-
535
- rb_define_private_method(c, "draw_line", RUBY_METHOD_FUNC(line), 4);
536
- rb_define_private_method(c, "draw_rect", RUBY_METHOD_FUNC(rect), 4);
537
- rb_define_private_method(c, "draw_ellipse", RUBY_METHOD_FUNC(ellipse), -1);
538
- rb_define_private_method(c, "draw_arc", RUBY_METHOD_FUNC(arc), -1);
539
- rb_define_private_method(c, "draw_image", RUBY_METHOD_FUNC(image), -1);
540
- rb_define_private_method(c, "draw_text", RUBY_METHOD_FUNC(text), -1);
541
-
542
- rb_define_method(c, "get_fill", RUBY_METHOD_FUNC(get_fill), 0);
543
- rb_define_method(c, "set_fill", RUBY_METHOD_FUNC(set_fill), -1);
544
- rb_define_method(c, "no_fill", RUBY_METHOD_FUNC(no_fill), 0);
545
- rb_define_method(c, "get_stroke", RUBY_METHOD_FUNC(get_stroke), 0);
546
- rb_define_method(c, "set_stroke", RUBY_METHOD_FUNC(set_stroke), -1);
547
- rb_define_method(c, "no_stroke", RUBY_METHOD_FUNC(no_stroke), 0);
548
- rb_define_method(c, "get_clear", RUBY_METHOD_FUNC(get_clear), 0);
549
- rb_define_method(c, "set_clear", RUBY_METHOD_FUNC(set_clear), -1);
550
- rb_define_method(c, "no_clear", RUBY_METHOD_FUNC(no_clear), 0);
551
- rb_define_method(c, "get_clip", RUBY_METHOD_FUNC(get_clip), 0);
552
- rb_define_method(c, "set_clip", RUBY_METHOD_FUNC(set_clip), 4);
553
- rb_define_method(c, "no_clip", RUBY_METHOD_FUNC(no_clip), 0);
630
+ Module mRays = rb_define_module("Rays");
631
+
632
+ cPainter = rb_define_class_under(mRays, "Painter", rb_cObject);
633
+ rb_define_alloc_func(cPainter, alloc);
634
+
635
+ rb_define_method(cPainter, "canvas", RUBY_METHOD_FUNC(canvas), 4);
636
+ rb_define_method(cPainter, "begin_paint", RUBY_METHOD_FUNC(begin_paint), 0);
637
+ rb_define_method(cPainter, "end_paint", RUBY_METHOD_FUNC(end_paint), 0);
638
+
639
+ rb_define_method(cPainter, "line", RUBY_METHOD_FUNC(line), 4);
640
+ rb_define_method(cPainter, "rect", RUBY_METHOD_FUNC(rect), 4);
641
+ rb_define_method(cPainter, "ellipse", RUBY_METHOD_FUNC(ellipse), -1);
642
+ rb_define_method(cPainter, "arc", RUBY_METHOD_FUNC(arc), -1);
643
+ rb_define_method(cPainter, "image", RUBY_METHOD_FUNC(image), -1);
644
+ rb_define_method(cPainter, "text", RUBY_METHOD_FUNC(text), -1);
645
+
646
+ rb_define_method(cPainter, "set_background", RUBY_METHOD_FUNC(set_background), -1);
647
+ rb_define_method(cPainter, "no_background", RUBY_METHOD_FUNC(no_background), 0);
648
+ rb_define_method(cPainter, "get_background", RUBY_METHOD_FUNC(get_background), 0);
649
+ rb_define_method(cPainter, "set_fill", RUBY_METHOD_FUNC(set_fill), -1);
650
+ rb_define_method(cPainter, "no_fill", RUBY_METHOD_FUNC(no_fill), 0);
651
+ rb_define_method(cPainter, "get_fill", RUBY_METHOD_FUNC(get_fill), 0);
652
+ rb_define_method(cPainter, "set_stroke", RUBY_METHOD_FUNC(set_stroke), -1);
653
+ rb_define_method(cPainter, "no_stroke", RUBY_METHOD_FUNC(no_stroke), 0);
654
+ rb_define_method(cPainter, "get_stroke", RUBY_METHOD_FUNC(get_stroke), 0);
655
+ rb_define_method(cPainter, "set_clip", RUBY_METHOD_FUNC(set_clip), 4);
656
+ rb_define_method(cPainter, "no_clip", RUBY_METHOD_FUNC(no_clip), 0);
657
+ rb_define_method(cPainter, "get_clip", RUBY_METHOD_FUNC(get_clip), 0);
658
+ rb_define_method(cPainter, "set_font", RUBY_METHOD_FUNC(set_font), 1);
659
+ rb_define_method(cPainter, "get_font", RUBY_METHOD_FUNC(get_font), 0);
660
+ rb_define_method(cPainter, "push_attrs", RUBY_METHOD_FUNC(push_attrs), 0);
661
+ rb_define_method(cPainter, "pop_attrs", RUBY_METHOD_FUNC(pop_attrs), 0);
662
+
663
+ rb_define_method(cPainter, "translate", RUBY_METHOD_FUNC(translate), -1);
664
+ rb_define_method(cPainter, "scale", RUBY_METHOD_FUNC(push_matrix), 0);
665
+ rb_define_method(cPainter, "rotate", RUBY_METHOD_FUNC(push_matrix), 0);
666
+ rb_define_method(cPainter, "set_matrix", RUBY_METHOD_FUNC(push_matrix), 0);
667
+ rb_define_method(cPainter, "get_matrix", RUBY_METHOD_FUNC(push_matrix), 0);
668
+ rb_define_method(cPainter, "push_matrix", RUBY_METHOD_FUNC(push_matrix), 0);
669
+ rb_define_method(cPainter, "pop_matrix", RUBY_METHOD_FUNC(pop_matrix), 0);
554
670
  }