mirror of
https://github.com/ppy/osu.git
synced 2025-01-28 02:43:19 +08:00
Use cache to ensure correct DrawSize when deciding scaling
This commit is contained in:
parent
74c961bcff
commit
9d091c96b8
@ -2,6 +2,7 @@
|
|||||||
// See the LICENCE file in the repository root for full licence text.
|
// See the LICENCE file in the repository root for full licence text.
|
||||||
|
|
||||||
using System;
|
using System;
|
||||||
|
using osu.Framework.Caching;
|
||||||
using osu.Framework.Graphics;
|
using osu.Framework.Graphics;
|
||||||
using osuTK;
|
using osuTK;
|
||||||
|
|
||||||
@ -55,6 +56,10 @@ namespace osu.Game.Skinning
|
|||||||
|
|
||||||
private readonly Func<string, T> createDefault;
|
private readonly Func<string, T> createDefault;
|
||||||
|
|
||||||
|
private readonly Cached scaling = new Cached();
|
||||||
|
|
||||||
|
private bool isDefault;
|
||||||
|
|
||||||
protected virtual T CreateDefault(string name) => createDefault(name);
|
protected virtual T CreateDefault(string name) => createDefault(name);
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
@ -66,7 +71,7 @@ namespace osu.Game.Skinning
|
|||||||
{
|
{
|
||||||
Drawable = skin.GetDrawableComponent(componentName);
|
Drawable = skin.GetDrawableComponent(componentName);
|
||||||
|
|
||||||
bool isDefault = false;
|
isDefault = false;
|
||||||
|
|
||||||
if (Drawable == null && allowFallback)
|
if (Drawable == null && allowFallback)
|
||||||
{
|
{
|
||||||
@ -76,7 +81,23 @@ namespace osu.Game.Skinning
|
|||||||
|
|
||||||
if (Drawable != null)
|
if (Drawable != null)
|
||||||
{
|
{
|
||||||
if (confineMode != ConfineMode.NoScaling && (!isDefault || ApplySizeRestrictionsToDefault))
|
scaling.Invalidate();
|
||||||
|
Drawable.Origin = Anchor.Centre;
|
||||||
|
Drawable.Anchor = Anchor.Centre;
|
||||||
|
|
||||||
|
InternalChild = Drawable;
|
||||||
|
}
|
||||||
|
else
|
||||||
|
ClearInternal();
|
||||||
|
}
|
||||||
|
|
||||||
|
protected override void Update()
|
||||||
|
{
|
||||||
|
base.Update();
|
||||||
|
|
||||||
|
if (!scaling.IsValid)
|
||||||
|
{
|
||||||
|
if (Drawable != null && confineMode != ConfineMode.NoScaling && (!isDefault || ApplySizeRestrictionsToDefault))
|
||||||
{
|
{
|
||||||
bool applyScaling = confineMode == ConfineMode.ScaleToFit ||
|
bool applyScaling = confineMode == ConfineMode.ScaleToFit ||
|
||||||
(confineMode == ConfineMode.ScaleDownToFit && (Drawable.DrawSize.X > DrawSize.X || Drawable.DrawSize.Y > DrawSize.Y));
|
(confineMode == ConfineMode.ScaleDownToFit && (Drawable.DrawSize.X > DrawSize.X || Drawable.DrawSize.Y > DrawSize.Y));
|
||||||
@ -90,13 +111,8 @@ namespace osu.Game.Skinning
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
Drawable.Origin = Anchor.Centre;
|
scaling.Validate();
|
||||||
Drawable.Anchor = Anchor.Centre;
|
|
||||||
|
|
||||||
InternalChild = Drawable;
|
|
||||||
}
|
}
|
||||||
else
|
|
||||||
ClearInternal();
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user