ScummVM API documentation
dialog.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 GUI_DIALOG_H
23 #define GUI_DIALOG_H
24 
25 #include "common/scummsys.h"
26 #include "common/str.h"
27 #include "common/keyboard.h"
28 
29 #include "gui/object.h"
30 #include "gui/ThemeEngine.h"
31 
32 namespace Common {
33 struct Event;
34 }
35 
36 namespace GUI {
37 
38 class EventRecorder;
39 
40 class Widget;
41 
42 // Some "common" commands sent to handleCommand()
43 enum {
44  kCloseWithResultCmd = 'clsr',
45  kCloseCmd = 'clos',
46  kOKCmd = 'ok '
47 };
48 
49 class Dialog : public GuiObject {
50  friend class GuiManager;
51  friend class EventRecorder;
52  friend class Tooltip;
53 protected:
54  Widget *_mouseWidget;
55  Widget *_focusedWidget;
56  Widget *_dragWidget;
57  Widget *_tickleWidget;
58  bool _visible;
59  // _mouseUpdatedOnFocus instructs gui-manager whether
60  // its lastMousePosition (time and x,y coordinates)
61  // should be updated, when this Dialog acquires focus.
62  // Default value is true.
63  bool _mouseUpdatedOnFocus;
64 
65  ThemeEngine::DialogBackground _backgroundType;
66 
67 private:
68  int _result;
69  bool _handlingMouseWheel;
70 
71 public:
72  Dialog(int x, int y, int w, int h, bool scale = false);
73  Dialog(const Common::String &name);
74 
75  virtual int runModal();
76 
77  bool isVisible() const override { return _visible; }
78 
79  bool isMouseUpdatedOnFocus() const { return _mouseUpdatedOnFocus; }
80 
81  void releaseFocus() override;
82  void setFocusWidget(Widget *widget);
83  Widget *getFocusWidget() { return _focusedWidget; }
84 
85  bool isDragging() const { return _dragWidget != nullptr; }
86 
87  void setTickleWidget(Widget *widget) { _tickleWidget = widget; }
88  void unSetTickleWidget() { _tickleWidget = nullptr; }
89  Widget *getTickleWidget() { return _tickleWidget; }
90 
91  void reflowLayout() override;
92  virtual void lostFocus();
93  virtual void receivedFocus(int x = -1, int y = -1) { if (x >= 0 && y >= 0) handleMouseMoved(x, y, 0); }
94 
95  virtual void open();
96  virtual void close();
97 
98 protected:
100  void markWidgetsAsDirty();
101 
103  virtual void drawDialog(DrawLayer layerToDraw);
104 
106  void drawWidgets();
107 
108  virtual void handleTickle(); // Called periodically (in every guiloop() )
109  virtual void handleMouseDown(int x, int y, int button, int clickCount);
110  virtual void handleMouseUp(int x, int y, int button, int clickCount);
111  virtual void handleMouseWheel(int x, int y, int direction) override;
112  virtual void handleKeyDown(Common::KeyState state);
113  virtual void handleKeyUp(Common::KeyState state);
114  virtual void handleMouseMoved(int x, int y, int button);
115  virtual void handleMouseLeft(int button) {}
116  virtual void handleOtherEvent(const Common::Event &evt);
117  void handleCommand(CommandSender *sender, uint32 cmd, uint32 data) override;
118 
119  Widget *findWidget(int x, int y); // Find the widget at pos x,y if any
120  Widget *findWidget(const char *name);
121  void removeWidget(Widget *widget) override;
122 
123  void setMouseUpdatedOnFocus(bool mouseUpdatedOnFocus) { _mouseUpdatedOnFocus = mouseUpdatedOnFocus; }
124  void setDefaultFocusedWidget();
125 
126  void setResult(int result) { _result = result; }
127  int getResult() const { return _result; }
128 };
129 
130 } // End of namespace GUI
131 
132 #endif
Definition: str.h:59
Definition: gui-manager.h:83
Definition: system.h:45
Definition: object.h:60
Graphics::Surface * scale(const Graphics::Surface &srcImage, int xSize, int ySize)
Definition: events.h:198
DialogBackground
Dialog background type.
Definition: ThemeEngine.h:239
Definition: algorithm.h:29
Definition: Tooltip.h:33
Definition: dialog.h:49
Definition: widget.h:100
Definition: keyboard.h:294
Definition: object.h:40