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;
78 
79  Common::String _userInput;
81  Common::Rect _bounds;
82 };
83 
85 public:
86  DialogElement(Dialog *dialog, Common::String title, DialogAction action, Common::Point position, uint width = 0, uint height = 0, Graphics::TextAlign alignment = Graphics::kTextAlignLeft);
87  virtual ~DialogElement() {}
88 
89  bool processEvent(Dialog *dialog, Common::Event event);
90  void draw(MacVenture::Dialog *dialog, Graphics::ManagedSurface &target);
91  const Common::String &getText();
92 
93  void setAction(DialogAction action) { _action = action; }
94 
95 private:
96  virtual bool doProcessEvent(Dialog *dialog, Common::Event event) = 0;
97  virtual void doDraw(MacVenture::Dialog *dialog, Graphics::ManagedSurface &target) = 0;
98  virtual const Common::String &doGetText();
99 
100 protected:
101  Common::String _text;
102  Graphics::MacText *_macText;
103  Common::Rect _bounds;
104  DialogAction _action;
105 };
106 
107 // Dialog elements
108 class DialogButton : public DialogElement {
109 public:
110  DialogButton(Dialog *dialog, Common::String title, DialogAction action, Common::Point position, uint width = 0, uint height = 0);
111  ~DialogButton() 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  DialogPlainText(Dialog *dialog, Common::String content, Common::Point position, int width, int height, Graphics::TextAlign alignment = Graphics::kTextAlignLeft);
121  ~DialogPlainText() 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 
129 public:
130  DialogTextInput(Dialog *dialog, Gui *gui, Common::Point position, uint width, uint height, Graphics::TextAlign alignment = Graphics::kTextAlignLeft);
131  ~DialogTextInput() override;
132 
133  void updateCursorPos();
134  void undrawCursor();
135 
136  Common::Point _cursorPos;
137  bool _cursorState;
138  bool _cursorDirty;
139 
140 private:
141  bool doProcessEvent(Dialog *dialog, Common::Event event) override;
142  void doDraw(MacVenture::Dialog *dialog, Graphics::ManagedSurface &target) override;
143 
144  int getCursorHeight() const;
145 
146  Gui *_gui;
147 
148  Common::Rect _cursorRect;
149  Graphics::ManagedSurface *_cursorSurface;
150 };
151 
152 } // End of namespace MacVenture
153 
154 #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:84
Align the text to the left.
Definition: font.h:51
Definition: dialog.h:118
Definition: macwindowmanager.h:45
Definition: rect.h:524
Definition: macwindowmanager.h:147
Definition: dialog.h:128
Definition: events.h:210
Definition: formatinfo.h:28
Definition: rect.h:144
Definition: prebuilt_dialogs.h:62
Definition: container.h:38
Definition: dialog.h:108