Is there anyway to get the component under the mouse if it’s a child of a PopupMenu? I’m trying to find my custom component.
Sorry to necro this thread, but did you ever find an answer to this?
I think I solved this a different way, but you can try something like this:
static juce::Component* realGetComponent (juce::Component& p, juce::Point<int> screenPos)
{
if (p.isVisible () && p.getScreenBounds ().contains (screenPos))
{
for (auto i = p.getNumChildComponents (); --i >= 0;)
if (auto c = p.getChildComponent (i))
if ( auto r = realGetComponent (*c, screenPos))
return r;
return &p;
}
return nullptr;
}
static juce::Component* realGetComponentUnderMouse()
{
auto mouse = juce::Desktop::getInstance().getMainMouseSource();
auto pos = mouse.getScreenPosition().toInt ();
auto& desktop = juce::Desktop::getInstance();
for (auto i = desktop.getNumComponents(); --i >= 0;)
if (auto dtc = desktop.getComponent (i))
if (dtc->isVisible())
if (auto c = realGetComponent (*dtc, pos))
return c;
return {};
}
It doesn’t take into hitTest() or interceptsMouse() which you may want to add.
1 Like
Thanks a lot! Will check it out.