summaryrefslogtreecommitdiff
path: root/common
diff options
context:
space:
mode:
authorleo2005-02-11 19:06:36 +0000
committerleo2005-02-11 19:06:36 +0000
commitd8fb3cc03a749691a5a12096fdfb6ca0d130b276 (patch)
tree32f714d7d632d28fe739581f128adceac596e7ad /common
parentb8ab42ca9ac2b2e8cd5e10b3fa6fe13b08dc3e44 (diff)
Added GetStringDimensions() function.
git-svn-id: http://svn.leocad.org/trunk@375 c7d43263-9d01-0410-8a33-9dba5d9f93d6
Diffstat (limited to 'common')
-rw-r--r--common/texfont.cpp33
-rw-r--r--common/texfont.h38
2 files changed, 53 insertions, 18 deletions
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)
diff --git a/common/texfont.h b/common/texfont.h
index f5b190c..a64a54e 100644
--- a/common/texfont.h
+++ b/common/texfont.h
@@ -9,28 +9,30 @@ class Texture;
class TexFont
{
public:
- TexFont ();
- ~TexFont ();
+ TexFont ();
+ ~TexFont ();
- bool IsLoaded () const
- { return m_bLoaded; }
- void MakeCurrent ()
- { if (m_bLoaded) m_pTexture->MakeCurrent (); }
+ bool IsLoaded () const
+ { return m_bLoaded; }
+ void MakeCurrent ()
+ { if (m_bLoaded) m_pTexture->MakeCurrent (); }
- bool FileLoad (File& file);
- void PrintText (float left, float top, const char* text) const;
- void PrintCharScaled (float scale, char ch) const;
+ bool FileLoad(File& file);
+ void PrintText(float left, float top, const char* text) const;
+ void PrintText(float Left, float Top, float ScaleX, float ScaleY, const char* Text) const;
+ void PrintCharScaled(float scale, char ch) const;
+ void GetStringDimensions(int* cx, int* cy, const char* Text) const;
protected:
- struct
- {
- unsigned char width;
- float left, right, top, bottom;
- } m_Glyphs[256];
-
- Texture* m_pTexture;
- unsigned char m_nFontHeight;
- bool m_bLoaded;
+ struct
+ {
+ unsigned char width;
+ float left, right, top, bottom;
+ } m_Glyphs[256];
+
+ Texture* m_pTexture;
+ unsigned char m_nFontHeight;
+ bool m_bLoaded;
};
#endif // _TEXFONT_H_