dialogs.h 4.9 KB

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