rays 0.1.6 → 0.1.7
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- data/.doc/ext/rays/bitmap.cpp +70 -233
- data/.doc/ext/rays/bounds.cpp +339 -57
- data/.doc/ext/rays/color.cpp +58 -48
- data/.doc/ext/rays/color_space.cpp +174 -0
- data/.doc/ext/rays/font.cpp +31 -53
- data/.doc/ext/rays/image.cpp +64 -67
- data/.doc/ext/rays/matrix.cpp +22 -50
- data/.doc/ext/rays/native.cpp +9 -2
- data/.doc/ext/rays/painter.cpp +276 -259
- data/.doc/ext/rays/point.cpp +186 -52
- data/.doc/ext/rays/rays.cpp +25 -20
- data/.doc/ext/rays/shader.cpp +61 -0
- data/.doc/ext/rays/texture.cpp +47 -59
- data/{README → README.md} +0 -0
- data/Rakefile +6 -5
- data/VERSION +1 -1
- data/ext/rays/bitmap.cpp +88 -248
- data/ext/rays/bounds.cpp +437 -141
- data/ext/rays/color.cpp +79 -69
- data/ext/rays/color_space.cpp +185 -0
- data/ext/rays/extconf.rb +14 -63
- data/ext/rays/font.cpp +44 -65
- data/ext/rays/image.cpp +82 -81
- data/ext/rays/matrix.cpp +32 -60
- data/ext/rays/native.cpp +9 -2
- data/ext/rays/painter.cpp +345 -321
- data/ext/rays/point.cpp +212 -69
- data/ext/rays/rays.cpp +29 -23
- data/ext/rays/shader.cpp +63 -0
- data/ext/rays/texture.cpp +64 -74
- data/include/rays/bitmap.h +21 -12
- data/include/rays/bounds.h +67 -9
- data/include/rays/color.h +23 -7
- data/include/rays/{colorspace.h → color_space.h} +6 -3
- data/include/rays/exception.h +17 -11
- data/include/rays/font.h +4 -3
- data/include/rays/image.h +11 -6
- data/include/rays/matrix.h +15 -12
- data/include/rays/opengl.h +54 -1
- data/include/rays/painter.h +98 -108
- data/include/rays/point.h +45 -5
- data/include/rays/rays.h +2 -2
- data/include/rays/ruby/bitmap.h +2 -16
- data/include/rays/ruby/bounds.h +4 -16
- data/include/rays/ruby/color.h +3 -16
- data/include/rays/ruby/color_space.h +27 -0
- data/include/rays/ruby/font.h +2 -16
- data/include/rays/ruby/image.h +2 -16
- data/include/rays/ruby/matrix.h +2 -16
- data/include/rays/ruby/painter.h +2 -16
- data/include/rays/ruby/point.h +3 -16
- data/include/rays/ruby/shader.h +27 -0
- data/include/rays/ruby/texture.h +2 -16
- data/include/rays/ruby.h +1 -0
- data/include/rays/shader.h +48 -0
- data/include/rays/texture.h +13 -2
- data/include/rays.h +2 -1
- data/lib/rays/bitmap.rb +20 -11
- data/lib/rays/bounds.rb +29 -68
- data/lib/rays/color.rb +39 -0
- data/lib/rays/color_space.rb +33 -0
- data/lib/rays/font.rb +29 -0
- data/lib/rays/image.rb +22 -0
- data/lib/rays/module.rb +11 -7
- data/lib/rays/painter.rb +103 -40
- data/lib/rays/point.rb +19 -36
- data/lib/rays/shader.rb +13 -0
- data/lib/rays/texture.rb +9 -0
- data/lib/rays.rb +4 -0
- data/rays.gemspec +3 -4
- data/src/bounds.cpp +272 -63
- data/src/color.cpp +168 -21
- data/src/{colorspace.cpp → color_space.cpp} +38 -1
- data/src/exception.cpp +24 -15
- data/src/frame_buffer.cpp +275 -0
- data/src/frame_buffer.h +79 -0
- data/src/image.cpp +80 -36
- data/src/ios/bitmap.mm +340 -0
- data/src/ios/font.mm +206 -0
- data/src/{cocoa → ios}/helper.h +2 -2
- data/src/{cocoa → ios}/helper.mm +0 -0
- data/src/ios/opengl.mm +21 -0
- data/src/ios/program.cpp +122 -0
- data/src/{cocoa → ios}/rays.mm +8 -7
- data/src/matrix.cpp +10 -22
- data/src/opengl.cpp +64 -0
- data/src/{cocoa → osx}/bitmap.mm +121 -70
- data/src/{cocoa → osx}/font.mm +32 -24
- data/src/osx/helper.h +26 -0
- data/src/osx/helper.mm +25 -0
- data/src/osx/opengl.mm +103 -0
- data/src/osx/rays.mm +43 -0
- data/src/painter.cpp +596 -422
- data/src/point.cpp +154 -11
- data/src/program.cpp +513 -0
- data/src/program.h +73 -0
- data/src/render_buffer.cpp +120 -0
- data/src/render_buffer.h +47 -0
- data/src/shader.cpp +117 -0
- data/src/texture.cpp +104 -134
- data/test/helper.rb +10 -3
- data/test/test_bitmap.rb +18 -0
- data/test/test_bounds.rb +81 -35
- data/test/test_color.rb +29 -2
- data/test/test_image.rb +63 -0
- data/test/test_painter.rb +120 -0
- data/test/test_point.rb +30 -9
- data/test/test_shader.rb +37 -0
- data/test/test_texture.rb +18 -0
- metadata +75 -58
- data/.gitignore +0 -14
- data/ChangeLog +0 -8
data/lib/rays/painter.rb
CHANGED
@@ -3,6 +3,7 @@
|
|
3
3
|
|
4
4
|
require 'xot/block_util'
|
5
5
|
require 'rays/ext'
|
6
|
+
require 'rays/color'
|
6
7
|
|
7
8
|
|
8
9
|
module Rays
|
@@ -10,85 +11,147 @@ module Rays
|
|
10
11
|
|
11
12
|
class Painter
|
12
13
|
|
13
|
-
|
14
|
-
|
15
|
-
def begin (&block)
|
16
|
-
if block
|
17
|
-
begin_paint
|
18
|
-
Xot::BlockUtil.instance_eval_or_block_call self, &block
|
19
|
-
end_paint
|
20
|
-
else
|
21
|
-
begin_paint
|
22
|
-
end
|
23
|
-
end
|
24
|
-
|
25
|
-
def background (*args)
|
26
|
-
send :background=, *args unless args.empty?
|
27
|
-
get_background
|
14
|
+
def background (*args, &block)
|
15
|
+
set_or_get :background=, :get_background, args, block
|
28
16
|
end
|
29
17
|
|
30
18
|
def background= (*args)
|
31
|
-
send_set :set_background, :no_background, args
|
19
|
+
send_set :set_background, :get_background, :no_background, args, :color
|
32
20
|
end
|
33
21
|
|
34
|
-
def fill (*args)
|
35
|
-
|
36
|
-
get_fill
|
22
|
+
def fill (*args, &block)
|
23
|
+
set_or_get :fill=, :get_fill, args, block
|
37
24
|
end
|
38
25
|
|
39
26
|
def fill= (*args)
|
40
|
-
send_set :set_fill, :no_fill, args
|
27
|
+
send_set :set_fill, :get_fill, :no_fill, args, :color
|
41
28
|
end
|
42
29
|
|
43
|
-
def stroke (*args)
|
44
|
-
|
45
|
-
get_stroke
|
30
|
+
def stroke (*args, &block)
|
31
|
+
set_or_get :stroke=, :get_stroke, args, block
|
46
32
|
end
|
47
33
|
|
48
34
|
def stroke= (*args)
|
49
|
-
send_set :set_stroke, :no_stroke, args
|
35
|
+
send_set :set_stroke, :get_stroke, :no_stroke, args, :color
|
50
36
|
end
|
51
37
|
|
52
|
-
def clip (*args)
|
53
|
-
|
54
|
-
get_clip
|
38
|
+
def clip (*args, &block)
|
39
|
+
set_or_get :clip=, :get_clip, args, block
|
55
40
|
end
|
56
41
|
|
57
42
|
def clip= (*args)
|
58
|
-
send_set :set_clip, :no_clip, args
|
43
|
+
send_set :set_clip, :get_clip, :no_clip, args
|
59
44
|
end
|
60
45
|
|
61
|
-
def font (*args)
|
62
|
-
|
63
|
-
get_font
|
46
|
+
def font (*args, &block)
|
47
|
+
set_or_get :font=, :get_font, args, block
|
64
48
|
end
|
65
49
|
|
66
50
|
def font= (*args)
|
67
|
-
send_set :set_font, nil, args
|
51
|
+
send_set :set_font, :get_font, nil, args
|
68
52
|
end
|
69
53
|
|
54
|
+
def color (fill, stroke = nil, &block)
|
55
|
+
org = [self.fill, self.stroke]
|
56
|
+
self.fill, self.stroke = fill, stroke
|
57
|
+
if block
|
58
|
+
Xot::BlockUtil.instance_eval_or_block_call self, &block
|
59
|
+
self.fill, self.stroke = org
|
60
|
+
end
|
61
|
+
org
|
62
|
+
end
|
63
|
+
|
64
|
+
def attach (shader, uniforms = {})
|
65
|
+
shader =
|
66
|
+
case shader
|
67
|
+
when Shader then shader
|
68
|
+
when String then Shader.new shader
|
69
|
+
else raise ArgumentError
|
70
|
+
end
|
71
|
+
attach_shader shader
|
72
|
+
uniforms.each {|name, args| set_uniform name, *args}
|
73
|
+
shader
|
74
|
+
end
|
75
|
+
|
76
|
+
alias detach detach_shader
|
77
|
+
|
70
78
|
def push (&block)
|
71
79
|
push_matrix
|
72
|
-
|
80
|
+
push_attr
|
81
|
+
push_shader
|
73
82
|
if block
|
74
|
-
block
|
83
|
+
Xot::BlockUtil.instance_eval_or_block_call self, &block
|
75
84
|
pop
|
76
85
|
end
|
77
86
|
end
|
78
87
|
|
79
88
|
def pop ()
|
80
|
-
|
89
|
+
pop_shader
|
90
|
+
pop_attr
|
81
91
|
pop_matrix
|
82
92
|
end
|
83
93
|
|
94
|
+
def begin (*args, &block)
|
95
|
+
begin_paint
|
96
|
+
Xot::BlockUtil.instance_eval_or_block_call self, *args, &block
|
97
|
+
end_paint
|
98
|
+
end
|
99
|
+
|
84
100
|
private
|
85
101
|
|
86
|
-
|
87
|
-
|
88
|
-
|
89
|
-
|
102
|
+
NONES = [:no, :none]
|
103
|
+
|
104
|
+
def send_set (setter, getter, no, args, mode = nil)
|
105
|
+
args = args[0] if args[0].kind_of? Array
|
106
|
+
raise ArgumentError if args.empty?
|
107
|
+
|
108
|
+
arg0 = args[0]
|
109
|
+
if args.size == 1 && (!arg0 || NONES.include?(arg0))
|
110
|
+
no ? send(no) : send(setter, nil)
|
90
111
|
else
|
91
|
-
|
112
|
+
case mode
|
113
|
+
when :color then args = to_color(args)
|
114
|
+
end
|
115
|
+
send setter, *args
|
116
|
+
end
|
117
|
+
send getter
|
118
|
+
end
|
119
|
+
|
120
|
+
def set_or_get (setter, getter, args, block)
|
121
|
+
unless args.empty?
|
122
|
+
set_or_push setter, getter, args, block
|
123
|
+
else
|
124
|
+
send getter
|
125
|
+
end
|
126
|
+
end
|
127
|
+
|
128
|
+
def set_or_push (setter, getter, args, block)
|
129
|
+
org = send getter
|
130
|
+
send setter, *args
|
131
|
+
if block
|
132
|
+
Xot::BlockUtil.instance_eval_or_block_call self, &block
|
133
|
+
send setter, org
|
134
|
+
end
|
135
|
+
org
|
136
|
+
end
|
137
|
+
|
138
|
+
COLORS = {
|
139
|
+
black: [0, 0, 0],
|
140
|
+
red: [1, 0, 0],
|
141
|
+
green: [0, 1, 0],
|
142
|
+
blue: [0, 0, 1],
|
143
|
+
yellow: [1, 1, 0],
|
144
|
+
cyan: [0, 1, 1],
|
145
|
+
magenta: [1, 0, 1],
|
146
|
+
white: [1, 1, 1],
|
147
|
+
gray: [0.5, 0.5, 0.5],
|
148
|
+
}.inject({}) {|hash, (name, array)| hash[name] = Color.new *array; hash}
|
149
|
+
|
150
|
+
def to_color (args)
|
151
|
+
case arg0 = args[0]
|
152
|
+
when Symbol then [COLORS[arg0]]
|
153
|
+
when String then [(arg0 =~ /^\s*#[\da-fA-F]+\s*$/) ? Color.new(arg0) : COLORS[arg0.intern]]
|
154
|
+
else args
|
92
155
|
end
|
93
156
|
end
|
94
157
|
|
data/lib/rays/point.rb
CHANGED
@@ -11,30 +11,10 @@ module Rays
|
|
11
11
|
|
12
12
|
include Comparable
|
13
13
|
|
14
|
-
def move_to! (*args)
|
15
|
-
case args.size
|
16
|
-
when 1 then self.x = self.y = args[0]
|
17
|
-
when 2 then self.x, self.y = args
|
18
|
-
when 3 then self.x, self.y, self.z = args
|
19
|
-
else raise ArgumentError
|
20
|
-
end
|
21
|
-
self
|
22
|
-
end
|
23
|
-
|
24
14
|
def move_to (*args)
|
25
15
|
dup.move_to! *args
|
26
16
|
end
|
27
17
|
|
28
|
-
def move_by! (*args)
|
29
|
-
case args.size
|
30
|
-
when 1 then self.x += args[0]; self.y += args[0]
|
31
|
-
when 2 then self.x += args[0]; self.y += args[1]
|
32
|
-
when 3 then self.x += args[0]; self.y += args[1]; self.z += args[2]
|
33
|
-
else raise ArgumentError
|
34
|
-
end
|
35
|
-
self
|
36
|
-
end
|
37
|
-
|
38
18
|
def move_by (*args)
|
39
19
|
dup.move_by! *args
|
40
20
|
end
|
@@ -48,22 +28,20 @@ module Rays
|
|
48
28
|
end
|
49
29
|
end
|
50
30
|
|
51
|
-
def
|
52
|
-
|
53
|
-
when 0 then x
|
54
|
-
when 1 then y
|
55
|
-
when 2 then z
|
56
|
-
else raise IndexError
|
57
|
-
end
|
31
|
+
def + (*args)
|
32
|
+
op_add Point.from(*args)
|
58
33
|
end
|
59
34
|
|
60
|
-
def
|
61
|
-
|
62
|
-
|
63
|
-
|
64
|
-
|
65
|
-
|
66
|
-
|
35
|
+
def - (*args)
|
36
|
+
op_sub Point.from(*args)
|
37
|
+
end
|
38
|
+
|
39
|
+
def * (*args)
|
40
|
+
op_mult Point.from(*args)
|
41
|
+
end
|
42
|
+
|
43
|
+
def / (*args)
|
44
|
+
op_div Point.from(*args)
|
67
45
|
end
|
68
46
|
|
69
47
|
def <=> (o)
|
@@ -72,8 +50,13 @@ module Rays
|
|
72
50
|
z <=> o.z
|
73
51
|
end
|
74
52
|
|
75
|
-
def
|
76
|
-
|
53
|
+
def self.from (*args)
|
54
|
+
case arg0 = args[0]
|
55
|
+
when Point then arg0
|
56
|
+
when Array then Point.new *arg0
|
57
|
+
when Numeric then Point.new arg0, arg0, arg0
|
58
|
+
else raise ArgumentError
|
59
|
+
end
|
77
60
|
end
|
78
61
|
|
79
62
|
end# Point
|
data/lib/rays/shader.rb
ADDED
data/lib/rays/texture.rb
CHANGED
@@ -2,6 +2,7 @@
|
|
2
2
|
|
3
3
|
|
4
4
|
require 'rays/ext'
|
5
|
+
require 'rays/color_space'
|
5
6
|
|
6
7
|
|
7
8
|
module Rays
|
@@ -9,6 +10,14 @@ module Rays
|
|
9
10
|
|
10
11
|
class Texture
|
11
12
|
|
13
|
+
def initialize (width, height, color_space = :RGBA, alpha_only = false)
|
14
|
+
setup width, height, ColorSpace.get_color_space(color_space), alpha_only
|
15
|
+
end
|
16
|
+
|
17
|
+
def bounds ()
|
18
|
+
Bounew.new 0, 0, width, height
|
19
|
+
end
|
20
|
+
|
12
21
|
end# Texture
|
13
22
|
|
14
23
|
|
data/lib/rays.rb
CHANGED
@@ -3,10 +3,14 @@
|
|
3
3
|
|
4
4
|
require 'rays/autoinit'
|
5
5
|
require 'rays/module'
|
6
|
+
|
6
7
|
require 'rays/point'
|
7
8
|
require 'rays/bounds'
|
8
9
|
require 'rays/color'
|
10
|
+
require 'rays/color_space'
|
9
11
|
require 'rays/bitmap'
|
10
12
|
require 'rays/texture'
|
11
13
|
require 'rays/image'
|
14
|
+
require 'rays/font'
|
15
|
+
require 'rays/shader'
|
12
16
|
require 'rays/painter'
|
data/rays.gemspec
CHANGED
@@ -1,9 +1,8 @@
|
|
1
1
|
# -*- mode: ruby; coding: utf-8 -*-
|
2
2
|
|
3
3
|
|
4
|
-
|
5
|
-
$:.unshift
|
6
|
-
end
|
4
|
+
File.expand_path('../lib', __FILE__)
|
5
|
+
.tap {|s| $:.unshift s if !$:.include?(s) && File.directory?(s)}
|
7
6
|
|
8
7
|
require 'rays/module'
|
9
8
|
|
@@ -13,7 +12,7 @@ Gem::Specification.new do |s|
|
|
13
12
|
patterns.map {|pat| Dir.glob(pat).to_a}.flatten
|
14
13
|
end
|
15
14
|
|
16
|
-
mod = Rays
|
15
|
+
mod = Rays::Module
|
17
16
|
name = mod.name.downcase
|
18
17
|
rdocs = glob.call *%w[README .doc/ext/**/*.cpp]
|
19
18
|
|