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