1 /*
2 Simple DirectMedia Layer
3 Copyright (C) 1997-2020 Sam Lantinga <slouken@libsdl.org>
4
5 This software is provided 'as-is', without any express or implied
6 warranty. In no event will the authors be held liable for any damages
7 arising from the use of this software.
8
9 Permission is granted to anyone to use this software for any purpose,
10 including commercial applications, and to alter it and redistribute it
11 freely, subject to the following restrictions:
12
13 1. The origin of this software must not be misrepresented; you must not
14 claim that you wrote the original software. If you use this software
15 in a product, an acknowledgment in the product documentation would be
16 appreciated but is not required.
17 2. Altered source versions must be plainly marked as such, and must not be
18 misrepresented as being the original software.
19 3. This notice may not be removed or altered from any source distribution.
20 */
21 #include "../../SDL_internal.h"
22
23 #if SDL_VIDEO_DRIVER_ANDROID
24
25 #include <android/log.h>
26
27 #include "SDL_hints.h"
28 #include "SDL_events.h"
29 #include "SDL_androidtouch.h"
30 #include "../../events/SDL_mouse_c.h"
31 #include "../../events/SDL_touch_c.h"
32 #include "../../core/android/SDL_android.h"
33
34 #define ACTION_DOWN 0
35 #define ACTION_UP 1
36 #define ACTION_MOVE 2
37 /* #define ACTION_CANCEL 3 */
38 /* #define ACTION_OUTSIDE 4 */
39 #define ACTION_POINTER_DOWN 5
40 #define ACTION_POINTER_UP 6
41
Android_InitTouch(void)42 void Android_InitTouch(void)
43 {
44 /* Add all touch devices */
45 Android_JNI_InitTouch();
46 }
47
Android_QuitTouch(void)48 void Android_QuitTouch(void)
49 {
50 }
51
Android_OnTouch(SDL_Window * window,int touch_device_id_in,int pointer_finger_id_in,int action,float x,float y,float p)52 void Android_OnTouch(SDL_Window *window, int touch_device_id_in, int pointer_finger_id_in, int action, float x, float y, float p)
53 {
54 SDL_TouchID touchDeviceId = 0;
55 SDL_FingerID fingerId = 0;
56
57 if (!window) {
58 return;
59 }
60
61 touchDeviceId = (SDL_TouchID)touch_device_id_in;
62 if (SDL_AddTouch(touchDeviceId, SDL_TOUCH_DEVICE_DIRECT, "") < 0) {
63 SDL_Log("error: can't add touch %s, %d", __FILE__, __LINE__);
64 }
65
66 fingerId = (SDL_FingerID)pointer_finger_id_in;
67 switch (action) {
68 case ACTION_DOWN:
69 case ACTION_POINTER_DOWN:
70 SDL_SendTouch(touchDeviceId, fingerId, window, SDL_TRUE, x, y, p);
71 break;
72
73 case ACTION_MOVE:
74 SDL_SendTouchMotion(touchDeviceId, fingerId, window, x, y, p);
75 break;
76
77 case ACTION_UP:
78 case ACTION_POINTER_UP:
79 SDL_SendTouch(touchDeviceId, fingerId, window, SDL_FALSE, x, y, p);
80 break;
81
82 default:
83 break;
84 }
85 }
86
87 #endif /* SDL_VIDEO_DRIVER_ANDROID */
88
89 /* vi: set ts=4 sw=4 expandtab: */
90