add multi-Touch support. 55/92755/2
authoryangchen <chen2.yang@samsung.com>
Tue, 18 Oct 2016 11:30:43 +0000 (19:30 +0800)
committeryangchen <chen2.yang@samsung.com>
Wed, 19 Oct 2016 08:28:54 +0000 (16:28 +0800)
Change-Id: I5172df08d77dd94f30dc8be8a41b86efba150a33

src/video/tizen/SDL_tizenmouse.c
src/video/tizen/SDL_tizentouch.c [changed mode: 0644->0755]
src/video/tizen/SDL_tizentouch.h [changed mode: 0644->0755]

index 65c364c..efc9034 100755 (executable)
@@ -30,6 +30,7 @@
 
 #include "SDL_tizenmouse.h"
 #include "SDL_log.h"
+#include "SDL_tizentouch.h"
 
 #include <sys/mman.h>
 #include <fcntl.h>
@@ -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;
 }
 
old mode 100644 (file)
new mode 100755 (executable)
index 7ba8b98..4970bc7
 
 #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: */
old mode 100644 (file)
new mode 100755 (executable)
index c64a48e..74b522d
 
 #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: */