mirror of
https://github.com/ppy/osu.git
synced 2024-11-06 09:07:25 +08:00
Add null check and simplify scaling conditional logic via switch
This commit is contained in:
parent
eca63980d2
commit
36c557c752
@ -84,7 +84,6 @@ namespace osu.Game.Skinning
|
|||||||
scaling.Invalidate();
|
scaling.Invalidate();
|
||||||
Drawable.Origin = Anchor.Centre;
|
Drawable.Origin = Anchor.Centre;
|
||||||
Drawable.Anchor = Anchor.Centre;
|
Drawable.Anchor = Anchor.Centre;
|
||||||
|
|
||||||
InternalChild = Drawable;
|
InternalChild = Drawable;
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
@ -97,21 +96,31 @@ namespace osu.Game.Skinning
|
|||||||
|
|
||||||
if (!scaling.IsValid)
|
if (!scaling.IsValid)
|
||||||
{
|
{
|
||||||
if (Drawable != null && confineMode != ConfineMode.NoScaling && (!isDefault || ApplySizeRestrictionsToDefault))
|
try
|
||||||
{
|
{
|
||||||
bool applyScaling = confineMode == ConfineMode.ScaleToFit ||
|
if (Drawable == null || (isDefault && !ApplySizeRestrictionsToDefault)) return;
|
||||||
(confineMode == ConfineMode.ScaleDownToFit && (Drawable.DrawSize.X > DrawSize.X || Drawable.DrawSize.Y > DrawSize.Y));
|
|
||||||
|
|
||||||
if (applyScaling)
|
switch (confineMode)
|
||||||
{
|
{
|
||||||
Drawable.RelativeSizeAxes = Axes.Both;
|
case ConfineMode.NoScaling:
|
||||||
Drawable.Size = Vector2.One;
|
return;
|
||||||
Drawable.Scale = Vector2.One;
|
|
||||||
Drawable.FillMode = FillMode.Fit;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
scaling.Validate();
|
case ConfineMode.ScaleDownToFit:
|
||||||
|
if (Drawable.DrawSize.X <= DrawSize.X && Drawable.DrawSize.Y <= DrawSize.Y)
|
||||||
|
return;
|
||||||
|
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
|
||||||
|
Drawable.RelativeSizeAxes = Axes.Both;
|
||||||
|
Drawable.Size = Vector2.One;
|
||||||
|
Drawable.Scale = Vector2.One;
|
||||||
|
Drawable.FillMode = FillMode.Fit;
|
||||||
|
}
|
||||||
|
finally
|
||||||
|
{
|
||||||
|
scaling.Validate();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user