dialogs.h 4.0 KB

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