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  void setDialogPaddings(int l, int r);
126  int getOverlayOffset() { return _topDialogRightPadding - _topDialogLeftPadding; }
127 
128  const Graphics::Font &getFont(ThemeEngine::FontStyle style = ThemeEngine::kFontStyleBold) const { return *(_theme->getFont(style)); }
129  int getFontHeight(ThemeEngine::FontStyle style = ThemeEngine::kFontStyleBold) const { return _theme->getFontHeight(style); }
130  int getStringWidth(const Common::String &str, ThemeEngine::FontStyle style = ThemeEngine::kFontStyleBold) const { return _theme->getStringWidth(str, style); }
131  int getStringWidth(const Common::U32String &str, ThemeEngine::FontStyle style = ThemeEngine::kFontStyleBold) const { return _theme->getStringWidth(str, style); }
132  int getCharWidth(uint32 c, ThemeEngine::FontStyle style = ThemeEngine::kFontStyleBold) const { return _theme->getCharWidth(c, style); }
133  int getKerningOffset(uint32 left, uint32 right, ThemeEngine::FontStyle font = ThemeEngine::kFontStyleBold) const { return _theme->getKerningOffset(left, right, font); }
134 
141  bool checkScreenChange();
142 
148  void addToTrash(GuiObject*, Dialog* parent = nullptr);
149  void initTextToSpeech();
150 
151  bool _launched;
152 
153  void redrawFull();
154 
155  void initIconsSet();
156 
157  void displayTopDialogOnly(bool mode);
158 
160 
161 protected:
162  enum RedrawStatus {
163  kRedrawDisabled = 0,
164  kRedrawOpenDialog,
165  kRedrawCloseDialog,
166  kRedrawTopDialog,
167  kRedrawFull
168  };
169 
170  OSystem *_system;
171 
172  ThemeEngine *_theme;
173 
174 // bool _needRedraw;
175  RedrawStatus _redrawStatus;
176  int _lastScreenChangeID;
177  int16 _baseWidth, _baseHeight;
178  float _scaleFactor;
179  DialogStack _dialogStack;
180 
181  bool _stateIsSaved;
182 
183  bool _useStdCursor;
184 
185  bool _useRTL;
186 
187  int _topDialogLeftPadding;
188  int _topDialogRightPadding;
189 
190  bool _displayTopDialogOnly;
191 
192  Common::Mutex _iconsMutex;
193  Common::SearchSet _iconsSet;
194  bool _iconsSetChanged;
195 
196  Graphics::MacWindowManager *_wm = nullptr;
197 
198  // position and time of last mouse click (used to detect double clicks)
199  struct MousePos {
200  MousePos() : x(-1), y(-1), count(0) { time = 0; }
201  int16 x, y; // Position of mouse when the click occurred
202  uint32 time; // Time
203  int count; // How often was it already pressed?
204  } _lastClick, _lastMousePosition, _globalMousePosition;
205 
206  struct TooltipData {
207  TooltipData() : x(-1), y(-1) { time = 0; wdg = nullptr; }
208  uint32 time; // Time
209  Widget *wdg; // Widget that had its tooltip shown
210  int16 x, y; // Position of mouse before tooltip was focused
211  } _lastTooltipShown;
212 
213  // mouse cursor state
214  uint32 _cursorAnimateCounter;
215  uint32 _cursorAnimateTimer;
216  byte _cursor[2048];
217 
218  // delayed deletion of GuiObject
220  GuiObject* object;
221  Dialog* parent;
222  };
223  Common::List<GuiObjectTrashItem> _guiObjectTrash;
224 
225  void initKeymap();
226  void enableKeymap(bool enabled);
227 
228  void saveState();
229  void restoreState();
230 
231  void openDialog(Dialog *dialog);
232  void closeTopDialog();
233 
234  void redraw();
235  void redrawInternalTopDialogOnly();
236  void redrawInternal();
237 
238  void setupCursor();
239  void animateCursor();
240 
241  Dialog *getTopDialog() const;
242 
243  void screenChange();
244 
245  void giveFocusToDialog(Dialog *dialog);
246  void setLastMousePos(int16 x, int16 y);
247 };
248 
249 } // End of namespace GUI
250 
251 #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:199
Definition: ThemeEval.h:37
Definition: system.h:46
Definition: object.h:60
Definition: macwindowmanager.h:149
Definition: gui-manager.h:206
Definition: gui-manager.h:219
Definition: ustr.h:57
Definition: archive.h:312
Definition: events.h:199
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:161
virtual int getFontHeight() const =0
GraphicsMode
Definition: ThemeEngine.h:334
Definition: object.h:40
Definition: singleton.h:42