KAZIK/build/installer/PokerGameSetup/CasinoCardCheck.cs

257 lines
5.9 KiB
C#

using System;
using System.Drawing;
using System.Drawing.Drawing2D;
using System.Windows.Forms;
namespace PokerGameSetup;
internal sealed class CasinoCardCheck : Control
{
private bool isChecked;
private bool isLocked;
private bool isHovered;
private string title = "";
private string badge = "";
private string description = "";
public event EventHandler CheckedChanged;
public bool Checked
{
get => isChecked;
set
{
if (isChecked != value)
{
isChecked = value;
Invalidate();
CheckedChanged?.Invoke(this, EventArgs.Empty);
}
}
}
public bool Locked
{
get => isLocked;
set
{
isLocked = value;
Invalidate();
}
}
public string Title
{
get => title;
set
{
title = value;
Invalidate();
}
}
public string Badge
{
get => badge;
set
{
badge = value;
Invalidate();
}
}
public string Description
{
get => description;
set
{
description = value;
Invalidate();
}
}
public CasinoCardCheck()
{
SetStyle(ControlStyles.UserPaint | ControlStyles.AllPaintingInWmPaint | ControlStyles.OptimizedDoubleBuffer | ControlStyles.ResizeRedraw, true);
Cursor = Cursors.Hand;
Height = 64;
Width = 365;
}
protected override void OnMouseEnter(EventArgs e)
{
base.OnMouseEnter(e);
isHovered = true;
Invalidate();
}
protected override void OnMouseLeave(EventArgs e)
{
base.OnMouseLeave(e);
isHovered = false;
Invalidate();
}
protected override void OnClick(EventArgs e)
{
base.OnClick(e);
if (!isLocked)
{
Checked = !Checked;
}
}
protected override void OnPaint(PaintEventArgs e)
{
Graphics g = e.Graphics;
g.SmoothingMode = SmoothingMode.AntiAlias;
g.PixelOffsetMode = PixelOffsetMode.HighQuality;
Rectangle rect = new Rectangle(0, 0, Width - 1, Height - 1);
int cornerRadius = 6;
using (GraphicsPath cardPath = CreateRoundedRectangle(rect, cornerRadius))
{
// Background
Color bgColor;
Color borderColor;
if (isHovered && !isLocked)
{
bgColor = Color.FromArgb(34, 38, 41);
borderColor = isChecked ? Color.FromArgb(180, 150, 85) : Color.FromArgb(115, 95, 62);
}
else
{
bgColor = Color.FromArgb(24, 27, 29);
borderColor = isChecked ? Color.FromArgb(145, 120, 68) : Color.FromArgb(70, 60, 44);
}
using (SolidBrush bgBrush = new SolidBrush(bgColor))
{
g.FillPath(bgBrush, cardPath);
}
// Border
using (Pen borderPen = new Pen(borderColor, isChecked ? 1.4f : 1f))
{
g.DrawPath(borderPen, cardPath);
}
}
// Checkbox square (20x20)
int boxSize = 20;
int boxX = 14;
int boxY = (Height - boxSize) / 2;
Rectangle boxRect = new Rectangle(boxX, boxY, boxSize, boxSize);
using (GraphicsPath boxPath = CreateRoundedRectangle(boxRect, 4))
{
if (isChecked)
{
// Filled gold square
using (LinearGradientBrush goldBrush = new LinearGradientBrush(
boxRect,
Color.FromArgb(242, 212, 135),
Color.FromArgb(195, 155, 75),
90f))
{
g.FillPath(goldBrush, boxPath);
}
// Checkmark icon ✓
using (Pen checkPen = new Pen(Color.FromArgb(22, 18, 10), 2.2f))
{
checkPen.StartCap = LineCap.Round;
checkPen.EndCap = LineCap.Round;
g.DrawLines(checkPen, new Point[]
{
new Point(boxX + 4, boxY + 10),
new Point(boxX + 8, boxY + 15),
new Point(boxX + 15, boxY + 5)
});
}
}
else
{
// Empty box
using (SolidBrush emptyBrush = new SolidBrush(Color.FromArgb(18, 20, 22)))
{
g.FillPath(emptyBrush, boxPath);
}
using (Pen emptyBorder = new Pen(Color.FromArgb(110, 95, 65), 1.2f))
{
g.DrawPath(emptyBorder, boxPath);
}
}
}
// Texts layout
int textX = boxX + boxSize + 12;
int availWidth = Width - textX - 12;
// Badge drawing
if (!string.IsNullOrEmpty(badge))
{
using Font badgeFont = new Font("Segoe UI", 7.8f, FontStyle.Bold);
Size badgeSize = TextRenderer.MeasureText(badge, badgeFont);
int badgeW = badgeSize.Width + 10;
int badgeH = 18;
int badgeX = Width - badgeW - 12;
int badgeY = 12;
Rectangle badgeRect = new Rectangle(badgeX, badgeY, badgeW, badgeH);
using (GraphicsPath badgePath = CreateRoundedRectangle(badgeRect, 4))
{
using (SolidBrush badgeBg = new SolidBrush(isLocked ? Color.FromArgb(45, 55, 45) : Color.FromArgb(38, 35, 26)))
{
g.FillPath(badgeBg, badgePath);
}
using (Pen badgeBorder = new Pen(isLocked ? Color.FromArgb(90, 160, 110) : Color.FromArgb(160, 130, 70), 1f))
{
g.DrawPath(badgeBorder, badgePath);
}
}
TextRenderer.DrawText(g, badge, badgeFont, badgeRect, isLocked ? Color.FromArgb(120, 210, 140) : InstallerForm.Gold, TextFormatFlags.HorizontalCenter | TextFormatFlags.VerticalCenter);
availWidth = badgeX - textX - 6;
}
// Title
using (Font titleFont = new Font("Segoe UI", 10f, FontStyle.Bold))
{
Rectangle titleRect = new Rectangle(textX, 10, availWidth, 20);
Color titleColor = isChecked ? InstallerForm.Paper : Color.FromArgb(180, 185, 185);
TextRenderer.DrawText(g, title, titleFont, titleRect, titleColor, TextFormatFlags.Left | TextFormatFlags.VerticalCenter | TextFormatFlags.EndEllipsis);
}
// Description
if (!string.IsNullOrEmpty(description))
{
using (Font descFont = new Font("Segoe UI", 8.2f))
{
Rectangle descRect = new Rectangle(textX, 31, Width - textX - 12, Height - 34);
TextRenderer.DrawText(g, description, descFont, descRect, Color.FromArgb(145, 155, 152), TextFormatFlags.Left | TextFormatFlags.Top | TextFormatFlags.WordBreak);
}
}
}
private static GraphicsPath CreateRoundedRectangle(Rectangle r, int d)
{
GraphicsPath path = new GraphicsPath();
if (d <= 0)
{
path.AddRectangle(r);
return path;
}
int x = r.X;
int y = r.Y;
int w = r.Width;
int h = r.Height;
path.AddArc(x, y, d, d, 180, 90);
path.AddArc(x + w - d, y, d, d, 270, 90);
path.AddArc(x + w - d, y + h - d, d, d, 0, 90);
path.AddArc(x, y + h - d, d, d, 90, 90);
path.CloseFigure();
return path;
}
}