mirror of
https://github.com/ppy/osu.git
synced 2025-02-13 10:33:07 +08:00
Fix shadow on SpriteIcon being a bit off
This commit is contained in:
parent
c9b0177e09
commit
d7fede96ef
@ -1,6 +1,7 @@
|
||||
// Copyright (c) 2007-2017 ppy Pty Ltd <contact@ppy.sh>.
|
||||
// Licensed under the MIT Licence - https://raw.githubusercontent.com/ppy/osu/master/LICENCE
|
||||
|
||||
using System;
|
||||
using osu.Framework.Allocation;
|
||||
using osu.Framework.Graphics.Containers;
|
||||
using osu.Framework.Graphics.Sprites;
|
||||
@ -18,18 +19,19 @@ namespace osu.Game.Graphics
|
||||
|
||||
public SpriteIcon()
|
||||
{
|
||||
spriteShadow = new Sprite
|
||||
{
|
||||
Anchor = Anchor.Centre,
|
||||
Origin = Anchor.Centre,
|
||||
RelativeSizeAxes = Axes.Both,
|
||||
FillMode = FillMode.Fit,
|
||||
Depth = 2,
|
||||
Y = 2,
|
||||
Colour = new Color4(0f, 0f, 0f, 0.2f),
|
||||
};
|
||||
|
||||
InternalChildren = new[]
|
||||
{
|
||||
spriteShadow = new Sprite
|
||||
{
|
||||
Anchor = Anchor.Centre,
|
||||
Origin = Anchor.Centre,
|
||||
RelativeSizeAxes = Axes.Both,
|
||||
FillMode = FillMode.Fit,
|
||||
Position = new Vector2(0, 0.06f),
|
||||
Colour = new Color4(0f, 0f, 0f, 0.2f),
|
||||
Alpha = 0
|
||||
},
|
||||
spriteMain = new Sprite
|
||||
{
|
||||
Anchor = Anchor.Centre,
|
||||
@ -60,10 +62,32 @@ namespace osu.Game.Graphics
|
||||
Size = new Vector2(texture?.DisplayWidth ?? 0, texture?.DisplayHeight ?? 0);
|
||||
}
|
||||
|
||||
public override bool Invalidate(Invalidation invalidation = Invalidation.All, Drawable source = null, bool shallPropagate = true)
|
||||
{
|
||||
if ((invalidation & Invalidation.Colour) > 0)
|
||||
{
|
||||
//adjust shadow alpha based on highest component intensity to avoid muddy display of darker text.
|
||||
//squared result for quadratic fall-off seems to give the best result.
|
||||
var avgColour = (Color4)DrawInfo.Colour.AverageColour;
|
||||
|
||||
spriteShadow.Alpha = (float)Math.Pow(Math.Max(Math.Max(avgColour.R, avgColour.G), avgColour.B), 2);
|
||||
}
|
||||
|
||||
return base.Invalidate(invalidation, source, shallPropagate);
|
||||
}
|
||||
|
||||
public bool Shadow
|
||||
{
|
||||
get { return spriteShadow.IsPresent; }
|
||||
set { spriteShadow.Alpha = value ? 1 : 0; }
|
||||
set
|
||||
{
|
||||
if (value == (spriteShadow.IsAlive && spriteShadow.IsLoaded)) return;
|
||||
|
||||
if (value)
|
||||
AddInternal(spriteShadow);
|
||||
else
|
||||
RemoveInternal(spriteShadow);
|
||||
}
|
||||
}
|
||||
|
||||
private FontAwesome icon;
|
||||
|
Loading…
Reference in New Issue
Block a user