The RPG Maker Resource Kit

RMRK RPG Maker Creation => RPG Maker General => General Scripting => Topic started by: shintashi on May 10, 2011, 04:46:05 AM

Title: [request] Fitting text in small boundaries?
Post by: shintashi on May 10, 2011, 04:46:05 AM
so I'm trying to fit longer words like "murasaki" in this:


#====================================================================
#      Fragment 1 - super (x, y, width, height)
#====================================================================
class Fragment_1 < Window_Base #Window_Fragment
attr_accessor :term

  def initialize
    super(100, 278, 90,42)
    self.contents = Bitmap.new(width-32, height-32)
    refresh
    self.back_opacity = 255
    @term = "" #$data_chants[0].name
    end
   
  def refresh
    self.contents.clear
        self.contents.font.color = text_color(0)#white
        self.contents.font.size = 16 #was 20
        self.contents.draw_text(0, -10, 90, 32, term.to_s)
      end
     
  def update
    if Graphics.frame_count / Graphics.frame_rate != @total_sec
      refresh
    end
  end
 
end


But all I get is "mura" and then the rest is cut off several pixels before the text hits the boundary. Is there a way to make text fit without using an illegible font size? I would really like to use those extra border pixels.
Title: Re: [request] Fitting text in small boundaries?
Post by: GregAzrael on May 15, 2011, 07:09:36 AM
If I remember right, try increasing the 90 in:

def initialize
    super(100, 278, 90,42)


Remember to have a backup of your work in case something happens.
Title: Re: [request] Fitting text in small boundaries?
Post by: pacdiggity on May 15, 2011, 07:33:46 AM
That's odd, I know that at least in VX the window automatically resizes the text if it doesn't fit. At GregAzrael said, increase the width (third value) of the super. If it collides with another window, you'll have to reset them all.
Although, XP should resize the text as well.
Title: Re: [request] Fitting text in small boundaries?
Post by: modern algebra on May 15, 2011, 01:14:46 PM
Well, it does in XP too. But your window is only 90 pixels wide, and 32 pixels of that is the border, so you don't have 90 pixels to draw in - you only have 58. If you change:


        self.contents.draw_text(0, -10, 90, 32, term.to_s)


to:


        self.contents.draw_text(0, -10, 58, 32, term.to_s)


Then the text would autmatically resize