rays 0.1.3 → 0.1.4
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.
- data/.doc/ext/rays/bitmap.cpp +76 -53
- data/.doc/ext/rays/font.cpp +31 -27
- data/.doc/ext/rays/image.cpp +44 -37
- data/.doc/ext/rays/native.cpp +6 -0
- data/.doc/ext/rays/painter.cpp +276 -160
- data/.doc/ext/rays/rays.cpp +8 -9
- data/.doc/ext/rays/texture.cpp +50 -28
- data/.gitignore +14 -0
- data/Rakefile +5 -30
- data/VERSION +1 -1
- data/ext/rays/bitmap.cpp +77 -53
- data/ext/rays/bounds.cpp +426 -0
- data/ext/rays/color.cpp +199 -0
- data/ext/rays/defs.h +1 -18
- data/ext/rays/extconf.rb +10 -8
- data/ext/rays/font.cpp +31 -27
- data/ext/rays/image.cpp +44 -37
- data/ext/rays/matrix.cpp +154 -0
- data/ext/rays/native.cpp +6 -0
- data/ext/rays/painter.cpp +288 -163
- data/ext/rays/point.cpp +175 -0
- data/ext/rays/rays.cpp +8 -9
- data/ext/rays/texture.cpp +52 -28
- data/include/rays.h +1 -2
- data/include/rays/bitmap.h +5 -3
- data/include/rays/bounds.h +94 -0
- data/include/rays/color.h +53 -0
- data/include/rays/colorspace.h +2 -2
- data/include/rays/exception.h +1 -1
- data/include/rays/font.h +7 -3
- data/include/rays/image.h +6 -2
- data/include/rays/matrix.h +63 -0
- data/include/rays/opengl.h +1 -1
- data/include/rays/painter.h +138 -39
- data/include/rays/point.h +39 -0
- data/include/rays/ruby.h +3 -0
- data/include/rays/ruby/bitmap.h +5 -3
- data/include/rays/ruby/bounds.h +41 -0
- data/include/rays/ruby/color.h +41 -0
- data/include/rays/ruby/font.h +5 -3
- data/include/rays/ruby/image.h +5 -3
- data/include/rays/ruby/matrix.h +41 -0
- data/include/rays/ruby/painter.h +5 -3
- data/include/rays/ruby/point.h +41 -0
- data/include/rays/ruby/texture.h +5 -3
- data/include/rays/texture.h +6 -2
- data/lib/rays.rb +3 -0
- data/lib/rays/autoinit.rb +1 -1
- data/lib/rays/bitmap.rb +15 -1
- data/lib/rays/bounds.rb +138 -0
- data/lib/rays/color.rb +52 -0
- data/lib/rays/ext.rb +4 -0
- data/lib/rays/image.rb +1 -1
- data/lib/rays/module.rb +9 -2
- data/lib/rays/painter.rb +40 -41
- data/lib/rays/point.rb +82 -0
- data/lib/rays/texture.rb +1 -1
- data/rays.gemspec +16 -37
- data/src/bounds.cpp +234 -0
- data/src/cocoa/bitmap.mm +4 -4
- data/src/cocoa/font.mm +35 -30
- data/src/cocoa/rays.mm +2 -0
- data/src/color.cpp +77 -0
- data/src/colorspace.cpp +3 -3
- data/src/exception.cpp +3 -18
- data/src/image.cpp +9 -2
- data/src/matrix.cpp +103 -0
- data/src/painter.cpp +475 -224
- data/src/point.cpp +52 -0
- data/src/texture.cpp +14 -2
- data/src/win32/bitmap.cpp +2 -2
- data/src/win32/gdi.cpp +22 -13
- data/src/win32/gdi.h +7 -7
- data/test/helpers.rb +1 -5
- data/test/test_bitmap.rb +9 -0
- data/test/test_bounds.rb +246 -0
- data/test/test_color.rb +88 -0
- data/test/test_font.rb +28 -0
- data/test/test_image.rb +9 -0
- data/test/test_painter.rb +1 -3
- data/test/test_point.rb +121 -0
- data/test/test_rays.rb +2 -3
- data/test/test_texture.rb +1 -3
- metadata +146 -75
- data/include/rays/helpers.h +0 -37
- data/include/rays/transform.h +0 -35
- data/src/helpers.cpp +0 -22
- data/src/transform.cpp +0 -88
data/ext/rays/point.cpp
ADDED
@@ -0,0 +1,175 @@
|
|
1
|
+
#include "rays/ruby/point.h"
|
2
|
+
|
3
|
+
|
4
|
+
#include <rucy.h>
|
5
|
+
#include "defs.h"
|
6
|
+
|
7
|
+
|
8
|
+
using namespace Rucy;
|
9
|
+
|
10
|
+
using Rays::coord;
|
11
|
+
|
12
|
+
|
13
|
+
static Class cPoint;
|
14
|
+
|
15
|
+
|
16
|
+
namespace Rays
|
17
|
+
{
|
18
|
+
|
19
|
+
|
20
|
+
Class
|
21
|
+
point_class ()
|
22
|
+
{
|
23
|
+
return cPoint;
|
24
|
+
}
|
25
|
+
|
26
|
+
|
27
|
+
}// Rays
|
28
|
+
|
29
|
+
|
30
|
+
namespace Rucy
|
31
|
+
{
|
32
|
+
|
33
|
+
|
34
|
+
Value
|
35
|
+
value (const Rays::Point& obj)
|
36
|
+
{
|
37
|
+
return new_type(cPoint, new Rays::Point(obj));
|
38
|
+
}
|
39
|
+
|
40
|
+
Value
|
41
|
+
value (const Rays::Point* obj)
|
42
|
+
{
|
43
|
+
return obj ? value(*obj) : nil();
|
44
|
+
}
|
45
|
+
|
46
|
+
|
47
|
+
}// Rucy
|
48
|
+
|
49
|
+
|
50
|
+
#define THIS to<Rays::Point*>(self)
|
51
|
+
|
52
|
+
#define CHECK RUCY_CHECK_OBJ(self, Rays::Point, cPoint)
|
53
|
+
|
54
|
+
|
55
|
+
static
|
56
|
+
RUBY_DEF_ALLOC(alloc, klass)
|
57
|
+
{
|
58
|
+
return new_type<Rays::Point>(klass);
|
59
|
+
}
|
60
|
+
RUBY_END
|
61
|
+
|
62
|
+
static
|
63
|
+
RUBY_DEFN(initialize)
|
64
|
+
{
|
65
|
+
RUCY_CHECK_OBJ(self, Rays::Point, cPoint);
|
66
|
+
|
67
|
+
if (argc != 0 && argc != 1 && argc != 2 && argc != 3)
|
68
|
+
arg_count_error("Point#initialize", argc, 0, 1, 2, 3);
|
69
|
+
|
70
|
+
if (argc == 0) return self;
|
71
|
+
|
72
|
+
switch (argc)
|
73
|
+
{
|
74
|
+
case 1:
|
75
|
+
*THIS = Rays::Point(to<coord>(argv[0]));
|
76
|
+
break;
|
77
|
+
|
78
|
+
case 2:
|
79
|
+
*THIS = Rays::Point(to<coord>(argv[0]), to<coord>(argv[1]));
|
80
|
+
break;
|
81
|
+
|
82
|
+
case 3:
|
83
|
+
*THIS = Rays::Point(
|
84
|
+
to<coord>(argv[0]), to<coord>(argv[1]), to<coord>(argv[2]));
|
85
|
+
break;
|
86
|
+
}
|
87
|
+
|
88
|
+
return self;
|
89
|
+
}
|
90
|
+
RUBY_END
|
91
|
+
|
92
|
+
static
|
93
|
+
RUBY_DEF1(initialize_copy, obj)
|
94
|
+
{
|
95
|
+
RUCY_CHECK_OBJ(self, Rays::Point, cPoint);
|
96
|
+
|
97
|
+
Rays::Point* point = to<Rays::Point*>(obj);
|
98
|
+
if (!point) argument_error();
|
99
|
+
|
100
|
+
*THIS = *point;
|
101
|
+
return self;
|
102
|
+
}
|
103
|
+
RUBY_END
|
104
|
+
|
105
|
+
static
|
106
|
+
RUBY_DEF1(set_x, x)
|
107
|
+
{
|
108
|
+
CHECK;
|
109
|
+
|
110
|
+
return value(THIS->x = to<coord>(x));
|
111
|
+
}
|
112
|
+
RUBY_END
|
113
|
+
|
114
|
+
static
|
115
|
+
RUBY_DEF0(get_x)
|
116
|
+
{
|
117
|
+
CHECK;
|
118
|
+
|
119
|
+
return value(THIS->x);
|
120
|
+
}
|
121
|
+
RUBY_END
|
122
|
+
|
123
|
+
static
|
124
|
+
RUBY_DEF1(set_y, y)
|
125
|
+
{
|
126
|
+
CHECK;
|
127
|
+
|
128
|
+
return value(THIS->y = to<coord>(y));
|
129
|
+
}
|
130
|
+
RUBY_END
|
131
|
+
|
132
|
+
static
|
133
|
+
RUBY_DEF0(get_y)
|
134
|
+
{
|
135
|
+
CHECK;
|
136
|
+
|
137
|
+
return value(THIS->y);
|
138
|
+
}
|
139
|
+
RUBY_END
|
140
|
+
|
141
|
+
static
|
142
|
+
RUBY_DEF1(set_z, z)
|
143
|
+
{
|
144
|
+
CHECK;
|
145
|
+
|
146
|
+
return value(THIS->z = to<coord>(z));
|
147
|
+
}
|
148
|
+
RUBY_END
|
149
|
+
|
150
|
+
static
|
151
|
+
RUBY_DEF0(get_z)
|
152
|
+
{
|
153
|
+
CHECK;
|
154
|
+
|
155
|
+
return value(THIS->z);
|
156
|
+
}
|
157
|
+
RUBY_END
|
158
|
+
|
159
|
+
|
160
|
+
void
|
161
|
+
Init_point ()
|
162
|
+
{
|
163
|
+
Module mRays = define_module("Rays");
|
164
|
+
|
165
|
+
cPoint = mRays.define_class("Point");
|
166
|
+
cPoint.define_alloc_func(alloc);
|
167
|
+
cPoint.define_private_method("initialize", initialize);
|
168
|
+
cPoint.define_private_method("initialize_copy", initialize_copy);
|
169
|
+
cPoint.define_method("x=", set_x);
|
170
|
+
cPoint.define_method("x", get_x);
|
171
|
+
cPoint.define_method("y=", set_y);
|
172
|
+
cPoint.define_method("y", get_y);
|
173
|
+
cPoint.define_method("z=", set_z);
|
174
|
+
cPoint.define_method("z", get_z);
|
175
|
+
}
|
data/ext/rays/rays.cpp
CHANGED
@@ -6,12 +6,13 @@
|
|
6
6
|
using namespace Rucy;
|
7
7
|
|
8
8
|
|
9
|
+
static Module mRays;
|
10
|
+
|
11
|
+
|
9
12
|
namespace Rays
|
10
13
|
{
|
11
14
|
|
12
15
|
|
13
|
-
static Module mRays;
|
14
|
-
|
15
16
|
Module
|
16
17
|
rays_module ()
|
17
18
|
{
|
@@ -26,7 +27,7 @@ static
|
|
26
27
|
RUBY_DEF0(init)
|
27
28
|
{
|
28
29
|
if (!Rays::init())
|
29
|
-
|
30
|
+
rays_error("Rays::init() failed.");
|
30
31
|
|
31
32
|
return self;
|
32
33
|
}
|
@@ -36,7 +37,7 @@ static
|
|
36
37
|
RUBY_DEF0(fin)
|
37
38
|
{
|
38
39
|
if (!Rays::fin())
|
39
|
-
|
40
|
+
rays_error("Rays::fin() failed.");
|
40
41
|
|
41
42
|
return self;
|
42
43
|
}
|
@@ -46,9 +47,7 @@ RUBY_END
|
|
46
47
|
void
|
47
48
|
Init_rays ()
|
48
49
|
{
|
49
|
-
|
50
|
-
|
51
|
-
|
52
|
-
m.define_singleton_method("init!", init);
|
53
|
-
m.define_singleton_method("fin!", fin);
|
50
|
+
mRays = define_module("Rays");
|
51
|
+
mRays.define_singleton_method("init!", init);
|
52
|
+
mRays.define_singleton_method("fin!", fin);
|
54
53
|
}
|
data/ext/rays/texture.cpp
CHANGED
@@ -11,12 +11,13 @@ using namespace Rucy;
|
|
11
11
|
using Rays::coord;
|
12
12
|
|
13
13
|
|
14
|
+
static Class cTexture;
|
15
|
+
|
16
|
+
|
14
17
|
namespace Rays
|
15
18
|
{
|
16
19
|
|
17
20
|
|
18
|
-
static Class cTexture;
|
19
|
-
|
20
21
|
Class
|
21
22
|
texture_class ()
|
22
23
|
{
|
@@ -32,33 +33,40 @@ namespace Rucy
|
|
32
33
|
|
33
34
|
|
34
35
|
Value
|
35
|
-
value (const Rays::Texture&
|
36
|
+
value (const Rays::Texture& obj)
|
36
37
|
{
|
37
|
-
return new_type
|
38
|
-
|
38
|
+
return new_type(cTexture, new Rays::Texture(obj));
|
39
|
+
}
|
40
|
+
|
41
|
+
Value
|
42
|
+
value (const Rays::Texture* obj)
|
43
|
+
{
|
44
|
+
return obj ? value(*obj) : nil();
|
39
45
|
}
|
40
46
|
|
41
47
|
|
42
48
|
}// Rucy
|
43
49
|
|
44
50
|
|
45
|
-
#define
|
51
|
+
#define THIS to<Rays::Texture*>(self)
|
46
52
|
|
47
|
-
#define CHECK
|
53
|
+
#define CHECK RUCY_CHECK_OBJECT(self, Rays::Texture, cTexture)
|
48
54
|
|
49
55
|
|
50
56
|
static
|
51
57
|
RUBY_DEF_ALLOC(alloc, klass)
|
52
58
|
{
|
53
|
-
return new_type<Rays::Texture>(klass
|
59
|
+
return new_type<Rays::Texture>(klass);
|
54
60
|
}
|
55
61
|
RUBY_END
|
56
62
|
|
57
63
|
static
|
58
64
|
RUBY_DEFN(initialize)
|
59
65
|
{
|
60
|
-
|
61
|
-
|
66
|
+
RUCY_CHECK_OBJ(self, Rays::Texture, cTexture);
|
67
|
+
|
68
|
+
if (argc != 1 && argc != 2)
|
69
|
+
arg_count_error("Texture#initialize", argc, 1, 2);
|
62
70
|
|
63
71
|
Rays::Bitmap* bitmap = to<Rays::Bitmap*>(argv[0]);
|
64
72
|
bool alphaonly = (argc == 2) ? to<bool>(argv[1]) : false;
|
@@ -66,7 +74,7 @@ RUBY_DEFN(initialize)
|
|
66
74
|
if (!bitmap)
|
67
75
|
argument_error("%s is not a Bitmap object.", argv[0].inspect().c_str());
|
68
76
|
|
69
|
-
*
|
77
|
+
*THIS = Rays::Texture(*bitmap, alphaonly);
|
70
78
|
return self;
|
71
79
|
}
|
72
80
|
RUBY_END
|
@@ -76,7 +84,7 @@ RUBY_DEF0(width)
|
|
76
84
|
{
|
77
85
|
CHECK;
|
78
86
|
|
79
|
-
return value(
|
87
|
+
return value(THIS->width());
|
80
88
|
}
|
81
89
|
RUBY_END
|
82
90
|
|
@@ -85,7 +93,25 @@ RUBY_DEF0(height)
|
|
85
93
|
{
|
86
94
|
CHECK;
|
87
95
|
|
88
|
-
return value(
|
96
|
+
return value(THIS->height());
|
97
|
+
}
|
98
|
+
RUBY_END
|
99
|
+
|
100
|
+
static
|
101
|
+
RUBY_DEF1(s, x)
|
102
|
+
{
|
103
|
+
CHECK;
|
104
|
+
|
105
|
+
return value(THIS->s(x.as_f(true)));
|
106
|
+
}
|
107
|
+
RUBY_END
|
108
|
+
|
109
|
+
static
|
110
|
+
RUBY_DEF1(t, y)
|
111
|
+
{
|
112
|
+
CHECK;
|
113
|
+
|
114
|
+
return value(THIS->t(y.as_f(true)));
|
89
115
|
}
|
90
116
|
RUBY_END
|
91
117
|
|
@@ -94,7 +120,7 @@ RUBY_DEF0(s_max)
|
|
94
120
|
{
|
95
121
|
CHECK;
|
96
122
|
|
97
|
-
return value(
|
123
|
+
return value(THIS->s_max());
|
98
124
|
}
|
99
125
|
RUBY_END
|
100
126
|
|
@@ -103,7 +129,7 @@ RUBY_DEF0(t_max)
|
|
103
129
|
{
|
104
130
|
CHECK;
|
105
131
|
|
106
|
-
return value(
|
132
|
+
return value(THIS->t_max());
|
107
133
|
}
|
108
134
|
RUBY_END
|
109
135
|
|
@@ -112,7 +138,7 @@ RUBY_DEF0(bitmap)
|
|
112
138
|
{
|
113
139
|
CHECK;
|
114
140
|
|
115
|
-
return value(
|
141
|
+
return value(THIS->bitmap());
|
116
142
|
}
|
117
143
|
RUBY_END
|
118
144
|
|
@@ -120,16 +146,14 @@ RUBY_END
|
|
120
146
|
void
|
121
147
|
Init_texture ()
|
122
148
|
{
|
123
|
-
Module
|
124
|
-
|
125
|
-
|
126
|
-
|
127
|
-
|
128
|
-
|
129
|
-
|
130
|
-
|
131
|
-
|
132
|
-
|
133
|
-
c.define_method("t_max", t_max);
|
134
|
-
c.define_method("bitmap", bitmap);
|
149
|
+
Module mRays = define_module("Rays");
|
150
|
+
|
151
|
+
cTexture = mRays.define_class("Texture");
|
152
|
+
cTexture.define_alloc_func(alloc);
|
153
|
+
cTexture.define_private_method("initialize", initialize);
|
154
|
+
cTexture.define_method("width", width);
|
155
|
+
cTexture.define_method("height", height);
|
156
|
+
cTexture.define_method("s_max", s_max);
|
157
|
+
cTexture.define_method("t_max", t_max);
|
158
|
+
cTexture.define_method("bitmap", bitmap);
|
135
159
|
}
|
data/include/rays.h
CHANGED
@@ -7,15 +7,14 @@
|
|
7
7
|
#include <rays/defs.h>
|
8
8
|
#include <rays/rays.h>
|
9
9
|
#include <rays/exception.h>
|
10
|
+
#include <rays/point.h>
|
10
11
|
#include <rays/colorspace.h>
|
11
12
|
#include <rays/bitmap.h>
|
12
13
|
#include <rays/texture.h>
|
13
14
|
#include <rays/image.h>
|
14
15
|
#include <rays/font.h>
|
15
|
-
#include <rays/transform.h>
|
16
16
|
#include <rays/painter.h>
|
17
17
|
#include <rays/opengl.h>
|
18
|
-
#include <rays/helpers.h>
|
19
18
|
|
20
19
|
|
21
20
|
#endif//EOH
|
data/include/rays/bitmap.h
CHANGED
@@ -4,10 +4,10 @@
|
|
4
4
|
#define __RAYS_BITMAP_H__
|
5
5
|
|
6
6
|
|
7
|
+
#include <xot/pimpl.h>
|
7
8
|
#include <rays/defs.h>
|
8
9
|
#include <rays/colorspace.h>
|
9
10
|
#include <rays/font.h>
|
10
|
-
#include <rays/helpers.h>
|
11
11
|
|
12
12
|
|
13
13
|
namespace Rays
|
@@ -17,6 +17,8 @@ namespace Rays
|
|
17
17
|
class Bitmap
|
18
18
|
{
|
19
19
|
|
20
|
+
typedef Bitmap This;
|
21
|
+
|
20
22
|
public:
|
21
23
|
|
22
24
|
Bitmap ();
|
@@ -50,7 +52,7 @@ namespace Rays
|
|
50
52
|
|
51
53
|
template <typename T> const T* at (int x, int y) const
|
52
54
|
{
|
53
|
-
return const_cast<
|
55
|
+
return const_cast<This*>(this)->at<T>(x, y);
|
54
56
|
}
|
55
57
|
|
56
58
|
operator bool () const;
|
@@ -59,7 +61,7 @@ namespace Rays
|
|
59
61
|
|
60
62
|
struct Data;
|
61
63
|
|
62
|
-
|
64
|
+
Xot::PImpl<Data, true> self;
|
63
65
|
|
64
66
|
};// Bitmap
|
65
67
|
|
@@ -0,0 +1,94 @@
|
|
1
|
+
// -*- c++ -*-
|
2
|
+
#pragma once
|
3
|
+
#ifndef __RAYS_BOUNDS_H__
|
4
|
+
#define __RAYS_BOUNDS_H__
|
5
|
+
|
6
|
+
|
7
|
+
#include <rays/defs.h>
|
8
|
+
#include <rays/point.h>
|
9
|
+
|
10
|
+
|
11
|
+
namespace Rays
|
12
|
+
{
|
13
|
+
|
14
|
+
|
15
|
+
struct Bounds
|
16
|
+
{
|
17
|
+
|
18
|
+
typedef Bounds This;
|
19
|
+
|
20
|
+
coord x, y, z, width, height, depth;
|
21
|
+
|
22
|
+
Bounds (coord size = 0);
|
23
|
+
|
24
|
+
Bounds ( coord width, coord height, coord depth = 0);
|
25
|
+
|
26
|
+
Bounds (coord x, coord y, coord width, coord height);
|
27
|
+
|
28
|
+
Bounds (coord x, coord y, coord z, coord width, coord height, coord depth);
|
29
|
+
|
30
|
+
Bounds dup () const;
|
31
|
+
|
32
|
+
Bounds& set (coord size = 0);
|
33
|
+
|
34
|
+
Bounds& set ( coord width, coord height, coord depth = 0);
|
35
|
+
|
36
|
+
Bounds& set (coord x, coord y, coord width, coord height);
|
37
|
+
|
38
|
+
Bounds& set (coord x, coord y, coord z, coord width, coord height, coord depth);
|
39
|
+
|
40
|
+
bool get (coord* x, coord* y, coord* width, coord* height) const;
|
41
|
+
|
42
|
+
bool get (coord* x, coord* y, coord* z, coord* width, coord* height, coord* depth) const;
|
43
|
+
|
44
|
+
void set_left (coord left);
|
45
|
+
|
46
|
+
coord left () const;
|
47
|
+
|
48
|
+
void set_right (coord right);
|
49
|
+
|
50
|
+
coord right () const;
|
51
|
+
|
52
|
+
void set_top (coord top);
|
53
|
+
|
54
|
+
coord top () const;
|
55
|
+
|
56
|
+
void set_bottom (coord bottom);
|
57
|
+
|
58
|
+
coord bottom () const;
|
59
|
+
|
60
|
+
void set_back (coord back);
|
61
|
+
|
62
|
+
coord back () const;
|
63
|
+
|
64
|
+
void set_front (coord front);
|
65
|
+
|
66
|
+
coord front () const;
|
67
|
+
|
68
|
+
Point& position ();
|
69
|
+
|
70
|
+
const Point& position () const;
|
71
|
+
|
72
|
+
Point& size ();
|
73
|
+
|
74
|
+
const Point& size () const;
|
75
|
+
|
76
|
+
coord* array ();
|
77
|
+
|
78
|
+
const coord* array () const;
|
79
|
+
|
80
|
+
operator bool () const;
|
81
|
+
|
82
|
+
bool operator ! () const;
|
83
|
+
|
84
|
+
friend bool operator == (const Bounds& lhs, const Bounds& rhs);
|
85
|
+
|
86
|
+
friend bool operator != (const Bounds& lhs, const Bounds& rhs);
|
87
|
+
|
88
|
+
};// Bounds
|
89
|
+
|
90
|
+
|
91
|
+
}// Rays
|
92
|
+
|
93
|
+
|
94
|
+
#endif//EOH
|