dialogs.h 4.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123
  1. /*************************************************************************/
  2. /* dialogs.h */
  3. /*************************************************************************/
  4. /* This file is part of: */
  5. /* GODOT ENGINE */
  6. /* https://godotengine.org */
  7. /*************************************************************************/
  8. /* Copyright (c) 2007-2022 Juan Linietsky, Ariel Manzur. */
  9. /* Copyright (c) 2014-2022 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. #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 = nullptr;
  44. HBoxContainer *hbc = nullptr;
  45. Label *label = nullptr;
  46. Button *ok = nullptr;
  47. bool hide_on_ok = true;
  48. bool close_on_escape = true;
  49. void _custom_action(const String &p_action);
  50. void _update_child_rects();
  51. static bool swap_cancel_ok;
  52. void _input_from_window(const Ref<InputEvent> &p_event);
  53. void _parent_focused();
  54. protected:
  55. virtual Size2 _get_contents_minimum_size() const override;
  56. void _notification(int p_what);
  57. static void _bind_methods();
  58. virtual void ok_pressed() {}
  59. virtual void cancel_pressed() {}
  60. virtual void custom_action(const String &) {}
  61. // Not private since used by derived classes signal.
  62. void _text_submitted(const String &p_text);
  63. void _ok_pressed();
  64. void _cancel_pressed();
  65. public:
  66. Label *get_label() { return label; }
  67. static void set_swap_cancel_ok(bool p_swap);
  68. void register_text_enter(Control *p_line_edit);
  69. Button *get_ok_button() { return ok; }
  70. Button *add_button(const String &p_text, bool p_right = false, const String &p_action = "");
  71. Button *add_cancel_button(const String &p_cancel = "");
  72. void remove_button(Control *p_button);
  73. void set_hide_on_ok(bool p_hide);
  74. bool get_hide_on_ok() const;
  75. void set_close_on_escape(bool p_enable);
  76. bool get_close_on_escape() const;
  77. void set_text(String p_text);
  78. String get_text() const;
  79. void set_autowrap(bool p_autowrap);
  80. bool has_autowrap();
  81. void set_ok_button_text(String p_ok_button_text);
  82. String get_ok_button_text() const;
  83. AcceptDialog();
  84. ~AcceptDialog();
  85. };
  86. class ConfirmationDialog : public AcceptDialog {
  87. GDCLASS(ConfirmationDialog, AcceptDialog);
  88. Button *cancel = nullptr;
  89. protected:
  90. static void _bind_methods();
  91. public:
  92. Button *get_cancel_button();
  93. void set_cancel_button_text(String p_cancel_button_text);
  94. String get_cancel_button_text() const;
  95. ConfirmationDialog();
  96. };
  97. #endif // DIALOGS_H