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 Graphics {
39 class MacText;
40 }
41 
42 namespace MacVenture {
43 
44 using namespace Graphics::MacGUIConstants;
45 class Gui;
46 class DialogElement;
47 
48 class Dialog {
49 public:
50  Dialog(Gui *gui, Common::MacResManager *resourceManager, uint16 resID);
51  Dialog(Gui *gui, Common::Point pos, uint width, uint height);
52  Dialog(Gui *gui, PrebuiltDialogs prebuilt, const Common::String &title);
53 
54  ~Dialog();
55 
56  bool processEvent(Common::Event event);
57  void draw();
58  void localize(Common::Point &point);
59  void handleDialogAction(DialogElement *trigger, DialogAction action);
60 
61  Graphics::MacWindowManager *getMacWindowManager() const;
62  const Graphics::Font &getFont();
63 
64  void addButton(Common::String title, DialogAction action, Common::Point position, uint width = 0, uint height = 0);
65  void addText(Common::String content, Common::Point position, int width = 0, int height = 0, Graphics::TextAlign alignment = Graphics::kTextAlignLeft);
66  void addTextInput(Common::Point position, int width, int height, Graphics::TextAlign alignment = Graphics::kTextAlignLeft);
67 
68  void setUserInput(Common::String content);
69  DialogElement *getElement(Common::String elementID);
70 
71 private:
72  void addPrebuiltElement(const PrebuiltDialogElement &element, const Common::String &title = "");
73 
74  void calculateBoundsFromPrebuilt(const PrebuiltDialogBounds &bounds);
75 
76 private:
77  Gui *_gui;
79 
80  Common::String _userInput;
82  Common::Rect _bounds;
83 };
84 
86 public:
87  DialogElement(Dialog *dialog, Common::String title, DialogAction action, Common::Point position, uint width = 0, uint height = 0, Graphics::TextAlign alignment = Graphics::kTextAlignLeft);
88  virtual ~DialogElement() {}
89 
90  bool processEvent(Dialog *dialog, Common::Event event);
91  void draw(MacVenture::Dialog *dialog, Graphics::ManagedSurface &target);
92  const Common::String &getText();
93 
94  void setAction(DialogAction action) { _action = action; }
95 
96 private:
97  virtual bool doProcessEvent(Dialog *dialog, Common::Event event) = 0;
98  virtual void doDraw(MacVenture::Dialog *dialog, Graphics::ManagedSurface &target) = 0;
99  virtual const Common::String &doGetText();
100 
101 protected:
102  Common::String _text;
103  Graphics::MacText *_macText;
104  Common::Rect _bounds;
105  DialogAction _action;
106 };
107 
108 // Dialog elements
109 class DialogButton : public DialogElement {
110 public:
111  DialogButton(Dialog *dialog, Common::String title, DialogAction action, Common::Point position, uint width = 0, uint height = 0);
112  ~DialogButton() override {}
113 
114 private:
115  bool doProcessEvent(Dialog *dialog, Common::Event event) override;
116  void doDraw(MacVenture::Dialog *dialog, Graphics::ManagedSurface &target) override;
117 };
118 
120 public:
121  DialogPlainText(Dialog *dialog, Common::String content, Common::Point position, int width, int height, Graphics::TextAlign alignment = Graphics::kTextAlignLeft);
122  ~DialogPlainText() override;
123 
124 private:
125  bool doProcessEvent(Dialog *dialog, Common::Event event) override;
126  void doDraw(MacVenture::Dialog *dialog, Graphics::ManagedSurface &target) override;
127 };
128 
130 public:
131  DialogTextInput(Dialog *dialog, Gui *gui, Common::Point position, uint width, uint height, Graphics::TextAlign alignment = Graphics::kTextAlignLeft);
132  ~DialogTextInput() override;
133 
134  void updateCursorPos();
135  void undrawCursor();
136 
137  Common::Point _cursorPos;
138  bool _cursorState;
139  bool _cursorDirty;
140 
141 private:
142  bool doProcessEvent(Dialog *dialog, Common::Event event) override;
143  void doDraw(MacVenture::Dialog *dialog, Graphics::ManagedSurface &target) override;
144 
145  int getCursorHeight() const;
146 
147  Gui *_gui;
148 
149  Common::Rect _cursorRect;
150  Graphics::ManagedSurface *_cursorSurface;
151 };
152 
153 } // End of namespace MacVenture
154 
155 #endif
Definition: prebuilt_dialogs.h:69
Definition: managed_surface.h:51
Definition: dialog.h:48
Definition: macresman.h:126
Definition: str.h:59
Definition: font.h:83
TextAlign
Definition: font.h:48
Definition: gui.h:92
Definition: array.h:52
Definition: mactext.h:47
Definition: dialog.h:85
Align the text to the left.
Definition: font.h:51
Definition: dialog.h:119
Definition: macwindowmanager.h:45
Definition: rect.h:524
Definition: macwindowmanager.h:147
Definition: dialog.h:129
Definition: events.h:210
Definition: formatinfo.h:28
Definition: rect.h:144
Definition: prebuilt_dialogs.h:62
Definition: container.h:38
Definition: dialog.h:109