How to draw a vertical gauge from bottom to top?

The default Bitmap#gradient_fill_rect method has the origin of the rectangle in the upper-left, and extends downwards. Here is an example

8l6Z9qs.jpg


How do I draw it so that it grows upwards instead of downwards?

I guess I could use a sprite and rotate...but that seems kind of too much?

EDIT: This is my desired result

Code:
|       ||       ||       ||       |      |100%   60%    20%
What you do is draw it normally in a separate bitmap, then blit that bitmap onto the contents of the window, except with the src rect in the blt fuction's height value modified. Something like:

class Window_Base def draw_vert_bar_bt(x, y, value, max_value, h = 40, w = 4, c1 = Color.new(255,255,255), c2 = Color.new(0,0,0)) b = Bitmap.new(w, h) b.gradient_fill_rect(b.rect, c1, c2, true) contents.blt(x, y, b, b.rect.tap {|r| r.height = ((value/max_value.to_f) * h).to_i}) # Where the magic happens. endendIf you use that along with this code, you'll see it in action:
Code:
$data_system = load_data("Data/System.rvdata2")$game_system = Game_System.new$w = Window_Base.new(0, 0, Graphics.width, Graphics.height)$w.draw_vert_bar_bt(20, 20, 100,100)$w.draw_vert_bar_bt(20, 20, 50, 100, 40, 4, Color.new(255,0,0), Color.new(0,255,0))$w.activate.openloop do  Graphics.update  Input.update  $w.update  break if Input.trigger?(:C)end$w.dispose
There are other ways of doing it, without creating another bitmap, but I digress. Hope this way helps 🙂 Edit: P.S. Just gotta say I love Object#tap, so useful in many ways!
Why not just set the Y position of the bar to the empty portion?  As in max_height - filled_height.
Because the bar doesn't empty from top to bottom, it empties from bottom to top. Thus, the y variable will remain constant. If Tsuki want a gradient bar, then the gradient has to match the bar emptying. Just changing the y will not do that 😛 The gradient will all be there, from color 1 to color 2, just less stretched.
I tried to integrate it here but it doesn't seem to work

Spoiler
class Window_StatusHud < Window_Base def initialize(x, y) super(x, y, Graphics.width, 116) refresh end def update super # needs to figure out how to avoid refresh if Graphics.frame_count % 10 == 0 end def refresh contents.clear for i in 0..3 actor = $game_party.battle_members next unless actor draw_actor_face(actor, 132*i, 0) draw_hp_bar(actor, 100 + 132*i, 0) draw_mp_bar(actor, 106 + 132*i, 0) end end def draw_vert_bar_bt(x, y, value, max_value, h = 40, w = 4, c1 = Color.new(255,255,255), c2 = Color.new(0,0,0)) b = Bitmap.new(w, h) b.gradient_fill_rect(b.rect, c1, c2, true) contents.blt(x, y, b, b.rect.tap {|r| r.height = ((value/max_value.to_f) * h).to_i}) # Where the magic happens. end def draw_hp_bar(actor, x, y) fill_y = actor.hp_rate * self.height - standard_padding * 2 if actor.hp_rate < 0.25 col = Color.new(255, 0, 0) elsif actor.hp_rate < 0.5 col = Color.new(255, 255, 0) else col = Color.new(0, 255, 0) end draw_vert_bar_bt(x, y, actor.hp, actor.mhp, fill_y, 4, col, col) #contents.gradient_fill_rect(x, 0, 4, fill_y, col, col, true) end def draw_mp_bar(actor, x, y) contents.fill_rect(x, y, 4, 100, mp_gauge_color1) endendclass Scene_Map < Scene_Base alias :th_status_hud_create_all_windows :create_all_windows def create_all_windows th_status_hud_create_all_windows create_status_window end def create_status_window @status_window = Window_StatusHud.new(0, Graphics.height - 116) endend
When my HP goes down, the bar still empties out from bottom to top.

Granted, I don't really understand the use of the tap method in this case. I guess it would be equivalent to

Code:
new_rect = b.rect.clonenew_rect.height = # set new height# blt using new_rect instead of b.rect
Maybe I should take out the gradient and just use a regular fill_rect, since I'm obviously not using a gradient in there.
Wait, do you want the bar to go down vertically as the value is reduced, or go up as the value is reduced? I may have been a bit confused.
Let me clarify with some art since the wording seems confusing no matter how I think about it.

Code:
|       ||       ||       ||       |      |100%   60%    20%
Ah. In that case, simply do this:

Code:
class Window_Base  def draw_vert_gauge_tb(x, y, w, h, value, max_value, c1=nil, c2=nil, back_color = Color.new(0,0,0))    c1 = Color.new(0,175,50) if c1.nil?    c2 = Color.new(100,0,0)  if c2.nil?    contents.fill_rect(x, y, w, h, back_color)    # calculate the new_height of the bar    new_height = (value.to_f / max_value) * h    # and the difference between the original and new    dif = h - new_height.to_i        # offset the y to match the new height, simulating the 'lowering'    # of the bar (top to bottom)    newY = (y + h) - new_height.to_i    b = Bitmap.new(w, h)    b.gradient_fill_rect(0, 0, w, h, c1, c2, true)    r = Rect.new(0, dif, w, new_height)    contents.blt(x, newY, b, r)    b.dispose  endend
Test it with this:
Code:
$data_system = load_data("Data/System.rvdata2")$game_system = Game_System.new$w = Window_Base.new(0, 0, Graphics.width, Graphics.height)v = 100$w.draw_vert_gauge_tb(20, 20, 50, 200, v, 100)$w.activate.openloop do  if (Graphics.frame_count % 10).zero?    v = (v - 2) % 100    p v    v = 100 if v < 0    $w.contents.clear    $w.draw_vert_gauge_tb(20, 20, 50, 200, v, 100)  end  Graphics.update  Input.update  $w.update  break if Input.trigger?(:C)end$w.dispose
Thanks, didn't think of adjusting the y-value (only the height). Now it looks a lot better


EqfqvP3.jpg



(still looking for a suitable kitty face for the fourth position)


But MGC's FPLE script is awesome


eR7qbtn.jpg

Original thread: https://forums.rpgmakerweb.com/threads/how-to-draw-a-vertical-gauge-from-bottom-to-top.20749/