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

Commit

Permalink
A bit of cleanup in the Android driver
Browse files Browse the repository at this point in the history
  • Loading branch information
slouken committed Jan 12, 2011
1 parent 6deb4b2 commit 40229d4
Show file tree
Hide file tree
Showing 8 changed files with 97 additions and 89 deletions.
6 changes: 0 additions & 6 deletions android-project/src/org/libsdl/app/SDLActivity.java
Expand Up @@ -158,12 +158,6 @@ else if(featureid == FEATURE_ACCEL){
}
}
}







}

Expand Down
20 changes: 10 additions & 10 deletions src/SDL_android.cpp
Expand Up @@ -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
*******************************************************************************/
Expand All @@ -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;
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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(
Expand Down Expand Up @@ -228,4 +229,3 @@ extern "C" void Android_UpdateAudioBuffer(unsigned char *buf, int len)
__android_log_print(ANDROID_LOG_INFO, "SDL", "SDL: invoked\n");

}

48 changes: 1 addition & 47 deletions src/video/android/SDL_androidevents.c
Expand Up @@ -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: */
1 change: 0 additions & 1 deletion src/video/android/SDL_androidevents.h
Expand Up @@ -24,6 +24,5 @@
#include "SDL_androidvideo.h"

extern void Android_PumpEvents(_THIS);
extern void Android_InitEvents();

/* vi: set ts=4 sw=4 expandtab: */
15 changes: 1 addition & 14 deletions src/video/android/SDL_androidgl.c
Expand Up @@ -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>

Expand All @@ -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;
Expand Down
52 changes: 52 additions & 0 deletions 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: */
30 changes: 30 additions & 0 deletions 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: */
14 changes: 3 additions & 11 deletions src/video/android/SDL_androidvideo.c
Expand Up @@ -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) */
Expand Down Expand Up @@ -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 */
Expand Down Expand Up @@ -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)
{
Expand All @@ -160,5 +153,4 @@ void Android_SetScreenResolution(int width, int height){
}



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

0 comments on commit 40229d4

Please sign in to comment.