1 /*************************************************************************/
2 /* panel_container.cpp */
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 #include "panel_container.h"
31
get_minimum_size() const32 Size2 PanelContainer::get_minimum_size() const {
33
34 Ref<StyleBox> style;
35
36 if (has_stylebox("panel"))
37 style = get_stylebox("panel");
38 else
39 style = get_stylebox("panel", "PanelContainer");
40
41 Size2 ms;
42 for (int i = 0; i < get_child_count(); i++) {
43
44 Control *c = get_child(i)->cast_to<Control>();
45 if (!c || !c->is_visible())
46 continue;
47 if (c->is_set_as_toplevel())
48 continue;
49
50 Size2 minsize = c->get_combined_minimum_size();
51 ms.width = MAX(ms.width, minsize.width);
52 ms.height = MAX(ms.height, minsize.height);
53 }
54
55 if (style.is_valid())
56 ms += style->get_minimum_size();
57 return ms;
58 }
59
_notification(int p_what)60 void PanelContainer::_notification(int p_what) {
61
62 if (p_what == NOTIFICATION_DRAW) {
63
64 RID ci = get_canvas_item();
65 Ref<StyleBox> style;
66
67 if (has_stylebox("panel"))
68 style = get_stylebox("panel");
69 else
70 style = get_stylebox("panel", "PanelContainer");
71
72 style->draw(ci, Rect2(Point2(), get_size()));
73 }
74
75 if (p_what == NOTIFICATION_SORT_CHILDREN) {
76
77 Ref<StyleBox> style;
78
79 if (has_stylebox("panel"))
80 style = get_stylebox("panel");
81 else
82 style = get_stylebox("panel", "PanelContainer");
83
84 Size2 size = get_size();
85 Point2 ofs;
86 if (style.is_valid()) {
87 size -= style->get_minimum_size();
88 ofs += style->get_offset();
89 }
90
91 for (int i = 0; i < get_child_count(); i++) {
92
93 Control *c = get_child(i)->cast_to<Control>();
94 if (!c || !c->is_visible())
95 continue;
96 if (c->is_set_as_toplevel())
97 continue;
98
99 fit_child_in_rect(c, Rect2(ofs, size));
100 }
101 }
102 }
103
PanelContainer()104 PanelContainer::PanelContainer() {
105 }
106