Class: Ruby2D::Image

Inherits:
Object
  • Object
show all
Defined in:
lib/ruby2d/image.rb,
ext/ruby2d/ruby2d-opal.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(x, y, path) ⇒ Image

Returns a new instance of Image.



9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
# File 'lib/ruby2d/image.rb', line 9

def initialize(x, y, path)
  
  # TODO: Check if file exists
  #   `File.exists?` is not available in MRuby
  #   Ideally would do:
  #     unless File.exists? path
  #       raise Error, "Cannot find image file `#{path}`"
  #     end
  
  @type_id = 3
  @x, @y, @path = x, y, path
  @color = Color.new([1, 1, 1, 1])
  init(path)
  add
end

Instance Attribute Details

#colorObject

Returns the value of attribute color.



7
8
9
# File 'lib/ruby2d/image.rb', line 7

def color
  @color
end

#dataObject

Returns the value of attribute data.



6
7
8
# File 'lib/ruby2d/image.rb', line 6

def data
  @data
end

#heightObject

Returns the value of attribute height.



6
7
8
# File 'lib/ruby2d/image.rb', line 6

def height
  @height
end

#pathObject (readonly)

Returns the value of attribute path.



7
8
9
# File 'lib/ruby2d/image.rb', line 7

def path
  @path
end

#widthObject

Returns the value of attribute width.



6
7
8
# File 'lib/ruby2d/image.rb', line 6

def width
  @width
end

#xObject

Returns the value of attribute x.



6
7
8
# File 'lib/ruby2d/image.rb', line 6

def x
  @x
end

#yObject

Returns the value of attribute y.



6
7
8
# File 'lib/ruby2d/image.rb', line 6

def y
  @y
end

Instance Method Details

#addObject



29
30
31
32
33
# File 'lib/ruby2d/image.rb', line 29

def add
  if Module.const_defined? :DSL
    Application.add(self)
  end
end

#init(path) ⇒ Object



135
136
137
# File 'ext/ruby2d/ruby2d-opal.rb', line 135

def init(path)
  `#{self}.data = S2D.CreateImage(path);`
end

#removeObject



35
36
37
38
39
# File 'lib/ruby2d/image.rb', line 35

def remove
  if Module.const_defined? :DSL
    Application.remove(self)
  end
end