Main Page   Class Hierarchy   Alphabetical List   Compound List   File List   Compound Members   Related Pages  

sglTextureFont.hpp

00001 /*****************************************************************************
00002  * SGL: A Scene Graph Library
00003  *
00004  * Copyright (C) 1997-2001  Scott McMillan   All Rights Reserved.
00005  *
00006  * This library is free software; you can redistribute it and/or
00007  * modify it under the terms of the GNU Library General Public
00008  * License as published by the Free Software Foundation; either
00009  * version 2 of the License, or (at your option) any later version.
00010  *
00011  * This library is distributed in the hope that it will be useful,
00012  * but WITHOUT ANY WARRANTY; without even the implied warranty of
00013  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
00014  * Library General Public License for more details.
00015  *
00016  * You should have received a copy of the GNU Library General Public
00017  * License along with this library; if not, write to the Free
00018  * Software Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
00019  *****************************************************************************
00020  *     File: sglTexturedFont.hpp
00021  *  Created: 18 June 2001
00022  *  Summary: Class that represents a font with a texture.
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    // not implemented
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

Generated at Mon Jul 1 18:00:06 2002 for SGL by doxygen1.2.6 written by Dimitri van Heesch, © 1997-2001