diff --git a/changes.txt b/changes.txt index 4a9c12ec..43666240 100644 --- a/changes.txt +++ b/changes.txt @@ -1,6 +1,7 @@ -------------------------- Changes in 1.9 (not yet released) - + +- IGUIEnvironment::hasFocus has now a parameter checkSubElements as subelements are usually seen as part of an element. Default unfortunately must be false due to backward compatibility. - Add IGUIElement::isTrulyVisible which works like ISceneNode::isTrulyVisible and checks for parent visibility as well. - Improved DDS loader and added support for DXTn (DXT1-5) compressed textures in OpenGL and Direct3D9 drivers. - Add function ISceneNode::getTransformedBoundingBoxEdges. diff --git a/include/IGUIEnvironment.h b/include/IGUIEnvironment.h index 02911072..77937bbc 100644 --- a/include/IGUIEnvironment.h +++ b/include/IGUIEnvironment.h @@ -103,8 +103,9 @@ public: //! Returns whether the element has focus /** \param element Pointer to the element which is tested. + \param checkSubElements When true and focus is on a sub-element of element then it will still count as focused and return true \return True if the element has focus, else false. */ - virtual bool hasFocus(IGUIElement* element) const = 0; + virtual bool hasFocus(IGUIElement* element, bool checkSubElements=false) const = 0; //! Returns the current video driver. /** \return Pointer to the video driver. */ diff --git a/source/Irrlicht/CGUIButton.cpp b/source/Irrlicht/CGUIButton.cpp index 5a451cdb..f01e8692 100644 --- a/source/Irrlicht/CGUIButton.cpp +++ b/source/Irrlicht/CGUIButton.cpp @@ -175,8 +175,8 @@ bool CGUIButton::OnEvent(const SEvent& event) if (Environment->hasFocus(this) && !AbsoluteClippingRect.isPointInside(core::position2d(event.MouseInput.X, event.MouseInput.Y))) { - Environment->removeFocus(this); - return false; + Environment->removeFocus(this); + return false; } if (!IsPushButton) diff --git a/source/Irrlicht/CGUIEnvironment.cpp b/source/Irrlicht/CGUIEnvironment.cpp index bf3fa866..ee39afbc 100644 --- a/source/Irrlicht/CGUIEnvironment.cpp +++ b/source/Irrlicht/CGUIEnvironment.cpp @@ -329,11 +329,24 @@ bool CGUIEnvironment::removeFocus(IGUIElement* element) } -//! Returns if the element has focus -bool CGUIEnvironment::hasFocus(IGUIElement* element) const +//! Returns whether the element has focus +bool CGUIEnvironment::hasFocus(IGUIElement* element, bool checkSubElements) const { _IRR_IMPLEMENT_MANAGED_MARSHALLING_BUGFIX; - return (element == Focus); + if (element == Focus) + return true; + + if ( !checkSubElements || !element ) + return false; + + IGUIElement* f = Focus; + while ( f && f->isSubElement() ) + { + f = f->getParent(); + if ( f == element ) + return true; + } + return false; } diff --git a/source/Irrlicht/CGUIEnvironment.h b/source/Irrlicht/CGUIEnvironment.h index 6b3be3b9..77d64ab5 100644 --- a/source/Irrlicht/CGUIEnvironment.h +++ b/source/Irrlicht/CGUIEnvironment.h @@ -187,7 +187,7 @@ public: virtual bool removeFocus(IGUIElement* element); //! Returns if the element has focus - virtual bool hasFocus(IGUIElement* element) const; + virtual bool hasFocus(IGUIElement* element, bool checkSubElements=false) const; //! Returns the element with the focus virtual IGUIElement* getFocus() const;