mirror of
https://github.com/osukey/osukey.git
synced 2025-07-01 16:29:58 +09:00
Fix shadow on SpriteIcon being a bit off
This commit is contained in:
@ -1,6 +1,7 @@
|
|||||||
// Copyright (c) 2007-2017 ppy Pty Ltd <contact@ppy.sh>.
|
// Copyright (c) 2007-2017 ppy Pty Ltd <contact@ppy.sh>.
|
||||||
// Licensed under the MIT Licence - https://raw.githubusercontent.com/ppy/osu/master/LICENCE
|
// Licensed under the MIT Licence - https://raw.githubusercontent.com/ppy/osu/master/LICENCE
|
||||||
|
|
||||||
|
using System;
|
||||||
using osu.Framework.Allocation;
|
using osu.Framework.Allocation;
|
||||||
using osu.Framework.Graphics.Containers;
|
using osu.Framework.Graphics.Containers;
|
||||||
using osu.Framework.Graphics.Sprites;
|
using osu.Framework.Graphics.Sprites;
|
||||||
@ -18,18 +19,19 @@ namespace osu.Game.Graphics
|
|||||||
|
|
||||||
public SpriteIcon()
|
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[]
|
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
|
spriteMain = new Sprite
|
||||||
{
|
{
|
||||||
Anchor = Anchor.Centre,
|
Anchor = Anchor.Centre,
|
||||||
@ -60,10 +62,32 @@ namespace osu.Game.Graphics
|
|||||||
Size = new Vector2(texture?.DisplayWidth ?? 0, texture?.DisplayHeight ?? 0);
|
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
|
public bool Shadow
|
||||||
{
|
{
|
||||||
get { return spriteShadow.IsPresent; }
|
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;
|
private FontAwesome icon;
|
||||||
|
Reference in New Issue
Block a user