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 /*
23  * Based on
24  * WebVenture (c) 2010, Sean Kasun
25  * https://github.com/mrkite/webventure, http://seancode.com/webventure/
26  *
27  * Used with explicit permission from the author
28  */
29 
30 #ifndef MACVENTURE_DIALOG_H
31 #define MACVENTURE_DIALOG_H
32 
33 #include "graphics/macgui/macwindowmanager.h"
34 
35 #include "macventure/macventure.h"
36 #include "macventure/prebuilt_dialogs.h"
37 
38 namespace MacVenture {
39 
40 using namespace Graphics::MacGUIConstants;
41 class Gui;
42 class DialogElement;
43 
44 class Dialog {
45 public:
46  Dialog(Gui *gui, Common::Point pos, uint width, uint height);
47  Dialog(Gui *gui, PrebuiltDialogs prebuilt);
48 
49  ~Dialog();
50 
51  bool processEvent(Common::Event event);
52  void draw();
53  void localize(Common::Point &point);
54  void handleDialogAction(DialogElement *trigger, DialogAction action);
55 
56  const Graphics::Font &getFont();
57 
58  void addButton(Common::String title, DialogAction action, Common::Point position, uint width = 0, uint height = 0);
59  void addText(Common::String content, Common::Point position);
60  void addTextInput(Common::Point position, int width, int height);
61 
62  void setUserInput(Common::String content);
63 
64 private:
65  void addPrebuiltElement(const PrebuiltDialogElement &element);
66 
67  void calculateBoundsFromPrebuilt(const PrebuiltDialogBounds &bounds);
68 
69 private:
70  Gui *_gui;
71 
72  Common::String _userInput;
74  Common::Rect _bounds;
75 };
76 
78 public:
79  DialogElement(Dialog *dialog, Common::String title, DialogAction action, Common::Point position, uint width = 0, uint height = 0);
80  virtual ~DialogElement() {}
81 
82  bool processEvent(Dialog *dialog, Common::Event event);
83  void draw(MacVenture::Dialog *dialog, Graphics::ManagedSurface &target);
84  const Common::String &getText();
85 
86 private:
87  virtual bool doProcessEvent(Dialog *dialog, Common::Event event) = 0;
88  virtual void doDraw(MacVenture::Dialog *dialog, Graphics::ManagedSurface &target) = 0;
89  virtual const Common::String &doGetText();
90 
91 protected:
92  Common::String _text;
93  Common::Rect _bounds;
94  DialogAction _action;
95 };
96 
97 // Dialog elements
98 class DialogButton : public DialogElement {
99 public:
100  DialogButton(Dialog *dialog, Common::String title, DialogAction action, Common::Point position, uint width = 0, uint height = 0);
101  ~DialogButton() override {}
102 
103 private:
104  bool doProcessEvent(Dialog *dialog, Common::Event event) override;
105  void doDraw(MacVenture::Dialog *dialog, Graphics::ManagedSurface &target) override;
106 };
107 
109 public:
110  DialogPlainText(Dialog *dialog, Common::String content, Common::Point position);
111  ~DialogPlainText() override;
112 
113 private:
114  bool doProcessEvent(Dialog *dialog, Common::Event event) override;
115  void doDraw(MacVenture::Dialog *dialog, Graphics::ManagedSurface &target) override;
116 };
117 
119 public:
120  DialogTextInput(Dialog *dialog, Common::Point position, uint width, uint height);
121  ~DialogTextInput() override;
122 
123 private:
124  bool doProcessEvent(Dialog *dialog, Common::Event event) override;
125  void doDraw(MacVenture::Dialog *dialog, Graphics::ManagedSurface &target) override;
126 };
127 
128 } // End of namespace MacVenture
129 
130 #endif
Definition: prebuilt_dialogs.h:69
Definition: managed_surface.h:51
Definition: dialog.h:44
Definition: str.h:59
Definition: font.h:83
Definition: gui.h:92
Definition: array.h:52
Definition: dialog.h:77
Definition: dialog.h:108
Definition: macwindowmanager.h:45
Definition: rect.h:144
Definition: dialog.h:118
Definition: events.h:199
Definition: rect.h:45
Definition: prebuilt_dialogs.h:62
Definition: container.h:38
Definition: dialog.h:98