Class: CyberarmEngine::Element::Image
- Inherits:
-
CyberarmEngine::Element
- Object
- CyberarmEngine::Element
- CyberarmEngine::Element::Image
- Defined in:
- lib/cyberarm_engine/ui/elements/image.rb
Constant Summary
Constants included from Theme
Instance Attribute Summary
Attributes inherited from CyberarmEngine::Element
#background_canvas, #border_canvas, #enabled, #event_handler, #options, #parent, #style, #x, #y, #z
Instance Method Summary collapse
- #clicked_left_mouse_button(sender, x, y) ⇒ Object
-
#initialize(path, options = {}, block = nil) ⇒ Image
constructor
A new instance of Image.
- #recalculate ⇒ Object
- #render ⇒ Object
- #value ⇒ Object
Methods inherited from CyberarmEngine::Element
#background=, #button_down, #button_up, #content_height, #content_width, #default_events, #draw, #enabled?, #height, #hide, #hit?, #inner_height, #inner_width, #is_root?, #noncontent_height, #noncontent_width, #outer_height, #outer_width, #reposition, #root, #set_background, #set_border_color, #set_border_thickness, #set_margin, #set_padding, #show, #stylize, #toggle, #update, #update_background, #value=, #visible?, #width
Methods included from Common
#current_state, #darken, #draw_rect, #fill, #get_asset, #get_image, #get_sample, #get_song, #lighten, #opacity, #pop_state, #previous_state, #push_state, #show_cursor, #show_cursor=, #window
Methods included from CyberarmEngine::Event
#event, #publish, #subscribe, #unsubscribe
Methods included from Theme
#deep_merge, #default, #theme_defaults
Constructor Details
#initialize(path, options = {}, block = nil) ⇒ Image
Returns a new instance of Image.
4 5 6 7 8 9 10 |
# File 'lib/cyberarm_engine/ui/elements/image.rb', line 4 def initialize(path, = {}, block = nil) super(, block) @path = path @image = Gosu::Image.new(path, retro: [:image_retro]) @scale_x, @scale_y = 1, 1 end |
Instance Method Details
#clicked_left_mouse_button(sender, x, y) ⇒ Object
20 21 22 23 24 |
# File 'lib/cyberarm_engine/ui/elements/image.rb', line 20 def (sender, x, y) @block.call(self) if @block return :handled end |
#recalculate ⇒ Object
26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 |
# File 'lib/cyberarm_engine/ui/elements/image.rb', line 26 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 |
#render ⇒ Object
12 13 14 15 16 17 18 |
# File 'lib/cyberarm_engine/ui/elements/image.rb', line 12 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 |
#value ⇒ Object
47 48 49 |
# File 'lib/cyberarm_engine/ui/elements/image.rb', line 47 def value @path end |