Browse Source

Fix for broken screen coord conversion in plugin windows.

tags/2021-05-28
jules 12 years ago
parent
commit
fc21a145cf
4 changed files with 41 additions and 14 deletions
  1. +3
    -5
      modules/juce_core/text/juce_String.cpp
  2. +30
    -6
      modules/juce_gui_basics/components/juce_Component.cpp
  3. +7
    -2
      modules/juce_gui_basics/mouse/juce_MouseInputSource.cpp
  4. +1
    -1
      modules/juce_gui_basics/native/juce_mac_NSViewComponentPeer.mm

+ 3
- 5
modules/juce_core/text/juce_String.cpp View File

@@ -364,7 +364,7 @@ String String::charToString (const juce_wchar character)
namespace NumberToStringConverters namespace NumberToStringConverters
{ {
template <typename Type> template <typename Type>
static inline char* printDigits (char* t, Type v) noexcept
static char* printDigits (char* t, Type v) noexcept
{ {
*--t = 0; *--t = 0;
@@ -507,10 +507,9 @@ juce_wchar String::operator[] (int index) const noexcept
int String::hashCode() const noexcept int String::hashCode() const noexcept
{ {
CharPointerType t (text);
int result = 0; int result = 0;
while (! t.isEmpty())
for (CharPointerType t (text); ! t.isEmpty();)
result = 31 * result + (int) t.getAndAdvance(); result = 31 * result + (int) t.getAndAdvance();
return result; return result;
@@ -518,10 +517,9 @@ int String::hashCode() const noexcept
int64 String::hashCode64() const noexcept int64 String::hashCode64() const noexcept
{ {
CharPointerType t (text);
int64 result = 0; int64 result = 0;
while (! t.isEmpty())
for (CharPointerType t (text); ! t.isEmpty();)
result = 101 * result + t.getAndAdvance(); result = 101 * result + t.getAndAdvance();
return result; return result;


+ 30
- 6
modules/juce_gui_basics/components/juce_Component.cpp View File

@@ -237,19 +237,43 @@ struct Component::ComponentHelpers
template <typename PointOrRect> template <typename PointOrRect>
static PointOrRect convertFromParentSpace (const Component& comp, PointOrRect pointInParentSpace) 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 <typename PointOrRect> template <typename PointOrRect>
static PointOrRect convertToParentSpace (const Component& comp, PointOrRect pointInLocalSpace) 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 <typename PointOrRect> template <typename PointOrRect>


+ 7
- 2
modules/juce_gui_basics/mouse/juce_MouseInputSource.cpp View File

@@ -59,6 +59,12 @@ public:
static Point<int> screenPosToLocalPos (Component& comp, Point<int> pos) static Point<int> screenPosToLocalPos (Component& comp, Point<int> 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)); return comp.getLocalPoint (nullptr, Component::ComponentHelpers::unscaledScreenPosToScaled (pos));
} }
@@ -66,9 +72,8 @@ public:
{ {
if (ComponentPeer* const peer = getPeer()) if (ComponentPeer* const peer = getPeer())
{ {
Point<int> relativePos (Component::ComponentHelpers::unscaledScreenPosToScaled (peer->globalToLocal (screenPos)));
Component& comp = peer->getComponent(); Component& comp = peer->getComponent();
Point<int> relativePos (Component::ComponentHelpers::convertFromParentSpace (comp,
Component::ComponentHelpers::unscaledScreenPosToScaled (screenPos)));
// (the contains() call is needed to test for overlapping desktop windows) // (the contains() call is needed to test for overlapping desktop windows)
if (comp.contains (relativePos)) if (comp.contains (relativePos))


+ 1
- 1
modules/juce_gui_basics/native/juce_mac_NSViewComponentPeer.mm View File

@@ -270,7 +270,7 @@ public:
r.origin.y = [[view superview] frame].size.height - r.origin.y - r.size.height; r.origin.y = [[view superview] frame].size.height - r.origin.y - r.size.height;
} }
return Rectangle<int> (convertToRectInt (r));
return convertToRectInt (r);
} }
Rectangle<int> getBounds() const override Rectangle<int> getBounds() const override


Loading…
Cancel
Save