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