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 *_dragHookWidget;
58  Widget *_tickleWidget;
59  bool _visible;
60 
61  ThemeEngine::DialogBackground _backgroundType;
62 
63 private:
64  int _result;
65  bool _handlingMouseWheel;
66 
67 public:
68  Dialog(int x, int y, int w, int h, bool scale = false);
69  Dialog(const Common::String &name);
70 
71  virtual int runModal();
72 
73  bool isVisible() const override { return _visible; }
74 
75  void releaseFocus() override;
76  void setFocusWidget(Widget *widget);
77  Widget *getFocusWidget() { return _focusedWidget; }
78 
79  bool isDragging() const { return _dragWidget != nullptr; }
80 
81  void reflowLayout() override;
82  virtual void lostFocus();
83  virtual void receivedFocus(int x = -1, int y = -1) { if (x >= 0 && y >= 0) handleMouseMoved(x, y, 0); }
84 
85  virtual void open();
86  virtual void close();
87 
88  Widget *findWidget(uint32 type);
89 
90 protected:
92  void markWidgetsAsDirty();
93 
95  Common::Rect getMaxDirtyRect() const;
96 
98  virtual void drawDialog(DrawLayer layerToDraw, bool resetClipping = true);
100  void drawWidgets();
101 
102  virtual void handleTickle(); // Called periodically (in every guiloop() )
103  virtual void handleMouseDown(int x, int y, int button, int clickCount);
104  virtual void handleMouseUp(int x, int y, int button, int clickCount);
105  virtual void handleMouseWheel(int x, int y, int direction) override;
106  virtual void handleKeyDown(Common::KeyState state);
107  virtual void handleKeyUp(Common::KeyState state);
108  virtual void handleMouseMoved(int x, int y, int button);
109  virtual void handleMouseLeft(int button) {}
110  virtual void handleOtherEvent(const Common::Event &evt);
111  void handleCommand(CommandSender *sender, uint32 cmd, uint32 data) override;
112 
113  Widget *findWidget(int x, int y); // Find the widget at pos x,y if any
114  Widget *findWidget(const char *name);
115  void removeWidget(Widget *widget) override;
116 
117  void setDefaultFocusedWidget();
118 
119  void registerTickleWidget(Widget *widget) override;
120  void unregisterTickleWidget(Widget *widget) override;
121 
122  void setResult(int result) { _result = result; }
123  int getResult() const { return _result; }
124 };
125 
126 } // End of namespace GUI
127 
128 #endif
Definition: str.h:59
Definition: rect.h:536
Definition: gui-manager.h:85
Definition: printman.h:30
Definition: object.h:60
Definition: events.h:218
DialogBackground
Dialog background type.
Definition: ThemeEngine.h:239
Definition: algorithm.h:29
Definition: Tooltip.h:33
Definition: dialog.h:49
Definition: widget.h:99
Definition: keyboard.h:294
Definition: object.h:40