Added mouse emulation for touch events on Android.
This commit is contained in:
parent
dcc4ab558c
commit
b950bcbbab
2 changed files with 41 additions and 3 deletions
|
@ -40,10 +40,23 @@
|
||||||
#define ACTION_POINTER_1_DOWN 5
|
#define ACTION_POINTER_1_DOWN 5
|
||||||
#define ACTION_POINTER_1_UP 6
|
#define ACTION_POINTER_1_UP 6
|
||||||
|
|
||||||
|
static SDL_FingerID leftFingerDown = 0;
|
||||||
|
|
||||||
|
static void Android_GetWindowCoordinates(float x, float y,
|
||||||
|
int *window_x, int *window_y)
|
||||||
|
{
|
||||||
|
int window_w, window_h;
|
||||||
|
|
||||||
|
SDL_GetWindowSize(Android_Window, &window_w, &window_h);
|
||||||
|
*window_x = (int)(x * window_w);
|
||||||
|
*window_y = (int)(y * window_h);
|
||||||
|
}
|
||||||
|
|
||||||
void Android_OnTouch(int touch_device_id_in, int pointer_finger_id_in, int action, float x, float y, float p)
|
void Android_OnTouch(int touch_device_id_in, int pointer_finger_id_in, int action, float x, float y, float p)
|
||||||
{
|
{
|
||||||
SDL_TouchID touchDeviceId = 0;
|
SDL_TouchID touchDeviceId = 0;
|
||||||
SDL_FingerID fingerId = 0;
|
SDL_FingerID fingerId = 0;
|
||||||
|
int window_x, window_y;
|
||||||
|
|
||||||
if (!Android_Window) {
|
if (!Android_Window) {
|
||||||
return;
|
return;
|
||||||
|
@ -68,18 +81,39 @@ void Android_OnTouch(int touch_device_id_in, int pointer_finger_id_in, int actio
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
fingerId = (SDL_FingerID)pointer_finger_id_in;
|
fingerId = (SDL_FingerID)pointer_finger_id_in;
|
||||||
switch (action) {
|
switch (action) {
|
||||||
case ACTION_DOWN:
|
case ACTION_DOWN:
|
||||||
case ACTION_POINTER_1_DOWN:
|
case ACTION_POINTER_1_DOWN:
|
||||||
|
if (!leftFingerDown) {
|
||||||
|
Android_GetWindowCoordinates(x, y, &window_x, &window_y);
|
||||||
|
|
||||||
|
/* send moved event */
|
||||||
|
SDL_SendMouseMotion(NULL, 0, window_x, window_y);
|
||||||
|
|
||||||
|
/* send mouse down event */
|
||||||
|
SDL_SendMouseButton(NULL, SDL_PRESSED, SDL_BUTTON_LEFT);
|
||||||
|
|
||||||
|
leftFingerDown = fingerId;
|
||||||
|
}
|
||||||
SDL_SendFingerDown(touchDeviceId, fingerId, SDL_TRUE, x, y, p);
|
SDL_SendFingerDown(touchDeviceId, fingerId, SDL_TRUE, x, y, p);
|
||||||
break;
|
break;
|
||||||
case ACTION_MOVE:
|
case ACTION_MOVE:
|
||||||
|
if (!leftFingerDown) {
|
||||||
|
Android_GetWindowCoordinates(x, y, &window_x, &window_y);
|
||||||
|
|
||||||
|
/* send moved event */
|
||||||
|
SDL_SendMouseMotion(NULL, 0, window_x, window_y);
|
||||||
|
}
|
||||||
SDL_SendTouchMotion(touchDeviceId, fingerId, SDL_FALSE, x, y, p);
|
SDL_SendTouchMotion(touchDeviceId, fingerId, SDL_FALSE, x, y, p);
|
||||||
break;
|
break;
|
||||||
case ACTION_UP:
|
case ACTION_UP:
|
||||||
case ACTION_POINTER_1_UP:
|
case ACTION_POINTER_1_UP:
|
||||||
|
if (fingerId == leftFingerDown) {
|
||||||
|
/* send mouse up */
|
||||||
|
SDL_SendMouseButton(NULL, SDL_RELEASED, SDL_BUTTON_LEFT);
|
||||||
|
leftFingerDown = 0;
|
||||||
|
}
|
||||||
SDL_SendFingerDown(touchDeviceId, fingerId, SDL_FALSE, x, y, p);
|
SDL_SendFingerDown(touchDeviceId, fingerId, SDL_FALSE, x, y, p);
|
||||||
break;
|
break;
|
||||||
default:
|
default:
|
||||||
|
|
|
@ -50,6 +50,10 @@ Android_CreateWindow(_THIS, SDL_Window * window)
|
||||||
window->flags |= SDL_WINDOW_SHOWN; /* only one window on Android */
|
window->flags |= SDL_WINDOW_SHOWN; /* only one window on Android */
|
||||||
window->flags |= SDL_WINDOW_INPUT_FOCUS; /* always has input focus */
|
window->flags |= SDL_WINDOW_INPUT_FOCUS; /* always has input focus */
|
||||||
|
|
||||||
|
/* One window, it always has focus */
|
||||||
|
SDL_SetMouseFocus(window);
|
||||||
|
//SDL_SetKeyboardFocus(window);
|
||||||
|
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue