using System.Drawing.Drawing2D; namespace UCVL.VPNPlus; internal enum BannerTone { Idle, Connecting, Connected, Attention, Error } internal sealed class DashboardConnectionBanner : CardPanel { private bool _wide; private BannerTone _tone; internal bool WideBanner { get => _wide; set { if (_wide != value) { _wide = value; Invalidate(true); } } } internal BannerTone Tone { get => _tone; set { if (_tone != value) { _tone = value; Invalidate(true); } } } protected override void OnPaintBackground(PaintEventArgs e) { base.OnPaintBackground(e); if (!WideBanner || Width < 30 || Height < 30) return; var g = e.Graphics; var state = g.Save(); g.SmoothingMode = SmoothingMode.AntiAlias; var scale = DeviceDpi / 96f; var inset = Math.Max(1, (int)Math.Round(scale)); var bounds = new Rectangle(inset, inset, Width - 2 * inset - 1, Height - 3 * inset - 1); using var path = UiGeometry.RoundedRectangle(bounds, Math.Min(bounds.Height / 2, (int)Math.Round(15 * scale))); var (start, middle, end) = Tone switch { BannerTone.Connected => (Color.FromArgb(21, 93, 153), Color.FromArgb(13, 84, 151), Color.FromArgb(13, 105, 147)), BannerTone.Attention => (Color.FromArgb(36, 81, 134), Color.FromArgb(39, 73, 124), Color.FromArgb(66, 81, 128)), BannerTone.Error => (Color.FromArgb(44, 75, 132), Color.FromArgb(59, 67, 120), Color.FromArgb(92, 67, 121)), BannerTone.Connecting => (Color.FromArgb(25, 102, 174), Color.FromArgb(11, 84, 158), Color.FromArgb(13, 108, 176)), _ => (Color.FromArgb(41, 94, 146), Color.FromArgb(30, 78, 132), Color.FromArgb(29, 101, 156)), }; using var fill = new LinearGradientBrush(bounds, start, end, 8) { InterpolationColors = new ColorBlend { Colors = [start, middle, end], Positions = [0f, .56f, 1f] }, }; g.FillPath(fill, path); g.SetClip(path, CombineMode.Intersect); using var sheen = new LinearGradientBrush(bounds, Color.FromArgb(36, 183, 230, 255), Color.Transparent, 90); g.FillPath(sheen, path); var left = Width * .40f; var right = Width - 3 * scale; var center = new PointF(Width * .70f, Height * .55f); using var flare = new GraphicsPath(); flare.AddEllipse(center.X - Width * .23f, center.Y - Height * .71f, Width * .46f, Height * 1.42f); using (var glow = new PathGradientBrush(flare) { CenterColor = Color.FromArgb(60, 116, 222, 255), SurroundColors = [Color.Transparent] }) g.FillPath(glow, flare); using var route = new GraphicsPath(); route.AddBezier(left, Height * .86f, Width * .58f, Height * .93f, Width * .58f, Height * .18f, center.X, center.Y); route.AddBezier(center.X, center.Y, Width * .81f, Height * .93f, Width * .86f, Height * .28f, right, Height * .36f); using (var halo = new Pen(Color.FromArgb(37, 108, 225, 255), Math.Max(2f, 5f * scale))) g.DrawPath(halo, route); using (var line = new Pen(Color.FromArgb(172, 182, 241, 255), Math.Max(1f, .85f * scale))) g.DrawPath(line, route); for (var i = 0; i < 2; i++) { using var line = new Pen(Color.FromArgb(44 + 18 * i, 166, 231, 255), Math.Max(1, scale * .65f)); g.DrawBezier(line, left + Width * .06f, Height * (.91f + .05f * i), Width * .66f, Height * (1.09f - .1f * i), Width * .73f, Height * (.15f + .12f * i), right, Height * (.50f + .14f * i)); } using var dot = new SolidBrush(Color.FromArgb(84, 200, 241, 255)); var step = Math.Max(3, (int)(5 * scale)); for (var y = (int)(8 * scale); y < Height * .74f; y += step) for (var x = (int)(Width * .61f); x < Width * .86f; x += step) { var dx = (x - Width * .73f) / (Width * .12f); var dy = (y - Height * .32f) / (Height * .31f); if (dx * dx + dy * dy < 1) g.FillEllipse(dot, x, y, Math.Max(1, scale), Math.Max(1, scale)); } using (var nodeHalo = new SolidBrush(Color.FromArgb(105, 125, 232, 255))) g.FillEllipse(nodeHalo, center.X - 3 * scale, center.Y - 3 * scale, 6 * scale, 6 * scale); g.FillEllipse(Brushes.White, center.X - 1.4f * scale, center.Y - 1.4f * scale, 2.8f * scale, 2.8f * scale); g.Restore(state); using var edge = new Pen(Color.FromArgb(233, 227, 248, 255), Math.Max(1, 1.05f * scale)); g.DrawPath(edge, path); } }