00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025 #ifndef __SGL_TEXTUREFONT_HPP
00026 #define __SGL_TEXTUREFONT_HPP
00027
00028 #include <sgl.h>
00029 #include <sglObject.hpp>
00030 #include <sglVector.hpp>
00031
00032 #include <map>
00033 #include <string>
00034
00035 class sglTexture2D;
00036 class sglBitmapFont;
00037
00043 class SGL_DLL_API sglTextureFont : public sglObject
00044 {
00045 public:
00057 sglTextureFont(const sglBitmapFont &font,
00058 bool use_invalid_char,
00059 char invalid_char);
00060
00074 sglTextureFont(const sglBitmapFont &font,
00075 const vector<char> &valid_chars,
00076 bool use_invalid_char,
00077 char invalid_char);
00078
00080 ~sglTextureFont();
00081
00096 unsigned int getStringInfo(const string &str,
00097 sglVec3f *coord,
00098 sglVec2f *tex_coords,
00099 float scale,
00100 const sglVec3f &offset,
00101 bool vertical = false) const;
00102
00106 sglTexture2D* getTexture() const { return m_texture; }
00107
00111 unsigned int getHeight() const;
00112
00117 unsigned int getCharWidth(char c) const;
00118
00122 unsigned int getCharWidthMax() const { return m_max_width; }
00123
00128 unsigned int getStringWidth(const string &str) const;
00129
00130 private:
00131 void computeTextureSize(
00132 unsigned int &tex_width,
00133 unsigned int &tex_height);
00134
00135 void generateTexture(
00136 const sglBitmapFont &font,
00137 unsigned int tex_width,
00138 unsigned int tex_height);
00139
00140
00141 sglTextureFont();
00142 sglTextureFont(const sglTextureFont &);
00143 sglTextureFont& operator=(const sglTextureFont &);
00144
00145 private:
00146 struct TexCorners
00147 {
00148 sglVec2f& operator[](unsigned int indx) { return m_corners[indx]; }
00149 const sglVec2f& operator[](unsigned int indx) const
00150 { return m_corners[indx]; }
00151
00152 sglVec2f m_corners[4];
00153 };
00154
00155 private:
00156 sglTexture2D *m_texture;
00157 void *m_image;
00158
00159 unsigned int m_height;
00160 unsigned int m_max_width;
00161
00162 char m_invalid_char;
00163 bool m_invalid_char_flag;
00164
00165 map<char, bool> m_valid_chars;
00166 map<char, TexCorners> m_tex_coords;
00167 map<char, float> m_char_widths;
00168 };
00169
00170 #endif