Hey, it's me again :)
After a very long break, I've started on my textbox engine again, and wrapping won't work.
//These are the font and background images.
int font = LoadFont("font1.png");
int box = LoadImage("box.png");
int vborder = 5; //The vertical and horizontal borders.
int hborder = 5;
int linespacing = FontHeight(font) * 2; //The spacing between lines.
void Textbox(string text, int x, int y)
{
int speed = 2; //This is how long it waits between letters.
int i = 0;
Blit(x, y, box, screen);
int origx = x;
int origy = y;
y += vborder;
x += hborder;
int linenum = 1;
int another = 0;
int wordlen = 0;
int wordstart;
while (i < len(text)) //Loop through the text, blitting it letter by letter
{
if (strcmp(mid(text, i, 2), "\n") == 0) //Go to the next line if we encounter a \n
{
i += 2;
y += linespacing;
x = origx + hborder;
}
if (strcmp(mid(text, i, 1), " ") != 0 && strcmp(mid(text, i - 1, 1), " ") == 0)
{
wordstart = i;
while(strcmp(mid(text, wordstart + wordlen, 1), " ") != 0)
{
wordlen += 1;
}
if (x + TextWidth(font, mid(text, wordstart, wordlen)) > origx + ImageWidth(box) - hborder)
{
y += FontHeight(font) * 2;
x = origx + hborder;
}
wordlen = 0;
}
PrintString(x, y, screen, font, mid(text, i, 1));
ShowPage();
x += TextWidth(font, mid(text, i, 1));
i++;
if (b1) //Go to the end if the button is pressed
speed = 0;
Unpress(b1);
Wait(speed);
ShowPage();
}
while (!b1 && !another)
UpdateControls();
Unpress(b1);
}
void Wait(int delay)
{
int timestamp = systemtime;
while (systemtime - timestamp < delay)
{
UpdateControls();
}
}
There's the source. It's just not wrapping at all. Thanks in advance to anyone who can help me.
EDIT: Read the last post.