ScummVM API documentation
text_view.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 MM1_VIEWS_ENH_TEXT_VIEW_H
23 #define MM1_VIEWS_ENH_TEXT_VIEW_H
24 
25 #include "graphics/font.h"
26 #include "mm/mm1/events.h"
27 #include "mm/shared/utils/xeen_font.h"
28 
29 namespace MM {
30 namespace MM1 {
31 namespace ViewsEnh {
32 
33 //#define MM1_NEW_GFX
34 
35 #ifdef MM1_NEW_GFX
36 constexpr int TEXT_COLOR = 9;
37 #else
38 constexpr int TEXT_COLOR = 0xff;
39 #endif
40 
41 
42 class TextView : public UIElement {
43 private:
44  XeenFont *getFont() const;
45 
49  void rawWriteString(const Common::String &str);
50 
51 protected:
52  Common::Point _textPos;
53  int _colorsNum = 0;
54  bool _fontReduced = false;
55 
59  byte setTextColor(byte col);
60 
64  void writeChar(unsigned char c);
65  void writeChar(int x, int y, unsigned char c);
66 
70  void writeString(const Common::String &str,
71  TextAlign align = ALIGN_LEFT);
72  void writeString(int x, int y, const Common::String &str,
73  TextAlign align = ALIGN_LEFT);
74 
78  void writeNumber(int val);
79  void writeNumber(int x, int y, int val);
80 
84  void writeLine(int lineNum, const Common::String &str,
85  TextAlign align = ALIGN_LEFT, int xp = 0);
86 
90  size_t getStringWidth(const Common::String &str);
91 
95  Common::String truncateString(const Common::String &str, int maxWidth);
96 
100  void newLine();
101 
106  int firstLineWidth = -1);
107 
111  void clearSurface() override;
112 
113  void drawGraphic(int gfxNum);
114 
115 public:
116  TextView(const Common::String &name);
117  TextView(const Common::String &name, UIElement *owner);
118  virtual ~TextView() {}
119 
123  void setReduced(bool flag) {
124  _fontReduced = flag;
125  }
126 };
127 
128 } // namespace ViewsEnh
129 } // namespace MM1
130 } // namespace MM
131 
132 #endif
Definition: str.h:59
void clearSurface() override
Common::StringArray splitLines(const Common::String &str, int firstLineWidth=-1)
void setReduced(bool flag)
Definition: text_view.h:123
void writeChar(unsigned char c)
Common::String truncateString(const Common::String &str, int maxWidth)
void writeLine(int lineNum, const Common::String &str, TextAlign align=ALIGN_LEFT, int xp=0)
Definition: detection.h:27
Definition: rect.h:144
Definition: text_view.h:42
Definition: events.h:68
Definition: xeen_font.h:35
size_t getStringWidth(const Common::String &str)
void writeString(const Common::String &str, TextAlign align=ALIGN_LEFT)