From 161f99b864795bf714941e981ad4032c6f50855e Mon Sep 17 00:00:00 2001 From: JosJuice Date: Sat, 12 Sep 2020 17:56:47 +0200 Subject: [PATCH] Android: Move OSD out of the way when menu is open https://bugs.dolphin-emu.org/issues/12256 --- .../dolphinemu/dolphinemu/NativeLibrary.java | 4 ++++ .../dolphinemu/fragments/MenuFragment.java | 13 ++++++++++++ Source/Android/jni/MainAndroid.cpp | 12 +++++++++++ Source/Core/VideoCommon/OnScreenDisplay.cpp | 20 +++++++++++++++++-- Source/Core/VideoCommon/OnScreenDisplay.h | 3 +++ 5 files changed, 50 insertions(+), 2 deletions(-) diff --git a/Source/Android/app/src/main/java/org/dolphinemu/dolphinemu/NativeLibrary.java b/Source/Android/app/src/main/java/org/dolphinemu/dolphinemu/NativeLibrary.java index 86e75d55ec..a03376bb8a 100644 --- a/Source/Android/app/src/main/java/org/dolphinemu/dolphinemu/NativeLibrary.java +++ b/Source/Android/app/src/main/java/org/dolphinemu/dolphinemu/NativeLibrary.java @@ -431,6 +431,10 @@ public final class NativeLibrary public static native String FormatSize(long bytes, int decimals); + public static native void SetObscuredPixelsLeft(int width); + + public static native void SetObscuredPixelsTop(int height); + private static boolean alertResult = false; public static boolean displayAlertMsg(final String caption, final String text, diff --git a/Source/Android/app/src/main/java/org/dolphinemu/dolphinemu/fragments/MenuFragment.java b/Source/Android/app/src/main/java/org/dolphinemu/dolphinemu/fragments/MenuFragment.java index f468240c4d..3badbd3e48 100644 --- a/Source/Android/app/src/main/java/org/dolphinemu/dolphinemu/fragments/MenuFragment.java +++ b/Source/Android/app/src/main/java/org/dolphinemu/dolphinemu/fragments/MenuFragment.java @@ -137,6 +137,11 @@ public final class MenuFragment extends Fragment implements View.OnClickListener mTitleText.setText(title); } + if (getResources().getConfiguration().getLayoutDirection() == View.LAYOUT_DIRECTION_LTR) + { + rootView.post(() -> NativeLibrary.SetObscuredPixelsLeft(rootView.getWidth())); + } + return rootView; } @@ -156,6 +161,14 @@ public final class MenuFragment extends Fragment implements View.OnClickListener options.findViewById(R.id.menu_emulation_load_root).setVisibility(savestateVisibility); } + @Override + public void onDestroyView() + { + super.onDestroyView(); + + NativeLibrary.SetObscuredPixelsLeft(0); + } + private void updatePauseUnpauseVisibility() { boolean paused = EmulationActivity.getHasUserPausedEmulation(); diff --git a/Source/Android/jni/MainAndroid.cpp b/Source/Android/jni/MainAndroid.cpp index 3dfafacf7c..25df43dc20 100644 --- a/Source/Android/jni/MainAndroid.cpp +++ b/Source/Android/jni/MainAndroid.cpp @@ -671,6 +671,18 @@ JNIEXPORT jstring JNICALL Java_org_dolphinemu_dolphinemu_NativeLibrary_FormatSiz return ToJString(env, UICommon::FormatSize(bytes, decimals)); } +JNIEXPORT void JNICALL Java_org_dolphinemu_dolphinemu_NativeLibrary_SetObscuredPixelsLeft( + JNIEnv* env, jobject obj, jint width) +{ + OSD::SetObscuredPixelsLeft(width); +} + +JNIEXPORT void JNICALL Java_org_dolphinemu_dolphinemu_NativeLibrary_SetObscuredPixelsTop( + JNIEnv* env, jobject obj, jint height) +{ + OSD::SetObscuredPixelsTop(height); +} + #ifdef __cplusplus } #endif diff --git a/Source/Core/VideoCommon/OnScreenDisplay.cpp b/Source/Core/VideoCommon/OnScreenDisplay.cpp index e08bfb0970..0558ee2619 100644 --- a/Source/Core/VideoCommon/OnScreenDisplay.cpp +++ b/Source/Core/VideoCommon/OnScreenDisplay.cpp @@ -5,6 +5,7 @@ #include "VideoCommon/OnScreenDisplay.h" #include +#include #include #include #include @@ -24,6 +25,9 @@ constexpr float LEFT_MARGIN = 10.0f; // Pixels to the left of OSD messages. constexpr float TOP_MARGIN = 10.0f; // Pixels above the first OSD message. constexpr float WINDOW_PADDING = 4.0f; // Pixels between subsequent OSD messages. +static std::atomic s_obscured_pixels_left = 0; +static std::atomic s_obscured_pixels_top = 0; + struct Message { Message() = default; @@ -97,8 +101,9 @@ void DrawMessages() { const bool draw_messages = Config::Get(Config::MAIN_OSD_MESSAGES); const u32 now = Common::Timer::GetTimeMs(); - const float current_x = LEFT_MARGIN * ImGui::GetIO().DisplayFramebufferScale.x; - float current_y = TOP_MARGIN * ImGui::GetIO().DisplayFramebufferScale.y; + const float current_x = + LEFT_MARGIN * ImGui::GetIO().DisplayFramebufferScale.x + s_obscured_pixels_left; + float current_y = TOP_MARGIN * ImGui::GetIO().DisplayFramebufferScale.y + s_obscured_pixels_top; int index = 0; std::lock_guard lock{s_messages_mutex}; @@ -128,4 +133,15 @@ void ClearMessages() std::lock_guard lock{s_messages_mutex}; s_messages.clear(); } + +void SetObscuredPixelsLeft(int width) +{ + s_obscured_pixels_left = width; +} + +void SetObscuredPixelsTop(int height) +{ + s_obscured_pixels_top = height; +} + } // namespace OSD diff --git a/Source/Core/VideoCommon/OnScreenDisplay.h b/Source/Core/VideoCommon/OnScreenDisplay.h index 73d6bcf753..fe31c99fe6 100644 --- a/Source/Core/VideoCommon/OnScreenDisplay.h +++ b/Source/Core/VideoCommon/OnScreenDisplay.h @@ -44,4 +44,7 @@ void AddTypedMessage(MessageType type, std::string message, u32 ms = Duration::S // Draw the current messages on the screen. Only call once per frame. void DrawMessages(); void ClearMessages(); + +void SetObscuredPixelsLeft(int width); +void SetObscuredPixelsTop(int height); } // namespace OSD