06-10-2011, 05:01 AM
Okay... this is the rewrite of the initialize method I mentioned:
And this is a map event 'Script Call' I wrote.
Rather than the window showing up at 0,0, it shows up at 20,20 (in pixels). The window resizes to fit the text... two small one-word lines.
Code:
def initialize(x,y,lines)
@lines = []
@lines = lines
@line_width = []
if @lines.size == 0
print("Error: Auto-sizing windows must have at least one line")
exit
end
@tester = Window_Base.new(0, 0, 640, 480)
@tester.contents = Bitmap.new(@tester.width - 32, @tester.height - 32)
@tester.contents.font.name = "Arial"
@tester.contents.font.size = 18
max = 0
for i in 0..@lines.size - 1
t = @lines[i]
@line_width[i] = @tester.contents.text_size(t).width
if @line_width[i] > max
max = @line_width[i]
end
end
w = max + 40
h = @lines.size + 1
h *= 32
@tester.dispose
super(x, y, w, h)
self.contents = Bitmap.new(width - 32, height - 32)
self.contents.font.name = "Arial"
self.contents.font.size = 18
refresh
end
And this is a map event 'Script Call' I wrote.
Code:
Window_Autosize.new(20,20,
["Here","There"])
Rather than the window showing up at 0,0, it shows up at 20,20 (in pixels). The window resizes to fit the text... two small one-word lines.