Scale C++ menus down to fit the window (#14690)

This commit is contained in:
grorp 2024-05-24 12:10:46 +02:00 committed by GitHub
parent d5fc040d2d
commit 728f643ea7
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
6 changed files with 32 additions and 29 deletions

@ -107,13 +107,9 @@ void GUIKeyChangeMenu::regenerateGui(v2u32 screensize)
removeAllChildren(); removeAllChildren();
key_used_text = nullptr; key_used_text = nullptr;
const float s = m_gui_scale; ScalingInfo info = getScalingInfo(screensize, v2u32(835, 430));
DesiredRect = core::rect<s32>( const float s = info.scale;
screensize.X / 2 - 835 * s / 2, DesiredRect = info.rect;
screensize.Y / 2 - 430 * s / 2,
screensize.X / 2 + 835 * s / 2,
screensize.Y / 2 + 430 * s / 2
);
recalculateAbsolutePosition(false); recalculateAbsolutePosition(false);
v2s32 size = DesiredRect.getSize(); v2s32 size = DesiredRect.getSize();

@ -66,13 +66,9 @@ void GUIOpenURLMenu::regenerateGui(v2u32 screensize)
/* /*
Calculate new sizes and positions Calculate new sizes and positions
*/ */
const float s = m_gui_scale; ScalingInfo info = getScalingInfo(screensize, v2u32(580, 250));
DesiredRect = core::rect<s32>( const float s = info.scale;
screensize.X / 2 - 580 * s / 2, DesiredRect = info.rect;
screensize.Y / 2 - 250 * s / 2,
screensize.X / 2 + 580 * s / 2,
screensize.Y / 2 + 250 * s / 2
);
recalculateAbsolutePosition(false); recalculateAbsolutePosition(false);
v2s32 size = DesiredRect.getSize(); v2s32 size = DesiredRect.getSize();

@ -62,14 +62,9 @@ void GUIPasswordChange::regenerateGui(v2u32 screensize)
/* /*
Calculate new sizes and positions Calculate new sizes and positions
*/ */
const float s = m_gui_scale; ScalingInfo info = getScalingInfo(screensize, v2u32(580, 300));
const float s = info.scale;
DesiredRect = core::rect<s32>( DesiredRect = info.rect;
screensize.X / 2 - 580 * s / 2,
screensize.Y / 2 - 300 * s / 2,
screensize.X / 2 + 580 * s / 2,
screensize.Y / 2 + 300 * s / 2
);
recalculateAbsolutePosition(false); recalculateAbsolutePosition(false);
v2s32 size = DesiredRect.getSize(); v2s32 size = DesiredRect.getSize();

@ -54,13 +54,9 @@ void GUIVolumeChange::regenerateGui(v2u32 screensize)
/* /*
Calculate new sizes and positions Calculate new sizes and positions
*/ */
const float s = m_gui_scale; ScalingInfo info = getScalingInfo(screensize, v2u32(380, 200));
DesiredRect = core::rect<s32>( const float s = info.scale;
screensize.X / 2 - 380 * s / 2, DesiredRect = info.rect;
screensize.Y / 2 - 200 * s / 2,
screensize.X / 2 + 380 * s / 2,
screensize.Y / 2 + 200 * s / 2
);
recalculateAbsolutePosition(false); recalculateAbsolutePosition(false);
v2s32 size = DesiredRect.getSize(); v2s32 size = DesiredRect.getSize();

@ -398,3 +398,17 @@ porting::AndroidDialogState GUIModalMenu::getAndroidUIInputState()
return porting::getInputDialogState(); return porting::getInputDialogState();
} }
#endif #endif
GUIModalMenu::ScalingInfo GUIModalMenu::getScalingInfo(v2u32 screensize, v2u32 base_size)
{
f32 scale = m_gui_scale;
scale = std::min(scale, (f32)screensize.X / (f32)base_size.X);
scale = std::min(scale, (f32)screensize.Y / (f32)base_size.Y);
s32 w = base_size.X * scale, h = base_size.Y * scale;
return {scale, core::rect<s32>(
screensize.X / 2 - w / 2,
screensize.Y / 2 - h / 2,
screensize.X / 2 + w / 2,
screensize.Y / 2 + h / 2
)};
}

@ -94,6 +94,12 @@ protected:
std::string m_jni_field_name; std::string m_jni_field_name;
#endif #endif
struct ScalingInfo {
f32 scale;
core::rect<s32> rect;
};
ScalingInfo getScalingInfo(v2u32 screensize, v2u32 base_size);
// This is set to true if the menu is currently processing a second-touch event. // This is set to true if the menu is currently processing a second-touch event.
bool m_second_touch = false; bool m_second_touch = false;
// This is set to true if the menu is currently processing a mouse event // This is set to true if the menu is currently processing a mouse event