mirror of
https://github.com/cyberarm/cyberarm_engine.git
synced 2026-11-06 09:23:54 +00:00
Added Progress bar, refactored Elements to be under CyberarmEngine::Element namespace.
This commit is contained in:
50
lib/cyberarm_engine/ui/elements/image.rb
Normal file
50
lib/cyberarm_engine/ui/elements/image.rb
Normal file
@@ -0,0 +1,50 @@
|
||||
module CyberarmEngine
|
||||
class Element
|
||||
class Image < Element
|
||||
def initialize(path, options = {}, block = nil)
|
||||
super(options, block)
|
||||
@path = path
|
||||
|
||||
@image = Gosu::Image.new(path, retro: @options[:image_retro])
|
||||
@scale_x, @scale_y = 1, 1
|
||||
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
|
||||
_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, @scale_y = 1, 1
|
||||
end
|
||||
|
||||
@width = _width ? _width : @image.width.round * @scale_x
|
||||
@height= _height ? _height : @image.height.round * @scale_y
|
||||
end
|
||||
|
||||
def value
|
||||
@path
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
Reference in New Issue
Block a user