mirror of
https://github.com/juce-framework/JUCE.git
synced 2026-01-10 23:44:24 +00:00
MouseInputSource: Avoid wrong ComponentPeer association
When the mouse moves from one window to another, the mouseExit event for the old window can occur after the mouseMove event for the new. Until this commit this would cause the MouseInputSource to be associated with the old window, and getComponentUnderMouse() would incorrectly return a nullptr.
This commit is contained in:
parent
b1ff2eda65
commit
a115c99da4
1 changed files with 14 additions and 13 deletions
|
|
@ -57,18 +57,18 @@ public:
|
|||
return lastPeer;
|
||||
}
|
||||
|
||||
Component* findComponentAt (Point<float> screenPos)
|
||||
static Component* findComponentAt (Point<float> screenPos, ComponentPeer* peer)
|
||||
{
|
||||
if (auto* peer = getPeer())
|
||||
{
|
||||
auto relativePos = ScalingHelpers::unscaledScreenPosToScaled (peer->getComponent(),
|
||||
peer->globalToLocal (screenPos));
|
||||
auto& comp = peer->getComponent();
|
||||
if (! ComponentPeer::isValidPeer (peer))
|
||||
return nullptr;
|
||||
|
||||
// (the contains() call is needed to test for overlapping desktop windows)
|
||||
if (comp.contains (relativePos))
|
||||
return comp.getComponentAt (relativePos);
|
||||
}
|
||||
auto relativePos = ScalingHelpers::unscaledScreenPosToScaled (peer->getComponent(),
|
||||
peer->globalToLocal (screenPos));
|
||||
auto& comp = peer->getComponent();
|
||||
|
||||
// (the contains() call is needed to test for overlapping desktop windows)
|
||||
if (comp.contains (relativePos))
|
||||
return comp.getComponentAt (relativePos);
|
||||
|
||||
return nullptr;
|
||||
}
|
||||
|
|
@ -244,11 +244,12 @@ public:
|
|||
|
||||
void setPeer (ComponentPeer& newPeer, const PointerState& pointerState, Time time)
|
||||
{
|
||||
if (&newPeer != lastPeer)
|
||||
if (&newPeer != lastPeer && ( findComponentAt (pointerState.position, &newPeer) != nullptr
|
||||
|| findComponentAt (pointerState.position, lastPeer) == nullptr))
|
||||
{
|
||||
setComponentUnderMouse (nullptr, pointerState, time);
|
||||
lastPeer = &newPeer;
|
||||
setComponentUnderMouse (findComponentAt (pointerState.position), pointerState, time);
|
||||
setComponentUnderMouse (findComponentAt (pointerState.position, getPeer()), pointerState, time);
|
||||
}
|
||||
}
|
||||
|
||||
|
|
@ -257,7 +258,7 @@ public:
|
|||
const auto& newScreenPos = newPointerState.position;
|
||||
|
||||
if (! isDragging())
|
||||
setComponentUnderMouse (findComponentAt (newScreenPos), newPointerState, time);
|
||||
setComponentUnderMouse (findComponentAt (newScreenPos, getPeer()), newPointerState, time);
|
||||
|
||||
if ((newPointerState != lastPointerState) || forceUpdate)
|
||||
{
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue