changeset 4716:f2c2a33a1a38

Added resize hander stub and initial screen size setter
author Paul Hunkin <paul@bieh.net>
date Tue, 27 Jul 2010 10:49:11 +0200
parents 9bb98766eed0
children 191f4693d0c1
files android/testproject/jni/app-android.cpp android/testproject/jni/lesson05.c android/testproject/src/org/libsdl/android/SDLActivity.java src/video/android/SDL_androidevents.c src/video/android/SDL_androidvideo.c
diffstat 5 files changed, 76 insertions(+), 18 deletions(-) [+]
line wrap: on
line diff
--- a/android/testproject/jni/app-android.cpp	Tue Jul 27 10:20:22 2010 +0200
+++ b/android/testproject/jni/app-android.cpp	Tue Jul 27 10:49:11 2010 +0200
@@ -38,6 +38,8 @@
 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 @@
                  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 @@
     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_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_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 @@
     __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);
+}
+
 
 
 /*******************************************************************************
--- a/android/testproject/jni/lesson05.c	Tue Jul 27 10:20:22 2010 +0200
+++ b/android/testproject/jni/lesson05.c	Tue Jul 27 10:49:11 2010 +0200
@@ -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 */
--- a/android/testproject/src/org/libsdl/android/SDLActivity.java	Tue Jul 27 10:20:22 2010 +0200
+++ b/android/testproject/src/org/libsdl/android/SDLActivity.java	Tue Jul 27 10:49:11 2010 +0200
@@ -62,10 +62,12 @@
     //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 @@
     public void run(){
         //Runs SDL_main()
         SDLActivity.nativeInit();
+
+        Log.v("SDL","SDL thread terminated");
     }
 }
 
@@ -132,6 +136,14 @@
     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 surfaceChanged(SurfaceHolder holder, int format, 
                                 int width, int height) {
         Log.v("SDL","Surface resized");
+        
+        SDLActivity.onNativeResize(width, height, format);
     }
 
     //unused
--- a/src/video/android/SDL_androidevents.c	Tue Jul 27 10:20:22 2010 +0200
+++ b/src/video/android/SDL_androidevents.c	Tue Jul 27 10:49:11 2010 +0200
@@ -67,6 +67,11 @@
     */
 }
 
+
+void Android_OnResize(int width, int height, int format){
+
+}
+
 int
 Android_OnKeyDown(int keycode){
     return SDL_SendKeyboardKey(0, SDL_PRESSED, (SDL_scancode)keycode);
--- a/src/video/android/SDL_androidvideo.c	Tue Jul 27 10:20:22 2010 +0200
+++ b/src/video/android/SDL_androidvideo.c	Tue Jul 27 10:49:11 2010 +0200
@@ -57,6 +57,12 @@
 /* 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 @@
 
     /* 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 @@
 }
 
 
+void Android_SetScreenResolution(int width, int height){
+    iScreenWidth = width;
+    iScreenHeight = height;   
+}
+
+
 
 /* vi: set ts=4 sw=4 expandtab: */