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
@@ -1,24 +1,25 @@
1
- #include <rucy.h>
2
1
  #include "defs.h"
3
2
 
4
3
 
5
- using namespace Rucy;
6
-
7
-
8
4
  void Init_rays ();
9
5
 
10
6
  void Init_point ();
11
7
  void Init_bounds ();
12
8
  void Init_color ();
13
9
  void Init_color_space ();
10
+ void Init_matrix ();
14
11
 
12
+ void Init_painter ();
13
+ void Init_polyline ();
14
+ void Init_polygon_line ();
15
+ void Init_polygon ();
15
16
  void Init_bitmap ();
16
- void Init_texture ();
17
17
  void Init_image ();
18
18
  void Init_font ();
19
19
  void Init_shader ();
20
+ void Init_camera ();
20
21
 
21
- void Init_painter ();
22
+ void Init_noise ();
22
23
 
23
24
 
24
25
  extern "C" void
@@ -38,14 +39,19 @@ extern "C" void
38
39
  Init_bounds();
39
40
  Init_color();
40
41
  Init_color_space();
42
+ Init_matrix();
41
43
 
44
+ Init_painter();
45
+ Init_polyline();
46
+ Init_polygon_line();
47
+ Init_polygon();
42
48
  Init_bitmap();
43
- Init_texture();
44
49
  Init_image();
45
50
  Init_font();
46
51
  Init_shader();
52
+ Init_camera();
47
53
 
48
- Init_painter();
54
+ Init_noise();
49
55
 
50
56
  RUCY_CATCH
51
57
  }
@@ -0,0 +1,55 @@
1
+ #include "rays/noise.h"
2
+ #include "rays/ruby/point.h"
3
+ #include "defs.h"
4
+
5
+
6
+ static
7
+ RUCY_DEFN(perlin)
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
+ RUCY_END
26
+
27
+ static
28
+ RUCY_DEFN(simplex)
29
+ {
30
+ check_arg_count(__FILE__, __LINE__, "Rays.simplex", argc, 1, 2, 3, 4);
31
+
32
+ coord noise = 0;
33
+ if (argc == 4)
34
+ {
35
+ noise = Rays::simplex(
36
+ to<coord>(argv[0]),
37
+ to<coord>(argv[1]),
38
+ to<coord>(argv[2]),
39
+ to<coord>(argv[3]));
40
+ }
41
+ else
42
+ noise = Rays::simplex(to<Rays::Point>(argc, argv));
43
+
44
+ return value(noise);
45
+ }
46
+ RUCY_END
47
+
48
+
49
+ void
50
+ Init_noise ()
51
+ {
52
+ Module mRays = define_module("Rays");
53
+ mRays.define_singleton_method("perlin", perlin);
54
+ mRays.define_singleton_method("simplex", simplex);
55
+ }
@@ -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)
@@ -55,6 +49,14 @@ RUCY_DEF0(bounds)
55
49
  }
56
50
  RUCY_END
57
51
 
52
+ static
53
+ RUCY_DEF0(pixel_density)
54
+ {
55
+ CHECK;
56
+ return value(THIS->pixel_density());
57
+ }
58
+ RUCY_END
59
+
58
60
 
59
61
  static
60
62
  RUCY_DEF0(begin_paint)
@@ -83,144 +85,102 @@ RUCY_DEF0(clear)
83
85
  RUCY_END
84
86
 
85
87
  static
86
- RUCY_DEFN(line)
88
+ RUCY_DEF1(polygon, poly)
87
89
  {
88
90
  CHECK;
89
- check_arg_count(__FILE__, __LINE__, "Painter#line", argc, 2, 4);
90
-
91
- if (argc == 2)
92
- THIS->line(to<Rays::Point&>(argv[0]), to<Rays::Point&>(argv[1]));
93
- else
94
- {
95
- coord x1 = to<coord>(argv[0]);
96
- coord y1 = to<coord>(argv[1]);
97
- coord x2 = to<coord>(argv[2]);
98
- coord y2 = to<coord>(argv[3]);
99
- THIS->line(x1, y1, x2, y2);
100
- }
101
91
 
92
+ THIS->polygon(to<Rays::Polygon&>(poly));
102
93
  return self;
103
94
  }
104
95
  RUCY_END
105
96
 
106
97
  static
107
- RUCY_DEFN(lines)
98
+ RUCY_DEF2(line, args, loop)
108
99
  {
109
100
  CHECK;
110
- if (argc <= 0)
111
- argument_error(__FILE__, __LINE__, "Painter#lines");
112
101
 
113
- std::vector<Rays::Coord3> points;
114
- points.reserve(argc);
115
- for (int i = 0; i < argc; ++i)
116
- points.push_back(to<Rays::Point&>(argv[i]));
102
+ std::vector<Rays::Point> points;
103
+ get_line_args(&points, args.size(), args.as_array());
104
+
105
+ THIS->line(&points[0], points.size(), loop);
106
+ return self;
107
+ }
108
+ RUCY_END
109
+
110
+ static
111
+ RUCY_DEF1(polyline, poly)
112
+ {
113
+ CHECK;
117
114
 
118
- THIS->lines((Rays::Point*) &points[0], points.size());
115
+ THIS->line(to<Rays::Polyline&>(poly));
119
116
  return self;
120
117
  }
121
118
  RUCY_END
122
119
 
123
120
  static
124
- RUCY_DEFN(polygon)
121
+ RUCY_DEF6(rect, args, round, lefttop, righttop, leftbottom, rightbottom)
125
122
  {
126
123
  CHECK;
127
- if (argc <= 0)
128
- argument_error(__FILE__, __LINE__, "Painter#polygon");
129
124
 
130
- std::vector<Rays::Coord3> points;
131
- points.reserve(argc);
132
- for (int i = 0; i < argc; ++i)
133
- points.push_back(to<Rays::Point&>(argv[i]));
125
+ coord x, y, w, h, lt, rt, lb, rb;
126
+ uint _;
127
+ get_rect_args(
128
+ &x, &y, &w, &h, &lt, &rt, &lb, &rb, &_,
129
+ args.size(), args.as_array(),
130
+ round, lefttop, righttop, leftbottom, rightbottom, nil());
134
131
 
135
- THIS->polygon((Rays::Point*) &points[0], points.size());
132
+ THIS->rect(x, y, w, h, lt, rt, lb, rb);
136
133
  return self;
137
134
  }
138
135
  RUCY_END
139
136
 
140
137
  static
141
- RUCY_DEFN(rect)
138
+ RUCY_DEF6(ellipse, args, center, radius, hole, angle_from, angle_to)
142
139
  {
143
140
  CHECK;
144
- check_arg_count(__FILE__, __LINE__, "Painter#rect", argc, 1, 2, 3, 4, 5, 6);
145
141
 
146
- if (argc <= 3)
147
- {
148
- Rays::Bounds& b = to<Rays::Bounds&>(argv[0]);
149
- coord rw = argc >= 2 ? to<coord>(argv[1]) : 0;
150
- coord rh = argc >= 3 ? to<coord>(argv[2]) : rw;
151
- THIS->rect(b, rw, rh);
152
- }
153
- else
154
- {
155
- coord x = to<coord>(argv[0]);
156
- coord y = to<coord>(argv[1]);
157
- coord w = to<coord>(argv[2]);
158
- coord h = to<coord>(argv[3]);
159
- coord rw = argc >= 5 ? to<coord>(argv[4]) : 0;
160
- coord rh = argc >= 6 ? to<coord>(argv[5]) : rw;
161
- THIS->rect(x, y, w, h, rw, rh);
162
- }
142
+ coord x, y, w, h;
143
+ Rays::Point hole_size;
144
+ float from, to_;
145
+ uint _;
146
+ get_ellipse_args(
147
+ &x, &y, &w, &h, &hole_size, &from, &to_, &_,
148
+ args.size(), args.as_array(),
149
+ center, radius, hole, angle_from, angle_to, nil());
163
150
 
151
+ THIS->ellipse(x, y, w, h, hole_size, from, to_);
164
152
  return self;
165
153
  }
166
154
  RUCY_END
167
155
 
168
156
  static
169
- RUCY_DEFN(ellipse)
157
+ RUCY_DEF2(curve, args, loop)
170
158
  {
171
159
  CHECK;
172
- check_arg_count(__FILE__, __LINE__, "Painter#ellipse", argc, 1, 2, 3, 4, 5, 6);
173
160
 
174
- if (argv[0].is_kind_of(Rays::bounds_class()))
175
- {
176
- const Rays::Bounds& b = to<Rays::Bounds&>(argv[0]);
177
- coord min_ = (argc >= 2) ? to<coord>(argv[1]) : 0;
178
- uint nseg = (argc >= 3) ? to<uint> (argv[2]) : 0;
179
- THIS->ellipse(b, min_, nseg);
180
- }
181
- else
182
- {
183
- coord x = to<coord>(argv[0]);
184
- coord y = to<coord>(argv[1]);
185
- coord w = to<coord>(argv[2]);
186
- coord h = (argc >= 4) ? to<coord>(argv[3]) : 0;
187
- coord min_ = (argc >= 5) ? to<coord>(argv[4]) : 0;
188
- uint nseg = (argc >= 6) ? to<uint> (argv[5]) : 0;
189
- THIS->ellipse(x, y, w, h, min_, nseg);
190
- }
161
+ if (args.empty())
162
+ argument_error(__FILE__, __LINE__);
191
163
 
164
+ std::vector<Rays::Point> points;
165
+ get_line_args(&points, args.size(), args.as_array());
166
+
167
+ THIS->curve(&points[0], points.size(), loop);
192
168
  return self;
193
169
  }
194
170
  RUCY_END
195
171
 
196
172
  static
197
- RUCY_DEFN(arc)
173
+ RUCY_DEF2(bezier, args, loop)
198
174
  {
199
175
  CHECK;
200
- check_arg_count(__FILE__, __LINE__, "Painter#ellipse", argc, 1, 2, 3, 4, 5, 6, 7, 8);
201
176
 
202
- if (argv[0].is_kind_of(Rays::bounds_class()))
203
- {
204
- const Rays::Bounds& b = to<Rays::Bounds&>(argv[0]);
205
- float begin = (argc >= 2) ? to<float>(argv[1]) : 0;
206
- float end = (argc >= 3) ? to<float>(argv[2]) : 360;
207
- coord min_ = (argc >= 4) ? to<coord>(argv[3]) : 0;
208
- uint nseg = (argc >= 5) ? to<uint> (argv[4]) : 0;
209
- THIS->arc(b, begin, end, min_, nseg);
210
- }
211
- else
212
- {
213
- coord x = to<coord>(argv[0]);
214
- coord y = to<coord>(argv[1]);
215
- coord w = to<coord>(argv[2]);
216
- coord h = (argc >= 4) ? to<coord>(argv[3]) : 0;
217
- float begin = (argc >= 5) ? to<float>(argv[4]) : 0;
218
- float end = (argc >= 6) ? to<float>(argv[5]) : 360;
219
- coord min_ = (argc >= 7) ? to<coord>(argv[6]) : 0;
220
- uint nseg = (argc >= 8) ? to<uint> (argv[7]) : 0;
221
- THIS->arc(x, y, w, h, begin, end, min_, nseg);
222
- }
177
+ if (args.empty())
178
+ argument_error(__FILE__, __LINE__);
179
+
180
+ std::vector<Rays::Point> points;
181
+ get_line_args(&points, args.size(), args.as_array());
223
182
 
183
+ THIS->bezier(&points[0], points.size(), loop);
224
184
  return self;
225
185
  }
226
186
  RUCY_END
@@ -273,7 +233,7 @@ static
273
233
  RUCY_DEFN(text)
274
234
  {
275
235
  CHECK;
276
- check_arg_count(__FILE__, __LINE__, "Painter#text", argc, 1, 3, 4, 5, 7);
236
+ check_arg_count(__FILE__, __LINE__, "Painter#text", argc, 1, 3, 5);
277
237
 
278
238
  if (argc == 1)
279
239
  THIS->text(argv[0].c_str());
@@ -282,63 +242,35 @@ RUCY_DEFN(text)
282
242
  coord x = to<coord>(argv[1]), y = to<coord>(argv[2]);
283
243
  THIS->text(argv[0].c_str(), x, y);
284
244
  }
285
- else if (argc == 4)
286
- {
287
- const Rays::Font* font = to<Rays::Font*>(argv[3]);
288
- if (!font || !*font)
289
- rays_error(__FILE__, __LINE__, "Painter#text: invalid font.");
290
-
291
- coord x = to<coord>(argv[1]), y = to<coord>(argv[2]);
292
- THIS->text(argv[0].c_str(), x, y, font);
293
- }
294
245
  else if (argc == 5)
295
246
  {
296
247
  coord x = to<coord>(argv[1]), w = to<coord>(argv[3]);
297
248
  coord y = to<coord>(argv[2]), h = to<coord>(argv[4]);
298
249
  THIS->text(argv[0].c_str(), x, y, w, h);
299
250
  }
300
- else if (argc == 7)
301
- {
302
- const Rays::Font* font = to<Rays::Font*>(argv[3]);
303
- if (!font || !*font)
304
- rays_error(__FILE__, __LINE__, "Painter#text: invalid font.");
305
-
306
- coord x = to<coord>(argv[1]), w = to<coord>(argv[3]);
307
- coord y = to<coord>(argv[2]), h = to<coord>(argv[4]);
308
- THIS->text(argv[0].c_str(), x, y, w, h, font);
309
- }
310
251
 
311
252
  return self;
312
253
  }
313
254
  RUCY_END
314
255
 
256
+
315
257
  static
316
258
  RUCY_DEFN(set_background)
317
259
  {
318
260
  CHECK;
319
- check_arg_count(__FILE__, __LINE__, "Painter#set_background", argc, 1, 2, 3, 4);
320
-
321
- if (argc == 1 && argv[0].is_kind_of(Rays::color_class()))
322
- THIS->set_background(to<Rays::Color&>(argv[0]));
323
- else if (argc == 1 || argc == 2)
324
- {
325
- float v = to<float>(argv[0]);
326
- float a = (argc >= 2) ? to<float>(argv[1]) : 1;
327
- THIS->set_background(v, v, v, a);
328
- }
329
- else
330
- {
331
- float r = to<float>(argv[0]);
332
- float g = to<float>(argv[1]);
333
- float b = to<float>(argv[2]);
334
- float a = (argc == 4) ? to<float>(argv[3]) : 1;
335
- THIS->set_background(r, g, b, a);
336
- }
337
-
261
+ THIS->set_background(to<Rays::Color>(argc, argv));
338
262
  return self;
339
263
  }
340
264
  RUCY_END
341
265
 
266
+ static
267
+ RUCY_DEF0(get_background)
268
+ {
269
+ CHECK;
270
+ return value(THIS->background());
271
+ }
272
+ RUCY_END
273
+
342
274
  static
343
275
  RUCY_DEF0(no_background)
344
276
  {
@@ -349,37 +281,19 @@ RUCY_DEF0(no_background)
349
281
  RUCY_END
350
282
 
351
283
  static
352
- RUCY_DEF0(get_background)
284
+ RUCY_DEFN(set_fill)
353
285
  {
354
286
  CHECK;
355
- return value(THIS->background());
287
+ THIS->set_fill(to<Rays::Color>(argc, argv));
288
+ return self;
356
289
  }
357
290
  RUCY_END
358
291
 
359
292
  static
360
- RUCY_DEFN(set_fill)
293
+ RUCY_DEF0(get_fill)
361
294
  {
362
295
  CHECK;
363
- check_arg_count(__FILE__, __LINE__, "Painter#set_fill", argc, 1, 2, 3, 4);
364
-
365
- if (argc == 1 && argv[0].is_kind_of(Rays::color_class()))
366
- THIS->set_fill(to<Rays::Color&>(argv[0]));
367
- else if (argc == 1 || argc == 2)
368
- {
369
- float v = to<float>(argv[0]);
370
- float a = (argc >= 2) ? to<float>(argv[1]) : 1;
371
- THIS->set_fill(v, v, v, a);
372
- }
373
- else
374
- {
375
- float r = to<float>(argv[0]);
376
- float g = to<float>(argv[1]);
377
- float b = to<float>(argv[2]);
378
- float a = (argc == 4) ? to<float>(argv[3]) : 1;
379
- THIS->set_fill(r, g, b, a);
380
- }
381
-
382
- return self;
296
+ return value(THIS->fill());
383
297
  }
384
298
  RUCY_END
385
299
 
@@ -393,37 +307,19 @@ RUCY_DEF0(no_fill)
393
307
  RUCY_END
394
308
 
395
309
  static
396
- RUCY_DEF0(get_fill)
310
+ RUCY_DEFN(set_stroke)
397
311
  {
398
312
  CHECK;
399
- return value(THIS->fill());
313
+ THIS->set_stroke(to<Rays::Color>(argc, argv));
314
+ return self;
400
315
  }
401
316
  RUCY_END
402
317
 
403
318
  static
404
- RUCY_DEFN(set_stroke)
319
+ RUCY_DEF0(get_stroke)
405
320
  {
406
321
  CHECK;
407
- check_arg_count(__FILE__, __LINE__, "Painter#set_stroke", argc, 1, 2, 3, 4);
408
-
409
- if (argc == 1 && argv[0].is_kind_of(Rays::color_class()))
410
- THIS->set_stroke(to<Rays::Color&>(argv[0]));
411
- else if (argc == 1 || argc == 2)
412
- {
413
- float v = to<float>(argv[0]);
414
- float a = (argc >= 2) ? to<float>(argv[1]) : 1;
415
- THIS->set_stroke(v, v, v, a);
416
- }
417
- else
418
- {
419
- float r = to<float>(argv[0]);
420
- float g = to<float>(argv[1]);
421
- float b = to<float>(argv[2]);
422
- float a = (argc == 4) ? to<float>(argv[3]) : 1;
423
- THIS->set_stroke(r, g, b, a);
424
- }
425
-
426
- return self;
322
+ return value(THIS->stroke());
427
323
  }
428
324
  RUCY_END
429
325
 
@@ -437,177 +333,177 @@ RUCY_DEF0(no_stroke)
437
333
  RUCY_END
438
334
 
439
335
  static
440
- RUCY_DEF0(get_stroke)
336
+ RUCY_DEF1(set_stroke_width, width)
441
337
  {
442
338
  CHECK;
443
- return value(THIS->stroke());
339
+ THIS->set_stroke_width(to<coord>(width));
340
+ return self;
444
341
  }
445
342
  RUCY_END
446
343
 
447
344
  static
448
- RUCY_DEFN(set_clip)
345
+ RUCY_DEF0(get_stroke_width)
449
346
  {
450
347
  CHECK;
451
- check_arg_count(__FILE__, __LINE__, "Painter#set_clip", argc, 1, 4);
452
-
453
- if (argc == 1)
454
- THIS->set_clip(to<Rays::Bounds&>(argv[0]));
455
- else
456
- {
457
- coord x = to<coord>(argv[0]);
458
- coord y = to<coord>(argv[1]);
459
- coord w = to<coord>(argv[2]);
460
- coord h = to<coord>(argv[3]);
461
- THIS->set_clip(x, y, w, h);
462
- }
463
-
464
- return self;
348
+ return value(THIS->stroke_width());
465
349
  }
466
350
  RUCY_END
467
351
 
468
352
  static
469
- RUCY_DEF0(no_clip)
353
+ RUCY_DEF1(set_stroke_cap, cap)
470
354
  {
471
355
  CHECK;
472
- THIS->no_clip();
356
+ THIS->set_stroke_cap(to<Rays::CapType>(cap));
473
357
  return self;
474
358
  }
475
359
  RUCY_END
476
360
 
477
361
  static
478
- RUCY_DEF0(get_clip)
362
+ RUCY_DEF0(get_stroke_cap)
479
363
  {
480
364
  CHECK;
481
- return value(THIS->clip());
365
+ return value(THIS->stroke_cap());
482
366
  }
483
367
  RUCY_END
484
368
 
485
369
  static
486
- RUCY_DEFN(set_font)
370
+ RUCY_DEF1(set_stroke_join, join)
487
371
  {
488
372
  CHECK;
489
- check_arg_count(__FILE__, __LINE__, "Painter#set_font", argc, 0, 1, 2);
490
-
491
- if (argc == 0 || argv[0].is_kind_of(Rays::font_class()))
492
- {
493
- const Rays::Font* f = argc == 0
494
- ? &Rays::default_font()
495
- : to<Rays::Font*>(argv[0]);
496
- if (!f || !*f)
497
- argument_error(__FILE__, __LINE__);
373
+ THIS->set_stroke_join(to<Rays::JoinType>(join));
374
+ return self;
375
+ }
376
+ RUCY_END
498
377
 
499
- THIS->set_font(*f);
500
- }
501
- else
502
- {
503
- const char* name = argv[0].c_str();
504
- coord size = argc >= 2 ? to<coord>(argv[1]) : 0;
505
- THIS->set_font(name, size);
506
- }
378
+ static
379
+ RUCY_DEF0(get_stroke_join)
380
+ {
381
+ CHECK;
382
+ return value(THIS->stroke_join());
383
+ }
384
+ RUCY_END
507
385
 
386
+ static
387
+ RUCY_DEF1(set_miter_limit, limit)
388
+ {
389
+ CHECK;
390
+ THIS->set_miter_limit(to<coord>(limit));
508
391
  return self;
509
392
  }
510
393
  RUCY_END
511
394
 
512
395
  static
513
- RUCY_DEF0(get_font)
396
+ RUCY_DEF0(get_miter_limit)
514
397
  {
515
398
  CHECK;
516
- return value(THIS->font());
399
+ return value(THIS->miter_limit());
517
400
  }
518
401
  RUCY_END
519
402
 
520
403
  static
521
- RUCY_DEF0(push_attr)
404
+ RUCY_DEF1(set_nsegment, nsegment)
522
405
  {
523
406
  CHECK;
524
- THIS->push_attr();
407
+ THIS->set_nsegment(nsegment ? to<int>(nsegment) : 0);
525
408
  return self;
526
409
  }
527
410
  RUCY_END
528
411
 
529
412
  static
530
- RUCY_DEF0(pop_attr)
413
+ RUCY_DEF0(get_nsegment)
414
+ {
415
+ CHECK;
416
+ return value(THIS->nsegment());
417
+ }
418
+ RUCY_END
419
+
420
+ static
421
+ RUCY_DEFN(set_clip)
531
422
  {
532
423
  CHECK;
533
- THIS->pop_attr();
424
+ THIS->set_clip(to<Rays::Bounds>(argc, argv));
534
425
  return self;
535
426
  }
536
427
  RUCY_END
537
428
 
429
+ static
430
+ RUCY_DEF0(get_clip)
431
+ {
432
+ CHECK;
433
+ return value(THIS->clip());
434
+ }
435
+ RUCY_END
538
436
 
539
437
  static
540
- RUCY_DEF1(attach_shader, shader)
438
+ RUCY_DEF0(no_clip)
541
439
  {
542
440
  CHECK;
543
- THIS->attach(to<Rays::Shader&>(shader));
441
+ THIS->no_clip();
544
442
  return self;
545
443
  }
546
444
  RUCY_END
547
445
 
548
446
  static
549
- RUCY_DEF1(detach_shader, shader)
447
+ RUCY_DEFN(set_font)
550
448
  {
551
449
  CHECK;
552
- THIS->detach(to<Rays::Shader&>(shader));
450
+ check_arg_count(__FILE__, __LINE__, "Painter#set_font", argc, 0, 1, 2);
451
+
452
+ THIS->set_font(to<Rays::Font>(argc, argv));
553
453
  return self;
554
454
  }
555
455
  RUCY_END
556
456
 
557
457
  static
558
- RUCY_DEFN(set_uniform)
458
+ RUCY_DEF0(get_font)
559
459
  {
560
460
  CHECK;
561
- check_arg_count(__FILE__, __LINE__, "Painter#set_uniform", argc, 2, 3, 4, 5);
461
+ return value(THIS->font());
462
+ }
463
+ RUCY_END
562
464
 
563
- #define Ai(n) (argv[n].as_i())
564
- #define Af(n) ((float) argv[n].as_f())
465
+ static
466
+ RUCY_DEFN(set_shader)
467
+ {
468
+ CHECK;
469
+ check_arg_count(__FILE__, __LINE__, "Painter#set_shader", argc, 1);
565
470
 
566
- const char* name = argv[0].c_str();
567
- if (argv[1].is_i())
568
- {
569
- switch (argc)
570
- {
571
- case 2: THIS->set_uniform(name, Ai(1)); break;
572
- case 3: THIS->set_uniform(name, Ai(1), Ai(2)); break;
573
- case 4: THIS->set_uniform(name, Ai(1), Ai(2), Ai(3)); break;
574
- case 5: THIS->set_uniform(name, Ai(1), Ai(2), Ai(3), Ai(4)); break;
575
- }
576
- }
577
- else if (argv[1].is_f())
578
- {
579
- switch (argc)
580
- {
581
- case 2: THIS->set_uniform(name, Af(1)); break;
582
- case 3: THIS->set_uniform(name, Af(1), Af(2)); break;
583
- case 4: THIS->set_uniform(name, Af(1), Af(2), Af(3)); break;
584
- case 5: THIS->set_uniform(name, Af(1), Af(2), Af(3), Af(4)); break;
585
- }
586
- }
587
- else
588
- argument_error(__FILE__, __LINE__);
471
+ THIS->set_shader(to<Rays::Shader>(argc, argv));
472
+ return self;
473
+ }
474
+ RUCY_END
589
475
 
590
- #undef Ai
591
- #undef Af
476
+ static
477
+ RUCY_DEF0(get_shader)
478
+ {
479
+ CHECK;
480
+ return value(THIS->shader());
481
+ }
482
+ RUCY_END
592
483
 
484
+ static
485
+ RUCY_DEF0(no_shader)
486
+ {
487
+ CHECK;
488
+ THIS->no_shader();
593
489
  return self;
594
490
  }
595
491
  RUCY_END
596
492
 
597
493
  static
598
- RUCY_DEF0(push_shader)
494
+ RUCY_DEF0(push_state)
599
495
  {
600
496
  CHECK;
601
- THIS->push_shader();
497
+ THIS->push_state();
602
498
  return self;
603
499
  }
604
500
  RUCY_END
605
501
 
606
502
  static
607
- RUCY_DEF0(pop_shader)
503
+ RUCY_DEF0(pop_state)
608
504
  {
609
505
  CHECK;
610
- THIS->pop_shader();
506
+ THIS->pop_state();
611
507
  return self;
612
508
  }
613
509
  RUCY_END
@@ -667,8 +563,8 @@ static
667
563
  RUCY_DEFN(set_matrix)
668
564
  {
669
565
  CHECK;
670
- THIS->set_matrix();
671
- return self;
566
+ THIS->set_matrix(to<Rays::Matrix>(argc, argv));
567
+ return value(THIS->matrix());
672
568
  }
673
569
  RUCY_END
674
570
 
@@ -711,47 +607,56 @@ Init_painter ()
711
607
 
712
608
  cPainter.define_method("canvas", canvas);
713
609
  cPainter.define_method("bounds", bounds);
610
+ cPainter.define_method("pixel_density", pixel_density);
714
611
 
715
612
  cPainter.define_private_method("begin_paint", begin_paint);
716
613
  cPainter.define_private_method( "end_paint", end_paint);
717
614
  cPainter.define_method("clear", clear);
718
- cPainter.define_method("line", line);
719
- cPainter.define_method("lines", lines);
720
615
  cPainter.define_method("polygon", polygon);
721
- cPainter.define_method("rect", rect);
722
- cPainter.define_method("ellipse", ellipse);
723
- cPainter.define_method("arc", arc);
724
- cPainter.define_method("image", image);
725
- cPainter.define_method("text", text);
726
-
727
- cPainter.define_private_method("set_background", set_background);
728
- cPainter.define_private_method("get_background", get_background);
729
- cPainter.define_method( "no_background", no_background);
730
- cPainter.define_private_method("set_fill", set_fill);
731
- cPainter.define_private_method("get_fill", get_fill);
732
- cPainter.define_method( "no_fill", no_fill);
733
- cPainter.define_private_method("set_stroke", set_stroke);
734
- cPainter.define_private_method("get_stroke", get_stroke);
735
- cPainter.define_method( "no_stroke", no_stroke);
736
- cPainter.define_private_method("set_clip", set_clip);
737
- cPainter.define_private_method("get_clip", get_clip);
738
- cPainter.define_method( "no_clip", no_clip);
739
- cPainter.define_private_method("set_font", set_font);
740
- cPainter.define_private_method("get_font", get_font);
741
- cPainter.define_method("push_attr", push_attr);
742
- cPainter.define_method( "pop_attr", pop_attr);
743
-
744
- cPainter.define_private_method("attach_shader", attach_shader);
745
- cPainter.define_private_method("detach_shader", detach_shader);
746
- cPainter.define_private_method("set_uniform", set_uniform);
747
- cPainter.define_method("push_shader", push_shader);
748
- cPainter.define_method( "pop_shader", pop_shader);
616
+ cPainter.define_private_method("draw_line", line);
617
+ cPainter.define_private_method("draw_polyline", polyline);
618
+ cPainter.define_private_method("draw_rect", rect);
619
+ cPainter.define_private_method("draw_ellipse", ellipse);
620
+ cPainter.define_private_method("draw_curve", curve);
621
+ cPainter.define_private_method("draw_bezier", bezier);
622
+ cPainter.define_method("image", image);
623
+ cPainter.define_method("text", text);
624
+
625
+ cPainter.define_method( "background=", set_background);
626
+ cPainter.define_method( "background", get_background);
627
+ cPainter.define_method("no_background", no_background);
628
+ cPainter.define_method( "fill=", set_fill);
629
+ cPainter.define_method( "fill", get_fill);
630
+ cPainter.define_method("no_fill", no_fill);
631
+ cPainter.define_method( "stroke=", set_stroke);
632
+ cPainter.define_method( "stroke", get_stroke);
633
+ cPainter.define_method("no_stroke", no_stroke);
634
+ cPainter.define_method( "stroke_width=", set_stroke_width);
635
+ cPainter.define_method( "stroke_width", get_stroke_width);
636
+ cPainter.define_method( "stroke_cap=", set_stroke_cap);
637
+ cPainter.define_method( "stroke_cap", get_stroke_cap);
638
+ cPainter.define_method( "stroke_join=", set_stroke_join);
639
+ cPainter.define_method( "stroke_join", get_stroke_join);
640
+ cPainter.define_method("miter_limit=", set_miter_limit);
641
+ cPainter.define_method("miter_limit", get_miter_limit);
642
+ cPainter.define_method("nsegment=", set_nsegment);
643
+ cPainter.define_method("nsegment", get_nsegment);
644
+ cPainter.define_method( "clip=", set_clip);
645
+ cPainter.define_method( "clip", get_clip);
646
+ cPainter.define_method("no_clip", no_clip);
647
+ cPainter.define_method("font=", set_font);
648
+ cPainter.define_method("font", get_font);
649
+ cPainter.define_private_method("set_shader", set_shader);
650
+ cPainter.define_method( "shader", get_shader);
651
+ cPainter.define_method( "no_shader", no_shader);
652
+ cPainter.define_method("push_state", push_state);
653
+ cPainter.define_method( "pop_state", pop_state);
749
654
 
750
655
  cPainter.define_method("translate", translate);
751
656
  cPainter.define_method("scale", scale);
752
657
  cPainter.define_method("rotate", rotate);
753
- cPainter.define_private_method("set_matrix", set_matrix);
754
- cPainter.define_private_method("get_matrix", get_matrix);
658
+ cPainter.define_method("matrix=", set_matrix);
659
+ cPainter.define_method("matrix", get_matrix);
755
660
  cPainter.define_method("push_matrix", push_matrix);
756
661
  cPainter.define_method( "pop_matrix", pop_matrix);
757
662
  }