diff --git a/modules/juce_gui_basics/components/juce_Component.cpp b/modules/juce_gui_basics/components/juce_Component.cpp index 75b66756b7..c2bfdb75ba 100644 --- a/modules/juce_gui_basics/components/juce_Component.cpp +++ b/modules/juce_gui_basics/components/juce_Component.cpp @@ -1378,14 +1378,19 @@ void Component::getInterceptsMouseClicks (bool& allowsClicksOnThisComponent, bool Component::contains (Point point) { - if (ComponentHelpers::hitTest (*this, point)) + return containsInternal (point.toFloat()); +} + +bool Component::containsInternal (Point point) +{ + if (ComponentHelpers::hitTest (*this, point.roundToInt())) { if (parentComponent != nullptr) - return parentComponent->contains (ComponentHelpers::convertToParentSpace (*this, point)); + return parentComponent->containsInternal (ComponentHelpers::convertToParentSpace (*this, point)); if (flags.hasHeavyweightPeerFlag) if (auto* peer = getPeer()) - return peer->contains (ComponentHelpers::localPositionToRawPeerPos (*this, point), true); + return peer->contains (ComponentHelpers::localPositionToRawPeerPos (*this, point).roundToInt(), true); } return false; @@ -1393,24 +1398,34 @@ bool Component::contains (Point point) bool Component::reallyContains (Point point, bool returnTrueIfWithinAChild) { - if (! contains (point)) + return reallyContainsInternal (point.toFloat(), returnTrueIfWithinAChild); +} + +bool Component::reallyContainsInternal (Point point, bool returnTrueIfWithinAChild) +{ + if (! containsInternal (point)) return false; auto* top = getTopLevelComponent(); - auto* compAtPosition = top->getComponentAt (top->getLocalPoint (this, point)); + auto* compAtPosition = top->getComponentAtInternal (top->getLocalPoint (this, point)); return (compAtPosition == this) || (returnTrueIfWithinAChild && isParentOf (compAtPosition)); } Component* Component::getComponentAt (Point position) { - if (flags.visibleFlag && ComponentHelpers::hitTest (*this, position)) + return getComponentAtInternal (position.toFloat()); +} + +Component* Component::getComponentAtInternal (Point position) +{ + if (flags.visibleFlag && ComponentHelpers::hitTest (*this, position.roundToInt())) { for (int i = childComponentList.size(); --i >= 0;) { - auto* child = childComponentList.getUnchecked(i); + auto* child = childComponentList.getUnchecked (i); - child = child->getComponentAt (ComponentHelpers::convertFromParentSpace (*child, position)); + child = child->getComponentAtInternal (ComponentHelpers::convertFromParentSpace (*child, position)); if (child != nullptr) return child; @@ -3019,7 +3034,7 @@ bool Component::isMouseOver (bool includeChildren) const if (c != nullptr && (c == this || (includeChildren && isParentOf (c)))) if (ms.isDragging() || ! (ms.isTouch() || ms.isPen())) - if (c->reallyContains (c->getLocalPoint (nullptr, ms.getScreenPosition().roundToInt()), false)) + if (c->reallyContainsInternal (c->getLocalPoint (nullptr, ms.getScreenPosition()), false)) return true; } diff --git a/modules/juce_gui_basics/components/juce_Component.h b/modules/juce_gui_basics/components/juce_Component.h index fd1b94e7bb..cc78b6d4d3 100644 --- a/modules/juce_gui_basics/components/juce_Component.h +++ b/modules/juce_gui_basics/components/juce_Component.h @@ -2565,6 +2565,10 @@ private: void sendEnablementChangeMessage(); void sendVisibilityChangeMessage(); + bool containsInternal (Point); + bool reallyContainsInternal (Point, bool); + Component* getComponentAtInternal (Point); + struct ComponentHelpers; friend struct ComponentHelpers; diff --git a/modules/juce_gui_basics/mouse/juce_MouseInputSource.cpp b/modules/juce_gui_basics/mouse/juce_MouseInputSource.cpp index a8c2c283a8..2e6ab4c148 100644 --- a/modules/juce_gui_basics/mouse/juce_MouseInputSource.cpp +++ b/modules/juce_gui_basics/mouse/juce_MouseInputSource.cpp @@ -76,11 +76,10 @@ public: auto relativePos = ScalingHelpers::unscaledScreenPosToScaled (peer->getComponent(), peer->globalToLocal (screenPos)); auto& comp = peer->getComponent(); - auto pos = relativePos.roundToInt(); // (the contains() call is needed to test for overlapping desktop windows) - if (comp.contains (pos)) - return comp.getComponentAt (pos); + if (comp.containsInternal (relativePos)) + return comp.getComponentAtInternal (relativePos); } return nullptr;