| 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 | #ifndef DIALOGS_H |
| 32 | #define DIALOGS_H |
| 33 | |
| 34 | #include "box_container.h" |
| 35 | #include "scene/gui/button.h" |
| 36 | #include "scene/gui/label.h" |
| 37 | #include "scene/gui/panel.h" |
| 38 | #include "scene/gui/popup.h" |
| 39 | #include "scene/gui/texture_button.h" |
| 40 | #include "scene/main/window.h" |
| 41 | |
| 42 | class LineEdit; |
| 43 | |
| 44 | class AcceptDialog : public Window { |
| 45 | GDCLASS(AcceptDialog, Window); |
| 46 | |
| 47 | Window *parent_visible = nullptr; |
| 48 | |
| 49 | Panel *bg_panel = nullptr; |
| 50 | Label *message_label = nullptr; |
| 51 | HBoxContainer *buttons_hbox = nullptr; |
| 52 | Button *ok_button = nullptr; |
| 53 | |
| 54 | bool hide_on_ok = true; |
| 55 | bool close_on_escape = true; |
| 56 | |
| 57 | struct ThemeCache { |
| 58 | Ref<StyleBox> panel_style; |
| 59 | int buttons_separation = 0; |
| 60 | } theme_cache; |
| 61 | |
| 62 | void _custom_action(const String &p_action); |
| 63 | void _custom_button_visibility_changed(Button *button); |
| 64 | void _update_child_rects(); |
| 65 | |
| 66 | static bool swap_cancel_ok; |
| 67 | |
| 68 | void _input_from_window(const Ref<InputEvent> &p_event); |
| 69 | void _parent_focused(); |
| 70 | |
| 71 | protected: |
| 72 | virtual Size2 _get_contents_minimum_size() const override; |
| 73 | |
| 74 | void _notification(int p_what); |
| 75 | static void _bind_methods(); |
| 76 | |
| 77 | virtual void ok_pressed() {} |
| 78 | virtual void cancel_pressed() {} |
| 79 | virtual void custom_action(const String &) {} |
| 80 | |
| 81 | // Not private since used by derived classes signal. |
| 82 | void _text_submitted(const String &p_text); |
| 83 | void _ok_pressed(); |
| 84 | void _cancel_pressed(); |
| 85 | |
| 86 | public: |
| 87 | Label *get_label() { return message_label; } |
| 88 | static void set_swap_cancel_ok(bool p_swap); |
| 89 | |
| 90 | void register_text_enter(Control *p_line_edit); |
| 91 | |
| 92 | Button *get_ok_button() { return ok_button; } |
| 93 | Button *add_button(const String &p_text, bool p_right = false, const String &p_action = "" ); |
| 94 | Button *add_cancel_button(const String &p_cancel = "" ); |
| 95 | void remove_button(Control *p_button); |
| 96 | |
| 97 | void set_hide_on_ok(bool p_hide); |
| 98 | bool get_hide_on_ok() const; |
| 99 | |
| 100 | void set_close_on_escape(bool p_enable); |
| 101 | bool get_close_on_escape() const; |
| 102 | |
| 103 | void set_text(String p_text); |
| 104 | String get_text() const; |
| 105 | |
| 106 | void set_autowrap(bool p_autowrap); |
| 107 | bool has_autowrap(); |
| 108 | |
| 109 | void set_ok_button_text(String p_ok_button_text); |
| 110 | String get_ok_button_text() const; |
| 111 | |
| 112 | AcceptDialog(); |
| 113 | ~AcceptDialog(); |
| 114 | }; |
| 115 | |
| 116 | class ConfirmationDialog : public AcceptDialog { |
| 117 | GDCLASS(ConfirmationDialog, AcceptDialog); |
| 118 | Button *cancel = nullptr; |
| 119 | |
| 120 | protected: |
| 121 | static void _bind_methods(); |
| 122 | |
| 123 | public: |
| 124 | Button *get_cancel_button(); |
| 125 | |
| 126 | void set_cancel_button_text(String p_cancel_button_text); |
| 127 | String get_cancel_button_text() const; |
| 128 | |
| 129 | ConfirmationDialog(); |
| 130 | }; |
| 131 | |
| 132 | #endif // DIALOGS_H |
| 133 | |