void DrawString(Vector2 pos, int flags, Colour colour, const char* txt, ...) { char buf[512]; va_list ap; va_start(ap, txt); _vsnprintf_s(buf, sizeof(buf), _TRUNCATE, txt, ap); va_end(ap); if (flags == kTextCentre) pos.x -= MeasureString(txt) * 0.5f; else if (flags == kTextRight) pos.x -= MeasureString(txt); const char* letters = "ABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789.:/-!@"; for(const char* p = buf; *p != '\0'; p++) { int c = toupper(*p); int sprite = -1; if (const char* ofs = strchr(letters, c)) sprite = 256 + (int)(intptr_t)(ofs - letters); if (sprite >= 0) DrawChar(pos, Vector2(1.0f), sprite, 0, colour); pos.x += MeasureChar(c); } }
int Graphics_::MeasureString(const char* s, int len) { int x = 0; while (len--) x += MeasureChar(*s++) + 1; return x; }
float MeasureString(const char* txt) { float w = 0.0f; for(; *txt; txt++) w += MeasureChar(*txt); return w; }