diff options
| author | jacksonmj <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) |
| commit | 90f8c4f4835004e683ab5fe06937fa1f1e5ce637 (patch) | |
| tree | eae467d0741fd5c5cad3591e69d2f38dc465ee47 /src/graphics.c | |
| parent | 45b1b2bc965111b8b9c0b3237f541704fe49c47c (diff) | |
| download | powder-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/graphics.c')
| -rw-r--r-- | src/graphics.c | 39 |
1 files changed, 39 insertions, 0 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__) |
