rays 0.1.1
Sign up to get free protection for your applications and to get access to all the features.
- data/ChangeLog +8 -0
- data/README +4 -0
- data/Rakefile +72 -0
- data/VERSION +1 -0
- data/ext/rays/bitmap.cpp +322 -0
- data/ext/rays/extconf.rb +61 -0
- data/ext/rays/font.cpp +125 -0
- data/ext/rays/image.cpp +166 -0
- data/ext/rays/native.cpp +24 -0
- data/ext/rays/painter.cpp +573 -0
- data/ext/rays/rays.cpp +61 -0
- data/ext/rays/rays.h +39 -0
- data/ext/rays/texture.cpp +130 -0
- data/include/rays.h +20 -0
- data/include/rays/bitmap.h +80 -0
- data/include/rays/colorspace.h +101 -0
- data/include/rays/defs.h +33 -0
- data/include/rays/font.h +49 -0
- data/include/rays/helpers.h +37 -0
- data/include/rays/image.h +68 -0
- data/include/rays/opengl.h +15 -0
- data/include/rays/painter.h +179 -0
- data/include/rays/rays.h +19 -0
- data/include/rays/ruby.h +15 -0
- data/include/rays/ruby/bitmap.h +39 -0
- data/include/rays/ruby/font.h +39 -0
- data/include/rays/ruby/image.h +39 -0
- data/include/rays/ruby/painter.h +39 -0
- data/include/rays/ruby/rays.h +21 -0
- data/include/rays/ruby/texture.h +39 -0
- data/include/rays/texture.h +56 -0
- data/include/rays/transform.h +35 -0
- data/lib/rays.rb +9 -0
- data/lib/rays/autoinit.rb +10 -0
- data/lib/rays/bitmap.rb +25 -0
- data/lib/rays/image.rb +15 -0
- data/lib/rays/module.rb +30 -0
- data/lib/rays/painter.rb +99 -0
- data/lib/rays/texture.rb +15 -0
- data/rays.gemspec +54 -0
- data/src/cocoa/bitmap.mm +286 -0
- data/src/cocoa/font.mm +193 -0
- data/src/cocoa/helpers.h +26 -0
- data/src/cocoa/helpers.mm +25 -0
- data/src/cocoa/rays.mm +40 -0
- data/src/colorspace.cpp +183 -0
- data/src/helpers.cpp +22 -0
- data/src/image.cpp +133 -0
- data/src/painter.cpp +769 -0
- data/src/texture.cpp +360 -0
- data/src/transform.cpp +88 -0
- data/src/win32/bitmap.cpp +212 -0
- data/src/win32/font.cpp +99 -0
- data/src/win32/gdi.cpp +771 -0
- data/src/win32/gdi.h +226 -0
- data/src/win32/rays.cpp +36 -0
- data/support.rb +58 -0
- data/task/ext.rake +41 -0
- data/task/gem.rake +33 -0
- data/task/git.rake +22 -0
- data/task/lib.rake +54 -0
- data/test/helpers.rb +15 -0
- data/test/test_painter.rb +11 -0
- data/test/test_rays.rb +19 -0
- data/test/test_texture.rb +11 -0
- metadata +153 -0
data/src/win32/gdi.h
ADDED
@@ -0,0 +1,226 @@
|
|
1
|
+
// -*- c++ -*-
|
2
|
+
#pragma once
|
3
|
+
#ifndef __RAYS_WIN32_GDI_H__
|
4
|
+
#define __RAYS_WIN32_GDI_H__
|
5
|
+
|
6
|
+
|
7
|
+
#include <windows.h>
|
8
|
+
#include <rays/defs.h>
|
9
|
+
#include <rays/helpers.h>
|
10
|
+
|
11
|
+
|
12
|
+
namespace Rays
|
13
|
+
{
|
14
|
+
|
15
|
+
|
16
|
+
namespace Win32
|
17
|
+
{
|
18
|
+
|
19
|
+
|
20
|
+
class Pen
|
21
|
+
{
|
22
|
+
|
23
|
+
public:
|
24
|
+
|
25
|
+
Pen (HPEN handle = NULL, bool owner = false);
|
26
|
+
|
27
|
+
Pen (int red, int green, int blue, int width = 1, int style = PS_SOLID);
|
28
|
+
|
29
|
+
~Pen ();
|
30
|
+
|
31
|
+
bool get_color (int* red, int* green, int* blue) const;
|
32
|
+
|
33
|
+
HPEN handle () const;
|
34
|
+
|
35
|
+
operator bool () const;
|
36
|
+
|
37
|
+
bool operator ! () const;
|
38
|
+
|
39
|
+
struct Data;
|
40
|
+
|
41
|
+
Impl<Data> self;
|
42
|
+
|
43
|
+
};// Pen
|
44
|
+
|
45
|
+
|
46
|
+
class Brush
|
47
|
+
{
|
48
|
+
|
49
|
+
public:
|
50
|
+
|
51
|
+
Brush (HBRUSH handle = NULL, bool owner = false);
|
52
|
+
|
53
|
+
Brush (int red, int green, int blue, int style = BS_SOLID);
|
54
|
+
|
55
|
+
~Brush ();
|
56
|
+
|
57
|
+
bool get_color (int* red, int* green, int* blue) const;
|
58
|
+
|
59
|
+
HBRUSH handle () const;
|
60
|
+
|
61
|
+
operator bool () const;
|
62
|
+
|
63
|
+
bool operator ! () const;
|
64
|
+
|
65
|
+
struct Data;
|
66
|
+
|
67
|
+
Impl<Data> self;
|
68
|
+
|
69
|
+
};// Brush
|
70
|
+
|
71
|
+
|
72
|
+
class Font
|
73
|
+
{
|
74
|
+
|
75
|
+
public:
|
76
|
+
|
77
|
+
Font (HFONT handle = NULL, bool owner = false);
|
78
|
+
|
79
|
+
Font (const char* name, coord size = 0);
|
80
|
+
|
81
|
+
~Font ();
|
82
|
+
|
83
|
+
String name () const;
|
84
|
+
|
85
|
+
coord size () const;
|
86
|
+
|
87
|
+
bool get_extent (
|
88
|
+
coord* width, coord* height, const char* str, HDC hdc = NULL);
|
89
|
+
|
90
|
+
HFONT handle () const;
|
91
|
+
|
92
|
+
operator bool () const;
|
93
|
+
|
94
|
+
bool operator ! () const;
|
95
|
+
|
96
|
+
struct Data;
|
97
|
+
|
98
|
+
Impl<Data> self;
|
99
|
+
|
100
|
+
};// Font
|
101
|
+
|
102
|
+
|
103
|
+
class Bitmap
|
104
|
+
{
|
105
|
+
|
106
|
+
public:
|
107
|
+
|
108
|
+
Bitmap (HBITMAP handle = NULL, bool owner = false);
|
109
|
+
|
110
|
+
Bitmap (HDC hdc, int width, int height);
|
111
|
+
|
112
|
+
~Bitmap ();
|
113
|
+
|
114
|
+
int width () const;
|
115
|
+
|
116
|
+
int height () const;
|
117
|
+
|
118
|
+
HBITMAP handle () const;
|
119
|
+
|
120
|
+
operator bool () const;
|
121
|
+
|
122
|
+
bool operator ! () const;
|
123
|
+
|
124
|
+
struct Data;
|
125
|
+
|
126
|
+
Impl<Data> self;
|
127
|
+
|
128
|
+
};// Bitmap
|
129
|
+
|
130
|
+
|
131
|
+
class DC
|
132
|
+
{
|
133
|
+
|
134
|
+
public:
|
135
|
+
|
136
|
+
enum DeleteType {DELETE_DC, RELEASE_DC};
|
137
|
+
|
138
|
+
DC (
|
139
|
+
HDC handle = NULL, bool owner = false,
|
140
|
+
DeleteType deltype = DELETE_DC);
|
141
|
+
|
142
|
+
~DC ();
|
143
|
+
|
144
|
+
Pen pen () const;
|
145
|
+
|
146
|
+
bool set_pen (const Pen& pen);
|
147
|
+
|
148
|
+
Brush brush () const;
|
149
|
+
|
150
|
+
bool set_brush (const Brush& brush);
|
151
|
+
|
152
|
+
Font font () const;
|
153
|
+
|
154
|
+
bool set_font (const Font& font);
|
155
|
+
|
156
|
+
Bitmap bitmap () const;
|
157
|
+
|
158
|
+
bool set_bitmap (const Bitmap& bitmap);
|
159
|
+
|
160
|
+
COLORREF text_color () const;
|
161
|
+
|
162
|
+
bool set_text_color (COLORREF color);
|
163
|
+
|
164
|
+
COLORREF back_color () const;
|
165
|
+
|
166
|
+
bool set_back_color (COLORREF color);
|
167
|
+
|
168
|
+
int back_mode () const;
|
169
|
+
|
170
|
+
bool set_back_mode (int mode);
|
171
|
+
|
172
|
+
bool push ();
|
173
|
+
|
174
|
+
bool pop ();
|
175
|
+
|
176
|
+
HDC handle () const;
|
177
|
+
|
178
|
+
operator bool () const;
|
179
|
+
|
180
|
+
bool operator ! () const;
|
181
|
+
|
182
|
+
struct Data;
|
183
|
+
|
184
|
+
Impl<Data> self;
|
185
|
+
|
186
|
+
};// DC
|
187
|
+
|
188
|
+
|
189
|
+
class MemoryDC : public DC
|
190
|
+
{
|
191
|
+
|
192
|
+
typedef DC Super;
|
193
|
+
|
194
|
+
public:
|
195
|
+
|
196
|
+
MemoryDC ();
|
197
|
+
|
198
|
+
MemoryDC (HDC hdc, int width, int height);
|
199
|
+
|
200
|
+
MemoryDC (HDC hdc, const Bitmap& bitmap);
|
201
|
+
|
202
|
+
~MemoryDC ();
|
203
|
+
|
204
|
+
const Bitmap& bitmap () const;
|
205
|
+
|
206
|
+
operator bool () const;
|
207
|
+
|
208
|
+
bool operator ! () const;
|
209
|
+
|
210
|
+
struct Data;
|
211
|
+
|
212
|
+
Impl<Data> self;
|
213
|
+
|
214
|
+
};// MemoryDC
|
215
|
+
|
216
|
+
|
217
|
+
DC screen_dc ();
|
218
|
+
|
219
|
+
|
220
|
+
}// Win32
|
221
|
+
|
222
|
+
|
223
|
+
}// Rays
|
224
|
+
|
225
|
+
|
226
|
+
#endif//EOH
|
data/src/win32/rays.cpp
ADDED
@@ -0,0 +1,36 @@
|
|
1
|
+
// -*- objc -*-
|
2
|
+
#include "rays/rays.h"
|
3
|
+
|
4
|
+
|
5
|
+
namespace Rays
|
6
|
+
{
|
7
|
+
|
8
|
+
|
9
|
+
namespace global
|
10
|
+
{
|
11
|
+
|
12
|
+
|
13
|
+
static bool initialized = false;
|
14
|
+
|
15
|
+
|
16
|
+
}// global
|
17
|
+
|
18
|
+
|
19
|
+
bool
|
20
|
+
init ()
|
21
|
+
{
|
22
|
+
if (global::initialized) return false;
|
23
|
+
global::initialized = true;
|
24
|
+
return true;
|
25
|
+
}
|
26
|
+
|
27
|
+
bool
|
28
|
+
fin ()
|
29
|
+
{
|
30
|
+
if (!global::initialized) return false;
|
31
|
+
global::initialized = false;
|
32
|
+
return true;
|
33
|
+
}
|
34
|
+
|
35
|
+
|
36
|
+
}// Rays
|
data/support.rb
ADDED
@@ -0,0 +1,58 @@
|
|
1
|
+
# -*- coding: utf-8 -*-
|
2
|
+
|
3
|
+
|
4
|
+
require 'erb'
|
5
|
+
require 'pp'
|
6
|
+
|
7
|
+
|
8
|
+
def version ()
|
9
|
+
open("VERSION") {|f| f.readline.chomp}
|
10
|
+
end
|
11
|
+
|
12
|
+
def glob (*patterns)
|
13
|
+
paths = []
|
14
|
+
patterns.each do |pattern|
|
15
|
+
paths.concat Dir.glob(pattern)
|
16
|
+
end
|
17
|
+
paths
|
18
|
+
end
|
19
|
+
|
20
|
+
def erb (str)
|
21
|
+
ERB.new(str, nil, "%").result binding
|
22
|
+
end
|
23
|
+
|
24
|
+
def compile (path, out)
|
25
|
+
open(path) do |input|
|
26
|
+
open(out, "w") do |output|
|
27
|
+
output.write erb(input.read)
|
28
|
+
end
|
29
|
+
end
|
30
|
+
#rescue
|
31
|
+
end
|
32
|
+
|
33
|
+
def convertions (paths, convs)
|
34
|
+
raise "empty conversion." if convs.empty?
|
35
|
+
paths = paths.map do |path|
|
36
|
+
convpath = path
|
37
|
+
convs.each do |from, to|
|
38
|
+
convpath = convpath.sub(/#{from.gsub('.', '\.')}$/, to)
|
39
|
+
end
|
40
|
+
[path, convpath]
|
41
|
+
end
|
42
|
+
Hash[*paths.flatten]
|
43
|
+
end
|
44
|
+
|
45
|
+
alias sh_original sh
|
46
|
+
|
47
|
+
def sh (*args)
|
48
|
+
sh_original *args
|
49
|
+
#rescue
|
50
|
+
end
|
51
|
+
|
52
|
+
def win32? ()
|
53
|
+
RUBY_PLATFORM =~ /mswin|ming|cygwin/
|
54
|
+
end
|
55
|
+
|
56
|
+
def cocoa? ()
|
57
|
+
RUBY_PLATFORM =~ /darwin/
|
58
|
+
end
|
data/task/ext.rake
ADDED
@@ -0,0 +1,41 @@
|
|
1
|
+
# -*- mode: ruby; coding: utf-8 -*-
|
2
|
+
|
3
|
+
|
4
|
+
require 'rucy/module'
|
5
|
+
|
6
|
+
|
7
|
+
namespace :ext do
|
8
|
+
|
9
|
+
dir = "#{EXTDIR}/#{NAME}"
|
10
|
+
name = "#{NAME}/native"
|
11
|
+
outname = "#{name}.#{EXTEXT}"
|
12
|
+
out = File.join EXTDIR, outname
|
13
|
+
|
14
|
+
extconf = File.join dir, "extconf.rb"
|
15
|
+
makefile = File.join dir, "Makefile"
|
16
|
+
depend = File.join dir, "depend"
|
17
|
+
|
18
|
+
cpps = Dir.glob("#{dir}/**/*.cpp")
|
19
|
+
|
20
|
+
task :build => makefile do
|
21
|
+
sh %( cd #{dir} && #{MAKE} )
|
22
|
+
end
|
23
|
+
|
24
|
+
task :clean do
|
25
|
+
sh %( cd #{dir} && #{MAKE} clean ) if File.exist? makefile
|
26
|
+
sh %( rm -f #{makefile} #{depend} )
|
27
|
+
end
|
28
|
+
|
29
|
+
file makefile => [extconf, depend] do
|
30
|
+
sh %( cd #{dir} && #{RUBY} #{File.basename extconf} )
|
31
|
+
end
|
32
|
+
|
33
|
+
file depend => ["lib:build"] + cpps do
|
34
|
+
incdirs = INCDIRS + Rucy.include_dirs
|
35
|
+
incdirs = incdirs.map{|s| " -I#{s}"}.join
|
36
|
+
srcs = cpps.map{|cpp| File.basename cpp}.join ' '
|
37
|
+
dep = File.basename depend
|
38
|
+
sh %( cd #{dir} && #{CC} -M #{CFLAGS} #{incdirs} #{srcs} > #{dep} )
|
39
|
+
end
|
40
|
+
|
41
|
+
end# :ext
|
data/task/gem.rake
ADDED
@@ -0,0 +1,33 @@
|
|
1
|
+
# -*- mode: ruby; coding: utf-8 -*-
|
2
|
+
|
3
|
+
|
4
|
+
namespace :gem do
|
5
|
+
|
6
|
+
name = NAME
|
7
|
+
|
8
|
+
gemspec = "#{name}.gemspec"
|
9
|
+
gem = "#{name}-#{version}.gem"
|
10
|
+
|
11
|
+
task :build => gem
|
12
|
+
|
13
|
+
task :install => gem do
|
14
|
+
sh %( #{GEM} install #{gem} )
|
15
|
+
end
|
16
|
+
|
17
|
+
task :uninstall do
|
18
|
+
sh %( #{GEM} uninstall #{name} )
|
19
|
+
end
|
20
|
+
|
21
|
+
task :clean do
|
22
|
+
sh %( rm -f #{gem} )
|
23
|
+
end
|
24
|
+
|
25
|
+
task :upload => gem do
|
26
|
+
sh %( #{GEM} push #{gem} )
|
27
|
+
end
|
28
|
+
|
29
|
+
file gem => "lib:build" do
|
30
|
+
sh %( #{GEM} build #{gemspec} )
|
31
|
+
end
|
32
|
+
|
33
|
+
end# :gem
|
data/task/git.rake
ADDED
@@ -0,0 +1,22 @@
|
|
1
|
+
# -*- mode: ruby; coding: utf-8 -*-
|
2
|
+
|
3
|
+
|
4
|
+
namespace :git do
|
5
|
+
|
6
|
+
task :status do
|
7
|
+
sh %( #{GIT} status )
|
8
|
+
end
|
9
|
+
|
10
|
+
task :diff do
|
11
|
+
sh %( #{GIT} diff | cat )
|
12
|
+
end
|
13
|
+
|
14
|
+
task :push do
|
15
|
+
sh %( #{GIT} push )
|
16
|
+
end
|
17
|
+
|
18
|
+
task :pull do
|
19
|
+
sh %( #{GIT} pull )
|
20
|
+
end
|
21
|
+
|
22
|
+
end# :git
|
data/task/lib.rake
ADDED
@@ -0,0 +1,54 @@
|
|
1
|
+
# -*- mode: ruby; coding: utf-8 -*-
|
2
|
+
|
3
|
+
|
4
|
+
require 'rake/loaders/makefile'
|
5
|
+
|
6
|
+
|
7
|
+
namespace :lib do
|
8
|
+
|
9
|
+
name = NAME
|
10
|
+
outname = "lib#{name}.a"
|
11
|
+
out = File.join LIBDIR, outname
|
12
|
+
|
13
|
+
headers = glob("include/**/*.h")
|
14
|
+
srcs = glob("src/**/*.cpp")
|
15
|
+
srcs += glob("src/**/*.mm") if cocoa?
|
16
|
+
srcs = srcs.reject {|s| s =~ %r(/win32/)} unless win32?
|
17
|
+
srcs = srcs.reject {|s| s =~ %r(/cocoa/)} unless cocoa?
|
18
|
+
|
19
|
+
depend = 'depend.mf'
|
20
|
+
objs = convertions srcs, {".cpp" => ".o", ".mm" => ".o"}
|
21
|
+
tmps = objs.values + [depend]
|
22
|
+
|
23
|
+
cflags = CFLAGS.dup
|
24
|
+
cflags << INCDIRS.map{|s| " -I#{s}"}.join
|
25
|
+
|
26
|
+
task :build => out
|
27
|
+
|
28
|
+
task :compile => objs.values
|
29
|
+
|
30
|
+
task :clean do
|
31
|
+
sh %( rm -rf #{tmps.join " "} #{out} )
|
32
|
+
end
|
33
|
+
|
34
|
+
file out => objs.values do
|
35
|
+
sh %( #{AR} #{ARFLAGS} #{out} #{objs.values.join " "} )
|
36
|
+
end
|
37
|
+
|
38
|
+
file depend do
|
39
|
+
sh %( #{CC} -M #{cflags} #{srcs.join ' '} > #{depend} )
|
40
|
+
input = open(depend) {|f| f.read}
|
41
|
+
open(depend, 'w') do |output|
|
42
|
+
output << input.gsub(/\w+\.o/, SRCDIR + '/\0')
|
43
|
+
end
|
44
|
+
end
|
45
|
+
|
46
|
+
import depend if File.exist? depend
|
47
|
+
|
48
|
+
objs.each do |(src, obj)|
|
49
|
+
file obj => [depend, src] do
|
50
|
+
sh %( #{CC} -c #{cflags} -o #{obj} #{src} )
|
51
|
+
end
|
52
|
+
end
|
53
|
+
|
54
|
+
end# :lib
|