Added "mouse" support for the Android touch screen
This commit is contained in:
parent
70c916a415
commit
cab4e0652a
7 changed files with 108 additions and 8 deletions
|
@ -26,6 +26,7 @@
|
||||||
extern "C" {
|
extern "C" {
|
||||||
#include "events/SDL_events_c.h"
|
#include "events/SDL_events_c.h"
|
||||||
#include "video/android/SDL_androidkeyboard.h"
|
#include "video/android/SDL_androidkeyboard.h"
|
||||||
|
#include "video/android/SDL_androidtouch.h"
|
||||||
#include "video/android/SDL_androidvideo.h"
|
#include "video/android/SDL_androidvideo.h"
|
||||||
|
|
||||||
/* Impelemented in audio/android/SDL_androidaudio.c */
|
/* Impelemented in audio/android/SDL_androidaudio.c */
|
||||||
|
@ -124,13 +125,7 @@ extern "C" void Java_org_libsdl_app_SDLActivity_onNativeTouch(
|
||||||
JNIEnv* env, jclass jcls,
|
JNIEnv* env, jclass jcls,
|
||||||
jint action, jfloat x, jfloat y, jfloat p)
|
jint action, jfloat x, jfloat y, jfloat p)
|
||||||
{
|
{
|
||||||
#ifdef DEBUG
|
Android_OnTouch(action, x, y, p);
|
||||||
__android_log_print(ANDROID_LOG_INFO, "SDL",
|
|
||||||
"SDL: native touch event %d @ %f/%f, pressure %f\n",
|
|
||||||
action, x, y, p);
|
|
||||||
#endif
|
|
||||||
|
|
||||||
//TODO: Pass this off to the SDL multitouch stuff
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// Accelerometer
|
// Accelerometer
|
||||||
|
|
|
@ -26,7 +26,7 @@
|
||||||
|
|
||||||
struct SDL_Cursor
|
struct SDL_Cursor
|
||||||
{
|
{
|
||||||
SDL_Cursor *next;
|
struct SDL_Cursor *next;
|
||||||
void *driverdata;
|
void *driverdata;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
60
src/video/android/SDL_androidtouch.c
Normal file
60
src/video/android/SDL_androidtouch.c
Normal file
|
@ -0,0 +1,60 @@
|
||||||
|
/*
|
||||||
|
SDL - Simple DirectMedia Layer
|
||||||
|
Copyright (C) 1997-2010 Sam Lantinga
|
||||||
|
|
||||||
|
This library is free software; you can redistribute it and/or
|
||||||
|
modify it under the terms of the GNU Lesser General Public
|
||||||
|
License as published by the Free Software Foundation; either
|
||||||
|
version 2.1 of the License, or (at your option) any later version.
|
||||||
|
|
||||||
|
This library is distributed in the hope that it will be useful,
|
||||||
|
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||||
|
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
||||||
|
Lesser General Public License for more details.
|
||||||
|
|
||||||
|
You should have received a copy of the GNU Lesser General Public
|
||||||
|
License along with this library; if not, write to the Free Software
|
||||||
|
Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
|
||||||
|
|
||||||
|
Sam Lantinga
|
||||||
|
slouken@libsdl.org
|
||||||
|
*/
|
||||||
|
#include "SDL_config.h"
|
||||||
|
|
||||||
|
#include <android/log.h>
|
||||||
|
|
||||||
|
#include "SDL_events.h"
|
||||||
|
#include "../../events/SDL_mouse_c.h"
|
||||||
|
|
||||||
|
#include "SDL_androidtouch.h"
|
||||||
|
|
||||||
|
|
||||||
|
#define ACTION_DOWN 0
|
||||||
|
#define ACTION_UP 1
|
||||||
|
#define ACTION_MOVE 2
|
||||||
|
#define ACTION_CANCEL 3
|
||||||
|
#define ACTION_OUTSIDE 4
|
||||||
|
|
||||||
|
void Android_OnTouch(int action, float x, float y, float p)
|
||||||
|
{
|
||||||
|
if (!Android_Window) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
if ((action != ACTION_CANCEL) && (action != ACTION_OUTSIDE)) {
|
||||||
|
SDL_SetMouseFocus(Android_Window);
|
||||||
|
SDL_SendMouseMotion(Android_Window, 0, (int)x, (int)y);
|
||||||
|
switch(action) {
|
||||||
|
case ACTION_DOWN:
|
||||||
|
SDL_SendMouseButton(Android_Window, SDL_PRESSED, SDL_BUTTON_LEFT);
|
||||||
|
break;
|
||||||
|
case ACTION_UP:
|
||||||
|
SDL_SendMouseButton(Android_Window, SDL_RELEASED, SDL_BUTTON_LEFT);
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
SDL_SetMouseFocus(NULL);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/* vi: set ts=4 sw=4 expandtab: */
|
28
src/video/android/SDL_androidtouch.h
Normal file
28
src/video/android/SDL_androidtouch.h
Normal file
|
@ -0,0 +1,28 @@
|
||||||
|
/*
|
||||||
|
SDL - Simple DirectMedia Layer
|
||||||
|
Copyright (C) 1997-2010 Sam Lantinga
|
||||||
|
|
||||||
|
This library is free software; you can redistribute it and/or
|
||||||
|
modify it under the terms of the GNU Lesser General Public
|
||||||
|
License as published by the Free Software Foundation; either
|
||||||
|
version 2.1 of the License, or (at your option) any later version.
|
||||||
|
|
||||||
|
This library is distributed in the hope that it will be useful,
|
||||||
|
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||||
|
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
||||||
|
Lesser General Public License for more details.
|
||||||
|
|
||||||
|
You should have received a copy of the GNU Lesser General Public
|
||||||
|
License along with this library; if not, write to the Free Software
|
||||||
|
Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
|
||||||
|
|
||||||
|
Sam Lantinga
|
||||||
|
slouken@libsdl.org
|
||||||
|
*/
|
||||||
|
#include "SDL_config.h"
|
||||||
|
|
||||||
|
#include "SDL_androidvideo.h"
|
||||||
|
|
||||||
|
extern void Android_OnTouch(int action, float x, float y, float p);
|
||||||
|
|
||||||
|
/* vi: set ts=4 sw=4 expandtab: */
|
|
@ -29,6 +29,7 @@
|
||||||
#include "../SDL_sysvideo.h"
|
#include "../SDL_sysvideo.h"
|
||||||
#include "../SDL_pixels_c.h"
|
#include "../SDL_pixels_c.h"
|
||||||
#include "../../events/SDL_events_c.h"
|
#include "../../events/SDL_events_c.h"
|
||||||
|
#include "../../events/SDL_windowevents_c.h"
|
||||||
|
|
||||||
#include "SDL_androidvideo.h"
|
#include "SDL_androidvideo.h"
|
||||||
#include "SDL_androidevents.h"
|
#include "SDL_androidevents.h"
|
||||||
|
@ -63,6 +64,8 @@ int Android_ScreenWidth = 0;
|
||||||
int Android_ScreenHeight = 0;
|
int Android_ScreenHeight = 0;
|
||||||
Uint32 Android_ScreenFormat = SDL_PIXELFORMAT_UNKNOWN;
|
Uint32 Android_ScreenFormat = SDL_PIXELFORMAT_UNKNOWN;
|
||||||
|
|
||||||
|
/* Currently only one window */
|
||||||
|
SDL_Window *Android_Window = NULL;
|
||||||
|
|
||||||
static int
|
static int
|
||||||
Android_Available(void)
|
Android_Available(void)
|
||||||
|
@ -158,6 +161,10 @@ Android_SetScreenResolution(int width, int height, Uint32 format)
|
||||||
Android_ScreenWidth = width;
|
Android_ScreenWidth = width;
|
||||||
Android_ScreenHeight = height;
|
Android_ScreenHeight = height;
|
||||||
Android_ScreenFormat = format;
|
Android_ScreenFormat = format;
|
||||||
|
|
||||||
|
if (Android_Window) {
|
||||||
|
SDL_SendWindowEvent(Android_Window, SDL_WINDOWEVENT_RESIZED, width, height);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/* vi: set ts=4 sw=4 expandtab: */
|
/* vi: set ts=4 sw=4 expandtab: */
|
||||||
|
|
|
@ -34,6 +34,7 @@ extern void Android_SetScreenResolution(int width, int height, Uint32 format);
|
||||||
extern int Android_ScreenWidth;
|
extern int Android_ScreenWidth;
|
||||||
extern int Android_ScreenHeight;
|
extern int Android_ScreenHeight;
|
||||||
extern Uint32 Android_ScreenFormat;
|
extern Uint32 Android_ScreenFormat;
|
||||||
|
extern SDL_Window *Android_Window;
|
||||||
|
|
||||||
#endif /* _SDL_androidvideo_h */
|
#endif /* _SDL_androidvideo_h */
|
||||||
|
|
||||||
|
|
|
@ -29,6 +29,12 @@
|
||||||
int
|
int
|
||||||
Android_CreateWindow(_THIS, SDL_Window * window)
|
Android_CreateWindow(_THIS, SDL_Window * window)
|
||||||
{
|
{
|
||||||
|
if (Android_Window) {
|
||||||
|
SDL_SetError("Android only supports one window");
|
||||||
|
return -1;
|
||||||
|
}
|
||||||
|
Android_Window = window;
|
||||||
|
|
||||||
/* Adjust the window data to match the screen */
|
/* Adjust the window data to match the screen */
|
||||||
window->x = 0;
|
window->x = 0;
|
||||||
window->y = 0;
|
window->y = 0;
|
||||||
|
@ -47,6 +53,9 @@ Android_SetWindowTitle(_THIS, SDL_Window * window)
|
||||||
void
|
void
|
||||||
Android_DestroyWindow(_THIS, SDL_Window * window)
|
Android_DestroyWindow(_THIS, SDL_Window * window)
|
||||||
{
|
{
|
||||||
|
if (window == Android_Window) {
|
||||||
|
Android_Window = NULL;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/* vi: set ts=4 sw=4 expandtab: */
|
/* vi: set ts=4 sw=4 expandtab: */
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue