rays 0.1.3 → 0.1.4

Sign up to get free protection for your applications and to get access to all the features.
Files changed (88) hide show
  1. data/.doc/ext/rays/bitmap.cpp +76 -53
  2. data/.doc/ext/rays/font.cpp +31 -27
  3. data/.doc/ext/rays/image.cpp +44 -37
  4. data/.doc/ext/rays/native.cpp +6 -0
  5. data/.doc/ext/rays/painter.cpp +276 -160
  6. data/.doc/ext/rays/rays.cpp +8 -9
  7. data/.doc/ext/rays/texture.cpp +50 -28
  8. data/.gitignore +14 -0
  9. data/Rakefile +5 -30
  10. data/VERSION +1 -1
  11. data/ext/rays/bitmap.cpp +77 -53
  12. data/ext/rays/bounds.cpp +426 -0
  13. data/ext/rays/color.cpp +199 -0
  14. data/ext/rays/defs.h +1 -18
  15. data/ext/rays/extconf.rb +10 -8
  16. data/ext/rays/font.cpp +31 -27
  17. data/ext/rays/image.cpp +44 -37
  18. data/ext/rays/matrix.cpp +154 -0
  19. data/ext/rays/native.cpp +6 -0
  20. data/ext/rays/painter.cpp +288 -163
  21. data/ext/rays/point.cpp +175 -0
  22. data/ext/rays/rays.cpp +8 -9
  23. data/ext/rays/texture.cpp +52 -28
  24. data/include/rays.h +1 -2
  25. data/include/rays/bitmap.h +5 -3
  26. data/include/rays/bounds.h +94 -0
  27. data/include/rays/color.h +53 -0
  28. data/include/rays/colorspace.h +2 -2
  29. data/include/rays/exception.h +1 -1
  30. data/include/rays/font.h +7 -3
  31. data/include/rays/image.h +6 -2
  32. data/include/rays/matrix.h +63 -0
  33. data/include/rays/opengl.h +1 -1
  34. data/include/rays/painter.h +138 -39
  35. data/include/rays/point.h +39 -0
  36. data/include/rays/ruby.h +3 -0
  37. data/include/rays/ruby/bitmap.h +5 -3
  38. data/include/rays/ruby/bounds.h +41 -0
  39. data/include/rays/ruby/color.h +41 -0
  40. data/include/rays/ruby/font.h +5 -3
  41. data/include/rays/ruby/image.h +5 -3
  42. data/include/rays/ruby/matrix.h +41 -0
  43. data/include/rays/ruby/painter.h +5 -3
  44. data/include/rays/ruby/point.h +41 -0
  45. data/include/rays/ruby/texture.h +5 -3
  46. data/include/rays/texture.h +6 -2
  47. data/lib/rays.rb +3 -0
  48. data/lib/rays/autoinit.rb +1 -1
  49. data/lib/rays/bitmap.rb +15 -1
  50. data/lib/rays/bounds.rb +138 -0
  51. data/lib/rays/color.rb +52 -0
  52. data/lib/rays/ext.rb +4 -0
  53. data/lib/rays/image.rb +1 -1
  54. data/lib/rays/module.rb +9 -2
  55. data/lib/rays/painter.rb +40 -41
  56. data/lib/rays/point.rb +82 -0
  57. data/lib/rays/texture.rb +1 -1
  58. data/rays.gemspec +16 -37
  59. data/src/bounds.cpp +234 -0
  60. data/src/cocoa/bitmap.mm +4 -4
  61. data/src/cocoa/font.mm +35 -30
  62. data/src/cocoa/rays.mm +2 -0
  63. data/src/color.cpp +77 -0
  64. data/src/colorspace.cpp +3 -3
  65. data/src/exception.cpp +3 -18
  66. data/src/image.cpp +9 -2
  67. data/src/matrix.cpp +103 -0
  68. data/src/painter.cpp +475 -224
  69. data/src/point.cpp +52 -0
  70. data/src/texture.cpp +14 -2
  71. data/src/win32/bitmap.cpp +2 -2
  72. data/src/win32/gdi.cpp +22 -13
  73. data/src/win32/gdi.h +7 -7
  74. data/test/helpers.rb +1 -5
  75. data/test/test_bitmap.rb +9 -0
  76. data/test/test_bounds.rb +246 -0
  77. data/test/test_color.rb +88 -0
  78. data/test/test_font.rb +28 -0
  79. data/test/test_image.rb +9 -0
  80. data/test/test_painter.rb +1 -3
  81. data/test/test_point.rb +121 -0
  82. data/test/test_rays.rb +2 -3
  83. data/test/test_texture.rb +1 -3
  84. metadata +146 -75
  85. data/include/rays/helpers.h +0 -37
  86. data/include/rays/transform.h +0 -35
  87. data/src/helpers.cpp +0 -22
  88. data/src/transform.cpp +0 -88
@@ -0,0 +1,53 @@
1
+ // -*- c++ -*-
2
+ #pragma once
3
+ #ifndef __RAYS_COLOR_H__
4
+ #define __RAYS_COLOR_H__
5
+
6
+
7
+ #include <xot/util.h>
8
+ #include <rays/defs.h>
9
+ #include <rays/point.h>
10
+
11
+
12
+ namespace Rays
13
+ {
14
+
15
+
16
+ struct Color
17
+ {
18
+
19
+ typedef Color This;
20
+
21
+ float red, green, blue, alpha;
22
+
23
+ Color (float value = 0, float alpha = 1);
24
+
25
+ Color (float red, float green, float blue, float alpha = 1);
26
+
27
+ Color dup () const;
28
+
29
+ Color& set (float value = 0, float alpha = 1);
30
+
31
+ Color& set (float red, float green, float blue, float alpha = 1);
32
+
33
+ bool get (float* red, float* green, float* blue, float* alpha = NULL) const;
34
+
35
+ float* array ();
36
+
37
+ const float* array () const;
38
+
39
+ operator bool () const;
40
+
41
+ bool operator ! () const;
42
+
43
+ static uchar float2uchar (float value) {return (uchar) Xot::clip(0.f, 255.f, value * 255);}
44
+
45
+ static float uchar2float (uchar value) {return value / 255.f;}
46
+
47
+ };// Color
48
+
49
+
50
+ }// Rays
51
+
52
+
53
+ #endif//EOH
@@ -1,7 +1,7 @@
1
1
  // -*- c++ -*-
2
2
  #pragma once
3
- #ifndef __RAYS_COLOR_H__
4
- #define __RAYS_COLOR_H__
3
+ #ifndef __RAYS_COLORSPACE_H__
4
+ #define __RAYS_COLORSPACE_H__
5
5
 
6
6
 
7
7
  #include <rays/defs.h>
@@ -32,7 +32,7 @@ namespace Rays
32
32
  };// RaysException
33
33
 
34
34
 
35
- void error (const char* format = NULL, ...);
35
+ void rays_error (const char* format = NULL, ...);
36
36
 
37
37
 
38
38
  }// Rays
data/include/rays/font.h CHANGED
@@ -4,8 +4,8 @@
4
4
  #define __RAYS_FONT_H__
5
5
 
6
6
 
7
+ #include <xot/pimpl.h>
7
8
  #include <rays/defs.h>
8
- #include <rays/helpers.h>
9
9
 
10
10
 
11
11
  namespace Rays
@@ -27,7 +27,11 @@ namespace Rays
27
27
 
28
28
  coord size () const;
29
29
 
30
- bool get_extent (coord* width, coord* height, const char* str) const;
30
+ bool get_width (coord* width, const char* str) const;
31
+
32
+ bool get_height (
33
+ coord* height,
34
+ coord* ascent = NULL, coord* descent = NULL, coord* leading = NULL) const;
31
35
 
32
36
  operator bool () const;
33
37
 
@@ -35,7 +39,7 @@ namespace Rays
35
39
 
36
40
  struct Data;
37
41
 
38
- Impl<Data> self;
42
+ Xot::PImpl<Data, true> self;
39
43
 
40
44
  };// Font
41
45
 
data/include/rays/image.h CHANGED
@@ -4,8 +4,8 @@
4
4
  #define __RAYS_IMAGE_H__
5
5
 
6
6
 
7
+ #include <xot/pimpl.h>
7
8
  #include <rays/colorspace.h>
8
- #include <rays/helpers.h>
9
9
 
10
10
 
11
11
  namespace Rays
@@ -20,6 +20,8 @@ namespace Rays
20
20
  class Image
21
21
  {
22
22
 
23
+ typedef Image This;
24
+
23
25
  public:
24
26
 
25
27
  Image ();
@@ -54,13 +56,15 @@ namespace Rays
54
56
 
55
57
  struct Data;
56
58
 
57
- Impl<Data> self;
59
+ Xot::PImpl<Data, true> self;
58
60
 
59
61
  };// Image
60
62
 
61
63
 
62
64
  bool load_image (Image* image, const char* path, bool alphatexture = false);
63
65
 
66
+ bool save_image (const Image& image, const char* path);
67
+
64
68
 
65
69
  }// Rays
66
70
 
@@ -0,0 +1,63 @@
1
+ // -*- c++ -*-
2
+ #pragma once
3
+ #ifndef __RAYS_MATRIX_H__
4
+ #define __RAYS_MATRIX_H__
5
+
6
+
7
+ #include <rays/defs.h>
8
+
9
+
10
+ namespace Rays
11
+ {
12
+
13
+
14
+ struct Matrix
15
+ {
16
+
17
+ float
18
+ a1, a2, a3, a4,
19
+ b1, b2, b3, b4,
20
+ c1, c2, c3, c4,
21
+ d1, d2, d3, d4;
22
+
23
+ Matrix (float value = 1);
24
+
25
+ Matrix (
26
+ float a1, float a2, float a3, float a4,
27
+ float b1, float b2, float b3, float b4,
28
+ float c1, float c2, float c3, float c4,
29
+ float d1, float d2, float d3, float d4);
30
+
31
+ Matrix (const float* elements, size_t size);
32
+
33
+ Matrix dup () const;
34
+
35
+ Matrix& set (float value = 1);
36
+
37
+ Matrix& set (
38
+ float a1, float a2, float a3, float a4,
39
+ float b1, float b2, float b3, float b4,
40
+ float c1, float c2, float c3, float c4,
41
+ float d1, float d2, float d3, float d4);
42
+
43
+ Matrix& set (const float* elements, size_t size);
44
+
45
+ float& at (int row, int column);
46
+
47
+ float at (int row, int column) const;
48
+
49
+ float* array ();
50
+
51
+ const float* array () const;
52
+
53
+ float& operator [] (int index);
54
+
55
+ float operator [] (int index) const;
56
+
57
+ };// Matrix
58
+
59
+
60
+ }// Rays
61
+
62
+
63
+ #endif//EOH
@@ -5,7 +5,7 @@
5
5
 
6
6
 
7
7
  #if defined(COCOA)
8
- #include <OpenGL/OpenGL.h>
8
+ #include <OpenGL/gl.h>
9
9
  #elif defined(WIN32)
10
10
  #include <GL/gl.h>
11
11
  #include <GL/glext.h>
@@ -4,10 +4,10 @@
4
4
  #define __RAYS_PAINTER_H__
5
5
 
6
6
 
7
+ #include <xot/pimpl.h>
7
8
  #include <rays/defs.h>
9
+ #include <rays/texture.h>
8
10
  #include <rays/opengl.h>
9
- #include <rays/font.h>
10
- #include <rays/helpers.h>
11
11
 
12
12
 
13
13
  namespace Rays
@@ -42,7 +42,15 @@ namespace Rays
42
42
  };// ShapeType
43
43
 
44
44
 
45
- class Texture;
45
+ class Point;
46
+
47
+ class Bounds;
48
+
49
+ class Color;
50
+
51
+ class Matrix;
52
+
53
+ class Font;
46
54
 
47
55
  class Image;
48
56
 
@@ -58,88 +66,172 @@ namespace Rays
58
66
 
59
67
  bool canvas (coord x, coord y, coord width, coord height);
60
68
 
61
- bool begin ();
69
+ bool canvas (coord x, coord y, coord z, coord width, coord height, coord depth);
62
70
 
63
- bool end ();
71
+ bool canvas (const Bounds& bounds);
64
72
 
65
- bool push_matrix ();
73
+ bool begin ();
66
74
 
67
- bool pop_matrix ();
75
+ bool end ();
68
76
 
69
77
  //
70
78
  // high level drawing methods
71
79
  //
72
80
  bool line (coord x1, coord y1, coord x2, coord y2);
73
81
 
82
+ bool line (const Point& p1, const Point& p2);
83
+
74
84
  bool rect (coord x, coord y, coord width, coord height);
75
85
 
86
+ bool rect (const Bounds& bounds);
87
+
88
+ bool ellipse (
89
+ coord x, coord y, coord width, coord height = 0,
90
+ coord radius_min = 0, uint nsegment = 0);
91
+
92
+ bool ellipse (
93
+ const Bounds& bounds,
94
+ coord radius_min = 0, uint nsegment = 0);
95
+
76
96
  bool ellipse (
77
- coord x, coord y, coord width, coord height = 0, coord radius_min = 0,
78
- uint nsegment = 0);
97
+ const Point& center, coord radius,
98
+ coord radius_min = 0, uint nsegment = 0);
79
99
 
80
100
  bool arc (
81
101
  coord x, coord y, coord width, coord height = 0,
82
- float angle_from = 0, float angle_to = 360, coord radius_min = 0,
83
- uint nsegment = 0);
102
+ float angle_from = 0, float angle_to = 360,
103
+ coord radius_min = 0, uint nsegment = 0);
104
+
105
+ bool arc (
106
+ const Bounds& bounds,
107
+ float angle_from = 0, float angle_to = 360,
108
+ coord radius_min = 0, uint nsegment = 0);
109
+
110
+ bool arc (
111
+ const Point& center, coord radius,
112
+ float angle_from = 0, float angle_to = 360,
113
+ coord radius_min = 0, uint nsegment = 0);
84
114
 
85
115
  bool image (
86
116
  const Image& image, coord x = 0, coord y = 0);
87
117
 
118
+ bool image (
119
+ const Image& image, const Point& position);
120
+
88
121
  bool image (
89
122
  const Image& image, coord x, coord y, coord width, coord height);
90
123
 
124
+ bool image (
125
+ const Image& image, const Bounds& bounds);
126
+
91
127
  bool image (
92
128
  const Image& image,
93
129
  coord src_x, coord src_y, coord src_width, coord src_height,
94
130
  coord dest_x, coord dest_y);
95
131
 
132
+ bool image (
133
+ const Image& image,
134
+ const Bounds& src_bounds, const Point& dest_position);
135
+
96
136
  bool image (
97
137
  const Image& image,
98
138
  coord src_x, coord src_y, coord src_width, coord src_height,
99
139
  coord dest_x, coord dest_y, coord dest_width, coord dest_height);
100
140
 
141
+ bool image (
142
+ const Image& image,
143
+ const Bounds& src_bounds, const Bounds& dest_bounds);
144
+
101
145
  bool text (
102
146
  const char* str, coord x = 0, coord y = 0,
103
- const Font& font = default_font());
147
+ const Font* font = NULL);
148
+
149
+ bool text (
150
+ const char* str, const Point& position,
151
+ const Font* font = NULL);
104
152
 
105
153
  bool text (
106
154
  const char* str, coord x, coord y, coord width, coord height,
107
- const Font& font = default_font());
155
+ const Font* font = NULL);
156
+
157
+ bool text (
158
+ const char* str, const Bounds& bounds,
159
+ const Font* font = NULL);
108
160
 
109
161
  bool clear ();
110
162
 
111
- bool get_clear (
112
- float* red, float* green = NULL, float* blue = NULL,
113
- float* alpha = NULL);
163
+ bool set_background (float red, float green, float blue, float alpha = 1);
114
164
 
115
- bool set_clear (
116
- float red, float green, float blue, float alpha = 1);
165
+ bool set_background (const Color& color);
117
166
 
118
- bool no_clear ();
167
+ bool no_background ();
119
168
 
120
- bool get_fill (
121
- float* red, float* green = NULL, float* blue = NULL,
122
- float* alpha = NULL);
169
+ const Color& background () const;
123
170
 
124
171
  bool set_fill (float red, float green, float blue, float alpha = 1);
125
172
 
126
- bool no_fill ();
173
+ bool set_fill (const Color& color);
174
+
175
+ bool no_fill ();
127
176
 
128
- bool get_stroke (
129
- float* red, float* green = NULL, float* blue = NULL,
130
- float* alpha = NULL);
177
+ const Color& fill () const;
131
178
 
132
179
  bool set_stroke (float red, float green, float blue, float alpha = 1);
133
180
 
134
- bool no_stroke ();
181
+ bool set_stroke (const Color& color);
135
182
 
136
- bool get_clip (
137
- coord* x, coord* y = NULL,
138
- coord* width = NULL, coord* height = NULL);
183
+ bool no_stroke ();
184
+
185
+ const Color& stroke () const;
139
186
 
140
187
  bool set_clip (coord x, coord y, coord width, coord height);
141
188
 
142
- bool no_clip ();
189
+ bool set_clip (const Bounds& bounds);
190
+
191
+ bool no_clip ();
192
+
193
+ const Bounds& clip () const;
194
+
195
+ bool set_font (const Font& font);
196
+
197
+ const Font& font () const;
198
+
199
+ bool push_attrs ();
200
+
201
+ bool pop_attrs ();
202
+
203
+ //
204
+ // transformation methods
205
+ //
206
+ bool translate (coord x, coord y, coord z = 0);
207
+
208
+ bool translate (const Point& value);
209
+
210
+ bool scale (coord x, coord y, coord z = 1);
211
+
212
+ bool scale (const Point& value);
213
+
214
+ bool rotate (float angle, coord x = 0, coord y = 0, coord z = 1);
215
+
216
+ bool rotate (float angle, const Point& center);
217
+
218
+ bool set_matrix (float value = 1);
219
+
220
+ bool set_matrix (
221
+ float a1, float a2, float a3, float a4,
222
+ float b1, float b2, float b3, float b4,
223
+ float c1, float c2, float c3, float c4,
224
+ float d1, float d2, float d3, float d4);
225
+
226
+ bool set_matrix (const float* elements);
227
+
228
+ bool set_matrix (const Matrix& matrix);
229
+
230
+ const Matrix& matrix () const;
231
+
232
+ bool push_matrix ();
233
+
234
+ bool pop_matrix ();
143
235
 
144
236
  //
145
237
  // low level drawing methods
@@ -148,19 +240,26 @@ namespace Rays
148
240
 
149
241
  bool end_shape ();
150
242
 
151
- bool color (float red, float green, float blue, float alpha = 1);
243
+ bool set_color (float red, float green, float blue, float alpha = 1);
244
+
245
+ bool set_color (const Color& color);
246
+
247
+ bool set_texture (const Texture& tex);
248
+
249
+ bool no_texture ();
250
+
251
+ bool add_vertex (coord x, coord y);
152
252
 
153
- bool texture (const Texture& tex);
253
+ bool add_vertex (coord x, coord y, coord z);
154
254
 
155
- bool no_texture ();
255
+ bool add_vertex (const Point& position);
156
256
 
157
- bool vertex (coord x, coord y);
257
+ bool add_vertex (coord x, coord y, coord tex_s, coord tex_t);
158
258
 
159
- bool vertex (coord x, coord y, coord z);
259
+ bool add_vertex (coord x, coord y, coord z, coord tex_s, coord tex_t);
160
260
 
161
- bool vertex (coord x, coord y, coord texture_s, coord texture_t);
261
+ bool add_vertex (const Point& position, coord tex_s, coord tex_t);
162
262
 
163
- bool vertex (coord x, coord y, coord z, coord texture_s, coord texture_t);
164
263
 
165
264
  operator bool () const;
166
265
 
@@ -168,7 +267,7 @@ namespace Rays
168
267
 
169
268
  struct Data;
170
269
 
171
- Impl<Data> self;
270
+ Xot::PImpl<Data, true> self;
172
271
 
173
272
  };// Painter
174
273