Method: MiniGL::ProgressBar#draw

Defined in:
lib/minigl/forms.rb

#draw(alpha = 0xff, z_index = 0, color = 0xffffff) ⇒ Object

Draws the progress bar.

Parameters:

alpha

(Fixnum) The opacity with which the progress bar will be drawn. Allowed values vary between 0 (fully transparent) and 255 (fully opaque).

z_index

(Fixnum) The z-order to draw the object. Objects with larger z-orders will be drawn on top of the ones with smaller z-orders.

color

Color to apply a filter to the images (when these are provided).



1232
1233
1234
1235
1236
1237
1238
1239
1240
1241
1242
1243
1244
1245
1246
1247
1248
1249
1250
1251
1252
1253
1254
1255
1256
1257
1258
1259
1260
1261
1262
1263
1264
1265
1266
1267
1268
1269
1270
1271
1272
# File 'lib/minigl/forms.rb', line 1232

def draw(alpha = 0xff, z_index = 0, color = 0xffffff)
  return unless @visible

  if @bg
    c = (alpha << 24) | color
    @bg.draw @x, @y, z_index, @scale_x, @scale_y, c
  else
    c = (alpha << 24) | @bg_color
    G.window.draw_quad @x, @y, c,
                       @x + @w, @y, c,
                       @x + @w, @y + @h, c,
                       @x, @y + @h, c, z_index
  end
  if @fg
    c = (alpha << 24) | color
    w1 = @fg.width * @scale_x
    w2 = (@value.to_f / @max_value * @w).round
    x0 = @x + @fg_margin_x
    x = 0
    while x <= w2 - w1
      @fg.draw x0 + x, @y + @fg_margin_y, z_index, @scale_x, @scale_y, c
      x += w1
    end
    if w2 - x > 0
      img = Gosu::Image.new(@fg_path, tileable: true, retro: @retro, rect: [0, 0, ((w2 - x) / @scale_x).round, @fg.height])
      img.draw x0 + x, @y + @fg_margin_y, z_index, @scale_x, @scale_y, c
    end
  else
    c = (alpha << 24) | @fg_color
    rect_r = @x + (@value.to_f / @max_value * @w).round
    G.window.draw_quad @x, @y, c,
                       rect_r, @y, c,
                       rect_r, @y + @h, c,
                       @x, @y + @h, c, z_index
  end
  if @font
    c = (alpha << 24) | @text_color
    @text = @format == '%' ? "#{(@value.to_f / @max_value * 100).round}%" : "#{@value}/#{@max_value}"
    @font.draw_text_rel @text, @x + @w / 2, @y + @h / 2, z_index, 0.5, 0.5, @scale_x, @scale_y, c
  end
end