WrapTextX

WrapTextX
string WrapTextX(int wt_font, string wt_s, int wt_linelen)

Documentation

Inserts the "|" character as line breaks. This is speed optimised, but is still only recommended for short blocks (ie. not the entire works of Shakespeare passed in one argument) and once-only uses.

Example Usage

string WrapTextX(int wt_font, string wt_s, int wt_linelen)
// Pass: The font to use, the string to wrap, the length in pixels to fit into
// Return: The passed string with | characters inserted as breaks
// Assmes: The font is valid, and will overrun if a word is longer than linelen
// Note: Existing breaks will be respected, but adjacent | characters will be
//     replaced with a single | so add a space for multiple line breaks
{
	string wt_tpara = "";
	int curpara = 0;
	int nextpara, lenpara, curchr, nextchr, width;
	int length = len(wt_s);
	while (curpara < length)
	{
		nextpara = strstrp("|", wt_s, curpara + 1);
		if (nextpara > curpara + 1)
		{
			lenpara = nextpara - curpara - 1;
			wt_tpara = mid(wt_s, curpara + 1, lenpara);
			if (TextWidth(wt_font, wt_tpara) > wt_linelen)
			{
				curchr = 0-1;
				width = 0;
				while (curchr < lenpara)
				{
					nextchr = strstrp(" ", wt_tpara, curchr + 1);
					width += TextWidth(wt_font, mid(wt_tpara, curchr, nextchr - curchr));
					if (width > wt_linelen)
					{
						wt_s = chrovr(curpara + curchr + 1, "\", wt_s);
						width = TextWidth(wt_font, mid(wt_tpara, curchr + 1, nextchr - curchr - 1));
					}
					curchr = nextchr;
				}
			}
		}
		curpara = nextpara;
	}
	return wt_s;
}
Talkback

There are no talkbacks on this documentation page yet. Post the first?

Post a new comment?

Doc Nav

Your docs
View All Docs

If you log in, you can edit the documentation, or create your own documents and tutorials!

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.