diff --git a/src/guiengine/abstract_top_level_container.cpp b/src/guiengine/abstract_top_level_container.cpp index cd504059f..72d8d3852 100644 --- a/src/guiengine/abstract_top_level_container.cpp +++ b/src/guiengine/abstract_top_level_container.cpp @@ -91,6 +91,25 @@ void AbstractTopLevelContainer::addWidgetsRecursively( } // addWidgetsRecursively +// ---------------------------------------------------------------------------- +/** This function invokes resize() of each widgets and its children. + * \param widgets The vector of widgets to resize + * \param parent The parent widget of the vector of widgets */ +void AbstractTopLevelContainer::resizeWidgetsRecursively(PtrVector& widgets) +{ + const unsigned short widgets_amount = widgets.size(); + + for (int n=0; n& widgets, Widget* parent=NULL); + void resizeWidgetsRecursively(PtrVector& widgets); public: AbstractTopLevelContainer(); diff --git a/src/guiengine/engine.cpp b/src/guiengine/engine.cpp index 272ed60e7..d38188352 100644 --- a/src/guiengine/engine.cpp +++ b/src/guiengine/engine.cpp @@ -951,6 +951,8 @@ namespace GUIEngine } Debug::closeDebugMenu(); + if (!g_current_screen->isLoaded()) + g_current_screen->loadFromFile(); g_current_screen->beforeAddingWidget(); // show screen diff --git a/src/guiengine/engine.hpp b/src/guiengine/engine.hpp index acad0395a..3e11ac12d 100644 --- a/src/guiengine/engine.hpp +++ b/src/guiengine/engine.hpp @@ -102,6 +102,7 @@ namespace GUIEngine /** Widgets that need to be notified at every frame can add themselves there (FIXME: unclean) */ extern PtrVector needsUpdate; + extern PtrVector g_loaded_screens; /** * \brief Call this method to init the GUI engine. diff --git a/src/guiengine/screen.cpp b/src/guiengine/screen.cpp index ae6b9d126..1ca7af106 100644 --- a/src/guiengine/screen.cpp +++ b/src/guiengine/screen.cpp @@ -229,6 +229,17 @@ void Screen::manualRemoveWidget(Widget* w) m_widgets.remove(w); } // manualRemoveWidget +// ----------------------------------------------------------------------------- +void Screen::onResize() +{ + m_width = irr_driver->getActualScreenSize().Width; + m_height = irr_driver->getActualScreenSize().Height; + + calculateLayout(); + + resizeWidgetsRecursively(m_widgets); +} // onResize + // ----------------------------------------------------------------------------- #if 0 diff --git a/src/guiengine/screen.hpp b/src/guiengine/screen.hpp index 5926eeda4..b9900f8f6 100644 --- a/src/guiengine/screen.hpp +++ b/src/guiengine/screen.hpp @@ -289,6 +289,11 @@ protected: */ virtual void onDraw(float dt) { }; + /** + * \brief optional callback you can override to be notified at every resize. + */ + virtual void onResize(); + /** * \return which music to play at this screen */ diff --git a/src/guiengine/widget.cpp b/src/guiengine/widget.cpp index 19fcf642f..1a0e149a5 100644 --- a/src/guiengine/widget.cpp +++ b/src/guiengine/widget.cpp @@ -299,17 +299,23 @@ bool Widget::isFocusedForPlayer(const int playerID) // ----------------------------------------------------------------------------- -void Widget::move(const int x, const int y, const int w, const int h) +void Widget::resize() { assert(m_magic_number == 0xCAFEC001); + if (m_element) + moveIrrlichtElement(); +} + +// ----------------------------------------------------------------------------- + +void Widget::move(const int x, const int y, const int w, const int h) +{ m_x = x; m_y = y; m_w = w; m_h = h; - - if (m_element != NULL) - m_element->setRelativePosition( core::rect < s32 > (x, y, x+w, y+h) ); + resize(); } // ----------------------------------------------------------------------------- diff --git a/src/guiengine/widget.hpp b/src/guiengine/widget.hpp index 2170a4590..03aaac9f2 100644 --- a/src/guiengine/widget.hpp +++ b/src/guiengine/widget.hpp @@ -405,7 +405,12 @@ namespace GUIEngine virtual EventPropagation onActivationInput(const int playerID) { return EVENT_LET; } /** - * Call to resize/move the widget. Not all widgets can resize gracefully. + * Call to resize the widget when its coordinations are updated. + */ + virtual void resize(); + + /** + * Move the widget to the given position. */ virtual void move(const int x, const int y, const int w, const int h);