From 3e0fa4489a58769ad1df954a9ca03e21749ef183 Mon Sep 17 00:00:00 2001 From: reuk Date: Tue, 15 Mar 2022 14:48:09 +0000 Subject: [PATCH] LinuxComponentPeer: Properly transform coordinates into peer space when collision testing --- .../native/juce_linux_Windowing.cpp | 24 +++++++++++++++---- 1 file changed, 20 insertions(+), 4 deletions(-) diff --git a/modules/juce_gui_basics/native/juce_linux_Windowing.cpp b/modules/juce_gui_basics/native/juce_linux_Windowing.cpp index 9d3328ad1d..defc3dcd7d 100644 --- a/modules/juce_gui_basics/native/juce_linux_Windowing.cpp +++ b/modules/juce_gui_basics/native/juce_linux_Windowing.cpp @@ -147,12 +147,12 @@ public: Point localToGlobal (Point relativePosition) override { - return relativePosition + getScreenPosition (false).toFloat(); + return localToGlobal (*this, relativePosition); } Point globalToLocal (Point screenPosition) override { - return screenPosition - getScreenPosition (false).toFloat(); + return globalToLocal (*this, screenPosition); } using ComponentPeer::localToGlobal; @@ -231,8 +231,11 @@ public: if (! c->isVisible()) continue; - if (auto* peer = c->getPeer()) - if (peer->contains (localPos + bounds.getPosition() - peer->getBounds().getPosition(), true)) + auto* otherPeer = c->getPeer(); + jassert (otherPeer == nullptr || dynamic_cast (c->getPeer()) != nullptr); + + if (auto* peer = static_cast (otherPeer)) + if (peer->contains (globalToLocal (*peer, localToGlobal (*this, localPos.toFloat())).roundToInt(), true)) return false; } @@ -474,6 +477,19 @@ private: JUCE_DECLARE_NON_COPYABLE (LinuxRepaintManager) }; + //============================================================================== + template + static Point localToGlobal (This& t, Point relativePosition) + { + return relativePosition + t.getScreenPosition (false).toFloat(); + } + + template + static Point globalToLocal (This& t, Point screenPosition) + { + return screenPosition - t.getScreenPosition (false).toFloat(); + } + //============================================================================== void settingChanged (const XWindowSystemUtilities::XSetting& settingThatHasChanged) override {