From 56a8bed0e38035ae2ba5ad4e686f5368d9438ece Mon Sep 17 00:00:00 2001 From: "wrenczes@gmail.com" Date: Sat, 11 Jun 2011 06:59:32 +0000 Subject: [PATCH] More work on Android touch events. Fixed the issues I was having with busted float coords, and added some logic for a different way to deal with selection. Doubleclicking is no longer required; instead, if you generate a finger up event within 50 pixels of where you fingered down, this will be treated as an JGE_BTN_OK event. I think this feels more natural, as you can drag around in a menu or to various cards; then when you find your selection, simply touching it again once triggers the selection. --- JGE/Dependencies/SDL/src/events/SDL_touch.c | 19 +++++++---------- .../SDL/src/video/android/SDL_androidtouch.c | 16 +++++++++----- JGE/src/SDLmain.cpp | 21 ++++++++++++++++--- 3 files changed, 37 insertions(+), 19 deletions(-) diff --git a/JGE/Dependencies/SDL/src/events/SDL_touch.c b/JGE/Dependencies/SDL/src/events/SDL_touch.c index 975d46f36..dafb78e4c 100644 --- a/JGE/Dependencies/SDL/src/events/SDL_touch.c +++ b/JGE/Dependencies/SDL/src/events/SDL_touch.c @@ -141,8 +141,10 @@ SDL_AddTouch(const SDL_Touch * touch, char *name) SDL_touchPads[index]->relative_mode = SDL_FALSE; SDL_touchPads[index]->flush_motion = SDL_FALSE; - SDL_touchPads[index]->xres = (1<<(16-1)); - SDL_touchPads[index]->yres = (1<<(16-1)); + // Wil 06/10/11: WTF is this for? It's stomping over what's been passed in! + //SDL_touchPads[index]->xres = (1<<(16-1)); + //SDL_touchPads[index]->yres = (1<<(16-1)); + //Do I want this here? Probably SDL_GestureAddTouch(SDL_touchPads[index]); @@ -309,16 +311,15 @@ SDL_DelFinger(SDL_Touch* touch,SDL_FingerID fingerid) return 0; } - int SDL_SendFingerDown(SDL_TouchID id, SDL_FingerID fingerid, SDL_bool down, float xin, float yin, float pressurein) { int posted; - Uint16 x; - Uint16 y; - Uint16 pressure; - SDL_Finger *finger; + Uint16 x; + Uint16 y; + Uint16 pressure; + SDL_Finger *finger; SDL_Touch* touch = SDL_GetTouch(id); @@ -331,10 +332,6 @@ SDL_SendFingerDown(SDL_TouchID id, SDL_FingerID fingerid, SDL_bool down, y = (Uint16)((yin+touch->y_min)*(touch->yres)/(touch->native_yres)); pressure = (Uint16)((pressurein+touch->pressure_min)*(touch->pressureres)/(touch->native_pressureres)); - char buffer[64]; - sprintf(buffer, "Finger Down: xin: %g yin: %g x: %d y: %d", xin, yin, x, y); - __android_log_write(ANDROID_LOG_DEBUG, "Wagic", buffer); - finger = SDL_GetFinger(touch,fingerid); if(down) { if(finger == NULL) { diff --git a/JGE/Dependencies/SDL/src/video/android/SDL_androidtouch.c b/JGE/Dependencies/SDL/src/video/android/SDL_androidtouch.c index a7ec2da40..2f124d005 100644 --- a/JGE/Dependencies/SDL/src/video/android/SDL_androidtouch.c +++ b/JGE/Dependencies/SDL/src/video/android/SDL_androidtouch.c @@ -25,6 +25,7 @@ #include "SDL_events.h" #include "SDL_touch.h" #include "../../events/SDL_mouse_c.h" +#include "../../events/SDL_touch_c.h" #include "SDL_androidtouch.h" @@ -42,16 +43,21 @@ SDL_Touch* CreateTouchInstance() { SDL_Touch touch; touch.id = gTouchID; + touch.x_min = 0; touch.x_max = 1; - touch.native_xres = touch.xres = 1; + touch.native_xres = 1; touch.xres = 1; - touch.y_min = 0; + + touch.y_min = 0; touch.y_max = 1; - touch.native_yres = touch.yres = 1; - touch.pressure_min = 0; + touch.native_yres = 1; + touch.yres = 1; + + touch.pressure_min = 0; touch.pressure_max = 1; - touch.native_pressureres = touch.pressure_max - touch.pressure_min; + touch.native_pressureres = 1; + touch.pressureres = 1; SDL_AddTouch(&touch, ""); diff --git a/JGE/src/SDLmain.cpp b/JGE/src/SDLmain.cpp index 6e8d4890e..b4438dfa4 100644 --- a/JGE/src/SDLmain.cpp +++ b/JGE/src/SDLmain.cpp @@ -40,6 +40,8 @@ enum eDisplayMode unsigned int gDisplayMode = DisplayMode_lowRes; +const int kHitzonePliancy = 50; + class SdlApp { public: /* For easy interfacing with JGE static functions */ @@ -53,8 +55,11 @@ public: /* For easy interfacing with JGE static functions */ int windowed_pos_x; int windowed_pos_y; + int mMouseDownX; + int mMouseDownY; + public: - SdlApp() : Surf_Display(NULL), window(NULL), lastMouseUpTime(0), Running(true) + SdlApp() : Surf_Display(NULL), window(NULL), lastMouseUpTime(0), Running(true), mMouseDownX(0), mMouseDownY(0) { } @@ -503,11 +508,21 @@ void SdlApp::OnTouchEvent(const SDL_TouchFingerEvent& event) g_engine->LeftClicked( ((event.x - viewPort.x) * SCREEN_WIDTH) / actualWidth, ((event.y - viewPort.y) * SCREEN_HEIGHT) / actualHeight); - + + if (event.type == SDL_FINGERDOWN) + { + mMouseDownX = event.x; + mMouseDownY = event.y; + } + #if (defined ANDROID) || (defined IOS) if (event.type == SDL_FINGERUP) { - g_engine->HoldKey_NoRepeat(JGE_BTN_OK); + // treat an up finger within 50 pixels of the down finger coords as a double click event + if (abs(mMouseDownX - event.x) < kHitzonePliancy && abs(mMouseDownY - event.y) < kHitzonePliancy) + { + g_engine->HoldKey_NoRepeat(JGE_BTN_OK); + } } #endif }