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 class 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
79 typedef Common::FixedStack<Dialog *> DialogStack;
80 
81 
85 class GuiManager : public Common::Singleton<GuiManager>, public CommandSender {
86  friend class Dialog;
87  friend class Common::Singleton<SingletonBaseType>;
88  GuiManager();
89  ~GuiManager() override;
90 public:
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 
140  bool checkScreenChange();
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 
164 protected:
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, _lastMousePosition, _globalMousePosition;
207 
208  struct TooltipData {
209  TooltipData() : x(-1), y(-1), wdg(nullptr) { time = 0; }
210  uint32 time; // Time
211  Widget *wdg; // Widget that had its tooltip shown
212  int16 x, y; // Position of mouse before tooltip was focused
213  } _lastTooltipShown;
214  Tooltip *_tooltip;
215 
216  // mouse cursor state
217  uint32 _cursorAnimateCounter;
218  uint32 _cursorAnimateTimer;
219  byte _cursor[2048];
220 
221  // delayed deletion of GuiObject
223  GuiObject* object;
224  Dialog* parent;
225  };
226  Common::List<GuiObjectTrashItem> _guiObjectTrash;
227 
228  void initKeymap();
229  void enableKeymap(bool enabled);
230 
231  void saveState();
232  void restoreState();
233 
234  void openDialog(Dialog *dialog);
235  void closeTopDialog();
236 
237  void redraw();
238  void redrawInternalTopDialogOnly();
239  void redrawInternal();
240 
241  void setupCursor();
242  void animateCursor();
243 
244  Dialog *getTopDialog() const;
245 
246  void screenChange();
247 
248  void giveFocusToDialog(Dialog *dialog);
249  void setLastMousePos(int16 x, int16 y);
250 
251  void emptyTrash(Dialog *const activeDialog);
252 };
253 
254 } // End of namespace GUI
255 
256 #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:85
Definition: gui-manager.h:201
Definition: ThemeEval.h:37
Definition: printman.h:30
Definition: object.h:60
Definition: macwindowmanager.h:147
Definition: gui-manager.h:208
Definition: gui-manager.h:222
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: Tooltip.h:33
Definition: dialog.h:49
Definition: widget.h:101
Definition: system.h:165
virtual int getFontHeight() const =0
GraphicsMode
Definition: ThemeEngine.h:334
Definition: object.h:40
Definition: singleton.h:42