Commit 07b28cab authored by cutealien's avatar cutealien

Remove lot's of setFocus and removeFocus calls. Also several places where...

Remove lot's of setFocus and removeFocus calls. Also several places where elements check if they have the focus inside events.
Slightly risky change - but it's hard to improve all this without cleaning it up first. And most elements should _not_ be responsible for their 
own focus but the guienvironment should do that (and does do it).


git-svn-id: svn://svn.code.sf.net/p/irrlicht/code/trunk@4757 dfc29bdd-3216-0410-991c-e03cc46cb475
parent 5b156c1d
......@@ -217,7 +217,7 @@ int main()
creates a window and the third opens a file open dialog. The third
parameter is the id of the button, with which we can easily identify
the button in the event receiver.
*/
*/
env->addButton(rect<s32>(10,240,110,240 + 32), 0, GUI_ID_QUIT_BUTTON,
L"Quit", L"Exits Program");
......@@ -262,7 +262,7 @@ int main()
/*
And at last, we create a nice Irrlicht Engine logo in the top left corner.
And at last, we create a nice Irrlicht Engine logo in the top left corner.
*/
env->addImage(driver->getTexture("../../media/irrlichtlogo2.png"),
position2d<int>(10,10));
......@@ -278,7 +278,7 @@ int main()
driver->beginScene(true, true, SColor(0,200,200,200));
env->drawAll();
driver->endScene();
}
......
......@@ -179,17 +179,9 @@ bool CGUIButton::OnEvent(const SEvent& event)
case EET_MOUSE_INPUT_EVENT:
if (event.MouseInput.Event == EMIE_LMOUSE_PRESSED_DOWN)
{
if (Environment->hasFocus(this) &&
!AbsoluteClippingRect.isPointInside(core::position2d<s32>(event.MouseInput.X, event.MouseInput.Y)))
{
Environment->removeFocus(this);
return false;
}
if (!IsPushButton)
setPressed(true);
Environment->setFocus(this);
return true;
}
else
......
......@@ -82,7 +82,6 @@ bool CGUICheckBox::OnEvent(const SEvent& event)
{
Pressed = true;
CheckTime = os::Timer::getTime();
Environment->setFocus(this);
return true;
}
else
......
......@@ -363,11 +363,9 @@ bool CGUIColorSelectDialog::OnEvent(const SEvent& event)
DragStart.X = event.MouseInput.X;
DragStart.Y = event.MouseInput.Y;
Dragging = true;
Environment->setFocus(this);
return true;
case EMIE_LMOUSE_LEFT_UP:
Dragging = false;
Environment->removeFocus(this);
return true;
case EMIE_MOUSE_MOVED:
if (Dragging)
......
......@@ -224,7 +224,7 @@ bool CGUIEnvironment::setFocus(IGUIElement* element)
return false;
}
// GUI Environment should not get the focus
// GUI Environment should just reset the focus to 0
if (element == this)
element = 0;
......
......@@ -262,7 +262,6 @@ bool CGUIFileOpenDialog::OnEvent(const SEvent& event)
DragStart.X = event.MouseInput.X;
DragStart.Y = event.MouseInput.Y;
Dragging = true;
Environment->setFocus(this);
return true;
case EMIE_LMOUSE_LEFT_UP:
Dragging = false;
......
......@@ -130,11 +130,6 @@ bool CGUIMenu::OnEvent(const SEvent& event)
{
case EMIE_LMOUSE_PRESSED_DOWN:
{
if (!Environment->hasFocus(this))
{
Environment->setFocus(this);
}
if (Parent)
Parent->bringToFront(this);
......
......@@ -166,7 +166,6 @@ bool CGUIScrollBar::OnEvent(const SEvent& event)
DraggedBySlider = SliderRect.isPointInside(p);
TrayClick = !DraggedBySlider;
DesiredPos = getPosFromMousePos(p);
Environment->setFocus ( this );
return true;
}
break;
......
......@@ -588,21 +588,18 @@ bool CGUITable::OnEvent(const SEvent &event)
case EMIE_LMOUSE_PRESSED_DOWN:
if (Environment->hasFocus(this) &&
VerticalScrollBar->isVisible() &&
if (VerticalScrollBar->isVisible() &&
VerticalScrollBar->getAbsolutePosition().isPointInside(p) &&
VerticalScrollBar->OnEvent(event))
return true;
if (Environment->hasFocus(this) &&
HorizontalScrollBar->isVisible() &&
if (HorizontalScrollBar->isVisible() &&
HorizontalScrollBar->getAbsolutePosition().isPointInside(p) &&
HorizontalScrollBar->OnEvent(event))
return true;
if ( dragColumnStart( event.MouseInput.X, event.MouseInput.Y ) )
{
Environment->setFocus(this);
return true;
}
......@@ -610,28 +607,21 @@ bool CGUITable::OnEvent(const SEvent &event)
return true;
Selecting = true;
Environment->setFocus(this);
return true;
case EMIE_LMOUSE_LEFT_UP:
CurrentResizedColumn = -1;
Selecting = false;
if (!getAbsolutePosition().isPointInside(p))
{
Environment->removeFocus(this);
}
if (Environment->hasFocus(this) &&
VerticalScrollBar->isVisible() &&
if (VerticalScrollBar->isVisible() &&
VerticalScrollBar->getAbsolutePosition().isPointInside(p) &&
VerticalScrollBar->OnEvent(event))
{
return true;
}
if (Environment->hasFocus(this) &&
HorizontalScrollBar->isVisible() &&
if (HorizontalScrollBar->isVisible() &&
HorizontalScrollBar->getAbsolutePosition().isPointInside(p) &&
HorizontalScrollBar->OnEvent(event))
{
......
......@@ -631,38 +631,26 @@ bool CGUITreeView::OnEvent( const SEvent &event )
case EMIE_LMOUSE_PRESSED_DOWN:
if (Environment->hasFocus(this) && !AbsoluteClippingRect.isPointInside(p) )
{
Environment->removeFocus(this);
return false;
}
if( Environment->hasFocus( this ) &&
( ( ScrollBarV && ScrollBarV->getAbsolutePosition().isPointInside( p ) && ScrollBarV->OnEvent( event ) ) ||
if( ( ScrollBarV && ScrollBarV->getAbsolutePosition().isPointInside( p ) && ScrollBarV->OnEvent( event ) ) ||
( ScrollBarH && ScrollBarH->getAbsolutePosition().isPointInside( p ) && ScrollBarH->OnEvent( event ) )
)
)
{
return true;
}
Selecting = true;
Environment->setFocus( this );
return true;
break;
case EMIE_LMOUSE_LEFT_UP:
if( Environment->hasFocus( this ) &&
( ( ScrollBarV && ScrollBarV->getAbsolutePosition().isPointInside( p ) && ScrollBarV->OnEvent( event ) ) ||
if( ( ScrollBarV && ScrollBarV->getAbsolutePosition().isPointInside( p ) && ScrollBarV->OnEvent( event ) ) ||
( ScrollBarH && ScrollBarH->getAbsolutePosition().isPointInside( p ) && ScrollBarH->OnEvent( event ) )
)
)
{
return true;
}
Selecting = false;
Environment->removeFocus( this );
mouseAction( event.MouseInput.X, event.MouseInput.Y );
return true;
break;
......
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