diff options
author | Juan Linietsky <reduzio@gmail.com> | 2016-10-05 01:26:35 -0300 |
---|---|---|
committer | Juan Linietsky <reduzio@gmail.com> | 2016-10-05 01:26:35 -0300 |
commit | cf5778e51a883936ffc896231da8259e5ebabc0a (patch) | |
tree | 286f7eb7956a5c2c275276bbc9e3db5e3ff0730f /scene/gui | |
parent | a6e9dc615346f44b68b418483dd218d11ba4a674 (diff) |
-Added ViewportContainer, this is the only way to make viewports show up in GUI now
-2D editing now seems to work
-Added some functions and refactoring to Viewport
Diffstat (limited to 'scene/gui')
-rw-r--r-- | scene/gui/viewport_container.cpp | 103 | ||||
-rw-r--r-- | scene/gui/viewport_container.h | 25 |
2 files changed, 128 insertions, 0 deletions
diff --git a/scene/gui/viewport_container.cpp b/scene/gui/viewport_container.cpp new file mode 100644 index 0000000000..3418a495e9 --- /dev/null +++ b/scene/gui/viewport_container.cpp @@ -0,0 +1,103 @@ +#include "viewport_container.h" +#include "scene/main/viewport.h" +Size2 ViewportContainer::get_minimum_size() const { + + + if (stretch) + return Size2(); + Size2 ms; + for(int i=0;i<get_child_count();i++) { + + Viewport *c = get_child(i)->cast_to<Viewport>(); + if (!c) + continue; + + Size2 minsize = c->get_size(); + ms.width = MAX(ms.width , minsize.width); + ms.height = MAX(ms.height , minsize.height); + } + + return ms; + +} + + +void ViewportContainer::set_stretch(bool p_enable) { + + stretch=p_enable; + queue_sort(); + update(); + +} + +bool ViewportContainer::is_stretch_enabled() const { + + return stretch; +} + + +void ViewportContainer::_notification(int p_what) { + + + if (p_what==NOTIFICATION_RESIZED) { + + if (!stretch) + return; + + for(int i=0;i<get_child_count();i++) { + + Viewport *c = get_child(i)->cast_to<Viewport>(); + if (!c) + continue; + + c->set_size(get_size()); + } + } + + if (p_what==NOTIFICATION_ENTER_TREE || p_what==NOTIFICATION_VISIBILITY_CHANGED) { + + for(int i=0;i<get_child_count();i++) { + + Viewport *c = get_child(i)->cast_to<Viewport>(); + if (!c) + continue; + + + if (is_visible()) + c->set_update_mode(Viewport::UPDATE_ALWAYS); + else + c->set_update_mode(Viewport::UPDATE_DISABLED); + } + + } + + if (p_what==NOTIFICATION_DRAW) { + + for(int i=0;i<get_child_count();i++) { + + + Viewport *c = get_child(i)->cast_to<Viewport>(); + if (!c) + continue; + + if (stretch) + draw_texture_rect(c->get_texture(),Rect2(Vector2(),get_size()*Size2(1,-1))); + else + draw_texture_rect(c->get_texture(),Rect2(Vector2(),c->get_size()*Size2(1,-1))); + } + } + +} + +void ViewportContainer::_bind_methods() { + + ObjectTypeDB::bind_method(_MD("set_stretch","enable"),&ViewportContainer::set_stretch); + ObjectTypeDB::bind_method(_MD("is_stretch_enabled"),&ViewportContainer::is_stretch_enabled); + + ADD_PROPERTY( PropertyInfo(Variant::BOOL,"stretch"),_SCS("set_stretch"),_SCS("is_stretch_enabled")); +} + +ViewportContainer::ViewportContainer() { + + stretch=false; +} diff --git a/scene/gui/viewport_container.h b/scene/gui/viewport_container.h new file mode 100644 index 0000000000..cfc58f7d6e --- /dev/null +++ b/scene/gui/viewport_container.h @@ -0,0 +1,25 @@ +#ifndef VIEWPORTCONTAINER_H +#define VIEWPORTCONTAINER_H + +#include "scene/gui/container.h" + +class ViewportContainer : public Container { + + OBJ_TYPE( ViewportContainer, Container ); + + bool stretch; +protected: + + void _notification(int p_what); + static void _bind_methods(); +public: + + void set_stretch(bool p_enable); + bool is_stretch_enabled() const; + + virtual Size2 get_minimum_size() const; + + ViewportContainer(); +}; + +#endif // VIEWPORTCONTAINER_H |