diff options
Diffstat (limited to 'src/strings33.c')
-rw-r--r-- | src/strings33.c | 51 |
1 files changed, 23 insertions, 28 deletions
diff --git a/src/strings33.c b/src/strings33.c index 8613c02..0291393 100644 --- a/src/strings33.c +++ b/src/strings33.c @@ -3,74 +3,69 @@ #include "string.h" #include "strings33.h" -#include "types.h" +#include "types33.h" -extern Font33 defFont; -extern Font33 bigFont; - static Font33 *fonts[2] = { &defFont, &bigFont }; static u32 textColours[9] = { - 0xff000000, - 0xffffffff, - 0xffff0000, - 0xff00ff00, - 0xff0000ff, - 0xffffff00, - 0xff00ffff, - 0xffff00ff, - 0xffffaa00, + BLACK, + RED, + GREEN, + BLUE, + YELLOW, + ORANGE, + MAGENTA, + CYAN, + WHITE }; -void e33_uprintf( Surface *surf, Size f, u32 col, Size x, Size y, const char *fmt, ... ) +void e33_uprintf( Surface33 *surf, Size f, u32 col, Size x, Size y, const char *fmt, ... ) { - static char tmp[512]; + static char tmp[ _STRING_MAX ]; va_list args; va_start(args, fmt); - vsprintf(tmp, fmt, args); + vsnprintf(tmp, _STRING_MAX, fmt, args); e33_uprint( surf, f, col, x, y, tmp ); va_end(args); } -void e33_uprint( Surface *surf, Size f, u32 col, Size x, Size y, const char *str ) +void e33_uprint( Surface33 *surf, Size f, u32 col, Size x, Size y, const char *str ) { Size i, j, ofs; Font33 *font = fonts[f]; Size sWidth = surf->w; Size sHeight = surf->h; FontGlyph33 *glyphs = font->glyphs; - Size fbw = surf->w; - Size fbh = surf->h; u32 *out; - uSize slen = strlen(str); + uSize stringLen = strlen(str); Size strWid = 0; - for( i = 0; i < slen; ++i ) { + for( i = 0; i < stringLen; ++i ) { if( str[i] < 0x20 ) continue; - strWid += glyphs[ str[i] - 0x20 ].width; + strWid += glyphs[ str[i] - 0x20 ].w; } if( (x + strWid) >= sWidth ) { x -= (strWid - (sWidth - x)); } - if( (y + font->height) >= sHeight ) { - y -= (font->height - (sHeight - y)); + if( (y + font->h) >= sHeight ) { + y -= (font->h- (sHeight - y)); } if(x < 0) { x = 0; } if(y < 0) { y = 0; } out = surf->data + (x + (y * surf->w)); - for( i = 0, ofs = 0; i < slen; ++i ) + for( i = 0, ofs = 0; i < stringLen; ++i ) { if( str[i] < 0x20 ) { @@ -79,14 +74,14 @@ void e33_uprint( Surface *surf, Size f, u32 col, Size x, Size y, const char *str } FontGlyph33 *glyph = &glyphs[ str[i] - 0x20 ]; - Size numPlots = glyph->num_plots; - Size gWidth = glyph->width; + Size numPlots = glyph->plotCount; + Size gWidth = glyph->w; u16 *plots = glyph->plots; for( j = 0; j < numPlots; ++j ) { Size plot = plots[j]; - Size offset = (((plot & font->yAnd) * fbw) + (plot >> font->xShift)) + ofs; + Size offset = (((plot & font->yAnd) * sWidth) + (plot >> font->xShift)) + ofs; memcpy( out + offset, &col, sizeof(u32) ); } |