|
1 /* |
|
2 SDL - Simple DirectMedia Layer |
|
3 Copyright (C) 1997-2011 Sam Lantinga |
|
4 |
|
5 This library is free software; you can redistribute it and/or |
|
6 modify it under the terms of the GNU Lesser General Public |
|
7 License as published by the Free Software Foundation; either |
|
8 version 2.1 of the License, or (at your option) any later version. |
|
9 |
|
10 This library is distributed in the hope that it will be useful, |
|
11 but WITHOUT ANY WARRANTY; without even the implied warranty of |
|
12 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU |
|
13 Lesser General Public License for more details. |
|
14 |
|
15 You should have received a copy of the GNU Lesser General Public |
|
16 License along with this library; if not, write to the Free Software |
|
17 Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA |
|
18 |
|
19 Sam Lantinga |
|
20 slouken@libsdl.org |
|
21 */ |
|
22 #include "SDL_config.h" |
|
23 |
|
24 #include <android/log.h> |
|
25 |
|
26 #include "SDL_events.h" |
|
27 #include "../../events/SDL_touch_c.h" |
|
28 |
|
29 #include "SDL_androidtouch.h" |
|
30 |
|
31 |
|
32 #define ACTION_DOWN 0 |
|
33 #define ACTION_UP 1 |
|
34 #define ACTION_MOVE 2 |
|
35 #define ACTION_CANCEL 3 |
|
36 #define ACTION_OUTSIDE 4 |
|
37 #define ACTION_POINTER_DOWN 5 |
|
38 #define ACTION_POINTER_UP 6 |
|
39 |
|
40 |
|
41 void Android_OnTouch(int action, int pointerId, float x, float y, float p) |
|
42 { |
|
43 if (!Android_Window) { |
|
44 return; |
|
45 } |
|
46 |
|
47 //The first event will provide the x, y and pressure max values, |
|
48 if(!SDL_GetTouch(1)){ |
|
49 SDL_Touch touch; |
|
50 touch.id = 1; |
|
51 touch.x_min = 0; |
|
52 touch.x_max = x; |
|
53 touch.native_xres = touch.x_max - touch.x_min; |
|
54 touch.y_min = 0; |
|
55 touch.y_max = y; |
|
56 touch.native_yres = touch.y_max - touch.y_min; |
|
57 touch.pressure_min = 0; |
|
58 touch.pressure_max = p; |
|
59 touch.native_pressureres = touch.pressure_max - touch.pressure_min; |
|
60 |
|
61 if(SDL_AddTouch(&touch, "") < 0) return; |
|
62 } |
|
63 |
|
64 |
|
65 switch(action){ |
|
66 case ACTION_DOWN: |
|
67 case ACTION_POINTER_DOWN: |
|
68 SDL_SetTouchFocus(pointerId, Android_Window); |
|
69 SDL_SendFingerDown(1, pointerId, SDL_TRUE, x, y, p); |
|
70 break; |
|
71 case ACTION_CANCEL: |
|
72 case ACTION_POINTER_UP: |
|
73 case ACTION_UP: |
|
74 SDL_SendFingerDown(1, pointerId, SDL_FALSE, x, y, p); |
|
75 break; |
|
76 case ACTION_MOVE: |
|
77 SDL_SendTouchMotion(1, pointerId, 0, x, y, p); |
|
78 break; |
|
79 case ACTION_OUTSIDE: |
|
80 break; |
|
81 } |
|
82 } |
|
83 |
|
84 /* vi: set ts=4 sw=4 expandtab: */ |