From c3fa7f167fbf701f961b516e3527969bc93b8149 Mon Sep 17 00:00:00 2001 From: smoogipoo Date: Fri, 21 Sep 2018 15:53:06 +0900 Subject: [PATCH] Move aspect adjustments out of CatchPlayfield --- osu.Game.Rulesets.Catch/UI/CatchPlayfield.cs | 34 ++++++++------------ osu.Game.Rulesets.Catch/UI/PlayfieldLayer.cs | 33 ++++++++++++++++--- 2 files changed, 41 insertions(+), 26 deletions(-) diff --git a/osu.Game.Rulesets.Catch/UI/CatchPlayfield.cs b/osu.Game.Rulesets.Catch/UI/CatchPlayfield.cs index 8b5ec2df9b..b90b90f45a 100644 --- a/osu.Game.Rulesets.Catch/UI/CatchPlayfield.cs +++ b/osu.Game.Rulesets.Catch/UI/CatchPlayfield.cs @@ -33,31 +33,23 @@ public CatchPlayfield(BeatmapDifficulty difficulty, Func. // Licensed under the MIT Licence - https://raw.githubusercontent.com/ppy/osu/master/LICENCE +using osu.Framework.Graphics; using osu.Framework.Graphics.Containers; using OpenTK; @@ -8,12 +9,34 @@ namespace osu.Game.Rulesets.Catch.UI { public class PlayfieldLayer : Container { - protected override void Update() - { - base.Update(); + protected override Container Content => content; + private readonly Container content; - Scale = new Vector2(Parent.ChildSize.X / CatchPlayfield.BASE_WIDTH); - Size = Vector2.Divide(Vector2.One, Scale); + public PlayfieldLayer() + { + InternalChild = new Container + { + Anchor = Anchor.Centre, + Origin = Anchor.Centre, + RelativeSizeAxes = Axes.Both, + FillMode = FillMode.Fit, + FillAspectRatio = 4f / 3, + Child = content = new ScalingContainer { RelativeSizeAxes = Axes.Both } + }; + } + + /// + /// A which scales its content relative to a target width. + /// + private class ScalingContainer : Container + { + protected override void Update() + { + base.Update(); + + Scale = new Vector2(Parent.ChildSize.X / CatchPlayfield.BASE_WIDTH); + Size = Vector2.Divide(Vector2.One, Scale); + } } } }