Method: MiniGL::ProgressBar#initialize

Defined in:
lib/minigl/forms.rb

#initialize(x, y = nil, w = nil, h = nil, bg = nil, fg = nil, max_value = 100, value = 100, fg_margin_x = 0, fg_margin_y = 0, font = nil, text_color = 0, format = nil, retro = nil, scale_x = 1, scale_y = 1, anchor = nil) ⇒ ProgressBar

Creates a progress bar.

Parameters:

x

The x-coordinate of the progress bar on the screen.

y

The y-coordinate of the progress bar on the screen.

w

Width of the progress bar, in pixels. This is the maximum space the bar foreground can occupy. Note that the width of the foreground image (fg) can be less than this, in which case the image will be horizontally repeated to fill all the needed space.

h

Height of the progress bar. This will be the height of the bar foreground when fg is a color (when it is an image, the height of the image will be kept).

bg

A background image (string or symbol that will be passed to Res.img) or color (in RRGGBB hexadecimal format).

fg

A foreground image (string or symbol that will be passed to Res.img) or color (in RRGGBB hexadecimal format). The image will be horizontally repeated when needed, if its width is less than w.

max_value

The maximum value the progress bar can reach (an integer).

value

The starting value for the progress bar.

fg_margin_x

Horizontal margin between the background image and the foreground image (when these are provided).

fg_margin_y

Vertical margin between the background image and the foreground image (when these are provided).

font

Font that will be used to draw a text indicating the value of the progress bar.

text_color

Color of the text.

format

Format to display the value. Specify ‘%’ for a percentage and anything else for absolute values (current/maximum).

retro

Whether the images should be loaded with the ‘retro’ option set (see Gosu::Image for details). If the value is omitted, the Res.retro_images value will be used.

scale_x

Horizontal scale to draw the component with.

scale_y

Vertical scale to draw the component with.

anchor

See parameter with the same name in Panel#initialize for details.

Obs.: This method accepts named parameters, but x, y, w, h, bg and fg are mandatory.



1096
1097
1098
1099
1100
1101
1102
1103
1104
1105
1106
1107
1108
1109
1110
1111
1112
1113
1114
1115
1116
1117
1118
1119
1120
1121
1122
1123
1124
1125
1126
1127
1128
1129
1130
1131
1132
1133
1134
1135
1136
1137
1138
1139
1140
1141
1142
1143
1144
1145
1146
1147
1148
1149
# File 'lib/minigl/forms.rb', line 1096

def initialize(x, y = nil, w = nil, h = nil, bg = nil, fg = nil,
               max_value = 100, value = 100, fg_margin_x = 0, fg_margin_y = 0, # fg_left = nil, fg_right = nil,
               font = nil, text_color = 0, format = nil, retro = nil, scale_x = 1, scale_y = 1, anchor = nil)
  if x.is_a? Hash
    y = x[:y]
    w = x[:w]
    h = x[:h]
    bg = x[:bg]
    fg = x[:fg]
    max_value = x.fetch(:max_value, 100)
    value = x.fetch(:value, 100)
    fg_margin_x = x.fetch(:fg_margin_x, 0)
    fg_margin_y = x.fetch(:fg_margin_y, 0)
    font = x.fetch(:font, nil)
    text_color = x.fetch(:text_color, 0)
    format = x.fetch(:format, nil)
    retro = x.fetch(:retro, nil)
    scale_x = x.fetch(:scale_x, 1)
    scale_y = x.fetch(:scale_y, 1)
    anchor = x.fetch(:anchor, nil)
    x = x[:x]
  end

  @scale_x = scale_x
  @scale_y = scale_y
  retro = Res.retro_images if retro.nil?
  if bg.is_a? Integer
    @bg_color = bg
  else # String or Symbol
    @bg = Res.img bg, false, false, '.png', retro
  end
  if fg.is_a? Integer
    @fg_color = fg
  else # String or Symbol
    @fg = Res.img fg, false, false, '.png', retro
    @fg_path = "#{Res.prefix}#{Res.img_dir}#{fg.to_s.gsub(Res.separator, '/')}.png"
  end
  @fg_margin_x = fg_margin_x * @scale_x
  @fg_margin_y = fg_margin_y * @scale_y

  @w = (@bg ? @bg.width : w) * @scale_x
  @h = (@bg ? @bg.height : h) * @scale_y

  @anchor_offset_x = x; @anchor_offset_y = y
  @anchor, x, y = FormUtils.check_anchor(anchor, x, y, @w, @h)

  super x, y, font, '', text_color, text_color
  # @fg_left = fg_left
  # @fg_right = fg_right
  @max_value = max_value
  self.value = value
  @format = format
  @retro = retro
end