Gray C++ Libraries  0.0.2
A set of C++ libraries for MSVC, GNU on Windows, WinCE, Linux
cDXFont.h
Go to the documentation of this file.
1 //
5 //
6 
7 #ifndef _INC_cDXFont_H
8 #define _INC_cDXFont_H
9 #ifndef NO_PRAGMA_ONCE
10 #pragma once
11 #endif
12 
13 #include "cDXBase.h"
15 
16 #ifdef USE_DXX
18 #include "GrayLib/include/WinAPI/WinTypes.h" // cWinSize
20 
21 namespace GrayLib
22 {
23  class cRectI;
24 };
25 namespace Gray3D
26 {
27  class GRAY3D_LINK cDXFont : public cDXBaseT<ID3DXFont> // cFontBase
28  {
34 
35  typedef cDXBaseT<ID3DXFont> SUPER_t;
36 
37  private:
38  cWinFontCfg m_FontCfg;
39  cWinSize m_MeasureA;
40  int m_iTabWidth;
41 
42  private:
43  void SetFontChanged(); // m_MeasureA
44  bool MeasureStr(cWinSize& sizeret, const GChar_t* pszText);
45  void MeasureFont();
46 
47  public:
48  cDXFont(int iFontSize = 0, const GChar_t* pszFontFaceName = k_szFontDef);
49  cDXFont(const cDXFont& Font);
50  virtual ~cDXFont();
51 
52  static const int k_SIZE_MIN = 6;
53  static const int k_SIZE_MAX = 80;
54  static const int k_SIZE_DEFAULT = 12;
55  static const GChar_t* k_szFontDef;
56 
57  operator const cWinFontCfg&() const
58  {
59  return m_FontCfg;
60  }
61  ID3DXFont* get_DXFont() const
62  {
63  return m_pDXObj;
64  }
65 
66  bool IsSameFont(const cWinFontCfg& fontcfg) const
67  {
68  return m_FontCfg.IsSameFont(fontcfg);
69  }
70  void put_Font(const cDXFont& fontcfg);
71 
72  void put_LogFontCfg(const cWinFontCfg& fontcfg);
73  bool put_LogFontSystem(UINT uType = SPI_GETICONTITLELOGFONT);
74 
75  int get_FontSize() const noexcept
76  {
77  return m_FontCfg.lfHeight;
78  }
79  int get_FontSizeA() const
80  {
81  return m_FontCfg.get_FontSizeA(); // sort of like pixel height but not exactly.
82  }
83  void put_FontSize(PIXELS_t iFontSize);
84  void put_FontWeight(int lfWeight)
85  {
86  if (m_FontCfg.lfWeight == lfWeight)
87  return;
88  m_FontCfg.lfWeight = lfWeight; // FW_BOLD;
89  SetFontChanged();
90  }
91  void put_FontFaceName(const GChar_t* pszFaceName)
92  {
93  if (pszFaceName == nullptr)
94  pszFaceName = _GT("");
95  if (!StrT::Cmp(pszFaceName, m_FontCfg.lfFaceName))
96  return;
97  StrT::CopyLen<GChar_t>(m_FontCfg.lfFaceName, pszFaceName, _countof(m_FontCfg.lfFaceName));
98  SetFontChanged();
99  }
100 
101  bool put_FontHeight(PIXELS_t iHeightPixels); // try to make a font of this size in pixels
102  void put_FontSizeStr(SIZE size, const cString& sText, DWORD dwFormatFlags = 0); // try to make a font of this size in pixels
103  PIXELS_t get_FontHeight(); // actual measured height of the font in pixels.
104  PIXELS_t get_FontWidth(); // actual measured width of the font in pixels.
105 
106  HRESULT LoadFont();
107 
108  HRESULT GetFontRectW(cRectI& rect, const wchar_t* pwText, StrLen_t iSizeChars, DWORD dwFormatFlags = 0);
109  HRESULT GetFontRectA(cRectI& rectText, const char* pszText, StrLen_t iSizeChars = -1, DWORD dwFormatFlags = 0);
110  HRESULT GetFontRectS(cRectI& rectText, const cString& sText, DWORD dwFormatFlags = 0);
111 
112  HRESULT AddTabs(char* pszText, int iWidthTabs, PIXELS_t iTabWidth = 0);
113  PIXELS_t CheckTabWidth();
114 
115  HRESULT DrawTextW(ID3DXSprite* pSprite, const wchar_t* pwText, StrLen_t iSizeChars, cRectI& rect, DWORD dwFormatFlags, D3DCOLOR crTextColor);
116  HRESULT DrawTextEmbossW(ID3DXSprite* pSprite, const wchar_t* pwText, StrLen_t iSizeChars, cRectI& rect, DWORD dwFormatFlags, D3DCOLOR crTextColor);
117 
118  HRESULT DrawTextS(ID3DXSprite* pSprite, const cString& sText, cRectI& rect, DWORD dwFormatFlags, D3DCOLOR crTextColor);
119  HRESULT DrawTextEmbossS(ID3DXSprite* pSprite, const cString& sText, cRectI& rect, DWORD dwFormatFlags, D3DCOLOR crTextColor);
120 
121  UNITTEST_FRIEND(cDXFont);
122  };
123 };
124 #endif // USE_DXX
125 #endif // _INC_cDXFont_H
#define GRAY3D_LINK
Definition: Gray3D.h:15
#define _GT(x)
like _T(x) macro for static text.
Definition: StrConst.h:27
INT32 HRESULT
_WIN32 style error codes. INT32
Definition: SysTypes.h:465
DWORD D3DCOLOR
Stuff normally defined in windows.h or DirectX headers.
Definition: cColorRef.h:24
#define _countof(a)
Definition: cKernel.h:35
#define UNITTEST_FRIEND(n)
Define this in the class body to be unit tested. Allow the unit test to access private/protected stuf...
Definition: cUnitTestDecl.h:17
Definition: Gray3D.cpp:12
Definition: cMesh.h:22
interface const RECTQ_t & rect
Definition: cQuadtree.h:44
int PIXELS_t
Count of pixels in a dimension of some image/surface.
Definition: cSurfaceInfo.h:20
int StrLen_t
the length of a string in chars (bytes for UTF8, wchar_t for UNICODE). or offset in characters....
Definition: StrConst.h:32
char GChar_t
My version of TCHAR, _TCHAR.
Definition: StrConst.h:26
cStringT< GChar_t > cString
Definition: cString.h:636
static __DECL_IMPORT COMPARE_t __stdcall Cmp(const TYPE *pszStr1, const TYPE *pszStr2)