rays 0.1.12 → 0.1.17

Sign up to get free protection for your applications and to get access to all the features.
Files changed (168) hide show
  1. checksums.yaml +5 -5
  2. data/.doc/ext/rays/bitmap.cpp +22 -76
  3. data/.doc/ext/rays/bounds.cpp +95 -125
  4. data/.doc/ext/rays/camera.cpp +171 -0
  5. data/.doc/ext/rays/color.cpp +223 -45
  6. data/.doc/ext/rays/color_space.cpp +146 -46
  7. data/.doc/ext/rays/defs.cpp +183 -0
  8. data/.doc/ext/rays/font.cpp +69 -21
  9. data/.doc/ext/rays/image.cpp +26 -37
  10. data/.doc/ext/rays/matrix.cpp +186 -29
  11. data/.doc/ext/rays/native.cpp +14 -8
  12. data/.doc/ext/rays/noise.cpp +53 -0
  13. data/.doc/ext/rays/painter.cpp +187 -292
  14. data/.doc/ext/rays/point.cpp +96 -77
  15. data/.doc/ext/rays/polygon.cpp +313 -0
  16. data/.doc/ext/rays/polygon_line.cpp +96 -0
  17. data/.doc/ext/rays/polyline.cpp +167 -0
  18. data/.doc/ext/rays/rays.cpp +103 -12
  19. data/.doc/ext/rays/shader.cpp +83 -9
  20. data/LICENSE +21 -0
  21. data/README.md +1 -1
  22. data/Rakefile +24 -9
  23. data/VERSION +1 -1
  24. data/ext/rays/bitmap.cpp +23 -81
  25. data/ext/rays/bounds.cpp +100 -128
  26. data/ext/rays/camera.cpp +186 -0
  27. data/ext/rays/color.cpp +231 -51
  28. data/ext/rays/color_space.cpp +149 -47
  29. data/ext/rays/defs.cpp +183 -0
  30. data/ext/rays/defs.h +26 -2
  31. data/ext/rays/extconf.rb +2 -3
  32. data/ext/rays/font.cpp +74 -24
  33. data/ext/rays/image.cpp +28 -40
  34. data/ext/rays/matrix.cpp +198 -30
  35. data/ext/rays/native.cpp +14 -8
  36. data/ext/rays/noise.cpp +55 -0
  37. data/ext/rays/painter.cpp +203 -298
  38. data/ext/rays/point.cpp +105 -81
  39. data/ext/rays/polygon.cpp +329 -0
  40. data/ext/rays/polygon_line.cpp +99 -0
  41. data/ext/rays/polyline.cpp +176 -0
  42. data/ext/rays/rays.cpp +103 -13
  43. data/ext/rays/shader.cpp +84 -9
  44. data/include/rays.h +10 -2
  45. data/include/rays/bitmap.h +14 -26
  46. data/include/rays/bounds.h +21 -4
  47. data/include/rays/camera.h +74 -0
  48. data/include/rays/color.h +25 -14
  49. data/include/rays/color_space.h +15 -10
  50. data/include/rays/coord.h +114 -0
  51. data/include/rays/debug.h +22 -0
  52. data/include/rays/defs.h +36 -0
  53. data/include/rays/exception.h +6 -2
  54. data/include/rays/font.h +4 -4
  55. data/include/rays/image.h +12 -18
  56. data/include/rays/matrix.h +50 -24
  57. data/include/rays/noise.h +42 -0
  58. data/include/rays/opengl.h +2 -50
  59. data/include/rays/painter.h +89 -93
  60. data/include/rays/point.h +44 -51
  61. data/include/rays/polygon.h +198 -0
  62. data/include/rays/polyline.h +71 -0
  63. data/include/rays/rays.h +3 -0
  64. data/include/rays/ruby.h +7 -1
  65. data/include/rays/ruby/bounds.h +1 -1
  66. data/include/rays/ruby/camera.h +41 -0
  67. data/include/rays/ruby/color.h +1 -1
  68. data/include/rays/ruby/color_space.h +1 -1
  69. data/include/rays/ruby/font.h +1 -1
  70. data/include/rays/ruby/matrix.h +1 -1
  71. data/include/rays/ruby/point.h +1 -1
  72. data/include/rays/ruby/polygon.h +52 -0
  73. data/include/rays/ruby/polyline.h +41 -0
  74. data/include/rays/ruby/rays.h +8 -0
  75. data/include/rays/ruby/shader.h +1 -1
  76. data/include/rays/shader.h +36 -8
  77. data/lib/rays.rb +7 -2
  78. data/lib/rays/bitmap.rb +0 -15
  79. data/lib/rays/bounds.rb +17 -23
  80. data/lib/rays/camera.rb +24 -0
  81. data/lib/rays/color.rb +20 -47
  82. data/lib/rays/color_space.rb +13 -13
  83. data/lib/rays/image.rb +3 -7
  84. data/lib/rays/matrix.rb +28 -0
  85. data/lib/rays/module.rb +4 -19
  86. data/lib/rays/painter.rb +78 -93
  87. data/lib/rays/point.rb +13 -21
  88. data/lib/rays/polygon.rb +58 -0
  89. data/lib/rays/polygon_line.rb +36 -0
  90. data/lib/rays/polyline.rb +32 -0
  91. data/lib/rays/shader.rb +20 -1
  92. data/rays.gemspec +5 -7
  93. data/src/bitmap.h +36 -0
  94. data/src/bounds.cpp +74 -11
  95. data/src/color.cpp +58 -23
  96. data/src/color_space.cpp +52 -34
  97. data/src/color_space.h +22 -0
  98. data/src/coord.cpp +170 -0
  99. data/src/coord.h +35 -0
  100. data/src/font.cpp +118 -0
  101. data/src/font.h +64 -0
  102. data/src/frame_buffer.cpp +37 -71
  103. data/src/frame_buffer.h +4 -4
  104. data/src/image.cpp +172 -98
  105. data/src/image.h +25 -0
  106. data/src/ios/bitmap.h +23 -0
  107. data/src/ios/bitmap.mm +133 -110
  108. data/src/ios/camera.mm +510 -0
  109. data/src/ios/font.mm +50 -62
  110. data/src/ios/helper.h +4 -4
  111. data/src/ios/opengl.mm +19 -4
  112. data/src/ios/rays.mm +3 -0
  113. data/src/matrix.cpp +111 -26
  114. data/src/matrix.h +30 -0
  115. data/src/noise.cpp +74 -0
  116. data/src/opengl.cpp +9 -27
  117. data/src/opengl.h +37 -0
  118. data/src/osx/bitmap.h +23 -0
  119. data/src/osx/bitmap.mm +133 -110
  120. data/src/osx/camera.mm +451 -0
  121. data/src/osx/font.mm +49 -62
  122. data/src/osx/helper.h +2 -2
  123. data/src/osx/opengl.mm +19 -83
  124. data/src/osx/rays.mm +3 -0
  125. data/src/painter.cpp +845 -671
  126. data/src/painter.h +24 -0
  127. data/src/point.cpp +140 -119
  128. data/src/polygon.cpp +1266 -0
  129. data/src/polygon.h +32 -0
  130. data/src/polyline.cpp +160 -0
  131. data/src/polyline.h +69 -0
  132. data/src/render_buffer.cpp +11 -4
  133. data/src/render_buffer.h +2 -2
  134. data/src/shader.cpp +163 -106
  135. data/src/shader.h +38 -0
  136. data/src/shader_program.cpp +533 -0
  137. data/src/{program.h → shader_program.h} +28 -16
  138. data/src/shader_source.cpp +140 -0
  139. data/src/shader_source.h +52 -0
  140. data/src/texture.cpp +136 -160
  141. data/src/texture.h +65 -0
  142. data/src/win32/bitmap.cpp +62 -52
  143. data/src/win32/font.cpp +11 -13
  144. data/src/win32/font.h +24 -0
  145. data/src/win32/gdi.h +6 -6
  146. data/test/helper.rb +0 -3
  147. data/test/test_bitmap.rb +31 -7
  148. data/test/test_bounds.rb +36 -0
  149. data/test/test_color.rb +59 -19
  150. data/test/test_color_space.rb +95 -0
  151. data/test/test_font.rb +5 -0
  152. data/test/test_image.rb +24 -20
  153. data/test/test_matrix.rb +106 -0
  154. data/test/test_painter.rb +157 -51
  155. data/test/test_painter_shape.rb +102 -0
  156. data/test/test_point.rb +29 -0
  157. data/test/test_polygon.rb +234 -0
  158. data/test/test_polygon_line.rb +167 -0
  159. data/test/test_polyline.rb +171 -0
  160. data/test/test_shader.rb +9 -9
  161. metadata +102 -70
  162. data/.doc/ext/rays/texture.cpp +0 -138
  163. data/ext/rays/texture.cpp +0 -149
  164. data/include/rays/ruby/texture.h +0 -41
  165. data/include/rays/texture.h +0 -71
  166. data/lib/rays/texture.rb +0 -24
  167. data/src/program.cpp +0 -648
  168. data/test/test_texture.rb +0 -27
@@ -0,0 +1,53 @@
1
+ #include "rays/noise.h"
2
+ #include "rays/ruby/point.h"
3
+ #include "defs.h"
4
+
5
+
6
+ static
7
+ VALUE perlin(VALUE self)
8
+ {
9
+ check_arg_count(__FILE__, __LINE__, "Rays.perlin", argc, 1, 2, 3, 4);
10
+
11
+ coord noise = 0;
12
+ if (argc == 4)
13
+ {
14
+ noise = Rays::perlin(
15
+ to<coord>(argv[0]),
16
+ to<coord>(argv[1]),
17
+ to<coord>(argv[2]),
18
+ to<coord>(argv[3]));
19
+ }
20
+ else
21
+ noise = Rays::perlin(to<Rays::Point>(argc, argv));
22
+
23
+ return value(noise);
24
+ }
25
+
26
+ static
27
+ VALUE simplex(VALUE self)
28
+ {
29
+ check_arg_count(__FILE__, __LINE__, "Rays.simplex", argc, 1, 2, 3, 4);
30
+
31
+ coord noise = 0;
32
+ if (argc == 4)
33
+ {
34
+ noise = Rays::simplex(
35
+ to<coord>(argv[0]),
36
+ to<coord>(argv[1]),
37
+ to<coord>(argv[2]),
38
+ to<coord>(argv[3]));
39
+ }
40
+ else
41
+ noise = Rays::simplex(to<Rays::Point>(argc, argv));
42
+
43
+ return value(noise);
44
+ }
45
+
46
+
47
+ void
48
+ Init_noise ()
49
+ {
50
+ Module mRays = rb_define_module("Rays");
51
+ rb_define_singleton_method(mRays, "perlin", RUBY_METHOD_FUNC(perlin), -1);
52
+ rb_define_singleton_method(mRays, "simplex", RUBY_METHOD_FUNC(simplex), -1);
53
+ }
@@ -2,22 +2,16 @@
2
2
 
3
3
 
4
4
  #include <vector>
5
- #include <rucy.h>
6
5
  #include "rays/ruby/point.h"
7
6
  #include "rays/ruby/bounds.h"
8
7
  #include "rays/ruby/color.h"
9
8
  #include "rays/ruby/matrix.h"
10
- #include "rays/ruby/font.h"
11
9
  #include "rays/ruby/image.h"
10
+ #include "rays/ruby/font.h"
12
11
  #include "rays/ruby/shader.h"
13
12
  #include "defs.h"
14
13
 
15
14
 
16
- using namespace Rucy;
17
-
18
- using Rays::coord;
19
-
20
-
21
15
  RUCY_DEFINE_VALUE_FROM_TO(Rays::Painter)
22
16
 
23
17
  #define THIS to<Rays::Painter*>(self)
@@ -52,6 +46,13 @@ VALUE bounds(VALUE self)
52
46
  return value(THIS->bounds());
53
47
  }
54
48
 
49
+ static
50
+ VALUE pixel_density(VALUE self)
51
+ {
52
+ CHECK;
53
+ return value(THIS->pixel_density());
54
+ }
55
+
55
56
 
56
57
  static
57
58
  VALUE begin_paint(VALUE self)
@@ -77,139 +78,96 @@ VALUE clear(VALUE self)
77
78
  }
78
79
 
79
80
  static
80
- VALUE line(VALUE self)
81
+ VALUE polygon(VALUE self, VALUE poly)
81
82
  {
82
83
  CHECK;
83
- check_arg_count(__FILE__, __LINE__, "Painter#line", argc, 2, 4);
84
-
85
- if (argc == 2)
86
- THIS->line(to<Rays::Point&>(argv[0]), to<Rays::Point&>(argv[1]));
87
- else
88
- {
89
- coord x1 = to<coord>(argv[0]);
90
- coord y1 = to<coord>(argv[1]);
91
- coord x2 = to<coord>(argv[2]);
92
- coord y2 = to<coord>(argv[3]);
93
- THIS->line(x1, y1, x2, y2);
94
- }
95
84
 
85
+ THIS->polygon(to<Rays::Polygon&>(poly));
96
86
  return self;
97
87
  }
98
88
 
99
89
  static
100
- VALUE lines(VALUE self)
90
+ VALUE line(VALUE self, VALUE args, VALUE loop)
101
91
  {
102
92
  CHECK;
103
- if (argc <= 0)
104
- argument_error(__FILE__, __LINE__, "Painter#lines");
105
93
 
106
- std::vector<Rays::Coord3> points;
107
- points.reserve(argc);
108
- for (int i = 0; i < argc; ++i)
109
- points.push_back(to<Rays::Point&>(argv[i]));
94
+ std::vector<Rays::Point> points;
95
+ get_line_args(&points, args.size(), args.as_array());
96
+
97
+ THIS->line(&points[0], points.size(), loop);
98
+ return self;
99
+ }
100
+
101
+ static
102
+ VALUE polyline(VALUE self, VALUE poly)
103
+ {
104
+ CHECK;
110
105
 
111
- THIS->lines((Rays::Point*) &points[0], points.size());
106
+ THIS->line(to<Rays::Polyline&>(poly));
112
107
  return self;
113
108
  }
114
109
 
115
110
  static
116
- VALUE polygon(VALUE self)
111
+ VALUE rect(VALUE self, VALUE args, VALUE round, VALUE lefttop, VALUE righttop, VALUE leftbottom, VALUE rightbottom)
117
112
  {
118
113
  CHECK;
119
- if (argc <= 0)
120
- argument_error(__FILE__, __LINE__, "Painter#polygon");
121
114
 
122
- std::vector<Rays::Coord3> points;
123
- points.reserve(argc);
124
- for (int i = 0; i < argc; ++i)
125
- points.push_back(to<Rays::Point&>(argv[i]));
115
+ coord x, y, w, h, lt, rt, lb, rb;
116
+ uint _;
117
+ get_rect_args(
118
+ &x, &y, &w, &h, &lt, &rt, &lb, &rb, &_,
119
+ args.size(), args.as_array(),
120
+ round, lefttop, righttop, leftbottom, rightbottom, nil());
126
121
 
127
- THIS->polygon((Rays::Point*) &points[0], points.size());
122
+ THIS->rect(x, y, w, h, lt, rt, lb, rb);
128
123
  return self;
129
124
  }
130
125
 
131
126
  static
132
- VALUE rect(VALUE self)
127
+ VALUE ellipse(VALUE self, VALUE args, VALUE center, VALUE radius, VALUE hole, VALUE angle_from, VALUE angle_to)
133
128
  {
134
129
  CHECK;
135
- check_arg_count(__FILE__, __LINE__, "Painter#rect", argc, 1, 2, 3, 4, 5, 6);
136
130
 
137
- if (argc <= 3)
138
- {
139
- Rays::Bounds& b = to<Rays::Bounds&>(argv[0]);
140
- coord rw = argc >= 2 ? to<coord>(argv[1]) : 0;
141
- coord rh = argc >= 3 ? to<coord>(argv[2]) : rw;
142
- THIS->rect(b, rw, rh);
143
- }
144
- else
145
- {
146
- coord x = to<coord>(argv[0]);
147
- coord y = to<coord>(argv[1]);
148
- coord w = to<coord>(argv[2]);
149
- coord h = to<coord>(argv[3]);
150
- coord rw = argc >= 5 ? to<coord>(argv[4]) : 0;
151
- coord rh = argc >= 6 ? to<coord>(argv[5]) : rw;
152
- THIS->rect(x, y, w, h, rw, rh);
153
- }
131
+ coord x, y, w, h;
132
+ Rays::Point hole_size;
133
+ float from, to_;
134
+ uint _;
135
+ get_ellipse_args(
136
+ &x, &y, &w, &h, &hole_size, &from, &to_, &_,
137
+ args.size(), args.as_array(),
138
+ center, radius, hole, angle_from, angle_to, nil());
154
139
 
140
+ THIS->ellipse(x, y, w, h, hole_size, from, to_);
155
141
  return self;
156
142
  }
157
143
 
158
144
  static
159
- VALUE ellipse(VALUE self)
145
+ VALUE curve(VALUE self, VALUE args, VALUE loop)
160
146
  {
161
147
  CHECK;
162
- check_arg_count(__FILE__, __LINE__, "Painter#ellipse", argc, 1, 2, 3, 4, 5, 6);
163
148
 
164
- if (argv[0].is_kind_of(Rays::bounds_class()))
165
- {
166
- const Rays::Bounds& b = to<Rays::Bounds&>(argv[0]);
167
- coord min_ = (argc >= 2) ? to<coord>(argv[1]) : 0;
168
- uint nseg = (argc >= 3) ? to<uint> (argv[2]) : 0;
169
- THIS->ellipse(b, min_, nseg);
170
- }
171
- else
172
- {
173
- coord x = to<coord>(argv[0]);
174
- coord y = to<coord>(argv[1]);
175
- coord w = to<coord>(argv[2]);
176
- coord h = (argc >= 4) ? to<coord>(argv[3]) : 0;
177
- coord min_ = (argc >= 5) ? to<coord>(argv[4]) : 0;
178
- uint nseg = (argc >= 6) ? to<uint> (argv[5]) : 0;
179
- THIS->ellipse(x, y, w, h, min_, nseg);
180
- }
149
+ if (args.empty())
150
+ argument_error(__FILE__, __LINE__);
151
+
152
+ std::vector<Rays::Point> points;
153
+ get_line_args(&points, args.size(), args.as_array());
181
154
 
155
+ THIS->curve(&points[0], points.size(), loop);
182
156
  return self;
183
157
  }
184
158
 
185
159
  static
186
- VALUE arc(VALUE self)
160
+ VALUE bezier(VALUE self, VALUE args, VALUE loop)
187
161
  {
188
162
  CHECK;
189
- check_arg_count(__FILE__, __LINE__, "Painter#ellipse", argc, 1, 2, 3, 4, 5, 6, 7, 8);
190
163
 
191
- if (argv[0].is_kind_of(Rays::bounds_class()))
192
- {
193
- const Rays::Bounds& b = to<Rays::Bounds&>(argv[0]);
194
- float begin = (argc >= 2) ? to<float>(argv[1]) : 0;
195
- float end = (argc >= 3) ? to<float>(argv[2]) : 360;
196
- coord min_ = (argc >= 4) ? to<coord>(argv[3]) : 0;
197
- uint nseg = (argc >= 5) ? to<uint> (argv[4]) : 0;
198
- THIS->arc(b, begin, end, min_, nseg);
199
- }
200
- else
201
- {
202
- coord x = to<coord>(argv[0]);
203
- coord y = to<coord>(argv[1]);
204
- coord w = to<coord>(argv[2]);
205
- coord h = (argc >= 4) ? to<coord>(argv[3]) : 0;
206
- float begin = (argc >= 5) ? to<float>(argv[4]) : 0;
207
- float end = (argc >= 6) ? to<float>(argv[5]) : 360;
208
- coord min_ = (argc >= 7) ? to<coord>(argv[6]) : 0;
209
- uint nseg = (argc >= 8) ? to<uint> (argv[7]) : 0;
210
- THIS->arc(x, y, w, h, begin, end, min_, nseg);
211
- }
164
+ if (args.empty())
165
+ argument_error(__FILE__, __LINE__);
212
166
 
167
+ std::vector<Rays::Point> points;
168
+ get_line_args(&points, args.size(), args.as_array());
169
+
170
+ THIS->bezier(&points[0], points.size(), loop);
213
171
  return self;
214
172
  }
215
173
 
@@ -260,7 +218,7 @@ static
260
218
  VALUE text(VALUE self)
261
219
  {
262
220
  CHECK;
263
- check_arg_count(__FILE__, __LINE__, "Painter#text", argc, 1, 3, 4, 5, 7);
221
+ check_arg_count(__FILE__, __LINE__, "Painter#text", argc, 1, 3, 5);
264
222
 
265
223
  if (argc == 1)
266
224
  THIS->text(argv[0].c_str());
@@ -269,61 +227,32 @@ VALUE text(VALUE self)
269
227
  coord x = to<coord>(argv[1]), y = to<coord>(argv[2]);
270
228
  THIS->text(argv[0].c_str(), x, y);
271
229
  }
272
- else if (argc == 4)
273
- {
274
- const Rays::Font* font = to<Rays::Font*>(argv[3]);
275
- if (!font || !*font)
276
- rays_error(__FILE__, __LINE__, "Painter#text: invalid font.");
277
-
278
- coord x = to<coord>(argv[1]), y = to<coord>(argv[2]);
279
- THIS->text(argv[0].c_str(), x, y, font);
280
- }
281
230
  else if (argc == 5)
282
231
  {
283
232
  coord x = to<coord>(argv[1]), w = to<coord>(argv[3]);
284
233
  coord y = to<coord>(argv[2]), h = to<coord>(argv[4]);
285
234
  THIS->text(argv[0].c_str(), x, y, w, h);
286
235
  }
287
- else if (argc == 7)
288
- {
289
- const Rays::Font* font = to<Rays::Font*>(argv[3]);
290
- if (!font || !*font)
291
- rays_error(__FILE__, __LINE__, "Painter#text: invalid font.");
292
-
293
- coord x = to<coord>(argv[1]), w = to<coord>(argv[3]);
294
- coord y = to<coord>(argv[2]), h = to<coord>(argv[4]);
295
- THIS->text(argv[0].c_str(), x, y, w, h, font);
296
- }
297
236
 
298
237
  return self;
299
238
  }
300
239
 
240
+
301
241
  static
302
242
  VALUE set_background(VALUE self)
303
243
  {
304
244
  CHECK;
305
- check_arg_count(__FILE__, __LINE__, "Painter#set_background", argc, 1, 2, 3, 4);
306
-
307
- if (argc == 1 && argv[0].is_kind_of(Rays::color_class()))
308
- THIS->set_background(to<Rays::Color&>(argv[0]));
309
- else if (argc == 1 || argc == 2)
310
- {
311
- float v = to<float>(argv[0]);
312
- float a = (argc >= 2) ? to<float>(argv[1]) : 1;
313
- THIS->set_background(v, v, v, a);
314
- }
315
- else
316
- {
317
- float r = to<float>(argv[0]);
318
- float g = to<float>(argv[1]);
319
- float b = to<float>(argv[2]);
320
- float a = (argc == 4) ? to<float>(argv[3]) : 1;
321
- THIS->set_background(r, g, b, a);
322
- }
323
-
245
+ THIS->set_background(to<Rays::Color>(argc, argv));
324
246
  return self;
325
247
  }
326
248
 
249
+ static
250
+ VALUE get_background(VALUE self)
251
+ {
252
+ CHECK;
253
+ return value(THIS->background());
254
+ }
255
+
327
256
  static
328
257
  VALUE no_background(VALUE self)
329
258
  {
@@ -333,36 +262,18 @@ VALUE no_background(VALUE self)
333
262
  }
334
263
 
335
264
  static
336
- VALUE get_background(VALUE self)
265
+ VALUE set_fill(VALUE self)
337
266
  {
338
267
  CHECK;
339
- return value(THIS->background());
268
+ THIS->set_fill(to<Rays::Color>(argc, argv));
269
+ return self;
340
270
  }
341
271
 
342
272
  static
343
- VALUE set_fill(VALUE self)
273
+ VALUE get_fill(VALUE self)
344
274
  {
345
275
  CHECK;
346
- check_arg_count(__FILE__, __LINE__, "Painter#set_fill", argc, 1, 2, 3, 4);
347
-
348
- if (argc == 1 && argv[0].is_kind_of(Rays::color_class()))
349
- THIS->set_fill(to<Rays::Color&>(argv[0]));
350
- else if (argc == 1 || argc == 2)
351
- {
352
- float v = to<float>(argv[0]);
353
- float a = (argc >= 2) ? to<float>(argv[1]) : 1;
354
- THIS->set_fill(v, v, v, a);
355
- }
356
- else
357
- {
358
- float r = to<float>(argv[0]);
359
- float g = to<float>(argv[1]);
360
- float b = to<float>(argv[2]);
361
- float a = (argc == 4) ? to<float>(argv[3]) : 1;
362
- THIS->set_fill(r, g, b, a);
363
- }
364
-
365
- return self;
276
+ return value(THIS->fill());
366
277
  }
367
278
 
368
279
  static
@@ -374,36 +285,18 @@ VALUE no_fill(VALUE self)
374
285
  }
375
286
 
376
287
  static
377
- VALUE get_fill(VALUE self)
288
+ VALUE set_stroke(VALUE self)
378
289
  {
379
290
  CHECK;
380
- return value(THIS->fill());
291
+ THIS->set_stroke(to<Rays::Color>(argc, argv));
292
+ return self;
381
293
  }
382
294
 
383
295
  static
384
- VALUE set_stroke(VALUE self)
296
+ VALUE get_stroke(VALUE self)
385
297
  {
386
298
  CHECK;
387
- check_arg_count(__FILE__, __LINE__, "Painter#set_stroke", argc, 1, 2, 3, 4);
388
-
389
- if (argc == 1 && argv[0].is_kind_of(Rays::color_class()))
390
- THIS->set_stroke(to<Rays::Color&>(argv[0]));
391
- else if (argc == 1 || argc == 2)
392
- {
393
- float v = to<float>(argv[0]);
394
- float a = (argc >= 2) ? to<float>(argv[1]) : 1;
395
- THIS->set_stroke(v, v, v, a);
396
- }
397
- else
398
- {
399
- float r = to<float>(argv[0]);
400
- float g = to<float>(argv[1]);
401
- float b = to<float>(argv[2]);
402
- float a = (argc == 4) ? to<float>(argv[3]) : 1;
403
- THIS->set_stroke(r, g, b, a);
404
- }
405
-
406
- return self;
299
+ return value(THIS->stroke());
407
300
  }
408
301
 
409
302
  static
@@ -415,165 +308,158 @@ VALUE no_stroke(VALUE self)
415
308
  }
416
309
 
417
310
  static
418
- VALUE get_stroke(VALUE self)
311
+ VALUE set_stroke_width(VALUE self, VALUE width)
419
312
  {
420
313
  CHECK;
421
- return value(THIS->stroke());
314
+ THIS->set_stroke_width(to<coord>(width));
315
+ return self;
422
316
  }
423
317
 
424
318
  static
425
- VALUE set_clip(VALUE self)
319
+ VALUE get_stroke_width(VALUE self)
426
320
  {
427
321
  CHECK;
428
- check_arg_count(__FILE__, __LINE__, "Painter#set_clip", argc, 1, 4);
429
-
430
- if (argc == 1)
431
- THIS->set_clip(to<Rays::Bounds&>(argv[0]));
432
- else
433
- {
434
- coord x = to<coord>(argv[0]);
435
- coord y = to<coord>(argv[1]);
436
- coord w = to<coord>(argv[2]);
437
- coord h = to<coord>(argv[3]);
438
- THIS->set_clip(x, y, w, h);
439
- }
440
-
441
- return self;
322
+ return value(THIS->stroke_width());
442
323
  }
443
324
 
444
325
  static
445
- VALUE no_clip(VALUE self)
326
+ VALUE set_stroke_cap(VALUE self, VALUE cap)
446
327
  {
447
328
  CHECK;
448
- THIS->no_clip();
329
+ THIS->set_stroke_cap(to<Rays::CapType>(cap));
449
330
  return self;
450
331
  }
451
332
 
452
333
  static
453
- VALUE get_clip(VALUE self)
334
+ VALUE get_stroke_cap(VALUE self)
454
335
  {
455
336
  CHECK;
456
- return value(THIS->clip());
337
+ return value(THIS->stroke_cap());
457
338
  }
458
339
 
459
340
  static
460
- VALUE set_font(VALUE self)
341
+ VALUE set_stroke_join(VALUE self, VALUE join)
461
342
  {
462
343
  CHECK;
463
- check_arg_count(__FILE__, __LINE__, "Painter#set_font", argc, 0, 1, 2);
464
-
465
- if (argc == 0 || argv[0].is_kind_of(Rays::font_class()))
466
- {
467
- const Rays::Font* f = argc == 0
468
- ? &Rays::default_font()
469
- : to<Rays::Font*>(argv[0]);
470
- if (!f || !*f)
471
- argument_error(__FILE__, __LINE__);
344
+ THIS->set_stroke_join(to<Rays::JoinType>(join));
345
+ return self;
346
+ }
472
347
 
473
- THIS->set_font(*f);
474
- }
475
- else
476
- {
477
- const char* name = argv[0].c_str();
478
- coord size = argc >= 2 ? to<coord>(argv[1]) : 0;
479
- THIS->set_font(name, size);
480
- }
348
+ static
349
+ VALUE get_stroke_join(VALUE self)
350
+ {
351
+ CHECK;
352
+ return value(THIS->stroke_join());
353
+ }
481
354
 
355
+ static
356
+ VALUE set_miter_limit(VALUE self, VALUE limit)
357
+ {
358
+ CHECK;
359
+ THIS->set_miter_limit(to<coord>(limit));
482
360
  return self;
483
361
  }
484
362
 
485
363
  static
486
- VALUE get_font(VALUE self)
364
+ VALUE get_miter_limit(VALUE self)
487
365
  {
488
366
  CHECK;
489
- return value(THIS->font());
367
+ return value(THIS->miter_limit());
490
368
  }
491
369
 
492
370
  static
493
- VALUE push_attr(VALUE self)
371
+ VALUE set_nsegment(VALUE self, VALUE nsegment)
494
372
  {
495
373
  CHECK;
496
- THIS->push_attr();
374
+ THIS->set_nsegment(nsegment ? to<int>(nsegment) : 0);
497
375
  return self;
498
376
  }
499
377
 
500
378
  static
501
- VALUE pop_attr(VALUE self)
379
+ VALUE get_nsegment(VALUE self)
502
380
  {
503
381
  CHECK;
504
- THIS->pop_attr();
382
+ return value(THIS->nsegment());
383
+ }
384
+
385
+ static
386
+ VALUE set_clip(VALUE self)
387
+ {
388
+ CHECK;
389
+ THIS->set_clip(to<Rays::Bounds>(argc, argv));
505
390
  return self;
506
391
  }
507
392
 
393
+ static
394
+ VALUE get_clip(VALUE self)
395
+ {
396
+ CHECK;
397
+ return value(THIS->clip());
398
+ }
508
399
 
509
400
  static
510
- VALUE attach_shader(VALUE self, VALUE shader)
401
+ VALUE no_clip(VALUE self)
511
402
  {
512
403
  CHECK;
513
- THIS->attach(to<Rays::Shader&>(shader));
404
+ THIS->no_clip();
514
405
  return self;
515
406
  }
516
407
 
517
408
  static
518
- VALUE detach_shader(VALUE self, VALUE shader)
409
+ VALUE set_font(VALUE self)
519
410
  {
520
411
  CHECK;
521
- THIS->detach(to<Rays::Shader&>(shader));
412
+ check_arg_count(__FILE__, __LINE__, "Painter#set_font", argc, 0, 1, 2);
413
+
414
+ THIS->set_font(to<Rays::Font>(argc, argv));
522
415
  return self;
523
416
  }
524
417
 
525
418
  static
526
- VALUE set_uniform(VALUE self)
419
+ VALUE get_font(VALUE self)
527
420
  {
528
421
  CHECK;
529
- check_arg_count(__FILE__, __LINE__, "Painter#set_uniform", argc, 2, 3, 4, 5);
422
+ return value(THIS->font());
423
+ }
530
424
 
531
- #define Ai(n) (argv[n].as_i())
532
- #define Af(n) ((float) argv[n].as_f())
425
+ static
426
+ VALUE set_shader(VALUE self)
427
+ {
428
+ CHECK;
429
+ check_arg_count(__FILE__, __LINE__, "Painter#set_shader", argc, 1);
533
430
 
534
- const char* name = argv[0].c_str();
535
- if (argv[1].is_i())
536
- {
537
- switch (argc)
538
- {
539
- case 2: THIS->set_uniform(name, Ai(1)); break;
540
- case 3: THIS->set_uniform(name, Ai(1), Ai(2)); break;
541
- case 4: THIS->set_uniform(name, Ai(1), Ai(2), Ai(3)); break;
542
- case 5: THIS->set_uniform(name, Ai(1), Ai(2), Ai(3), Ai(4)); break;
543
- }
544
- }
545
- else if (argv[1].is_f())
546
- {
547
- switch (argc)
548
- {
549
- case 2: THIS->set_uniform(name, Af(1)); break;
550
- case 3: THIS->set_uniform(name, Af(1), Af(2)); break;
551
- case 4: THIS->set_uniform(name, Af(1), Af(2), Af(3)); break;
552
- case 5: THIS->set_uniform(name, Af(1), Af(2), Af(3), Af(4)); break;
553
- }
554
- }
555
- else
556
- argument_error(__FILE__, __LINE__);
431
+ THIS->set_shader(to<Rays::Shader>(argc, argv));
432
+ return self;
433
+ }
557
434
 
558
- #undef Ai
559
- #undef Af
435
+ static
436
+ VALUE get_shader(VALUE self)
437
+ {
438
+ CHECK;
439
+ return value(THIS->shader());
440
+ }
560
441
 
442
+ static
443
+ VALUE no_shader(VALUE self)
444
+ {
445
+ CHECK;
446
+ THIS->no_shader();
561
447
  return self;
562
448
  }
563
449
 
564
450
  static
565
- VALUE push_shader(VALUE self)
451
+ VALUE push_state(VALUE self)
566
452
  {
567
453
  CHECK;
568
- THIS->push_shader();
454
+ THIS->push_state();
569
455
  return self;
570
456
  }
571
457
 
572
458
  static
573
- VALUE pop_shader(VALUE self)
459
+ VALUE pop_state(VALUE self)
574
460
  {
575
461
  CHECK;
576
- THIS->pop_shader();
462
+ THIS->pop_state();
577
463
  return self;
578
464
  }
579
465
 
@@ -629,8 +515,8 @@ static
629
515
  VALUE set_matrix(VALUE self)
630
516
  {
631
517
  CHECK;
632
- THIS->set_matrix();
633
- return self;
518
+ THIS->set_matrix(to<Rays::Matrix>(argc, argv));
519
+ return value(THIS->matrix());
634
520
  }
635
521
 
636
522
  static
@@ -669,47 +555,56 @@ Init_painter ()
669
555
 
670
556
  rb_define_method(cPainter, "canvas", RUBY_METHOD_FUNC(canvas), 4);
671
557
  rb_define_method(cPainter, "bounds", RUBY_METHOD_FUNC(bounds), 0);
558
+ rb_define_method(cPainter, "pixel_density", RUBY_METHOD_FUNC(pixel_density), 0);
672
559
 
673
560
  rb_define_private_method(cPainter, "begin_paint", RUBY_METHOD_FUNC(begin_paint), 0);
674
561
  rb_define_private_method(cPainter, "end_paint", RUBY_METHOD_FUNC(end_paint), 0);
675
562
  rb_define_method(cPainter, "clear", RUBY_METHOD_FUNC(clear), 0);
676
- rb_define_method(cPainter, "line", RUBY_METHOD_FUNC(line), -1);
677
- rb_define_method(cPainter, "lines", RUBY_METHOD_FUNC(lines), -1);
678
- rb_define_method(cPainter, "polygon", RUBY_METHOD_FUNC(polygon), -1);
679
- rb_define_method(cPainter, "rect", RUBY_METHOD_FUNC(rect), -1);
680
- rb_define_method(cPainter, "ellipse", RUBY_METHOD_FUNC(ellipse), -1);
681
- rb_define_method(cPainter, "arc", RUBY_METHOD_FUNC(arc), -1);
563
+ rb_define_method(cPainter, "polygon", RUBY_METHOD_FUNC(polygon), 1);
564
+ rb_define_private_method(cPainter, "draw_line", RUBY_METHOD_FUNC(line), 2);
565
+ rb_define_private_method(cPainter, "draw_polyline", RUBY_METHOD_FUNC(polyline), 1);
566
+ rb_define_private_method(cPainter, "draw_rect", RUBY_METHOD_FUNC(rect), 6);
567
+ rb_define_private_method(cPainter, "draw_ellipse", RUBY_METHOD_FUNC(ellipse), 6);
568
+ rb_define_private_method(cPainter, "draw_curve", RUBY_METHOD_FUNC(curve), 2);
569
+ rb_define_private_method(cPainter, "draw_bezier", RUBY_METHOD_FUNC(bezier), 2);
682
570
  rb_define_method(cPainter, "image", RUBY_METHOD_FUNC(image), -1);
683
571
  rb_define_method(cPainter, "text", RUBY_METHOD_FUNC(text), -1);
684
572
 
685
- rb_define_private_method(cPainter, "set_background", RUBY_METHOD_FUNC(set_background), -1);
686
- rb_define_private_method(cPainter, "get_background", RUBY_METHOD_FUNC(get_background), 0);
573
+ rb_define_method(cPainter, "background=", RUBY_METHOD_FUNC(set_background), -1);
574
+ rb_define_method(cPainter, "background", RUBY_METHOD_FUNC(get_background), 0);
687
575
  rb_define_method(cPainter, "no_background", RUBY_METHOD_FUNC(no_background), 0);
688
- rb_define_private_method(cPainter, "set_fill", RUBY_METHOD_FUNC(set_fill), -1);
689
- rb_define_private_method(cPainter, "get_fill", RUBY_METHOD_FUNC(get_fill), 0);
576
+ rb_define_method(cPainter, "fill=", RUBY_METHOD_FUNC(set_fill), -1);
577
+ rb_define_method(cPainter, "fill", RUBY_METHOD_FUNC(get_fill), 0);
690
578
  rb_define_method(cPainter, "no_fill", RUBY_METHOD_FUNC(no_fill), 0);
691
- rb_define_private_method(cPainter, "set_stroke", RUBY_METHOD_FUNC(set_stroke), -1);
692
- rb_define_private_method(cPainter, "get_stroke", RUBY_METHOD_FUNC(get_stroke), 0);
579
+ rb_define_method(cPainter, "stroke=", RUBY_METHOD_FUNC(set_stroke), -1);
580
+ rb_define_method(cPainter, "stroke", RUBY_METHOD_FUNC(get_stroke), 0);
693
581
  rb_define_method(cPainter, "no_stroke", RUBY_METHOD_FUNC(no_stroke), 0);
694
- rb_define_private_method(cPainter, "set_clip", RUBY_METHOD_FUNC(set_clip), -1);
695
- rb_define_private_method(cPainter, "get_clip", RUBY_METHOD_FUNC(get_clip), 0);
582
+ rb_define_method(cPainter, "stroke_width=", RUBY_METHOD_FUNC(set_stroke_width), 1);
583
+ rb_define_method(cPainter, "stroke_width", RUBY_METHOD_FUNC(get_stroke_width), 0);
584
+ rb_define_method(cPainter, "stroke_cap=", RUBY_METHOD_FUNC(set_stroke_cap), 1);
585
+ rb_define_method(cPainter, "stroke_cap", RUBY_METHOD_FUNC(get_stroke_cap), 0);
586
+ rb_define_method(cPainter, "stroke_join=", RUBY_METHOD_FUNC(set_stroke_join), 1);
587
+ rb_define_method(cPainter, "stroke_join", RUBY_METHOD_FUNC(get_stroke_join), 0);
588
+ rb_define_method(cPainter, "miter_limit=", RUBY_METHOD_FUNC(set_miter_limit), 1);
589
+ rb_define_method(cPainter, "miter_limit", RUBY_METHOD_FUNC(get_miter_limit), 0);
590
+ rb_define_method(cPainter, "nsegment=", RUBY_METHOD_FUNC(set_nsegment), 1);
591
+ rb_define_method(cPainter, "nsegment", RUBY_METHOD_FUNC(get_nsegment), 0);
592
+ rb_define_method(cPainter, "clip=", RUBY_METHOD_FUNC(set_clip), -1);
593
+ rb_define_method(cPainter, "clip", RUBY_METHOD_FUNC(get_clip), 0);
696
594
  rb_define_method(cPainter, "no_clip", RUBY_METHOD_FUNC(no_clip), 0);
697
- rb_define_private_method(cPainter, "set_font", RUBY_METHOD_FUNC(set_font), -1);
698
- rb_define_private_method(cPainter, "get_font", RUBY_METHOD_FUNC(get_font), 0);
699
- rb_define_method(cPainter, "push_attr", RUBY_METHOD_FUNC(push_attr), 0);
700
- rb_define_method(cPainter, "pop_attr", RUBY_METHOD_FUNC(pop_attr), 0);
701
-
702
- rb_define_private_method(cPainter, "attach_shader", RUBY_METHOD_FUNC(attach_shader), 1);
703
- rb_define_private_method(cPainter, "detach_shader", RUBY_METHOD_FUNC(detach_shader), 1);
704
- rb_define_private_method(cPainter, "set_uniform", RUBY_METHOD_FUNC(set_uniform), -1);
705
- rb_define_method(cPainter, "push_shader", RUBY_METHOD_FUNC(push_shader), 0);
706
- rb_define_method(cPainter, "pop_shader", RUBY_METHOD_FUNC(pop_shader), 0);
595
+ rb_define_method(cPainter, "font=", RUBY_METHOD_FUNC(set_font), -1);
596
+ rb_define_method(cPainter, "font", RUBY_METHOD_FUNC(get_font), 0);
597
+ rb_define_private_method(cPainter, "set_shader", RUBY_METHOD_FUNC(set_shader), -1);
598
+ rb_define_method(cPainter, "shader", RUBY_METHOD_FUNC(get_shader), 0);
599
+ rb_define_method(cPainter, "no_shader", RUBY_METHOD_FUNC(no_shader), 0);
600
+ rb_define_method(cPainter, "push_state", RUBY_METHOD_FUNC(push_state), 0);
601
+ rb_define_method(cPainter, "pop_state", RUBY_METHOD_FUNC(pop_state), 0);
707
602
 
708
603
  rb_define_method(cPainter, "translate", RUBY_METHOD_FUNC(translate), -1);
709
604
  rb_define_method(cPainter, "scale", RUBY_METHOD_FUNC(scale), -1);
710
605
  rb_define_method(cPainter, "rotate", RUBY_METHOD_FUNC(rotate), -1);
711
- rb_define_private_method(cPainter, "set_matrix", RUBY_METHOD_FUNC(set_matrix), -1);
712
- rb_define_private_method(cPainter, "get_matrix", RUBY_METHOD_FUNC(get_matrix), 0);
606
+ rb_define_method(cPainter, "matrix=", RUBY_METHOD_FUNC(set_matrix), -1);
607
+ rb_define_method(cPainter, "matrix", RUBY_METHOD_FUNC(get_matrix), 0);
713
608
  rb_define_method(cPainter, "push_matrix", RUBY_METHOD_FUNC(push_matrix), 0);
714
609
  rb_define_method(cPainter, "pop_matrix", RUBY_METHOD_FUNC(pop_matrix), 0);
715
610
  }