rays 0.3.16 → 0.5.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (90) hide show
  1. checksums.yaml +4 -4
  2. data/.doc/ext/rays/bitmap.cpp +29 -9
  3. data/.doc/ext/rays/bounds.cpp +2 -5
  4. data/.doc/ext/rays/camera.cpp +15 -7
  5. data/.doc/ext/rays/color.cpp +2 -4
  6. data/.doc/ext/rays/color_space.cpp +13 -9
  7. data/.doc/ext/rays/font.cpp +117 -22
  8. data/.doc/ext/rays/image.cpp +31 -7
  9. data/.doc/ext/rays/matrix.cpp +2 -5
  10. data/.doc/ext/rays/painter.cpp +13 -5
  11. data/.doc/ext/rays/point.cpp +2 -5
  12. data/.doc/ext/rays/polygon.cpp +15 -7
  13. data/.doc/ext/rays/polyline.cpp +15 -10
  14. data/.doc/ext/rays/rays.cpp +10 -6
  15. data/.doc/ext/rays/shader.cpp +15 -7
  16. data/.github/workflows/release-gem.yml +2 -40
  17. data/.github/workflows/tag.yml +5 -28
  18. data/.github/workflows/test.yml +1 -28
  19. data/ChangeLog.md +31 -0
  20. data/Gemfile.lock +13 -8
  21. data/Rakefile +2 -2
  22. data/VERSION +1 -1
  23. data/ext/rays/bitmap.cpp +29 -9
  24. data/ext/rays/bounds.cpp +2 -5
  25. data/ext/rays/camera.cpp +16 -7
  26. data/ext/rays/color.cpp +2 -4
  27. data/ext/rays/color_space.cpp +13 -9
  28. data/ext/rays/defs.h +3 -3
  29. data/ext/rays/extconf.rb +6 -5
  30. data/ext/rays/font.cpp +121 -22
  31. data/ext/rays/image.cpp +31 -7
  32. data/ext/rays/matrix.cpp +2 -5
  33. data/ext/rays/painter.cpp +14 -5
  34. data/ext/rays/point.cpp +2 -5
  35. data/ext/rays/polygon.cpp +16 -7
  36. data/ext/rays/polyline.cpp +16 -10
  37. data/ext/rays/rays.cpp +10 -6
  38. data/ext/rays/shader.cpp +16 -7
  39. data/include/rays/bitmap.h +3 -1
  40. data/include/rays/color_space.h +6 -2
  41. data/include/rays/defs.h +14 -4
  42. data/include/rays/font.h +46 -4
  43. data/include/rays/image.h +11 -7
  44. data/include/rays/painter.h +3 -1
  45. data/include/rays/ruby/color_space.h +2 -0
  46. data/include/rays/shader.h +3 -0
  47. data/lib/rays/camera.rb +1 -1
  48. data/lib/rays/extension.rb +1 -1
  49. data/lib/rays/font.rb +4 -1
  50. data/lib/rays/image.rb +4 -2
  51. data/lib/rays/painter.rb +5 -5
  52. data/lib/rays/polygon.rb +1 -1
  53. data/lib/rays/polyline.rb +1 -1
  54. data/lib/rays/shader.rb +1 -1
  55. data/rays.gemspec +3 -3
  56. data/src/bitmap.cpp +107 -0
  57. data/src/color.cpp +17 -0
  58. data/src/color_space.cpp +5 -5
  59. data/src/font.cpp +121 -25
  60. data/src/font.h +7 -5
  61. data/src/image.cpp +104 -102
  62. data/src/ios/bitmap.mm +3 -3
  63. data/src/ios/font.mm +79 -26
  64. data/src/opengl/bitmap.cpp +1 -1
  65. data/src/opengl/color_space.cpp +15 -3
  66. data/src/opengl/color_space.h +1 -1
  67. data/src/opengl/painter.cpp +86 -18
  68. data/src/opengl/shader.cpp +15 -13
  69. data/src/opengl/texture.cpp +7 -7
  70. data/src/opengl/win32/opengl.cpp +17 -12
  71. data/src/osx/bitmap.mm +14 -3
  72. data/src/osx/font.mm +79 -26
  73. data/src/painter.cpp +12 -12
  74. data/src/painter.h +5 -1
  75. data/src/polygon.cpp +21 -21
  76. data/src/polyline.cpp +4 -4
  77. data/src/sdl/bitmap.cpp +43 -18
  78. data/src/sdl/font.cpp +56 -50
  79. data/src/texture.h +1 -1
  80. data/src/win32/bitmap.cpp +92 -45
  81. data/src/win32/font.cpp +43 -44
  82. data/src/win32/gdi.cpp +43 -46
  83. data/src/win32/gdi.h +6 -1
  84. data/src/win32/rays.cpp +18 -1
  85. data/test/test_bitmap.rb +28 -10
  86. data/test/test_font.rb +58 -0
  87. data/test/test_image.rb +29 -6
  88. data/test/test_painter.rb +39 -0
  89. metadata +8 -8
  90. data/.github/workflows/utils.rb +0 -127
data/ext/rays/painter.cpp CHANGED
@@ -2,6 +2,7 @@
2
2
 
3
3
 
4
4
  #include <vector>
5
+ #include "rays/exception.h"
5
6
  #include "rays/ruby/point.h"
6
7
  #include "rays/ruby/bounds.h"
7
8
  #include "rays/ruby/color.h"
@@ -16,7 +17,7 @@ RUCY_DEFINE_VALUE_FROM_TO(RAYS_EXPORT, Rays::Painter)
16
17
 
17
18
  #define THIS to<Rays::Painter*>(self)
18
19
 
19
- #define CHECK RUCY_CHECK_OBJECT(Rays::Painter, self)
20
+ #define CHECK RUCY_CHECK_OBJ(Rays::Painter, self)
20
21
 
21
22
 
22
23
  static
@@ -26,6 +27,13 @@ RUCY_DEF_ALLOC(alloc, klass)
26
27
  }
27
28
  RUCY_END
28
29
 
30
+ static
31
+ RUCY_DEF1(initialize_copy, obj)
32
+ {
33
+ Rays::rays_error(__FILE__, __LINE__, "can not duplicate Painter");
34
+ }
35
+ RUCY_END
36
+
29
37
  static
30
38
  RUCY_DEFN(canvas)
31
39
  {
@@ -164,7 +172,7 @@ RUCY_DEFN(point)
164
172
  std::vector<Rays::Point> points;
165
173
  get_points(&points, argc, argv);
166
174
 
167
- THIS->points(&points[0], points.size());
175
+ THIS->points(points.data(), points.size());
168
176
  return self;
169
177
  }
170
178
  RUCY_END
@@ -177,7 +185,7 @@ RUCY_DEF2(line, args, loop)
177
185
  std::vector<Rays::Point> points;
178
186
  get_points(&points, args.size(), args.as_array());
179
187
 
180
- THIS->line(&points[0], points.size(), loop);
188
+ THIS->line(points.data(), points.size(), loop);
181
189
  return self;
182
190
  }
183
191
  RUCY_END
@@ -239,7 +247,7 @@ RUCY_DEF2(curve, args, loop)
239
247
  std::vector<Rays::Point> points;
240
248
  get_points(&points, args.size(), args.as_array());
241
249
 
242
- THIS->curve(&points[0], points.size(), loop);
250
+ THIS->curve(points.data(), points.size(), loop);
243
251
  return self;
244
252
  }
245
253
  RUCY_END
@@ -255,7 +263,7 @@ RUCY_DEF2(bezier, args, loop)
255
263
  std::vector<Rays::Point> points;
256
264
  get_points(&points, args.size(), args.as_array());
257
265
 
258
- THIS->bezier(&points[0], points.size(), loop);
266
+ THIS->bezier(points.data(), points.size(), loop);
259
267
  return self;
260
268
  }
261
269
  RUCY_END
@@ -865,6 +873,7 @@ Init_rays_painter ()
865
873
 
866
874
  cPainter = mRays.define_class("Painter");
867
875
  cPainter.define_alloc_func(alloc);
876
+ cPainter.define_private_method("initialize_copy", initialize_copy);
868
877
 
869
878
  cPainter.define_method("canvas", canvas);
870
879
  cPainter.define_method("bounds", bounds);
data/ext/rays/point.cpp CHANGED
@@ -1,7 +1,6 @@
1
1
  #include "rays/ruby/point.h"
2
2
 
3
3
 
4
- #include <assert.h>
5
4
  #include "defs.h"
6
5
 
7
6
 
@@ -9,7 +8,7 @@ RUCY_DEFINE_VALUE_OR_ARRAY_FROM_TO(RAYS_EXPORT, Rays::Point)
9
8
 
10
9
  #define THIS to<Rays::Point*>(self)
11
10
 
12
- #define CHECK RUCY_CHECK_OBJ(Rays::Point, self)
11
+ #define CHECK RUCY_CHECK_PTR(Rays::Point, self)
13
12
 
14
13
 
15
14
  static
@@ -306,14 +305,12 @@ namespace Rucy
306
305
  template <> RAYS_EXPORT Rays::Point
307
306
  value_to<Rays::Point> (int argc, const Value* argv, bool convert)
308
307
  {
309
- if (argc == 1 && argv->is_array())
308
+ if (argc == 1 && argv && argv->is_array())
310
309
  {
311
310
  argc = argv->size();
312
311
  argv = argv->as_array();
313
312
  }
314
313
 
315
- assert(argc == 0 || (argc > 0 && argv));
316
-
317
314
  if (convert)
318
315
  {
319
316
  if (argc == 0)
data/ext/rays/polygon.cpp CHANGED
@@ -12,7 +12,7 @@ RUCY_DEFINE_VALUE_OR_ARRAY_FROM_TO(RAYS_EXPORT, Rays::Polygon)
12
12
 
13
13
  #define THIS to<Rays::Polygon*>(self)
14
14
 
15
- #define CHECK RUCY_CHECK_OBJECT(Rays::Polygon, self)
15
+ #define CHECK RUCY_CHECK_OBJ(Rays::Polygon, self)
16
16
 
17
17
 
18
18
  static
@@ -23,7 +23,7 @@ RUCY_DEF_ALLOC(alloc, klass)
23
23
  RUCY_END
24
24
 
25
25
  static
26
- RUCY_DEF4(setup, args, loop, colors, texcoords)
26
+ RUCY_DEF4(initialize, args, loop, colors, texcoords)
27
27
  {
28
28
  CHECK;
29
29
 
@@ -39,6 +39,14 @@ RUCY_DEF4(setup, args, loop, colors, texcoords)
39
39
  }
40
40
  RUCY_END
41
41
 
42
+ static
43
+ RUCY_DEF1(initialize_copy, obj)
44
+ {
45
+ CHECK;
46
+ *THIS = to<Rays::Polygon&>(obj);
47
+ }
48
+ RUCY_END
49
+
42
50
  static
43
51
  RUCY_DEFN(expand)
44
52
  {
@@ -105,7 +113,7 @@ RUCY_DEF0(each)
105
113
 
106
114
  Value ret = Qnil;
107
115
  for (const auto& polyline : *THIS)
108
- ret = rb_yield(value(polyline));
116
+ ret = yield(value(polyline));
109
117
  return ret;
110
118
  }
111
119
  RUCY_END
@@ -157,7 +165,7 @@ RUCY_DEF1(op_add, obj)
157
165
  });
158
166
  }
159
167
 
160
- return value(Rays::Polygon(&polylines[0], polylines.size()));
168
+ return value(Rays::Polygon(polylines.data(), polylines.size()));
161
169
  }
162
170
  RUCY_END
163
171
 
@@ -371,7 +379,8 @@ Init_rays_polygon ()
371
379
 
372
380
  cPolygon = mRays.define_class("Polygon");
373
381
  cPolygon.define_alloc_func(alloc);
374
- cPolygon.define_private_method("setup", setup);
382
+ cPolygon.define_private_method("initialize!", initialize);
383
+ cPolygon.define_private_method("initialize_copy", initialize_copy);
375
384
  cPolygon.define_method("expand", expand);
376
385
  cPolygon.define_method("bounds", bounds);
377
386
  cPolygon.define_method("size", size);
@@ -419,14 +428,14 @@ namespace Rucy
419
428
  polylines.reserve(argc);
420
429
  for (int i = 0; i < argc; ++i)
421
430
  polylines.emplace_back(to<Rays::Polyline&>(argv[i]));
422
- return Rays::Polygon(&polylines[0], polylines.size());
431
+ return Rays::Polygon(polylines.data(), polylines.size());
423
432
  }
424
433
  }
425
434
  else if (argv->is_num() || argv->is_array())
426
435
  {
427
436
  std::vector<Rays::Point> points;
428
437
  get_points(&points, argc, argv);
429
- return Rays::Polygon(&points[0], points.size());
438
+ return Rays::Polygon(points.data(), points.size());
430
439
  }
431
440
  }
432
441
 
@@ -1,7 +1,6 @@
1
1
  #include "rays/ruby/polyline.h"
2
2
 
3
3
 
4
- #include <assert.h>
5
4
  #include <vector>
6
5
  #include "rays/ruby/color.h"
7
6
  #include "rays/ruby/point.h"
@@ -14,7 +13,7 @@ RUCY_DEFINE_VALUE_OR_ARRAY_FROM_TO(RAYS_EXPORT, Rays::Polyline)
14
13
 
15
14
  #define THIS to<Rays::Polyline*>(self)
16
15
 
17
- #define CHECK RUCY_CHECK_OBJECT(Rays::Polyline, self)
16
+ #define CHECK RUCY_CHECK_OBJ(Rays::Polyline, self)
18
17
 
19
18
 
20
19
  static
@@ -25,7 +24,7 @@ RUCY_DEF_ALLOC(alloc, klass)
25
24
  RUCY_END
26
25
 
27
26
  static
28
- RUCY_DEF6(setup, points, loop, fill, colors, texcoords, hole)
27
+ RUCY_DEF6(initialize, points, loop, fill, colors, texcoords, hole)
29
28
  {
30
29
  CHECK;
31
30
 
@@ -37,6 +36,14 @@ RUCY_DEF6(setup, points, loop, fill, colors, texcoords, hole)
37
36
  }
38
37
  RUCY_END
39
38
 
39
+ static
40
+ RUCY_DEF1(initialize_copy, obj)
41
+ {
42
+ CHECK;
43
+ *THIS = to<Rays::Polyline&>(obj);
44
+ }
45
+ RUCY_END
46
+
40
47
  static
41
48
  RUCY_DEFN(expand)
42
49
  {
@@ -151,7 +158,7 @@ RUCY_DEF0(each_point)
151
158
 
152
159
  Value ret = Qnil;
153
160
  for (const auto& point : *THIS)
154
- ret = rb_yield(value(point));
161
+ ret = yield(value(point));
155
162
  return ret;
156
163
  }
157
164
  RUCY_END
@@ -168,7 +175,7 @@ RUCY_DEF0(each_color)
168
175
  {
169
176
  size_t size = THIS->size();
170
177
  for (size_t i = 0; i < size; ++i)
171
- ret = rb_yield(value(colors[i]));
178
+ ret = yield(value(colors[i]));
172
179
  }
173
180
  return ret;
174
181
  }
@@ -186,7 +193,7 @@ RUCY_DEF0(each_texcoord)
186
193
  {
187
194
  size_t size = THIS->size();
188
195
  for (size_t i = 0; i < size; ++i)
189
- ret = rb_yield(value(*(Rays::Point*) &texcoords[i]));
196
+ ret = yield(value(*(Rays::Point*) &texcoords[i]));
190
197
  }
191
198
  return ret;
192
199
  }
@@ -202,7 +209,8 @@ Init_rays_polyline ()
202
209
 
203
210
  cPolyline = mRays.define_class("Polyline");
204
211
  cPolyline.define_alloc_func(alloc);
205
- cPolyline.define_private_method("setup", setup);
212
+ cPolyline.define_private_method("initialize!", initialize);
213
+ cPolyline.define_private_method("initialize_copy", initialize_copy);
206
214
  cPolyline.define_method("expand", expand);
207
215
  cPolyline.define_method("bounds", bounds);
208
216
  cPolyline.define_method("loop?", is_loop);
@@ -227,8 +235,6 @@ namespace Rucy
227
235
  template <> RAYS_EXPORT Rays::Polyline
228
236
  value_to<Rays::Polyline> (int argc, const Value* argv, bool convert)
229
237
  {
230
- assert(argc == 0 || (argc > 0 && argv));
231
-
232
238
  if (convert)
233
239
  {
234
240
  if (argc <= 0)
@@ -237,7 +243,7 @@ namespace Rucy
237
243
  {
238
244
  std::vector<Rays::Point> points;
239
245
  get_points(&points, argc, argv);
240
- return Rays::Polyline(&points[0], points.size());
246
+ return Rays::Polyline(points.data(), points.size());
241
247
  }
242
248
  }
243
249
 
data/ext/rays/rays.cpp CHANGED
@@ -1,7 +1,6 @@
1
1
  #include "rays/ruby/rays.h"
2
2
 
3
3
 
4
- #include <assert.h>
5
4
  #include <vector>
6
5
  #include "defs.h"
7
6
 
@@ -115,7 +114,8 @@ namespace Rucy
115
114
  template <> RAYS_EXPORT Rays::CapType
116
115
  value_to<Rays::CapType> (int argc, const Value* argv, bool convert)
117
116
  {
118
- assert(argc > 0 && argv);
117
+ if (argc <= 0 || !argv)
118
+ argument_error(__FILE__, __LINE__);
119
119
 
120
120
  if (convert)
121
121
  {
@@ -148,7 +148,8 @@ namespace Rucy
148
148
  template <> RAYS_EXPORT Rays::JoinType
149
149
  value_to<Rays::JoinType> (int argc, const Value* argv, bool convert)
150
150
  {
151
- assert(argc > 0 && argv);
151
+ if (argc <= 0 || !argv)
152
+ argument_error(__FILE__, __LINE__);
152
153
 
153
154
  if (convert)
154
155
  {
@@ -181,7 +182,8 @@ namespace Rucy
181
182
  template <> RAYS_EXPORT Rays::BlendMode
182
183
  value_to<Rays::BlendMode> (int argc, const Value* argv, bool convert)
183
184
  {
184
- assert(argc > 0 && argv);
185
+ if (argc <= 0 || !argv)
186
+ argument_error(__FILE__, __LINE__);
185
187
 
186
188
  if (convert)
187
189
  {
@@ -214,7 +216,8 @@ namespace Rucy
214
216
  template <> RAYS_EXPORT Rays::TexCoordMode
215
217
  value_to<Rays::TexCoordMode> (int argc, const Value* argv, bool convert)
216
218
  {
217
- assert(argc > 0 && argv);
219
+ if (argc <= 0 || !argv)
220
+ argument_error(__FILE__, __LINE__);
218
221
 
219
222
  if (convert)
220
223
  {
@@ -247,7 +250,8 @@ namespace Rucy
247
250
  template <> RAYS_EXPORT Rays::TexCoordWrap
248
251
  value_to<Rays::TexCoordWrap> (int argc, const Value* argv, bool convert)
249
252
  {
250
- assert(argc > 0 && argv);
253
+ if (argc <= 0 || !argv)
254
+ argument_error(__FILE__, __LINE__);
251
255
 
252
256
  if (convert)
253
257
  {
data/ext/rays/shader.cpp CHANGED
@@ -1,7 +1,7 @@
1
1
  #include "rays/ruby/shader.h"
2
2
 
3
3
 
4
- #include <assert.h>
4
+ #include "rays/exception.h"
5
5
  #include "rays/ruby/image.h"
6
6
  #include "defs.h"
7
7
 
@@ -10,7 +10,7 @@ RUCY_DEFINE_VALUE_OR_ARRAY_FROM_TO(RAYS_EXPORT, Rays::Shader)
10
10
 
11
11
  #define THIS to<Rays::Shader*>(self)
12
12
 
13
- #define CHECK RUCY_CHECK_OBJECT(Rays::Shader, self)
13
+ #define CHECK RUCY_CHECK_OBJ(Rays::Shader, self)
14
14
 
15
15
 
16
16
  static
@@ -20,6 +20,13 @@ RUCY_DEF_ALLOC(alloc, klass)
20
20
  }
21
21
  RUCY_END
22
22
 
23
+ static
24
+ RUCY_DEF1(initialize_copy, obj)
25
+ {
26
+ Rays::rays_error(__FILE__, __LINE__, "can not duplicate Shader");
27
+ }
28
+ RUCY_END
29
+
23
30
  static const char*
24
31
  to_name (const Value& names, size_t index)
25
32
  {
@@ -82,11 +89,11 @@ make_env (const Value& names, const Value& ignore_no_uniform_location_error)
82
89
  }
83
90
 
84
91
  static
85
- RUCY_DEF4(setup,
92
+ RUCY_DEF4(initialize,
86
93
  fragment_shader_source, vertex_shader_source,
87
94
  builtin_variable_names, ignore_no_uniform_location_error)
88
95
  {
89
- RUCY_CHECK_OBJ(Rays::Shader, self);
96
+ RUCY_CHECK_PTR(Rays::Shader, self);
90
97
 
91
98
  if (fragment_shader_source.is_nil())
92
99
  argument_error(__FILE__, __LINE__);
@@ -185,7 +192,8 @@ Init_rays_shader ()
185
192
 
186
193
  cShader = mRays.define_class("Shader");
187
194
  cShader.define_alloc_func(alloc);
188
- cShader.define_private_method("setup", setup);
195
+ cShader.define_private_method("initialize!", initialize);
196
+ cShader.define_private_method("initialize_copy", initialize_copy);
189
197
  cShader.define_private_method("set_uniform", set_uniform);
190
198
  cShader.define_method( "vertex_shader_source", get_vertex_shader_source);
191
199
  cShader.define_method("fragment_shader_source", get_fragment_shader_source);
@@ -199,13 +207,14 @@ namespace Rucy
199
207
  template <> RAYS_EXPORT Rays::Shader
200
208
  value_to<Rays::Shader> (int argc, const Value* argv, bool convert)
201
209
  {
202
- if (argc == 1 && argv->is_array())
210
+ if (argc == 1 && argv && argv->is_array())
203
211
  {
204
212
  argc = argv->size();
205
213
  argv = argv->as_array();
206
214
  }
207
215
 
208
- assert(argc > 0 && argv);
216
+ if (argc <= 0 || !argv)
217
+ argument_error(__FILE__, __LINE__);
209
218
 
210
219
  if (convert)
211
220
  {
@@ -24,13 +24,15 @@ namespace Rays
24
24
  Bitmap ();
25
25
 
26
26
  Bitmap (
27
- int width, int height, const ColorSpace& cs = RGBA,
27
+ int width, int height, const ColorSpace& cs = DEFAULT_COLORSPACE,
28
28
  const void* pixels = NULL);
29
29
 
30
30
  ~Bitmap ();
31
31
 
32
32
  Bitmap dup () const;
33
33
 
34
+ Bitmap dup (bool premult) const;
35
+
34
36
  int width () const;
35
37
 
36
38
  int height () const;
@@ -14,7 +14,7 @@ namespace Rays
14
14
  enum ColorSpaceType
15
15
  {
16
16
 
17
- COLORSPACE_UNKNOWN = 0,
17
+ COLORSPACE_NONE = 0,
18
18
 
19
19
  GRAY_8, GRAY_16, GRAY_24, GRAY_32, GRAY_float,
20
20
 
@@ -40,7 +40,11 @@ namespace Rays
40
40
 
41
41
  BGRA = BGRA_8888, BGRX = BGRX_8888, ABGR = ABGR_8888, XBGR = XBGR_8888,
42
42
 
43
- DEFAULT_COLOR_SPACE = RGBA
43
+ #ifdef WIN32
44
+ DEFAULT_COLORSPACE = BGRA,
45
+ #else
46
+ DEFAULT_COLORSPACE = RGBA,
47
+ #endif
44
48
 
45
49
  };// ColorSpaceType
46
50
 
data/include/rays/defs.h CHANGED
@@ -22,14 +22,24 @@ namespace Rays
22
22
  {
23
23
 
24
24
 
25
- using namespace Xot::Types;
25
+ namespace Types
26
+ {
26
27
 
27
- using Xot::String;
28
28
 
29
- using Xot::StringList;
29
+ typedef float coord;
30
+
31
+
32
+ }// Types
33
+
30
34
 
35
+ using namespace Xot ::Types;
31
36
 
32
- typedef float coord;
37
+ using namespace Rays::Types;
38
+
39
+
40
+ using Xot::String;
41
+
42
+ using Xot::StringList;
33
43
 
34
44
 
35
45
  enum CapType
data/include/rays/font.h CHANGED
@@ -19,22 +19,64 @@ namespace Rays
19
19
 
20
20
  public:
21
21
 
22
- enum {DEFAULT_SIZE = 12};
22
+ enum
23
+ {
24
+
25
+ WEIGHT_MIN = 0,
26
+
27
+ WEIGHT_THIN = 100,
28
+
29
+ WEIGHT_EXTRALIGHT = 200,
30
+
31
+ WEIGHT_LIGHT = 300,
32
+
33
+ WEIGHT_NORMAL = 400,
34
+
35
+ WEIGHT_MEDIUM = 500,
36
+
37
+ WEIGHT_SEMIBOLD = 600,
38
+
39
+ WEIGHT_BOLD = 700,
40
+
41
+ WEIGHT_EXTRABOLD = 800,
42
+
43
+ WEIGHT_BLACK = 900,
44
+
45
+ WEIGHT_MAX = 1000,
46
+
47
+ DEFAULT_SIZE = 12,
48
+
49
+ DEFAULT_WEIGHT = WEIGHT_NORMAL,
50
+
51
+ };
23
52
 
24
53
  Font ();
25
54
 
26
- Font (const char* name, coord size = DEFAULT_SIZE, bool smooth = true);
55
+ Font (
56
+ const char* name,
57
+ coord size = DEFAULT_SIZE,
58
+ int weight = DEFAULT_WEIGHT,
59
+ bool italic = false,
60
+ bool smooth = true);
27
61
 
28
62
  ~Font ();
29
63
 
30
64
  Font dup () const;
31
65
 
32
- String name () const;
66
+ String name (bool resolved = false) const;
33
67
 
34
68
  void set_size (coord size);
35
69
 
36
70
  coord size () const;
37
71
 
72
+ void set_weight (int weight);
73
+
74
+ int weight () const;
75
+
76
+ void set_italic (bool italic);
77
+
78
+ bool italic () const;
79
+
38
80
  void set_smooth (bool smooth);
39
81
 
40
82
  bool smooth () const;
@@ -63,7 +105,7 @@ namespace Rays
63
105
 
64
106
  Font load_font (const char* path, coord size = Font::DEFAULT_SIZE);
65
107
 
66
- const Font& get_default_font ();
108
+ Font get_default_font ();
67
109
 
68
110
 
69
111
  }// Rays
data/include/rays/image.h CHANGED
@@ -26,7 +26,7 @@ namespace Rays
26
26
  Image ();
27
27
 
28
28
  Image (
29
- int width, int height, const ColorSpace& cs = DEFAULT_COLOR_SPACE,
29
+ int width, int height, const ColorSpace& cs = DEFAULT_COLORSPACE,
30
30
  float pixel_density = 1, bool smooth = false);
31
31
 
32
32
  Image (
@@ -65,20 +65,24 @@ namespace Rays
65
65
 
66
66
  friend bool operator != (const This& lhs, const This& rhs);
67
67
 
68
- struct Data
68
+ struct Loader
69
69
  {
70
- virtual ~Data ();
71
- virtual void preprocess (const Image* image) const;
70
+ virtual ~Loader ();
71
+ virtual bool load (Bitmap* bitmap) = 0;
72
72
  };
73
73
 
74
- Xot::PSharedImpl<Data> self;
74
+ Image (const Image& pixels, Loader* loader);
75
+
76
+ const Loader* loader () const;
75
77
 
76
- Image (Data* data);
78
+ struct Data;
79
+
80
+ Xot::PSharedImpl<Data> self;
77
81
 
78
82
  };// Image
79
83
 
80
84
 
81
- Image load_image (const char* path);
85
+ Image load_image (const char* path, float pixel_density = 1, bool smooth = false);
82
86
 
83
87
 
84
88
  }// Rays
@@ -267,7 +267,9 @@ namespace Rays
267
267
 
268
268
  const Bounds& clip () const;
269
269
 
270
- void set_font (const char* name, coord size = 0, bool smooth = true);
270
+ void set_font (
271
+ const char* name, coord size = 0,
272
+ int weight = -1, bool italic = false, bool smooth = true);
271
273
 
272
274
  void set_font (const Font& font);
273
275
 
@@ -11,6 +11,8 @@
11
11
 
12
12
  RUCY_DECLARE_VALUE_OR_ARRAY_FROM_TO(RAYS_EXPORT, Rays::ColorSpace)
13
13
 
14
+ RUCY_DECLARE_CONVERT_TO(RAYS_EXPORT, Rays::ColorSpaceType)
15
+
14
16
 
15
17
  namespace Rays
16
18
  {
@@ -20,6 +20,9 @@ namespace Rays
20
20
 
21
21
  class Shader
22
22
  {
23
+ // A fragment shader sees premultiplied alpha and must produce it too:
24
+ // samples from the texture uniform are premultiplied, and gl_FragColor
25
+ // is blended as premultiplied. The vertex color is straight.
23
26
 
24
27
  typedef Shader This;
25
28
 
data/lib/rays/camera.rb CHANGED
@@ -11,7 +11,7 @@ module Rays
11
11
  min_width = -1, min_height = -1,
12
12
  device_name: nil, resize: true, crop: true, &block)
13
13
 
14
- setup device_name, min_width, min_height, resize, crop
14
+ initialize! device_name, min_width, min_height, resize, crop
15
15
  Xot::BlockUtil.instance_eval_or_block_call self, &block if block
16
16
  end
17
17
 
@@ -6,7 +6,7 @@ module Rays
6
6
  module_function
7
7
 
8
8
  def name(downcase = false)
9
- super().split('::')[-2].then {|s|
9
+ super().split('::')[..-2].join.then {|s|
10
10
  downcase ? s.gsub(/([a-z])([A-Z])/) {"#{$1}-#{$2}"}.downcase : s
11
11
  }
12
12
  end
data/lib/rays/font.rb CHANGED
@@ -11,13 +11,16 @@ module Rays
11
11
  alias w width
12
12
  alias h height
13
13
 
14
+ alias italic? italic
15
+ alias smooth? smooth
16
+
14
17
  def <=>(o)
15
18
  ret = name <=> o.name; return ret if ret != 0
16
19
  size <=> o.size
17
20
  end
18
21
 
19
22
  def inspect()
20
- "#<Rays::Font name='#{name}', size=#{size}>"
23
+ "#<Rays::Font name='#{name}', size=#{size}, weight=#{weight}#{italic? ? ', italic' : ''}>"
21
24
  end
22
25
 
23
26
  end# Font
data/lib/rays/image.rb CHANGED
@@ -18,6 +18,8 @@ module Rays
18
18
  initialize! args, pixel_density, smooth
19
19
  end
20
20
 
21
+ alias smooth? smooth
22
+
21
23
  def paint(&block)
22
24
  painter.paint self, &block
23
25
  self
@@ -39,9 +41,9 @@ module Rays
39
41
  get_bitmap true
40
42
  end
41
43
 
42
- def self.load(path)
44
+ def self.load(path, pixel_density: 1, smooth: false)
43
45
  raise Errno::ENOENT, "no such file: '#{path}'" unless File.exist? path
44
- load! path
46
+ load! path, pixel_density, smooth
45
47
  end
46
48
 
47
49
  end# Image