From d8fb3cc03a749691a5a12096fdfb6ca0d130b276 Mon Sep 17 00:00:00 2001 From: leo Date: Fri, 11 Feb 2005 19:06:36 +0000 Subject: Added GetStringDimensions() function. git-svn-id: http://svn.leocad.org/trunk@375 c7d43263-9d01-0410-8a33-9dba5d9f93d6 --- common/texfont.cpp | 33 +++++++++++++++++++++++++++++++++ 1 file changed, 33 insertions(+) (limited to 'common/texfont.cpp') diff --git a/common/texfont.cpp b/common/texfont.cpp index fa3fe0f..4e53092 100644 --- a/common/texfont.cpp +++ b/common/texfont.cpp @@ -92,6 +92,39 @@ bool TexFont::FileLoad (File& file) return true; } +void TexFont::GetStringDimensions(int* cx, int* cy, const char* Text) const +{ + *cx = 0; + *cy = m_nFontHeight; + + while (*Text != 0) + { + *cx += m_Glyphs[*Text].width; + Text++; + } +} + +void TexFont::PrintText(float Left, float Top, float ScaleX, float ScaleY, const char* Text) const +{ + float Height = m_nFontHeight * ScaleY; + + while (*Text != 0) + { + glTexCoord2f(m_Glyphs[*Text].left, m_Glyphs[*Text].top); + glVertex2f(Left, Top); + glTexCoord2f(m_Glyphs[*Text].left, m_Glyphs[*Text].bottom); + glVertex2f(Left, Top - Height); + glTexCoord2f(m_Glyphs[*Text].right, m_Glyphs[*Text].bottom); + glVertex2f(Left + m_Glyphs[*Text].width * ScaleX, Top - Height); + glTexCoord2f(m_Glyphs[*Text].right, m_Glyphs[*Text].top); + glVertex2f(Left + m_Glyphs[*Text].width * ScaleX, Top); + + Left += m_Glyphs[*Text].width * ScaleX; + Text++; + } +} + +// Old function, should probably be removed. void TexFont::PrintText (float left, float top, const char* text) const { while (*text != 0) -- cgit v1.2.3