From: yangchen Date: Tue, 18 Oct 2016 11:30:43 +0000 (+0800) Subject: add multi-Touch support. X-Git-Tag: accepted/tizen/common/20161102.121534~7^2 X-Git-Url: http://review.tizen.org/git/?a=commitdiff_plain;h=706368e2ebe73fd0691469e61058db929d3b6a6d;p=platform%2Fupstream%2FSDL.git add multi-Touch support. Change-Id: I5172df08d77dd94f30dc8be8a41b86efba150a33 --- diff --git a/src/video/tizen/SDL_tizenmouse.c b/src/video/tizen/SDL_tizenmouse.c index 65c364c..efc9034 100755 --- a/src/video/tizen/SDL_tizenmouse.c +++ b/src/video/tizen/SDL_tizenmouse.c @@ -30,6 +30,7 @@ #include "SDL_tizenmouse.h" #include "SDL_log.h" +#include "SDL_tizentouch.h" #include #include @@ -256,6 +257,9 @@ _tizen_cb_event_mousedown_change(void *data, int type, void *event) SDL_LogDebug(SDL_LOG_CATEGORY_APPLICATION, "mouse down (%d x %d)",e->x,e->y); SDL_SendMouseMotion(_this->current_glwin, 0, 0, e->x, e->y); SDL_SendMouseButton(_this->current_glwin, 0, SDL_PRESSED, SDL_BUTTON_LEFT); + + Tizen_OnTouch(_this,1,e->multi.device,ACTION_POINTER_DOWN,e->x,e->y,1.0f); + return ECORE_CALLBACK_PASS_ON; } @@ -269,6 +273,9 @@ _tizen_cb_event_mouseup_change(void *data, int type, void *event) SDL_LogDebug(SDL_LOG_CATEGORY_APPLICATION, "mouse up (%d x %d)",e->x,e->y); SDL_SendMouseMotion(_this->current_glwin, 0, 0, e->x, e->y); SDL_SendMouseButton(_this->current_glwin, 0, SDL_RELEASED, SDL_BUTTON_LEFT); + + Tizen_OnTouch(_this,1,e->multi.device,ACTION_POINTER_UP,e->x,e->y,1.0f); + return ECORE_CALLBACK_PASS_ON; } @@ -283,6 +290,8 @@ _tizen_cb_event_mousemove_change(void *data, int type, void *event) //SDL_LogDebug(SDL_LOG_CATEGORY_APPLICATION, "mouse move (%d x %d)",e->x,e->y); SDL_SendMouseMotion(_this->current_glwin, 0, 0, e->x, e->y); + Tizen_OnTouch(_this,1,e->multi.device,ACTION_POINTER_MOVE,e->x,e->y,1.0f); + return ECORE_CALLBACK_PASS_ON; } diff --git a/src/video/tizen/SDL_tizentouch.c b/src/video/tizen/SDL_tizentouch.c old mode 100644 new mode 100755 index 7ba8b98..4970bc7 --- a/src/video/tizen/SDL_tizentouch.c +++ b/src/video/tizen/SDL_tizentouch.c @@ -24,3 +24,97 @@ #include "../../SDL_internal.h" +#if SDL_VIDEO_DRIVER_TIZEN + +#include "../SDL_sysvideo.h" +#include "SDL_video.h" +#include "SDL_mouse.h" +#include "SDL_stdinc.h" +#include "SDL_hints.h" +#include "../../events/SDL_events_c.h" +#include "../../core/tizen/SDL_tizen.h" + +#include "SDL_tizenvideo.h" +#include "SDL_tizenevents_c.h" +#include "SDL_tizenmouse.h" +#include "SDL_tizentouch.h" + +static void Tizen_GetNormalizedCoordinates(_THIS,float x, float y, + float *normalized_x, float *normalized_y) +{ + int window_w, window_h; + + SDL_GetWindowSize(_this->windows, &window_w, &window_h); + *normalized_x = (float)(x / window_w); + *normalized_y = (float)(y / window_h); +} + +static volatile SDL_bool separate_mouse_and_touch = SDL_FALSE; + +static void +SeparateEventsHintWatcher(void *userdata, const char *name, + const char *oldValue, const char *newValue) +{ + SDL_Unsupported(); +} + +void Tizen_InitTouch(void) +{ + /*By default,tizen only have one touch device*/ + SDL_TouchID deviceId = 1; + + SDL_AddHintCallback(SDL_HINT_ANDROID_SEPARATE_MOUSE_AND_TOUCH, + SeparateEventsHintWatcher, NULL); + if(SDL_AddTouch(deviceId, "Tizen_Touch")<0) + { + SDL_Log("error: can't add tizen touch %s, %d", __FILE__, __LINE__); + } +} + +void Tizen_QuitTouch(void) +{ + SDL_DelHintCallback(SDL_HINT_ANDROID_SEPARATE_MOUSE_AND_TOUCH, + SeparateEventsHintWatcher, NULL); + separate_mouse_and_touch = SDL_FALSE; +} + +void Tizen_OnTouch(_THIS, int touch_device_id_in, int pointer_finger_id_in, int action, float x, float y, float p) +{ + SDL_TouchID touchDeviceId = 0; + SDL_FingerID fingerId = 0; + float normalized_x, normalized_y; + + if (!_this->windows) { + return; + } + Tizen_GetNormalizedCoordinates(_this,x,y,&normalized_x,&normalized_y); + + touchDeviceId = (SDL_TouchID)touch_device_id_in; + if (SDL_AddTouch(touchDeviceId, "Tizen_Touch") < 0) { + SDL_Log("error: can't add touch %s, %d", __FILE__, __LINE__); + } + + fingerId = (SDL_FingerID)pointer_finger_id_in; + switch (action) { + case ACTION_POINTER_DOWN: + /* Touch pointer down */ + SDL_SendTouch(touchDeviceId, fingerId, SDL_TRUE, normalized_x, normalized_y, p); + break; + + case ACTION_POINTER_MOVE: + SDL_SendTouchMotion(touchDeviceId, fingerId, normalized_x, normalized_y, p); + break; + + case ACTION_POINTER_UP: + /* Touch pointer up */ + SDL_SendTouch(touchDeviceId, fingerId, SDL_FALSE, normalized_x, normalized_y, p); + break; + + default: + break; + } +} + +#endif /* SDL_VIDEO_DRIVER_TIZEN */ + +/* vi: set ts=4 sw=4 expandtab: */ diff --git a/src/video/tizen/SDL_tizentouch.h b/src/video/tizen/SDL_tizentouch.h old mode 100644 new mode 100755 index c64a48e..74b522d --- a/src/video/tizen/SDL_tizentouch.h +++ b/src/video/tizen/SDL_tizentouch.h @@ -22,3 +22,18 @@ #include "../../SDL_internal.h" +#include "SDL_tizenvideo.h" + +#define ACTION_POINTER_DOWN 1 +#define ACTION_POINTER_UP 2 +#define ACTION_POINTER_MOVE 3 +#define ACTION_CANCEL 4 +#define ACTION_OUTSIDE 5 + +#define TOUCH_THRESHOLD 100.0f + +extern void Tizen_InitTouch(void); +extern void Tizen_QuitTouch(void); +extern void Tizen_OnTouch(_THIS, int touch_device_id_in, int pointer_finger_id_in, int action, float x, float y, float p); + +/* vi: set ts=4 sw=4 expandtab: */