rays 0.1.6 → 0.1.7

Sign up to get free protection for your applications and to get access to all the features.
Files changed (113) hide show
  1. checksums.yaml +7 -0
  2. data/.doc/ext/rays/bitmap.cpp +70 -233
  3. data/.doc/ext/rays/bounds.cpp +339 -57
  4. data/.doc/ext/rays/color.cpp +58 -48
  5. data/.doc/ext/rays/color_space.cpp +174 -0
  6. data/.doc/ext/rays/font.cpp +31 -53
  7. data/.doc/ext/rays/image.cpp +64 -67
  8. data/.doc/ext/rays/matrix.cpp +22 -50
  9. data/.doc/ext/rays/native.cpp +9 -2
  10. data/.doc/ext/rays/painter.cpp +276 -259
  11. data/.doc/ext/rays/point.cpp +186 -52
  12. data/.doc/ext/rays/rays.cpp +25 -20
  13. data/.doc/ext/rays/shader.cpp +61 -0
  14. data/.doc/ext/rays/texture.cpp +47 -59
  15. data/{README → README.md} +0 -0
  16. data/Rakefile +6 -5
  17. data/VERSION +1 -1
  18. data/ext/rays/bitmap.cpp +88 -248
  19. data/ext/rays/bounds.cpp +437 -141
  20. data/ext/rays/color.cpp +79 -69
  21. data/ext/rays/color_space.cpp +185 -0
  22. data/ext/rays/extconf.rb +14 -63
  23. data/ext/rays/font.cpp +44 -65
  24. data/ext/rays/image.cpp +82 -81
  25. data/ext/rays/matrix.cpp +32 -60
  26. data/ext/rays/native.cpp +9 -2
  27. data/ext/rays/painter.cpp +345 -321
  28. data/ext/rays/point.cpp +212 -69
  29. data/ext/rays/rays.cpp +29 -23
  30. data/ext/rays/shader.cpp +63 -0
  31. data/ext/rays/texture.cpp +64 -74
  32. data/include/rays/bitmap.h +21 -12
  33. data/include/rays/bounds.h +67 -9
  34. data/include/rays/color.h +23 -7
  35. data/include/rays/{colorspace.h → color_space.h} +6 -3
  36. data/include/rays/exception.h +17 -11
  37. data/include/rays/font.h +4 -3
  38. data/include/rays/image.h +11 -6
  39. data/include/rays/matrix.h +15 -12
  40. data/include/rays/opengl.h +54 -1
  41. data/include/rays/painter.h +98 -108
  42. data/include/rays/point.h +45 -5
  43. data/include/rays/rays.h +2 -2
  44. data/include/rays/ruby/bitmap.h +2 -16
  45. data/include/rays/ruby/bounds.h +4 -16
  46. data/include/rays/ruby/color.h +3 -16
  47. data/include/rays/ruby/color_space.h +27 -0
  48. data/include/rays/ruby/font.h +2 -16
  49. data/include/rays/ruby/image.h +2 -16
  50. data/include/rays/ruby/matrix.h +2 -16
  51. data/include/rays/ruby/painter.h +2 -16
  52. data/include/rays/ruby/point.h +3 -16
  53. data/include/rays/ruby/shader.h +27 -0
  54. data/include/rays/ruby/texture.h +2 -16
  55. data/include/rays/ruby.h +1 -0
  56. data/include/rays/shader.h +48 -0
  57. data/include/rays/texture.h +13 -2
  58. data/include/rays.h +2 -1
  59. data/lib/rays/bitmap.rb +20 -11
  60. data/lib/rays/bounds.rb +29 -68
  61. data/lib/rays/color.rb +39 -0
  62. data/lib/rays/color_space.rb +33 -0
  63. data/lib/rays/font.rb +29 -0
  64. data/lib/rays/image.rb +22 -0
  65. data/lib/rays/module.rb +11 -7
  66. data/lib/rays/painter.rb +103 -40
  67. data/lib/rays/point.rb +19 -36
  68. data/lib/rays/shader.rb +13 -0
  69. data/lib/rays/texture.rb +9 -0
  70. data/lib/rays.rb +4 -0
  71. data/rays.gemspec +3 -4
  72. data/src/bounds.cpp +272 -63
  73. data/src/color.cpp +168 -21
  74. data/src/{colorspace.cpp → color_space.cpp} +38 -1
  75. data/src/exception.cpp +24 -15
  76. data/src/frame_buffer.cpp +275 -0
  77. data/src/frame_buffer.h +79 -0
  78. data/src/image.cpp +80 -36
  79. data/src/ios/bitmap.mm +340 -0
  80. data/src/ios/font.mm +206 -0
  81. data/src/{cocoa → ios}/helper.h +2 -2
  82. data/src/{cocoa → ios}/helper.mm +0 -0
  83. data/src/ios/opengl.mm +21 -0
  84. data/src/ios/program.cpp +122 -0
  85. data/src/{cocoa → ios}/rays.mm +8 -7
  86. data/src/matrix.cpp +10 -22
  87. data/src/opengl.cpp +64 -0
  88. data/src/{cocoa → osx}/bitmap.mm +121 -70
  89. data/src/{cocoa → osx}/font.mm +32 -24
  90. data/src/osx/helper.h +26 -0
  91. data/src/osx/helper.mm +25 -0
  92. data/src/osx/opengl.mm +103 -0
  93. data/src/osx/rays.mm +43 -0
  94. data/src/painter.cpp +596 -422
  95. data/src/point.cpp +154 -11
  96. data/src/program.cpp +513 -0
  97. data/src/program.h +73 -0
  98. data/src/render_buffer.cpp +120 -0
  99. data/src/render_buffer.h +47 -0
  100. data/src/shader.cpp +117 -0
  101. data/src/texture.cpp +104 -134
  102. data/test/helper.rb +10 -3
  103. data/test/test_bitmap.rb +18 -0
  104. data/test/test_bounds.rb +81 -35
  105. data/test/test_color.rb +29 -2
  106. data/test/test_image.rb +63 -0
  107. data/test/test_painter.rb +120 -0
  108. data/test/test_point.rb +30 -9
  109. data/test/test_shader.rb +37 -0
  110. data/test/test_texture.rb +18 -0
  111. metadata +75 -58
  112. data/.gitignore +0 -14
  113. 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
- alias end end_paint
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
- send :fill=, *args unless args.empty?
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
- send :stroke=, *args unless args.empty?
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
- send :clip=, *args unless args.empty?
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
- send :font=, *args unless args.empty?
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
- push_attrs
80
+ push_attr
81
+ push_shader
73
82
  if block
74
- block.call
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
- pop_attrs
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
- def send_set (set, no, args)
87
- args = args[0] if Array === args[0]
88
- if args.size == 1 && [nil, :no, :none].include?(args[0])
89
- no ? send(no) : send(set, nil)
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
- send set, *args
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 [] (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
31
+ def + (*args)
32
+ op_add Point.from(*args)
58
33
  end
59
34
 
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
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 inspect ()
76
- "#<Rays::Point x=#{self.x}, y=#{self.y}, z=#{self.z}>"
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
@@ -0,0 +1,13 @@
1
+ # -*- coding: utf-8 -*-
2
+
3
+
4
+ require 'rays/ext'
5
+
6
+
7
+ module Rays
8
+
9
+
10
+ #class Shader
11
+
12
+
13
+ end# Rays
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
- $:.unshift File.expand_path('../lib', __FILE__) do |path|
5
- $:.unshift path if !$:.include?(path) && File.directory?(path)
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