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