Text Wrapping
Displaying 1-3 of 3 total.
1
Please enter a numerical value for the importance of this sticky.
Enter 0 to unsticky.
miky

I have made a nearly complete textbox engine, and you can find it in the download list, by searching for "textbox". It can only print one line at a time, however, and I want to be able to do multiple lines without having to type a separate string for each line. How would I make a string wrap to a new line?

Posted on 2007-02-17 16:15:57

Beni

Use the function TextWidth() on a subset of your string obtained from the function left(), until it exceeds the length of the textbox, or whatever. Something like this.


void WrapPrint(int x, int y, int dest, int font, string t, int maxlen)
{
int i;
while(len(t) > 0)
{
i = 0;
while(TextWidth(font, left(t,i)) < maxlen && i <= len(t))
i++;
i--;
PrintString(x,y,dest,font,left(t,i));
t = right(t,len(t)-i);
y += FontHeight(font);
}
}


This won't separate the string by words though.

Posted on 2007-02-17 18:46:00

miky

Thanks, I didn't know if there was a function for the width of a string. Making it only wrap words should be pretty easy. :)

EDIT: I'll just redo it because I want to check when the next space is and junk like that.

Posted on 2007-02-17 18:55:33 (last edited on 2007-02-19 20:48:33)


Displaying 1-3 of 3 total.
1
 
Newest messages

Ben McGraw's lovingly crafted this website from scratch for years.
It's a lot prettier this go around because of Jon Wofford.
Verge-rpg.com is a member of the lunarnet irc network, and would like to take this opportunity to remind you that regardless how babies taste, it is wrong to eat them.