Skip to content

Commit

Permalink
Fixed an iOS multitouch bug and added MouseInputSource::offscreenMous…
Browse files Browse the repository at this point in the history
…ePos to replace some magic numbers
  • Loading branch information
ed95 committed Mar 26, 2019
1 parent b271166 commit b1c4d98
Show file tree
Hide file tree
Showing 6 changed files with 17 additions and 17 deletions.
Expand Up @@ -88,7 +88,7 @@ class FakeMouseMoveGenerator : private Timer
{
if (auto* peer = safeOldComponent->getPeer())
{
peer->handleMouseEvent (MouseInputSource::InputSourceType::mouse, { -1.0f, -1.0f }, mods,
peer->handleMouseEvent (MouseInputSource::InputSourceType::mouse, MouseInputSource::offscreenMousePos, mods,
MouseInputSource::invalidPressure, MouseInputSource::invalidOrientation, Time::currentTimeMillis());
}
}
Expand Down
9 changes: 7 additions & 2 deletions modules/juce_gui_basics/mouse/juce_MouseInputSource.cpp
Expand Up @@ -96,7 +96,8 @@ class MouseInputSourceInternal : private AsyncUpdater

Point<float> getRawScreenPosition() const noexcept
{
return unboundedMouseOffset + MouseInputSource::getCurrentRawMousePosition();
return unboundedMouseOffset + (inputType != MouseInputSource::InputSourceType::touch ? MouseInputSource::getCurrentRawMousePosition()
: lastScreenPos);
}

void setScreenPosition (Point<float> p)
Expand Down Expand Up @@ -271,7 +272,9 @@ class MouseInputSourceInternal : private AsyncUpdater
if (newScreenPos != lastScreenPos || forceUpdate)
{
cancelPendingUpdate();
lastScreenPos = newScreenPos;

if (newScreenPos != MouseInputSource::offscreenMousePos)
lastScreenPos = newScreenPos;

if (auto* current = getComponentUnderMouse())
{
Expand Down Expand Up @@ -648,6 +651,8 @@ const float MouseInputSource::invalidRotation = 0.0f;
const float MouseInputSource::invalidTiltX = 0.0f;
const float MouseInputSource::invalidTiltY = 0.0f;

const Point<float> MouseInputSource::offscreenMousePos { -10.0f, -10.0f };

// Deprecated method
bool MouseInputSource::hasMouseMovedSignificantlySincePressed() const noexcept { return pimpl->hasMouseMovedSignificantlySincePressed(); }

Expand Down
5 changes: 5 additions & 0 deletions modules/juce_gui_basics/mouse/juce_MouseInputSource.h
Expand Up @@ -237,6 +237,11 @@ class JUCE_API MouseInputSource final
static const float invalidTiltX;
static const float invalidTiltY;

/** An offscreen mouse position used when triggering mouse exits where we don't want to move
the cursor over an existing component.
*/
static const Point<float> offscreenMousePos;

#if ! DOXYGEN
// This method has been deprecated and replaced with the isLongPressOrDrag() and hasMovedSignificantlySincePressed()
// methods. If you want the same behaviour you should use isLongPressOrDrag() which accounts for the amount of time
Expand Down
Expand Up @@ -900,7 +900,7 @@ static float getTouchForce (UITouch* touch) noexcept

if (isUp || isCancel)
{
handleMouseEvent (MouseInputSource::InputSourceType::touch, Point<float> (-1.0f, -1.0f), modsToSend,
handleMouseEvent (MouseInputSource::InputSourceType::touch, MouseInputSource::offscreenMousePos, modsToSend,
MouseInputSource::invalidPressure, MouseInputSource::invalidOrientation, time, {}, touchIndex);

if (! isValidPeer (this))
Expand Down
Expand Up @@ -632,7 +632,7 @@ void redirectMouseMove (NSEvent* ev)
sendMouseEvent (ev);
else
// moved into another window which overlaps this one, so trigger an exit
handleMouseEvent (MouseInputSource::InputSourceType::mouse, { -1.0f, -1.0f }, ModifierKeys::currentModifiers,
handleMouseEvent (MouseInputSource::InputSourceType::mouse, MouseInputSource::offscreenMousePos, ModifierKeys::currentModifiers,
getMousePressure (ev), MouseInputSource::invalidOrientation, getMouseTime (ev));

showArrowCursorIfNeeded();
Expand Down
14 changes: 2 additions & 12 deletions modules/juce_gui_basics/native/juce_win32_Windowing.cpp
Expand Up @@ -621,9 +621,6 @@ int64 getMouseEventTime()
return eventTimeOffset + thisMessageTime;
}

Point<float> juce_lastTouchPos;
static JUCE_CONSTEXPR Point<float> juce_invalidTouchPos { -10.0f, -10.0f };

//==============================================================================
const int extendedKeyModifier = 0x10000;

Expand Down Expand Up @@ -2442,8 +2439,6 @@ class HWNDComponentPeer : public ComponentPeer,
//==============================================================================
void doMouseEvent (Point<float> position, float pressure, float orientation = 0.0f, ModifierKeys mods = ModifierKeys::currentModifiers)
{
juce_lastTouchPos = juce_invalidTouchPos;

handleMouseEvent (MouseInputSource::InputSourceType::mouse, position, mods, pressure, orientation, getMouseEventTime());
}

Expand Down Expand Up @@ -2772,8 +2767,6 @@ class HWNDComponentPeer : public ComponentPeer,
const auto pressure = touchPressure;
auto modsToSend = ModifierKeys::currentModifiers;

juce_lastTouchPos = pos;

if (isDown)
{
ModifierKeys::currentModifiers = ModifierKeys::currentModifiers.withoutMouseButtons().withFlags (ModifierKeys::leftButtonModifier);
Expand Down Expand Up @@ -2808,7 +2801,7 @@ class HWNDComponentPeer : public ComponentPeer,

if (isUp)
{
handleMouseEvent (MouseInputSource::InputSourceType::touch, juce_invalidTouchPos, ModifierKeys::currentModifiers.withoutMouseButtons(),
handleMouseEvent (MouseInputSource::InputSourceType::touch, MouseInputSource::offscreenMousePos, ModifierKeys::currentModifiers.withoutMouseButtons(),
pressure, orientation, time, {}, touchIndex);

if (! isValidPeer (this))
Expand Down Expand Up @@ -2921,7 +2914,7 @@ class HWNDComponentPeer : public ComponentPeer,

if (isUp)
{
handleMouseEvent (MouseInputSource::InputSourceType::pen, juce_invalidTouchPos, ModifierKeys::currentModifiers,
handleMouseEvent (MouseInputSource::InputSourceType::pen, MouseInputSource::offscreenMousePos, ModifierKeys::currentModifiers,
pressure, MouseInputSource::invalidOrientation, time, penDetails);

if (! isValidPeer (this))
Expand Down Expand Up @@ -4288,9 +4281,6 @@ bool MouseInputSource::SourceList::canUseTouch()

Point<float> MouseInputSource::getCurrentRawMousePosition()
{
if (juce_lastTouchPos != juce_invalidTouchPos)
return juce_lastTouchPos;

POINT mousePos;
GetCursorPos (&mousePos);

Expand Down

0 comments on commit b1c4d98

Please sign in to comment.