changeset 4980:d9fdff945ec9

A bit of cleanup in the Android driver
author Sam Lantinga <slouken@libsdl.org>
date Wed, 12 Jan 2011 13:52:41 -0800
parents be4ba07d9867
children 55b82067815b
files android-project/src/org/libsdl/app/SDLActivity.java src/SDL_android.cpp src/video/android/SDL_androidevents.c src/video/android/SDL_androidevents.h src/video/android/SDL_androidgl.c src/video/android/SDL_androidkeyboard.c src/video/android/SDL_androidkeyboard.h src/video/android/SDL_androidvideo.c
diffstat 8 files changed, 97 insertions(+), 89 deletions(-) [+]
line wrap: on
line diff
--- a/android-project/src/org/libsdl/app/SDLActivity.java	Wed Jan 12 13:52:27 2011 -0800
+++ b/android-project/src/org/libsdl/app/SDLActivity.java	Wed Jan 12 13:52:41 2011 -0800
@@ -158,12 +158,6 @@
             }
         }
     }
-
-
-
-
-
-    
     
 }
 
--- a/src/SDL_android.cpp	Wed Jan 12 13:52:27 2011 -0800
+++ b/src/SDL_android.cpp	Wed Jan 12 13:52:41 2011 -0800
@@ -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 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 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 @@
                                         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 @@
     __android_log_print(ANDROID_LOG_INFO, "SDL", "SDL: invoked\n");
     
 }
-
--- a/src/video/android/SDL_androidevents.c	Wed Jan 12 13:52:27 2011 -0800
+++ b/src/video/android/SDL_androidevents.c	Wed Jan 12 13:52:41 2011 -0800
@@ -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 <stdio.h>
-#include <stdlib.h>
-
-#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: */
--- a/src/video/android/SDL_androidevents.h	Wed Jan 12 13:52:27 2011 -0800
+++ b/src/video/android/SDL_androidevents.h	Wed Jan 12 13:52:41 2011 -0800
@@ -24,6 +24,5 @@
 #include "SDL_androidvideo.h"
 
 extern void Android_PumpEvents(_THIS);
-extern void Android_InitEvents();
 
 /* vi: set ts=4 sw=4 expandtab: */
--- a/src/video/android/SDL_androidgl.c	Wed Jan 12 13:52:27 2011 -0800
+++ b/src/video/android/SDL_androidgl.c	Wed Jan 12 13:52:41 2011 -0800
@@ -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 <android/log.h>
 
@@ -58,13 +52,6 @@
 	__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;
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/src/video/android/SDL_androidkeyboard.c	Wed Jan 12 13:52:41 2011 -0800
@@ -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: */
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/src/video/android/SDL_androidkeyboard.h	Wed Jan 12 13:52:41 2011 -0800
@@ -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: */
--- a/src/video/android/SDL_androidvideo.c	Wed Jan 12 13:52:27 2011 -0800
+++ b/src/video/android/SDL_androidvideo.c	Wed Jan 12 13:52:41 2011 -0800
@@ -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 @@
     /* 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 @@
     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 @@
 }
 
 
-
 /* vi: set ts=4 sw=4 expandtab: */