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

Commit

Permalink
Added resize hander stub and initial screen size setter
Browse files Browse the repository at this point in the history
  • Loading branch information
bieh committed Jul 27, 2010
1 parent e61a95e commit b788f09
Show file tree
Hide file tree
Showing 5 changed files with 76 additions and 18 deletions.
57 changes: 42 additions & 15 deletions android/testproject/jni/app-android.cpp
Expand Up @@ -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
Expand All @@ -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;
Expand Down Expand Up @@ -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);
Expand All @@ -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);
Expand All @@ -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 ){

Expand All @@ -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);
}



/*******************************************************************************
Expand Down
2 changes: 1 addition & 1 deletion android/testproject/jni/lesson05.c
Expand Up @@ -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 */
Expand Down
14 changes: 14 additions & 0 deletions android/testproject/src/org/libsdl/android/SDLActivity.java
Expand Up @@ -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);



Expand Down Expand Up @@ -95,6 +97,8 @@ class SDLRunner implements Runnable{
public void run(){
//Runs SDL_main()
SDLActivity.nativeInit();

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

Expand Down Expand Up @@ -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();
}
Expand All @@ -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
Expand Down
5 changes: 5 additions & 0 deletions src/video/android/SDL_androidevents.c
Expand Up @@ -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);
Expand Down
16 changes: 14 additions & 2 deletions src/video/android/SDL_androidvideo.c
Expand Up @@ -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)
{
Expand Down Expand Up @@ -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) {
Expand Down Expand Up @@ -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.