2023-01-22 04:02:33 +00:00
|
|
|
using System;
|
2021-12-10 08:15:04 +00:00
|
|
|
using System.Drawing;
|
|
|
|
|
|
|
|
namespace PKHeX.Drawing;
|
|
|
|
|
2023-01-22 04:02:33 +00:00
|
|
|
/// <summary>
|
|
|
|
/// Utility class for manipulating <see cref="Color"/> values.
|
|
|
|
/// </summary>
|
2021-12-10 08:15:04 +00:00
|
|
|
public static class ColorUtil
|
|
|
|
{
|
2023-01-22 04:02:33 +00:00
|
|
|
private const byte MaxStat = 180; // shift the green cap down
|
|
|
|
private const byte MinStat = 0;
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
/// Gets the <see cref="Color"/> value for the specified <see cref="stat"/> value.
|
|
|
|
/// </summary>
|
|
|
|
public static Color ColorBaseStat(int stat)
|
2021-12-10 08:15:04 +00:00
|
|
|
{
|
2023-01-22 04:02:33 +00:00
|
|
|
float x = (100f * stat) / MaxStat;
|
2021-12-10 08:15:04 +00:00
|
|
|
if (x > 100)
|
|
|
|
x = 100;
|
|
|
|
double red = 255f * (x > 50 ? 1 - (2 * (x - 50) / 100.0) : 1.0);
|
|
|
|
double green = 255f * (x > 50 ? 1.0 : 2 * x / 100.0);
|
|
|
|
|
|
|
|
return Blend(Color.FromArgb((int)red, (int)green, 0), Color.White, 0.4);
|
|
|
|
}
|
|
|
|
|
2023-01-22 04:02:33 +00:00
|
|
|
public static Color ColorBaseStatTotal(int tot)
|
|
|
|
{
|
|
|
|
const byte sumShiftDown = 175;
|
|
|
|
const float sumDivisor = 3f;
|
|
|
|
var sumToSingle = Math.Max(MinStat, tot - sumShiftDown) / sumDivisor;
|
|
|
|
return ColorBaseStat((int)sumToSingle);
|
|
|
|
}
|
2021-12-10 08:15:04 +00:00
|
|
|
|
|
|
|
public static Color Blend(Color color, Color backColor, double amount)
|
|
|
|
{
|
|
|
|
byte r = (byte)((color.R * amount) + (backColor.R * (1 - amount)));
|
|
|
|
byte g = (byte)((color.G * amount) + (backColor.G * (1 - amount)));
|
|
|
|
byte b = (byte)((color.B * amount) + (backColor.B * (1 - amount)));
|
|
|
|
return Color.FromArgb(r, g, b);
|
|
|
|
}
|
|
|
|
}
|