window_wrapper.h 4.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111
  1. /**************************************************************************/
  2. /* window_wrapper.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 WINDOW_WRAPPER_H
  31. #define WINDOW_WRAPPER_H
  32. #include "core/math/rect2.h"
  33. #include "scene/gui/margin_container.h"
  34. #include "scene/gui/menu_button.h"
  35. class Window;
  36. class HBoxContainer;
  37. class WindowWrapper : public MarginContainer {
  38. GDCLASS(WindowWrapper, MarginContainer);
  39. Control *wrapped_control = nullptr;
  40. MarginContainer *margins = nullptr;
  41. Window *window = nullptr;
  42. Panel *window_background = nullptr;
  43. Ref<Shortcut> enable_shortcut;
  44. Rect2 _get_default_window_rect() const;
  45. Node *_get_wrapped_control_parent() const;
  46. void _set_window_enabled_with_rect(bool p_visible, const Rect2 p_rect);
  47. void _set_window_rect(const Rect2 p_rect);
  48. protected:
  49. static void _bind_methods();
  50. void _notification(int p_what);
  51. virtual void shortcut_input(const Ref<InputEvent> &p_event) override;
  52. public:
  53. void set_wrapped_control(Control *p_control, const Ref<Shortcut> &p_enable_shortcut = Ref<Shortcut>());
  54. Control *get_wrapped_control() const;
  55. Control *release_wrapped_control();
  56. bool is_window_available() const;
  57. bool get_window_enabled() const;
  58. void set_window_enabled(bool p_enabled);
  59. Rect2i get_window_rect() const;
  60. int get_window_screen() const;
  61. void restore_window(const Rect2i &p_rect, int p_screen = -1);
  62. void restore_window_from_saved_position(const Rect2 p_window_rect, int p_screen, const Rect2 p_screen_rect);
  63. void enable_window_on_screen(int p_screen = -1, bool p_auto_scale = false);
  64. void set_window_title(const String &p_title);
  65. void set_margins_enabled(bool p_enabled);
  66. WindowWrapper();
  67. };
  68. class ScreenSelect : public Button {
  69. GDCLASS(ScreenSelect, Button);
  70. Popup *popup = nullptr;
  71. Panel *popup_background = nullptr;
  72. HBoxContainer *screen_list = nullptr;
  73. void _build_advanced_menu();
  74. void _emit_screen_signal(int p_screen_idx);
  75. void _handle_mouse_shortcut(const Ref<InputEvent> &p_event);
  76. void _show_popup();
  77. protected:
  78. virtual void pressed() override;
  79. static void _bind_methods();
  80. void _notification(int p_what);
  81. public:
  82. ScreenSelect();
  83. };
  84. #endif // WINDOW_WRAPPER_H