Add basic code for widget and screen resize
This commit is contained in:
parent
78c6f16d79
commit
2f87966ff6
@ -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<Widget>& widgets)
|
||||
{
|
||||
const unsigned short widgets_amount = widgets.size();
|
||||
|
||||
for (int n=0; n<widgets_amount; n++)
|
||||
{
|
||||
widgets[n].resize();
|
||||
if (widgets[n].getType() == WTYPE_DIV)
|
||||
{
|
||||
resizeWidgetsRecursively(widgets[n].m_children);
|
||||
}
|
||||
} // for n in all widgets
|
||||
|
||||
} // resizeWidgetsRecursively
|
||||
|
||||
// ----------------------------------------------------------------------------
|
||||
|
||||
/** This function checks recursively if a widget is a child of a vector of widgets
|
||||
|
@ -63,6 +63,7 @@ namespace GUIEngine
|
||||
|
||||
void addWidgetsRecursively(PtrVector<Widget>& widgets,
|
||||
Widget* parent=NULL);
|
||||
void resizeWidgetsRecursively(PtrVector<Widget>& widgets);
|
||||
|
||||
public:
|
||||
AbstractTopLevelContainer();
|
||||
|
@ -951,6 +951,8 @@ namespace GUIEngine
|
||||
}
|
||||
|
||||
Debug::closeDebugMenu();
|
||||
if (!g_current_screen->isLoaded())
|
||||
g_current_screen->loadFromFile();
|
||||
g_current_screen->beforeAddingWidget();
|
||||
|
||||
// show screen
|
||||
|
@ -102,6 +102,7 @@ namespace GUIEngine
|
||||
|
||||
/** Widgets that need to be notified at every frame can add themselves there (FIXME: unclean) */
|
||||
extern PtrVector<Widget, REF> needsUpdate;
|
||||
extern PtrVector<Screen, REF> g_loaded_screens;
|
||||
|
||||
/**
|
||||
* \brief Call this method to init the GUI engine.
|
||||
|
@ -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
|
||||
|
@ -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
|
||||
*/
|
||||
|
@ -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();
|
||||
}
|
||||
|
||||
// -----------------------------------------------------------------------------
|
||||
|
@ -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);
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user