mirror of
https://github.com/juce-framework/JUCE.git
synced 2026-01-10 23:44:24 +00:00
Component: Ensure getScreenPosition result is in terms of the logical coordinate space of the screen
Previously, getScreenPosition would return a result in the component's coordinate space if it was called on a component that was not directly or indirectly on the desktop. This behaviour is surprising and difficult to program around. This change should ensure that the result is always in the screen's coordinate space.
This commit is contained in:
parent
73523cd6a5
commit
1c2abc80d7
1 changed files with 27 additions and 26 deletions
|
|
@ -329,47 +329,48 @@ struct Component::ComponentHelpers
|
|||
}
|
||||
|
||||
template <typename PointOrRect>
|
||||
static PointOrRect convertFromParentSpace (const Component& comp, PointOrRect pointInParentSpace)
|
||||
static PointOrRect convertFromParentSpace (const Component& comp, const PointOrRect pointInParentSpace)
|
||||
{
|
||||
if (comp.affineTransform != nullptr)
|
||||
pointInParentSpace = pointInParentSpace.transformedBy (comp.affineTransform->inverted());
|
||||
const auto transformed = comp.affineTransform != nullptr ? pointInParentSpace.transformedBy (comp.affineTransform->inverted())
|
||||
: pointInParentSpace;
|
||||
|
||||
if (comp.isOnDesktop())
|
||||
{
|
||||
if (auto* peer = comp.getPeer())
|
||||
pointInParentSpace = ScalingHelpers::unscaledScreenPosToScaled
|
||||
(comp, peer->globalToLocal (ScalingHelpers::scaledScreenPosToUnscaled (pointInParentSpace)));
|
||||
else
|
||||
jassertfalse;
|
||||
}
|
||||
else
|
||||
{
|
||||
pointInParentSpace = ScalingHelpers::subtractPosition (pointInParentSpace, comp);
|
||||
return ScalingHelpers::unscaledScreenPosToScaled (comp, peer->globalToLocal (ScalingHelpers::scaledScreenPosToUnscaled (transformed)));
|
||||
|
||||
jassertfalse;
|
||||
return transformed;
|
||||
}
|
||||
|
||||
return pointInParentSpace;
|
||||
if (comp.getParentComponent() == nullptr)
|
||||
return ScalingHelpers::subtractPosition (ScalingHelpers::unscaledScreenPosToScaled (comp, ScalingHelpers::scaledScreenPosToUnscaled (transformed)), comp);
|
||||
|
||||
return ScalingHelpers::subtractPosition (transformed, comp);
|
||||
}
|
||||
|
||||
template <typename PointOrRect>
|
||||
static PointOrRect convertToParentSpace (const Component& comp, PointOrRect pointInLocalSpace)
|
||||
static PointOrRect convertToParentSpace (const Component& comp, const PointOrRect pointInLocalSpace)
|
||||
{
|
||||
if (comp.isOnDesktop())
|
||||
const auto preTransform = [&]
|
||||
{
|
||||
if (auto* peer = comp.getPeer())
|
||||
pointInLocalSpace = ScalingHelpers::unscaledScreenPosToScaled
|
||||
(peer->localToGlobal (ScalingHelpers::scaledScreenPosToUnscaled (comp, pointInLocalSpace)));
|
||||
else
|
||||
if (comp.isOnDesktop())
|
||||
{
|
||||
if (auto* peer = comp.getPeer())
|
||||
return ScalingHelpers::unscaledScreenPosToScaled (peer->localToGlobal (ScalingHelpers::scaledScreenPosToUnscaled (comp, pointInLocalSpace)));
|
||||
|
||||
jassertfalse;
|
||||
}
|
||||
else
|
||||
{
|
||||
pointInLocalSpace = ScalingHelpers::addPosition (pointInLocalSpace, comp);
|
||||
}
|
||||
return pointInLocalSpace;
|
||||
}
|
||||
|
||||
if (comp.affineTransform != nullptr)
|
||||
pointInLocalSpace = pointInLocalSpace.transformedBy (*comp.affineTransform);
|
||||
if (comp.getParentComponent() == nullptr)
|
||||
return ScalingHelpers::unscaledScreenPosToScaled (ScalingHelpers::scaledScreenPosToUnscaled (comp, ScalingHelpers::addPosition (pointInLocalSpace, comp)));
|
||||
|
||||
return pointInLocalSpace;
|
||||
return ScalingHelpers::addPosition (pointInLocalSpace, comp);
|
||||
}();
|
||||
|
||||
return comp.affineTransform != nullptr ? preTransform.transformedBy (*comp.affineTransform)
|
||||
: preTransform;
|
||||
}
|
||||
|
||||
template <typename PointOrRect>
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue