From 303bd41765452192a763a14a2d0a2cc4be258890 Mon Sep 17 00:00:00 2001 From: Huo Yaoyuan Date: Mon, 24 Oct 2016 13:13:49 +0800 Subject: [PATCH] Background scale. --- osu.Game/Overlays/MusicController.cs | 22 ++++++++++++++++------ 1 file changed, 16 insertions(+), 6 deletions(-) diff --git a/osu.Game/Overlays/MusicController.cs b/osu.Game/Overlays/MusicController.cs index e17d33e20c..506e33df52 100644 --- a/osu.Game/Overlays/MusicController.cs +++ b/osu.Game/Overlays/MusicController.cs @@ -8,6 +8,7 @@ using osu.Framework; using osu.Framework.Graphics; using osu.Framework.Graphics.Containers; using osu.Framework.Graphics.Sprites; +using osu.Framework.Graphics.Textures; using osu.Framework.Input; using osu.Game.Graphics; @@ -15,7 +16,7 @@ namespace osu.Game.Overlays { public class MusicController : OverlayContainer { - private Sprite background; + private Sprite backgroundSprite; private Box progress; private SpriteText title, artist; public override void Load(BaseGame game) @@ -27,11 +28,7 @@ namespace osu.Game.Overlays Masking = true; Children = new Drawable[] { - background = new Sprite - { - RelativeSizeAxes = Axes.Both, - Texture = game.Textures.Get(@"Backgrounds/bg4")//placeholder - }, + backgroundSprite = getScaledSprite(game.Textures.Get(@"Backgrounds/bg4")),//placeholder new Box { RelativeSizeAxes = Axes.Both, @@ -107,6 +104,19 @@ namespace osu.Game.Overlays }; } + private Sprite getScaledSprite(Texture background) + { + Sprite scaledSprite = new Sprite + { + Origin = Anchor.Centre, + Anchor = Anchor.Centre, + Texture = background, + Depth = float.MinValue + }; + scaledSprite.Scale = new Vector2(Math.Max(DrawSize.X / scaledSprite.DrawSize.X, DrawSize.Y / scaledSprite.DrawSize.Y)); + return scaledSprite; + } + //placeholder for toggling protected override void PopIn() => FadeIn(500);