PDA

View Full Version : getstringlength



siodine
02-12-2005, 05:27 AM
this is a stripped down version of IMessageChars::GetStringLength, all this does is get the width and height of text, its useful for console stuff like making a editline cursor






void GetStringLength( vgui::HFont hCustomFont, int *width, int *height, const char *fmt, ... )
{
va_list argptr;
char data[1024];
int len;

va_start( argptr, fmt );
len = Q_vsnprintf( data, sizeof( data ), fmt, argptr );
va_end(argptr);

data[1023] = 0;

*width = g_pDraw->DrawTextLen( hCustomFont, (char *)data );
*height = g_pSurface->GetFontTall( hCustomFont );
}




credits: valve sdk

sp0rky
02-12-2005, 05:56 AM
I already posted a func in the vgui esp thread that gets the height of the string, which I think would be better than yours since it will work on all strings instead of a string on one line.

siodine
02-12-2005, 07:10 AM
im not positive because i can barely think from lack of sleep but i think theyre two totatly different things, im using mine for getting the width of the edit text buffer for my console then drawing the blinking cursor at the end of it andi just tried yours for getting the width and it dodnt work but maybe i fucked up