ScummVM API documentation
All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Macros Modules Pages
mactextwindow.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_MACTEXTWINDOW_H
23 #define GRAPHICS_MACGUI_MACTEXTWINDOW_H
24 
25 #include "graphics/macgui/macfontmanager.h"
26 #include "graphics/macgui/mactext.h"
27 
28 namespace Graphics {
29 
30 class MacTextWindow : public MacWindow {
31 public:
32  MacTextWindow(MacWindowManager *wm, const MacFont *font, int fgcolor, int bgcolor, int maxWidth, TextAlign textAlignment, MacMenu *menu, bool cursorHandler = true);
33  MacTextWindow(MacWindowManager *wm, const Font *font, int fgcolor, int bgcolor, int maxWidth, TextAlign textAlignment, MacMenu *menu, bool cursorHandler = true);
34  virtual ~MacTextWindow();
35 
36  virtual void resize(int w, int h) override;
37  void setDimensions(const Common::Rect &r) override;
38 
39  virtual bool processEvent(Common::Event &event) override;
40 
41  virtual bool draw(ManagedSurface *g, bool forceRedraw = false) override;
42  virtual bool draw(bool forceRedraw = false) override;
43  virtual void blit(ManagedSurface *g, Common::Rect &dest) override;
44 
45  void setTextWindowFont(const MacFont *macFont);
46  const MacFont *getTextWindowFont();
47 
48  void appendText(const Common::U32String &str, const MacFont *macFont = nullptr, bool skipAdd = false);
49  void appendText(const Common::String &str, const MacFont *macFont = nullptr, bool skipAdd = false);
50  void clearText();
51  void setMarkdownText(const Common::U32String &str);
52 
53  void setEditable(bool editable) { _editable = editable; _mactext->setEditable(editable); }
54  void setSelectable(bool selectable) { _selectable = selectable; }
55 
56  void undrawCursor();
57 
58  const Common::U32String &getInput() { return _inputText; }
59  void clearInput();
60  void appendInput(const Common::U32String &str);
61  void appendInput(const Common::String &str);
62 
63  Common::U32String getSelection(bool formatted = false, bool newlines = true);
64  void clearSelection();
65  Common::U32String cutSelection();
66  const SelectedText *getSelectedText() { return &_selectedText; }
67  uint32 getTextColor() { return _mactext->getTextColor(); }
68  uint32 getTextColor(int start, int end) { return _mactext->getTextColor(start, end); }
69  void setTextColor(uint32 color, int start, int end) { return _mactext->setTextColor(color, start, end); }
70  int getTextFont() { return _mactext->getTextFont(); }
71  int getTextFont(int start, int end) { return _mactext->getTextFont(start, end); }
72  int getTextSlant() { return _mactext->getTextSlant(); }
73  int getTextSlant(int start, int end) { return _mactext->getTextSlant(start, end); }
74  int getTextHeight() { return _mactext->getTextHeight(); }
75  int getLineHeight(int line) { return _mactext->getLineHeight(line); }
76  Common::U32String getTextChunk(int startRow, int startCol, int endRow, int endCol, bool formatted = false, bool newlines = true) { return _mactext->getTextChunk(startRow, startCol, endRow, endCol, formatted, newlines); }
77  Common::U32String getPlainText() { return _mactext->getPlainText(); }
78  Common::U32String getEditedString() { return _mactext->getEditedString(); };
79  void enforceTextFont(uint16 fontId) { return _mactext->enforceTextFont(fontId); }
80  void setTextFont(uint16 fontId, int start, int end) { return _mactext->setTextFont(fontId, start, end); }
81  void enforceTextSlant(int textSlant) { return _mactext->enforceTextSlant(textSlant); }
82  void setTextSlant(int textSlant, int start, int end) { return _mactext->setTextSlant(textSlant, start, end); }
83  int getRowCount() { return _mactext->getRowCount(); }
84  int getLineSpacing() { return _mactext->getLineSpacing(); }
85  int getTextSize() { return _mactext->getTextSize(); }
86  int getTextSize(int start, int end) { return _mactext->getTextSize(start, end); }
87  void setTextSize(int textSize) { return _mactext->setTextSize(textSize); }
88  void setTextSize(int textSize, int start, int end) { return _mactext->setTextSize(textSize, start, end); }
89 
90  int getMouseLine(int x, int y);
91 
96  void setTextColorRGB (uint32 rgb) { _textColorRGB = rgb; }
97 
98 private:
99  void init(bool cursorHandler);
100  bool isCutAllowed();
101 
102  void scroll(int delta);
103  void calcScrollBar();
104 
105  void undrawInput();
106  void drawInput();
107  void drawSelection();
108  void updateCursorPos();
109 
110  void startMarking(int x, int y);
111  void updateTextSelection(int x, int y);
112 
113 public:
114  int _cursorX, _cursorY;
115  bool _cursorState;
116 
117  bool _cursorDirty;
118  Common::Rect *_cursorRect;
119  bool _cursorOff;
120  bool _editable;
121  bool _selectable;
122 
123  int _scrollPos;
124 
125 private:
126  MacText *_mactext;
127  const MacFont *_font;
128  const Font *_fontRef;
129 
130  ManagedSurface *_cursorSurface;
131 
132  bool _inTextSelection;
133  SelectedText _selectedText;
134 
135  int _maxWidth;
136  Common::U32String _inputText;
137  uint _inputTextHeight;
138  bool _inputIsDirty;
139 
140  MacMenu *_menu;
141 
142  int _bgcolor;
143  int _textColorRGB;
144 };
145 
146 } // End of namespace Graphics
147 
148 #endif
Definition: managed_surface.h:51
Definition: str.h:59
Definition: font.h:83
TextAlign
Definition: font.h:48
virtual bool draw(ManagedSurface *g, bool forceRedraw=false) override
Definition: mactext.h:47
Definition: macwindow.h:192
Definition: mactextwindow.h:30
Definition: rect.h:144
Definition: macwindowmanager.h:147
virtual bool processEvent(Common::Event &event) override
Definition: ustr.h:57
Definition: events.h:199
Definition: formatinfo.h:28
Definition: macmenu.h:94
Definition: mactext.h:29
Definition: macfontmanager.h:106
void setTextColorRGB(uint32 rgb)
Definition: mactextwindow.h:96