Skip to content
This repository has been archived by the owner. It is now read-only.
Permalink
Browse files

Added resize hander stub and initial screen size setter

  • Loading branch information
bieh committed Jul 27, 2010
1 parent e61a95e commit b788f098b518ceeadc107351c5525ffd0646197b
@@ -38,6 +38,8 @@ jmethodID midFlipBuffers;
extern "C" int SDL_main();
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();

//If we're not the active app, don't try to render
@@ -47,18 +49,7 @@ bool bRenderingEnabled = false;
Functions called by JNI
*******************************************************************************/

extern "C" void Java_org_libsdl_android_SDLActivity_nativeInit( JNIEnv* env,
jobject obj ){

__android_log_print(ANDROID_LOG_INFO, "SDL", "SDL: Native Init");

mEnv = env;

bRenderingEnabled = true;

SDL_main();
}

//Library init
extern "C" jint JNI_OnLoad(JavaVM* vm, void* reserved){

JNIEnv* env = NULL;
@@ -86,7 +77,21 @@ extern "C" jint JNI_OnLoad(JavaVM* vm, void* reserved){
return JNI_VERSION_1_4;
}

extern "C" void Java_org_libsdl_android_SDLActivity_onNativeKeyDown(JNIEnv* env,
//Start up the SDL app
extern "C" void Java_org_libsdl_android_SDLActivity_nativeInit( JNIEnv* env,
jobject obj ){

__android_log_print(ANDROID_LOG_INFO, "SDL", "SDL: Native Init");

mEnv = env;

bRenderingEnabled = true;

SDL_main();
}

//Keydown
extern "C" void Java_org_libsdl_android_SDLActivity_onNativeKeyDown(JNIEnv* env,
jobject obj, jint keycode){

int r = Android_OnKeyDown(keycode);
@@ -95,7 +100,8 @@ extern "C" void Java_org_libsdl_android_SDLActivity_onNativeKeyDown(JNIEnv* env

}

extern "C" void Java_org_libsdl_android_SDLActivity_onNativeKeyUp(JNIEnv* env,
//Keyup
extern "C" void Java_org_libsdl_android_SDLActivity_onNativeKeyUp(JNIEnv* env,
jobject obj, jint keycode){

int r = Android_OnKeyUp(keycode);
@@ -104,15 +110,19 @@ extern "C" void Java_org_libsdl_android_SDLActivity_onNativeKeyUp(JNIEnv* env,

}

extern "C" void Java_org_libsdl_android_SDLActivity_onNativeTouch(JNIEnv* env,
//Touch
extern "C" void Java_org_libsdl_android_SDLActivity_onNativeTouch(JNIEnv* env,
jobject obj, jint action, jfloat x, jfloat y, jfloat p){

__android_log_print(ANDROID_LOG_INFO, "SDL",
"SDL: native touch event %d @ %f/%f, pressure %f\n",
action, x, y, p);

//TODO: Pass this off to the SDL multitouch stuff

}

//Quit
extern "C" void Java_org_libsdl_android_SDLActivity_nativeQuit( JNIEnv* env,
jobject obj ){

@@ -125,6 +135,23 @@ extern "C" void Java_org_libsdl_android_SDLActivity_nativeQuit( JNIEnv* env,
__android_log_print(ANDROID_LOG_INFO, "SDL", "SDL: Native quit %d", r);
}

//Screen size
extern "C" void Java_org_libsdl_android_SDLActivity_nativeSetScreenSize(
JNIEnv* env, jobject obj, jint width, jint height){

__android_log_print(ANDROID_LOG_INFO, "SDL",
"SDL: Set screen size on init: %d/%d\n", width, height);
Android_SetScreenResolution(width, height);

}

//Resize
extern "C" void Java_org_libsdl_android_SDLActivity_onNativeResize(
JNIEnv* env, jobject obj, jint width,
jint height, jint format){
Android_OnResize(width, height, format);
}



/*******************************************************************************
@@ -27,7 +27,7 @@

/* screen width, height, and bit depth */
#define SCREEN_WIDTH 320
#define SCREEN_HEIGHT 480
#define SCREEN_HEIGHT 430
#define SCREEN_BPP 16

/* Define our booleans */
@@ -62,10 +62,12 @@ protected void onResume() {
//C functions we call
public static native void nativeInit();
public static native void nativeQuit();
public static native void nativeSetScreenSize(int width, int height);
public static native void onNativeKeyDown(int keycode);
public static native void onNativeKeyUp(int keycode);
public static native void onNativeTouch(int action, float x,
float y, float p);
public static native void onNativeResize(int x, int y, int format);



@@ -95,6 +97,8 @@ Simple nativeInit() runnable
public void run(){
//Runs SDL_main()
SDLActivity.nativeInit();

Log.v("SDL","SDL thread terminated");
}
}

@@ -132,6 +136,14 @@ public SDLSurface(Context context) {
public void surfaceCreated(SurfaceHolder holder) {
Log.v("SDL","Surface created");

int width = getWidth();
int height = getHeight();

//Set the width and height variables in C before we start SDL so we have
//it available on init
SDLActivity.nativeSetScreenSize(width, height);

//Now start up the C app thread
mSDLThread = new Thread(new SDLRunner(), "SDLThread");
mSDLThread.start();
}
@@ -147,6 +159,8 @@ public void surfaceDestroyed(SurfaceHolder holder) {
public void surfaceChanged(SurfaceHolder holder, int format,
int width, int height) {
Log.v("SDL","Surface resized");

SDLActivity.onNativeResize(width, height, format);
}

//unused
@@ -67,6 +67,11 @@ Android_PumpEvents(_THIS)
*/
}


void Android_OnResize(int width, int height, int format){

}

int
Android_OnKeyDown(int keycode){
return SDL_SendKeyboardKey(0, SDL_PRESSED, (SDL_scancode)keycode);
@@ -57,6 +57,12 @@ extern void Android_GL_DeleteContext(_THIS, SDL_GLContext context);
/* Android driver bootstrap functions */


//These are filled in with real values in Android_SetScreenResolution on
//init (before SDL_Main())
static int iScreenWidth = 320;
static int iScreenHeight = 240;


static int
Android_Available(void)
{
@@ -120,8 +126,8 @@ Android_VideoInit(_THIS)

/* Use a fake 32-bpp desktop mode */
mode.format = SDL_PIXELFORMAT_RGB888;
mode.w = 320;
mode.h = 480;
mode.w = iScreenWidth;
mode.h = iScreenHeight;
mode.refresh_rate = 0;
mode.driverdata = NULL;
if (SDL_AddBasicVideoDisplay(&mode) < 0) {
@@ -150,5 +156,11 @@ Android_VideoQuit(_THIS)
}


void Android_SetScreenResolution(int width, int height){
iScreenWidth = width;
iScreenHeight = height;
}



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

0 comments on commit b788f09

Please sign in to comment.