SDL 2.0
SDL_androidtouch.c
Go to the documentation of this file.
1/*
2 Simple DirectMedia Layer
3 Copyright (C) 1997-2019 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_log.h"
30#include "SDL_androidtouch.h"
31#include "../../events/SDL_mouse_c.h"
32#include "../../events/SDL_touch_c.h"
33#include "../../core/android/SDL_android.h"
34
35#define ACTION_DOWN 0
36#define ACTION_UP 1
37#define ACTION_MOVE 2
38#define ACTION_CANCEL 3
39#define ACTION_OUTSIDE 4
40#define ACTION_POINTER_DOWN 5
41#define ACTION_POINTER_UP 6
42
43void Android_InitTouch(void)
44{
45 /* Add all touch devices */
47}
48
49void Android_QuitTouch(void)
50{
51 return;
52}
53
54void Android_OnTouch(SDL_Window *window, int touch_device_id_in, int pointer_finger_id_in, int action, float x, float y, float p)
55{
56 SDL_TouchID touchDeviceId = 0;
57 SDL_FingerID fingerId = 0;
58
59 if (!window) {
60 return;
61 }
62
63 touchDeviceId = (SDL_TouchID)touch_device_id_in;
64 if (SDL_AddTouch(touchDeviceId, SDL_TOUCH_DEVICE_DIRECT, "") < 0) {
65 SDL_Log("error: can't add touch %s, %d", __FILE__, __LINE__);
66 }
67
68 fingerId = (SDL_FingerID)pointer_finger_id_in;
69 switch (action) {
70 case ACTION_DOWN:
71 case ACTION_POINTER_DOWN:
72 SDL_SendTouch(touchDeviceId, fingerId, SDL_TRUE, x, y, p);
73 break;
74
75 case ACTION_MOVE:
76 SDL_SendTouchMotion(touchDeviceId, fingerId, x, y, p);
77 break;
78
79 case ACTION_UP:
80 case ACTION_POINTER_UP:
81 SDL_SendTouch(touchDeviceId, fingerId, SDL_FALSE, x, y, p);
82 break;
83
84 default:
85 break;
86 }
87}
88
89#endif /* SDL_VIDEO_DRIVER_ANDROID */
90
91/* vi: set ts=4 sw=4 expandtab: */
void Android_JNI_InitTouch(void)
void Android_OnTouch(SDL_Window *window, int touch_device_id_in, int pointer_finger_id_in, int action, float x, float y, float p)
void Android_QuitTouch(void)
void Android_InitTouch(void)
#define SDL_Log
GLint GLint GLint GLint GLint GLint y
Definition: SDL_opengl.h:1574
GLint GLint GLint GLint GLint x
Definition: SDL_opengl.h:1574
GLfloat GLfloat p
@ SDL_TRUE
Definition: SDL_stdinc.h:164
@ SDL_FALSE
Definition: SDL_stdinc.h:163
int SDL_SendTouch(SDL_TouchID id, SDL_FingerID fingerid, SDL_bool down, float x, float y, float pressure)
Definition: SDL_touch.c:242
int SDL_SendTouchMotion(SDL_TouchID id, SDL_FingerID fingerid, float x, float y, float pressure)
Definition: SDL_touch.c:364
int SDL_AddTouch(SDL_TouchID touchID, SDL_TouchDeviceType type, const char *name)
Definition: SDL_touch.c:155
Sint64 SDL_FingerID
Definition: SDL_touch.h:42
@ SDL_TOUCH_DEVICE_DIRECT
Definition: SDL_touch.h:47
Sint64 SDL_TouchID
Definition: SDL_touch.h:41
EGLSurface EGLNativeWindowType * window
Definition: eglext.h:1025
The type used to identify a window.
Definition: SDL_sysvideo.h:74