1 /*************************************************************************/
2 /*  dialogs.h                                                            */
3 /*************************************************************************/
4 /*                       This file is part of:                           */
5 /*                           GODOT ENGINE                                */
6 /*                      https://godotengine.org                          */
7 /*************************************************************************/
8 /* Copyright (c) 2007-2019 Juan Linietsky, Ariel Manzur.                 */
9 /* Copyright (c) 2014-2019 Godot Engine contributors (cf. AUTHORS.md)    */
10 /*                                                                       */
11 /* Permission is hereby granted, free of charge, to any person obtaining */
12 /* a copy of this software and associated documentation files (the       */
13 /* "Software"), to deal in the Software without restriction, including   */
14 /* without limitation the rights to use, copy, modify, merge, publish,   */
15 /* distribute, sublicense, and/or sell copies of the Software, and to    */
16 /* permit persons to whom the Software is furnished to do so, subject to */
17 /* the following conditions:                                             */
18 /*                                                                       */
19 /* The above copyright notice and this permission notice shall be        */
20 /* included in all copies or substantial portions of the Software.       */
21 /*                                                                       */
22 /* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,       */
23 /* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF    */
24 /* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.*/
25 /* IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY  */
26 /* CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,  */
27 /* TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE     */
28 /* SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.                */
29 /*************************************************************************/
30 #ifndef DIALOGS_H
31 #define DIALOGS_H
32 
33 #include "box_container.h"
34 #include "scene/gui/button.h"
35 #include "scene/gui/label.h"
36 #include "scene/gui/panel.h"
37 #include "scene/gui/popup.h"
38 #include "scene/gui/texture_button.h"
39 /**
40 	@author Juan Linietsky <reduzio@gmail.com>
41 */
42 
43 class WindowDialog : public Popup {
44 
45 	OBJ_TYPE(WindowDialog, Popup);
46 
47 	TextureButton *close_button;
48 	String title;
49 	bool dragging;
50 
51 	void _input_event(const InputEvent &p_event);
52 	void _closed();
53 
54 protected:
55 	virtual void _post_popup();
56 
_close_pressed()57 	virtual void _close_pressed() {}
58 	virtual bool has_point(const Point2 &p_point) const;
59 	void _notification(int p_what);
60 	static void _bind_methods();
61 
62 public:
63 	TextureButton *get_close_button();
64 
65 	void set_title(const String &p_title);
66 	String get_title() const;
67 
68 	Size2 get_minimum_size() const;
69 
70 	WindowDialog();
71 	~WindowDialog();
72 };
73 
74 class PopupDialog : public Popup {
75 
76 	OBJ_TYPE(PopupDialog, Popup);
77 
78 protected:
79 	void _notification(int p_what);
80 
81 public:
82 	PopupDialog();
83 	~PopupDialog();
84 };
85 
86 class LineEdit;
87 
88 class AcceptDialog : public WindowDialog {
89 
90 	OBJ_TYPE(AcceptDialog, WindowDialog);
91 
92 	Control *child;
93 	HBoxContainer *hbc;
94 	Label *label;
95 	Button *ok;
96 	//	Button *cancel; no more cancel (there is X on tht titlebar)
97 	bool hide_on_ok;
98 
99 	void _custom_action(const String &p_action);
100 	void _ok_pressed();
101 	void _close_pressed();
102 	void _builtin_text_entered(const String &p_text);
103 	void _update_child_rect();
104 
105 	static bool swap_ok_cancel;
106 
107 	virtual void remove_child_notify(Node *p_child);
108 
109 protected:
110 	virtual void _post_popup();
111 	void _notification(int p_what);
112 	static void _bind_methods();
ok_pressed()113 	virtual void ok_pressed() {}
cancel_pressed()114 	virtual void cancel_pressed() {}
custom_action(const String &)115 	virtual void custom_action(const String &) {}
116 
117 public:
118 	Size2 get_minimum_size() const;
119 
get_label()120 	Label *get_label() { return label; }
121 	static void set_swap_ok_cancel(bool p_swap);
122 
123 	void register_text_enter(Node *p_line_edit);
124 
get_ok()125 	Button *get_ok() { return ok; }
126 	Button *add_button(const String &p_text, bool p_right = false, const String &p_action = "");
127 	Button *add_cancel(const String &p_cancel = "");
128 
129 	void set_hide_on_ok(bool p_hide);
130 	bool get_hide_on_ok() const;
131 
132 	void set_text(String p_text);
133 	String get_text() const;
134 
135 	void set_child_rect(Control *p_child);
136 
137 	AcceptDialog();
138 	~AcceptDialog();
139 };
140 
141 class ConfirmationDialog : public AcceptDialog {
142 
143 	OBJ_TYPE(ConfirmationDialog, AcceptDialog);
144 	Button *cancel;
145 
146 protected:
147 	static void _bind_methods();
148 
149 public:
150 	Button *get_cancel();
151 	ConfirmationDialog();
152 };
153 
154 #endif
155