mirror of
https://github.com/ppy/osu.git
synced 2025-02-15 17:33:02 +08:00
Move foreground colour helper into OsuColour
This commit is contained in:
parent
97573fb11d
commit
0825fc57a9
@ -94,6 +94,18 @@ namespace osu.Game.Graphics
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Returns a foreground text colour that is supposed to contrast well with
|
||||||
|
/// the supplied <paramref name="backgroundColour"/>.
|
||||||
|
/// </summary>
|
||||||
|
public static Color4 ForegroundTextColourFor(Color4 backgroundColour)
|
||||||
|
{
|
||||||
|
// formula taken from the RGB->YIQ conversions: https://en.wikipedia.org/wiki/YIQ
|
||||||
|
// brightness here is equivalent to the Y component in the above colour model, which is a rough estimate of lightness.
|
||||||
|
float brightness = 0.299f * backgroundColour.R + 0.587f * backgroundColour.G + 0.114f * backgroundColour.B;
|
||||||
|
return Gray(brightness > 0.5f ? 0.2f : 0.9f);
|
||||||
|
}
|
||||||
|
|
||||||
// See https://github.com/ppy/osu-web/blob/master/resources/assets/less/colors.less
|
// See https://github.com/ppy/osu-web/blob/master/resources/assets/less/colors.less
|
||||||
public readonly Color4 PurpleLighter = Color4Extensions.FromHex(@"eeeeff");
|
public readonly Color4 PurpleLighter = Color4Extensions.FromHex(@"eeeeff");
|
||||||
public readonly Color4 PurpleLight = Color4Extensions.FromHex(@"aa88ff");
|
public readonly Color4 PurpleLight = Color4Extensions.FromHex(@"aa88ff");
|
||||||
|
@ -10,7 +10,6 @@ using osu.Framework.Graphics.Shapes;
|
|||||||
using osu.Framework.Graphics.UserInterface;
|
using osu.Framework.Graphics.UserInterface;
|
||||||
using osu.Framework.Localisation;
|
using osu.Framework.Localisation;
|
||||||
using osu.Game.Graphics.Sprites;
|
using osu.Game.Graphics.Sprites;
|
||||||
using osu.Game.Utils;
|
|
||||||
using osuTK;
|
using osuTK;
|
||||||
using osuTK.Graphics;
|
using osuTK.Graphics;
|
||||||
|
|
||||||
@ -102,7 +101,7 @@ namespace osu.Game.Graphics.UserInterfaceV2
|
|||||||
{
|
{
|
||||||
fill.Colour = current.Value;
|
fill.Colour = current.Value;
|
||||||
colourHexCode.Text = current.Value.ToHex();
|
colourHexCode.Text = current.Value.ToHex();
|
||||||
colourHexCode.Colour = ColourUtils.ForegroundTextColourFor(current.Value);
|
colourHexCode.Colour = OsuColour.ForegroundTextColourFor(current.Value);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -21,7 +21,6 @@ using osu.Game.Rulesets.Edit;
|
|||||||
using osu.Game.Rulesets.Objects;
|
using osu.Game.Rulesets.Objects;
|
||||||
using osu.Game.Rulesets.Objects.Types;
|
using osu.Game.Rulesets.Objects.Types;
|
||||||
using osu.Game.Skinning;
|
using osu.Game.Skinning;
|
||||||
using osu.Game.Utils;
|
|
||||||
using osuTK;
|
using osuTK;
|
||||||
using osuTK.Graphics;
|
using osuTK.Graphics;
|
||||||
|
|
||||||
@ -159,7 +158,7 @@ namespace osu.Game.Screens.Edit.Compose.Components.Timeline
|
|||||||
circle.Colour = comboColour;
|
circle.Colour = comboColour;
|
||||||
|
|
||||||
var col = circle.Colour.TopLeft.Linear;
|
var col = circle.Colour.TopLeft.Linear;
|
||||||
colouredComponents.Colour = ColourUtils.ForegroundTextColourFor(col);
|
colouredComponents.Colour = OsuColour.ForegroundTextColourFor(col);
|
||||||
}
|
}
|
||||||
|
|
||||||
protected override void Update()
|
protected override void Update()
|
||||||
|
@ -1,23 +0,0 @@
|
|||||||
// 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.Game.Graphics;
|
|
||||||
using osuTK.Graphics;
|
|
||||||
|
|
||||||
namespace osu.Game.Utils
|
|
||||||
{
|
|
||||||
public static class ColourUtils
|
|
||||||
{
|
|
||||||
/// <summary>
|
|
||||||
/// Returns a foreground text colour that is supposed to contrast well on top of
|
|
||||||
/// the supplied <paramref name="backgroundColour"/>.
|
|
||||||
/// </summary>
|
|
||||||
public static Color4 ForegroundTextColourFor(Color4 backgroundColour)
|
|
||||||
{
|
|
||||||
// formula taken from the RGB->YIQ conversions: https://en.wikipedia.org/wiki/YIQ
|
|
||||||
// brightness here is equivalent to the Y component in the above colour model, which is a rough estimate of lightness.
|
|
||||||
float brightness = 0.299f * backgroundColour.R + 0.587f * backgroundColour.G + 0.114f * backgroundColour.B;
|
|
||||||
return OsuColour.Gray(brightness > 0.5f ? 0.2f : 0.9f);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
Loading…
Reference in New Issue
Block a user