ScummVM API documentation
mactext.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 GRAPHICS_MACGUI_MACTEXT_H
23#define GRAPHICS_MACGUI_MACTEXT_H
24
25#include "graphics/macgui/mactext-canvas.h"
26
27namespace Graphics {
28
30 int startX, startY;
31 int endX, endY;
32 int startRow, startCol;
33 int endRow, endCol;
34
35 SelectedText() {
36 startX = startY = -1;
37 endX = endY = -1;
38 startRow = startCol = -1;
39 endRow = endCol = -1;
40 }
41
42 bool needsRender() {
43 return startX != endX || startY != endY;
44 }
45};
46
47class MacText : public MacWidget {
48public:
49 MacText(MacWidget *parent, int x, int y, int w, int h, MacWindowManager *wm, const Common::U32String &s, const MacFont *font, uint32 fgcolor, uint32 bgcolor, int maxWidth, TextAlign textAlignment = kTextAlignLeft, int interlinear = 0, uint16 border = 0, uint16 gutter = 0, uint16 boxShadow = 0, uint16 textShadow = 0, bool fixedDims = true, bool scrollBar = false);
50 // 0 pixels between the lines by default
51
52 MacText(const Common::U32String &s, MacWindowManager *wm, const MacFont *font, uint32 fgcolor, uint32 bgcolor, int maxWidth, TextAlign textAlignment, int interlinear = 0, bool fixedDims = true, bool scrollBar = false);
53
54 MacText(const Common::U32String &s, MacWindowManager *wm, const Font *font, uint32 fgcolor, uint32 bgcolor, int maxWidth, TextAlign textAlignment, int interlinear = 0, bool fixedDims = true, bool scrollBar = false);
55
56 virtual ~MacText();
57
58 virtual void resize(int w, int h);
59 bool processEvent(Common::Event &event) override;
60
61 bool needsRedraw() override { return _contentIsDirty || _cursorDirty; }
62
63 WindowClick isInScrollBar(int x, int y) const;
64 void setScrollBar(bool enable);
65 void resizeScrollBar(int w, int h);
66
67 void setAutoSelect(bool enable) { _autoSelect = enable; }
68
69 void render();
70 void undrawCursor();
71 void drawStep(ManagedSurface *g, ManagedSurface *src, ManagedSurface *border, int x, int y, int w, int h, int xoff, int yoff, uint32 transcolor, uint32 btcolor);
72 void draw(ManagedSurface *g, int x, int y, int w, int h, int xoff, int yoff);
73 bool draw(ManagedSurface *g, bool forceRedraw = false) override;
74 bool draw(bool forceRedraw = false) override;
75 void drawToPoint(ManagedSurface *g, Common::Rect srcRect, Common::Point dstPoint);
76 void drawToPoint(ManagedSurface *g, Common::Point dstPoint);
77
78 ManagedSurface *getRawSurface() { return _canvas._surface; }
79 ManagedSurface *getGlyphMask() { return _glyphMaskSurface; }
80 ManagedSurface *getCharBoxMask() { return _charBoxMaskSurface; }
81
82 int getInterLinear() { return _canvas._interLinear; }
83 void setInterLinear(int interLinear);
84 void setMaxWidth(int maxWidth);
85 void setDefaultFormatting(uint16 fontId, byte textSlant, uint16 fontSize,
86 uint16 palinfo1, uint16 palinfo2, uint16 palinfo3);
87 const MacFontRun &getDefaultFormatting() { return _defaultFormatting; }
88
89 void setAlignOffset(TextAlign align);
90 TextAlign getAlign() { return _canvas._textAlignment; }
91 virtual Common::Point calculateOffset();
92 void setActive(bool active) override;
93 void setEditable(bool editable);
94 void setInputPadding(bool enable){ _addInputPadding = enable; }
95
96 void setColors(uint32 fg, uint32 bg) override;
97 // set fgcolor for line x
98 void setTextColor(uint32 color, uint32 line);
99 void setTextColor(uint32 color, uint32 start, uint32 end);
100
101 void appendText(const Common::U32String &str, int fontId = kMacFontSystem, int fontSize = 12, int fontSlant = kMacFontRegular, bool skipAdd = false);
102 void appendText(const Common::U32String &str, int fontId = kMacFontSystem, int fontSize = 12, int fontSlant = kMacFontRegular, uint16 r = 0, uint16 g = 0, uint16 b = 0, bool skipAdd = false);
103 void appendText(const Common::U32String &str, const Font *font, uint16 r = 0, uint16 g = 0, uint16 b = 0, bool skipAdd = false);
104
105 int getTextFont() { return _defaultFormatting.fontId; }
106 void enforceTextFont(uint16 fontId);
107
108 int getRowCount();
109
110 // because currently, we are counting linespacing as font height
111 int getTextSize() { return _defaultFormatting.fontSize; }
112 void setTextSize(int textSize);
113
114 int getTextSize(int start, int end);
115 void setTextSize(int textSize, int start, int end);
116
117 uint32 getTextColor() { return _defaultFormatting.fgcolor; }
118 uint32 getTextColor(int start, int end);
119
120 int getTextFont(int start, int end);
121 void setTextFont(int fontId, int start, int end);
122
123 int getTextSlant() { return _defaultFormatting.textSlant; }
124 int getTextSlant(int start, int end);
125 void setTextSlant(int textSlant, int start, int end);
126 void enforceTextSlant(int textSlant);
127
128 // director text related-functions
129 int getMouseChar(int x, int y);
130 int getMouseWord(int x, int y);
131 int getMouseItem(int x, int y);
132 int getMouseLine(int x, int y);
133 Common::U32String getMouseLink(int x, int y);
134
135 bool setImageArchive(const Common::Path &name) { return _canvas._imageArchive.setImageArchive(name); }
136
137private:
138 MacFontRun getTextChunks(int start, int end);
139 void setTextChunks(int start, int end, int param, void (*callback)(MacFontRun &, int));
140
141 void appendText_(const Common::U32String &strWithFont, uint oldLen);
142 void deletePreviousCharInternal(int *row, int *col);
143 void insertTextFromClipboard();
144 MacFontRun getFgColor();
145
146public:
147 void appendTextDefault(const Common::U32String &str, bool skipAdd = false);
148 void appendTextDefault(const Common::String &str, bool skipAdd = false);
149 void clearText();
150 void removeLastLine();
151 int getLineCount() { return _canvas._text.size(); }
152 int getLastLineWidth();
153 int getTextHeight() { return _canvas._textMaxHeight; }
154 int getLineHeight(int line);
155 int getTextMaxWidth() { return _canvas._textMaxWidth; }
156
157 void setText(const Common::U32String &str);
158
159 void setFixDims(bool fixed) { _fixedDims = fixed; }
160 bool getFixDims() { return _fixedDims; }
161
162 void deleteSelection();
163 void deletePreviousChar(int *row, int *col);
164 void addNewLine(int *row, int *col);
165 void insertChar(byte c, int *row, int *col);
166
167 void getChunkPosFromIndex(int index, uint &lineNum, uint &chunkNum, uint &offset);
168 void getRowCol(int x, int y, int *sx, int *sy, int *row, int *col, int *chunk_ = nullptr);
169 void getLineCharacter(int x, int y, int *sx, int *sy, int *line, int *character, int *chunk_ = nullptr);
170 Common::U32String getTextChunk(int startRow, int startCol, int endRow, int endCol, bool formatted = false, bool newlines = true);
171
172 Common::U32String getSelection(bool formatted = false, bool newlines = true);
173 uint getSelectionIndex(bool start);
174 void clearSelection();
175 Common::U32String cutSelection();
176 const SelectedText *getSelectedText() { return &_selectedText; }
177 bool hasSelection() { return _selectedText.endY != -1; }
178
179 int getLineSpacing() { return _canvas._interLinear; }
180
186 void setSelection(int pos, bool start);
187
188 Common::U32String getEditedString();
189 Common::U32String getText() { return _str; }
190 Common::U32String getPlainText();
191
192 void setSelRange(int selStart, int selEnd);
193
194 void scroll(int delta);
195
196 // Markdown
197public:
198 void setMarkdownText(const Common::U32String &str);
199
200private:
201 void init(uint32 fgcolor, uint32 bgcolor, int maxWidth, TextAlign textAlignment, int interlinear, uint16 textShadow, bool macFontMode);
202 bool isCutAllowed();
203
204 void recalcDims();
205
206 void drawSelection(int xoff, int yoff);
207 void updateCursorPos();
208
209 void startMarking(int x, int y);
210 void updateTextSelection(int x, int y);
211
215 void clearChunkInput();
216
217public:
218 int _cursorX, _cursorY;
219 bool _cursorState;
220 int _cursorRow, _cursorCol;
221
222 bool _cursorDirty;
223 Common::Rect *_cursorRect;
224 bool _cursorOff;
225 bool _selectable;
226
227 int _scrollPos;
228
229 bool _fullRefresh;
230
231protected:
233 const MacFont *_macFont;
234
235 bool _fixedDims;
236 bool _scrollBar;
237 MacWindowBorder _scrollBorder;
238 ManagedSurface _borderSurface;
239 ManagedSurface _borderMaskSurface;
240
241 int _selEnd;
242 int _selStart;
243
244 MacTextCanvas _canvas;
245
246 MacFontRun _defaultFormatting;
247 MacFontRun _currentFormatting;
248
249private:
250 ManagedSurface *_cursorSurface;
251 ManagedSurface *_cursorSurface2;
252
253 ManagedSurface *_glyphMaskSurface;
254 ManagedSurface *_charBoxMaskSurface;
255
256 int _editableRow;
257
258 bool _addInputPadding;
259
260 bool _inTextSelection;
261 SelectedText _selectedText;
262 bool _selectionIsDirty;
263
264 MacMenu *_menu;
265
266 bool _autoSelect;
267};
268
269int getStringWidth(MacFontRun &format, const Common::U32String &str);
270
271} // End of namespace Graphics
272
273#endif
Definition: path.h:52
Definition: str.h:59
Definition: ustr.h:57
Definition: font.h:83
Definition: macfontmanager.h:110
Definition: macmenu.h:95
Definition: mactext-canvas.h:110
Definition: mactext.h:47
void setActive(bool active) override
void setSelection(int pos, bool start)
Definition: macwidget.h:39
Definition: macwindowborder.h:81
Definition: macwindowmanager.h:149
Definition: managed_surface.h:51
TextAlign
Definition: font.h:48
@ kTextAlignLeft
Align the text to the left.
Definition: font.h:51
Definition: formatinfo.h:28
Definition: events.h:218
Definition: rect.h:144
Definition: rect.h:536
Definition: mactext-canvas.h:32
Definition: mactext.h:29