Class: Ruby2D::Image
- Inherits:
-
Object
- Object
- Ruby2D::Image
- Includes:
- Renderable
- Defined in:
- lib/ruby2d/image.rb,
ext/ruby2d/ruby2d-opal.rb
Instance Attribute Summary collapse
-
#color ⇒ Object
Returns the value of attribute color.
-
#data ⇒ Object
Returns the value of attribute data.
-
#height ⇒ Object
Returns the value of attribute height.
-
#path ⇒ Object
readonly
Returns the value of attribute path.
-
#width ⇒ Object
Returns the value of attribute width.
-
#x ⇒ Object
Returns the value of attribute x.
-
#y ⇒ Object
Returns the value of attribute y.
Attributes included from Renderable
Instance Method Summary collapse
- #contains?(x, y) ⇒ Boolean
- #ext_init(path) ⇒ Object
- #ext_render ⇒ Object
-
#initialize(opts = {}) ⇒ Image
constructor
A new instance of Image.
Methods included from Renderable
#add, #opacity, #opacity=, #remove
Constructor Details
#initialize(opts = {}) ⇒ Image
Returns a new instance of Image.
10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 |
# File 'lib/ruby2d/image.rb', line 10 def initialize(opts = {}) @path = opts[:path] unless RUBY_ENGINE == 'opal' unless File.exists? @path raise Error, "Cannot find image file `#{@path}`" end end @x = opts[:x] || 0 @y = opts[:y] || 0 @z = opts[:z] || 0 @width = opts[:width] || nil @height = opts[:height] || nil self.color = opts[:color] || 'white' ext_init(@path) add end |
Instance Attribute Details
#color ⇒ Object
Returns the value of attribute color.
8 9 10 |
# File 'lib/ruby2d/image.rb', line 8 def color @color end |
#data ⇒ Object
Returns the value of attribute data.
7 8 9 |
# File 'lib/ruby2d/image.rb', line 7 def data @data end |
#height ⇒ Object
Returns the value of attribute height.
7 8 9 |
# File 'lib/ruby2d/image.rb', line 7 def height @height end |
#path ⇒ Object (readonly)
Returns the value of attribute path.
8 9 10 |
# File 'lib/ruby2d/image.rb', line 8 def path @path end |
#width ⇒ Object
Returns the value of attribute width.
7 8 9 |
# File 'lib/ruby2d/image.rb', line 7 def width @width end |
#x ⇒ Object
Returns the value of attribute x.
7 8 9 |
# File 'lib/ruby2d/image.rb', line 7 def x @x end |
#y ⇒ Object
Returns the value of attribute y.
7 8 9 |
# File 'lib/ruby2d/image.rb', line 7 def y @y end |
Instance Method Details
#contains?(x, y) ⇒ Boolean
35 36 37 |
# File 'lib/ruby2d/image.rb', line 35 def contains?(x, y) @x < x and @x + @width > x and @y < y and @y + @height > y end |
#ext_init(path) ⇒ Object
140 141 142 143 144 145 146 147 148 149 150 151 |
# File 'ext/ruby2d/ruby2d-opal.rb', line 140 def ext_init(path) ` #{self}.data = S2D.CreateImage(path, function() { if (#{@width} == Opal.nil) { #{@width} = #{self}.data.width; } if (#{@height} == Opal.nil) { #{@height} = #{self}.data.height; } }); ` end |
#ext_render ⇒ Object
153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 |
# File 'ext/ruby2d/ruby2d-opal.rb', line 153 def ext_render ` #{self}.data.x = #{self}.x; #{self}.data.y = #{self}.y; if (#{self}.width != Opal.nil) #{self}.data.width = #{self}.width; if (#{self}.height != Opal.nil) #{self}.data.height = #{self}.height; #{self}.data.color.r = #{self}.color.r; #{self}.data.color.g = #{self}.color.g; #{self}.data.color.b = #{self}.color.b; #{self}.data.color.a = #{self}.color.a; S2D.DrawImage(#{self}.data); ` end |