rays 0.1.6 → 0.1.7

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