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/boflib/gfx/bitmap.h"
28 #include "bagel/boflib/error.h"
29 #include "bagel/boflib/string.h"
30 
31 namespace Bagel {
32 
33 #define NUM_POINT_SIZES 32
34 
35 // Text color and offset definitions
36 #define CTEXT_COLOR RGB(0,0,0)
37 #define CTEXT_SHADOW_COLOR RGB(0,0,0)
38 #define CTEXT_YELLOW RGB(255, 255, 0)
39 #define CTEXT_WHITE RGB(255, 255, 255)
40 
41 #define CTEXT_SHADOW_DX 2
42 #define CTEXT_SHADOW_DY 2
43 
44 // Text justification definitions
45 #define JUSTIFY_CENTER 0
46 #define JUSTIFY_LEFT 1
47 #define JUSTIFY_RIGHT 2
48 #define JUSTIFY_WRAP 3
49 
50 // Text weight definitions
51 //
52 
53 /*
54  * DrawText Format Flags
55  */
56 #define DT_TOP 0x00000000
57 #define DT_LEFT 0x00000000
58 #define DT_CENTER 0x00000001
59 #define DT_RIGHT 0x00000002
60 #define DT_VCENTER 0x00000004
61 #define DT_BOTTOM 0x00000008
62 #define DT_WORDBREAK 0x00000010
63 #define DT_SINGLELINE 0x00000020
64 #define DT_EXPANDTABS 0x00000040
65 #define DT_TABSTOP 0x00000080
66 #define DT_NOCLIP 0x00000100
67 #define DT_EXTERNALLEADING 0x00000200
68 #define DT_CALCRECT 0x00000400
69 #define DT_NOPREFIX 0x00000800
70 #define DT_intERNAL 0x00001000
71 
72 
73 enum {
74  FW_NORMAL,
75  FW_BOLD,
76  FW_MEDIUM,
77 };
78 
79 #define FONT_DEFAULT 0
80 #define FONT_MONO 1
81 
82 #define TEXT_DONTCARE 0
83 #define TEXT_THIN FW_THIN
84 #define TEXT_EXTRALIGHT FW_EXTRALIGHT
85 #define TEXT_ULTRALIGHT FW_ULTRALIGHT
86 #define TEXT_LIGHT FW_LIGHT
87 #define TEXT_NORMAL FW_NORMAL
88 #define TEXT_REGULAR FW_REGULAR
89 #define TEXT_MEDIUM FW_MEDIUM
90 #define TEXT_SEMIBOLD FW_SEMIBOLD
91 #define TEXT_DEMIBOLD FW_DEMIBOLD
92 #define TEXT_BOLD FW_BOLD
93 #define TEXT_EXTRABOLD FW_EXTRABOLD
94 #define TEXT_ULTRABOLD FW_ULTRABOLD
95 #define TEXT_BLACK FW_BLACK
96 #define TEXT_HEAVY FW_HEAVY
97 
98 #define FORMAT_TOP_LEFT ( DT_TOP | DT_LEFT )
99 #define FORMAT_TOP_RIGHT ( DT_TOP | DT_RIGHT )
100 #define FORMAT_TOP_CENTER ( DT_TOP | DT_CENTER )
101 #define FORMAT_BOT_LEFT ( DT_BOTTOM | DT_LEFT )
102 #define FORMAT_BOT_RIGHT ( DT_BOTTOM | DT_RIGHT )
103 #define FORMAT_BOT_CENTER ( DT_BOTTOM | DT_CENTER )
104 #define FORMAT_CENTER_LEFT ( DT_VCENTER | DT_LEFT )
105 #define FORMAT_CENTER_RIGHT ( DT_VCENTER | DT_RIGHT )
106 #define FORMAT_CENTER_CENTER ( DT_VCENTER | DT_CENTER )
107 #define FORMAT_SINGLE_LINE DT_SINGLELINE
108 #define FORMAT_MULTI_LINE DT_WORDBREAK
109 #define FORMAT_DEFAULT ( FORMAT_TOP_LEFT | FORMAT_MULTI_LINE )
110 
111 #define FONT_DEFAULT_SIZE (-14)
112 #define FONT_8POINT 8
113 #define FONT_10POINT 10
114 #define FONT_12POINT 12
115 #define FONT_14POINT 14
116 #define FONT_15POINT 15
117 #define FONT_18POINT 18
118 #define FONT_20POINT 20
119 #define TEXT_DEFAULT_FACE TEXT_BOLD
120 
121 
122 class CBofText: public CBofObject, public CBofError {
123 public:
124  // Constructors
125  CBofText();
126  CBofText(const CBofRect *pRect, int nJustify = JUSTIFY_CENTER, uint32 nFormatFlags = FORMAT_DEFAULT);
127  virtual ~CBofText();
128 
129  // Implementation
130  //
131 
140  ErrorCode setupText(const CBofRect *pRect, int nJustify = JUSTIFY_CENTER, uint32 nFormatFlags = FORMAT_DEFAULT);
141  ErrorCode setupTextOpt(const CBofRect *pRect, int nJustify = JUSTIFY_CENTER, uint32 nFormatFlags = FORMAT_DEFAULT);
142 
143  void setText(const CBofString &cString) {
144  _cCurString = cString;
145  }
146  void setColor(const RGBCOLOR cColor) {
147  _cTextColor = cColor;
148  }
149  void SetSize(const int nSize) {
150  _nCurSize = nSize;
151  }
152  void setWeight(const int nWeight) {
153  _nCurWeight = nWeight;
154  }
155 
156  void setShadowColor(const RGBCOLOR cColor) {
157  _cShadowColor = cColor;
158  }
159  void setShadowSize(int nDX, int nDY) {
160  _nShadow_DX = nDX;
161  _nShadow_DY = nDY;
162  }
163 
164  CBofString getText() const {
165  return _cCurString;
166  }
167  RGBCOLOR getColor() const {
168  return _cTextColor;
169  }
170  int getSize() const {
171  return _nCurSize;
172  }
173  int getWeight() const {
174  return _nCurWeight;
175  }
176 
182  ErrorCode erase(CBofWindow *pWnd);
183 
189  ErrorCode erase(CBofBitmap *pBmp);
190 
196  ErrorCode display(CBofWindow *pWnd);
197 
203  ErrorCode display(CBofBitmap *pBmp);
204 
215  ErrorCode display(CBofWindow *pWnd, const char *pszText, int nSize, int nWeight, RGBCOLOR cColor = CTEXT_COLOR, int nFont = FONT_DEFAULT);
216 
227  ErrorCode display(CBofBitmap *pBmp, const char *pszText, int nSize, int nWeight, RGBCOLOR cColor = CTEXT_COLOR, int nFont = FONT_DEFAULT);
228 
242  ErrorCode displayShadowed(CBofWindow *pWnd, const char *pszText, int nSize,
243  int nWeight, RGBCOLOR cColor, RGBCOLOR cShadow = CTEXT_SHADOW_COLOR,
244  int nDX = CTEXT_SHADOW_DX, int nDY = CTEXT_SHADOW_DY, int nFont = FONT_DEFAULT);
245 
246 
247  void flushBackground() {
248  _bSaved = false;
249  }
250 
251  static ErrorCode initialize();
252  static ErrorCode shutdown();
253 
265  ErrorCode displayTextEx(CBofBitmap *pBmp, const char *pszText, CBofRect *pRect, int nSize, int nWeight, bool bShadowed, int nFont = FONT_DEFAULT);
266 
267  static Graphics::Font *getFont(int nFont, int nSize, int nWeight);
268 
269 private:
273  void initializeFields();
274 
286  ErrorCode displayText(CBofWindow *pWnd, const char *pszText, CBofRect *pRect, int nSize, int nWeight, bool bShadowed, int nFont = FONT_DEFAULT);
287  ErrorCode displayText(CBofBitmap *pBmp, const char *pszText, CBofRect *pRect, int nSize, int nWeight, bool bShadowed, int nFont = FONT_DEFAULT);
288 
289  void displayLine(Graphics::Font *font, Graphics::ManagedSurface &surface, const Common::U32String &line,
290  int left, int top, int width, int color, Graphics::TextAlign align);
291 
292 protected:
293  CBofString _cCurString; // text to be displayed
294  CBofRect _cRect; // bounding rectangle of text area
295  CBofPoint _cPosition; // upper left corner of text displayed
296  CBofSize _cSize; // dx/dy size of the text bitmap
297  RGBCOLOR _cTextColor; // color to use for the text itself
298  RGBCOLOR _cShadowColor; // color to use for the text's shadow
299  CBofBitmap *_pBackground; // bitmap for the text's background
300  CBofBitmap *_pWork; // bitmap for the work area
301 
302  int _nCurSize; // point size of current text
303  int _nCurWeight; // style of current text
304 
305  int _nJustify; // positioning within the rectangle
306  int _nShadow_DX; // horizontal offset for shadow
307  int _nShadow_DY; // vertical offset for shadow
308  uint32 _nFormatFlags; // multi line formatting flags
309  bool _bMultiLine; // multi vs single line formatting
310  bool _bSaved;
311 
312  static Graphics::Font *_defaultFonts[NUM_POINT_SIZES];
313  static Graphics::Font *_fixedFonts[NUM_POINT_SIZES];
314 
315  static bool _initialized;
316 
317  static int _tabStop; // tabstop table
318 };
319 
320 
321 // Global text functions
322 //
323 ErrorCode paintText(CBofWindow *pWnd, CBofRect *pRect, const char *, int nSize, int nWeight, RGBCOLOR cColor = CTEXT_COLOR, int nJustify = JUSTIFY_CENTER, uint32 nFormat = FORMAT_DEFAULT, int nFont = FONT_DEFAULT);
324 ErrorCode paintText(CBofBitmap *pBmp, CBofRect *pRect, const char *, int nSize, int nWeight, RGBCOLOR cColor = CTEXT_COLOR, int nJustify = JUSTIFY_CENTER, uint32 nFormat = FORMAT_DEFAULT, int nFont = FONT_DEFAULT);
325 
326 ErrorCode paintShadowedText(CBofBitmap *, CBofRect *pRect, const char *, int nSize, int nWeight, RGBCOLOR cColor = CTEXT_COLOR, int nJustify = JUSTIFY_CENTER, uint32 n = FORMAT_DEFAULT, int nFont = FONT_DEFAULT);
327 
332 CBofRect calculateTextRect(CBofWindow *pWnd, const CBofString *pStr, int nSize, int nFont);
333 CBofRect calculateTextRect(CBofRect rect, const CBofString *pStr, int nSize, int nFont);
334 
335 } // namespace Bagel
336 
337 #endif
Definition: managed_surface.h:51
ErrorCode displayTextEx(CBofBitmap *pBmp, const char *pszText, CBofRect *pRect, int nSize, int nWeight, bool bShadowed, int nFont=0)
Definition: window.h:50
Definition: font.h:83
TextAlign
Definition: font.h:48
ErrorCode erase(CBofWindow *pWnd)
Definition: object.h:28
Definition: size.h:31
ErrorCode setupText(const CBofRect *pRect, int nJustify=0, uint32 nFormatFlags=((0x00000000|0x00000000)|0x00000010))
Definition: bitmap.h:55
Definition: rect.h:36
Definition: error.h:50
Definition: ustr.h:57
ErrorCode displayShadowed(CBofWindow *pWnd, const char *pszText, int nSize, int nWeight, RGBCOLOR cColor, RGBCOLOR cShadow=RGB(0, 0, 0), int nDX=2, int nDY=2, int nFont=0)
Definition: string.h:38
Definition: bagel.h:31
ErrorCode display(CBofWindow *pWnd)
Definition: point.h:34
Definition: text.h:122