diff options
author | Juan Linietsky <reduzio@gmail.com> | 2017-10-31 14:23:25 -0300 |
---|---|---|
committer | Juan Linietsky <reduzio@gmail.com> | 2017-10-31 14:23:47 -0300 |
commit | a4ea63737c9ed862c4a421d668942d6ffaf5a861 (patch) | |
tree | db255867f3e033cd48e080340e9e8e2812badf45 /scene/gui | |
parent | 157fa55e34b9bf21a22876aecef89ed0a9491412 (diff) |
Ability to shrink 3D viewport by half
Diffstat (limited to 'scene/gui')
-rw-r--r-- | scene/gui/viewport_container.cpp | 35 | ||||
-rw-r--r-- | scene/gui/viewport_container.h | 4 |
2 files changed, 38 insertions, 1 deletions
diff --git a/scene/gui/viewport_container.cpp b/scene/gui/viewport_container.cpp index c321b873fd..9244d8de2f 100644 --- a/scene/gui/viewport_container.cpp +++ b/scene/gui/viewport_container.cpp @@ -62,6 +62,34 @@ bool ViewportContainer::is_stretch_enabled() const { return stretch; } +void ViewportContainer::set_stretch_shrink(int p_shrink) { + + ERR_FAIL_COND(p_shrink < 1); + if (shrink == p_shrink) + return; + + shrink = p_shrink; + + if (!stretch) + return; + + for (int i = 0; i < get_child_count(); i++) { + + Viewport *c = Object::cast_to<Viewport>(get_child(i)); + if (!c) + continue; + + c->set_size(get_size() / shrink); + } + + update(); +} + +int ViewportContainer::get_stretch_shrink() const { + + return shrink; +} + void ViewportContainer::_notification(int p_what) { if (p_what == NOTIFICATION_RESIZED) { @@ -75,7 +103,7 @@ void ViewportContainer::_notification(int p_what) { if (!c) continue; - c->set_size(get_size()); + c->set_size(get_size() / shrink); } } @@ -115,10 +143,15 @@ void ViewportContainer::_bind_methods() { ClassDB::bind_method(D_METHOD("set_stretch", "enable"), &ViewportContainer::set_stretch); ClassDB::bind_method(D_METHOD("is_stretch_enabled"), &ViewportContainer::is_stretch_enabled); + ClassDB::bind_method(D_METHOD("set_stretch_shrink", "amount"), &ViewportContainer::set_stretch_shrink); + ClassDB::bind_method(D_METHOD("get_stretch_shrink"), &ViewportContainer::get_stretch_shrink); + ADD_PROPERTY(PropertyInfo(Variant::BOOL, "stretch"), "set_stretch", "is_stretch_enabled"); + ADD_PROPERTY(PropertyInfo(Variant::INT, "stretch_shrink"), "set_stretch_shrink", "get_stretch_shrink"); } ViewportContainer::ViewportContainer() { stretch = false; + shrink = 1; } diff --git a/scene/gui/viewport_container.h b/scene/gui/viewport_container.h index 630523b5fb..ebf5869ed9 100644 --- a/scene/gui/viewport_container.h +++ b/scene/gui/viewport_container.h @@ -37,6 +37,7 @@ class ViewportContainer : public Container { GDCLASS(ViewportContainer, Container); bool stretch; + int shrink; protected: void _notification(int p_what); @@ -46,6 +47,9 @@ public: void set_stretch(bool p_enable); bool is_stretch_enabled() const; + void set_stretch_shrink(int p_shrink); + int get_stretch_shrink() const; + virtual Size2 get_minimum_size() const; ViewportContainer(); |