mirror of
https://github.com/minetest/minetest.git
synced 2024-12-27 00:17:29 +01:00
Scale C++ menus down to fit the window (#14690)
This commit is contained in:
parent
d5fc040d2d
commit
728f643ea7
@ -107,13 +107,9 @@ void GUIKeyChangeMenu::regenerateGui(v2u32 screensize)
|
||||
removeAllChildren();
|
||||
key_used_text = nullptr;
|
||||
|
||||
const float s = m_gui_scale;
|
||||
DesiredRect = core::rect<s32>(
|
||||
screensize.X / 2 - 835 * s / 2,
|
||||
screensize.Y / 2 - 430 * s / 2,
|
||||
screensize.X / 2 + 835 * s / 2,
|
||||
screensize.Y / 2 + 430 * s / 2
|
||||
);
|
||||
ScalingInfo info = getScalingInfo(screensize, v2u32(835, 430));
|
||||
const float s = info.scale;
|
||||
DesiredRect = info.rect;
|
||||
recalculateAbsolutePosition(false);
|
||||
|
||||
v2s32 size = DesiredRect.getSize();
|
||||
|
@ -66,13 +66,9 @@ void GUIOpenURLMenu::regenerateGui(v2u32 screensize)
|
||||
/*
|
||||
Calculate new sizes and positions
|
||||
*/
|
||||
const float s = m_gui_scale;
|
||||
DesiredRect = core::rect<s32>(
|
||||
screensize.X / 2 - 580 * s / 2,
|
||||
screensize.Y / 2 - 250 * s / 2,
|
||||
screensize.X / 2 + 580 * s / 2,
|
||||
screensize.Y / 2 + 250 * s / 2
|
||||
);
|
||||
ScalingInfo info = getScalingInfo(screensize, v2u32(580, 250));
|
||||
const float s = info.scale;
|
||||
DesiredRect = info.rect;
|
||||
recalculateAbsolutePosition(false);
|
||||
|
||||
v2s32 size = DesiredRect.getSize();
|
||||
|
@ -62,14 +62,9 @@ void GUIPasswordChange::regenerateGui(v2u32 screensize)
|
||||
/*
|
||||
Calculate new sizes and positions
|
||||
*/
|
||||
const float s = m_gui_scale;
|
||||
|
||||
DesiredRect = core::rect<s32>(
|
||||
screensize.X / 2 - 580 * s / 2,
|
||||
screensize.Y / 2 - 300 * s / 2,
|
||||
screensize.X / 2 + 580 * s / 2,
|
||||
screensize.Y / 2 + 300 * s / 2
|
||||
);
|
||||
ScalingInfo info = getScalingInfo(screensize, v2u32(580, 300));
|
||||
const float s = info.scale;
|
||||
DesiredRect = info.rect;
|
||||
recalculateAbsolutePosition(false);
|
||||
|
||||
v2s32 size = DesiredRect.getSize();
|
||||
|
@ -54,13 +54,9 @@ void GUIVolumeChange::regenerateGui(v2u32 screensize)
|
||||
/*
|
||||
Calculate new sizes and positions
|
||||
*/
|
||||
const float s = m_gui_scale;
|
||||
DesiredRect = core::rect<s32>(
|
||||
screensize.X / 2 - 380 * s / 2,
|
||||
screensize.Y / 2 - 200 * s / 2,
|
||||
screensize.X / 2 + 380 * s / 2,
|
||||
screensize.Y / 2 + 200 * s / 2
|
||||
);
|
||||
ScalingInfo info = getScalingInfo(screensize, v2u32(380, 200));
|
||||
const float s = info.scale;
|
||||
DesiredRect = info.rect;
|
||||
recalculateAbsolutePosition(false);
|
||||
|
||||
v2s32 size = DesiredRect.getSize();
|
||||
|
@ -398,3 +398,17 @@ porting::AndroidDialogState GUIModalMenu::getAndroidUIInputState()
|
||||
return porting::getInputDialogState();
|
||||
}
|
||||
#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;
|
||||
#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.
|
||||
bool m_second_touch = false;
|
||||
// This is set to true if the menu is currently processing a mouse event
|
||||
|
Loading…
Reference in New Issue
Block a user