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

Commit

Permalink
Added "mouse" support for the Android touch screen
Browse files Browse the repository at this point in the history
  • Loading branch information
slouken committed Jan 14, 2011
1 parent 7635c27 commit 6dc0cc9
Show file tree
Hide file tree
Showing 7 changed files with 108 additions and 8 deletions.
9 changes: 2 additions & 7 deletions src/SDL_android.cpp
Expand Up @@ -26,6 +26,7 @@
extern "C" {
#include "events/SDL_events_c.h"
#include "video/android/SDL_androidkeyboard.h"
#include "video/android/SDL_androidtouch.h"
#include "video/android/SDL_androidvideo.h"

/* Impelemented in audio/android/SDL_androidaudio.c */
Expand Down Expand Up @@ -124,13 +125,7 @@ extern "C" void Java_org_libsdl_app_SDLActivity_onNativeTouch(
JNIEnv* env, jclass jcls,
jint action, jfloat x, jfloat y, jfloat p)
{
#ifdef DEBUG
__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
Android_OnTouch(action, x, y, p);
}

// Accelerometer
Expand Down
2 changes: 1 addition & 1 deletion src/events/SDL_mouse_c.h
Expand Up @@ -26,7 +26,7 @@

struct SDL_Cursor
{
SDL_Cursor *next;
struct SDL_Cursor *next;
void *driverdata;
};

Expand Down
60 changes: 60 additions & 0 deletions src/video/android/SDL_androidtouch.c
@@ -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 changes: 28 additions & 0 deletions src/video/android/SDL_androidtouch.h
@@ -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: */
7 changes: 7 additions & 0 deletions src/video/android/SDL_androidvideo.c
Expand Up @@ -29,6 +29,7 @@
#include "../SDL_sysvideo.h"
#include "../SDL_pixels_c.h"
#include "../../events/SDL_events_c.h"
#include "../../events/SDL_windowevents_c.h"

#include "SDL_androidvideo.h"
#include "SDL_androidevents.h"
Expand Down Expand Up @@ -63,6 +64,8 @@ int Android_ScreenWidth = 0;
int Android_ScreenHeight = 0;
Uint32 Android_ScreenFormat = SDL_PIXELFORMAT_UNKNOWN;

/* Currently only one window */
SDL_Window *Android_Window = NULL;

static int
Android_Available(void)
Expand Down Expand Up @@ -158,6 +161,10 @@ Android_SetScreenResolution(int width, int height, Uint32 format)
Android_ScreenWidth = width;
Android_ScreenHeight = height;
Android_ScreenFormat = format;

if (Android_Window) {
SDL_SendWindowEvent(Android_Window, SDL_WINDOWEVENT_RESIZED, width, height);
}
}

/* vi: set ts=4 sw=4 expandtab: */
1 change: 1 addition & 0 deletions src/video/android/SDL_androidvideo.h
Expand Up @@ -34,6 +34,7 @@ extern void Android_SetScreenResolution(int width, int height, Uint32 format);
extern int Android_ScreenWidth;
extern int Android_ScreenHeight;
extern Uint32 Android_ScreenFormat;
extern SDL_Window *Android_Window;

#endif /* _SDL_androidvideo_h */

Expand Down
9 changes: 9 additions & 0 deletions src/video/android/SDL_androidwindow.c
Expand Up @@ -29,6 +29,12 @@
int
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 */
window->x = 0;
window->y = 0;
Expand All @@ -47,6 +53,9 @@ Android_SetWindowTitle(_THIS, SDL_Window * window)
void
Android_DestroyWindow(_THIS, SDL_Window * window)
{
if (window == Android_Window) {
Android_Window = NULL;
}
}

/* vi: set ts=4 sw=4 expandtab: */

0 comments on commit 6dc0cc9

Please sign in to comment.