Use cache to ensure correct DrawSize when deciding scaling

This commit is contained in:
Dean Herbert 2019-07-18 17:52:50 +09:00
parent 74c961bcff
commit 9d091c96b8
1 changed files with 24 additions and 8 deletions

View File

@ -2,6 +2,7 @@
// See the LICENCE file in the repository root for full licence text.
using System;
using osu.Framework.Caching;
using osu.Framework.Graphics;
using osuTK;
@ -55,6 +56,10 @@ protected SkinnableDrawable(string name, Func<ISkinSource, bool> allowFallback =
private readonly Func<string, T> createDefault;
private readonly Cached scaling = new Cached();
private bool isDefault;
protected virtual T CreateDefault(string name) => createDefault(name);
/// <summary>
@ -66,7 +71,7 @@ protected override void SkinChanged(ISkinSource skin, bool allowFallback)
{
Drawable = skin.GetDrawableComponent(componentName);
bool isDefault = false;
isDefault = false;
if (Drawable == null && allowFallback)
{
@ -76,7 +81,23 @@ protected override void SkinChanged(ISkinSource skin, bool allowFallback)
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 ||
(confineMode == ConfineMode.ScaleDownToFit && (Drawable.DrawSize.X > DrawSize.X || Drawable.DrawSize.Y > DrawSize.Y));
@ -90,13 +111,8 @@ protected override void SkinChanged(ISkinSource skin, bool allowFallback)
}
}
Drawable.Origin = Anchor.Centre;
Drawable.Anchor = Anchor.Centre;
InternalChild = Drawable;
scaling.Validate();
}
else
ClearInternal();
}
}