Class: CyberarmEngine::Element::Progress

Inherits:
CyberarmEngine::Element show all
Defined in:
lib/cyberarm_engine/ui/elements/progress.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, #x, #y, #z

Instance Method Summary collapse

Methods inherited from CyberarmEngine::Element

#background=, #button_down, #button_up, #default_events, #draw, #enabled?, #height, #hide, #hit?, #inner_height, #inner_width, #is_root?, #outer_height, #outer_width, #reposition, #root, #set_background, #set_border_color, #set_border_thickness, #set_margin, #set_padding, #show, #stylize, #toggle, #update, #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(options = {}, block = nil) ⇒ Progress

Returns a new instance of Progress.



4
5
6
7
8
9
# File 'lib/cyberarm_engine/ui/elements/progress.rb', line 4

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

  @fraction_background = Background.new(background: @style.fraction_background)
  self.value = options[:fraction] ? options[:fraction] : 0.0
end

Instance Method Details

#recalculateObject



15
16
17
18
19
20
21
22
# File 'lib/cyberarm_engine/ui/elements/progress.rb', line 15

def recalculate
  _width = dimensional_size(@style.width, :width)
  _height= dimensional_size(@style.height,:height)
  @width = _width
  @height= _height

  update_background
end

#renderObject



11
12
13
# File 'lib/cyberarm_engine/ui/elements/progress.rb', line 11

def render
  @fraction_background.draw
end

#update_backgroundObject



24
25
26
27
28
29
30
31
32
33
34
# File 'lib/cyberarm_engine/ui/elements/progress.rb', line 24

def update_background
  super

  @fraction_background.x = @style.border_thickness_left + @style.padding_left + @x
  @fraction_background.y = @style.border_thickness_top + @style.padding_top + @y
  @fraction_background.z = @z
  @fraction_background.width = @width * @fraction
  @fraction_background.height = @height

  @fraction_background.background = @style.fraction_background
end

#valueObject



36
37
38
# File 'lib/cyberarm_engine/ui/elements/progress.rb', line 36

def value
  @fraction
end

#value=(decimal) ⇒ Object



40
41
42
43
44
45
46
47
# File 'lib/cyberarm_engine/ui/elements/progress.rb', line 40

def value=(decimal)
  raise "value must be number" unless decimal.is_a?(Numeric)

  @fraction = decimal.clamp(0.0, 1.0)
  update_background

  return @fraction
end