From f9e616ebf863c244454dd1cf33332c16589122d0 Mon Sep 17 00:00:00 2001 From: Lennart Eichhorn Date: Mon, 7 Dec 2020 19:02:33 +0100 Subject: [PATCH 1/2] Added support for touch input to the SimpleSimulator --- SimpleSimulator.cpp | 21 ++++++++++++++++++--- 1 file changed, 18 insertions(+), 3 deletions(-) diff --git a/SimpleSimulator.cpp b/SimpleSimulator.cpp index ea07899..dc89ca1 100644 --- a/SimpleSimulator.cpp +++ b/SimpleSimulator.cpp @@ -159,13 +159,28 @@ void SimpleSimulator::processEvents() break; case SDL_MOUSEMOTION: - if (event.button.button == SDL_BUTTON_LEFT) mouseDragged((float)event.button.x/width, (float)event.button.y/height); + if (event.button.button == SDL_BUTTON_LEFT && event.motion.which != SDL_TOUCH_MOUSEID){ + mouseDragged((float)event.button.x/width, (float)event.button.y/height); + } break; case SDL_MOUSEBUTTONDOWN: - if (event.button.button == SDL_BUTTON_LEFT) mousePressed((float)event.button.x/width, (float)event.button.y/height); + if (event.button.button == SDL_BUTTON_LEFT && event.button.which != SDL_TOUCH_MOUSEID){ + mousePressed((float)event.button.x/width, (float)event.button.y/height); + } break; case SDL_MOUSEBUTTONUP: - if (event.button.button == SDL_BUTTON_LEFT) mouseReleased((float)event.button.x/width, (float)event.button.y/height); + if (event.button.button == SDL_BUTTON_LEFT && event.button.which != SDL_TOUCH_MOUSEID){ + mouseReleased((float)event.button.x/width, (float)event.button.y/height); + } + break; + case SDL_FINGERMOTION: + mouseDragged((float)event.tfinger.x, (float)event.tfinger.y); + break; + case SDL_FINGERDOWN: + mousePressed((float)event.tfinger.x, (float)event.tfinger.y); + break; + case SDL_FINGERUP: + mouseReleased((float)event.tfinger.x, (float)event.tfinger.y); break; case SDL_QUIT: running = false; From e91e3d3253c52cdc9441f8c088647a6f295006a3 Mon Sep 17 00:00:00 2001 From: Lennart Eichhorn Date: Mon, 7 Dec 2020 21:12:44 +0100 Subject: [PATCH 2/2] Improved support for multiple inputs in SimpleSimulator --- SimpleSimulator.cpp | 104 +++++++++++++++----------------------------- SimpleSimulator.h | 11 ++--- 2 files changed, 41 insertions(+), 74 deletions(-) diff --git a/SimpleSimulator.cpp b/SimpleSimulator.cpp index dc89ca1..e0e6831 100644 --- a/SimpleSimulator.cpp +++ b/SimpleSimulator.cpp @@ -154,33 +154,33 @@ void SimpleSimulator::processEvents() tuioServer->resetTuioCursors(); stickyCursorList.clear(); jointCursorList.clear(); - activeCursorList.clear(); + activeCursorMap.clear(); } break; case SDL_MOUSEMOTION: if (event.button.button == SDL_BUTTON_LEFT && event.motion.which != SDL_TOUCH_MOUSEID){ - mouseDragged((float)event.button.x/width, (float)event.button.y/height); + mouseDragged((float)event.button.x/width, (float)event.button.y/height, MOUSE_FINGER_ID); } break; case SDL_MOUSEBUTTONDOWN: if (event.button.button == SDL_BUTTON_LEFT && event.button.which != SDL_TOUCH_MOUSEID){ - mousePressed((float)event.button.x/width, (float)event.button.y/height); + mousePressed((float)event.button.x/width, (float)event.button.y/height, MOUSE_FINGER_ID); } break; case SDL_MOUSEBUTTONUP: if (event.button.button == SDL_BUTTON_LEFT && event.button.which != SDL_TOUCH_MOUSEID){ - mouseReleased((float)event.button.x/width, (float)event.button.y/height); + mouseReleased((float)event.button.x/width, (float)event.button.y/height, MOUSE_FINGER_ID); } break; case SDL_FINGERMOTION: - mouseDragged((float)event.tfinger.x, (float)event.tfinger.y); + mouseDragged((float)event.tfinger.x, (float)event.tfinger.y, event.tfinger.fingerId); break; case SDL_FINGERDOWN: - mousePressed((float)event.tfinger.x, (float)event.tfinger.y); + mousePressed((float)event.tfinger.x, (float)event.tfinger.y, event.tfinger.fingerId); break; case SDL_FINGERUP: - mouseReleased((float)event.tfinger.x, (float)event.tfinger.y); + mouseReleased((float)event.tfinger.x, (float)event.tfinger.y, event.tfinger.fingerId); break; case SDL_QUIT: running = false; @@ -191,7 +191,7 @@ void SimpleSimulator::processEvents() } } -void SimpleSimulator::mousePressed(float x, float y) { +void SimpleSimulator::mousePressed(float x, float y, long long int activeId) { //printf("pressed %f %f\n",x,y); TuioCursor *match = NULL; @@ -204,101 +204,67 @@ void SimpleSimulator::mousePressed(float x, float y) { match = tcur; } } - - const Uint8 *keystate = SDL_GetKeyboardState(NULL); + const Uint8 *keystate = SDL_GetKeyboardState(NULL); if ((keystate[SDL_SCANCODE_LSHIFT]) || (keystate[SDL_SCANCODE_RSHIFT])) { - if (match!=NULL) { std::list::iterator joint = std::find( jointCursorList.begin(), jointCursorList.end(), match ); if( joint != jointCursorList.end() ) { jointCursorList.erase( joint ); } stickyCursorList.remove(match); - activeCursorList.remove(match); tuioServer->removeTuioCursor(match); } else { TuioCursor *cursor = tuioServer->addTuioCursor(x,y); stickyCursorList.push_back(cursor); - activeCursorList.push_back(cursor); + activeCursorMap[activeId] = cursor; } } else if ((keystate[SDL_SCANCODE_LCTRL]) || (keystate[SDL_SCANCODE_RCTRL])) { - if (match!=NULL) { std::list::iterator joint = std::find( jointCursorList.begin(), jointCursorList.end(), match ); if( joint != jointCursorList.end() ) { jointCursorList.remove( match ); } else jointCursorList.push_back(match); } + } else if (match==NULL) { + TuioCursor *cursor = tuioServer->addTuioCursor(x,y); + activeCursorMap[activeId] = cursor; } else { - if (match==NULL) { - TuioCursor *cursor = tuioServer->addTuioCursor(x,y); - activeCursorList.push_back(cursor); - } else activeCursorList.push_back(match); + activeCursorMap[activeId] = match; } } -void SimpleSimulator::mouseDragged(float x, float y) { +void SimpleSimulator::mouseDragged(float x, float y, long long int activeId) { //printf("dragged %f %f\n",x,y); - TuioCursor *cursor = NULL; - float distance = width; - for (std::list::iterator iter = activeCursorList.begin(); iter!=activeCursorList.end(); iter++) { - TuioCursor *tcur = (*iter); - float test = tcur->getDistance(x,y); - if (testsecond; - if (cursor==NULL) return; - if (cursor->getTuioTime()==frameTime) return; + if (cursor->getTuioTime()==frameTime) return; - std::list::iterator joint = std::find( jointCursorList.begin(), jointCursorList.end(), cursor ); - if( joint != jointCursorList.end() ) { - float dx = x-cursor->getX(); - float dy = y-cursor->getY(); - for (std::list::iterator iter = jointCursorList.begin(); iter!=jointCursorList.end(); iter++) { - TuioCursor *jointCursor = (*iter); - tuioServer->updateTuioCursor(jointCursor,jointCursor->getX()+dx,jointCursor->getY()+dy); - } - } else tuioServer->updateTuioCursor(cursor,x,y); + bool joint = ( std::find(jointCursorList.begin(), jointCursorList.end(), cursor) != jointCursorList.end() ); + if( joint ) { + float dx = x-cursor->getX(); + float dy = y-cursor->getY(); + for (TuioCursor* jointCursor : jointCursorList) { + tuioServer->updateTuioCursor(jointCursor,jointCursor->getX()+dx,jointCursor->getY()+dy); + } + } else tuioServer->updateTuioCursor(cursor,x,y); + } } -void SimpleSimulator::mouseReleased(float x, float y) { +void SimpleSimulator::mouseReleased(float x, float y, long long int activeId) { //printf("released %f %f\n",x,y); - TuioCursor *cursor = NULL; - float distance = 0.01f; - for (std::list::iterator iter = stickyCursorList.begin(); iter!=stickyCursorList.end(); iter++) { - TuioCursor *tcur = (*iter); - float test = tcur->getDistance(x,y); - if (test::iterator iter = activeCursorList.begin(); iter!=activeCursorList.end(); iter++) { - TuioCursor *tcur = (*iter); - float test = tcur->getDistance(x,y); - if (testsecond) != stickyCursorList.end()); + if( !sticky ){ + tuioServer->removeTuioCursor(cursorIterator->second); } } - - if (cursor!=NULL) { - activeCursorList.remove(cursor); - tuioServer->removeTuioCursor(cursor); - } } SimpleSimulator::SimpleSimulator(TuioServer *server) diff --git a/SimpleSimulator.h b/SimpleSimulator.h index 528a118..8ae9817 100644 --- a/SimpleSimulator.h +++ b/SimpleSimulator.h @@ -24,6 +24,7 @@ #include "TuioCursor.h" #include "osc/OscTypes.h" #include +#include #include #include "FlashSender.h" @@ -54,7 +55,7 @@ class SimpleSimulator { TuioServer *tuioServer; std::list stickyCursorList; std::list jointCursorList; - std::list activeCursorList; + std::map activeCursorMap; private: void drawFrame(); @@ -65,16 +66,16 @@ class SimpleSimulator { SDL_Window *window; SDL_Renderer *renderer; bool verbose, fullupdate, periodic, fullscreen, running, help; + const static long long int MOUSE_FINGER_ID = 0x93BB922B64699C8C; int width, height; int screen_width, screen_height; int window_width, window_height; TuioTime frameTime; - void mousePressed(float x, float y); - void mouseReleased(float x, float y); - void mouseDragged(float x, float y); - //int s_id; + void mousePressed(float x, float y, long long int activeId); + void mouseReleased(float x, float y, long long int activeId); + void mouseDragged(float x, float y, long long int activeId); }; #endif /* INCLUDED_SimpleSimulator_H */