mirror of
https://github.com/kwsch/PKHeX.git
synced 2026-03-21 17:48:28 -05:00
Extract contest colors to static utility class
Fixes more hardcoded colors to SystemColors for easier darkmode handling
This commit is contained in:
parent
b5c29b3de8
commit
d047f02410
31
PKHeX.Drawing.PokeSprite/Util/ContestColor.cs
Normal file
31
PKHeX.Drawing.PokeSprite/Util/ContestColor.cs
Normal file
|
|
@ -0,0 +1,31 @@
|
|||
using System;
|
||||
using System.Drawing;
|
||||
|
||||
namespace PKHeX.Drawing.PokeSprite;
|
||||
|
||||
/// <summary>
|
||||
/// Utility class for getting the color of a contest category.
|
||||
/// </summary>
|
||||
public static class ContestColor
|
||||
{
|
||||
public static Color Cool => Color.FromArgb(248, 152, 096);
|
||||
public static Color Beauty => Color.FromArgb(128, 152, 248);
|
||||
public static Color Cute => Color.FromArgb(248, 168, 208);
|
||||
public static Color Clever => Color.FromArgb(112, 224, 112);
|
||||
public static Color Tough => Color.FromArgb(248, 240, 056);
|
||||
|
||||
/// <summary>
|
||||
/// Retrieves a predefined color based on the specified index.
|
||||
/// </summary>
|
||||
/// <param name="index">The index of the color to retrieve. Valid values are 0 through 4.</param>
|
||||
/// <exception cref="ArgumentOutOfRangeException">Thrown if <paramref name="index"/> is less than 0 or greater than 4.</exception>
|
||||
public static Color GetColor(int index) => index switch
|
||||
{
|
||||
0 => Cool,
|
||||
1 => Beauty,
|
||||
2 => Cute,
|
||||
3 => Clever,
|
||||
4 => Tough,
|
||||
_ => throw new ArgumentOutOfRangeException(nameof(index), index, null),
|
||||
};
|
||||
}
|
||||
|
|
@ -167,7 +167,7 @@ private void NUD_Scale_ValueChanged(object sender, EventArgs e)
|
|||
private void SetLabelColorHeightWeight(Control label)
|
||||
{
|
||||
if (scale is not null)
|
||||
label.ForeColor = Color.Gray; // not indicative of actual size
|
||||
label.ForeColor = SystemColors.ControlDark; // not indicative of actual size
|
||||
else
|
||||
label.ResetForeColor();
|
||||
}
|
||||
|
|
|
|||
|
|
@ -1,6 +1,7 @@
|
|||
using System.Drawing;
|
||||
using System.Drawing.Drawing2D;
|
||||
using System.Windows.Forms;
|
||||
using PKHeX.Drawing.PokeSprite;
|
||||
|
||||
namespace PKHeX.WinForms.Controls;
|
||||
|
||||
|
|
@ -24,15 +25,7 @@ protected override void OnDrawItem(DrawItemEventArgs e)
|
|||
var bounds = GetTabRect(index);
|
||||
|
||||
var graphics = e.Graphics;
|
||||
if (e.State == DrawItemState.Selected)
|
||||
{
|
||||
using var brush = new LinearGradientBrush(bounds, Color.White, Color.LightGray, 90f);
|
||||
graphics.FillRectangle(brush, bounds);
|
||||
}
|
||||
else
|
||||
{
|
||||
e.DrawBackground();
|
||||
}
|
||||
DrawBackground(e, bounds, graphics);
|
||||
|
||||
using var flags = new StringFormat();
|
||||
flags.Alignment = StringAlignment.Center;
|
||||
|
|
@ -43,6 +36,19 @@ protected override void OnDrawItem(DrawItemEventArgs e)
|
|||
base.OnDrawItem(e);
|
||||
}
|
||||
|
||||
protected static void DrawBackground(DrawItemEventArgs e, Rectangle bounds, Graphics graphics)
|
||||
{
|
||||
if (e.State != DrawItemState.Selected)
|
||||
{
|
||||
e.DrawBackground();
|
||||
return;
|
||||
}
|
||||
|
||||
var (c1, c2) = (SystemColors.ControlLightLight, SystemColors.ScrollBar);
|
||||
using var brush = new LinearGradientBrush(bounds, c1, c2, 90f);
|
||||
graphics.FillRectangle(brush, bounds);
|
||||
}
|
||||
|
||||
protected override void ScaleControl(SizeF factor, BoundsSpecified specified)
|
||||
{
|
||||
base.ScaleControl(factor, specified);
|
||||
|
|
@ -60,12 +66,12 @@ public sealed class VerticalTabControlEntityEditor : VerticalTabControl
|
|||
/// </summary>
|
||||
private static readonly Color[] SelectedTags =
|
||||
[
|
||||
Color.FromArgb(248, 152, 096),
|
||||
Color.FromArgb(128, 152, 248),
|
||||
Color.FromArgb(248, 168, 208),
|
||||
Color.FromArgb(112, 224, 112),
|
||||
Color.FromArgb(248, 240, 056),
|
||||
Color.RosyBrown,
|
||||
ContestColor.Cool, // Main
|
||||
ContestColor.Beauty, // Met
|
||||
ContestColor.Cute, // Stats
|
||||
ContestColor.Clever, // Moves
|
||||
ContestColor.Tough, // Cosmetic
|
||||
Color.RosyBrown, // OT
|
||||
];
|
||||
|
||||
protected override void OnDrawItem(DrawItemEventArgs e)
|
||||
|
|
@ -76,22 +82,17 @@ protected override void OnDrawItem(DrawItemEventArgs e)
|
|||
var bounds = GetTabRect(index);
|
||||
|
||||
var graphics = e.Graphics;
|
||||
DrawBackground(e, bounds, graphics);
|
||||
if (e.State == DrawItemState.Selected)
|
||||
{
|
||||
var (c1, c2) = (SystemColors.ControlLightLight, SystemColors.ScrollBar);
|
||||
using var brush = new LinearGradientBrush(bounds, c1, c2, 90f);
|
||||
graphics.FillRectangle(brush, bounds);
|
||||
|
||||
// draw colored pip on the left side of the tab
|
||||
using var pipBrush = new SolidBrush(SelectedTags[index]);
|
||||
var pip = GetTabRect(index) with { Width = bounds.Width / 8 };
|
||||
graphics.FillRectangle(pipBrush, pip);
|
||||
|
||||
// shift text to the right to avoid pip overlap
|
||||
bounds = bounds with { Width = bounds.Width - pip.Width, X = bounds.X + pip.Width };
|
||||
}
|
||||
else
|
||||
{
|
||||
// no need to shift text
|
||||
e.DrawBackground();
|
||||
}
|
||||
|
||||
using var flags = new StringFormat();
|
||||
flags.Alignment = StringAlignment.Center;
|
||||
|
|
|
|||
|
|
@ -4,6 +4,7 @@
|
|||
using System.Text;
|
||||
using System.Windows.Forms;
|
||||
using PKHeX.Core;
|
||||
using PKHeX.Drawing.PokeSprite;
|
||||
using static System.Buffers.Binary.BinaryPrimitives;
|
||||
|
||||
namespace PKHeX.WinForms;
|
||||
|
|
@ -651,14 +652,7 @@ private void LoadPainting(int index)
|
|||
|
||||
PaintingIndex = index;
|
||||
|
||||
NUD_Painting.BackColor = index switch
|
||||
{
|
||||
0 => Color.FromArgb(248, 152, 096),
|
||||
1 => Color.FromArgb(128, 152, 248),
|
||||
2 => Color.FromArgb(248, 168, 208),
|
||||
3 => Color.FromArgb(112, 224, 112),
|
||||
_ => Color.FromArgb(248, 240, 056),
|
||||
};
|
||||
NUD_Painting.BackColor = ContestColor.GetColor(index);
|
||||
}
|
||||
|
||||
private void SavePainting(int index)
|
||||
|
|
|
|||
Loading…
Reference in New Issue
Block a user