Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
godotengine
GitHub Repository: godotengine/godot
Path: blob/master/scene/gui/dialogs.h
9898 views
1
/**************************************************************************/
2
/* dialogs.h */
3
/**************************************************************************/
4
/* This file is part of: */
5
/* GODOT ENGINE */
6
/* https://godotengine.org */
7
/**************************************************************************/
8
/* Copyright (c) 2014-present Godot Engine contributors (see AUTHORS.md). */
9
/* Copyright (c) 2007-2014 Juan Linietsky, Ariel Manzur. */
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
31
#pragma once
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
#include "scene/main/window.h"
40
41
class LineEdit;
42
43
class AcceptDialog : public Window {
44
GDCLASS(AcceptDialog, Window);
45
46
Window *parent_visible = nullptr;
47
48
Panel *bg_panel = nullptr;
49
Label *message_label = nullptr;
50
HBoxContainer *buttons_hbox = nullptr;
51
Button *ok_button = nullptr;
52
53
bool popped_up = false;
54
String ok_text;
55
String default_ok_text;
56
57
bool hide_on_ok = true;
58
bool close_on_escape = true;
59
60
struct ThemeCache {
61
Ref<StyleBox> panel_style;
62
int buttons_separation = 0;
63
int buttons_min_width = 0;
64
int buttons_min_height = 0;
65
} theme_cache;
66
67
void _custom_action(const String &p_action);
68
void _button_visibility_changed(Button *button);
69
void _update_child_rects();
70
void _update_ok_text();
71
72
inline static bool swap_cancel_ok = false;
73
74
void _parent_focused();
75
76
protected:
77
virtual Size2 _get_contents_minimum_size() const override;
78
virtual void _input_from_window(const Ref<InputEvent> &p_event) override;
79
virtual void _post_popup() override;
80
81
void _notification(int p_what);
82
static void _bind_methods();
83
void _validate_property(PropertyInfo &p_property) const;
84
85
virtual void ok_pressed() {}
86
virtual void cancel_pressed() {}
87
virtual void custom_action(const String &) {}
88
89
void set_default_ok_text(const String &p_text);
90
91
// Not private since used by derived classes signal.
92
void _text_submitted(const String &p_text);
93
void _ok_pressed();
94
void _cancel_pressed();
95
96
#ifndef DISABLE_DEPRECATED
97
void _register_text_enter_bind_compat_89419(Control *p_line_edit);
98
void _remove_button_bind_compat_89419(Control *p_button);
99
100
static void _bind_compatibility_methods();
101
#endif
102
103
public:
104
Label *get_label() { return message_label; }
105
static void set_swap_cancel_ok(bool p_swap);
106
107
void register_text_enter(LineEdit *p_line_edit);
108
109
Button *get_ok_button() { return ok_button; }
110
Button *add_button(const String &p_text, bool p_right = false, const String &p_action = "");
111
Button *add_cancel_button(const String &p_cancel = "");
112
void remove_button(Button *p_button);
113
114
void set_hide_on_ok(bool p_hide);
115
bool get_hide_on_ok() const;
116
117
void set_close_on_escape(bool p_enable);
118
bool get_close_on_escape() const;
119
120
void set_text(String p_text);
121
String get_text() const;
122
123
void set_autowrap(bool p_autowrap);
124
bool has_autowrap();
125
126
void set_ok_button_text(String p_ok_button_text);
127
String get_ok_button_text() const;
128
129
AcceptDialog();
130
~AcceptDialog();
131
};
132
133
class ConfirmationDialog : public AcceptDialog {
134
GDCLASS(ConfirmationDialog, AcceptDialog);
135
Button *cancel = nullptr;
136
137
protected:
138
static void _bind_methods();
139
140
public:
141
Button *get_cancel_button();
142
143
void set_cancel_button_text(String p_cancel_button_text);
144
String get_cancel_button_text() const;
145
146
ConfirmationDialog();
147
};
148
149