Sha256: ad8ba86fc3c4ed2ac0a418c14c5cef00b61b78cb7366db2af7d352d00bf0bef6
Contents?: true
Size: 1.24 KB
Versions: 2
Compression:
Stored size: 1.24 KB
Contents
module CyberarmEngine class Image < Element def initialize(path, options = {}, block = nil) super(options, block) @path = path @image = Gosu::Image.new(path, retro: @options[:image_retro]) if @options[:width] && @options[:height] @scale_x = @options[:width].to_f / @image.width @scale_y = @options[:height].to_f / @image.height elsif @options[:width] @scale_x = @options[:width].to_f / @image.width @scale_y = @scale_x elsif @options[:height] @scale_y = @options[:height].to_f / @image.height @scale_x = @scale_y else @scale_x, @scale_y = 1, 1 end raise "Scale X" unless @scale_x.is_a?(Numeric) raise "Scale Y" unless @scale_y.is_a?(Numeric) end 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) # TODO: Add color support? end def clicked_left_mouse_button(sender, x, y) @block.call(self) if @block end def recalculate @style.width = @image.width * @scale_x @style.height = @image.height * @scale_y end def value @path end end end
Version data entries
2 entries across 2 versions & 1 rubygems
Version | Path |
---|---|
cyberarm_engine-0.8.1 | lib/cyberarm_engine/ui/image.rb |
cyberarm_engine-0.8.0 | lib/cyberarm_engine/ui/image.rb |