diff --git a/android/src/main/java/SuperTuxKartActivity.java b/android/src/main/java/SuperTuxKartActivity.java index 2298f3f21..85c66c419 100644 --- a/android/src/main/java/SuperTuxKartActivity.java +++ b/android/src/main/java/SuperTuxKartActivity.java @@ -65,6 +65,7 @@ public class SuperTuxKartActivity extends SDLActivity private ImageView m_splash_screen; private STKEditText m_stk_edittext; private int m_bottom_y; + private int m_intial_orientation; private float m_top_padding; private float m_bottom_padding; private float m_left_padding; @@ -186,7 +187,7 @@ public class SuperTuxKartActivity extends SDLActivity m_progress_dialog = null; m_progress_bar = null; m_splash_screen = null; - m_bottom_y = 0; + m_bottom_y = m_intial_orientation = 0; m_top_padding = m_bottom_padding = m_left_padding = m_right_padding = 0.0f; final View root = getWindow().getDecorView().findViewById( @@ -398,6 +399,9 @@ public class SuperTuxKartActivity extends SDLActivity // ------------------------------------------------------------------------ public float getRightPadding() { return m_right_padding; } // ------------------------------------------------------------------------ + public int getInitialOrientation() { return m_intial_orientation; } + // ------------------------------------------------------------------------ + public void showExtractProgress(final int progress) { runOnUiThread(new Runnable() @@ -485,6 +489,9 @@ public class SuperTuxKartActivity extends SDLActivity m_bottom_padding = (float)dc.getBoundingRectBottom().height(); m_left_padding = (float)dc.getBoundingRectLeft().width(); m_right_padding = (float)dc.getBoundingRectRight().width(); + // Left or right will depend on the device initial orientation + // So save it for dealing with device rotation later + m_intial_orientation = SDLActivity.getCurrentOrientation(); } } } diff --git a/lib/irrlicht/source/Irrlicht/CIrrDeviceAndroid.cpp b/lib/irrlicht/source/Irrlicht/CIrrDeviceAndroid.cpp index 819d99ce6..237811888 100644 --- a/lib/irrlicht/source/Irrlicht/CIrrDeviceAndroid.cpp +++ b/lib/irrlicht/source/Irrlicht/CIrrDeviceAndroid.cpp @@ -62,7 +62,8 @@ ANDROID_HANDLE_PADDING_CALLBACK(ANDROID_PACKAGE_CALLBACK_NAME) } extern "C" void Android_initDisplayCutout(float* top, float* bottom, - float* left, float* right) + float* left, float* right, + int* initial_orientation) { JNIEnv* env = NULL; jobject activity = NULL; @@ -71,6 +72,7 @@ extern "C" void Android_initDisplayCutout(float* top, float* bottom, jmethodID bottom_method = NULL; jmethodID left_method = NULL; jmethodID right_method = NULL; + jmethodID initial_orientation_method = NULL; env = (JNIEnv*)SDL_AndroidGetJNIEnv(); if (!env) @@ -104,6 +106,10 @@ extern "C" void Android_initDisplayCutout(float* top, float* bottom, goto exit; *right = env->CallFloatMethod(activity, right_method); + initial_orientation_method = env->GetMethodID(class_native_activity, "getInitialOrientation", "()I"); + if (initial_orientation_method == NULL) + goto exit; + *initial_orientation = env->CallIntMethod(activity, initial_orientation_method); exit: if (!env) return; diff --git a/lib/irrlicht/source/Irrlicht/CIrrDeviceSDL.cpp b/lib/irrlicht/source/Irrlicht/CIrrDeviceSDL.cpp index 2ea8ab036..60245cfd6 100644 --- a/lib/irrlicht/source/Irrlicht/CIrrDeviceSDL.cpp +++ b/lib/irrlicht/source/Irrlicht/CIrrDeviceSDL.cpp @@ -43,7 +43,7 @@ namespace irr extern "C" void init_objc(SDL_SysWMinfo* info, float* top, float* bottom, float* left, float* right); extern "C" int handle_app_event(void* userdata, SDL_Event* event); -extern "C" void Android_initDisplayCutout(float* top, float* bottom, float* left, float* right); +extern "C" void Android_initDisplayCutout(float* top, float* bottom, float* left, float* right, int* initial_orientation); extern "C" int Android_disablePadding(); namespace irr @@ -59,8 +59,8 @@ CIrrDeviceSDL::CIrrDeviceSDL(const SIrrlichtCreationParameters& param) MouseX(0), MouseY(0), MouseButtonStates(0), Width(param.WindowSize.Width), Height(param.WindowSize.Height), TopPadding(0), BottomPadding(0), LeftPadding(0), RightPadding(0), - WindowHasFocus(false), WindowMinimized(false), Resizable(false), - AccelerometerIndex(-1), AccelerometerInstance(-1), + InitialOrientation(0), WindowHasFocus(false), WindowMinimized(false), + Resizable(false), AccelerometerIndex(-1), AccelerometerInstance(-1), GyroscopeIndex(-1), GyroscopeInstance(-1) { #ifdef _DEBUG @@ -117,7 +117,7 @@ CIrrDeviceSDL::CIrrDeviceSDL(const SIrrlichtCreationParameters& param) init_objc(&Info, &TopPadding, &BottomPadding, &LeftPadding, &RightPadding); #endif #ifdef ANDROID - Android_initDisplayCutout(&TopPadding, &BottomPadding, &LeftPadding, &RightPadding); + Android_initDisplayCutout(&TopPadding, &BottomPadding, &LeftPadding, &RightPadding, &InitialOrientation); #endif core::stringc sdlversion = "SDL Version "; sdlversion += Info.version.major; @@ -1469,7 +1469,9 @@ s32 CIrrDeviceSDL::getLeftPadding() if (Android_disablePadding() != 0) return 0; #if SDL_VERSION_ATLEAST(2, 0, 9) - if (SDL_GetDisplayOrientation(0) == SDL_ORIENTATION_LANDSCAPE_FLIPPED) + if ((InitialOrientation == SDL_ORIENTATION_LANDSCAPE || + InitialOrientation == SDL_ORIENTATION_LANDSCAPE_FLIPPED) && + SDL_GetDisplayOrientation(0) != InitialOrientation) return RightPadding; #endif return LeftPadding; @@ -1485,7 +1487,9 @@ s32 CIrrDeviceSDL::getRightPadding() #if SDL_VERSION_ATLEAST(2, 0, 9) if (Android_disablePadding() != 0) return 0; - if (SDL_GetDisplayOrientation(0) == SDL_ORIENTATION_LANDSCAPE_FLIPPED) + if ((InitialOrientation == SDL_ORIENTATION_LANDSCAPE || + InitialOrientation == SDL_ORIENTATION_LANDSCAPE_FLIPPED) && + SDL_GetDisplayOrientation(0) != InitialOrientation) return LeftPadding; #endif return RightPadding; diff --git a/lib/irrlicht/source/Irrlicht/CIrrDeviceSDL.h b/lib/irrlicht/source/Irrlicht/CIrrDeviceSDL.h index ac13658c9..9ca74c396 100644 --- a/lib/irrlicht/source/Irrlicht/CIrrDeviceSDL.h +++ b/lib/irrlicht/source/Irrlicht/CIrrDeviceSDL.h @@ -291,6 +291,7 @@ namespace irr f32 BottomPadding; f32 LeftPadding; f32 RightPadding; + int InitialOrientation; bool WindowHasFocus; bool WindowMinimized;