class CyberarmEngine::Element::Image
Public Class Methods
new(path_or_image, options = {}, block = nil)
click to toggle source
Calls superclass method
CyberarmEngine::Element::new
# File lib/cyberarm_engine/ui/elements/image.rb, line 4 def initialize(path_or_image, options = {}, block = nil) super(options, block) @path = path_or_image if path_or_image.is_a?(String) @image = Gosu::Image.new(path_or_image, retro: @options[:retro], tileable: @options[:tileable]) if @path @image = path_or_image unless @path @scale_x = 1 @scale_y = 1 end
Public Instance Methods
path()
click to toggle source
# File lib/cyberarm_engine/ui/elements/image.rb, line 67 def path @path end
recalculate()
click to toggle source
# File lib/cyberarm_engine/ui/elements/image.rb, line 30 def recalculate _width = dimensional_size(@style.width, :width) _height = dimensional_size(@style.height, :height) if _width && _height @scale_x = _width.to_f / @image.width @scale_y = _height.to_f / @image.height elsif _width @scale_x = _width.to_f / @image.width @scale_y = @scale_x elsif _height @scale_y = _height.to_f / @image.height @scale_x = @scale_y else @scale_x = 1 @scale_y = 1 end @width = _width || @image.width.round * @scale_x @height = _height || @image.height.round * @scale_y update_background end
render()
click to toggle source
# File lib/cyberarm_engine/ui/elements/image.rb, line 15 def render @image.draw( @style.border_thickness_left + @style.padding_left + @x, @style.border_thickness_top + @style.padding_top + @y, @z + 2, @scale_x, @scale_y, @style.color ) end
value()
click to toggle source
# File lib/cyberarm_engine/ui/elements/image.rb, line 54 def value @image end
value=(path_or_image, retro: false, tileable: false)
click to toggle source
# File lib/cyberarm_engine/ui/elements/image.rb, line 58 def value=(path_or_image, retro: false, tileable: false) @path = path_or_image if path_or_image.is_a?(String) @image = Gosu::Image.new(path_or_image, retro: retro, tileable: tileable) if @path @image = path_or_image unless @path recalculate end