Commit 71ac2ee2 authored by cutealien's avatar cutealien

- serialize modal screens

- allow stacking modal screens
- allowing hiding modals
- replace many IsVisible checks with virtual isVisible() checks in IGUIElement 


git-svn-id: svn://svn.code.sf.net/p/irrlicht/code/trunk@2406 dfc29bdd-3216-0410-991c-e03cc46cb475
parent 122084c7
...@@ -358,7 +358,7 @@ public: ...@@ -358,7 +358,7 @@ public:
core::list<IGUIElement*>::Iterator it = Children.getLast(); core::list<IGUIElement*>::Iterator it = Children.getLast();
if (IsVisible) if (isVisible())
{ {
while(it != Children.end()) while(it != Children.end())
{ {
...@@ -370,7 +370,7 @@ public: ...@@ -370,7 +370,7 @@ public:
} }
} }
if (IsVisible && isPointInside(point)) if (isVisible() && isPointInside(point))
target = this; target = this;
return target; return target;
...@@ -425,7 +425,7 @@ public: ...@@ -425,7 +425,7 @@ public:
//! Draws the element and its children. //! Draws the element and its children.
virtual void draw() virtual void draw()
{ {
if ( IsVisible ) if ( isVisible() )
{ {
core::list<IGUIElement*>::Iterator it = Children.begin(); core::list<IGUIElement*>::Iterator it = Children.begin();
for (; it != Children.end(); ++it) for (; it != Children.end(); ++it)
...@@ -437,7 +437,7 @@ public: ...@@ -437,7 +437,7 @@ public:
//! animate the element and its children. //! animate the element and its children.
virtual void OnPostRender(u32 timeMs) virtual void OnPostRender(u32 timeMs)
{ {
if ( IsVisible ) if ( isVisible() )
{ {
core::list<IGUIElement*>::Iterator it = Children.begin(); core::list<IGUIElement*>::Iterator it = Children.begin();
for (; it != Children.end(); ++it) for (; it != Children.end(); ++it)
......
...@@ -29,23 +29,70 @@ CGUIModalScreen::CGUIModalScreen(IGUIEnvironment* environment, IGUIElement* pare ...@@ -29,23 +29,70 @@ CGUIModalScreen::CGUIModalScreen(IGUIEnvironment* environment, IGUIElement* pare
setTabGroup(true); setTabGroup(true);
} }
bool CGUIModalScreen::canTakeFocus(IGUIElement* target) const
{
return (target && (target == this // this element can take it
|| isMyChild(target) // own childs also
|| (target->getType() == EGUIET_MODAL_SCREEN )// other modals also fine
|| (target->getParent() && target->getParent()->getType() == EGUIET_MODAL_SCREEN ))) // childs of other modals will do
;
}
bool CGUIModalScreen::isVisible() const
{
// any parent invisible?
IGUIElement * parentElement = getParent();
while ( parentElement )
{
if ( !parentElement->isVisible() )
return false;
parentElement = parentElement->getParent();
}
// if we have no children then the modal is probably abused as a way to block input
if ( Children.empty() )
{
return IGUIElement::isVisible();
}
// any child visible?
bool visible = false;
core::list<IGUIElement*>::ConstIterator it = Children.begin();
for (; it != Children.end(); ++it)
{
if ( (*it)->isVisible() )
{
visible = true;
break;
}
}
return visible;
}
bool CGUIModalScreen::isPointInside(const core::position2d<s32>& point) const
{
return true;
}
//! called if an event happened. //! called if an event happened.
bool CGUIModalScreen::OnEvent(const SEvent& event) bool CGUIModalScreen::OnEvent(const SEvent& event)
{ {
if (!IsEnabled || !isVisible() )
return IGUIElement::OnEvent(event);
switch(event.EventType) switch(event.EventType)
{ {
case EET_GUI_EVENT: case EET_GUI_EVENT:
switch(event.GUIEvent.EventType) switch(event.GUIEvent.EventType)
{ {
case EGET_ELEMENT_FOCUSED: case EGET_ELEMENT_FOCUSED:
// only children are allowed the focus if ( !canTakeFocus(event.GUIEvent.Caller))
if (event.GUIEvent.Caller != this && !isMyChild(event.GUIEvent.Caller)) {
Environment->setFocus(this); Environment->setFocus(this);
}
return false; return false;
case EGET_ELEMENT_FOCUS_LOST: case EGET_ELEMENT_FOCUS_LOST:
// only children are allowed the focus if ( !canTakeFocus(event.GUIEvent.Element))
if (!(isMyChild(event.GUIEvent.Element) || event.GUIEvent.Element == this))
{ {
MouseDownTime = os::Timer::getTime(); MouseDownTime = os::Timer::getTime();
return true; return true;
...@@ -116,7 +163,9 @@ void CGUIModalScreen::removeChild(IGUIElement* child) ...@@ -116,7 +163,9 @@ void CGUIModalScreen::removeChild(IGUIElement* child)
IGUIElement::removeChild(child); IGUIElement::removeChild(child);
if (Children.empty()) if (Children.empty())
{
remove(); remove();
}
} }
...@@ -148,13 +197,13 @@ void CGUIModalScreen::updateAbsolutePosition() ...@@ -148,13 +197,13 @@ void CGUIModalScreen::updateAbsolutePosition()
//! Writes attributes of the element. //! Writes attributes of the element.
void CGUIModalScreen::serializeAttributes(io::IAttributes* out, io::SAttributeReadWriteOptions* options=0) const void CGUIModalScreen::serializeAttributes(io::IAttributes* out, io::SAttributeReadWriteOptions* options=0) const
{ {
// these don't get serialized, their status is added to their children. IGUIElement::serializeAttributes(out,options);
} }
//! Reads attributes of the element //! Reads attributes of the element
void CGUIModalScreen::deserializeAttributes(io::IAttributes* in, io::SAttributeReadWriteOptions* options=0) void CGUIModalScreen::deserializeAttributes(io::IAttributes* in, io::SAttributeReadWriteOptions* options=0)
{ {
// these don't get deserialized. children create them if required IGUIElement::deserializeAttributes(in, options);
} }
......
...@@ -38,12 +38,23 @@ namespace gui ...@@ -38,12 +38,23 @@ namespace gui
//! Updates the absolute position. //! Updates the absolute position.
virtual void updateAbsolutePosition(); virtual void updateAbsolutePosition();
//! Modalscreen is not a typical element, but rather acts like a state for it's children.
//! isVisible is overriden to give this a useful behaviour, so that a modal will no longer
//! be active when its parent is invisible or all its children are invisible.
virtual bool isVisible() const;
//! Modals are infinite so every point is inside
virtual bool isPointInside(const core::position2d<s32>& point) const;
//! Writes attributes of the element. //! Writes attributes of the element.
virtual void serializeAttributes(io::IAttributes* out, io::SAttributeReadWriteOptions* options) const; virtual void serializeAttributes(io::IAttributes* out, io::SAttributeReadWriteOptions* options) const;
//! Reads attributes of the element //! Reads attributes of the element
virtual void deserializeAttributes(io::IAttributes* in, io::SAttributeReadWriteOptions* options); virtual void deserializeAttributes(io::IAttributes* in, io::SAttributeReadWriteOptions* options);
protected:
virtual bool canTakeFocus(IGUIElement* target) const;
private: private:
u32 MouseDownTime; u32 MouseDownTime;
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment