From 40229d440fc16174925e00e6fee937e22560133f Mon Sep 17 00:00:00 2001 From: Sam Lantinga Date: Wed, 12 Jan 2011 13:52:41 -0800 Subject: [PATCH] A bit of cleanup in the Android driver --- .../src/org/libsdl/app/SDLActivity.java | 6 --- src/SDL_android.cpp | 20 +++---- src/video/android/SDL_androidevents.c | 48 +---------------- src/video/android/SDL_androidevents.h | 1 - src/video/android/SDL_androidgl.c | 15 +----- src/video/android/SDL_androidkeyboard.c | 52 +++++++++++++++++++ src/video/android/SDL_androidkeyboard.h | 30 +++++++++++ src/video/android/SDL_androidvideo.c | 14 ++--- 8 files changed, 97 insertions(+), 89 deletions(-) create mode 100644 src/video/android/SDL_androidkeyboard.c create mode 100644 src/video/android/SDL_androidkeyboard.h diff --git a/android-project/src/org/libsdl/app/SDLActivity.java b/android-project/src/org/libsdl/app/SDLActivity.java index dff571f91..c902d107c 100644 --- a/android-project/src/org/libsdl/app/SDLActivity.java +++ b/android-project/src/org/libsdl/app/SDLActivity.java @@ -158,12 +158,6 @@ else if(featureid == FEATURE_ACCEL){ } } } - - - - - - } diff --git a/src/SDL_android.cpp b/src/SDL_android.cpp index de76a22d2..1af915c3d 100644 --- a/src/SDL_android.cpp +++ b/src/SDL_android.cpp @@ -21,6 +21,11 @@ */ #include "SDL_config.h" +extern "C" { +#include "events/SDL_events_c.h" +#include "video/android/SDL_androidkeyboard.h" +} + /******************************************************************************* This file links the Java side of Android with libsdl *******************************************************************************/ @@ -44,12 +49,8 @@ jmethodID midFlipBuffers; jmethodID midEnableFeature; jmethodID midUpdateAudio; -extern "C" int Android_OnKeyDown(int keycode); -extern "C" int Android_OnKeyUp(int keycode); extern "C" void Android_SetScreenResolution(int width, int height); -extern "C" void Android_OnResize(int width, int height, int format); extern "C" int SDL_SendQuit(); -extern "C" void Android_EnableFeature(int featureid, bool enabled); //If we're not the active app, don't try to render bool bRenderingEnabled = false; @@ -102,22 +103,22 @@ extern "C" void SDL_Android_Init(JNIEnv* env) extern "C" void Java_org_libsdl_app_SDLActivity_onNativeKeyDown(JNIEnv* env, jobject obj, jint keycode) { - int r = Android_OnKeyDown(keycode); #ifdef DEBUG __android_log_print(ANDROID_LOG_INFO, "SDL", - "SDL: native key down %d, %d\n", keycode, r); + "SDL: native key down %d\n", keycode); #endif + Android_OnKeyDown(keycode); } // Keyup extern "C" void Java_org_libsdl_app_SDLActivity_onNativeKeyUp(JNIEnv* env, jobject obj, jint keycode) { - int r = Android_OnKeyUp(keycode); #ifdef DEBUG __android_log_print(ANDROID_LOG_INFO, "SDL", - "SDL: native key up %d, %d\n", keycode, r); + "SDL: native key up %d\n", keycode); #endif + Android_OnKeyUp(keycode); } // Touch @@ -158,7 +159,7 @@ extern "C" void Java_org_libsdl_app_SDLActivity_onNativeResize( JNIEnv* env, jobject obj, jint width, jint height, jint format) { - Android_OnResize(width, height, format); + /* FIXME: What is the relationship between this and the window? */ } extern "C" void Java_org_libsdl_app_SDLActivity_onNativeAccel( @@ -228,4 +229,3 @@ extern "C" void Android_UpdateAudioBuffer(unsigned char *buf, int len) __android_log_print(ANDROID_LOG_INFO, "SDL", "SDL: invoked\n"); } - diff --git a/src/video/android/SDL_androidevents.c b/src/video/android/SDL_androidevents.c index e8c836daa..4b45470e7 100644 --- a/src/video/android/SDL_androidevents.c +++ b/src/video/android/SDL_androidevents.c @@ -21,58 +21,12 @@ */ #include "SDL_config.h" -/* Being a null driver, there's no event stream. We just define stubs for - most of the API. */ - -#include -#include - -#include "../../events/SDL_sysevents.h" -#include "../../events/SDL_events_c.h" - #include "SDL_androidevents.h" -void Android_InitEvents() -{ - SDLKey keymap[SDL_NUM_SCANCODES]; - - /* Add default scancode to key mapping */ - SDL_GetDefaultKeymap(keymap); - SDL_SetKeymap(0, keymap, SDL_NUM_SCANCODES); -} - void Android_PumpEvents(_THIS) { - - //scanKeys(); - /* TODO: defer click-age */ - /* - if (keysDown() & KEY_TOUCH) { - SDL_SendMouseButton(0, SDL_PRESSED, 0); - } else if (keysUp() & KEY_TOUCH) { - SDL_SendMouseButton(0, SDL_RELEASED, 0); - } - if (keysHeld() & KEY_TOUCH) { - touchPosition t = touchReadXY(); - SDL_SendMouseMotion(0, 0, t.px, t.py, 1); - } - */ -} - - -void Android_OnResize(int width, int height, int format){ - -} - -int -Android_OnKeyDown(int keycode){ - return SDL_SendKeyboardKey(SDL_PRESSED, (SDL_scancode)keycode); -} - -int -Android_OnKeyUp(int keycode){ - return SDL_SendKeyboardKey(SDL_RELEASED, (SDL_scancode)keycode); + /* No polling necessary */ } /* vi: set ts=4 sw=4 expandtab: */ diff --git a/src/video/android/SDL_androidevents.h b/src/video/android/SDL_androidevents.h index 4a7ba5299..b53b74ebe 100644 --- a/src/video/android/SDL_androidevents.h +++ b/src/video/android/SDL_androidevents.h @@ -24,6 +24,5 @@ #include "SDL_androidvideo.h" extern void Android_PumpEvents(_THIS); -extern void Android_InitEvents(); /* vi: set ts=4 sw=4 expandtab: */ diff --git a/src/video/android/SDL_androidgl.c b/src/video/android/SDL_androidgl.c index 15276b1bb..0007cc4da 100644 --- a/src/video/android/SDL_androidgl.c +++ b/src/video/android/SDL_androidgl.c @@ -21,17 +21,11 @@ */ #include "SDL_config.h" -/* Android SDL video driver implementation -*/ +/* Android SDL video driver implementation */ #include "SDL_video.h" -#include "SDL_mouse.h" -#include "../SDL_sysvideo.h" -#include "../SDL_pixels_c.h" -#include "../../events/SDL_events_c.h" #include "SDL_androidvideo.h" -#include "SDL_androidevents.h" #include @@ -58,13 +52,6 @@ void Android_GL_UnloadLibrary(_THIS){ __android_log_print(ANDROID_LOG_INFO, "SDL", "[STUB] GL_UnloadLibrary\n"); } -/* -int *Android_GL_GetVisual(_THIS, Display * display, int screen){ - __android_log_print(ANDROID_LOG_INFO, "SDL","[STUB] GL_GetVisual\n"); - return 0; -} -*/ - SDL_GLContext Android_GL_CreateContext(_THIS, SDL_Window * window){ Android_CreateContext(); return 1; diff --git a/src/video/android/SDL_androidkeyboard.c b/src/video/android/SDL_androidkeyboard.c new file mode 100644 index 000000000..6efb791e4 --- /dev/null +++ b/src/video/android/SDL_androidkeyboard.c @@ -0,0 +1,52 @@ +/* + 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 "../../events/SDL_events_c.h" + +#include "SDL_androidkeyboard.h" + + +void Android_InitKeyboard() +{ + SDLKey keymap[SDL_NUM_SCANCODES]; + + /* Add default scancode to key mapping */ + SDL_GetDefaultKeymap(keymap); + SDL_SetKeymap(0, keymap, SDL_NUM_SCANCODES); +} + +int +Android_OnKeyDown(int keycode) +{ + /* FIXME: Need conversion from Android keycode to SDL scancode */ + return SDL_SendKeyboardKey(SDL_PRESSED, (SDL_scancode)keycode); +} + +int +Android_OnKeyUp(int keycode) +{ + /* FIXME: Need conversion from Android keycode to SDL scancode */ + return SDL_SendKeyboardKey(SDL_RELEASED, (SDL_scancode)keycode); +} + +/* vi: set ts=4 sw=4 expandtab: */ diff --git a/src/video/android/SDL_androidkeyboard.h b/src/video/android/SDL_androidkeyboard.h new file mode 100644 index 000000000..0b525952f --- /dev/null +++ b/src/video/android/SDL_androidkeyboard.h @@ -0,0 +1,30 @@ +/* + 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_InitKeyboard(); +extern int Android_OnKeyDown(int keycode); +extern int Android_OnKeyUp(int keycode); + +/* vi: set ts=4 sw=4 expandtab: */ diff --git a/src/video/android/SDL_androidvideo.c b/src/video/android/SDL_androidvideo.c index a85307ef7..5994f99bb 100644 --- a/src/video/android/SDL_androidvideo.c +++ b/src/video/android/SDL_androidvideo.c @@ -32,12 +32,12 @@ #include "SDL_androidvideo.h" #include "SDL_androidevents.h" +#include "SDL_androidkeyboard.h" #define ANDROID_VID_DRIVER_NAME "Android" /* Initialization/Query functions */ static int Android_VideoInit(_THIS); -static int Android_SetDisplayMode(_THIS, SDL_VideoDisplay * display, SDL_DisplayMode * mode); static void Android_VideoQuit(_THIS); /* GL functions (SDL_androidgl.c) */ @@ -93,9 +93,8 @@ Android_CreateDevice(int devindex) /* Set the function pointers */ device->VideoInit = Android_VideoInit; device->VideoQuit = Android_VideoQuit; - device->SetDisplayMode = Android_SetDisplayMode; device->PumpEvents = Android_PumpEvents; - + device->free = Android_DeleteDevice; /* GL pointers */ @@ -136,18 +135,12 @@ Android_VideoInit(_THIS) SDL_zero(mode); SDL_AddDisplayMode(&_this->displays[0], &mode); - Android_InitEvents(); + Android_InitKeyboard(); /* We're done! */ return 0; } -static int -Android_SetDisplayMode(_THIS, SDL_VideoDisplay * display, SDL_DisplayMode * mode) -{ - return 0; -} - void Android_VideoQuit(_THIS) { @@ -160,5 +153,4 @@ void Android_SetScreenResolution(int width, int height){ } - /* vi: set ts=4 sw=4 expandtab: */