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,18 +1,65 @@
1
1
  #include "rays/ruby/color_space.h"
2
2
 
3
3
 
4
- #include <rucy.h>
5
4
  #include "defs.h"
6
5
 
7
6
 
8
- using namespace Rucy;
7
+ RUCY_DEFINE_VALUE_OR_ARRAY_FROM_TO(Rays::ColorSpace)
9
8
 
9
+ #define THIS to<Rays::ColorSpace*>(self)
10
10
 
11
- RUCY_DEFINE_VALUE_FROM_TO(Rays::ColorSpace)
11
+ #define CHECK RUCY_CHECK_OBJECT(Rays::ColorSpace, self)
12
12
 
13
- #define THIS to<Rays::ColorSpace*>(self)
14
13
 
15
- #define CHECK RUCY_CHECK_OBJ(Rays::ColorSpace, self)
14
+ static struct ColorSpaceEnum
15
+ {
16
+ const char* name;
17
+ Rays::ColorSpaceType type;
18
+ }
19
+ COLOR_SPACES[] =
20
+ {
21
+ {"GRAY", Rays::GRAY},
22
+ {"ALPHA", Rays::ALPHA},
23
+ {"RGB", Rays:: RGB},
24
+ {"BGR", Rays:: BGR},
25
+ {"RGBA", Rays:: RGBA},
26
+ {"RGBX", Rays:: RGBX},
27
+ {"ARGB", Rays::ARGB},
28
+ {"XRGB", Rays::XRGB},
29
+ {"BGRA", Rays:: BGRA},
30
+ {"BGRX", Rays:: BGRX},
31
+ {"ABGR", Rays::ABGR},
32
+ {"XBGR", Rays::XBGR},
33
+ {"GRAY_8", Rays::GRAY_8},
34
+ {"GRAY_16", Rays::GRAY_16},
35
+ {"GRAY_24", Rays::GRAY_24},
36
+ {"GRAY_32", Rays::GRAY_32},
37
+ {"GRAY_float", Rays::GRAY_float},
38
+ {"ALPHA_8", Rays::ALPHA_8},
39
+ {"ALPHA_16", Rays::ALPHA_16},
40
+ {"ALPHA_24", Rays::ALPHA_24},
41
+ {"ALPHA_32", Rays::ALPHA_32},
42
+ {"ALPHA_float", Rays::ALPHA_float},
43
+ {"RGB_888", Rays:: RGB_888},
44
+ {"RGBA_8888", Rays:: RGBA_8888},
45
+ {"RGBX_8888", Rays:: RGBX_8888},
46
+ {"ARGB_8888", Rays::ARGB_8888},
47
+ {"XRGB_8888", Rays::XRGB_8888},
48
+ {"BGR_888", Rays:: BGR_888},
49
+ {"BGRA_8888", Rays:: BGRA_8888},
50
+ {"BGRX_8888", Rays:: BGRX_8888},
51
+ {"ABGR_8888", Rays::ABGR_8888},
52
+ {"XBGR_8888", Rays::XBGR_8888},
53
+ {"RGB_float", Rays:: RGB_float},
54
+ {"RGBA_float", Rays:: RGBA_float},
55
+ {"ARGB_float", Rays::ARGB_float},
56
+ {"BGR_float", Rays:: BGR_float},
57
+ {"BGRA_float", Rays:: BGRA_float},
58
+ {"ABGR_float", Rays::ABGR_float},
59
+ };
60
+
61
+ static const size_t COLOR_SPACES_SIZE =
62
+ sizeof(COLOR_SPACES) / sizeof(COLOR_SPACES[0]);
16
63
 
17
64
 
18
65
  static
@@ -22,13 +69,12 @@ VALUE alloc(VALUE klass)
22
69
  }
23
70
 
24
71
  static
25
- VALUE setup(VALUE self, VALUE type, VALUE premultiplied)
72
+ VALUE initialize(VALUE self)
26
73
  {
27
- CHECK;
74
+ RUCY_CHECK_OBJ(Rays::ColorSpace, self);
75
+ check_arg_count(__FILE__, __LINE__, "ColorSpace#initialize", argc, 1, 2);
28
76
 
29
- *THIS = Rays::ColorSpace(
30
- (Rays::ColorSpaceType) to<uint>(type),
31
- to<bool>(premultiplied));
77
+ *THIS = to<Rays::ColorSpace>(argc, argv);
32
78
  return self;
33
79
  }
34
80
 
@@ -56,6 +102,14 @@ VALUE is_gray(VALUE self)
56
102
  return value(THIS->is_gray());
57
103
  }
58
104
 
105
+ static
106
+ VALUE is_alpha(VALUE self)
107
+ {
108
+ CHECK;
109
+
110
+ return value(THIS->is_alpha());
111
+ }
112
+
59
113
  static
60
114
  VALUE is_rgb(VALUE self)
61
115
  {
@@ -104,6 +158,21 @@ VALUE is_premult(VALUE self)
104
158
  return value(THIS->is_premult());
105
159
  }
106
160
 
161
+ static
162
+ VALUE to_s(VALUE self)
163
+ {
164
+ CHECK;
165
+
166
+ Rays::ColorSpaceType type = THIS->type();
167
+ for (size_t i = 0; i < COLOR_SPACES_SIZE; ++i)
168
+ {
169
+ if (type == COLOR_SPACES[i].type)
170
+ return value(COLOR_SPACES[i].name);
171
+ }
172
+
173
+ invalid_object_error(__FILE__, __LINE__);
174
+ }
175
+
107
176
 
108
177
  static Class cColorSpace;
109
178
 
@@ -112,54 +181,85 @@ Init_color_space ()
112
181
  {
113
182
  Module mRays = rb_define_module("Rays");
114
183
 
184
+ for (size_t i = 0; i < COLOR_SPACES_SIZE; ++i)
185
+ mRays.define_const(COLOR_SPACES[i].name, COLOR_SPACES[i].type);
186
+
115
187
  cColorSpace = rb_define_class_under(mRays, "ColorSpace", rb_cObject);
116
188
  rb_define_alloc_func(cColorSpace, alloc);
189
+ rb_define_private_method(cColorSpace, "initialize", RUBY_METHOD_FUNC(initialize), -1);
117
190
  rb_define_private_method(cColorSpace, "initialize_copy", RUBY_METHOD_FUNC(initialize_copy), 1);
118
- rb_define_private_method(cColorSpace, "setup", RUBY_METHOD_FUNC(setup), 2);
119
191
  rb_define_method(cColorSpace, "type", RUBY_METHOD_FUNC(type), 0);
120
192
  cColorSpace.define_method("gray?", is_gray);
193
+ cColorSpace.define_method("alpha?", is_alpha);
121
194
  cColorSpace.define_method("rgb?", is_rgb);
122
195
  cColorSpace.define_method("bgr?", is_bgr);
123
196
  cColorSpace.define_method("float?", is_float);
124
- cColorSpace.define_method("alpha?", has_alpha);
125
- cColorSpace.define_method("skip?", has_skip);
197
+ cColorSpace.define_method("has_alpha?", has_alpha);
198
+ cColorSpace.define_method("has_skip?", has_skip);
126
199
  cColorSpace.define_method("premult?", is_premult);
127
-
128
- cColorSpace.define_const("GRAY_8", Rays::GRAY_8);
129
- cColorSpace.define_const("GRAY_16", Rays::GRAY_16);
130
- cColorSpace.define_const("GRAY_24", Rays::GRAY_24);
131
- cColorSpace.define_const("GRAY_32", Rays::GRAY_32);
132
- cColorSpace.define_const("GRAY_float", Rays::GRAY_float);
133
- cColorSpace.define_const("RGB_888", Rays:: RGB_888);
134
- cColorSpace.define_const("RGBA_8888", Rays:: RGBA_8888);
135
- cColorSpace.define_const("RGBX_8888", Rays:: RGBX_8888);
136
- cColorSpace.define_const("ARGB_8888", Rays::ARGB_8888);
137
- cColorSpace.define_const("XRGB_8888", Rays::XRGB_8888);
138
- cColorSpace.define_const("BGR_888", Rays:: BGR_888);
139
- cColorSpace.define_const("BGRA_8888", Rays:: BGRA_8888);
140
- cColorSpace.define_const("BGRX_8888", Rays:: BGRX_8888);
141
- cColorSpace.define_const("ABGR_8888", Rays::ABGR_8888);
142
- cColorSpace.define_const("XBGR_8888", Rays::XBGR_8888);
143
- cColorSpace.define_const("RGB_float", Rays:: RGB_float);
144
- cColorSpace.define_const("RGBA_float", Rays:: RGBA_float);
145
- cColorSpace.define_const("ARGB_float", Rays::ARGB_float);
146
- cColorSpace.define_const("BGR_float", Rays:: BGR_float);
147
- cColorSpace.define_const("BGRA_float", Rays:: BGRA_float);
148
- cColorSpace.define_const("ABGR_float", Rays::ABGR_float);
149
- cColorSpace.define_const("GRAY", Rays::GRAY);
150
- cColorSpace.define_const("RGB", Rays:: RGB);
151
- cColorSpace.define_const("BGR", Rays:: BGR);
152
- cColorSpace.define_const("RGBA", Rays:: RGBA);
153
- cColorSpace.define_const("RGBX", Rays:: RGBX);
154
- cColorSpace.define_const("ARGB", Rays::ARGB);
155
- cColorSpace.define_const("XRGB", Rays::XRGB);
156
- cColorSpace.define_const("BGRA", Rays:: BGRA);
157
- cColorSpace.define_const("BGRX", Rays:: BGRX);
158
- cColorSpace.define_const("ABGR", Rays::ABGR);
159
- cColorSpace.define_const("XBGR", Rays::XBGR);
200
+ rb_define_method(cColorSpace, "to_s", RUBY_METHOD_FUNC(to_s), 0);
160
201
  }
161
202
 
162
203
 
204
+ namespace Rucy
205
+ {
206
+
207
+
208
+ template <> Rays::ColorSpace
209
+ value_to<Rays::ColorSpace> (int argc, const Value* argv, bool convert)
210
+ {
211
+ if (argc == 1 && argv->is_array())
212
+ {
213
+ argc = argv->size();
214
+ argv = argv->as_array();
215
+ }
216
+
217
+ assert(argc > 0 && argv);
218
+
219
+ if (convert)
220
+ {
221
+ if (argv->is_i() || argv->is_s() || argv->is_sym())
222
+ {
223
+ return Rays::ColorSpace(
224
+ to<Rays::ColorSpaceType>(argv[0]),
225
+ argc >= 2 ? to<bool>(argv[1]) : true);
226
+ }
227
+ }
228
+
229
+ if (argc != 1)
230
+ argument_error(__FILE__, __LINE__);
231
+
232
+ return value_to<Rays::ColorSpace&>(*argv, convert);
233
+ }
234
+
235
+
236
+ template <> Rays::ColorSpaceType
237
+ value_to<Rays::ColorSpaceType> (Value value, bool convert)
238
+ {
239
+ if (convert)
240
+ {
241
+ if (value.is_s() || value.is_sym())
242
+ {
243
+ const char* str = value.c_str();
244
+ for (size_t i = 0; i < COLOR_SPACES_SIZE; ++i)
245
+ {
246
+ if (strcasecmp(str, COLOR_SPACES[i].name) == 0)
247
+ return COLOR_SPACES[i].type;
248
+ }
249
+ }
250
+ }
251
+
252
+ uint type = value_to<uint>(value, convert);
253
+ if (type >= Rays::COLORSPACE_MAX)
254
+ argument_error(__FILE__, __LINE__, "invalid color space type -- %d", type);
255
+
256
+ return (Rays::ColorSpaceType) type;
257
+ }
258
+
259
+
260
+ }// Rucy
261
+
262
+
163
263
  namespace Rays
164
264
  {
165
265
 
@@ -0,0 +1,183 @@
1
+ #include "defs.h"
2
+
3
+
4
+ #include <assert.h>
5
+ #include "rays/ruby/bounds.h"
6
+ #include "rays/ruby/point.h"
7
+
8
+
9
+ void
10
+ get_line_args (std::vector<Rays::Point>* points, int argc, const Value* argv)
11
+ {
12
+ assert(points && argv);
13
+
14
+ points->clear();
15
+
16
+ if (argc <= 0)
17
+ return;
18
+
19
+ if (argv[0].is_num())
20
+ {
21
+ if (argc % 2 != 0)
22
+ argument_error(__FILE__, __LINE__);
23
+
24
+ points->reserve(argc / 2);
25
+ for (int i = 0; i < argc; i += 2)
26
+ {
27
+ coord x = to<coord>(argv[i + 0]);
28
+ coord y = to<coord>(argv[i + 1]);
29
+ points->emplace_back(Rays::Point(x, y));
30
+ }
31
+ }
32
+ else
33
+ {
34
+ points->reserve(argc);
35
+ for (int i = 0; i < argc; ++i)
36
+ points->emplace_back(to<Rays::Point>(argv[i]));
37
+ }
38
+ }
39
+
40
+ static uint
41
+ get_nsegment (Value nsegment)
42
+ {
43
+ int value = nsegment ? to<int>(nsegment) : 0;
44
+ if (value < 0) value = 0;
45
+ return (uint) value;
46
+ }
47
+
48
+ void get_rect_args (
49
+ coord* x, coord* y, coord* w, coord* h,
50
+ coord* lt, coord* rt, coord* lb, coord* rb,
51
+ uint* nseg,
52
+ int argc, const Value* argv,
53
+ Value round, Value lefttop, Value righttop, Value leftbottom, Value rightbottom,
54
+ Value nsegment)
55
+ {
56
+ assert(x && y && w && h && lt && rt && lb && rb && nseg && argv);
57
+
58
+ if (argc <= 0)
59
+ argument_error(__FILE__, __LINE__);
60
+
61
+ if (argv[0].is_kind_of(Rays::bounds_class()))
62
+ {
63
+ Rays::Bounds& b = to<Rays::Bounds&>(argv[0]);
64
+ *x = b.x;
65
+ *y = b.y;
66
+ *w = b.w;
67
+ *h = b.h;
68
+ *lt = argc >= 2 ? to<coord>(argv[1]) : 0;
69
+ *rt = argc >= 3 ? to<coord>(argv[2]) : *lt;
70
+ *lb = argc >= 4 ? to<coord>(argv[3]) : *lt;
71
+ *rb = argc >= 5 ? to<coord>(argv[4]) : *lt;
72
+ }
73
+ else if (argv[0].is_kind_of(Rays::point_class()))
74
+ {
75
+ if (argc < 2)
76
+ argument_error(__FILE__, __LINE__);
77
+
78
+ Rays::Point& p = to<Rays::Point&>(argv[0]);
79
+ *x = p.x;
80
+ *y = p.y;
81
+ *w = to<coord>(argv[1]);
82
+ *h = argc >= 3 ? to<coord>(argv[2]) : *w;
83
+ *lt = argc >= 4 ? to<coord>(argv[3]) : 0;
84
+ *rt = argc >= 5 ? to<coord>(argv[4]) : *lt;
85
+ *lb = argc >= 6 ? to<coord>(argv[5]) : *lt;
86
+ *rb = argc >= 7 ? to<coord>(argv[6]) : *lt;
87
+ }
88
+ else if (argc <= 2)
89
+ {
90
+ *x = *y = *lt = *rt = *lb = *rb = 0;
91
+ *w = to<coord>(argv[0]);
92
+ *h = argc >= 2 ? to<coord>(argv[1]) : *w;
93
+ }
94
+ else
95
+ {
96
+ *x = to<coord>(argv[0]);
97
+ *y = to<coord>(argv[1]);
98
+ *w = to<coord>(argv[2]);
99
+ *h = argc >= 4 ? to<coord>(argv[3]) : *w;
100
+ *lt = argc >= 5 ? to<coord>(argv[4]) : 0;
101
+ *rt = argc >= 6 ? to<coord>(argv[5]) : *lt;
102
+ *lb = argc >= 7 ? to<coord>(argv[6]) : *lt;
103
+ *rb = argc >= 8 ? to<coord>(argv[7]) : *lt;
104
+ }
105
+
106
+ if (! lefttop) lefttop = round;
107
+ if (!righttop) righttop = round;
108
+ if (! leftbottom) leftbottom = round;
109
+ if (!rightbottom) rightbottom = round;
110
+
111
+ if ( lefttop) *lt = to<coord>( lefttop);
112
+ if (righttop) *rt = to<coord>(righttop);
113
+ if ( leftbottom) *lb = to<coord>( leftbottom);
114
+ if (rightbottom) *rb = to<coord>(rightbottom);
115
+
116
+ *nseg = get_nsegment(nsegment);
117
+ }
118
+
119
+ void get_ellipse_args (
120
+ coord* x, coord* y, coord* w, coord* h,
121
+ Rays::Point* hole_size, float* from, float* to_,
122
+ uint* nseg,
123
+ int argc, const Value* argv,
124
+ Value center, Value radius, Value hole, Value angle_from, Value angle_to,
125
+ Value nsegment)
126
+ {
127
+ assert(x && y && w && h && hole_size && from && to_ && nseg && argv);
128
+
129
+ if (argc <= 0)
130
+ argument_error(__FILE__, __LINE__);
131
+
132
+ if (argv[0].is_kind_of(Rays::bounds_class()))
133
+ {
134
+ const Rays::Bounds& b = to<Rays::Bounds&>(argv[0]);
135
+ *x = b.x;
136
+ *y = b.y;
137
+ *w = b.w;
138
+ *h = b.h;
139
+ }
140
+ else if (argv[0].is_kind_of(Rays::point_class()))
141
+ {
142
+ if (argc < 2)
143
+ argument_error(__FILE__, __LINE__);
144
+
145
+ const Rays::Point& p = to<Rays::Point&>(argv[0]);
146
+ *x = p.x;
147
+ *y = p.y;
148
+ *w = to<coord>(argv[1]);
149
+ *h = argc >= 3 ? to<coord>(argv[2]) : *w;
150
+ }
151
+ else if (argc <= 2)
152
+ {
153
+ *x = *y = 0;
154
+ *w = to<coord>(argv[0]);
155
+ *h = argc >= 2 ? to<coord>(argv[1]) : *w;
156
+ }
157
+ else
158
+ {
159
+ *x = to<coord>(argv[0]);
160
+ *y = to<coord>(argv[1]);
161
+ *w = to<coord>(argv[2]);
162
+ *h = argc >= 4 ? to<coord>(argv[3]) : *w;
163
+ }
164
+
165
+ if (center)
166
+ {
167
+ Rays::Point p = to<Rays::Point>(center);
168
+ *x = p.x;
169
+ *y = p.y;
170
+ }
171
+
172
+ if (radius)
173
+ {
174
+ Rays::Point p = to<Rays::Point>(radius);
175
+ *w = p.x * 2;
176
+ *h = p.y * 2;
177
+ }
178
+
179
+ *hole_size = hole ? to<Rays::Point>(hole) : 0;
180
+ *from = angle_from ? to<float>(angle_from) : 0;
181
+ *to_ = angle_to ? to<float>(angle_to) : 360;
182
+ *nseg = get_nsegment(nsegment);
183
+ }
@@ -1,16 +1,10 @@
1
1
  #include "rays/ruby/font.h"
2
2
 
3
3
 
4
- #include <rucy.h>
5
4
  #include "defs.h"
6
5
 
7
6
 
8
- using namespace Rucy;
9
-
10
- using Rays::coord;
11
-
12
-
13
- RUCY_DEFINE_VALUE_FROM_TO(Rays::Font)
7
+ RUCY_DEFINE_VALUE_OR_ARRAY_FROM_TO(Rays::Font)
14
8
 
15
9
  #define THIS to<Rays::Font*>(self)
16
10
 
@@ -29,19 +23,7 @@ VALUE initialize(VALUE self)
29
23
  RUCY_CHECK_OBJ(Rays::Font, self);
30
24
  check_arg_count(__FILE__, __LINE__, "Font#initialize", argc, 0, 1, 2);
31
25
 
32
- const char* name = (argc >= 1) ? argv[0].c_str() : NULL;
33
- float size = (argc >= 2) ? to<float>(argv[1]) : 0;
34
- *THIS = Rays::Font(name, size);
35
-
36
- return self;
37
- }
38
-
39
- static
40
- VALUE initialize_copy(VALUE self, VALUE obj)
41
- {
42
- RUCY_CHECK_OBJ(Rays::Font, self);
43
-
44
- *THIS = to<Rays::Font&>(obj).copy();
26
+ *THIS = to<Rays::Font>(argc, argv);
45
27
  return self;
46
28
  }
47
29
 
@@ -73,6 +55,33 @@ VALUE height(VALUE self)
73
55
  return value(THIS->get_height());
74
56
  }
75
57
 
58
+ static
59
+ VALUE ascent(VALUE self)
60
+ {
61
+ CHECK;
62
+ coord ascent = 0;
63
+ THIS->get_height(&ascent);
64
+ return value(ascent);
65
+ }
66
+
67
+ static
68
+ VALUE descent(VALUE self)
69
+ {
70
+ CHECK;
71
+ coord descent = 0;
72
+ THIS->get_height(NULL, &descent);
73
+ return value(descent);
74
+ }
75
+
76
+ static
77
+ VALUE leading(VALUE self)
78
+ {
79
+ CHECK;
80
+ coord leading = 0;
81
+ THIS->get_height(NULL, NULL, &leading);
82
+ return value(leading);
83
+ }
84
+
76
85
 
77
86
  static Class cFont;
78
87
 
@@ -84,14 +93,53 @@ Init_font ()
84
93
  cFont = rb_define_class_under(mRays, "Font", rb_cObject);
85
94
  rb_define_alloc_func(cFont, alloc);
86
95
  rb_define_private_method(cFont, "initialize", RUBY_METHOD_FUNC(initialize), -1);
87
- rb_define_private_method(cFont, "initialize_copy", RUBY_METHOD_FUNC(initialize_copy), 1);
88
96
  rb_define_method(cFont, "name", RUBY_METHOD_FUNC(name), 0);
89
97
  rb_define_method(cFont, "size", RUBY_METHOD_FUNC(size), 0);
90
98
  rb_define_method(cFont, "width", RUBY_METHOD_FUNC(width), 1);
91
99
  rb_define_method(cFont, "height", RUBY_METHOD_FUNC(height), 0);
100
+ rb_define_method(cFont, "ascent", RUBY_METHOD_FUNC(ascent), 0);
101
+ rb_define_method(cFont, "descent", RUBY_METHOD_FUNC(descent), 0);
102
+ rb_define_method(cFont, "leading", RUBY_METHOD_FUNC(leading), 0);
92
103
  }
93
104
 
94
105
 
106
+ namespace Rucy
107
+ {
108
+
109
+
110
+ template <> Rays::Font
111
+ value_to<Rays::Font> (int argc, const Value* argv, bool convert)
112
+ {
113
+ if (argc == 1 && argv->is_array())
114
+ {
115
+ argc = argv->size();
116
+ argv = argv->as_array();
117
+ }
118
+
119
+ assert(argc == 0 || (argc > 0 && argv));
120
+
121
+ if (convert)
122
+ {
123
+ if (argc == 0)
124
+ return Rays::default_font();
125
+
126
+ coord size = argc >= 2 ? to<coord>(argv[1]) : 0;
127
+ if (argv->is_nil())
128
+ return Rays::Font(NULL, size);
129
+ else if (argv->is_s() || argv->is_sym())
130
+ return Rays::Font(argv[0].c_str(), size);
131
+ }
132
+
133
+ if (argc != 1)
134
+ argument_error(__FILE__, __LINE__);
135
+
136
+ return value_to<Rays::Font&>(*argv, convert);
137
+ }
138
+
139
+
140
+ }// Rucy
141
+
142
+
95
143
  namespace Rays
96
144
  {
97
145