Class: CyberarmEngine::Element::Image

Inherits:
CyberarmEngine::Element show all
Defined in:
lib/cyberarm_engine/ui/elements/image.rb

Constant Summary

Constants included from Theme

Theme::THEME

Instance Attribute Summary

Attributes inherited from CyberarmEngine::Element

#background_canvas, #border_canvas, #enabled, #event_handler, #options, #parent, #style, #tip, #x, #y, #z

Instance Method Summary collapse

Methods inherited from CyberarmEngine::Element

#background=, #button_down, #button_up, #content_height, #content_width, #default_events, #dimensional_size, #draggable?, #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, #set_static_position, #show, #stylize, #to_s, #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
11
# File 'lib/cyberarm_engine/ui/elements/image.rb', line 4

def initialize(path, options = {}, block = nil)
  super(options, block)
  @path = path

  @image = Gosu::Image.new(path, retro: @options[:image_retro])
  @scale_x = 1
  @scale_y = 1
end

Instance Method Details

#clicked_left_mouse_button(_sender, _x, _y) ⇒ Object



22
23
24
25
26
# File 'lib/cyberarm_engine/ui/elements/image.rb', line 22

def clicked_left_mouse_button(_sender, _x, _y)
  @block.call(self) if @block

  :handled
end

#recalculateObject



28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
# File 'lib/cyberarm_engine/ui/elements/image.rb', line 28

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
end

#renderObject



13
14
15
16
17
18
19
20
# File 'lib/cyberarm_engine/ui/elements/image.rb', line 13

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

#valueObject



50
51
52
# File 'lib/cyberarm_engine/ui/elements/image.rb', line 50

def value
  @path
end