Browse Source

Fixed an issue with stuck touches when a component peer was closed on a mouse down event

tags/2021-05-28
hogliux 8 years ago
parent
commit
2021c64f00
3 changed files with 37 additions and 12 deletions
  1. +33
    -10
      modules/juce_gui_basics/native/juce_MultiTouchMapper.h
  2. +2
    -1
      modules/juce_gui_basics/native/juce_ios_UIViewComponentPeer.mm
  3. +2
    -1
      modules/juce_gui_basics/native/juce_win32_Windowing.cpp

+ 33
- 10
modules/juce_gui_basics/native/juce_MultiTouchMapper.h View File

@@ -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<IDType> 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<TouchInfo> currentTouches;
JUCE_DECLARE_NON_COPYABLE_WITH_LEAK_DETECTOR (MultiTouchMapper)
};


+ 2
- 1
modules/juce_gui_basics/native/juce_ios_UIViewComponentPeer.mm View File

@@ -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);


+ 2
- 1
modules/juce_gui_basics/native/juce_win32_Windowing.cpp View File

@@ -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;


Loading…
Cancel
Save