diff options
| author | Cracker64 <cracker642@gmail.com> | 2011-02-11 00:46:34 (GMT) |
|---|---|---|
| committer | Cracker64 <cracker642@gmail.com> | 2011-02-11 00:46:34 (GMT) |
| commit | e882dfecf91bbad8480422418f163686e60b64b6 (patch) | |
| tree | 7687a19b0891f67da347e3c9e2a093ef14483b0e /src/graphics.c | |
| parent | 30d86813fcc642cdb2e68c59b5e1db2992a741bc (diff) | |
| download | powder-e882dfecf91bbad8480422418f163686e60b64b6.zip powder-e882dfecf91bbad8480422418f163686e60b64b6.tar.gz | |
update with latest
Diffstat (limited to 'src/graphics.c')
| -rw-r--r-- | src/graphics.c | 141 |
1 files changed, 90 insertions, 51 deletions
diff --git a/src/graphics.c b/src/graphics.c index 786bdca..78f1867 100644 --- a/src/graphics.c +++ b/src/graphics.c @@ -855,49 +855,65 @@ int drawtextwrap(pixel *vid, int x, int y, int w, const char *s, int r, int g, i int rh = 12; int rw = 0; int cw = x; - for (; *s; s++) + int wordlen; + int charspace; + while (*s) { - if (*s == '\n') + wordlen = strcspn(s," .,!?\n"); + charspace = textwidthx(s, w-(x-cw)); + if (charspace<wordlen && wordlen && w-(x-cw)<w/3) { x = sx; rw = 0; - y += FONT_H+2; + y+=FONT_H+2; + rh+=FONT_H+2; } - else if (*s == '\b') + for (; *s && --wordlen>=-1; s++) { - switch (s[1]) + if (*s == '\n') { - case 'w': - r = g = b = 255; - break; - case 'g': - r = g = b = 192; - break; - case 'o': - r = 255; - g = 216; - b = 32; - break; - case 'r': - r = 255; - g = b = 0; - break; - case 'b': - r = g = 0; - b = 255; - break; - } - s++; - } - else - { - if (x-cw>=w) { x = sx; rw = 0; - y+=FONT_H+2; - rh+=FONT_H+2; + y += FONT_H+2; + } + else if (*s == '\b') + { + switch (s[1]) + { + case 'w': + r = g = b = 255; + break; + case 'g': + r = g = b = 192; + break; + case 'o': + r = 255; + g = 216; + b = 32; + break; + case 'r': + r = 255; + g = b = 0; + break; + case 'b': + r = g = 0; + b = 255; + break; + } + s++; + } + else + { + + if (x-cw>=w) + { + x = sx; + rw = 0; + y+=FONT_H+2; + rh+=FONT_H+2; + } + x = drawchar(vid, x, y, *(unsigned char *)s, r, g, b, a); } - x = drawchar(vid, x, y, *(unsigned char *)s, r, g, b, a); } } #endif @@ -1009,18 +1025,29 @@ 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++) + int wordlen, charspace; + while (*s&&n) { - if (!n) { - break; - } - x += font_data[font_ptrs[(int)(*(unsigned char *)s)]]; - if (x>=w) { + wordlen = strcspn(s," .,!?\n"); + charspace = textwidthx(s, w-x); + if (charspace<wordlen && wordlen && w-x<w/3) + { x = 0; y += FONT_H+2; } - n--; + for (; *s && --wordlen>=-1; s++) + { + if (!n) { + break; + } + x += font_data[font_ptrs[(int)(*(unsigned char *)s)]]; + if (x>=w) + { + x = 0; + y += FONT_H+2; + } + n--; + } } *cx = x-1; *cy = y; @@ -1041,18 +1068,28 @@ int textwidthx(char *s, int w) } int textposxy(char *s, int width, int w, int h) { - int x=0,y=0,n=0,cw; - for (; *s; s++) + int x=0,y=0,n=0,cw, wordlen, charspace; + while (*s) { - cw = font_data[font_ptrs[(int)(*(unsigned char *)s)]]; - if (x+(cw/2) >= w && y+6 >= h) - break; - x += cw; - if (x>=width) { + wordlen = strcspn(s," .,!?\n"); + charspace = textwidthx(s, width-x); + if (charspace<wordlen && wordlen && width-x<width/3) + { x = 0; y += FONT_H+2; } - n++; + for (; *s && --wordlen>=-1; s++) + { + cw = font_data[font_ptrs[(int)(*(unsigned char *)s)]]; + if ((x+(cw/2) >= w && y+6 >= h)||(y+6 >= h+FONT_H+2)) + return n++; + x += cw; + if (x>=width) { + x = 0; + y += FONT_H+2; + } + n++; + } } return n; } @@ -1483,7 +1520,9 @@ void draw_parts(pixel *vid) t!=PT_HFLM && t!=PT_SPRK && t!=PT_FIRW && t!=PT_DUST && t!=PT_FIRW && t!=PT_FWRK && t!=PT_NEUT && t!=PT_LAVA && t!=PT_BOMB && - t!=PT_PHOT && t!=PT_THDR && t!=PT_SMKE) + t!=PT_PHOT && t!=PT_THDR && t!=PT_SMKE && + t!=PT_LCRY && t!=PT_SWCH && t!=PT_PCLN && + t!=PT_PUMP && t!=PT_HSWC && t!=PT_FILT) { if (ptypes[parts[i].type].properties&TYPE_LIQUID) { @@ -2907,7 +2946,7 @@ void render_signs(pixel *vid_buf) sprintf(buff, "Temp: 0.00"); //...tempirature drawtext(vid_buf, x+3, y+3, buff, 255, 255, 255, 255); } - + if(sregexp(signs[i].text, "^{c:[0-9]*|.*}$")==0) { int sldr, startm; |
