Skip to content

Commit

Permalink
android: Refactor layout code to use LargeScreen layout
Browse files Browse the repository at this point in the history
  • Loading branch information
DavidRGriswold authored and Gamer64ytb committed Sep 1, 2024
1 parent df34087 commit a9db475
Show file tree
Hide file tree
Showing 10 changed files with 27 additions and 48 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ class ScreenAdjustmentUtil(private val windowManager: WindowManager,

fun cycleLayouts() {
// TODO: figure out how to pull these from R.array
val landscapeValues = intArrayOf(6, 1, 3, 4, 0, 5)
val landscapeValues = intArrayOf(2, 1, 3, 4, 0, 5)
val portraitValues = intArrayOf(0, 1)
if (NativeLibrary.isPortraitMode) {
val currentLayout = IntSetting.PORTRAIT_SCREEN_LAYOUT.int
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,12 +11,11 @@ enum class ScreenLayout(val int: Int) {
LARGE_SCREEN(2),
SIDE_SCREEN(3),
HYBRID_SCREEN(4),
CUSTOM_LAYOUT(5),
MOBILE_LANDSCAPE(6);
CUSTOM_LAYOUT(5);

companion object {
fun from(int: Int): ScreenLayout {
return entries.firstOrNull { it.int == int } ?: MOBILE_LANDSCAPE
return entries.firstOrNull { it.int == int } ?: LARGE_SCREEN
}
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -829,14 +829,14 @@ class EmulationFragment : Fragment(), SurfaceHolder.Callback, Choreographer.Fram
ScreenLayout.CUSTOM_LAYOUT.int ->
R.id.menu_screen_layout_custom

else -> R.id.menu_screen_layout_landscape
else -> R.id.menu_screen_layout_largescreen
}
popupMenu.menu.findItem(layoutOptionMenuItem).setChecked(true)

popupMenu.setOnMenuItemClickListener {
when (it.itemId) {
R.id.menu_screen_layout_landscape -> {
screenAdjustmentUtil.changeScreenOrientation(ScreenLayout.MOBILE_LANDSCAPE.int)
R.id.menu_screen_layout_largescreen -> {
screenAdjustmentUtil.changeScreenOrientation(ScreenLayout.LARGE_SCREEN.int)
true
}

Expand Down
14 changes: 12 additions & 2 deletions src/android/app/src/main/jni/config.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -183,8 +183,18 @@ void Config::ReadValues() {
ReadSetting("Renderer", Settings::values.disable_flush_cpu_write);

// Layout
Settings::values.layout_option = static_cast<Settings::LayoutOption>(sdl2_config->GetInteger(
"Layout", "layout_option", static_cast<int>(Settings::LayoutOption::LargeScreen)));
// Somewhat inelegant solution to ensure layout value is between 0 and 5 on read
// since older config files may have other values
int layoutInt = (int)sdl2_config->GetInteger(
"Layout", "layout_option", static_cast<int>(Settings::LayoutOption::LargeScreen));
if (layoutInt < 0 || layoutInt > 5) {
layoutInt = static_cast<int>(Settings::LayoutOption::LargeScreen);
}
Settings::values.layout_option = static_cast<Settings::LayoutOption>(layoutInt);

Settings::values.large_screen_proportion =
static_cast<float>(sdl2_config->GetReal("Layout", "large_screen_proportion", 2.25));

ReadSetting("Layout", Settings::values.custom_top_x);
ReadSetting("Layout", Settings::values.custom_top_y);
ReadSetting("Layout", Settings::values.custom_top_width);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,8 @@
<group android:checkableBehavior="single">

<item
android:id="@+id/menu_screen_layout_landscape"
android:title="@string/emulation_screen_layout_landscape" />
android:id="@+id/menu_screen_layout_largescreen"
android:title="@string/emulation_screen_layout_largescreen" />

<item
android:id="@+id/menu_screen_layout_single"
Expand Down
9 changes: 3 additions & 6 deletions src/android/app/src/main/res/values/arrays.xml
Original file line number Diff line number Diff line change
Expand Up @@ -12,19 +12,16 @@
</integer-array>

<string-array name="landscapeLayouts">
<item>@string/emulation_screen_layout_landscape</item>
<item>@string/emulation_screen_layout_largescreen</item>
<item>@string/emulation_screen_layout_single</item>
<item>@string/emulation_screen_layout_sidebyside</item>
<item>@string/emulation_screen_layout_hybrid</item>
<item>@string/emulation_screen_layout_original</item>
<item>@string/emulation_screen_layout_custom</item>
</string-array>
<!-- start with 6 because that is the MobileLandscape layout in cpp files
- skip 0 because top/bottom rarely makes sense in landscape
- skip 2 because that is "Large Screen" which the default replaces in mobile
-->
<!-- start with 2 because that is the Large Screen layout in cpp files -->
<integer-array name="landscapeLayoutValues">
<item>6</item>
<item>2</item>
<item>1</item>
<item>3</item>
<item>4</item>
Expand Down
2 changes: 1 addition & 1 deletion src/android/app/src/main/res/values/strings.xml
Original file line number Diff line number Diff line change
Expand Up @@ -383,7 +383,7 @@
<string name="emulation_open_cheats">Open Cheats</string>
<string name="emulation_switch_screen_layout">Landscape Screen Layout</string>
<string name="emulation_switch_portrait_layout">Portrait Screen Layout</string>
<string name="emulation_screen_layout_landscape">Default</string>
<string name="emulation_screen_layout_largescreen">Large Screen</string>
<string name="emulation_screen_layout_portrait">Portrait</string>
<string name="emulation_screen_layout_single">Single Screen</string>
<string name="emulation_screen_layout_sidebyside">Side by Side Screens</string>
Expand Down
4 changes: 0 additions & 4 deletions src/common/settings.h
Original file line number Diff line number Diff line change
Expand Up @@ -44,10 +44,6 @@ enum class LayoutOption : u32 {
#endif
HybridScreen,
CustomLayout,

// Similiar to LargeScreen, but better for mobile devices in landscape mode. The screens are
// clamped to the top of the frame, and the bottom screen is a bit bigger.
MobileLandscape,
};

/** Defines the layout option for mobile portrait */
Expand Down
6 changes: 0 additions & 6 deletions src/core/frontend/emu_window.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -232,12 +232,6 @@ void EmuWindow::UpdateCurrentFramebufferLayout(u32 width, u32 height, bool is_po
Settings::values.upright_screen.GetValue());
break;
#endif
case Settings::LayoutOption::MobileLandscape:
layout =
Layout::LargeFrameLayout(width, height, Settings::values.swap_screen.GetValue(),
false, 2.25f, Layout::VerticalAlignment::Top);
break;

case Settings::LayoutOption::Default:
default:
layout =
Expand Down
23 changes: 3 additions & 20 deletions src/core/frontend/framebuffer_layout.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -204,7 +204,9 @@ FramebufferLayout LargeFrameLayout(u32 width, u32 height, bool swapped, bool upr
float scale_factor, VerticalAlignment vertical_alignment) {
ASSERT(width > 0);
ASSERT(height > 0);

#ifdef ANDROID
vertical_alignment = VerticalAlignment::Top;
#endif
FramebufferLayout res{width, height, true, true, {}, {}, !upright};
// Split the window into two parts. Give 4x width to the main screen and 1x width to the small
// To do that, find the total emulation box and maximize that based on window size
Expand Down Expand Up @@ -512,23 +514,6 @@ FramebufferLayout FrameLayoutFromResolutionScale(u32 res_scale, bool is_secondar
Settings::values.upright_screen.GetValue(), 1,
VerticalAlignment::Middle);

case Settings::LayoutOption::MobileLandscape: {
constexpr float large_screen_proportion = 2.25f;
if (Settings::values.swap_screen.GetValue()) {
width = (Core::kScreenBottomWidth +
static_cast<int>(Core::kScreenTopWidth / large_screen_proportion)) *
res_scale;
height = Core::kScreenBottomHeight * res_scale;
} else {
width = (Core::kScreenTopWidth +
static_cast<int>(Core::kScreenBottomWidth / large_screen_proportion)) *
res_scale;
height = Core::kScreenTopHeight * res_scale;
}
return LargeFrameLayout(width, height, Settings::values.swap_screen.GetValue(), false,
large_screen_proportion, VerticalAlignment::Top);
}

case Settings::LayoutOption::Default:
default:
width = Core::kScreenTopWidth * res_scale;
Expand Down Expand Up @@ -579,9 +564,7 @@ FramebufferLayout GetCardboardSettings(const FramebufferLayout& layout) {
}
} else {
switch (Settings::values.layout_option.GetValue()) {
case Settings::LayoutOption::MobileLandscape:
case Settings::LayoutOption::SideScreen:
// If orientation is portrait, only use MobilePortrait
cardboard_screen_width = top_screen_width + bottom_screen_width;
cardboard_screen_height = is_swapped ? bottom_screen_height : top_screen_height;
if (is_swapped)
Expand Down

0 comments on commit a9db475

Please sign in to comment.