I'm making a Gui where Widgets have children, and children are both clipped in the hit test, and in rendering, to the parent's rectangle. However it is not always like this. A widget can choose not to clip i开发者_如何学Pythonts children. In this case, the children are bound to the parent's parent rectangle. My rendering currently reflects this, but my hit test does not.
Here is my hit test:
AguiWidget* AguiEventManager::GetWidgetUnderMouse( AguiWidget* root,
const AguiMouseEventArgs &mouse )
{
/* sets the current node to the root node
while a widget passes the hit test
and the current node has children,
iterate through the current node's
children and set the current node
to the child who passes the hit test */
AguiWidget* currentNode = root;
bool foundsomething = true;
while(foundsomething)
{
foundsomething = false;
if(currentNode->getChildWidgetCount() > 0)
for (std::vector<AguiWidget*>::const_reverse_iterator rit =
currentNode->getChildRBeginIterator();
rit < currentNode->getChildREndIterator(); ++rit)
{
if (((*rit)->intersectionWithPoint(mouse.getPosition())
)
&& (*rit)->isEnabled() && (*rit)->isVisible())
{
foundsomething = true;
currentNode = *rit;
break;
}
}
}
return currentNode;
}
How could I modify this to deal with (*rit)->isClippingChildren(); ?
Basically at the moment, what it does is, it finds the first widget that passes a hit test, it then digs through its children because only they can then be eligible. And it continues to do this until there are no more children to dig into, and therefore the last widget found is the correct one. This needs to change to something more like this:
If the widget is not clipping its children, then if its parent passed the hit test, we check the children of the one who is not clipping its children. If none of them pass the hit test, then we need to go back and carry on from where we were.
I have a feeling some type of queue could be useful but I'm just not sure how.
The essential result of the modification is that it would be the same outcome as if the same algorithm was used as above, except if a widget is not clipping its children, we just let its children be processed as children of the parent.
Thanks
Give your AguiWidget a hitTest, and let it recurse into its children when positive. Then when clicking on a clipped area, the gitTest of the parent (clipping) widget will fail, and the hit test will never be performed for the clipped Widget.
精彩评论