Use initial orientation for device rotation instead of hardcoded values
This commit is contained in:
parent
3480a5da9b
commit
4081efbcaa
@ -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();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -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;
|
||||
|
@ -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;
|
||||
|
@ -291,6 +291,7 @@ namespace irr
|
||||
f32 BottomPadding;
|
||||
f32 LeftPadding;
|
||||
f32 RightPadding;
|
||||
int InitialOrientation;
|
||||
|
||||
bool WindowHasFocus;
|
||||
bool WindowMinimized;
|
||||
|
Loading…
Reference in New Issue
Block a user