From fc21a145cf3c47f123af4a96bb00710fa589b83d Mon Sep 17 00:00:00 2001 From: jules Date: Mon, 29 Jul 2013 16:31:03 +0100 Subject: [PATCH] Fix for broken screen coord conversion in plugin windows. --- modules/juce_core/text/juce_String.cpp | 8 ++--- .../components/juce_Component.cpp | 36 +++++++++++++++---- .../mouse/juce_MouseInputSource.cpp | 9 +++-- .../native/juce_mac_NSViewComponentPeer.mm | 2 +- 4 files changed, 41 insertions(+), 14 deletions(-) diff --git a/modules/juce_core/text/juce_String.cpp b/modules/juce_core/text/juce_String.cpp index c146e80e63..56c3926b85 100644 --- a/modules/juce_core/text/juce_String.cpp +++ b/modules/juce_core/text/juce_String.cpp @@ -364,7 +364,7 @@ String String::charToString (const juce_wchar character) namespace NumberToStringConverters { template - static inline char* printDigits (char* t, Type v) noexcept + static char* printDigits (char* t, Type v) noexcept { *--t = 0; @@ -507,10 +507,9 @@ juce_wchar String::operator[] (int index) const noexcept int String::hashCode() const noexcept { - CharPointerType t (text); int result = 0; - while (! t.isEmpty()) + for (CharPointerType t (text); ! t.isEmpty();) result = 31 * result + (int) t.getAndAdvance(); return result; @@ -518,10 +517,9 @@ int String::hashCode() const noexcept int64 String::hashCode64() const noexcept { - CharPointerType t (text); int64 result = 0; - while (! t.isEmpty()) + for (CharPointerType t (text); ! t.isEmpty();) result = 101 * result + t.getAndAdvance(); return result; diff --git a/modules/juce_gui_basics/components/juce_Component.cpp b/modules/juce_gui_basics/components/juce_Component.cpp index 398e60354f..50cd4a8add 100644 --- a/modules/juce_gui_basics/components/juce_Component.cpp +++ b/modules/juce_gui_basics/components/juce_Component.cpp @@ -237,19 +237,43 @@ struct Component::ComponentHelpers template static PointOrRect convertFromParentSpace (const Component& comp, PointOrRect pointInParentSpace) { - if (comp.affineTransform == nullptr) - return pointInParentSpace - comp.getPosition(); + if (comp.affineTransform != nullptr) + pointInParentSpace = pointInParentSpace.transformedBy (comp.affineTransform->inverted()); - return pointInParentSpace.transformedBy (comp.affineTransform->inverted()) - comp.getPosition(); + if (comp.isOnDesktop()) + { + if (ComponentPeer* peer = comp.getPeer()) + pointInParentSpace = unscaledScreenPosToScaled (peer->globalToLocal (scaledScreenPosToUnscaled (pointInParentSpace))); + else + jassertfalse; + } + else + { + pointInParentSpace -= comp.getPosition(); + } + + return pointInParentSpace; } template static PointOrRect convertToParentSpace (const Component& comp, PointOrRect pointInLocalSpace) { - if (comp.affineTransform == nullptr) - return pointInLocalSpace + comp.getPosition(); + if (comp.isOnDesktop()) + { + if (ComponentPeer* peer = comp.getPeer()) + pointInLocalSpace = unscaledScreenPosToScaled (peer->localToGlobal (scaledScreenPosToUnscaled (pointInLocalSpace))); + else + jassertfalse; + } + else + { + pointInLocalSpace += comp.getPosition(); + } + + if (comp.affineTransform != nullptr) + pointInLocalSpace = pointInLocalSpace.transformedBy (*comp.affineTransform); - return (pointInLocalSpace + comp.getPosition()).transformedBy (*comp.affineTransform); + return pointInLocalSpace; } template diff --git a/modules/juce_gui_basics/mouse/juce_MouseInputSource.cpp b/modules/juce_gui_basics/mouse/juce_MouseInputSource.cpp index 79ae338af6..5725c382ce 100644 --- a/modules/juce_gui_basics/mouse/juce_MouseInputSource.cpp +++ b/modules/juce_gui_basics/mouse/juce_MouseInputSource.cpp @@ -59,6 +59,12 @@ public: static Point screenPosToLocalPos (Component& comp, Point pos) { + if (ComponentPeer* const peer = comp.getPeer()) + { + pos = peer->globalToLocal (pos); + return comp.getLocalPoint (&peer->getComponent(), Component::ComponentHelpers::unscaledScreenPosToScaled (pos)); + } + return comp.getLocalPoint (nullptr, Component::ComponentHelpers::unscaledScreenPosToScaled (pos)); } @@ -66,9 +72,8 @@ public: { if (ComponentPeer* const peer = getPeer()) { + Point relativePos (Component::ComponentHelpers::unscaledScreenPosToScaled (peer->globalToLocal (screenPos))); Component& comp = peer->getComponent(); - Point relativePos (Component::ComponentHelpers::convertFromParentSpace (comp, - Component::ComponentHelpers::unscaledScreenPosToScaled (screenPos))); // (the contains() call is needed to test for overlapping desktop windows) if (comp.contains (relativePos)) diff --git a/modules/juce_gui_basics/native/juce_mac_NSViewComponentPeer.mm b/modules/juce_gui_basics/native/juce_mac_NSViewComponentPeer.mm index db6a72227a..4b0ea731b0 100644 --- a/modules/juce_gui_basics/native/juce_mac_NSViewComponentPeer.mm +++ b/modules/juce_gui_basics/native/juce_mac_NSViewComponentPeer.mm @@ -270,7 +270,7 @@ public: r.origin.y = [[view superview] frame].size.height - r.origin.y - r.size.height; } - return Rectangle (convertToRectInt (r)); + return convertToRectInt (r); } Rectangle getBounds() const override