diff --git a/modules/juce_gui_basics/native/juce_MultiTouchMapper.h b/modules/juce_gui_basics/native/juce_MultiTouchMapper.h index ed27ec1977..39cb4b0e7d 100644 --- a/modules/juce_gui_basics/native/juce_MultiTouchMapper.h +++ b/modules/juce_gui_basics/native/juce_MultiTouchMapper.h @@ -33,19 +33,17 @@ class MultiTouchMapper public: MultiTouchMapper() {} - int getIndexOfTouch (IDType touchID) + int getIndexOfTouch (ComponentPeer* peer, IDType touchID) { jassert (touchID != 0); // need to rethink this if IDs can be 0! + TouchInfo info {touchID, peer}; - int touchIndex = currentTouches.indexOf (touchID); + int touchIndex = currentTouches.indexOf (info); if (touchIndex < 0) { - for (touchIndex = 0; touchIndex < currentTouches.size(); ++touchIndex) - if (currentTouches.getUnchecked (touchIndex) == 0) - break; - - currentTouches.set (touchIndex, touchID); + touchIndex = jmax (0, currentTouches.indexOf ({})); + currentTouches.set (touchIndex, info); } return touchIndex; @@ -58,20 +56,45 @@ public: void clearTouch (int index) { - currentTouches.set (index, 0); + currentTouches.set (index, {}); } bool areAnyTouchesActive() const noexcept { for (auto& t : currentTouches) - if (t != 0) + if (t.touchId != 0) return true; return false; } + void deleteAllTouchesForPeer (ComponentPeer* peer) + { + for (auto& t : currentTouches) + if (t.owner == peer) + t.touchId = 0; + } + private: - Array currentTouches; + //============================================================================== + struct TouchInfo + { + TouchInfo() noexcept : touchId (0), owner (nullptr) {} + TouchInfo (IDType idToUse, ComponentPeer* peer) noexcept : touchId (idToUse), owner (peer) {} + TouchInfo (const TouchInfo&) noexcept = default; + TouchInfo (TouchInfo&&) noexcept = default; + + TouchInfo& operator= (const TouchInfo&) noexcept = default; + TouchInfo& operator= (TouchInfo&&) noexcept = default; + + IDType touchId; + ComponentPeer* owner; + + bool operator== (const TouchInfo& o) const noexcept { return (touchId == o.touchId); } + }; + + //============================================================================== + Array currentTouches; JUCE_DECLARE_NON_COPYABLE_WITH_LEAK_DETECTOR (MultiTouchMapper) }; diff --git a/modules/juce_gui_basics/native/juce_ios_UIViewComponentPeer.mm b/modules/juce_gui_basics/native/juce_ios_UIViewComponentPeer.mm index d935d3ceee..aabfcf69bc 100644 --- a/modules/juce_gui_basics/native/juce_ios_UIViewComponentPeer.mm +++ b/modules/juce_gui_basics/native/juce_ios_UIViewComponentPeer.mm @@ -610,6 +610,7 @@ UIViewComponentPeer::UIViewComponentPeer (Component& comp, const int windowStyle UIViewComponentPeer::~UIViewComponentPeer() { + currentTouches.deleteAllTouchesForPeer (this); Desktop::getInstance().removeFocusChangeListener (this); view->owner = nullptr; @@ -841,7 +842,7 @@ void UIViewComponentPeer::handleTouches (UIEvent* event, const bool isDown, cons juce_lastMousePos = pos + getBounds (true).getPosition().toFloat(); const int64 time = getMouseTime (event); - const int touchIndex = currentTouches.getIndexOfTouch (touch); + const int touchIndex = currentTouches.getIndexOfTouch (this, touch); ModifierKeys modsToSend (currentModifiers); diff --git a/modules/juce_gui_basics/native/juce_win32_Windowing.cpp b/modules/juce_gui_basics/native/juce_win32_Windowing.cpp index 5f101128e8..966aa6f2ee 100644 --- a/modules/juce_gui_basics/native/juce_win32_Windowing.cpp +++ b/modules/juce_gui_basics/native/juce_win32_Windowing.cpp @@ -964,6 +964,7 @@ public: ~HWNDComponentPeer() { shadower = nullptr; + currentTouches.deleteAllTouchesForPeer (this); // do this before the next bit to avoid messages arriving for this window // before it's destroyed @@ -2359,7 +2360,7 @@ private: { auto isCancel = false; - const auto touchIndex = currentTouches.getIndexOfTouch (touch.dwID); + const auto touchIndex = currentTouches.getIndexOfTouch (this, touch.dwID); const auto time = getMouseEventTime(); const auto pos = globalToLocal ({ touch.x / 100.0f, touch.y / 100.0f }); const auto pressure = touchPressure;