wg_renderedstring.h

00001 // wg_renderedstring.h
00002 //
00003 // CRenderedString interface
00004 // CRenderedString uses the FreeType 2 library
00005 //
00006 //
00007 // Copyright (c) 2002-2004 Rob Wiskow
00008 // rob-dev@boxedchaos.com
00009 //
00010 // This library is free software; you can redistribute it and/or
00011 // modify it under the terms of the GNU Lesser General Public
00012 // License as published by the Free Software Foundation; either
00013 // version 2.1 of the License, or (at your option) any later version.
00014 //
00015 // This library is distributed in the hope that it will be useful,
00016 // but WITHOUT ANY WARRANTY; without even the implied warranty of
00017 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
00018 // Lesser General Public License for more details.
00019 //
00020 // You should have received a copy of the GNU Lesser General Public
00021 // License along with this library; if not, write to the Free Software
00022 // Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
00023 //
00024 
00025 
00026 #ifndef _WG_RENDEREDSTRING_H_
00027 #define _WG_RENDEREDSTRING_H_
00028 
00029 #include "wg_fontengine.h"
00030 #include <vector>
00031 #include "wg_rect.h"
00032 #include "wg_color.h"
00033 #include "SDL.h"
00034 #include "std_ex.h"
00035 
00036 
00037 namespace wGui
00038 {
00039 
00040 #ifdef WIN32
00041 #pragma warning(push)
00042 #pragma warning(disable: 4512)
00043 #endif // WIN32
00044 
00047 
00048 class CRenderedString
00049 {
00050 public:
00052      enum EVAlign
00053      {
00054           VALIGN_NORMAL,  
00055           VALIGN_CENTER,  
00056           VALIGN_TOP,  
00057           VALIGN_BOTTOM  
00058      };
00059 
00061      enum EHAlign
00062      {
00063           HALIGN_LEFT,  
00064           HALIGN_CENTER,  
00065           HALIGN_RIGHT  
00066      };
00067 
00073      CRenderedString(CFontEngine* pFontEngine, const std::wstring& sString, EVAlign eVertAlign = VALIGN_NORMAL, EHAlign eHorzAlign = HALIGN_LEFT);
00074 
00080      void Draw(SDL_Surface* pSurface, const CRect& BoundingRect, const CPoint& OriginPoint, const CRGBColor& FontColor = DEFAULT_LINE_COLOR) const;
00081 
00086      void GetMetrics(CPoint* pBoundedDimensions = 0, CPoint* pOriginOffset = 0, std::vector<CRect>* pCharacterRects = 0) const;
00087 
00090      unsigned int GetLength(void) const { return stdex::safe_static_cast<unsigned int>(m_sString.size()); }
00091 
00094      unsigned int GetMaxFontHeight(void);
00095 
00098      unsigned int GetMaxFontWidth(void);
00099 
00102      void SetMaskChar(wchar_t MaskChar) { m_MaskChar = MaskChar; }
00103 
00106      wchar_t GetMaskChar(void) const { return m_MaskChar; }
00107 
00108 
00109 protected:
00110      CFontEngine* m_pFontEngine;  
00111      std::wstring m_sString;  
00112      wchar_t m_MaskChar;  
00113 
00114 
00115 private:
00116      EVAlign m_eVertAlign;  
00117      EHAlign m_eHorzAlign;  
00118      mutable CPoint m_CachedBoundedDimensions;  
00119      mutable CPoint m_OriginOffset;  
00120      mutable std::vector<CRect> m_CachedCharacterRects;  
00121      mutable bool m_bCachedMetricsValid;  
00122      int m_MaxFontHeight; 
00123      int m_MaxFontWidth; 
00124 };
00125 
00126 #ifdef WIN32
00127 #pragma warning(pop)
00128 #endif // WIN32
00129 
00130 }
00131 
00132 #endif  // _WG_RENDEREDSTRING_H_

Generated on Wed May 16 23:11:26 2007 for wGui by  doxygen 1.5.1