Make MsgDialog not put text outside the screen.

This commit is contained in:
Henrik Rydgard 2013-01-03 14:02:35 +01:00
parent 6b64554e64
commit 59e52f4e5a
2 changed files with 5 additions and 2 deletions

View File

@ -50,7 +50,7 @@ void PSPDialog::EndDraw()
void PSPDialog::DisplayMessage(std::string text)
{
PPGeDrawText(text.c_str(), 480/2, 100, PPGE_ALIGN_CENTER, 0.5f, 0xFFFFFFFF);
PPGeDrawText(text.c_str(), 40, 30, PPGE_ALIGN_LEFT, 0.5f, 0xFFFFFFFF);
}
int PSPDialog::Shutdown()

View File

@ -238,18 +238,20 @@ static void PPGeMeasureText(const char *text, float scale, float *w, float *h) {
const AtlasFont &atlasfont = *ppge_atlas.fonts[0];
unsigned char cval;
float wacc = 0;
float maxw = 0;
int lines = 1;
while ((cval = *text++) != '\0') {
if (cval < 32) continue;
if (cval > 127) continue;
if (cval == '\n') {
if (wacc > maxw) maxw = wacc;
wacc = 0;
lines++;
}
AtlasChar c = atlasfont.chars[cval - 32];
wacc += c.wx * scale;
}
if (w) *w = wacc;
if (w) *w = maxw;
if (h) *h = atlasfont.height * scale * lines;
}
@ -278,6 +280,7 @@ void PPGeDrawText(const char *text, float x, float y, int align, float scale, u3
float sx = x;
while ((cval = *text++) != '\0') {
if (cval == '\n') {
// This is not correct when centering or right-justifying, need to set x depending on line width (tricky)
y += atlasfont.height * scale;
x = sx;
continue;