diff --git a/project/sdl/sdl-1.3/src/video/android/SDL_androidinput.c b/project/sdl/sdl-1.3/src/video/android/SDL_androidinput.c index 675a6a4ca..4a6fc8d16 100644 --- a/project/sdl/sdl-1.3/src/video/android/SDL_androidinput.c +++ b/project/sdl/sdl-1.3/src/video/android/SDL_androidinput.c @@ -30,26 +30,6 @@ #include "SDL_config.h" #include "SDL_version.h" -#include "SDL_video.h" -#include "SDL_mouse.h" -#include "SDL_mutex.h" -#include "SDL_thread.h" -#include "../SDL_sysvideo.h" -#include "../SDL_pixels_c.h" -#include "SDL_events.h" -#if (SDL_VERSION_ATLEAST(1,3,0)) -#include "../../events/SDL_events_c.h" -#include "../../events/SDL_keyboard_c.h" -#include "../../events/SDL_mouse_c.h" -#include "SDL_scancode.h" -#include "SDL_compat.h" -#else -#include "SDL_keysym.h" -#include "../../events/SDL_events_c.h" -#endif -#include "SDL_joystick.h" -#include "../../joystick/SDL_sysjoystick.h" -#include "../../joystick/SDL_joystick_c.h" #include "SDL_androidvideo.h" #include "SDL_androidinput.h" diff --git a/project/sdl/sdl-1.3/src/video/android/SDL_androidinput.h b/project/sdl/sdl-1.3/src/video/android/SDL_androidinput.h index e8f34c602..d4123506f 100644 --- a/project/sdl/sdl-1.3/src/video/android/SDL_androidinput.h +++ b/project/sdl/sdl-1.3/src/video/android/SDL_androidinput.h @@ -171,8 +171,6 @@ enum MOUSE_ACTION { MOUSE_DOWN = 0, MOUSE_UP=1, MOUSE_MOVE=2 }; enum { MAX_MULTITOUCH_POINTERS = 5 }; -extern int SDL_android_drawTouchscreenKeyboard(); - extern int SDL_android_processTouchscreenKeyboard(int x, int y, int action, int pointerId); #ifndef SDL_ANDROID_KEYCODE_0 diff --git a/project/sdl/sdl-1.3/src/video/android/SDL_androidvideo.h b/project/sdl/sdl-1.3/src/video/android/SDL_androidvideo.h index b95af6cf8..993285f40 100644 --- a/project/sdl/sdl-1.3/src/video/android/SDL_androidvideo.h +++ b/project/sdl/sdl-1.3/src/video/android/SDL_androidvideo.h @@ -19,11 +19,13 @@ Sam Lantinga slouken@libsdl.org */ -#include "SDL_config.h" - #ifndef _SDL_androidvideo_h #define _SDL_androidvideo_h +#include "SDL_config.h" +#include "SDL_video.h" +#include "../SDL_sysvideo.h" + extern void ANDROID_InitOSKeymap(); extern int SDL_ANDROID_sWindowWidth; @@ -31,7 +33,7 @@ extern int SDL_ANDROID_sWindowHeight; extern int SDL_ANDROID_sFakeWindowWidth; // SDL 1.2 only extern int SDL_ANDROID_sFakeWindowHeight; // SDL 1.2 only extern int SDL_ANDROID_CallJavaSwapBuffers(); -// typedef struct SDL_VideoDevice SDL_VideoDevice; +extern int SDL_android_drawTouchscreenKeyboard(); extern SDL_VideoDevice *ANDROID_CreateDevice_1_3(int devindex); // Keycodes ripped from Java SDK diff --git a/project/sdl/sdl-1.3/src/video/android/SDL_touchscreenkeyboard.c b/project/sdl/sdl-1.3/src/video/android/SDL_touchscreenkeyboard.c index b76f38191..bbd9fcfd0 100644 --- a/project/sdl/sdl-1.3/src/video/android/SDL_touchscreenkeyboard.c +++ b/project/sdl/sdl-1.3/src/video/android/SDL_touchscreenkeyboard.c @@ -26,30 +26,11 @@ #include #include #include // for memset() +#include #include "SDL_config.h" #include "SDL_version.h" -#include "SDL_video.h" -#include "SDL_mouse.h" -#include "SDL_mutex.h" -#include "SDL_thread.h" -#include "../SDL_sysvideo.h" -#include "../SDL_pixels_c.h" -#include "SDL_events.h" -#if (SDL_VERSION_ATLEAST(1,3,0)) -#include "../../events/SDL_events_c.h" -#include "../../events/SDL_keyboard_c.h" -#include "../../events/SDL_mouse_c.h" -#include "SDL_scancode.h" -#include "SDL_compat.h" -#else -#include "SDL_keysym.h" -#include "../../events/SDL_events_c.h" -#endif -#include "SDL_joystick.h" -#include "../../joystick/SDL_sysjoystick.h" -#include "../../joystick/SDL_joystick_c.h" #include "SDL_androidvideo.h" #include "SDL_androidinput.h" @@ -122,7 +103,7 @@ static inline void drawChar(int idx, Uint16 x, Uint16 y, Uint8 r, Uint8 g, Uint8 glPushMatrix(); glTranslatex( x, y, 0 ); - glVertexPointer(2, GL_SHORT, 0, vertices); + glVertexPointer(2, GL_SHORT, 0, fontGL[idx]); glEnableClientState(GL_VERTEX_ARRAY); glDrawArrays(GL_LINE_STRIP, 0, fontGL[idx][FONT_CHAR_LINES_COUNT]); glDisableClientState(GL_VERTEX_ARRAY); @@ -198,7 +179,7 @@ int SDL_android_drawTouchscreenKeyboard() static inline int ArrowKeysPressed(int x, int y) { - itn ret = 0, dx, dy; + int ret = 0, dx, dy; /* if( !InsideRect( &arrows, x, y ) ) return 0; @@ -261,7 +242,7 @@ int SDL_android_processTouchscreenKeyboard(int x, int y, int action, int pointer return 1; } - for( int i = 0; i < nbuttons; i++ ) + for( i = 0; i < nbuttons; i++ ) { if( InsideRect( &buttons[i], x, y) ) { @@ -289,12 +270,12 @@ int SDL_android_processTouchscreenKeyboard(int x, int y, int action, int pointer oldArrows = 0; return 1; } - for( int i = 0; i < nbuttons; i++ ) + for( i = 0; i < nbuttons; i++ ) { if( OldCoords[pointerId] == &buttons[i] ) { if( ! ( i == 0 && Button1AutoFire ) ) - SDL_SendKeyboardKey( SDL_RELEASED, GetKeysym(buttonKeysyms[i]) ,&keysym) ); + SDL_SendKeyboardKey( SDL_RELEASED, GetKeysym(buttonKeysyms[i] ,&keysym) ); OldCoords[pointerId] = NULL; return 1; } @@ -344,3 +325,10 @@ int SDL_android_processTouchscreenKeyboard(int x, int y, int action, int pointer return 0; }; + +JNIEXPORT void JNICALL +JAVA_EXPORT_NAME(Settings_nativeSetTouchscreenKeyboardUsed) ( JNIEnv* env, jobject thiz) +{ + isTouchscreenKeyboardUsed = 1; +} + diff --git a/project/src/Accelerometer.java b/project/src/Accelerometer.java index dd696158e..8218593d2 100644 --- a/project/src/Accelerometer.java +++ b/project/src/Accelerometer.java @@ -25,7 +25,7 @@ class AccelerometerReader implements SensorEventListener { _manager = (SensorManager) context.getSystemService(Context.SENSOR_SERVICE); if( _manager != null ) { - if( Globals.AppNeedsArrowKeys ) + if( Globals.UseAccelerometerAsArrowKeys ) { _manager.registerListener(this, _manager.getDefaultSensor(Sensor.TYPE_ACCELEROMETER), SensorManager.SENSOR_DELAY_GAME); } diff --git a/project/src/Globals.java b/project/src/Globals.java index 8b2e6c277..a3fb272c6 100644 --- a/project/src/Globals.java +++ b/project/src/Globals.java @@ -10,12 +10,6 @@ class Globals { // Should be zip file public static String DataDownloadUrl = "http://sites.google.com/site/xpelyax/Home/alienblaster110_data.zip?attredirects=0%26d=1|http://sitesproxy.goapk.com/site/xpelyax/Home/alienblaster110_data.zip"; // This string is autogenerated by ChangeAppSettings.sh, do not change spaces amount - // Set DownloadToSdcard to true if your app data is bigger than 5 megabytes. - // It will download app data to /sdcard/alienblaster then, - // otherwise it will download it to /data/data/de.schwardtnet.alienblaster/files - - // set this dir in jni/Android.mk in SDL_CURDIR_PATH - public static boolean DownloadToSdcard = false; - // Set this value to true if you're planning to render 3D using OpenGL - it eats some GFX resources, so disabled for 2D public static boolean NeedDepthBuffer = false; @@ -27,14 +21,20 @@ class Globals { public static boolean AppUsesMouse = false; - // We have to use accelerometer as arrow keys public static boolean AppNeedsArrowKeys = true; - + public static boolean AppUsesJoystick = false; public static boolean AppUsesMultitouch = false; + // Phone-specific config + // It will download app data to /sdcard/alienblaster if set to true, + // otherwise it will download it to /data/data/de.schwardtnet.alienblaster/files + public static boolean DownloadToSdcard = false; public static boolean PhoneHasTrackball = false; + public static boolean PhoneHasArrowKeys = false; + public static boolean UseAccelerometerAsArrowKeys = false; + public static boolean UseTouchscreenKeyboard = false; } class LoadLibrary { diff --git a/project/src/Settings.java b/project/src/Settings.java index 8a7bafb67..2a3df148a 100644 --- a/project/src/Settings.java +++ b/project/src/Settings.java @@ -20,13 +20,31 @@ import android.os.StatFs; class Settings { static String SettingsFileName = "libsdl-settings.cfg"; + + static void Save(final MainActivity p) + { + try { + ObjectOutputStream out = new ObjectOutputStream(p.openFileOutput( SettingsFileName, p.MODE_WORLD_READABLE )); + out.writeBoolean(Globals.DownloadToSdcard); + out.writeBoolean(Globals.PhoneHasArrowKeys); + out.writeBoolean(Globals.PhoneHasTrackball); + out.writeBoolean(Globals.UseAccelerometerAsArrowKeys); + out.writeBoolean(Globals.UseTouchscreenKeyboard); + out.close(); + } catch( FileNotFoundException e ) { + } catch( SecurityException e ) { + } catch ( IOException e ) {}; + } + static void Load( final MainActivity p ) { try { ObjectInputStream settingsFile = new ObjectInputStream(new FileInputStream( p.getFilesDir().getAbsolutePath() + "/" + SettingsFileName )); Globals.DownloadToSdcard = settingsFile.readBoolean(); - Globals.AppNeedsArrowKeys = settingsFile.readBoolean(); + Globals.PhoneHasArrowKeys = settingsFile.readBoolean(); Globals.PhoneHasTrackball = settingsFile.readBoolean(); + Globals.UseAccelerometerAsArrowKeys = settingsFile.readBoolean(); + Globals.UseTouchscreenKeyboard = settingsFile.readBoolean(); startDownloader(p); return; @@ -86,7 +104,7 @@ class Settings static void showKeyboardConfig(final MainActivity p) { - if( ! Globals.AppNeedsArrowKeys ) + if( ! Globals.AppNeedsArrowKeys ) { Save(p); startDownloader(p); @@ -101,11 +119,11 @@ class Settings { public void onClick(DialogInterface dialog, int item) { - Globals.AppNeedsArrowKeys = (item == 2); + Globals.PhoneHasArrowKeys = (item == 0); Globals.PhoneHasTrackball = (item == 1); dialog.dismiss(); - showAccelermoeterConfig(p); + showAdditionalInputConfig(p); } }); AlertDialog alert = builder.create(); @@ -113,24 +131,23 @@ class Settings alert.show(); } - static void showAccelermoeterConfig(final MainActivity p) + static void showAdditionalInputConfig(final MainActivity p) { - if( Globals.AppNeedsArrowKeys || Globals.AppUsesJoystick ) - { - Save(p); - startDownloader(p); - return; - } - - final CharSequence[] items = {"Do not use accelerometer", "Use accelerometer as navigation keys"}; + final CharSequence[] items = { + "On-screen keyboard" + ( Globals.AppUsesMouse ? " (disables mouse input)" : ""), + "Accelerometer as navigation keys" + ( Globals.AppUsesJoystick ? " (disables joystick input)" : "" ), + "Both accelerometer and on-screen keyboard", + "No additional controls" + ( Globals.AppNeedsArrowKeys ? " (you won't be able to play without arrow keys)" : " (only if your phone has enough buttons)") + }; AlertDialog.Builder builder = new AlertDialog.Builder(p); - builder.setTitle("You may optionally use accelerometer as another navigation keys"); + builder.setTitle("Additional controls to use"); builder.setSingleChoiceItems(items, -1, new DialogInterface.OnClickListener() { public void onClick(DialogInterface dialog, int item) { - Globals.AppNeedsArrowKeys = (item == 1); + Globals.UseTouchscreenKeyboard = (item == 0 || item == 2); + Globals.UseAccelerometerAsArrowKeys = (item == 1 || item == 2); Save(p); dialog.dismiss(); @@ -142,19 +159,6 @@ class Settings alert.show(); } - static void Save(final MainActivity p) - { - try { - ObjectOutputStream out = new ObjectOutputStream(p.openFileOutput( SettingsFileName, p.MODE_WORLD_READABLE )); - out.writeBoolean(Globals.DownloadToSdcard); - out.writeBoolean(Globals.AppNeedsArrowKeys); - out.writeBoolean(Globals.PhoneHasTrackball); - out.close(); - } catch( FileNotFoundException e ) { - } catch( SecurityException e ) { - } catch ( IOException e ) {}; - } - static void Apply() { @@ -164,10 +168,15 @@ class Settings nativeSetTrackballUsed(); if( Globals.AppUsesMouse ) nativeSetMouseUsed(); - if( Globals.AppUsesJoystick && !Globals.AppNeedsArrowKeys ) + if( Globals.AppUsesJoystick && !Globals.UseAccelerometerAsArrowKeys ) nativeSetJoystickUsed(); if( Globals.AppUsesMultitouch ) nativeSetMultitouchUsed(); + if( Globals.UseTouchscreenKeyboard ) + { + nativeSetTouchscreenKeyboardUsed(); + nativeSetupScreenKeyboard(0, 4); + } } static void startDownloader(MainActivity p) @@ -186,10 +195,12 @@ class Settings }; - private static native int nativeIsSdcardUsed(int flag); - private static native int nativeSetTrackballUsed(); - private static native int nativeSetMouseUsed(); - private static native int nativeSetJoystickUsed(); - private static native int nativeSetMultitouchUsed(); + private static native void nativeIsSdcardUsed(int flag); + private static native void nativeSetTrackballUsed(); + private static native void nativeSetMouseUsed(); + private static native void nativeSetJoystickUsed(); + private static native void nativeSetMultitouchUsed(); + private static native void nativeSetTouchscreenKeyboardUsed(); + private static native void nativeSetupScreenKeyboard(int size, int nbuttons); }