From bdaae198544684bde95c04efd213308cd829bf20 Mon Sep 17 00:00:00 2001 From: nathan Date: Wed, 11 Mar 2020 22:07:57 -0700 Subject: [PATCH] separating touch and mouse events to avoid doubling up on touch laptops Former-commit-id: 52e7e5b694b63f32983161c30c7c303e65eeb948 Former-commit-id: 0dbb0763a6ee302365429495cdcc3ebe9029a584 --- Input.cpp | 62 ++++++++++++++++++++++++++++++++---------- map1090.REMOVED.git-id | 2 +- 2 files changed, 49 insertions(+), 15 deletions(-) diff --git a/Input.cpp b/Input.cpp index 30288a2..4c9c184 100644 --- a/Input.cpp +++ b/Input.cpp @@ -50,31 +50,65 @@ void Input::getInput() appData.mapMoved = 1; break; - case SDL_MOUSEBUTTONDOWN: + case SDL_FINGERMOTION:; + appData.isDragging = 1; + view->moveCenterRelative( appData.screen_width * event.tfinger.dx, appData.screen_height * event.tfinger.dy); + break; + + case SDL_FINGERDOWN: if(mstime() - appData.touchDownTime > 500) { appData.tapCount = 0; } appData.touchDownTime = mstime(); break; + case SDL_FINGERUP: + if(mstime() - appData.touchDownTime < 120) { + appData.touchx = appData.screen_width * event.tfinger.x; + appData.touchy = appData.screen_height * event.tfinger.y; + appData.tapCount++; + appData.isDragging = 0; + + view->registerClick(); + } else { + appData.touchx = 0; + appData.touchy = 0; + appData.tapCount = 0; + } + + break; + + case SDL_MOUSEBUTTONDOWN: + if(event.button.which != SDL_TOUCH_MOUSEID) { + if(mstime() - appData.touchDownTime > 500) { + appData.tapCount = 0; + } + appData.touchDownTime = mstime(); + } + break; + case SDL_MOUSEBUTTONUP:; - appData.touchx = event.motion.x; - appData.touchy = event.motion.y; - appData.tapCount = event.button.clicks; + if(event.button.which != SDL_TOUCH_MOUSEID) { + appData.touchx = event.motion.x; + appData.touchy = event.motion.y; + appData.tapCount = event.button.clicks; + appData.isDragging = 0; - view->registerClick(); - - appData.isDragging = 0; + view->registerClick(); + } break; case SDL_MOUSEMOTION:; - appData.mouseMovedTime = mstime(); - appData.mousex = event.motion.x; - appData.mousey = event.motion.y; - - if (SDL_GetMouseState(NULL, NULL) & SDL_BUTTON(SDL_BUTTON_LEFT)) { - appData.isDragging = 1; - view->moveCenterRelative(event.motion.xrel, event.motion.yrel); + + if(event.motion.which != SDL_TOUCH_MOUSEID) { + appData.mouseMovedTime = mstime(); + appData.mousex = event.motion.x; + appData.mousey = event.motion.y; + + if (SDL_GetMouseState(NULL, NULL) & SDL_BUTTON(SDL_BUTTON_LEFT)) { + appData.isDragging = 1; + view->moveCenterRelative(event.motion.xrel, event.motion.yrel); + } } break; } diff --git a/map1090.REMOVED.git-id b/map1090.REMOVED.git-id index 2146ae3..5805694 100644 --- a/map1090.REMOVED.git-id +++ b/map1090.REMOVED.git-id @@ -1 +1 @@ -93406437edceb4cd6d39e963d3094663472f660b \ No newline at end of file +3e3eb8a1241fe042f8979c8ab0fb931f24e6100f \ No newline at end of file