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 
27 namespace Graphics {
28 
29 struct SelectedText {
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 
47 class MacText : public MacWidget {
48 public:
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);
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);
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);
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  void render();
64  void undrawCursor();
65  void draw(ManagedSurface *g, int x, int y, int w, int h, int xoff, int yoff);
66  bool draw(ManagedSurface *g, bool forceRedraw = false) override;
67  bool draw(bool forceRedraw = false) override;
68  void drawToPoint(ManagedSurface *g, Common::Rect srcRect, Common::Point dstPoint);
69  void drawToPoint(ManagedSurface *g, Common::Point dstPoint);
70 
71  ManagedSurface *getSurface() { return _canvas._surface; }
72  int getInterLinear() { return _canvas._interLinear; }
73  void setInterLinear(int interLinear);
74  void setMaxWidth(int maxWidth);
75  void setDefaultFormatting(uint16 fontId, byte textSlant, uint16 fontSize,
76  uint16 palinfo1, uint16 palinfo2, uint16 palinfo3);
77  const MacFontRun &getDefaultFormatting() { return _defaultFormatting; }
78 
79  void setAlignOffset(TextAlign align);
80  TextAlign getAlign() { return _canvas._textAlignment; }
81  virtual Common::Point calculateOffset();
82  void setActive(bool active) override;
83  void setEditable(bool editable);
84 
85  void setColors(uint32 fg, uint32 bg) override;
86  // set fgcolor for line x
87  void setTextColor(uint32 color, uint32 line);
88  void setTextColor(uint32 color, uint32 start, uint32 end);
89 
90  void appendText(const Common::U32String &str, int fontId = kMacFontChicago, int fontSize = 12, int fontSlant = kMacFontRegular, bool skipAdd = false);
91  void appendText(const Common::U32String &str, int fontId = kMacFontChicago, int fontSize = 12, int fontSlant = kMacFontRegular, uint16 r = 0, uint16 g = 0, uint16 b = 0, bool skipAdd = false);
92  void appendText(const Common::U32String &str, const Font *font, uint16 r = 0, uint16 g = 0, uint16 b = 0, bool skipAdd = false);
93 
94  int getTextFont() { return _defaultFormatting.fontId; }
95  void enforceTextFont(uint16 fontId);
96 
97  // because currently, we are counting linespacing as font height
98  int getTextSize() { return _defaultFormatting.fontSize; }
99  void setTextSize(int textSize);
100 
101  int getTextSize(int start, int end);
102  void setTextSize(int textSize, int start, int end);
103 
104  uint32 getTextColor() { return _defaultFormatting.fgcolor; }
105  uint32 getTextColor(int start, int end);
106 
107  int getTextFont(int start, int end);
108  void setTextFont(int fontId, int start, int end);
109 
110  int getTextSlant(int start, int end);
111  void setTextSlant(int textSlant, int start, int end);
112  void enforceTextSlant(int textSlant);
113 
114  // director text related-functions
115  int getMouseChar(int x, int y);
116  int getMouseWord(int x, int y);
117  int getMouseItem(int x, int y);
118  int getMouseLine(int x, int y);
119  Common::U32String getMouseLink(int x, int y);
120 
121  bool setImageArchive(const Common::Path &name) { return _canvas._imageArchive.setImageArchive(name); }
122 
123 private:
124  MacFontRun getTextChunks(int start, int end);
125  void setTextChunks(int start, int end, int param, void (*callback)(MacFontRun &, int));
126 
127  void appendText_(const Common::U32String &strWithFont, uint oldLen);
128  void deletePreviousCharInternal(int *row, int *col);
129  void insertTextFromClipboard();
130  MacFontRun getFgColor();
131 
132 public:
133  void appendTextDefault(const Common::U32String &str, bool skipAdd = false);
134  void appendTextDefault(const Common::String &str, bool skipAdd = false);
135  void clearText();
136  void removeLastLine();
137  int getLineCount() { return _canvas._text.size(); }
138  int getLastLineWidth();
139  int getTextHeight() { return _canvas._textMaxHeight; }
140  int getLineHeight(int line);
141  int getTextMaxWidth() { return _canvas._textMaxWidth; }
142 
143  void setText(const Common::U32String &str);
144 
145  void setFixDims(bool fixed) { _fixedDims = fixed; }
146  bool getFixDims() { return _fixedDims; }
147 
148  void deleteSelection();
149  void deletePreviousChar(int *row, int *col);
150  void addNewLine(int *row, int *col);
151  void insertChar(byte c, int *row, int *col);
152 
153  void getChunkPosFromIndex(int index, uint &lineNum, uint &chunkNum, uint &offset);
154  void getRowCol(int x, int y, int *sx, int *sy, int *row, int *col, int *chunk_ = nullptr);
155  Common::U32String getTextChunk(int startRow, int startCol, int endRow, int endCol, bool formatted = false, bool newlines = true);
156 
157  Common::U32String getSelection(bool formatted = false, bool newlines = true);
158  uint getSelectionIndex(bool start);
159  void clearSelection();
160  Common::U32String cutSelection();
161  const SelectedText *getSelectedText() { return &_selectedText; }
162 
163  int getLineSpacing() { return _canvas._interLinear; }
164 
170  void setSelection(int pos, bool start);
171 
172  Common::U32String getEditedString();
173  Common::U32String getText() { return _str; }
174  Common::U32String getPlainText();
175 
176  void setSelRange(int selStart, int selEnd);
177 
178  void scroll(int delta);
179 
180  // Markdown
181 public:
182  void setMarkdownText(const Common::U32String &str);
183 
184 private:
185  void init(uint32 fgcolor, uint32 bgcolor, int maxWidth, TextAlign textAlignment, int interlinear, uint16 textShadow, bool macFontMode);
186  bool isCutAllowed();
187 
188  void recalcDims();
189 
190  void drawSelection(int xoff, int yoff);
191  void updateCursorPos();
192 
193  void startMarking(int x, int y);
194  void updateTextSelection(int x, int y);
195 
199  void clearChunkInput();
200 
201 public:
202  int _cursorX, _cursorY;
203  bool _cursorState;
204  int _cursorRow, _cursorCol;
205 
206  bool _cursorDirty;
207  Common::Rect *_cursorRect;
208  bool _cursorOff;
209  bool _selectable;
210 
211  int _scrollPos;
212 
213  bool _fullRefresh;
214 
215 protected:
216  Common::U32String _str;
217  const MacFont *_macFont;
218 
219  bool _fixedDims;
220 
221  int _selEnd;
222  int _selStart;
223 
224  MacTextCanvas _canvas;
225 
226  MacFontRun _defaultFormatting;
227  MacFontRun _currentFormatting;
228 
229 private:
230  ManagedSurface *_cursorSurface;
231  ManagedSurface *_cursorSurface2;
232 
233  int _editableRow;
234 
235  bool _inTextSelection;
236  SelectedText _selectedText;
237 
238  MacMenu *_menu;
239 };
240 
241 int getStringWidth(MacFontRun &format, const Common::U32String &str);
242 
243 } // End of namespace Graphics
244 
245 #endif
Definition: managed_surface.h:51
Definition: str.h:59
Definition: font.h:82
TextAlign
Definition: font.h:48
Definition: mactext.h:47
Align the text to the left.
Definition: font.h:51
Definition: rect.h:144
Definition: path.h:52
Definition: mactext-canvas.h:32
Definition: macwindowmanager.h:148
Definition: mactext-canvas.h:110
Definition: ustr.h:57
Definition: events.h:199
Definition: formatinfo.h:28
Definition: rect.h:45
Definition: macwidget.h:39
Definition: macmenu.h:94
Definition: mactext.h:29
Definition: macfontmanager.h:85