zenilib: zenilib/jni/external/sdl/src/video/android/SDL_androidtouch.c Source File

zenilib 0.5.3.0

- Main Page
- Modules
- Namespaces
- Classes
- Files

- File List
- File Members

All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Groups Pages
SDL_androidtouch.c
Go to the documentation of this file.
1 /*
2 Simple DirectMedia Layer
3 Copyright (C) 1997-2013 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_config.h"
22
23 #if SDL_VIDEO_DRIVER_ANDROID
24
25 #include <android/log.h>
26
27 #include "SDL_events.h"
28 #include "../../events/SDL_mouse_c.h"
29 #include "../../events/SDL_touch_c.h"
30 #include "SDL_log.h"
31
32 #include "SDL_androidtouch.h"
33
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 /* The following two are deprecated but it seems they are still emitted (instead the corresponding ACTION_UP/DOWN) as of Android 3.2 */
41 #define ACTION_POINTER_1_DOWN 5
42 #define ACTION_POINTER_1_UP 6
43
44 static SDL_FingerID leftFingerDown = 0;
45
46 static void Android_GetWindowCoordinates(float x, float y,
47 int *window_x, int *window_y)
48 {
49 int window_w, window_h;
50
51 SDL_GetWindowSize(Android_Window, &window_w, &window_h);
52 *window_x = (int)(x * window_w);
53 *window_y = (int)(y * window_h);
54 }
55
56 void Android_OnTouch(int touch_device_id_in, int pointer_finger_id_in, int action, float x, float y, float p)
57 {
58 SDL_TouchID touchDeviceId = 0;
59 SDL_FingerID fingerId = 0;
60 int window_x, window_y;
61
62 if (!Android_Window) {
63 return;
64 }
65
66 touchDeviceId = (SDL_TouchID)touch_device_id_in;
67 if (SDL_AddTouch(touchDeviceId, "") < 0) {
68 SDL_Log("error: can't add touch %s, %d", __FILE__, __LINE__);
69 }
70
71 fingerId = (SDL_FingerID)pointer_finger_id_in;
72 switch (action) {
73 case ACTION_DOWN:
74 case ACTION_POINTER_1_DOWN:
75 if (!leftFingerDown) {
76 Android_GetWindowCoordinates(x, y, &window_x, &window_y);
77
78 /* send moved event */
79 SDL_SendMouseMotion(NULL, SDL_TOUCH_MOUSEID, 0, window_x, window_y);
80
81 /* send mouse down event */
82 SDL_SendMouseButton(NULL, SDL_TOUCH_MOUSEID, SDL_PRESSED, SDL_BUTTON_LEFT);
83
84 leftFingerDown = fingerId;
85 }
86 SDL_SendTouch(touchDeviceId, fingerId, SDL_TRUE, x, y, p);
87 break;
88 case ACTION_MOVE:
89 if (!leftFingerDown) {
90 Android_GetWindowCoordinates(x, y, &window_x, &window_y);
91
92 /* send moved event */
93 SDL_SendMouseMotion(NULL, SDL_TOUCH_MOUSEID, 0, window_x, window_y);
94 }
95 SDL_SendTouchMotion(touchDeviceId, fingerId, x, y, p);
96 break;
97 case ACTION_UP:
98 case ACTION_POINTER_1_UP:
99 if (fingerId == leftFingerDown) {
100 /* send mouse up */
101 SDL_SendMouseButton(NULL, SDL_TOUCH_MOUSEID, SDL_RELEASED, SDL_BUTTON_LEFT);
102 leftFingerDown = 0;
103 }
104 SDL_SendTouch(touchDeviceId, fingerId, SDL_FALSE, x, y, p);
105 break;
106 default:
107 break;
108 }
109 }
110
111 #endif /* SDL_VIDEO_DRIVER_ANDROID */
112
113 /* vi: set ts=4 sw=4 expandtab: */
SDL_TouchID
Sint64 SDL_TouchID
Definition: SDL_touch.h:41
SDL_log.h
NULL
#define NULL
Definition: ftobjs.h:61
SDL_FingerID
Sint64 SDL_FingerID
Definition: SDL_touch.h:42
SDL_TRUE
Definition: SDL_stdinc.h:119
x
EGLSurface EGLint x
Definition: eglext.h:293
SDL_events.h
SDL_SendTouch
int SDL_SendTouch(SDL_TouchID id, SDL_FingerID fingerid, SDL_bool down, float x, float y, float pressure)
Definition: SDL_touch.c:213
Android_OnTouch
void Android_OnTouch(int touch_device_id_in, int pointer_finger_id_in, int action, float x, float y, float p)
SDL_GetWindowSize
DECLSPEC void SDLCALL SDL_GetWindowSize(SDL_Window *window, int *w, int *h)
Get the size of a window&#39;s client area.
Definition: SDL_video.c:1638
SDL_TOUCH_MOUSEID
#define SDL_TOUCH_MOUSEID
Definition: SDL_touch.h:53
SDL_FALSE
Definition: SDL_stdinc.h:118
SDL_config.h
SDL_SendTouchMotion
int SDL_SendTouchMotion(SDL_TouchID id, SDL_FingerID fingerid, float x, float y, float pressure)
Definition: SDL_touch.c:275
int
int
Definition: SDL_systhread.c:37
SDL_SendMouseMotion
int SDL_SendMouseMotion(SDL_Window *window, SDL_MouseID mouseID, int relative, int x, int y)
Definition: SDL_mouse.c:178
SDL_BUTTON_LEFT
#define SDL_BUTTON_LEFT
Definition: SDL_mouse.h:204
p
GLfloat GLfloat p
Definition: glew.h:14938
Android_Window
SDL_Window * Android_Window
SDL_AddTouch
int SDL_AddTouch(SDL_TouchID touchID, const char *name)
Definition: SDL_touch.c:130
y
EGLSurface EGLint EGLint y
Definition: eglext.h:293
SDL_Log
DECLSPEC void SDLCALL SDL_Log(const char *fmt,...)
Log a message with SDL_LOG_CATEGORY_APPLICATION and SDL_LOG_PRIORITY_INFO.
Definition: SDL_log.c:173
SDL_PRESSED
#define SDL_PRESSED
Definition: SDL_events.h:50
SDL_RELEASED
#define SDL_RELEASED
Definition: SDL_events.h:49
SDL_androidtouch.h
SDL_SendMouseButton
int SDL_SendMouseButton(SDL_Window *window, SDL_MouseID mouseID, Uint8 state, Uint8 button)
Definition: SDL_mouse.c:276