You are not logged in.

#1 2009-03-29 01:23:35

Morukutsu
Member

GRRLIB_GetStringWidth

Hi.
This function returns the width of a string. It's useful when you want to draw a centered text smile

Code:

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

 

#2 2009-03-29 04:37:56

Crayon
Bad Mother Fucker

Re: GRRLIB_GetStringWidth

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:

Code:

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

 

#3 2009-03-29 19:32:12

Morukutsu
Member

Re: GRRLIB_GetStringWidth

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

 

#4 2009-07-20 16:22:35

BlueChip
Moderator

Re: GRRLIB_GetStringWidth

"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


I can be found on efnet, freenode, msn, gtalk, aim, ychat & icq ...PM me for details

Offline

 

Board footer

Powered by FluxBB