You are not logged in.
Hi.
This function returns the width of a string. It's useful when you want to draw a centered text
int GRRLIB_GetStringWidth(struct GRRLIB_texImg *tex, f32 zoom, const char *text, ...) { if (tex == NULL || tex->data == NULL) { return; } int size; int width = 0; char tmp[1024]; va_list argp; va_start(argp, text); size = vsprintf(tmp, text, argp); va_end(argp); width = size*tex->tilew*zoom; return width; }
Offline
Thanks for the contribution, I'm sure some people will appreciate it. Just a small comment, the variable named width is not required, the code should be:
int GRRLIB_GetStringWidth(struct GRRLIB_texImg *tex, f32 zoom, const char *text, ...) { if (tex == NULL || tex->data == NULL) { return; } int size; char tmp[1024]; va_list argp; va_start(argp, text); size = vsprintf(tmp, text, argp); va_end(argp); return size*tex->tilew*zoom; }
Offline
This variable was usless, indeed.
It seems that this code does not work well with text with a zoom factor which is not equal to 1.
Offline
"doesn't work properly" isn't the most comprehensive bug report, but...
Does this help?
return (int)( (f32)(size *tex->tilew) *zoom ) ;
The promotion should be occuring automatically because of the type of 'zoom', but as nobody said "the compiler says: return type is invalid" I guess it may not be happening
Offline