ScummVM API documentation
font.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 TITANIC_FONT_H
23 #define TITANIC_FONT_H
24 
25 #include "common/scummsys.h"
26 #include "common/array.h"
27 #include "titanic/support/rect.h"
28 #include "titanic/support/string.h"
29 #include "titanic/support/text_cursor.h"
30 
31 namespace Titanic {
32 
33 enum TextCommand { TEXTCMD_NPC = 26, TEXTCMD_SET_COLOR = 27 };
34 
35 enum WriteCharacterResult {
36  WC_IN_BOUNDS = 0, WC_OUTSIDE_TOP = -1, WC_OUTSIDE_BOTTOM = -2,
37  WC_OUTSIDE_LEFT = -3, WC_OUTSIDE_RIGHT = -4
38 };
39 
40 class CVideoSurface;
41 
42 class STFont {
43  struct CharEntry {
44  uint _width;
45  uint _offset;
46  };
47 private:
52  void copyRect(CVideoSurface *surface, const Common::Point &destPos,
53  Rect &srcRect);
54 
58  WriteCharacterResult writeChar(CVideoSurface *surface, unsigned char c,
59  const Common::Point &pt, const Rect &destRect, const Rect *srcRect);
60 
65  void extendBounds(Point &textSize, byte c, int maxWidth) const;
66 
70  void checkLineWrap(Point &textSize, int maxWidth, const char *&str) const;
71 public:
72  byte *_dataPtr;
73  size_t _dataSize;
74  int _fontHeight;
75  uint _dataWidth;
76  CharEntry _chars[256];
77  byte _fontR, _fontG, _fontB;
78 public:
79  STFont();
80  ~STFont();
81 
85  void load(int fontNumber);
86 
90  int stringWidth(const CString &text) const;
91 
97  int writeString(CVideoSurface *surface, const Rect &rect1, const Rect &destRect,
98  int yOffset, const CString &str, CTextCursor *textCursor);
99 
103  void writeString(CVideoSurface *surface, const Point &destPos, Rect &clipRect,
104  const CString &str, int lineWidth = 0);
105 
113  int getTextBounds(const CString &str, int maxWidth, Point *sizeOut) const;
114 
118  void setColor(byte r, byte g, byte b);
119 
123  uint16 getColor() const;
124 };
125 
126 } // End of namespace Titanic
127 
128 #endif /* TITANIC_FONT_H */
Definition: font.h:42
int writeString(CVideoSurface *surface, const Rect &rect1, const Rect &destRect, int yOffset, const CString &str, CTextCursor *textCursor)
uint16 getColor() const
void setColor(byte r, byte g, byte b)
int getTextBounds(const CString &str, int maxWidth, Point *sizeOut) const
void load(int fontNumber)
Definition: rect.h:35
Definition: rect.h:45
Definition: arm.h:30
Definition: string.h:40
Definition: text_cursor.h:33
int stringWidth(const CString &text) const
Definition: video_surface.h:43