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.
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
data/lib/rays/color.rb ADDED
@@ -0,0 +1,52 @@
1
+ # -*- coding: utf-8 -*-
2
+
3
+
4
+ require 'rays/ext'
5
+
6
+
7
+ module Rays
8
+
9
+
10
+ class Color
11
+
12
+ include Comparable
13
+
14
+ def to_a ()
15
+ [red, green, blue, alpha]
16
+ end
17
+
18
+ def [] (index)
19
+ case index
20
+ when 0 then red
21
+ when 1 then green
22
+ when 2 then blue
23
+ when 3 then alpha
24
+ else raise IndexError
25
+ end
26
+ end
27
+
28
+ def []= (index, val)
29
+ case index
30
+ when 0 then self.red = val
31
+ when 1 then self.green = val
32
+ when 2 then self.blue = val
33
+ when 3 then self.alpha = val
34
+ else raise IndexError
35
+ end
36
+ end
37
+
38
+ def <=> (o)
39
+ ret = red <=> o.red; return ret if ret != 0
40
+ ret = green <=> o.green; return ret if ret != 0
41
+ ret = blue <=> o.blue; return ret if ret != 0
42
+ alpha <=> o.alpha
43
+ end
44
+
45
+ def inspect ()
46
+ "#<Rays::Color r=#{red}, g=#{green}, b=#{blue}, a=#{alpha}>"
47
+ end
48
+
49
+ end# Color
50
+
51
+
52
+ end# Rays
data/lib/rays/ext.rb ADDED
@@ -0,0 +1,4 @@
1
+ # -*- coding: utf-8 -*-
2
+
3
+
4
+ require 'rays/native'
data/lib/rays/image.rb CHANGED
@@ -1,7 +1,7 @@
1
1
  # -*- coding: utf-8 -*-
2
2
 
3
3
 
4
- require 'rays/native'
4
+ require 'rays/ext'
5
5
 
6
6
 
7
7
  module Rays
data/lib/rays/module.rb CHANGED
@@ -22,8 +22,15 @@ module Rays
22
22
  File.join root_dir, 'task'
23
23
  end
24
24
 
25
- def load_tasks ()
26
- Dir["#{task_dir}/**/*.rake"].each {|path| load path}
25
+ def load_tasks (*names)
26
+ if names.empty?
27
+ Dir["#{task_dir}/**/*.rake"].each {|path| load path}
28
+ else
29
+ names.each do |name|
30
+ path = "#{task_dir}/#{name}.rake"
31
+ load path if File.exist? path
32
+ end
33
+ end
27
34
  end
28
35
 
29
36
  def version ()
data/lib/rays/painter.rb CHANGED
@@ -1,7 +1,8 @@
1
1
  # -*- coding: utf-8 -*-
2
2
 
3
3
 
4
- require 'rays/native'
4
+ require 'xot/blockutil'
5
+ require 'rays/ext'
5
6
 
6
7
 
7
8
  module Rays
@@ -9,50 +10,25 @@ module Rays
9
10
 
10
11
  class Painter
11
12
 
12
- attr_accessor :font
13
+ alias end end_paint
13
14
 
14
- def initialize ()
15
- @font = Rays::Font.new
16
- end
17
-
18
- def line (*args)
19
- args = args[0] if !args.empty? && args[0] === Array
20
- draw_rect *args
21
- end
22
-
23
- def rect (*args)
24
- args = args[0] if !args.empty? && args[0] === Array
25
- draw_rect *args
26
- end
27
-
28
- def ellipse (*args)
29
- args = args[0] if !args.empty? && args[0] === Array
30
- draw_ellipse *args
31
- end
32
-
33
- def arc (*args)
34
- args = args[0] if !args.empty? && args[0] === Array
35
- draw_arc *args
36
- end
37
-
38
- alias image draw_image
39
-
40
- def text (*args)
41
- case args.size
42
- when 1 then args << 0 << 0 << @font
43
- when 2 then args << 0 << @font
44
- when 3 then args << @font
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
45
22
  end
46
- draw_text *args
47
23
  end
48
24
 
49
- def clear (*args)
50
- send :clear=, *args unless args.empty?
51
- get_clear
25
+ def background (*args)
26
+ send :background=, *args unless args.empty?
27
+ get_background
52
28
  end
53
29
 
54
- def clear= (*args)
55
- send_set :set_clear, :no_clear, args
30
+ def background= (*args)
31
+ send_set :set_background, :no_background, args
56
32
  end
57
33
 
58
34
  def fill (*args)
@@ -82,12 +58,35 @@ module Rays
82
58
  send_set :set_clip, :no_clip, args
83
59
  end
84
60
 
61
+ def font (*args)
62
+ send :font=, *args unless args.empty?
63
+ get_font
64
+ end
65
+
66
+ def font= (*args)
67
+ send_set :set_font, nil, args
68
+ end
69
+
70
+ def push (&block)
71
+ push_matrix
72
+ push_attrs
73
+ if block
74
+ block.call
75
+ pop
76
+ end
77
+ end
78
+
79
+ def pop ()
80
+ pop_attrs
81
+ pop_matrix
82
+ end
83
+
85
84
  private
86
85
 
87
86
  def send_set (set, no, args)
88
- args = args[0] if args[0].kind_of?(Array)
87
+ args = args[0] if Array === args[0]
89
88
  if args.size == 1 && [nil, :no, :none].include?(args[0])
90
- send no
89
+ no ? send(no) : send(set, nil)
91
90
  else
92
91
  send set, *args
93
92
  end
data/lib/rays/point.rb ADDED
@@ -0,0 +1,82 @@
1
+ # -*- coding: utf-8 -*-
2
+
3
+
4
+ require 'rays/ext'
5
+
6
+
7
+ module Rays
8
+
9
+
10
+ class Point
11
+
12
+ include Comparable
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
+ def move_to (*args)
25
+ dup.move_to! *args
26
+ end
27
+
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
+ def move_by (*args)
39
+ dup.move_by! *args
40
+ end
41
+
42
+ def to_a (dimension = 2)
43
+ case dimension
44
+ when 1 then [x]
45
+ when 2 then [x, y]
46
+ when 3 then [x, y, z]
47
+ else raise ArgumentError
48
+ end
49
+ end
50
+
51
+ def [] (index)
52
+ case index
53
+ when 0 then x
54
+ when 1 then y
55
+ when 2 then z
56
+ else raise IndexError
57
+ end
58
+ end
59
+
60
+ def []= (index, val)
61
+ case index
62
+ when 0 then self.x = val
63
+ when 1 then self.y = val
64
+ when 2 then self.z = val
65
+ else raise IndexError
66
+ end
67
+ end
68
+
69
+ def <=> (o)
70
+ ret = x <=> o.x; return ret if ret != 0
71
+ ret = y <=> o.y; return ret if ret != 0
72
+ z <=> o.z
73
+ end
74
+
75
+ def inspect ()
76
+ "#<Rays::Point x=#{self.x}, y=#{self.y}, z=#{self.z}>"
77
+ end
78
+
79
+ end# Point
80
+
81
+
82
+ end# Rays
data/lib/rays/texture.rb CHANGED
@@ -1,7 +1,7 @@
1
1
  # -*- coding: utf-8 -*-
2
2
 
3
3
 
4
- require 'rays/native'
4
+ require 'rays/ext'
5
5
 
6
6
 
7
7
  module Rays
data/rays.gemspec CHANGED
@@ -1,64 +1,43 @@
1
1
  # -*- mode: ruby; coding: utf-8 -*-
2
2
 
3
3
 
4
- $: << File.join(File.dirname(__FILE__), 'lib')
4
+ $: << File.expand_path('../lib', __FILE__)
5
5
 
6
- require 'rake'
7
6
  require 'rays/module'
8
7
 
9
8
 
10
- MODULE = Rays
11
- NAME = MODULE.name.downcase
12
-
13
-
14
- FILES = FileList[*%W[
15
- README
16
- ChangeLog
17
- Rakefile
18
- #{NAME}.gemspec
19
- VERSION
20
- task/**/*.rake
21
- ext/**/*.rb
22
- ext/**/*.h
23
- ext/**/*.cpp
24
- include/**/*.h
25
- lib/**/*.rb
26
- src/**/*.h
27
- src/**/*.cpp
28
- src/**/*.mm
29
- test/**/*.rb
30
- ]]
31
-
32
- RDOCS = FileList[*%W[
33
- README
34
- .doc/ext/**/*.cpp
35
- ]]
9
+ Gem::Specification.new do |s|
10
+ def glob (*patterns)
11
+ patterns.map {|pat| Dir.glob(pat).to_a}.flatten
12
+ end
36
13
 
14
+ mod = Rays
15
+ name = mod.name.downcase
16
+ rdocs = glob *%w[README .doc/ext/**/*.cpp]
37
17
 
38
- Gem::Specification.new do |s|
39
- s.name = NAME
18
+ s.name = name
40
19
  s.summary = 'A Drawing Engine using OpenGL.'
41
20
  s.description = 'This library helps you to develop graphics application with OpenGL.'
42
- s.version = MODULE.version
21
+ s.version = mod.version
43
22
 
44
23
  s.authors = %w[snori]
45
24
  s.email = 'snori@xord.org'
46
- s.homepage = "http://github.com/xord/#{NAME}"
25
+ s.homepage = "http://github.com/xord/#{name}"
47
26
 
48
27
  s.platform = Gem::Platform::RUBY
49
28
  s.required_ruby_version = '>=1.9.0'
50
- s.require_paths << 'ext'
51
29
 
30
+ s.add_runtime_dependency 'bundler'
52
31
  s.add_runtime_dependency 'xot'
53
32
  s.add_runtime_dependency 'rucy'
54
33
  s.add_development_dependency 'rake'
55
34
  s.add_development_dependency 'gemcutter'
56
35
 
57
- s.files = FILES.to_a
58
- s.test_files = FileList['test/**/test_*.rb'].to_a
59
-
36
+ s.files = `git ls-files`.split $/
37
+ s.executables = s.files.grep(%r{^bin/}) {|f| File.basename f}
38
+ s.test_files = s.files.grep %r{^(test|spec|features)/}
39
+ s.extra_rdoc_files = rdocs.to_a
60
40
  s.has_rdoc = true
61
- s.extra_rdoc_files = RDOCS.to_a
62
41
 
63
42
  s.extensions << 'Rakefile'
64
43
  end
data/src/bounds.cpp ADDED
@@ -0,0 +1,234 @@
1
+ #include "rays/bounds.h"
2
+
3
+
4
+ namespace Rays
5
+ {
6
+
7
+
8
+ Bounds::Bounds (coord size)
9
+ {
10
+ set(size);
11
+ }
12
+
13
+ Bounds::Bounds (coord width, coord height, coord depth)
14
+ {
15
+ set(width, height, depth);
16
+ }
17
+
18
+ Bounds::Bounds (coord x, coord y, coord width, coord height)
19
+ {
20
+ set(x, y, width, height);
21
+ }
22
+
23
+ Bounds::Bounds (
24
+ coord x, coord y, coord z, coord width, coord height, coord depth)
25
+ {
26
+ set(x, y, z, width, height, depth);
27
+ }
28
+
29
+ Bounds
30
+ Bounds::dup () const
31
+ {
32
+ return *this;
33
+ }
34
+
35
+ Bounds&
36
+ Bounds::set (coord size)
37
+ {
38
+ return set(size, size, 0);
39
+ }
40
+
41
+ Bounds&
42
+ Bounds::set (coord width, coord height, coord depth)
43
+ {
44
+ this->x =
45
+ this->y =
46
+ this->z = 0;
47
+ this->width = width;
48
+ this->height = height;
49
+ this->depth = depth;
50
+ return *this;
51
+ }
52
+
53
+ Bounds&
54
+ Bounds::set (coord x, coord y, coord width, coord height)
55
+ {
56
+ return set(x, y, 0, width, height, 0);
57
+ }
58
+
59
+ Bounds&
60
+ Bounds::set (coord x, coord y, coord z, coord width, coord height, coord depth)
61
+ {
62
+ this->x = x;
63
+ this->y = y;
64
+ this->z = z;
65
+ this->width = width;
66
+ this->height = height;
67
+ this->depth = depth;
68
+ return *this;
69
+ }
70
+
71
+ bool
72
+ Bounds::get (coord* x, coord* y, coord* width, coord* height) const
73
+ {
74
+ return get(x, y, NULL, width, height, NULL);
75
+ }
76
+
77
+ bool
78
+ Bounds::get (
79
+ coord* x, coord* y, coord* z, coord* width, coord* height, coord* depth) const
80
+ {
81
+ if (!x && !y && !z && !width && !height && !depth)
82
+ return false;
83
+
84
+ if (x) *x = this->x;
85
+ if (y) *y = this->y;
86
+ if (z) *z = this->z;
87
+ if (width) *width = this->width;
88
+ if (height) *height = this->height;
89
+ if (depth) *depth = this->depth;
90
+ return true;
91
+ }
92
+
93
+ void
94
+ Bounds::set_left (coord left)
95
+ {
96
+ width -= left - x;
97
+ x = left;
98
+ }
99
+
100
+ coord
101
+ Bounds::left () const
102
+ {
103
+ return x;
104
+ }
105
+
106
+ void
107
+ Bounds::set_right (coord right)
108
+ {
109
+ width = right - x + 1;
110
+ }
111
+
112
+ coord
113
+ Bounds::right () const
114
+ {
115
+ return x + width - 1;
116
+ }
117
+
118
+ void
119
+ Bounds::set_top (coord top)
120
+ {
121
+ height -= top - y;
122
+ y = top;
123
+ }
124
+
125
+ coord
126
+ Bounds::top () const
127
+ {
128
+ return y;
129
+ }
130
+
131
+ void
132
+ Bounds::set_bottom (coord bottom)
133
+ {
134
+ height = bottom - y + 1;
135
+ }
136
+
137
+ coord
138
+ Bounds::bottom () const
139
+ {
140
+ return y + height - 1;
141
+ }
142
+
143
+ void
144
+ Bounds::set_back (coord back)
145
+ {
146
+ depth -= back - z;
147
+ z = back;
148
+ }
149
+
150
+ coord
151
+ Bounds::back () const
152
+ {
153
+ return z;
154
+ }
155
+
156
+ void
157
+ Bounds::set_front (coord front)
158
+ {
159
+ depth = front - z + 1;
160
+ }
161
+
162
+ coord
163
+ Bounds::front () const
164
+ {
165
+ return z + depth - 1;
166
+ }
167
+
168
+ Point&
169
+ Bounds::position ()
170
+ {
171
+ return ((Point*) this)[0];
172
+ }
173
+
174
+ const Point&
175
+ Bounds::position () const
176
+ {
177
+ return const_cast<This*>(this)->position();
178
+ }
179
+
180
+ Point&
181
+ Bounds::size ()
182
+ {
183
+ return ((Point*) this)[1];
184
+ }
185
+
186
+ const Point&
187
+ Bounds::size () const
188
+ {
189
+ return const_cast<This*>(this)->size();
190
+ }
191
+
192
+ coord*
193
+ Bounds::array ()
194
+ {
195
+ return (coord*) this;
196
+ }
197
+
198
+ const coord*
199
+ Bounds::array () const
200
+ {
201
+ return const_cast<Bounds*>(this)->array();
202
+ }
203
+
204
+ Bounds::operator bool () const
205
+ {
206
+ return width >= 0 && height >= 0 && depth >= 0;
207
+ }
208
+
209
+ bool
210
+ Bounds::operator ! () const
211
+ {
212
+ return !operator bool();
213
+ }
214
+
215
+ bool
216
+ operator == (const Bounds& lhs, const Bounds& rhs)
217
+ {
218
+ return
219
+ lhs.x == rhs.x &&
220
+ lhs.y == rhs.y &&
221
+ lhs.z == rhs.z &&
222
+ lhs.width == rhs.width &&
223
+ lhs.height == rhs.height &&
224
+ lhs.depth == rhs.depth;
225
+ }
226
+
227
+ bool
228
+ operator != (const Bounds& lhs, const Bounds& rhs)
229
+ {
230
+ return !operator==(lhs, rhs);
231
+ }
232
+
233
+
234
+ }// Rays