dialogs.h 4.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166
  1. /*************************************************************************/
  2. /* dialogs.h */
  3. /*************************************************************************/
  4. /* This file is part of: */
  5. /* GODOT ENGINE */
  6. /* https://godotengine.org */
  7. /*************************************************************************/
  8. /* Copyright (c) 2007-2019 Juan Linietsky, Ariel Manzur. */
  9. /* Copyright (c) 2014-2019 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. /**
  39. @author Juan Linietsky <reduzio@gmail.com>
  40. */
  41. class WindowDialog : public Popup {
  42. GDCLASS(WindowDialog, Popup);
  43. enum DRAG_TYPE {
  44. DRAG_NONE = 0,
  45. DRAG_MOVE = 1,
  46. DRAG_RESIZE_TOP = 1 << 1,
  47. DRAG_RESIZE_RIGHT = 1 << 2,
  48. DRAG_RESIZE_BOTTOM = 1 << 3,
  49. DRAG_RESIZE_LEFT = 1 << 4
  50. };
  51. TextureButton *close_button;
  52. String title;
  53. int drag_type;
  54. Point2 drag_offset;
  55. Point2 drag_offset_far;
  56. bool resizable;
  57. void _gui_input(const Ref<InputEvent> &p_event);
  58. void _closed();
  59. int _drag_hit_test(const Point2 &pos) const;
  60. protected:
  61. virtual void _post_popup();
  62. virtual void _fix_size();
  63. virtual void _close_pressed() {}
  64. virtual bool has_point(const Point2 &p_point) const;
  65. void _notification(int p_what);
  66. static void _bind_methods();
  67. public:
  68. TextureButton *get_close_button();
  69. void set_title(const String &p_title);
  70. String get_title() const;
  71. void set_resizable(bool p_resizable);
  72. bool get_resizable() const;
  73. Size2 get_minimum_size() const;
  74. WindowDialog();
  75. ~WindowDialog();
  76. };
  77. class PopupDialog : public Popup {
  78. GDCLASS(PopupDialog, Popup);
  79. protected:
  80. void _notification(int p_what);
  81. public:
  82. PopupDialog();
  83. ~PopupDialog();
  84. };
  85. class LineEdit;
  86. class AcceptDialog : public WindowDialog {
  87. GDCLASS(AcceptDialog, WindowDialog);
  88. HBoxContainer *hbc;
  89. Label *label;
  90. Button *ok;
  91. //Button *cancel; no more cancel (there is X on that titlebar)
  92. bool hide_on_ok;
  93. void _custom_action(const String &p_action);
  94. void _ok_pressed();
  95. void _close_pressed();
  96. void _builtin_text_entered(const String &p_text);
  97. void _update_child_rects();
  98. static bool swap_ok_cancel;
  99. protected:
  100. virtual void _post_popup();
  101. void _notification(int p_what);
  102. static void _bind_methods();
  103. virtual void ok_pressed() {}
  104. virtual void cancel_pressed() {}
  105. virtual void custom_action(const String &) {}
  106. public:
  107. Size2 get_minimum_size() const;
  108. Label *get_label() { return label; }
  109. static void set_swap_ok_cancel(bool p_swap);
  110. void register_text_enter(Node *p_line_edit);
  111. Button *get_ok() { return ok; }
  112. Button *add_button(const String &p_text, bool p_right = false, const String &p_action = "");
  113. Button *add_cancel(const String &p_cancel = "");
  114. void set_hide_on_ok(bool p_hide);
  115. bool get_hide_on_ok() const;
  116. void set_text(String p_text);
  117. String get_text() const;
  118. AcceptDialog();
  119. ~AcceptDialog();
  120. };
  121. class ConfirmationDialog : public AcceptDialog {
  122. GDCLASS(ConfirmationDialog, AcceptDialog);
  123. Button *cancel;
  124. protected:
  125. static void _bind_methods();
  126. public:
  127. Button *get_cancel();
  128. ConfirmationDialog();
  129. };
  130. #endif