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 collapse

Attributes inherited from CyberarmEngine::Element

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

Instance Method Summary collapse

Methods inherited from CyberarmEngine::Element

#background=, #background_image=, #background_nine_slice=, #blur, #button_down, #button_up, #child_of?, #clicked_left_mouse_button, #content_height, #content_width, #debug_draw, #default_events, #dimensional_size, #draggable?, #draw, #element_visible?, #enabled=, #enabled?, #enter, #focus, #focused?, #height, #hide, #hit?, #inner_height, #inner_width, #inspect, #is_root?, #leave, #left_mouse_button, #max_scroll_height, #max_scroll_width, #noncontent_height, #noncontent_width, #outer_height, #outer_width, #parent_of?, #recalculate, #recalculate_if_size_changed, #released_left_mouse_button, #reposition, #root, #safe_style_fetch, #scroll_height, #scroll_width, #set_background, #set_background_image, #set_background_nine_slice, #set_border_color, #set_border_thickness, #set_color, #set_font, #set_margin, #set_padding, #set_static_position, #show, #space_available_height, #space_available_width, #stylize, #to_s, #toggle, #update_background_image, #update_background_nine_slice, #update_styles, #visible?, #width

Methods included from Common

#alt_down?, #control_down?, #current_state, #darken, #draw_rect, #fill, #find_element_by_tag, #get_asset, #get_image, #get_sample, #get_song, #lighten, #opacity, #pop_state, #previous_state, #push_state, #shift_down?, #shift_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.



6
7
8
9
10
11
12
13
14
15
16
# File 'lib/cyberarm_engine/ui/elements/progress.rb', line 6

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

  @animation_speed = options[:animation_speed] || 3_000
  @marquee_width = options[:marquee_width] || 0.25
  @marquee_offset = 0
  @marquee_animation_time = Gosu.milliseconds
  @type = options[:type] || :linear
  @fraction_background = Background.new(background: @style.fraction_background)
  self.value = options[:fraction] || 0.0
end

Instance Attribute Details

#typeObject

Returns the value of attribute type.



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

def type
  @type
end

Instance Method Details

#layoutObject



22
23
24
25
26
27
28
29
# File 'lib/cyberarm_engine/ui/elements/progress.rb', line 22

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

  update_background
end

#renderObject



18
19
20
# File 'lib/cyberarm_engine/ui/elements/progress.rb', line 18

def render
  @fraction_background.draw
end

#updateObject



43
44
45
46
47
48
49
50
51
52
53
54
55
56
# File 'lib/cyberarm_engine/ui/elements/progress.rb', line 43

def update
  super

  return unless @type == :marquee

  marquee_width = @width * @marquee_width
  range = @width + marquee_width

  @marquee_offset = (@width * (Gosu.milliseconds - @marquee_animation_time) / @animation_speed) - marquee_width
  @marquee_animation_time = Gosu.milliseconds if @marquee_offset > range

  update_background
  root.gui_state.request_repaint
end

#update_backgroundObject



31
32
33
34
35
36
37
38
39
40
41
# File 'lib/cyberarm_engine/ui/elements/progress.rb', line 31

def update_background
  super

  @fraction_background.x = (@style.border_thickness_left + @style.padding_left + @x) + @marquee_offset
  @fraction_background.y = @style.border_thickness_top + @style.padding_top + @y
  @fraction_background.z = @z
  @fraction_background.width = @width * (@type == :marquee ? @marquee_width : @fraction)
  @fraction_background.height = @height

  @fraction_background.background = @style.fraction_background
end

#valueObject



74
75
76
# File 'lib/cyberarm_engine/ui/elements/progress.rb', line 74

def value
  @fraction
end

#value=(decimal) ⇒ Object



78
79
80
81
82
83
84
85
86
87
88
89
90
# File 'lib/cyberarm_engine/ui/elements/progress.rb', line 78

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

  old_value = @fraction

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

  root.gui_state.request_repaint if @fraction != old_value

  publish(:changed, @fraction)
  @fraction
end