1 /* ResidualVM - A 3D game interpreter
2  *
3  * ResidualVM is the legal property of its developers, whose names
4  * are too numerous to list here. Please refer to the AUTHORS
5  * file distributed with this source distribution.
6  *
7  * This program is free software; you can redistribute it and/or
8  * modify it under the terms of the GNU General Public License
9  * as published by the Free Software Foundation; either version 2
10  * of the License, or (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, write to the Free Software
19  * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
20  *
21  */
22 
23 #ifndef STARK_UI_DIALOG_BOX_H
24 #define STARK_UI_DIALOG_BOX_H
25 
26 #include "engines/stark/stark.h"
27 #include "engines/stark/ui/window.h"
28 
29 #include "common/keyboard.h"
30 #include "common/scummsys.h"
31 
32 namespace Stark {
33 
34 namespace Gfx {
35 class SurfaceRenderer;
36 class Texture;
37 }
38 
39 typedef Common::Functor0<void> ConfirmCallback;
40 
41 class VisualText;
42 
43 /**
44  * A confirmation dialog with two buttons
45  *
46  * The cancel button closes the dialog without action.
47  * The confirm button executes a callback.
48  */
49 class DialogBox : public Window {
50 public:
51 	DialogBox(StarkEngine *vm, Gfx::Driver *gfx, Cursor *cursor);
52 	~DialogBox() override;
53 
54 	/** Make the dialog visible with the specified message */
55 	void open(const Common::String &message, ConfirmCallback *confirmCallback,
56 	          const Common::String &confirmLabel, const Common::String &cancelLabel);
57 
58 	/** Hide the dialog performing no action */
59 	void close();
60 
61 	/** Called when the screen resolution changes */
62 	void onScreenChanged();
63 
64 	/** Called when a keyboard key is pressed and the dialog is active */
65 	void onKeyPress(const Common::KeyState &keyState);
66 
67 protected:
68 	void onRender() override;
69 	void onClick(const Common::Point &pos) override;
70 
71 private:
72 	Graphics::Surface *loadBackground();
73 	static void drawBevel(Graphics::Surface *surface, const Common::Rect &rect);
74 	static Common::Rect centerRect(const Common::Rect &container, const Common::Rect &size);
75 
76 	void freeForeground();
77 	void recomputeLayout();
78 
79 	StarkEngine *_vm;
80 
81 	Gfx::SurfaceRenderer *_surfaceRenderer;
82 	Gfx::Texture *_backgroundTexture;
83 	Gfx::Texture *_foregroundTexture;
84 
85 	VisualText *_messageVisual;
86 	VisualText *_confirmLabelVisual;
87 	VisualText *_cancelLabelVisual;
88 
89 	Common::Rect _confirmButtonRect;
90 	Common::Rect _cancelButtonRect;
91 	Common::Rect _messageRect;
92 
93 	ConfirmCallback *_confirmCallback;
94 };
95 
96 } // End of namespace Stark
97 
98 #endif // STARK_UI_DIALOG_BOX_H
99