1
0
mirror of https://github.com/ppy/osu.git synced 2024-11-09 09:37:42 +08:00
osu-lazer/osu.Game/Skinning/LegacyColourCompatibility.cs

Ignoring revisions in .git-blame-ignore-revs. Click here to bypass and see the normal blame view.

47 lines
1.8 KiB
C#
Raw Normal View History

2020-08-25 14:16:41 +08:00
// Copyright (c) ppy Pty Ltd <contact@ppy.sh>. Licensed under the MIT Licence.
// See the LICENCE file in the repository root for full licence text.
using osu.Framework.Graphics;
using osuTK.Graphics;
namespace osu.Game.Skinning
{
/// <summary>
/// Compatibility methods to apply osu!stable quirks to colours. Should be used for legacy skins only.
2020-08-25 14:16:41 +08:00
/// </summary>
public static class LegacyColourCompatibility
{
/// <summary>
/// Forces an alpha of 1 if a given <see cref="Color4"/> is fully transparent.
/// </summary>
/// <remarks>
/// This is equivalent to setting colour post-constructor in osu!stable.
/// </remarks>
/// <param name="colour">The <see cref="Color4"/> to disallow zero alpha on.</param>
/// <returns>The resultant <see cref="Color4"/>.</returns>
public static Color4 DisallowZeroAlpha(Color4 colour)
{
if (colour.A == 0)
colour.A = 1;
return colour;
}
/// <summary>
/// Applies a <see cref="Color4"/> to a <see cref="Drawable"/>, doubling the alpha value into the <see cref="Drawable.Alpha"/> property.
/// </summary>
/// <remarks>
/// This is equivalent to setting colour in the constructor in osu!stable.
/// </remarks>
/// <param name="drawable">The <see cref="Drawable"/> to apply the colour to.</param>
/// <param name="colour">The <see cref="Color4"/> to apply.</param>
/// <returns>The given <paramref name="drawable"/>.</returns>
public static T ApplyWithDoubledAlpha<T>(T drawable, Color4 colour)
where T : Drawable
{
drawable.Alpha = colour.A;
drawable.Colour = DisallowZeroAlpha(colour);
return drawable;
}
}
}