mirror of
https://github.com/ppy/osu
synced 2024-12-14 10:57:41 +00:00
Use helper methods instead of local valueAt() method
This commit is contained in:
parent
9e805dcd44
commit
140d29d537
@ -3,6 +3,7 @@
|
|||||||
|
|
||||||
using System;
|
using System;
|
||||||
using osu.Framework.Extensions.Color4Extensions;
|
using osu.Framework.Extensions.Color4Extensions;
|
||||||
|
using osu.Framework.Utils;
|
||||||
using osu.Game.Rulesets.Osu.Objects;
|
using osu.Game.Rulesets.Osu.Objects;
|
||||||
using osu.Game.Rulesets.Osu.Skinning.Default;
|
using osu.Game.Rulesets.Osu.Skinning.Default;
|
||||||
using osuTK.Graphics;
|
using osuTK.Graphics;
|
||||||
@ -36,13 +37,14 @@ namespace osu.Game.Rulesets.Osu.Skinning.Legacy
|
|||||||
|
|
||||||
position -= realBorderPortion;
|
position -= realBorderPortion;
|
||||||
|
|
||||||
Color4 outerColour = AccentColour.Darken(0.1f);
|
// Stable interpolates slider body colour directly in sRGB space, and because
|
||||||
Color4 innerColour = lighten(AccentColour, 0.5f);
|
// Interpolation.ValueAt() uses linear space, we have to counteract applying it
|
||||||
|
// by calling ToSRGB() on the input colours, and ToLinear() on the resulting colour.
|
||||||
|
|
||||||
// Stable doesn't use linear space / gamma-correct colour interpolation
|
Color4 outerColour = AccentColour.Darken(0.1f).ToSRGB();
|
||||||
// for slider bodies, so we can't use Interpolation.ValueAt().
|
Color4 innerColour = lighten(AccentColour, 0.5f).ToSRGB();
|
||||||
// Instead, we use a local method that interpolates between the colours directly in sRGB space.
|
|
||||||
return valueAt(position / realGradientPortion, outerColour, innerColour, 0, 1);
|
return Interpolation.ValueAt(position / realGradientPortion, outerColour, innerColour, 0, 1).ToLinear();
|
||||||
}
|
}
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
@ -57,26 +59,6 @@ namespace osu.Game.Rulesets.Osu.Skinning.Legacy
|
|||||||
Math.Min(1, color.B * (1 + 0.5f * amount) + 1 * amount),
|
Math.Min(1, color.B * (1 + 0.5f * amount) + 1 * amount),
|
||||||
color.A);
|
color.A);
|
||||||
}
|
}
|
||||||
|
|
||||||
private static Color4 valueAt(double time, Color4 startColour, Color4 endColour, double startTime, double endTime)
|
|
||||||
{
|
|
||||||
if (startColour == endColour)
|
|
||||||
return startColour;
|
|
||||||
|
|
||||||
double current = time - startTime;
|
|
||||||
double duration = endTime - startTime;
|
|
||||||
|
|
||||||
if (duration == 0 || current == 0)
|
|
||||||
return startColour;
|
|
||||||
|
|
||||||
float t = (float)Math.Max(0, Math.Min(1, current / duration));
|
|
||||||
|
|
||||||
return new Color4(
|
|
||||||
startColour.R + t * (endColour.R - startColour.R),
|
|
||||||
startColour.G + t * (endColour.G - startColour.G),
|
|
||||||
startColour.B + t * (endColour.B - startColour.B),
|
|
||||||
startColour.A + t * (endColour.A - startColour.A));
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user