dialogs.h 4.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133
  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 hide_on_ok = true;
  48. bool close_on_escape = true;
  49. struct ThemeCache {
  50. Ref<StyleBox> panel_style;
  51. int buttons_separation = 0;
  52. } theme_cache;
  53. void _custom_action(const String &p_action);
  54. void _custom_button_visibility_changed(Button *button);
  55. void _update_child_rects();
  56. static bool swap_cancel_ok;
  57. void _input_from_window(const Ref<InputEvent> &p_event);
  58. void _parent_focused();
  59. protected:
  60. virtual Size2 _get_contents_minimum_size() const override;
  61. void _notification(int p_what);
  62. static void _bind_methods();
  63. virtual void ok_pressed() {}
  64. virtual void cancel_pressed() {}
  65. virtual void custom_action(const String &) {}
  66. // Not private since used by derived classes signal.
  67. void _text_submitted(const String &p_text);
  68. void _ok_pressed();
  69. void _cancel_pressed();
  70. public:
  71. Label *get_label() { return message_label; }
  72. static void set_swap_cancel_ok(bool p_swap);
  73. void register_text_enter(Control *p_line_edit);
  74. Button *get_ok_button() { return ok_button; }
  75. Button *add_button(const String &p_text, bool p_right = false, const String &p_action = "");
  76. Button *add_cancel_button(const String &p_cancel = "");
  77. void remove_button(Control *p_button);
  78. void set_hide_on_ok(bool p_hide);
  79. bool get_hide_on_ok() const;
  80. void set_close_on_escape(bool p_enable);
  81. bool get_close_on_escape() const;
  82. void set_text(String p_text);
  83. String get_text() const;
  84. void set_autowrap(bool p_autowrap);
  85. bool has_autowrap();
  86. void set_ok_button_text(String p_ok_button_text);
  87. String get_ok_button_text() const;
  88. AcceptDialog();
  89. ~AcceptDialog();
  90. };
  91. class ConfirmationDialog : public AcceptDialog {
  92. GDCLASS(ConfirmationDialog, AcceptDialog);
  93. Button *cancel = nullptr;
  94. protected:
  95. static void _bind_methods();
  96. public:
  97. Button *get_cancel_button();
  98. void set_cancel_button_text(String p_cancel_button_text);
  99. String get_cancel_button_text() const;
  100. ConfirmationDialog();
  101. };
  102. #endif // DIALOGS_H