neonblack

Draw Number

Jun 21st, 2013
101
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. class Window_Base < Window
  2.   def draw_number(*args)
  3.     contents.draw_number(*args)
  4.   end
  5. end
  6.  
  7. class Bitmap # draw_number(x, y, width, numb, length, align, color2)
  8.   def draw_number(x, y, width, numb, length = 0, align = 0, color2 = self.font.color)
  9.     color1 = self.font.color.clone
  10.     text = sprintf("%0#{length}d", numb)
  11.     self.font.color = color2.clone
  12.     space = self.text_size(" ").width
  13.     x2 = x + (width - self.text_size(text).width) / 2 * align
  14.     text.split(//).each do |c|
  15.       self.font.color = color1 unless c == "0"
  16.       draw_text(x2 - space, y, self.width, self.height, " #{c} ")
  17.       x2 += self.text_size(c).width
  18.     end
  19.   end
  20. end
RAW Paste Data