summaryrefslogtreecommitdiff
path: root/scene/gui/subviewport_container.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'scene/gui/subviewport_container.cpp')
-rw-r--r--scene/gui/subviewport_container.cpp71
1 files changed, 33 insertions, 38 deletions
diff --git a/scene/gui/subviewport_container.cpp b/scene/gui/subviewport_container.cpp
index 50f468741d..4e1ad2ae05 100644
--- a/scene/gui/subviewport_container.cpp
+++ b/scene/gui/subviewport_container.cpp
@@ -1,5 +1,5 @@
/*************************************************************************/
-/* subviewport_container.cpp */
+/* subviewport_container.cpp */
/*************************************************************************/
/* This file is part of: */
/* GODOT ENGINE */
@@ -34,15 +34,15 @@
#include "scene/main/viewport.h"
Size2 SubViewportContainer::get_minimum_size() const {
-
- if (stretch)
+ if (stretch) {
return Size2();
+ }
Size2 ms;
for (int i = 0; i < get_child_count(); i++) {
-
SubViewport *c = Object::cast_to<SubViewport>(get_child(i));
- if (!c)
+ if (!c) {
continue;
+ }
Size2 minsize = c->get_size();
ms.width = MAX(ms.width, minsize.width);
@@ -53,33 +53,32 @@ Size2 SubViewportContainer::get_minimum_size() const {
}
void SubViewportContainer::set_stretch(bool p_enable) {
-
stretch = p_enable;
queue_sort();
update();
}
bool SubViewportContainer::is_stretch_enabled() const {
-
return stretch;
}
void SubViewportContainer::set_stretch_shrink(int p_shrink) {
-
ERR_FAIL_COND(p_shrink < 1);
- if (shrink == p_shrink)
+ if (shrink == p_shrink) {
return;
+ }
shrink = p_shrink;
- if (!stretch)
+ if (!stretch) {
return;
+ }
for (int i = 0; i < get_child_count(); i++) {
-
SubViewport *c = Object::cast_to<SubViewport>(get_child(i));
- if (!c)
+ if (!c) {
continue;
+ }
c->set_size(get_size() / shrink);
}
@@ -88,64 +87,62 @@ void SubViewportContainer::set_stretch_shrink(int p_shrink) {
}
int SubViewportContainer::get_stretch_shrink() const {
-
return shrink;
}
void SubViewportContainer::_notification(int p_what) {
-
if (p_what == NOTIFICATION_RESIZED) {
-
- if (!stretch)
+ if (!stretch) {
return;
+ }
for (int i = 0; i < get_child_count(); i++) {
-
SubViewport *c = Object::cast_to<SubViewport>(get_child(i));
- if (!c)
+ if (!c) {
continue;
+ }
c->set_size(get_size() / shrink);
}
}
if (p_what == NOTIFICATION_ENTER_TREE || p_what == NOTIFICATION_VISIBILITY_CHANGED) {
-
for (int i = 0; i < get_child_count(); i++) {
-
SubViewport *c = Object::cast_to<SubViewport>(get_child(i));
- if (!c)
+ if (!c) {
continue;
+ }
- if (is_visible_in_tree())
+ if (is_visible_in_tree()) {
c->set_update_mode(SubViewport::UPDATE_ALWAYS);
- else
+ } else {
c->set_update_mode(SubViewport::UPDATE_DISABLED);
+ }
c->set_handle_input_locally(false); //do not handle input locally here
}
}
if (p_what == NOTIFICATION_DRAW) {
-
for (int i = 0; i < get_child_count(); i++) {
-
SubViewport *c = Object::cast_to<SubViewport>(get_child(i));
- if (!c)
+ if (!c) {
continue;
+ }
- if (stretch)
+ if (stretch) {
draw_texture_rect(c->get_texture(), Rect2(Vector2(), get_size()));
- else
+ } else {
draw_texture_rect(c->get_texture(), Rect2(Vector2(), c->get_size()));
+ }
}
}
}
void SubViewportContainer::_input(const Ref<InputEvent> &p_event) {
-
- if (Engine::get_singleton()->is_editor_hint())
+ if (Engine::get_singleton()->is_editor_hint()) {
return;
+ }
Transform2D xform = get_global_transform();
@@ -158,19 +155,19 @@ void SubViewportContainer::_input(const Ref<InputEvent> &p_event) {
Ref<InputEvent> ev = p_event->xformed_by(xform.affine_inverse());
for (int i = 0; i < get_child_count(); i++) {
-
SubViewport *c = Object::cast_to<SubViewport>(get_child(i));
- if (!c || c->is_input_disabled())
+ if (!c || c->is_input_disabled()) {
continue;
+ }
c->input(ev);
}
}
void SubViewportContainer::_unhandled_input(const Ref<InputEvent> &p_event) {
-
- if (Engine::get_singleton()->is_editor_hint())
+ if (Engine::get_singleton()->is_editor_hint()) {
return;
+ }
Transform2D xform = get_global_transform();
@@ -183,17 +180,16 @@ void SubViewportContainer::_unhandled_input(const Ref<InputEvent> &p_event) {
Ref<InputEvent> ev = p_event->xformed_by(xform.affine_inverse());
for (int i = 0; i < get_child_count(); i++) {
-
SubViewport *c = Object::cast_to<SubViewport>(get_child(i));
- if (!c || c->is_input_disabled())
+ if (!c || c->is_input_disabled()) {
continue;
+ }
c->unhandled_input(ev);
}
}
void SubViewportContainer::_bind_methods() {
-
ClassDB::bind_method(D_METHOD("_unhandled_input", "event"), &SubViewportContainer::_unhandled_input);
ClassDB::bind_method(D_METHOD("_input", "event"), &SubViewportContainer::_input);
ClassDB::bind_method(D_METHOD("set_stretch", "enable"), &SubViewportContainer::set_stretch);
@@ -207,7 +203,6 @@ void SubViewportContainer::_bind_methods() {
}
SubViewportContainer::SubViewportContainer() {
-
stretch = false;
shrink = 1;
set_process_input(true);