using System; using System.Drawing; using System.Drawing.Drawing2D; using System.Windows.Forms; namespace PokerGameSetup; internal sealed class CasinoButton : Button { private const int CornerRadius = 6; private bool isHovered; private bool isPressed; public bool IsPrimary { get; set; } public CasinoButton() { SetStyle(ControlStyles.UserPaint | ControlStyles.AllPaintingInWmPaint | ControlStyles.OptimizedDoubleBuffer | ControlStyles.ResizeRedraw, true); Cursor = Cursors.Hand; Font = new Font("Segoe UI", 10f, FontStyle.Bold); } protected override void OnMouseEnter(EventArgs e) { base.OnMouseEnter(e); isHovered = true; Invalidate(); } protected override void OnMouseLeave(EventArgs e) { base.OnMouseLeave(e); isHovered = false; isPressed = false; Invalidate(); } protected override void OnMouseDown(MouseEventArgs mevent) { base.OnMouseDown(mevent); if (mevent.Button == MouseButtons.Left) { isPressed = true; Invalidate(); } } protected override void OnMouseUp(MouseEventArgs mevent) { base.OnMouseUp(mevent); isPressed = false; Invalidate(); } 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); using (GraphicsPath path = CreateRoundedRectangle(rect, CornerRadius)) { if (IsPrimary) { DrawPrimaryButton(g, path, rect); } else { DrawSecondaryButton(g, path, rect); } } } private void DrawPrimaryButton(Graphics g, GraphicsPath path, Rectangle rect) { Color topColor; Color bottomColor; Color borderColor; Color textColor = Color.FromArgb(20, 16, 10); if (!Enabled) { topColor = Color.FromArgb(70, 65, 55); bottomColor = Color.FromArgb(50, 47, 40); borderColor = Color.FromArgb(80, 75, 65); textColor = Color.FromArgb(120, 115, 105); } else if (isPressed) { topColor = Color.FromArgb(200, 160, 80); bottomColor = Color.FromArgb(170, 130, 60); borderColor = Color.FromArgb(220, 185, 110); } else if (isHovered) { topColor = Color.FromArgb(255, 235, 160); bottomColor = Color.FromArgb(235, 195, 110); borderColor = Color.FromArgb(255, 245, 200); } else { topColor = Color.FromArgb(242, 212, 135); bottomColor = Color.FromArgb(205, 165, 85); borderColor = Color.FromArgb(250, 225, 160); } // Outer subtle glow when hovered if (Enabled && isHovered) { using (Pen glowPen = new Pen(Color.FromArgb(40, 229, 190, 112), 3f)) { g.DrawPath(glowPen, path); } } // Button background fill using (LinearGradientBrush brush = new LinearGradientBrush(rect, topColor, bottomColor, 90f)) { g.FillPath(brush, path); } // Inner top highlight line if (Enabled && !isPressed) { using (Pen highlightPen = new Pen(Color.FromArgb(160, 255, 255, 255), 1f)) { g.DrawLine(highlightPen, rect.Left + CornerRadius, rect.Top + 1, rect.Right - CornerRadius, rect.Top + 1); } } // Outer border using (Pen borderPen = new Pen(borderColor, 1.2f)) { g.DrawPath(borderPen, path); } // Text Point textPos = isPressed ? new Point(0, 1) : Point.Empty; Rectangle textRect = new Rectangle(rect.X + textPos.X, rect.Y + textPos.Y, rect.Width, rect.Height); TextRenderer.DrawText(g, Text, Font, textRect, textColor, TextFormatFlags.HorizontalCenter | TextFormatFlags.VerticalCenter); } private void DrawSecondaryButton(Graphics g, GraphicsPath path, Rectangle rect) { Color bgColor; Color borderColor; Color textColor; if (!Enabled) { bgColor = Color.FromArgb(20, 23, 25); borderColor = Color.FromArgb(45, 48, 50); textColor = Color.FromArgb(85, 90, 92); } else if (isPressed) { bgColor = Color.FromArgb(22, 25, 27); borderColor = Color.FromArgb(90, 75, 50); textColor = InstallerForm.Gold; } else if (isHovered) { bgColor = Color.FromArgb(42, 46, 48); borderColor = Color.FromArgb(170, 140, 85); textColor = Color.FromArgb(250, 235, 185); } else { bgColor = Color.FromArgb(28, 31, 33); borderColor = Color.FromArgb(90, 75, 52); textColor = InstallerForm.Gold; } // Background fill using (SolidBrush brush = new SolidBrush(bgColor)) { g.FillPath(brush, path); } // Border using (Pen borderPen = new Pen(borderColor, 1.2f)) { g.DrawPath(borderPen, path); } // Text Point textPos = isPressed ? new Point(0, 1) : Point.Empty; Rectangle textRect = new Rectangle(rect.X + textPos.X, rect.Y + textPos.Y, rect.Width, rect.Height); TextRenderer.DrawText(g, Text, Font, textRect, textColor, TextFormatFlags.HorizontalCenter | TextFormatFlags.VerticalCenter); } 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; } }