mirror of
https://github.com/ppy/osu.git
synced 2024-11-11 11:37:28 +08:00
50 lines
1.5 KiB
C#
50 lines
1.5 KiB
C#
|
// Copyright (c) 2007-2018 ppy Pty Ltd <contact@ppy.sh>.
|
||
|
// Licensed under the MIT Licence - https://raw.githubusercontent.com/ppy/osu/master/LICENCE
|
||
|
|
||
|
using osu.Framework.Graphics;
|
||
|
using osu.Framework.Graphics.Containers;
|
||
|
using OpenTK;
|
||
|
|
||
|
namespace osu.Game.Rulesets.Osu.UI
|
||
|
{
|
||
|
public class PlayfieldLayer : Container
|
||
|
{
|
||
|
protected override Container<Drawable> Content => content;
|
||
|
private readonly Container content;
|
||
|
|
||
|
public PlayfieldLayer()
|
||
|
{
|
||
|
InternalChild = new Container
|
||
|
{
|
||
|
Anchor = Anchor.Centre,
|
||
|
Origin = Anchor.Centre,
|
||
|
RelativeSizeAxes = Axes.Both,
|
||
|
FillMode = FillMode.Fit,
|
||
|
FillAspectRatio = 4f / 3,
|
||
|
Child = content = new ScalingContainer(OsuPlayfield.BASE_SIZE.X) { RelativeSizeAxes = Axes.Both }
|
||
|
};
|
||
|
}
|
||
|
|
||
|
/// <summary>
|
||
|
/// A <see cref="Container"/> which scales its content relative to a target width.
|
||
|
/// </summary>
|
||
|
private class ScalingContainer : Container
|
||
|
{
|
||
|
private readonly float targetWidth;
|
||
|
|
||
|
public ScalingContainer(float targetWidth)
|
||
|
{
|
||
|
this.targetWidth = targetWidth;
|
||
|
}
|
||
|
|
||
|
protected override void Update()
|
||
|
{
|
||
|
base.Update();
|
||
|
|
||
|
Scale = new Vector2(Parent.ChildSize.X / targetWidth);
|
||
|
Size = Vector2.Divide(Vector2.One, Scale);
|
||
|
}
|
||
|
}
|
||
|
}
|
||
|
}
|