2009-01-14 04:37:51 -08:00
|
|
|
// Copyright (C) 2002-2009 Nikolaus Gebhardt
|
2007-05-20 11:03:49 -07:00
|
|
|
// This file is part of the "Irrlicht Engine".
|
|
|
|
// For conditions of distribution and use, see copyright notice in irrlicht.h
|
|
|
|
|
|
|
|
#include "CGUIModalScreen.h"
|
2007-07-25 22:30:19 -07:00
|
|
|
#ifdef _IRR_COMPILE_WITH_GUI_
|
|
|
|
|
2007-05-20 11:03:49 -07:00
|
|
|
#include "IGUIEnvironment.h"
|
|
|
|
#include "os.h"
|
|
|
|
#include "IVideoDriver.h"
|
|
|
|
#include "IGUISkin.h"
|
|
|
|
|
|
|
|
namespace irr
|
|
|
|
{
|
|
|
|
namespace gui
|
|
|
|
{
|
|
|
|
|
|
|
|
//! constructor
|
|
|
|
CGUIModalScreen::CGUIModalScreen(IGUIEnvironment* environment, IGUIElement* parent, s32 id)
|
|
|
|
: IGUIElement(EGUIET_MODAL_SCREEN, environment, parent, id, parent->getAbsolutePosition()),
|
|
|
|
MouseDownTime(0)
|
|
|
|
{
|
|
|
|
#ifdef _DEBUG
|
|
|
|
setDebugName("CGUIModalScreen");
|
|
|
|
#endif
|
2007-06-08 18:07:21 -07:00
|
|
|
setAlignment(EGUIA_UPPERLEFT, EGUIA_LOWERRIGHT, EGUIA_UPPERLEFT, EGUIA_LOWERRIGHT);
|
2009-01-22 04:40:06 -08:00
|
|
|
|
2007-07-07 00:03:54 -07:00
|
|
|
// this element is a tab group
|
|
|
|
setTabGroup(true);
|
2007-05-20 11:03:49 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
//! called if an event happened.
|
2007-09-16 16:41:55 -07:00
|
|
|
bool CGUIModalScreen::OnEvent(const SEvent& event)
|
2007-05-20 11:03:49 -07:00
|
|
|
{
|
|
|
|
switch(event.EventType)
|
|
|
|
{
|
2007-07-07 00:03:54 -07:00
|
|
|
case EET_GUI_EVENT:
|
|
|
|
switch(event.GUIEvent.EventType)
|
|
|
|
{
|
|
|
|
case EGET_ELEMENT_FOCUSED:
|
2007-08-29 16:37:24 -07:00
|
|
|
// only children are allowed the focus
|
2007-07-07 00:03:54 -07:00
|
|
|
if (event.GUIEvent.Caller != this && !isMyChild(event.GUIEvent.Caller))
|
|
|
|
Environment->setFocus(this);
|
|
|
|
return false;
|
|
|
|
case EGET_ELEMENT_FOCUS_LOST:
|
2007-08-29 16:37:24 -07:00
|
|
|
// only children are allowed the focus
|
2007-07-07 00:03:54 -07:00
|
|
|
if (!(isMyChild(event.GUIEvent.Element) || event.GUIEvent.Element == this))
|
|
|
|
{
|
|
|
|
MouseDownTime = os::Timer::getTime();
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
else
|
2007-08-29 16:37:24 -07:00
|
|
|
{
|
2007-07-07 00:03:54 -07:00
|
|
|
return IGUIElement::OnEvent(event);
|
2007-08-29 16:37:24 -07:00
|
|
|
}
|
|
|
|
case EGET_ELEMENT_CLOSED:
|
|
|
|
// do not interfere with children being removed
|
|
|
|
return IGUIElement::OnEvent(event);
|
2007-09-14 17:55:30 -07:00
|
|
|
default:
|
|
|
|
break;
|
2007-07-07 00:03:54 -07:00
|
|
|
}
|
2007-09-25 14:54:45 -07:00
|
|
|
break;
|
2007-05-20 11:03:49 -07:00
|
|
|
case EET_MOUSE_INPUT_EVENT:
|
2007-09-14 17:55:30 -07:00
|
|
|
if (event.MouseInput.Event == EMIE_LMOUSE_PRESSED_DOWN)
|
2007-05-20 11:03:49 -07:00
|
|
|
{
|
|
|
|
MouseDownTime = os::Timer::getTime();
|
2007-09-14 17:55:30 -07:00
|
|
|
}
|
|
|
|
default:
|
|
|
|
break;
|
2007-05-20 11:03:49 -07:00
|
|
|
}
|
2009-01-22 04:40:06 -08:00
|
|
|
|
2007-07-07 00:03:54 -07:00
|
|
|
IGUIElement::OnEvent(event);
|
2007-05-20 11:03:49 -07:00
|
|
|
|
2007-08-29 16:37:24 -07:00
|
|
|
return true; // absorb everything else
|
2007-05-20 11:03:49 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
//! draws the element and its children
|
|
|
|
void CGUIModalScreen::draw()
|
|
|
|
{
|
2007-07-07 00:03:54 -07:00
|
|
|
IGUISkin *skin = Environment->getSkin();
|
|
|
|
|
|
|
|
if (!skin)
|
|
|
|
return;
|
|
|
|
|
2007-05-20 11:03:49 -07:00
|
|
|
u32 now = os::Timer::getTime();
|
|
|
|
if (now - MouseDownTime < 300 && (now / 70)%2)
|
|
|
|
{
|
|
|
|
core::list<IGUIElement*>::Iterator it = Children.begin();
|
|
|
|
core::rect<s32> r;
|
|
|
|
video::SColor c = Environment->getSkin()->getColor(gui::EGDC_3D_HIGH_LIGHT);
|
|
|
|
|
|
|
|
for (; it != Children.end(); ++it)
|
|
|
|
{
|
2008-01-11 07:56:37 -08:00
|
|
|
if ((*it)->isVisible())
|
|
|
|
{
|
|
|
|
r = (*it)->getAbsolutePosition();
|
|
|
|
r.LowerRightCorner.X += 1;
|
|
|
|
r.LowerRightCorner.Y += 1;
|
|
|
|
r.UpperLeftCorner.X -= 1;
|
|
|
|
r.UpperLeftCorner.Y -= 1;
|
2007-05-20 11:03:49 -07:00
|
|
|
|
2008-01-11 07:56:37 -08:00
|
|
|
skin->draw2DRectangle(this, c, r, &AbsoluteClippingRect);
|
|
|
|
}
|
2007-05-20 11:03:49 -07:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
IGUIElement::draw();
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
//! Removes a child.
|
|
|
|
void CGUIModalScreen::removeChild(IGUIElement* child)
|
|
|
|
{
|
|
|
|
IGUIElement::removeChild(child);
|
|
|
|
|
|
|
|
if (Children.empty())
|
|
|
|
remove();
|
|
|
|
}
|
|
|
|
|
2009-01-22 04:40:06 -08:00
|
|
|
|
2007-07-07 00:03:54 -07:00
|
|
|
//! adds a child
|
|
|
|
void CGUIModalScreen::addChild(IGUIElement* child)
|
|
|
|
{
|
|
|
|
IGUIElement::addChild(child);
|
|
|
|
Environment->setFocus(child);
|
|
|
|
}
|
|
|
|
|
2007-05-20 11:03:49 -07:00
|
|
|
|
|
|
|
void CGUIModalScreen::updateAbsolutePosition()
|
|
|
|
{
|
|
|
|
core::rect<s32> parentRect(0,0,0,0);
|
|
|
|
|
|
|
|
if (Parent)
|
|
|
|
{
|
|
|
|
parentRect = Parent->getAbsolutePosition();
|
|
|
|
RelativeRect.UpperLeftCorner.X = 0;
|
|
|
|
RelativeRect.UpperLeftCorner.Y = 0;
|
|
|
|
RelativeRect.LowerRightCorner.X = parentRect.getWidth();
|
|
|
|
RelativeRect.LowerRightCorner.Y = parentRect.getHeight();
|
|
|
|
}
|
|
|
|
|
|
|
|
IGUIElement::updateAbsolutePosition();
|
|
|
|
}
|
|
|
|
|
2009-01-22 04:40:06 -08:00
|
|
|
|
2007-05-20 11:03:49 -07:00
|
|
|
//! Writes attributes of the element.
|
2007-09-14 15:25:59 -07:00
|
|
|
void CGUIModalScreen::serializeAttributes(io::IAttributes* out, io::SAttributeReadWriteOptions* options=0) const
|
2007-05-20 11:03:49 -07:00
|
|
|
{
|
|
|
|
// these don't get serialized, their status is added to their children.
|
|
|
|
}
|
|
|
|
|
|
|
|
//! Reads attributes of the element
|
|
|
|
void CGUIModalScreen::deserializeAttributes(io::IAttributes* in, io::SAttributeReadWriteOptions* options=0)
|
|
|
|
{
|
|
|
|
// these don't get deserialized. children create them if required
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
} // end namespace gui
|
|
|
|
} // end namespace irr
|
|
|
|
|
2007-07-25 22:30:19 -07:00
|
|
|
#endif // _IRR_COMPILE_WITH_GUI_
|
2009-01-22 04:40:06 -08:00
|
|
|
|