Skip to content

Commit

Permalink
FIX: Handling of TouchGroups colliding/merging
Browse files Browse the repository at this point in the history
  • Loading branch information
arthurnishimoto committed Mar 28, 2019
1 parent 658fce9 commit d56b53d
Show file tree
Hide file tree
Showing 2 changed files with 28 additions and 8 deletions.
1 change: 1 addition & 0 deletions include/omicron/TouchGestureManager.h
Original file line number Diff line number Diff line change
Expand Up @@ -157,6 +157,7 @@ namespace omicron {
void poll();

bool addTouch(Event::Type eventType, Touch touch);
TouchGroup* getTouchGroup(int ID);
void setNextID( int ID );

void generatePQServiceEvent(Event::Type eventType, TouchGroup* touchGroup, int advancedGesture);
Expand Down
35 changes: 27 additions & 8 deletions src/omicron/omicron/TouchGestureManager.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -130,21 +130,21 @@ void TouchGroup::addTouch( Event::Type eventType, float x, float y, int touchID,
int curTime = tb.millitm + (tb.time & 0xfffff) * 1000;

// Touch not in list but inside touch (likely from other touchgroup)
// Lower ID touch group takes priority
if (touchList.count(touchID) == 0 && eventType != Event::Down)
{

TouchGroup* tg = gestureManager->getTouchGroup(touchID);
if (tg != NULL)
{
tg->removeTouch(touchID);
ofmsg("TouchGroup %1% absorbed touch ID %2%", %ID %touchID);
}
}

if( eventType == Event::Up )
{
removeTouch(touchID);

ofmsg("TouchGroup %1% removed touch ID %2% new size: %3%", %ID %touchID %getTouchCount() );

if (getTouchCount() == 0)
{
setRemove();
}
}
else
{
Expand Down Expand Up @@ -528,6 +528,7 @@ void TouchGroup::removeTouch(int id) {
touchListLock->lock();
touchList.erase(id);

ofmsg("TouchGroup %1% removed touch ID %2%", %ID %id);
if (id == mainID)
{
// Main ID (controlling group) has been removed
Expand All @@ -537,10 +538,15 @@ void TouchGroup::removeTouch(int id) {
{
Touch t = (*it).second;
mainID = t.ID;
break;
ofmsg(" Remaining IDs: %1%", %t.ID);
}
}
touchListLock->unlock();
ofmsg(" Remaining IDs count %1%", %getTouchCount());
if (getTouchCount() == 0)
{
setRemove();
}
}

///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
Expand Down Expand Up @@ -642,6 +648,19 @@ bool TouchGestureManager::addTouch(Event::Type eventType, Touch touch)
return true;
}

///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
TouchGroup* TouchGestureManager::getTouchGroup(int ID)
{
if (touchGroupList.count(ID) > 0)
{
return touchGroupList[ID];
}
else
{
return NULL;
}
}

///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
bool TouchGestureManager::addTouchGroup( Event::Type eventType, float xPos, float yPos, int ID, float xWidth, float yWidth )
{
Expand Down

0 comments on commit d56b53d

Please sign in to comment.