ScummVM API documentation
text.h
1 /* ScummVM - Graphic Adventure Engine
2  *
3  * ScummVM is the legal property of its developers, whose names
4  * are too numerous to list here. Please refer to the COPYRIGHT
5  * file distributed with this source distribution.
6  *
7  * This program is free software: you can redistribute it and/or modify
8  * it under the terms of the GNU General Public License as published by
9  * the Free Software Foundation, either version 3 of the License, or
10  * (at your option) any later version.
11  *
12  * This program is distributed in the hope that it will be useful,
13  * but WITHOUT ANY WARRANTY; without even the implied warranty of
14  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15  * GNU General Public License for more details.
16  *
17  * You should have received a copy of the GNU General Public License
18  * along with this program. If not, see <http://www.gnu.org/licenses/>.
19  *
20  */
21 
22 #ifndef BAGEL_BOFLIB_GFX_TEXT_H
23 #define BAGEL_BOFLIB_GFX_TEXT_H
24 
25 #include "graphics/font.h"
26 #include "bagel/boflib/object.h"
27 #include "bagel/spacebar/boflib/gfx/bitmap.h"
28 #include "bagel/boflib/error.h"
29 #include "bagel/boflib/string.h"
30 
31 namespace Bagel {
32 namespace SpaceBar {
33 
34 #define NUM_POINT_SIZES 32
35 
36 // Text color and offset definitions
37 #define CTEXT_COLOR RGB(0,0,0)
38 #define CTEXT_SHADOW_COLOR RGB(0,0,0)
39 #define CTEXT_YELLOW RGB(255, 255, 0)
40 #define CTEXT_WHITE RGB(255, 255, 255)
41 
42 #define CTEXT_SHADOW_DX 2
43 #define CTEXT_SHADOW_DY 2
44 
45 // Text justification definitions
46 enum {
47  JUSTIFY_CENTER = 0,
48  JUSTIFY_LEFT = 1,
49  JUSTIFY_RIGHT = 2,
50  JUSTIFY_WRAP = 3
51 };
52 
53 // Text weight definitions
54 //
55 
56 /*
57  * DrawText Format Flags
58  */
59 #define DT_TOP 0x00000000
60 #define DT_LEFT 0x00000000
61 #define DT_CENTER 0x00000001
62 #define DT_RIGHT 0x00000002
63 #define DT_VCENTER 0x00000004
64 #define DT_BOTTOM 0x00000008
65 #define DT_WORDBREAK 0x00000010
66 #define DT_SINGLELINE 0x00000020
67 #define DT_EXPANDTABS 0x00000040
68 #define DT_TABSTOP 0x00000080
69 #define DT_NOCLIP 0x00000100
70 #define DT_EXTERNALLEADING 0x00000200
71 #define DT_CALCRECT 0x00000400
72 #define DT_NOPREFIX 0x00000800
73 #define DT_intERNAL 0x00001000
74 
75 
76 enum {
77  FW_NORMAL,
78  FW_BOLD,
79  FW_MEDIUM,
80 };
81 
82 #define FONT_DEFAULT 0
83 #define FONT_MONO 1
84 
85 #define TEXT_DONTCARE 0
86 #define TEXT_THIN FW_THIN
87 #define TEXT_EXTRALIGHT FW_EXTRALIGHT
88 #define TEXT_ULTRALIGHT FW_ULTRALIGHT
89 #define TEXT_LIGHT FW_LIGHT
90 #define TEXT_NORMAL FW_NORMAL
91 #define TEXT_REGULAR FW_REGULAR
92 #define TEXT_MEDIUM FW_MEDIUM
93 #define TEXT_SEMIBOLD FW_SEMIBOLD
94 #define TEXT_DEMIBOLD FW_DEMIBOLD
95 #define TEXT_BOLD FW_BOLD
96 #define TEXT_EXTRABOLD FW_EXTRABOLD
97 #define TEXT_ULTRABOLD FW_ULTRABOLD
98 #define TEXT_BLACK FW_BLACK
99 #define TEXT_HEAVY FW_HEAVY
100 
101 #define FORMAT_TOP_LEFT ( DT_TOP | DT_LEFT )
102 #define FORMAT_TOP_RIGHT ( DT_TOP | DT_RIGHT )
103 #define FORMAT_TOP_CENTER ( DT_TOP | DT_CENTER )
104 #define FORMAT_BOT_LEFT ( DT_BOTTOM | DT_LEFT )
105 #define FORMAT_BOT_RIGHT ( DT_BOTTOM | DT_RIGHT )
106 #define FORMAT_BOT_CENTER ( DT_BOTTOM | DT_CENTER )
107 #define FORMAT_CENTER_LEFT ( DT_VCENTER | DT_LEFT )
108 #define FORMAT_CENTER_RIGHT ( DT_VCENTER | DT_RIGHT )
109 #define FORMAT_CENTER_CENTER ( DT_VCENTER | DT_CENTER )
110 #define FORMAT_SINGLE_LINE DT_SINGLELINE
111 #define FORMAT_MULTI_LINE DT_WORDBREAK
112 #define FORMAT_DEFAULT ( FORMAT_TOP_LEFT | FORMAT_MULTI_LINE )
113 
114 #define FONT_DEFAULT_SIZE (-14)
115 #define FONT_8POINT 8
116 #define FONT_10POINT 10
117 #define FONT_12POINT 12
118 #define FONT_14POINT 14
119 #define FONT_15POINT 15
120 #define FONT_18POINT 18
121 #define FONT_20POINT 20
122 #define TEXT_DEFAULT_FACE TEXT_BOLD
123 
124 
125 class CBofText : public CBofObject, public CBofError {
126 public:
127  // Constructors
128  CBofText();
129  CBofText(const CBofRect *pRect, int nJustify = JUSTIFY_CENTER, uint32 nFormatFlags = FORMAT_DEFAULT);
130  virtual ~CBofText();
131 
132  // Implementation
133  //
134 
143  ErrorCode setupText(const CBofRect *pRect, int nJustify = JUSTIFY_CENTER, uint32 nFormatFlags = FORMAT_DEFAULT);
144  ErrorCode setupTextOpt(const CBofRect *pRect, int nJustify = JUSTIFY_CENTER, uint32 nFormatFlags = FORMAT_DEFAULT);
145 
146  void setText(const CBofString &cString) {
147  _cCurString = cString;
148  }
149  void setColor(const COLORREF cColor) {
150  _cTextColor = cColor;
151  }
152  void SetSize(const int nSize) {
153  _nCurSize = nSize;
154  }
155  void setWeight(const int nWeight) {
156  _nCurWeight = nWeight;
157  }
158 
159  void setShadowColor(const COLORREF cColor) {
160  _cShadowColor = cColor;
161  }
162  void setShadowSize(int nDX, int nDY) {
163  _nShadow_DX = nDX;
164  _nShadow_DY = nDY;
165  }
166 
167  CBofString getText() const {
168  return _cCurString;
169  }
170  COLORREF getColor() const {
171  return _cTextColor;
172  }
173  int getSize() const {
174  return _nCurSize;
175  }
176  int getWeight() const {
177  return _nCurWeight;
178  }
179 
185  ErrorCode erase(CBofWindow *pWnd);
186 
192  ErrorCode erase(CBofBitmap *pBmp);
193 
199  ErrorCode display(CBofWindow *pWnd);
200 
206  ErrorCode display(CBofBitmap *pBmp);
207 
218  ErrorCode display(CBofWindow *pWnd, const char *pszText, int nSize, int nWeight, COLORREF cColor = CTEXT_COLOR, int nFont = FONT_DEFAULT);
219 
230  ErrorCode display(CBofBitmap *pBmp, const char *pszText, int nSize, int nWeight, COLORREF cColor = CTEXT_COLOR, int nFont = FONT_DEFAULT);
231 
245  ErrorCode displayShadowed(CBofWindow *pWnd, const char *pszText, int nSize,
246  int nWeight, COLORREF cColor, COLORREF cShadow = CTEXT_SHADOW_COLOR,
247  int nDX = CTEXT_SHADOW_DX, int nDY = CTEXT_SHADOW_DY, int nFont = FONT_DEFAULT);
248 
249 
250  void flushBackground() {
251  _bSaved = false;
252  }
253 
254  static ErrorCode initialize();
255  static ErrorCode shutdown();
256 
268  ErrorCode displayTextEx(CBofBitmap *pBmp, const char *pszText, CBofRect *pRect, int nSize, int nWeight, bool bShadowed, int nFont = FONT_DEFAULT);
269 
270  static Graphics::Font *getFont(int nFont, int nSize, int nWeight);
271 
272 private:
276  void initializeFields();
277 
289  ErrorCode displayText(CBofWindow *pWnd, const char *pszText, CBofRect *pRect, int nSize, int nWeight, bool bShadowed, int nFont = FONT_DEFAULT);
290  ErrorCode displayText(CBofBitmap *pBmp, const char *pszText, CBofRect *pRect, int nSize, int nWeight, bool bShadowed, int nFont = FONT_DEFAULT);
291 
292  void displayLine(Graphics::Font *font, Graphics::ManagedSurface &surface, const Common::U32String &line,
293  int left, int top, int width, int color, Graphics::TextAlign align);
294 
295 protected:
296  CBofString _cCurString; // text to be displayed
297  CBofRect _cRect; // bounding rectangle of text area
298  CBofPoint _cPosition; // upper left corner of text displayed
299  CBofSize _cSize; // dx/dy size of the text bitmap
300  COLORREF _cTextColor; // color to use for the text itself
301  COLORREF _cShadowColor; // color to use for the text's shadow
302  CBofBitmap *_pBackground; // bitmap for the text's background
303  CBofBitmap *_pWork; // bitmap for the work area
304 
305  int _nCurSize; // point size of current text
306  int _nCurWeight; // style of current text
307 
308  int _nJustify; // positioning within the rectangle
309  int _nShadow_DX; // horizontal offset for shadow
310  int _nShadow_DY; // vertical offset for shadow
311  uint32 _nFormatFlags; // multi line formatting flags
312  bool _bMultiLine; // multi vs single line formatting
313  bool _bSaved;
314 
315  static Graphics::Font *_defaultFonts[NUM_POINT_SIZES];
316  static Graphics::Font *_fixedFonts[NUM_POINT_SIZES];
317 
318  static bool _initialized;
319 
320  static int _tabStop; // tabstop table
321 };
322 
323 // Global text functions
324 //
325 ErrorCode paintText(CBofWindow *pWnd, CBofRect *pRect, const char *, int nSize, int nWeight, COLORREF cColor = CTEXT_COLOR, int nJustify = JUSTIFY_CENTER, uint32 nFormat = FORMAT_DEFAULT, int nFont = FONT_DEFAULT);
326 ErrorCode paintText(CBofBitmap *pBmp, CBofRect *pRect, const char *, int nSize, int nWeight, COLORREF cColor = CTEXT_COLOR, int nJustify = JUSTIFY_CENTER, uint32 nFormat = FORMAT_DEFAULT, int nFont = FONT_DEFAULT);
327 
328 ErrorCode paintShadowedText(CBofBitmap *, CBofRect *pRect, const char *, int nSize, int nWeight, COLORREF cColor = CTEXT_COLOR, int nJustify = JUSTIFY_CENTER, uint32 n = FORMAT_DEFAULT, int nFont = FONT_DEFAULT);
329 
334 CBofRect calculateTextRect(CBofWindow *pWnd, const CBofString *pStr, int nSize, int nFont);
335 CBofRect calculateTextRect(CBofRect rect, const CBofString *pStr, int nSize, int nFont);
336 
337 } // namespace SpaceBar
338 } // namespace Bagel
339 
340 #endif
Definition: managed_surface.h:51
Definition: font.h:83
TextAlign
Definition: font.h:48
Definition: object.h:28
Definition: size.h:32
Definition: window.h:53
Definition: rect.h:35
ErrorCode setupText(const CBofRect *pRect, int nJustify=JUSTIFY_CENTER, uint32 nFormatFlags=((0x00000000|0x00000000)|0x00000010))
Definition: text.h:125
ErrorCode display(CBofWindow *pWnd)
Definition: error.h:52
Definition: ustr.h:57
Definition: string.h:38
Definition: afxwin.h:27
ErrorCode erase(CBofWindow *pWnd)
Definition: point.h:32
ErrorCode displayShadowed(CBofWindow *pWnd, const char *pszText, int nSize, int nWeight, COLORREF cColor, COLORREF cShadow=RGB(0, 0, 0), int nDX=2, int nDY=2, int nFont=0)
Definition: bitmap.h:57
ErrorCode displayTextEx(CBofBitmap *pBmp, const char *pszText, CBofRect *pRect, int nSize, int nWeight, bool bShadowed, int nFont=0)