Skip to content

Commit

Permalink
Merge pull request #31371 from frenzibyte/ios-ui-scale
Browse files Browse the repository at this point in the history
Improve default UI scale on iOS
  • Loading branch information
peppy authored Feb 14, 2025
2 parents 071a4ba + 27b9a6b commit ff81096
Show file tree
Hide file tree
Showing 6 changed files with 50 additions and 20 deletions.
10 changes: 10 additions & 0 deletions .idea/.idea.osu.Android/.idea/deploymentTargetSelector.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

3 changes: 3 additions & 0 deletions osu.Android/OsuGameAndroid.cs
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
using osu.Game.Screens;
using osu.Game.Updater;
using osu.Game.Utils;
using osuTK;

namespace osu.Android
{
Expand All @@ -20,6 +21,8 @@ public partial class OsuGameAndroid : OsuGame
[Cached]
private readonly OsuGameActivity gameActivity;

protected override Vector2 ScalingContainerTargetDrawSize => new Vector2(1024, 1024 * DrawHeight / DrawWidth);

public OsuGameAndroid(OsuGameActivity activity)
: base(null)
{
Expand Down
13 changes: 8 additions & 5 deletions osu.Game/Configuration/OsuConfigManager.cs
Original file line number Diff line number Diff line change
Expand Up @@ -238,7 +238,7 @@ protected override bool CheckLookupContainsPrivateInformation(OsuSetting lookup)

public void Migrate()
{
// arrives as 2020.123.0
// arrives as 2020.123.0-lazer
string rawVersion = Get<string>(OsuSetting.Version);

if (rawVersion.Length < 6)
Expand All @@ -251,11 +251,14 @@ public void Migrate()
if (!int.TryParse(pieces[0], out int year)) return;
if (!int.TryParse(pieces[1], out int monthDay)) return;

// ReSharper disable once UnusedVariable
int combined = (year * 10000) + monthDay;
int combined = year * 10000 + monthDay;

// migrations can be added here using a condition like:
// if (combined < 20220103) { performMigration() }
if (combined < 20250214)
{
// UI scaling on mobile platforms has been internally adjusted such that 1x UI scale looks correctly zoomed in than before.
if (RuntimeInfo.IsMobile)
GetBindable<float>(OsuSetting.UIScale).SetDefault();
}
}

public override TrackedSettings CreateTrackedSettings()
Expand Down
34 changes: 19 additions & 15 deletions osu.Game/Graphics/Containers/ScalingContainer.cs
Original file line number Diff line number Diff line change
@@ -1,8 +1,6 @@
// Copyright (c) ppy Pty Ltd <contact@ppy.sh>. Licensed under the MIT Licence.
// See the LICENCE file in the repository root for full licence text.

#nullable disable

using osu.Framework.Allocation;
using osu.Framework.Bindables;
using osu.Framework.Graphics;
Expand All @@ -26,17 +24,17 @@ public partial class ScalingContainer : Container
{
internal const float TRANSITION_DURATION = 500;

private Bindable<float> sizeX;
private Bindable<float> sizeY;
private Bindable<float> posX;
private Bindable<float> posY;
private Bindable<bool> applySafeAreaPadding;
private Bindable<float> sizeX = null!;
private Bindable<float> sizeY = null!;
private Bindable<float> posX = null!;
private Bindable<float> posY = null!;
private Bindable<bool> applySafeAreaPadding = null!;

private Bindable<MarginPadding> safeAreaPadding;
private Bindable<MarginPadding> safeAreaPadding = null!;

private readonly ScalingMode? targetMode;

private Bindable<ScalingMode> scalingMode;
private Bindable<ScalingMode> scalingMode = null!;

private readonly Container content;
protected override Container<Drawable> Content => content;
Expand All @@ -45,9 +43,9 @@ public partial class ScalingContainer : Container

private readonly Container sizableContainer;

private BackgroundScreenStack backgroundStack;
private BackgroundScreenStack? backgroundStack;

private Bindable<float> scalingMenuBackgroundDim;
private Bindable<float> scalingMenuBackgroundDim = null!;

private RectangleF? customRect;
private bool customRectIsRelativePosition;
Expand Down Expand Up @@ -88,7 +86,8 @@ public ScalingContainer(ScalingMode? targetMode = null)
public partial class ScalingDrawSizePreservingFillContainer : DrawSizePreservingFillContainer
{
private readonly bool applyUIScale;
private Bindable<float> uiScale;

private Bindable<float>? uiScale;

protected float CurrentScale { get; private set; } = 1;

Expand All @@ -99,6 +98,9 @@ public ScalingDrawSizePreservingFillContainer(bool applyUIScale)
this.applyUIScale = applyUIScale;
}

[Resolved(canBeNull: true)]
private OsuGame? game { get; set; }

[BackgroundDependencyLoader]
private void load(OsuConfigManager osuConfig)
{
Expand All @@ -111,6 +113,8 @@ private void load(OsuConfigManager osuConfig)

protected override void Update()
{
if (game != null)
TargetDrawSize = game.ScalingContainerTargetDrawSize;
Scale = new Vector2(CurrentScale);
Size = new Vector2(1 / CurrentScale);

Expand Down Expand Up @@ -233,13 +237,13 @@ public override void OnEntering(ScreenTransitionEvent e)
private partial class SizeableAlwaysInputContainer : Container
{
[Resolved]
private GameHost host { get; set; }
private GameHost host { get; set; } = null!;

[Resolved]
private ISafeArea safeArea { get; set; }
private ISafeArea safeArea { get; set; } = null!;

[Resolved]
private OsuConfigManager config { get; set; }
private OsuConfigManager config { get; set; } = null!;

private readonly bool confineHostCursor;
private readonly LayoutValue cursorRectCache = new LayoutValue(Invalidation.RequiredParentSizeToFit);
Expand Down
7 changes: 7 additions & 0 deletions osu.Game/OsuGame.cs
Original file line number Diff line number Diff line change
Expand Up @@ -72,6 +72,7 @@
using osu.Game.Updater;
using osu.Game.Users;
using osu.Game.Utils;
using osuTK;
using osuTK.Graphics;
using Sentry;

Expand Down Expand Up @@ -813,6 +814,12 @@ public override Task Import(ImportTask[] imports, ImportParameters parameters =

protected virtual UpdateManager CreateUpdateManager() => new UpdateManager();

/// <summary>
/// Adjust the globally applied <see cref="DrawSizePreservingFillContainer.TargetDrawSize"/> in every <see cref="ScalingContainer"/>.
/// Useful for changing how the game handles different aspect ratios.
/// </summary>
protected internal virtual Vector2 ScalingContainerTargetDrawSize { get; } = new Vector2(1024, 768);

protected override Container CreateScalingContainer() => new ScalingContainer(ScalingMode.Everything);

#region Beatmap progression
Expand Down
3 changes: 3 additions & 0 deletions osu.iOS/OsuGameIOS.cs
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
using osu.Game.Screens;
using osu.Game.Updater;
using osu.Game.Utils;
using osuTK;
using UIKit;

namespace osu.iOS
Expand All @@ -22,6 +23,8 @@ public partial class OsuGameIOS : OsuGame

public override bool HideUnlicensedContent => true;

protected override Vector2 ScalingContainerTargetDrawSize => new Vector2(1024, 1024 * DrawHeight / DrawWidth);

public OsuGameIOS(AppDelegate appDelegate)
{
this.appDelegate = appDelegate;
Expand Down

0 comments on commit ff81096

Please sign in to comment.