Commit 088b7581 authored by Paul Hunkin's avatar Paul Hunkin

Added resize hander stub and initial screen size setter

parent 27d80262
...@@ -38,6 +38,8 @@ jmethodID midFlipBuffers; ...@@ -38,6 +38,8 @@ jmethodID midFlipBuffers;
extern "C" int SDL_main(); extern "C" int SDL_main();
extern "C" int Android_OnKeyDown(int keycode); extern "C" int Android_OnKeyDown(int keycode);
extern "C" int Android_OnKeyUp(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" int SDL_SendQuit();
//If we're not the active app, don't try to render //If we're not the active app, don't try to render
...@@ -47,18 +49,7 @@ bool bRenderingEnabled = false; ...@@ -47,18 +49,7 @@ bool bRenderingEnabled = false;
Functions called by JNI Functions called by JNI
*******************************************************************************/ *******************************************************************************/
extern "C" void Java_org_libsdl_android_SDLActivity_nativeInit( JNIEnv* env, //Library init
jobject obj ){
__android_log_print(ANDROID_LOG_INFO, "SDL", "SDL: Native Init");
mEnv = env;
bRenderingEnabled = true;
SDL_main();
}
extern "C" jint JNI_OnLoad(JavaVM* vm, void* reserved){ extern "C" jint JNI_OnLoad(JavaVM* vm, void* reserved){
JNIEnv* env = NULL; JNIEnv* env = NULL;
...@@ -86,6 +77,20 @@ extern "C" jint JNI_OnLoad(JavaVM* vm, void* reserved){ ...@@ -86,6 +77,20 @@ extern "C" jint JNI_OnLoad(JavaVM* vm, void* reserved){
return JNI_VERSION_1_4; return JNI_VERSION_1_4;
} }
//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, extern "C" void Java_org_libsdl_android_SDLActivity_onNativeKeyDown(JNIEnv* env,
jobject obj, jint keycode){ jobject obj, jint keycode){
...@@ -95,6 +100,7 @@ extern "C" void Java_org_libsdl_android_SDLActivity_onNativeKeyDown(JNIEnv* env ...@@ -95,6 +100,7 @@ extern "C" void Java_org_libsdl_android_SDLActivity_onNativeKeyDown(JNIEnv* env
} }
//Keyup
extern "C" void Java_org_libsdl_android_SDLActivity_onNativeKeyUp(JNIEnv* env, extern "C" void Java_org_libsdl_android_SDLActivity_onNativeKeyUp(JNIEnv* env,
jobject obj, jint keycode){ jobject obj, jint keycode){
...@@ -104,6 +110,7 @@ extern "C" void Java_org_libsdl_android_SDLActivity_onNativeKeyUp(JNIEnv* env, ...@@ -104,6 +110,7 @@ extern "C" void Java_org_libsdl_android_SDLActivity_onNativeKeyUp(JNIEnv* env,
} }
//Touch
extern "C" void Java_org_libsdl_android_SDLActivity_onNativeTouch(JNIEnv* env, extern "C" void Java_org_libsdl_android_SDLActivity_onNativeTouch(JNIEnv* env,
jobject obj, jint action, jfloat x, jfloat y, jfloat p){ jobject obj, jint action, jfloat x, jfloat y, jfloat p){
...@@ -111,8 +118,11 @@ extern "C" void Java_org_libsdl_android_SDLActivity_onNativeTouch(JNIEnv* env, ...@@ -111,8 +118,11 @@ extern "C" void Java_org_libsdl_android_SDLActivity_onNativeTouch(JNIEnv* env,
"SDL: native touch event %d @ %f/%f, pressure %f\n", "SDL: native touch event %d @ %f/%f, pressure %f\n",
action, x, y, p); 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, extern "C" void Java_org_libsdl_android_SDLActivity_nativeQuit( JNIEnv* env,
jobject obj ){ jobject obj ){
...@@ -125,6 +135,23 @@ extern "C" void Java_org_libsdl_android_SDLActivity_nativeQuit( JNIEnv* env, ...@@ -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); __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 @@ ...@@ -27,7 +27,7 @@
/* screen width, height, and bit depth */ /* screen width, height, and bit depth */
#define SCREEN_WIDTH 320 #define SCREEN_WIDTH 320
#define SCREEN_HEIGHT 480 #define SCREEN_HEIGHT 430
#define SCREEN_BPP 16 #define SCREEN_BPP 16
/* Define our booleans */ /* Define our booleans */
......
...@@ -62,10 +62,12 @@ public class SDLActivity extends Activity { ...@@ -62,10 +62,12 @@ public class SDLActivity extends Activity {
//C functions we call //C functions we call
public static native void nativeInit(); public static native void nativeInit();
public static native void nativeQuit(); 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 onNativeKeyDown(int keycode);
public static native void onNativeKeyUp(int keycode); public static native void onNativeKeyUp(int keycode);
public static native void onNativeTouch(int action, float x, public static native void onNativeTouch(int action, float x,
float y, float p); float y, float p);
public static native void onNativeResize(int x, int y, int format);
...@@ -95,6 +97,8 @@ class SDLRunner implements Runnable{ ...@@ -95,6 +97,8 @@ class SDLRunner implements Runnable{
public void run(){ public void run(){
//Runs SDL_main() //Runs SDL_main()
SDLActivity.nativeInit(); SDLActivity.nativeInit();
Log.v("SDL","SDL thread terminated");
} }
} }
...@@ -132,6 +136,14 @@ class SDLSurface extends SurfaceView implements SurfaceHolder.Callback, ...@@ -132,6 +136,14 @@ class SDLSurface extends SurfaceView implements SurfaceHolder.Callback,
public void surfaceCreated(SurfaceHolder holder) { public void surfaceCreated(SurfaceHolder holder) {
Log.v("SDL","Surface created"); 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 = new Thread(new SDLRunner(), "SDLThread");
mSDLThread.start(); mSDLThread.start();
} }
...@@ -147,6 +159,8 @@ class SDLSurface extends SurfaceView implements SurfaceHolder.Callback, ...@@ -147,6 +159,8 @@ class SDLSurface extends SurfaceView implements SurfaceHolder.Callback,
public void surfaceChanged(SurfaceHolder holder, int format, public void surfaceChanged(SurfaceHolder holder, int format,
int width, int height) { int width, int height) {
Log.v("SDL","Surface resized"); Log.v("SDL","Surface resized");
SDLActivity.onNativeResize(width, height, format);
} }
//unused //unused
......
...@@ -67,6 +67,11 @@ Android_PumpEvents(_THIS) ...@@ -67,6 +67,11 @@ Android_PumpEvents(_THIS)
*/ */
} }
void Android_OnResize(int width, int height, int format){
}
int int
Android_OnKeyDown(int keycode){ Android_OnKeyDown(int keycode){
return SDL_SendKeyboardKey(0, SDL_PRESSED, (SDL_scancode)keycode); return SDL_SendKeyboardKey(0, SDL_PRESSED, (SDL_scancode)keycode);
......
...@@ -57,6 +57,12 @@ extern void Android_GL_DeleteContext(_THIS, SDL_GLContext context); ...@@ -57,6 +57,12 @@ extern void Android_GL_DeleteContext(_THIS, SDL_GLContext context);
/* Android driver bootstrap functions */ /* 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 static int
Android_Available(void) Android_Available(void)
{ {
...@@ -120,8 +126,8 @@ Android_VideoInit(_THIS) ...@@ -120,8 +126,8 @@ Android_VideoInit(_THIS)
/* Use a fake 32-bpp desktop mode */ /* Use a fake 32-bpp desktop mode */
mode.format = SDL_PIXELFORMAT_RGB888; mode.format = SDL_PIXELFORMAT_RGB888;
mode.w = 320; mode.w = iScreenWidth;
mode.h = 480; mode.h = iScreenHeight;
mode.refresh_rate = 0; mode.refresh_rate = 0;
mode.driverdata = NULL; mode.driverdata = NULL;
if (SDL_AddBasicVideoDisplay(&mode) < 0) { if (SDL_AddBasicVideoDisplay(&mode) < 0) {
...@@ -150,5 +156,11 @@ Android_VideoQuit(_THIS) ...@@ -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: */ /* vi: set ts=4 sw=4 expandtab: */
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment