diff options
| author | Simon <simon@hardwired.org.uk> | 2010-11-03 15:51:02 (GMT) |
|---|---|---|
| committer | Simon <simon@hardwired.org.uk> | 2010-11-03 15:51:02 (GMT) |
| commit | 9a40e4924e99af80a50b2c5f409d8463f993c4da (patch) | |
| tree | 1aa4f3982d1af6c2cbe523d2631e7d47df2e9fb6 /src/graphics.c | |
| parent | d1ce8e55dfd07faa3eb8029ea47a1db6a30f6988 (diff) | |
| download | powder-9a40e4924e99af80a50b2c5f409d8463f993c4da.zip powder-9a40e4924e99af80a50b2c5f409d8463f993c4da.tar.gz | |
Major improvements to text wrapping, acceptible but still character based
Diffstat (limited to 'src/graphics.c')
| -rw-r--r-- | src/graphics.c | 30 |
1 files changed, 27 insertions, 3 deletions
diff --git a/src/graphics.c b/src/graphics.c index d6604a3..83b1141 100644 --- a/src/graphics.c +++ b/src/graphics.c @@ -1002,18 +1002,25 @@ int textnwidth(char *s, int n) } return x-1; } -int textnheight(char *s, int n, int w) +void textnpos(char *s, int n, int w, int *cx, int *cy) { int x = 0; + int y = 0; //TODO: Implement Textnheight for wrapped text for(; *s; s++) { - if(!n) + if(!n){ break; + } x += font_data[font_ptrs[(int)(*(unsigned char *)s)]]; + if(x>=w) { + x = 0; + y += FONT_H+2; + } n--; } - return x-1; + *cx = x-1; + *cy = y; } int textwidthx(char *s, int w) @@ -1029,6 +1036,23 @@ int textwidthx(char *s, int w) } return n; } +int textposxy(char *s, int width, int w, int h) +{ + int x=0,y=0,n=0,cw; + for(; *s; s++) + { + cw = font_data[font_ptrs[(int)(*(unsigned char *)s)]]; + if(x+(cw/2) >= w && y+6 >= h) + break; + x += cw; + if(x>=width) { + x = 0; + y += FONT_H+2; + } + n++; + } + return n; +} #ifdef WIN32 _inline void blendpixel(pixel *vid, int x, int y, int r, int g, int b, int a) |
