Skip to content
This repository has been archived by the owner on Feb 11, 2021. It is now read-only.

Latest commit

 

History

History
92 lines (76 loc) · 3 KB

SDL_androidtouch.c

File metadata and controls

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