rays 0.1.12 → 0.1.13

Sign up to get free protection for your applications and to get access to all the features.
Files changed (155) 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/color.cpp +224 -45
  5. data/.doc/ext/rays/color_space.cpp +137 -45
  6. data/.doc/ext/rays/defs.cpp +183 -0
  7. data/.doc/ext/rays/font.cpp +39 -21
  8. data/.doc/ext/rays/image.cpp +26 -37
  9. data/.doc/ext/rays/matrix.cpp +186 -29
  10. data/.doc/ext/rays/native.cpp +12 -6
  11. data/.doc/ext/rays/noise.cpp +53 -0
  12. data/.doc/ext/rays/painter.cpp +120 -308
  13. data/.doc/ext/rays/point.cpp +82 -77
  14. data/.doc/ext/rays/polygon.cpp +287 -0
  15. data/.doc/ext/rays/polygon_line.cpp +96 -0
  16. data/.doc/ext/rays/polyline.cpp +161 -0
  17. data/.doc/ext/rays/rays.cpp +0 -13
  18. data/.doc/ext/rays/shader.cpp +83 -9
  19. data/README.md +1 -1
  20. data/Rakefile +21 -9
  21. data/VERSION +1 -1
  22. data/ext/rays/bitmap.cpp +22 -80
  23. data/ext/rays/bounds.cpp +100 -128
  24. data/ext/rays/color.cpp +232 -51
  25. data/ext/rays/color_space.cpp +140 -46
  26. data/ext/rays/defs.cpp +183 -0
  27. data/ext/rays/defs.h +26 -2
  28. data/ext/rays/extconf.rb +1 -2
  29. data/ext/rays/font.cpp +39 -22
  30. data/ext/rays/image.cpp +27 -39
  31. data/ext/rays/matrix.cpp +198 -30
  32. data/ext/rays/native.cpp +12 -6
  33. data/ext/rays/noise.cpp +55 -0
  34. data/ext/rays/painter.cpp +129 -315
  35. data/ext/rays/point.cpp +89 -81
  36. data/ext/rays/polygon.cpp +301 -0
  37. data/ext/rays/polygon_line.cpp +99 -0
  38. data/ext/rays/polyline.cpp +170 -0
  39. data/ext/rays/rays.cpp +0 -14
  40. data/ext/rays/shader.cpp +84 -9
  41. data/include/rays.h +10 -2
  42. data/include/rays/bitmap.h +14 -26
  43. data/include/rays/bounds.h +21 -4
  44. data/include/rays/color.h +25 -14
  45. data/include/rays/color_space.h +11 -8
  46. data/include/rays/coord.h +114 -0
  47. data/include/rays/debug.h +22 -0
  48. data/include/rays/defs.h +3 -0
  49. data/include/rays/font.h +4 -4
  50. data/include/rays/image.h +11 -17
  51. data/include/rays/matrix.h +50 -24
  52. data/include/rays/noise.h +42 -0
  53. data/include/rays/opengl.h +2 -50
  54. data/include/rays/painter.h +57 -99
  55. data/include/rays/point.h +44 -51
  56. data/include/rays/polygon.h +164 -0
  57. data/include/rays/polyline.h +65 -0
  58. data/include/rays/rays.h +3 -0
  59. data/include/rays/ruby.h +7 -1
  60. data/include/rays/ruby/bounds.h +1 -1
  61. data/include/rays/ruby/color.h +1 -1
  62. data/include/rays/ruby/color_space.h +1 -1
  63. data/include/rays/ruby/font.h +1 -1
  64. data/include/rays/ruby/matrix.h +1 -1
  65. data/include/rays/ruby/point.h +1 -1
  66. data/include/rays/ruby/polygon.h +52 -0
  67. data/include/rays/ruby/polyline.h +41 -0
  68. data/include/rays/ruby/shader.h +1 -1
  69. data/include/rays/shader.h +36 -8
  70. data/lib/rays.rb +6 -1
  71. data/lib/rays/bitmap.rb +0 -15
  72. data/lib/rays/bounds.rb +17 -23
  73. data/lib/rays/color.rb +20 -47
  74. data/lib/rays/color_space.rb +13 -13
  75. data/lib/rays/image.rb +2 -6
  76. data/lib/rays/matrix.rb +28 -0
  77. data/lib/rays/module.rb +4 -19
  78. data/lib/rays/painter.rb +60 -97
  79. data/lib/rays/point.rb +13 -21
  80. data/lib/rays/polygon.rb +50 -0
  81. data/lib/rays/polygon_line.rb +36 -0
  82. data/lib/rays/polyline.rb +32 -0
  83. data/lib/rays/shader.rb +20 -1
  84. data/rays.gemspec +5 -7
  85. data/src/bitmap.h +36 -0
  86. data/src/bounds.cpp +74 -11
  87. data/src/color.cpp +58 -23
  88. data/src/color_space.cpp +50 -32
  89. data/src/color_space.h +22 -0
  90. data/src/coord.cpp +170 -0
  91. data/src/coord.h +35 -0
  92. data/src/font.cpp +118 -0
  93. data/src/font.h +64 -0
  94. data/src/frame_buffer.cpp +37 -71
  95. data/src/frame_buffer.h +4 -4
  96. data/src/image.cpp +171 -97
  97. data/src/image.h +25 -0
  98. data/src/ios/bitmap.mm +107 -105
  99. data/src/ios/font.mm +48 -60
  100. data/src/ios/helper.h +2 -2
  101. data/src/ios/opengl.mm +19 -4
  102. data/src/ios/rays.mm +3 -0
  103. data/src/matrix.cpp +111 -26
  104. data/src/matrix.h +30 -0
  105. data/src/noise.cpp +74 -0
  106. data/src/opengl.cpp +9 -27
  107. data/src/opengl.h +37 -0
  108. data/src/osx/bitmap.mm +111 -106
  109. data/src/osx/font.mm +48 -61
  110. data/src/osx/helper.h +2 -2
  111. data/src/osx/opengl.mm +19 -83
  112. data/src/osx/rays.mm +3 -0
  113. data/src/painter.cpp +780 -696
  114. data/src/painter.h +24 -0
  115. data/src/point.cpp +140 -119
  116. data/src/polygon.cpp +1100 -0
  117. data/src/polygon.h +32 -0
  118. data/src/polyline.cpp +158 -0
  119. data/src/polyline.h +67 -0
  120. data/src/render_buffer.cpp +11 -4
  121. data/src/render_buffer.h +2 -2
  122. data/src/shader.cpp +163 -106
  123. data/src/shader.h +38 -0
  124. data/src/shader_program.cpp +533 -0
  125. data/src/{program.h → shader_program.h} +28 -16
  126. data/src/shader_source.cpp +140 -0
  127. data/src/shader_source.h +52 -0
  128. data/src/texture.cpp +136 -160
  129. data/src/texture.h +65 -0
  130. data/src/win32/bitmap.cpp +62 -52
  131. data/src/win32/font.cpp +11 -13
  132. data/src/win32/font.h +24 -0
  133. data/src/win32/gdi.h +6 -6
  134. data/test/helper.rb +0 -3
  135. data/test/test_bitmap.rb +31 -7
  136. data/test/test_bounds.rb +36 -0
  137. data/test/test_color.rb +59 -19
  138. data/test/test_color_space.rb +95 -0
  139. data/test/test_image.rb +24 -20
  140. data/test/test_matrix.rb +106 -0
  141. data/test/test_painter.rb +92 -46
  142. data/test/test_painter_shape.rb +57 -0
  143. data/test/test_point.rb +21 -0
  144. data/test/test_polygon.rb +234 -0
  145. data/test/test_polygon_line.rb +167 -0
  146. data/test/test_polyline.rb +145 -0
  147. data/test/test_shader.rb +9 -9
  148. metadata +88 -67
  149. data/.doc/ext/rays/texture.cpp +0 -138
  150. data/ext/rays/texture.cpp +0 -149
  151. data/include/rays/ruby/texture.h +0 -41
  152. data/include/rays/texture.h +0 -71
  153. data/lib/rays/texture.rb +0 -24
  154. data/src/program.cpp +0 -648
  155. data/test/test_texture.rb +0 -27
@@ -1,14 +1,11 @@
1
1
  #include "rays/ruby/matrix.h"
2
2
 
3
3
 
4
- #include <rucy.h>
4
+ #include "rays/ruby/point.h"
5
5
  #include "defs.h"
6
6
 
7
7
 
8
- using namespace Rucy;
9
-
10
-
11
- RUCY_DEFINE_VALUE_FROM_TO(Rays::Matrix)
8
+ RUCY_DEFINE_VALUE_OR_ARRAY_FROM_TO(Rays::Matrix)
12
9
 
13
10
  #define THIS to<Rays::Matrix*>(self)
14
11
 
@@ -28,22 +25,8 @@ RUCY_DEFN(initialize)
28
25
  CHECK;
29
26
  check_arg_count(__FILE__, __LINE__, "Matrix#initialize", argc, 0, 1, 16);
30
27
 
31
- if (argc == 0) return self;
32
-
33
- switch (argc)
34
- {
35
- case 1:
36
- *THIS = Rays::Matrix(to<float>(argv[0]));
37
- break;
38
-
39
- case 16:
40
- *THIS = Rays::Matrix(
41
- to<float>(argv[0]), to<float>(argv[1]), to<float>(argv[2]), to<float>(argv[3]),
42
- to<float>(argv[4]), to<float>(argv[5]), to<float>(argv[6]), to<float>(argv[7]),
43
- to<float>(argv[8]), to<float>(argv[9]), to<float>(argv[10]), to<float>(argv[11]),
44
- to<float>(argv[12]), to<float>(argv[13]), to<float>(argv[14]), to<float>(argv[15]));
45
- break;
46
- }
28
+ if (argc > 0)
29
+ *THIS = to<Rays::Matrix>(argc, argv);
47
30
 
48
31
  return self;
49
32
  }
@@ -59,23 +42,23 @@ RUCY_DEF1(initialize_copy, obj)
59
42
  RUCY_END
60
43
 
61
44
  static
62
- RUCY_DEFN(set)
45
+ RUCY_DEFN(reset)
63
46
  {
64
47
  CHECK;
65
- check_arg_count(__FILE__, __LINE__, "Matrix#initialize", argc, 0, 1, 16);
48
+ check_arg_count(__FILE__, __LINE__, "Matrix#reset", argc, 0, 1, 16);
66
49
 
67
50
  switch (argc)
68
51
  {
69
52
  case 0:
70
- *THIS = Rays::Matrix();
53
+ THIS->reset();
71
54
  break;
72
55
 
73
56
  case 1:
74
- *THIS = Rays::Matrix(to<float>(argv[0]));
57
+ THIS->reset(to<float>(argv[0]));
75
58
  break;
76
59
 
77
60
  case 16:
78
- *THIS = Rays::Matrix(
61
+ THIS->reset(
79
62
  to<float>(argv[0]), to<float>(argv[1]), to<float>(argv[2]), to<float>(argv[3]),
80
63
  to<float>(argv[4]), to<float>(argv[5]), to<float>(argv[6]), to<float>(argv[7]),
81
64
  to<float>(argv[8]), to<float>(argv[9]), to<float>(argv[10]), to<float>(argv[11]),
@@ -88,13 +71,140 @@ RUCY_DEFN(set)
88
71
  RUCY_END
89
72
 
90
73
  static
91
- RUCY_DEF2(at, row, column)
74
+ RUCY_DEFN(translate)
75
+ {
76
+ CHECK;
77
+ check_arg_count(__FILE__, __LINE__, "Matrix#translate", argc, 1, 2, 3);
78
+
79
+ THIS->translate(to<Rays::Point>(argc, argv));
80
+ return self;
81
+ }
82
+ RUCY_END
83
+
84
+ static
85
+ RUCY_DEFN(scale)
86
+ {
87
+ CHECK;
88
+ check_arg_count(__FILE__, __LINE__, "Matrix#scale", argc, 1, 2, 3);
89
+
90
+ THIS->scale(to<Rays::Point>(argc, argv));
91
+ return self;
92
+ }
93
+ RUCY_END
94
+
95
+ static
96
+ RUCY_DEFN(rotate)
97
+ {
98
+ CHECK;
99
+ check_arg_count(__FILE__, __LINE__, "Matrix#rotate", argc, 1, 2, 4);
100
+
101
+ float degree = to<float>(argv[0]);
102
+
103
+ if (argc == 1)
104
+ THIS->rotate(degree);
105
+ else
106
+ THIS->rotate(degree, to<Rays::Point>(argc - 1, argv + 1));
107
+
108
+ return self;
109
+ }
110
+ RUCY_END
111
+
112
+ static
113
+ RUCY_DEF0(to_a)
114
+ {
115
+ CHECK;
116
+ return array(
117
+ THIS->x0, THIS->y0, THIS->z0, THIS->w0,
118
+ THIS->x1, THIS->y1, THIS->z1, THIS->w1,
119
+ THIS->x2, THIS->y2, THIS->z2, THIS->w2,
120
+ THIS->x3, THIS->y3, THIS->z3, THIS->w3);
121
+ }
122
+ RUCY_END
123
+
124
+ static
125
+ RUCY_DEF1(mult, val)
126
+ {
127
+ CHECK;
128
+
129
+ if (val.is_kind_of(Rays::matrix_class()))
130
+ return value(*THIS * to<Rays::Matrix&>(val));
131
+
132
+ if (val.is_kind_of(Rays::point_class()))
133
+ return value(*THIS * to<Rays::Point&>(val));
134
+
135
+ if (val.is_array())
136
+ {
137
+ if (val.size() == 16)
138
+ return value(*THIS * to<Rays::Matrix>(val));
139
+ else
140
+ return value(*THIS * to<Rays::Point>(val));
141
+ }
142
+
143
+ argument_error(__FILE__, __LINE__);
144
+ }
145
+ RUCY_END
146
+
147
+ static
148
+ RUCY_DEF3(set_at, row, column, val)
149
+ {
150
+ CHECK;
151
+ return value(THIS->at(row.as_i(), column.as_i()) = to<float>(val));
152
+ }
153
+ RUCY_END
154
+
155
+ static
156
+ RUCY_DEF2(get_at, row, column)
92
157
  {
93
158
  CHECK;
94
159
  return value(THIS->at(row.as_i(), column.as_i()));
95
160
  }
96
161
  RUCY_END
97
162
 
163
+ static
164
+ RUCY_DEF1(compare, other)
165
+ {
166
+ CHECK;
167
+
168
+ const Rays::Matrix& a = *THIS;
169
+ const Rays::Matrix& b = to<const Rays::Matrix&>(other);
170
+ for (int i = 0; i < Rays::Matrix::NELEM; ++i)
171
+ {
172
+ if (a[i] == b[i]) continue;
173
+ return value(a[i] < b[i] ? -1 : +1);
174
+ }
175
+ return value(0);
176
+ }
177
+ RUCY_END
178
+
179
+ static
180
+ RUCY_DEF0(inspect)
181
+ {
182
+ CHECK;
183
+ return value(Xot::stringf("#<Rays::Matrix %s>", THIS->inspect().c_str()));
184
+ }
185
+ RUCY_END
186
+
187
+ static
188
+ RUCY_DEFN(s_translate)
189
+ {
190
+ return translate(argc, argv, value(Rays::Matrix()));
191
+ }
192
+ RUCY_END
193
+
194
+ static
195
+ RUCY_DEFN(s_scale)
196
+ {
197
+ return scale(argc, argv, value(Rays::Matrix()));
198
+ }
199
+ RUCY_END
200
+
201
+ static
202
+ RUCY_DEFN(s_rotate)
203
+ {
204
+ return rotate(argc, argv, value(Rays::Matrix()));
205
+ }
206
+ RUCY_END
207
+
98
208
 
99
209
  static Class cMatrix;
100
210
 
@@ -105,13 +215,71 @@ Init_matrix ()
105
215
 
106
216
  cMatrix = mRays.define_class("Matrix");
107
217
  cMatrix.define_alloc_func(alloc);
108
- cMatrix.define_private_method("initialize", initialize);
218
+ cMatrix.define_private_method("initialize", initialize);
109
219
  cMatrix.define_private_method("initialize_copy", initialize_copy);
110
- cMatrix.define_method("set", set);
111
- cMatrix.define_method("at", at);
220
+ cMatrix.define_method("reset", reset);
221
+ cMatrix.define_method("translate", translate);
222
+ cMatrix.define_method("scale", scale);
223
+ cMatrix.define_method("rotate", rotate);
224
+ cMatrix.define_method("to_a", to_a);
225
+ cMatrix.define_method("*", mult);
226
+ cMatrix.define_method("[]=", set_at);
227
+ cMatrix.define_method("[]", get_at);
228
+ cMatrix.define_method("<=>", compare);
229
+ cMatrix.define_method("inspect", inspect);
230
+
231
+ cMatrix.define_singleton_method("translate", s_translate);
232
+ cMatrix.define_singleton_method("scale", s_scale);
233
+ cMatrix.define_singleton_method("rotate", s_rotate);
112
234
  }
113
235
 
114
236
 
237
+ namespace Rucy
238
+ {
239
+
240
+
241
+ template <> Rays::Matrix
242
+ value_to<Rays::Matrix> (int argc, const Value* argv, bool convert)
243
+ {
244
+ if (argc == 1 && argv->is_array())
245
+ {
246
+ argc = argv->size();
247
+ argv = argv->as_array();
248
+ }
249
+
250
+ assert(argc == 0 || (argc > 0 && argv));
251
+
252
+ if (convert)
253
+ {
254
+ if (argc == 0)
255
+ return Rays::Matrix();
256
+ else if (argv->is_num())
257
+ {
258
+ switch (argc)
259
+ {
260
+ #define V(i) argv[i].as_f(true)
261
+ case 1: return Rays::Matrix(V(0));
262
+ case 16: return Rays::Matrix(
263
+ V(0), V(1), V(2), V(3),
264
+ V(4), V(5), V(6), V(7),
265
+ V(8), V(9), V(10), V(11),
266
+ V(12), V(13), V(14), V(15));
267
+ #undef V
268
+ default: argument_error(__FILE__, __LINE__);
269
+ }
270
+ }
271
+ }
272
+
273
+ if (argc != 1)
274
+ argument_error(__FILE__, __LINE__);
275
+
276
+ return value_to<Rays::Matrix&>(*argv, convert);
277
+ }
278
+
279
+
280
+ }// Rucy
281
+
282
+
115
283
  namespace Rays
116
284
  {
117
285
 
@@ -1,25 +1,26 @@
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_polyline ();
13
+ void Init_polygon_line ();
14
+ void Init_polygon ();
15
15
  void Init_bitmap ();
16
- void Init_texture ();
17
16
  void Init_image ();
18
17
  void Init_font ();
19
18
  void Init_shader ();
20
19
 
21
20
  void Init_painter ();
22
21
 
22
+ void Init_noise ();
23
+
23
24
 
24
25
  extern "C" void
25
26
  #ifdef COCOAPODS
@@ -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_polyline();
45
+ Init_polygon_line();
46
+ Init_polygon();
42
47
  Init_bitmap();
43
- Init_texture();
44
48
  Init_image();
45
49
  Init_font();
46
50
  Init_shader();
47
51
 
48
52
  Init_painter();
49
53
 
54
+ Init_noise();
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,70 @@ RUCY_DEF0(clear)
83
85
  RUCY_END
84
86
 
85
87
  static
86
- RUCY_DEFN(line)
87
- {
88
- 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
-
102
- return self;
103
- }
104
- RUCY_END
105
-
106
- static
107
- RUCY_DEFN(lines)
88
+ RUCY_DEF1(polygon, poly)
108
89
  {
109
90
  CHECK;
110
- if (argc <= 0)
111
- argument_error(__FILE__, __LINE__, "Painter#lines");
112
-
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]));
117
91
 
118
- THIS->lines((Rays::Point*) &points[0], points.size());
92
+ THIS->polygon(to<Rays::Polygon&>(poly));
119
93
  return self;
120
94
  }
121
95
  RUCY_END
122
96
 
123
97
  static
124
- RUCY_DEFN(polygon)
98
+ RUCY_DEF2(line, args, loop)
125
99
  {
126
100
  CHECK;
127
- if (argc <= 0)
128
- argument_error(__FILE__, __LINE__, "Painter#polygon");
129
101
 
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]));
102
+ std::vector<Rays::Point> points;
103
+ get_line_args(&points, args.size(), args.as_array());
134
104
 
135
- THIS->polygon((Rays::Point*) &points[0], points.size());
105
+ THIS->line(&points[0], points.size(), loop);
136
106
  return self;
137
107
  }
138
108
  RUCY_END
139
109
 
140
110
  static
141
- RUCY_DEFN(rect)
111
+ RUCY_DEF1(polyline, poly)
142
112
  {
143
113
  CHECK;
144
- check_arg_count(__FILE__, __LINE__, "Painter#rect", argc, 1, 2, 3, 4, 5, 6);
145
-
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
- }
163
114
 
115
+ THIS->line(to<Rays::Polyline&>(poly));
164
116
  return self;
165
117
  }
166
118
  RUCY_END
167
119
 
168
120
  static
169
- RUCY_DEFN(ellipse)
121
+ RUCY_DEF6(rect, args, round, lefttop, righttop, leftbottom, rightbottom)
170
122
  {
171
123
  CHECK;
172
- check_arg_count(__FILE__, __LINE__, "Painter#ellipse", argc, 1, 2, 3, 4, 5, 6);
173
124
 
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
- }
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());
191
131
 
132
+ THIS->rect(x, y, w, h, lt, rt, lb, rb);
192
133
  return self;
193
134
  }
194
135
  RUCY_END
195
136
 
196
137
  static
197
- RUCY_DEFN(arc)
138
+ RUCY_DEF6(ellipse, args, center, radius, hole, angle_from, angle_to)
198
139
  {
199
140
  CHECK;
200
- check_arg_count(__FILE__, __LINE__, "Painter#ellipse", argc, 1, 2, 3, 4, 5, 6, 7, 8);
201
141
 
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
- }
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());
223
150
 
151
+ THIS->ellipse(x, y, w, h, hole_size, from, to_);
224
152
  return self;
225
153
  }
226
154
  RUCY_END
@@ -273,7 +201,7 @@ static
273
201
  RUCY_DEFN(text)
274
202
  {
275
203
  CHECK;
276
- check_arg_count(__FILE__, __LINE__, "Painter#text", argc, 1, 3, 4, 5, 7);
204
+ check_arg_count(__FILE__, __LINE__, "Painter#text", argc, 1, 3, 5);
277
205
 
278
206
  if (argc == 1)
279
207
  THIS->text(argv[0].c_str());
@@ -282,63 +210,35 @@ RUCY_DEFN(text)
282
210
  coord x = to<coord>(argv[1]), y = to<coord>(argv[2]);
283
211
  THIS->text(argv[0].c_str(), x, y);
284
212
  }
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
213
  else if (argc == 5)
295
214
  {
296
215
  coord x = to<coord>(argv[1]), w = to<coord>(argv[3]);
297
216
  coord y = to<coord>(argv[2]), h = to<coord>(argv[4]);
298
217
  THIS->text(argv[0].c_str(), x, y, w, h);
299
218
  }
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
219
 
311
220
  return self;
312
221
  }
313
222
  RUCY_END
314
223
 
224
+
315
225
  static
316
226
  RUCY_DEFN(set_background)
317
227
  {
318
228
  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
-
229
+ THIS->set_background(to<Rays::Color>(argc, argv));
338
230
  return self;
339
231
  }
340
232
  RUCY_END
341
233
 
234
+ static
235
+ RUCY_DEF0(get_background)
236
+ {
237
+ CHECK;
238
+ return value(THIS->background());
239
+ }
240
+ RUCY_END
241
+
342
242
  static
343
243
  RUCY_DEF0(no_background)
344
244
  {
@@ -349,37 +249,19 @@ RUCY_DEF0(no_background)
349
249
  RUCY_END
350
250
 
351
251
  static
352
- RUCY_DEF0(get_background)
252
+ RUCY_DEFN(set_fill)
353
253
  {
354
254
  CHECK;
355
- return value(THIS->background());
255
+ THIS->set_fill(to<Rays::Color>(argc, argv));
256
+ return self;
356
257
  }
357
258
  RUCY_END
358
259
 
359
260
  static
360
- RUCY_DEFN(set_fill)
261
+ RUCY_DEF0(get_fill)
361
262
  {
362
263
  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;
264
+ return value(THIS->fill());
383
265
  }
384
266
  RUCY_END
385
267
 
@@ -393,37 +275,19 @@ RUCY_DEF0(no_fill)
393
275
  RUCY_END
394
276
 
395
277
  static
396
- RUCY_DEF0(get_fill)
278
+ RUCY_DEFN(set_stroke)
397
279
  {
398
280
  CHECK;
399
- return value(THIS->fill());
281
+ THIS->set_stroke(to<Rays::Color>(argc, argv));
282
+ return self;
400
283
  }
401
284
  RUCY_END
402
285
 
403
286
  static
404
- RUCY_DEFN(set_stroke)
287
+ RUCY_DEF0(get_stroke)
405
288
  {
406
289
  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;
290
+ return value(THIS->stroke());
427
291
  }
428
292
  RUCY_END
429
293
 
@@ -437,177 +301,126 @@ RUCY_DEF0(no_stroke)
437
301
  RUCY_END
438
302
 
439
303
  static
440
- RUCY_DEF0(get_stroke)
304
+ RUCY_DEF1(set_stroke_width, width)
441
305
  {
442
306
  CHECK;
443
- return value(THIS->stroke());
307
+ THIS->set_stroke_width(to<coord>(width));
308
+ return self;
444
309
  }
445
310
  RUCY_END
446
311
 
447
312
  static
448
- RUCY_DEFN(set_clip)
313
+ RUCY_DEF0(get_stroke_width)
449
314
  {
450
315
  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;
316
+ return value(THIS->stroke_width());
465
317
  }
466
318
  RUCY_END
467
319
 
468
320
  static
469
- RUCY_DEF0(no_clip)
321
+ RUCY_DEF1(set_nsegment, nsegment)
470
322
  {
471
323
  CHECK;
472
- THIS->no_clip();
324
+ THIS->set_nsegment(nsegment ? to<int>(nsegment) : 0);
473
325
  return self;
474
326
  }
475
327
  RUCY_END
476
328
 
477
329
  static
478
- RUCY_DEF0(get_clip)
330
+ RUCY_DEF0(get_nsegment)
479
331
  {
480
332
  CHECK;
481
- return value(THIS->clip());
333
+ return value(THIS->nsegment());
482
334
  }
483
335
  RUCY_END
484
336
 
485
337
  static
486
- RUCY_DEFN(set_font)
338
+ RUCY_DEFN(set_clip)
487
339
  {
488
340
  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__);
498
-
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
- }
507
-
341
+ THIS->set_clip(to<Rays::Bounds>(argc, argv));
508
342
  return self;
509
343
  }
510
344
  RUCY_END
511
345
 
512
346
  static
513
- RUCY_DEF0(get_font)
347
+ RUCY_DEF0(get_clip)
514
348
  {
515
349
  CHECK;
516
- return value(THIS->font());
350
+ return value(THIS->clip());
517
351
  }
518
352
  RUCY_END
519
353
 
520
354
  static
521
- RUCY_DEF0(push_attr)
355
+ RUCY_DEF0(no_clip)
522
356
  {
523
357
  CHECK;
524
- THIS->push_attr();
358
+ THIS->no_clip();
525
359
  return self;
526
360
  }
527
361
  RUCY_END
528
362
 
529
363
  static
530
- RUCY_DEF0(pop_attr)
364
+ RUCY_DEFN(set_font)
531
365
  {
532
366
  CHECK;
533
- THIS->pop_attr();
367
+ check_arg_count(__FILE__, __LINE__, "Painter#set_font", argc, 0, 1, 2);
368
+
369
+ THIS->set_font(to<Rays::Font>(argc, argv));
534
370
  return self;
535
371
  }
536
372
  RUCY_END
537
373
 
538
-
539
374
  static
540
- RUCY_DEF1(attach_shader, shader)
375
+ RUCY_DEF0(get_font)
541
376
  {
542
377
  CHECK;
543
- THIS->attach(to<Rays::Shader&>(shader));
544
- return self;
378
+ return value(THIS->font());
545
379
  }
546
380
  RUCY_END
547
381
 
548
382
  static
549
- RUCY_DEF1(detach_shader, shader)
383
+ RUCY_DEFN(set_shader)
550
384
  {
551
385
  CHECK;
552
- THIS->detach(to<Rays::Shader&>(shader));
386
+ check_arg_count(__FILE__, __LINE__, "Painter#set_shader", argc, 1);
387
+
388
+ THIS->set_shader(to<Rays::Shader>(argc, argv));
553
389
  return self;
554
390
  }
555
391
  RUCY_END
556
392
 
557
393
  static
558
- RUCY_DEFN(set_uniform)
394
+ RUCY_DEF0(get_shader)
559
395
  {
560
396
  CHECK;
561
- check_arg_count(__FILE__, __LINE__, "Painter#set_uniform", argc, 2, 3, 4, 5);
562
-
563
- #define Ai(n) (argv[n].as_i())
564
- #define Af(n) ((float) argv[n].as_f())
565
-
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__);
589
-
590
- #undef Ai
591
- #undef Af
397
+ return value(THIS->shader());
398
+ }
399
+ RUCY_END
592
400
 
401
+ static
402
+ RUCY_DEF0(no_shader)
403
+ {
404
+ CHECK;
405
+ THIS->no_shader();
593
406
  return self;
594
407
  }
595
408
  RUCY_END
596
409
 
597
410
  static
598
- RUCY_DEF0(push_shader)
411
+ RUCY_DEF0(push_state)
599
412
  {
600
413
  CHECK;
601
- THIS->push_shader();
414
+ THIS->push_state();
602
415
  return self;
603
416
  }
604
417
  RUCY_END
605
418
 
606
419
  static
607
- RUCY_DEF0(pop_shader)
420
+ RUCY_DEF0(pop_state)
608
421
  {
609
422
  CHECK;
610
- THIS->pop_shader();
423
+ THIS->pop_state();
611
424
  return self;
612
425
  }
613
426
  RUCY_END
@@ -667,8 +480,8 @@ static
667
480
  RUCY_DEFN(set_matrix)
668
481
  {
669
482
  CHECK;
670
- THIS->set_matrix();
671
- return self;
483
+ THIS->set_matrix(to<Rays::Matrix>(argc, argv));
484
+ return value(THIS->matrix());
672
485
  }
673
486
  RUCY_END
674
487
 
@@ -711,47 +524,48 @@ Init_painter ()
711
524
 
712
525
  cPainter.define_method("canvas", canvas);
713
526
  cPainter.define_method("bounds", bounds);
527
+ cPainter.define_method("pixel_density", pixel_density);
714
528
 
715
529
  cPainter.define_private_method("begin_paint", begin_paint);
716
530
  cPainter.define_private_method( "end_paint", end_paint);
717
531
  cPainter.define_method("clear", clear);
718
- cPainter.define_method("line", line);
719
- cPainter.define_method("lines", lines);
720
532
  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);
533
+ cPainter.define_private_method("draw_line", line);
534
+ cPainter.define_private_method("draw_polyline", polyline);
535
+ cPainter.define_private_method("draw_rect", rect);
536
+ cPainter.define_private_method("draw_ellipse", ellipse);
537
+ cPainter.define_method("image", image);
538
+ cPainter.define_method("text", text);
539
+
540
+ cPainter.define_method( "background=", set_background);
541
+ cPainter.define_method( "background", get_background);
542
+ cPainter.define_method("no_background", no_background);
543
+ cPainter.define_method( "fill=", set_fill);
544
+ cPainter.define_method( "fill", get_fill);
545
+ cPainter.define_method("no_fill", no_fill);
546
+ cPainter.define_method( "stroke=", set_stroke);
547
+ cPainter.define_method( "stroke", get_stroke);
548
+ cPainter.define_method("no_stroke", no_stroke);
549
+ cPainter.define_method( "stroke_width=", set_stroke_width);
550
+ cPainter.define_method( "stroke_width", get_stroke_width);
551
+ cPainter.define_method("nsegment=", set_nsegment);
552
+ cPainter.define_method("nsegment", get_nsegment);
553
+ cPainter.define_method( "clip=", set_clip);
554
+ cPainter.define_method( "clip", get_clip);
555
+ cPainter.define_method("no_clip", no_clip);
556
+ cPainter.define_method("font=", set_font);
557
+ cPainter.define_method("font", get_font);
558
+ cPainter.define_private_method("set_shader", set_shader);
559
+ cPainter.define_method( "shader", get_shader);
560
+ cPainter.define_method( "no_shader", no_shader);
561
+ cPainter.define_method("push_state", push_state);
562
+ cPainter.define_method( "pop_state", pop_state);
749
563
 
750
564
  cPainter.define_method("translate", translate);
751
565
  cPainter.define_method("scale", scale);
752
566
  cPainter.define_method("rotate", rotate);
753
- cPainter.define_private_method("set_matrix", set_matrix);
754
- cPainter.define_private_method("get_matrix", get_matrix);
567
+ cPainter.define_method("matrix=", set_matrix);
568
+ cPainter.define_method("matrix", get_matrix);
755
569
  cPainter.define_method("push_matrix", push_matrix);
756
570
  cPainter.define_method( "pop_matrix", pop_matrix);
757
571
  }