ScummVM API documentation
gui-manager.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 GUIMANAGER_H
23#define GUIMANAGER_H
24
25#include "common/scummsys.h"
26#include "common/singleton.h"
27#include "common/stack.h"
28#include "common/str.h"
29#include "common/list.h"
30#include "common/mutex.h"
31#include "common/printman.h"
32
33#include "gui/ThemeEngine.h"
34#include "gui/widget.h"
35
36class OSystem;
37
38namespace Graphics {
39class Font;
40class MacWindowManager;
41}
42
43namespace Common {
44 struct Event;
45 class Keymap;
46}
47
48namespace GUI {
49
50enum {
51 kActionEnd,
52 kActionShiftEnd,
53 kActionHome,
54 kActionShiftHome,
55 kActionCopy,
56 kActionCut,
57 kActionPaste,
58};
59
60enum {
61 kIconsSetLoadedCmd = 'icns'
62};
63
64class Dialog;
65class ThemeEval;
66class GuiObject;
67class Tooltip;
68
69#define g_gui (GUI::GuiManager::instance())
70
71
72// Height of a single text line
73#define kLineHeight (g_gui.getFontHeight() + 2)
74
75
76
77// Simple dialog stack class
78// Anybody nesting dialogs deeper than 4 is mad anyway
79typedef Common::FixedStack<Dialog *> DialogStack;
80
81
85class GuiManager : public Common::Singleton<GuiManager>, public CommandSender {
86 friend class Dialog;
87 friend class Common::Singleton<SingletonBaseType>;
88 GuiManager();
89 ~GuiManager() override;
90public:
91
92 // Main entry for the GUI: this will start an event loop that keeps running
93 // until no dialogs are active anymore.
94 void runLoop();
95
96 // If the GUI loop is running close all the dialogs causing the loop to finish.
97 // Typically you may want to use it after setting the ConfMan active domain to
98 // a game domain to cause the game to start.
99 void exitLoop();
100
101 void processEvent(const Common::Event &event, Dialog *const activeDialog);
102 Common::Keymap *getKeymap() const;
103 void scheduleTopDialogRedraw();
104 void scheduleFullRedraw();
105
106 bool isActive() const { return ! _dialogStack.empty(); }
107
108 bool loadNewTheme(Common::String id, ThemeEngine::GraphicsMode gfx = ThemeEngine::kGfxDisabled, bool force = false);
109 ThemeEngine *theme() { return _theme; }
110
111 ThemeEval *xmlEval() { return _theme->getEvaluator(); }
112
113 void lockIconsSet() { _iconsMutex.lock(); }
114 void unlockIconsSet() { _iconsMutex.unlock(); }
115 Common::SearchSet &getIconsSet() { return _iconsSet; }
116
117 int16 getGUIWidth() const { return _baseWidth; }
118 int16 getGUIHeight() const { return _baseHeight; }
119 float getScaleFactor() const { return _scaleFactor; }
120 void computeScaleFactor();
121
122 bool useLowResGUI() const { return _baseWidth <= 320; }
123
124 bool useRTL() const { return _useRTL; }
125 void setLanguageRTL();
126
127 const Graphics::Font &getFont(ThemeEngine::FontStyle style = ThemeEngine::kFontStyleBold) const { return *(_theme->getFont(style)); }
128 int getFontHeight(ThemeEngine::FontStyle style = ThemeEngine::kFontStyleBold) const { return _theme->getFontHeight(style); }
129 int getStringWidth(const Common::String &str, ThemeEngine::FontStyle style = ThemeEngine::kFontStyleBold) const { return _theme->getStringWidth(str, style); }
130 int getStringWidth(const Common::U32String &str, ThemeEngine::FontStyle style = ThemeEngine::kFontStyleBold) const { return _theme->getStringWidth(str, style); }
131 int getCharWidth(uint32 c, ThemeEngine::FontStyle style = ThemeEngine::kFontStyleBold) const { return _theme->getCharWidth(c, style); }
132 int getKerningOffset(uint32 left, uint32 right, ThemeEngine::FontStyle font = ThemeEngine::kFontStyleBold) const { return _theme->getKerningOffset(left, right, font); }
133
141
147 void addToTrash(GuiObject*, Dialog* parent = nullptr);
148 void initTextToSpeech();
149
150 bool _launched;
151
152 void redrawFull();
153
154 void initIconsSet();
155
156 void displayTopDialogOnly(bool mode);
157
159
160 // Defined in printing-dialog.cpp
161 void printImage(const Graphics::ManagedSurface &surf, bool defaultFitToPage, bool defaultCenter, PageOrientation defaultOrientation);
162 void printImage(const Graphics::ManagedSurface &surf);
163
164protected:
165 enum RedrawStatus {
166 kRedrawDisabled = 0,
167 kRedrawOpenTooltip,
168 kRedrawCloseTooltip,
169 kRedrawOpenDialog,
170 kRedrawCloseDialog,
171 kRedrawTopDialog,
172 kRedrawFull
173 };
174
175 OSystem *_system;
176
177 ThemeEngine *_theme;
178
179// bool _needRedraw;
180 RedrawStatus _redrawStatus;
181 int _lastScreenChangeID;
182 int16 _baseWidth, _baseHeight;
183 float _scaleFactor;
184 DialogStack _dialogStack;
185
186 bool _stateIsSaved;
187
188 bool _useStdCursor;
189
190 bool _useRTL;
191
192 bool _displayTopDialogOnly;
193
194 Common::Mutex _iconsMutex;
195 Common::SearchSet _iconsSet;
196 bool _iconsSetChanged;
197
198 Graphics::MacWindowManager *_wm = nullptr;
199
200 // position and time of last mouse click (used to detect double clicks)
201 struct MousePos {
202 MousePos() : x(-1), y(-1), count(0) { time = 0; }
203 int16 x, y; // Position of mouse when the click occurred
204 uint32 time; // Time
205 int count; // How often was it already pressed?
206 } _lastClick;
207 Common::Point _globalMousePosition;
208 uint32 _lastMouseMoveTime;
209
210 struct TooltipData {
211 TooltipData() : x(-1), y(-1), wdg(nullptr) { time = 0; }
212 uint32 time; // Time
213 Widget *wdg; // Widget that had its tooltip shown
214 int16 x, y; // Position of mouse before tooltip was focused
215 } _lastTooltipShown;
216 Tooltip *_tooltip;
217
218 // mouse cursor state
219 uint32 _cursorAnimateCounter;
220 uint32 _cursorAnimateTimer;
221 byte _cursor[2048];
222
223 // delayed deletion of GuiObject
225 GuiObject* object;
226 Dialog* parent;
227 };
228 Common::List<GuiObjectTrashItem> _guiObjectTrash;
229
230 void initKeymap();
231 void enableKeymap(bool enabled);
232
233 void saveState();
234 void restoreState();
235
236 void openDialog(Dialog *dialog);
237 void closeTopDialog();
238
239 void redraw();
240 void redrawInternalTopDialogOnly();
241 void redrawInternal();
242
243 void setupCursor();
244 void animateCursor();
245
246 Dialog *getTopDialog() const;
247
248 void screenChange();
249
250 void giveFocusToDialog(Dialog *dialog);
251
252 void emptyTrash(Dialog *const activeDialog);
253};
254
255} // End of namespace GUI
256
257#endif
Definition: keymap.h:66
Definition: list.h:44
Definition: mutex.h:67
Definition: archive.h:330
Definition: singleton.h:42
Definition: str.h:59
Definition: ustr.h:57
Definition: object.h:40
Definition: dialog.h:49
Definition: gui-manager.h:85
bool checkScreenChange()
void addToTrash(GuiObject *, Dialog *parent=nullptr)
Definition: object.h:60
Definition: ThemeEngine.h:209
FontStyle
Font style selector.
Definition: ThemeEngine.h:274
@ kFontStyleBold
A bold font. This is also the default font.
Definition: ThemeEngine.h:275
GraphicsMode
Definition: ThemeEngine.h:334
@ kGfxDisabled
No GFX.
Definition: ThemeEngine.h:335
Definition: ThemeEval.h:37
Definition: Tooltip.h:33
Definition: widget.h:99
Definition: font.h:83
Definition: macwindowmanager.h:149
Definition: managed_surface.h:51
Definition: system.h:166
Definition: algorithm.h:29
Definition: formatinfo.h:28
Definition: events.h:218
Definition: rect.h:144
Definition: gui-manager.h:224
Definition: gui-manager.h:201
Definition: gui-manager.h:210