Android: added a callback to java to determine dpi/dip how much we should scale the ui
--- a/hedgewars/SDLh.pas Sat Jun 02 16:25:13 2012 -0400
+++ b/hedgewars/SDLh.pas Sat Jun 02 22:31:41 2012 +0200
@@ -968,6 +968,10 @@
function SDL_getenv(const text: PChar): PChar; cdecl; external SDLLibName;
{$ENDIF}
+{$IFDEF ANDROID}
+function Android_JNI_getDensity(): Single; cdecl; external SDLLibName;
+{$ENDIF}
+
{* Compatibility between SDL-1.2 and SDL-1.3 *}
procedure SDL_WarpMouse(x, y: Word); {$IFDEF SDL13}inline{$ELSE}cdecl; external SDLLibName{$ENDIF};
function SDL_GetKeyState(numkeys: PLongInt): PByteArray; cdecl; external SDLLibName {$IFDEF SDL13} name 'SDL_GetKeyboardState'{$ENDIF};
--- a/hedgewars/uWorld.pas Sat Jun 02 16:25:13 2012 -0400
+++ b/hedgewars/uWorld.pas Sat Jun 02 22:31:41 2012 +0200
@@ -214,8 +214,13 @@
procedure InitTouchInterface;
begin
{$IFDEF USE_TOUCH_INTERFACE}
+
//positioning of the buttons
+{$IFDEF ANDROID}
+buttonScale:= Android_JNI_getDensity()/cDefaultZoomLevel;
+{$ELSE}
buttonScale:= 1.5/cDefaultZoomLevel;
+{$ENDIF}
with JumpWidget do
--- a/project_files/Android-build/SDL-android-project/jni/SDL/src/core/android/SDL_android.cpp Sat Jun 02 16:25:13 2012 -0400
+++ b/project_files/Android-build/SDL-android-project/jni/SDL/src/core/android/SDL_android.cpp Sat Jun 02 22:31:41 2012 +0200
@@ -638,6 +638,21 @@
return Android_JNI_FileClose(ctx, true);
}
+/*******************************************************************************
+ Functions called by the hwengine into Java
+*******************************************************************************/
+
+extern "C" float Android_JNI_getDensity(){
+ jmethodID mid;
+ jfloat density;
+ //SDLActivity.getDensity()
+ mid = mEnv->GetStaticMethodID(mActivityClass, "getDensity", "()F");
+ if(!mid) return 1.5f;
+ density = mEnv->CallStaticFloatMethod(mActivityClass, mid);
+ return density;
+
+}
+
#endif /* __ANDROID__ */
/* vi: set ts=4 sw=4 expandtab: */
--- a/project_files/Android-build/SDL-android-project/src/org/hedgewars/hedgeroid/SDLActivity.java Sat Jun 02 16:25:13 2012 -0400
+++ b/project_files/Android-build/SDL-android-project/src/org/hedgewars/hedgeroid/SDLActivity.java Sat Jun 02 22:31:41 2012 +0200
@@ -24,6 +24,7 @@
import android.os.Bundle;
import android.os.Handler;
import android.os.Message;
+import android.util.DisplayMetrics;
import android.util.Log;
import android.view.KeyEvent;
import android.view.MotionEvent;
@@ -401,6 +402,11 @@
mAudioTrack = null;
}
}
+
+ public static float getDensity(){
+ DisplayMetrics dm = SDLActivity.getContext().getResources().getDisplayMetrics();
+ return dm.density;
+ }
}
/**