My Project
GUIUniBuffer.h
1 #pragma once
2 #if defined(USE_DIRECTX_RENDERER) || 0
3 #include <list>
4 #include <usp10.h>
5 #include <dimm.h>
6 namespace ParaEngine
7 {
8  struct GUIFontElement;
9 
10  class CUniLine{
11  public:
12  CUniLine( int nInitialSize = 0 );
13  ~CUniLine();
14 
15  static void Initialize();
16  static void Uninitialize();
17 
18  int GetBufferSize() const;
19  bool SetBufferSize( int nSize );
20  int GetTextSize() const;
21  const char16_t* GetBuffer() const;
28  int GetBufferA(std::string& out) const;
29 
30  const char16_t& operator[]( int n ) const { return m_pwszBuffer[n]; }
31  char16_t& operator[](int n);
32  GUIFontElement* GetFontNode() const{ return m_pFontNode; }
33  void SetFontNode( GUIFontElement *pFontNode ) { m_pFontNode = pFontNode; }
34  void Clear();
35 
36  bool InsertChar(int nIndex, char16_t wchar); // Inserts the char at specified index. If nIndex == -1, insert to the end.
37  bool RemoveChar( int nIndex ); // Removes the char at specified index. If nIndex == -1, remove the last char.
38  bool InsertString(int nIndex, const char16_t *pStr, int nCount = -1); // Inserts the first nCount characters of the string pStr at specified index. If nCount == -1, the entire string is inserted. If nIndex == -1, insert to the end.
39  bool InsertStringA(int nIndex, const char*pStr, int nCount = -1); // Inserts the first nCount characters of the string pStr at specified index. If nCount == -1, the entire string is inserted. If nIndex == -1, insert to the end.
40  bool SetTextA( LPCSTR szText );
41  bool SetText( const char16_t* wszText );
42  bool IsEmpty();
43  // Uniscribe
44  HRESULT CPtoX( int nCP, BOOL bTrail, int *pX );
45  HRESULT XtoCP( int nX, int *pCP, int *pnTrail );
46  void GetPriorItemPos( int nCP, int *pPrior );
47  void GetNextItemPos( int nCP, int *pPrior );
48  const TEXTMETRIC& GetTextMetric(){
49  if( m_bAnalyseRequired )
50  Analyse();
51  return m_TextMetric;
52  }
53  int GetHeight()const;
54  private:
55  HRESULT Analyse(); // Uniscribe -- Analyse() analyses the string in the buffer
56 
57  char16_t* m_pwszBuffer; // Buffer to hold text
58  int m_nBufferSize; // Size of the buffer allocated, in characters
59 
60  // Uniscribe-specific
61  GUIFontElement* m_pFontNode; // Font node for the font that this buffer uses
62  bool m_bAnalyseRequired; // True if the string has changed since last analysis.
63  SCRIPT_STRING_ANALYSIS m_Analysis; // Analysis for the current string
64  TEXTMETRIC m_TextMetric; // analysis for the current font
65  private:
66  // Empty implementation of the Uniscribe API
67  static HRESULT WINAPI Dummy_ScriptApplyDigitSubstitution( const SCRIPT_DIGITSUBSTITUTE*, SCRIPT_CONTROL*, SCRIPT_STATE* ) { return E_NOTIMPL; }
68  static HRESULT WINAPI Dummy_ScriptStringAnalyse( HDC, const void *, int, int, int, DWORD, int, SCRIPT_CONTROL*, SCRIPT_STATE*, const int*, SCRIPT_TABDEF*, const BYTE*, SCRIPT_STRING_ANALYSIS* ) { return E_NOTIMPL; }
69  static HRESULT WINAPI Dummy_ScriptStringCPtoX( SCRIPT_STRING_ANALYSIS, int, BOOL, int* ) { return E_NOTIMPL; }
70  static HRESULT WINAPI Dummy_ScriptStringXtoCP( SCRIPT_STRING_ANALYSIS, int, int*, int* ) { return E_NOTIMPL; }
71  static HRESULT WINAPI Dummy_ScriptStringFree( SCRIPT_STRING_ANALYSIS* ) { return E_NOTIMPL; }
72  static const SCRIPT_LOGATTR* WINAPI Dummy_ScriptString_pLogAttr( SCRIPT_STRING_ANALYSIS ) { return NULL; }
73  static const int* WINAPI Dummy_ScriptString_pcOutChars( SCRIPT_STRING_ANALYSIS ) { return NULL; }
74  static bool WINAPI Dummy_GetTextMetrics(HDC, LPTEXTMETRIC){return true;}
75  // Function pointers
76  static HRESULT (WINAPI *_ScriptApplyDigitSubstitution)( const SCRIPT_DIGITSUBSTITUTE*, SCRIPT_CONTROL*, SCRIPT_STATE* );
77  static HRESULT (WINAPI *_ScriptStringAnalyse)( HDC, const void *, int, int, int, DWORD, int, SCRIPT_CONTROL*, SCRIPT_STATE*, const int*, SCRIPT_TABDEF*, const BYTE*, SCRIPT_STRING_ANALYSIS* );
78  static HRESULT (WINAPI *_ScriptStringCPtoX)( SCRIPT_STRING_ANALYSIS, int, BOOL, int* );
79  static HRESULT (WINAPI *_ScriptStringXtoCP)( SCRIPT_STRING_ANALYSIS, int, int*, int* );
80  static HRESULT (WINAPI *_ScriptStringFree)( SCRIPT_STRING_ANALYSIS* );
81  static const SCRIPT_LOGATTR* (WINAPI *_ScriptString_pLogAttr)( SCRIPT_STRING_ANALYSIS );
82  static const int* (WINAPI *_ScriptString_pcOutChars)( SCRIPT_STRING_ANALYSIS );
83  static bool (WINAPI *_GetTextMetrics)(HDC, LPTEXTMETRIC);
84  static HINSTANCE s_hDll; // Uniscribe DLL handle
85  };
86 
87  class CUniBuffer
88  {
89  public:
90  CUniBuffer( int nInitialSize = 1 );
91  ~CUniBuffer();
92 
93  static void Initialize();
94  static void Uninitialize();
95 
96  int GetBufferSize() const{
97  if (!m_bMultiline) {
98  return m_lines.front()->GetBufferSize();
99  }
100  return -1;
101  }
102  bool SetBufferSize( int nSize );
103  int GetTextSize()const;
104  const char16_t* GetBuffer()const {
105  if (!m_bMultiline) {
106  return m_lines.front()->GetBuffer();
107  }
108  return NULL;
109  }
116  int GetBufferA(std::string& out) const;
117  char16_t& operator[]( int n );
118  GUIFontElement* GetFontNode() const{
119  if (!m_bMultiline) {
120  return m_lines.front()->GetFontNode();
121  }
122  return NULL;
123  }
124  void SetFontNode( GUIFontElement *pFontNode ) {
125  if (!m_bMultiline) {
126  m_lines.front()->SetFontNode(pFontNode);
127  }
128  }
129  void Clear();
130 
131  bool InsertChar(int nIndex, char16_t wchar); // Inserts the char at specified index. If nIndex == -1, insert to the end.
132  bool RemoveChar( int nIndex ); // Removes the char at specified index. If nIndex == -1, remove the last char.
133  bool InsertString(int nIndex, const char16_t *pStr, int nCount = -1); // Inserts the first nCount characters of the string pStr at specified index. If nCount == -1, the entire string is inserted. If nIndex == -1, insert to the end.
134  bool InsertStringA( int nIndex, const char *pStr, int nCount = -1 ); // Inserts the first nCount characters of the string pStr at specified index. If nCount == -1, the entire string is inserted. If nIndex == -1, insert to the end.
135  bool SetTextA( const char* szText );
136  bool SetText( const char16_t* wszText );
137 
138  // Uniscribe
139  HRESULT CPtoXY( int nCP, BOOL bTrail, int *pX, int *pY);
140  HRESULT XYtoCP( int nX, int nY, int *pCP, int *pnTrail);
141  void GetPriorItemPos( int nCP, int *pPrior );
142  void GetNextItemPos( int nCP, int *pPrior );
143 
144  bool GetMultiline()const{return m_bMultiline;}
145  void SetMultiline(bool multiline){m_bMultiline=multiline;};
146 
153  int GetLineAt(int nIndex);
154 
155  CUniLine *GetCurLine(){return m_curLine;};
156 
157  bool IsEmpty();
158  private:
159 
160 
161  bool m_bMultiline;
162  CUniLine* m_curLine;
163  // Uniscribe-specific
164  //GUIFontElement* m_pFontNode; // Font node for the font that this buffer uses
165  //bool m_bAnalyseRequired; // True if the string has changed since last analysis.
166  //SCRIPT_STRING_ANALYSIS m_Analysis; // Analysis for the current string
167  //TEXTMETRICW m_TextMetric; // analysis for the current font
168  list<CUniLine*> m_lines;
169 
170  };
171 }
172 #else
173 namespace ParaEngine
174 {
177  {
178  public:
179  static void Initialize(){};
180  static void Uninitialize(){};
181  int GetTextSize()const;
182  const char16_t* GetBuffer()const;
183 
184  char16_t& operator[](int n);
191  int GetBufferA(std::string& out) const;
192  // Inserts the char at specified index. If nIndex == -1, insert to the end.
193  bool InsertChar(int nIndex, char16_t wchar);
194  // Removes the char at specified index. If nIndex == -1, remove the last char.
195  bool RemoveChar(int nIndex);
196  // Inserts the first nCount characters of the string pStr at specified index. If nCount == -1, the entire string is inserted. If nIndex == -1, insert to the end.
197  bool InsertString(int nIndex, const char16_t *pStr, int nCount = -1);
198  // Inserts the first nCount characters of the string pStr at specified index. If nCount == -1, the entire string is inserted. If nIndex == -1, insert to the end.
199  bool InsertStringA(int nIndex, const char *pStr, int nCount = -1);
200  bool SetTextA(LPCSTR szText);
201  bool SetText(const char16_t* wszText);
202  void Clear();
203 
204  HRESULT CPtoXY(int nCP, BOOL bTrail, int *pX, int *pY);
205  HRESULT XYtoCP(int nX, int nY, int *pCP, int *pnTrail);
206  void GetPriorItemPos(int nCP, int *pPrior);;
207  void GetNextItemPos(int nCP, int *pPrior);;
208 
209  bool GetMultiline()const{ return false; }
210  void SetMultiline(bool multiline){};
211 
212  const std::string& GetUtf8Text() const { return m_utf8Text; }
213  const std::u16string& GetUtf16Text() const { return m_utf16Text; }
214 
215  bool IsEmpty();
216  protected:
217  std::string m_utf8Text;
218  std::u16string m_utf16Text;
219  };
220 }
221 #endif
different physics engine has different winding order.
Definition: EventBinding.h:32
Null implementation.
Definition: GUIUniBuffer.h:176