I can't remember if I ever post this or not when on Blizzard Age, but just in case, I'll post this.
This is a simple Window_Base Extension, adding capabilities for Window_Base to draw FACE and BAR.
Usage:
draw_bar(curr_val, max_val, color, x, y, w, h)
draw_face(file, x, y)
The picture for face must be in 72x72 pixel, and imported in Pictures.
#==============================================================================
# Window_Base Extension
# © 2007 by Sthrattoff
#==============================================================================
class Window_Base < Window
# Add capability to draw a general bar
def draw_bar(curr_val, max_val, color, x, y, w, h)
#--------------------------------------------------------------------------
# curr_val : current value of bar
# max_val : maximum value of bar
# color : an array of color (RGB)
# x : bar's x position
# y : bar's y position
# w : bar's width
# h : bar's height
# -------------------------------------------------------------------------
much_to_fill = (curr_val * 1.0 / max_val) * (w - 2)
border = Rect.new(x, y, w, h)
empty = Rect.new(x + 1, y + 1, w - 2, h - 2)
fill = Rect.new(x + 1, y + 1, much_to_fill, h - 2)
self.contents.fill_rect(border, system_color)
self.contents.fill_rect(empty, Color.new(0, 0, 0, 255))
self.contents.fill_rect(fill, Color.new(color[0], color[1], color[2], 255))
end
# Add capability to draw face
def draw_face(file, x, y)
#--------------------------------------------------------------------------
# file : picture's file name (please include the file's extension)
# x : picture's x position
# y : picture's y position
#--------------------------------------------------------------------------
self.contents.blt(x, y, RPG::Cache.picture(file), Rect.new(0, 0, 72, 72))
end
end