summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorjacksonmj <mj-pt@jacksonmj.co.uk>2011-04-02 14:49:06 (GMT)
committer Simon <simon@hardwired.org.uk>2011-04-04 15:11:37 (GMT)
commit90f8c4f4835004e683ab5fe06937fa1f1e5ce637 (patch)
treeeae467d0741fd5c5cad3591e69d2f38dc465ee47 /src
parent45b1b2bc965111b8b9c0b3237f541704fe49c47c (diff)
downloadpowder-90f8c4f4835004e683ab5fe06937fa1f1e5ce637.zip
powder-90f8c4f4835004e683ab5fe06937fa1f1e5ce637.tar.gz
error_ui: wrap text and change message box height to fit
Stops banned user message overflowing out of message box
Diffstat (limited to 'src')
-rw-r--r--src/graphics.c39
-rw-r--r--src/interface.c20
2 files changed, 52 insertions, 7 deletions
diff --git a/src/graphics.c b/src/graphics.c
index 928b6a7..b4cd51c 100644
--- a/src/graphics.c
+++ b/src/graphics.c
@@ -1104,6 +1104,45 @@ int textposxy(char *s, int width, int w, int h)
}
return n;
}
+int textwrapheight(char *s, int width)
+{
+ int x=0, height=FONT_H+2, cw;
+ int wordlen;
+ int charspace;
+ while (*s)
+ {
+ wordlen = strcspn(s," .,!?\n");
+ charspace = textwidthx(s, width-x);
+ if (charspace<wordlen && wordlen && width-x<width/3)
+ {
+ x = 0;
+ height += FONT_H+2;
+ }
+ for (; *s && --wordlen>=-1; s++)
+ {
+ if (*s == '\n')
+ {
+ x = 0;
+ height += FONT_H+2;
+ }
+ else if (*s == '\b')
+ {
+ s++;
+ }
+ else
+ {
+ cw = font_data[font_ptrs[(int)(*(unsigned char *)s)]];
+ if (x+cw>=width)
+ {
+ x = 0;
+ height += FONT_H+2;
+ }
+ x += cw;
+ }
+ }
+ }
+ return height;
+}
//the most used function for drawing a pixel, because it has OpenGL support, which is not fully implemented.
#if defined(WIN32) && !defined(__GNUC__)
diff --git a/src/interface.c b/src/interface.c
index a6c327d..138a8cf 100644
--- a/src/interface.c
+++ b/src/interface.c
@@ -613,7 +613,7 @@ void draw_svf_ui(pixel *vid_buf)// all the buttons at the bottom
void error_ui(pixel *vid_buf, int err, char *txt)
{
- int x0=(XRES-240)/2,y0=(YRES-MENUSIZE)/2,b=1,bq,mx,my;
+ int x0=(XRES-240)/2,y0=YRES/2,b=1,bq,mx,my,textheight;
char *msg;
msg = malloc(strlen(txt)+16);
@@ -621,6 +621,12 @@ void error_ui(pixel *vid_buf, int err, char *txt)
sprintf(msg, "%03d %s", err, txt);
else
sprintf(msg, "%s", txt);
+ textheight = textwrapheight(msg, 240);
+ y0 -= (52+textheight)/2;
+ if (y0<2)
+ y0 = 2;
+ if (y0+50+textheight>YRES)
+ textheight = YRES-50-y0;
while (!sdl_poll())
{
@@ -636,18 +642,18 @@ void error_ui(pixel *vid_buf, int err, char *txt)
mx /= sdl_scale;
my /= sdl_scale;
- clearrect(vid_buf, x0-2, y0-2, 244, 64);
- drawrect(vid_buf, x0, y0, 240, 60, 192, 192, 192, 255);
+ clearrect(vid_buf, x0-2, y0-2, 244, 52+textheight);
+ drawrect(vid_buf, x0, y0, 240, 48+textheight, 192, 192, 192, 255);
if (err)
drawtext(vid_buf, x0+8, y0+8, "HTTP error:", 255, 64, 32, 255);
else
drawtext(vid_buf, x0+8, y0+8, "Error:", 255, 64, 32, 255);
- drawtext(vid_buf, x0+8, y0+26, msg, 255, 255, 255, 255);
- drawtext(vid_buf, x0+5, y0+49, "Dismiss", 255, 255, 255, 255);
- drawrect(vid_buf, x0, y0+44, 240, 16, 192, 192, 192, 255);
+ drawtextwrap(vid_buf, x0+8, y0+26, 224, msg, 255, 255, 255, 255);
+ drawtext(vid_buf, x0+5, y0+textheight+37, "Dismiss", 255, 255, 255, 255);
+ drawrect(vid_buf, x0, y0+textheight+32, 240, 16, 192, 192, 192, 255);
sdl_blit(0, 0, (XRES+BARSIZE), YRES+MENUSIZE, vid_buf, (XRES+BARSIZE));
- if (b && !bq && mx>=x0 && mx<x0+240 && my>=y0+44 && my<=y0+60)
+ if (b && !bq && mx>=x0 && mx<x0+240 && my>=y0+textheight+32 && my<=y0+textheight+48)
break;
if (sdl_key==SDLK_RETURN)