using System.Drawing;
using System.Windows.Forms;
using static PKHeX.WinForms.Properties.Resources;
namespace PKHeX.WinForms.Controls;
public partial class GenderToggle : UserControl, IGenderToggle
{
public bool AllowClick { get; set; } = true;
private int Value;
public int Gender
{
get => Value;
set => Value = SetGender(value);
}
public GenderToggle() => InitializeComponent();
private static readonly Image[] GenderImages =
{
gender_0,
gender_1,
gender_2,
};
private int SetGender(int value)
{
if ((uint)value > 2)
value = 2;
if (Value != value)
BackgroundImage = GenderImages[value];
return value;
}
private void GenderToggle_Click(object sender, System.EventArgs e)
{
if (!AllowClick)
return;
ToggleGender();
}
public (bool CanToggle, int Value) ToggleGender()
{
if ((uint)Gender < 2)
return (true, Gender ^= 1);
return (false, Gender);
}
}
public interface IGenderToggle
{
///
/// Enables use of the built in click action.
///
bool AllowClick { get; set; }
///
/// Get or set the value the control displays.
///
int Gender { get; set; }
///
/// Manually flips the gender state if possible.
///
/// True if can toggle, and the resulting value.
(bool CanToggle, int Value) ToggleGender();
}