-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathUI.cs
More file actions
389 lines (341 loc) · 13.9 KB
/
Copy pathUI.cs
File metadata and controls
389 lines (341 loc) · 13.9 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
using System;
using System.Drawing;
using System.Drawing.Drawing2D;
using System.Runtime.InteropServices;
using System.Windows.Forms;
namespace GIDE
{
/// <summary>
/// Centralized theme — Chrome-dark inspired, matching GBrowser.
/// </summary>
public static class Theme
{
// Backgrounds (Chrome-dark)
public static readonly Color BgDeep = Color.FromArgb(32, 33, 36); // root form / title bar
public static readonly Color BgMid = Color.FromArgb(40, 41, 45); // side panels
public static readonly Color BgPanel = Color.FromArgb(53, 54, 58); // cards / toolbar
public static readonly Color BgPanelHi = Color.FromArgb(68, 71, 76); // hover on cards
public static readonly Color BgInput = Color.FromArgb(41, 42, 45); // input field
public static readonly Color BgStatus = Color.FromArgb(32, 33, 36); // status bar
// Accent (blue, matching GBrowser)
public static readonly Color Accent = Color.FromArgb(138, 180, 248); // primary blue
public static readonly Color AccentHi = Color.FromArgb(168, 199, 250); // hover
public static readonly Color AccentLo = Color.FromArgb(100, 150, 230); // pressed
// Text
public static readonly Color Text = Color.FromArgb(255, 255, 255);
public static readonly Color TextDim = Color.FromArgb(180, 184, 190);
public static readonly Color TextFaint = Color.FromArgb(128, 134, 142);
// Borders / dividers
public static readonly Color Border = Color.FromArgb(60, 64, 67);
public static readonly Color BorderSoft = Color.FromArgb(48, 51, 54);
// Semantic
public static readonly Color UserBubble = Color.FromArgb(138, 180, 248); // blue
public static readonly Color AiBubble = Color.FromArgb(129, 201, 149); // green
public static readonly Color ErrorBubble = Color.FromArgb(242, 139, 130); // soft red
public static readonly string FontFamily = "Segoe UI Variable";
public static readonly string FontFamilyMono = "Cascadia Mono";
public static readonly string FontFamilyFallback = "Segoe UI";
public static Font Font(float size, FontStyle style = FontStyle.Regular)
{
try { return new Font(FontFamily, size, style); }
catch { return new Font(FontFamilyFallback, size, style); }
}
public static Font FontMono(float size, FontStyle style = FontStyle.Regular)
{
try { return new Font(FontFamilyMono, size, style); }
catch { return new Font("Consolas", size, style); }
}
}
/// <summary>
/// A panel that paints a smooth vertical (or diagonal) gradient background.
/// Used as the root background instead of a flat color for visual depth.
/// </summary>
public class GradientPanel : Panel
{
public Color GradientTop { get; set; }
public Color GradientBottom { get; set; }
public float Angle { get; set; }
public bool ShowGlow { get; set; }
public GradientPanel()
{
SetStyle(ControlStyles.AllPaintingInWmPaint
| ControlStyles.OptimizedDoubleBuffer
| ControlStyles.UserPaint
| ControlStyles.ResizeRedraw
| ControlStyles.SupportsTransparentBackColor, true);
DoubleBuffered = true;
BackColor = Theme.BgDeep;
GradientTop = Theme.BgDeep;
GradientBottom = Color.FromArgb(38, 39, 43);
Angle = 90f;
ShowGlow = true;
}
protected override void OnPaintBackground(PaintEventArgs e)
{
if (Width <= 0 || Height <= 0) return;
using (var brush = new LinearGradientBrush(ClientRectangle, GradientTop, GradientBottom, Angle))
{
e.Graphics.FillRectangle(brush, ClientRectangle);
}
PaintAmbientGlow(e.Graphics);
}
protected override void OnPaint(PaintEventArgs e)
{
// Background-only panel
}
// Subtle radial-style glow centered roughly where the input card will sit.
// Gives the form an atmospheric "spotlight" feel without needing real Mica.
private void PaintAmbientGlow(Graphics g)
{
if (!ShowGlow) return;
try
{
g.SmoothingMode = SmoothingMode.HighQuality;
int cx = Width / 2;
int cy = (int)(Height * 0.45f);
int r = (int)(Math.Max(Width, Height) * 0.55f);
using (var path = new GraphicsPath())
{
path.AddEllipse(cx - r, cy - r, r * 2, r * 2);
using (var pgb = new PathGradientBrush(path))
{
pgb.CenterColor = Color.FromArgb(30, 138, 180, 248);
pgb.SurroundColors = new[] { Color.FromArgb(0, 32, 33, 36) };
pgb.CenterPoint = new PointF(cx, cy);
g.FillPath(pgb, path);
}
}
}
catch { }
}
}
/// <summary>
/// Helper to draw rounded rectangles.
/// </summary>
public static class RoundedDraw
{
public static GraphicsPath Path(Rectangle rect, int radius)
{
var path = new GraphicsPath();
if (radius <= 0)
{
path.AddRectangle(rect);
path.CloseFigure();
return path;
}
int d = radius * 2;
if (d > rect.Width) d = rect.Width;
if (d > rect.Height) d = rect.Height;
path.AddArc(rect.X, rect.Y, d, d, 180, 90);
path.AddArc(rect.Right - d, rect.Y, d, d, 270, 90);
path.AddArc(rect.Right - d, rect.Bottom - d, d, d, 0, 90);
path.AddArc(rect.X, rect.Bottom - d, d, d, 90, 90);
path.CloseFigure();
return path;
}
}
/// <summary>
/// A panel with rounded corners and optional subtle border.
/// </summary>
public class RoundedPanel : Panel
{
private int _radius = 14;
private Color _borderColor = Color.Empty;
private int _borderWidth = 0;
public int Radius
{
get { return _radius; }
set { _radius = value; Invalidate(); }
}
public Color BorderColor
{
get { return _borderColor; }
set { _borderColor = value; Invalidate(); }
}
public int BorderWidth
{
get { return _borderWidth; }
set { _borderWidth = value; Invalidate(); }
}
public RoundedPanel()
{
SetStyle(ControlStyles.AllPaintingInWmPaint
| ControlStyles.OptimizedDoubleBuffer
| ControlStyles.UserPaint
| ControlStyles.ResizeRedraw
| ControlStyles.SupportsTransparentBackColor, true);
DoubleBuffered = true;
BackColor = Theme.BgPanel;
}
protected override void OnPaint(PaintEventArgs e)
{
var g = e.Graphics;
g.SmoothingMode = SmoothingMode.AntiAlias;
g.PixelOffsetMode = PixelOffsetMode.HighQuality;
var rect = new Rectangle(0, 0, Width - 1, Height - 1);
using (var path = RoundedDraw.Path(rect, _radius))
{
// Clip to rounded shape so no corner artifacts appear
this.Region = new Region(path);
using (var brush = new SolidBrush(BackColor))
g.FillPath(brush, path);
if (_borderWidth > 0 && _borderColor != Color.Empty)
{
using (var pen = new Pen(_borderColor, _borderWidth))
{
pen.Alignment = PenAlignment.Inset;
g.DrawPath(pen, path);
}
}
}
}
}
/// <summary>
/// A flat button with rounded corners, hover/press states, optional border.
/// </summary>
public class RoundedButton : Button
{
private int _radius = 12;
private Color _hoverColor = Color.Empty;
private Color _pressColor = Color.Empty;
private Color _borderColor = Color.Empty;
private int _borderWidth = 0;
private bool _hover = false;
private bool _press = false;
public int Radius
{
get { return _radius; }
set { _radius = value; Invalidate(); }
}
public Color HoverColor
{
get { return _hoverColor; }
set { _hoverColor = value; Invalidate(); }
}
public Color PressColor
{
get { return _pressColor; }
set { _pressColor = value; Invalidate(); }
}
public Color BorderColor
{
get { return _borderColor; }
set { _borderColor = value; Invalidate(); }
}
public int BorderWidth
{
get { return _borderWidth; }
set { _borderWidth = value; Invalidate(); }
}
public RoundedButton()
{
SetStyle(ControlStyles.AllPaintingInWmPaint
| ControlStyles.OptimizedDoubleBuffer
| ControlStyles.UserPaint
| ControlStyles.ResizeRedraw
| ControlStyles.SupportsTransparentBackColor, true);
DoubleBuffered = true;
FlatStyle = FlatStyle.Flat;
FlatAppearance.BorderSize = 0;
Cursor = Cursors.Hand;
BackColor = Theme.BgPanel;
ForeColor = Theme.Text;
Font = Theme.Font(9.5f);
}
protected override void OnMouseEnter(EventArgs e)
{
_hover = true; Invalidate(); base.OnMouseEnter(e);
}
protected override void OnMouseLeave(EventArgs e)
{
_hover = false; _press = false; Invalidate(); base.OnMouseLeave(e);
}
protected override void OnMouseDown(MouseEventArgs mevent)
{
_press = true; Invalidate(); base.OnMouseDown(mevent);
}
protected override void OnMouseUp(MouseEventArgs mevent)
{
_press = false; Invalidate(); base.OnMouseUp(mevent);
}
protected override void OnPaint(PaintEventArgs pe)
{
var g = pe.Graphics;
g.SmoothingMode = SmoothingMode.AntiAlias;
g.PixelOffsetMode = PixelOffsetMode.HighQuality;
var rect = new Rectangle(0, 0, Width - 1, Height - 1);
Color fill = BackColor;
if (!Enabled)
fill = Color.FromArgb(180, BackColor);
else if (_press && _pressColor != Color.Empty)
fill = _pressColor;
else if (_hover && _hoverColor != Color.Empty)
fill = _hoverColor;
using (var path = RoundedDraw.Path(rect, _radius))
{
// Clip to rounded shape so no corner artifacts appear
this.Region = new Region(path);
using (var brush = new SolidBrush(fill))
g.FillPath(brush, path);
if (_borderWidth > 0 && _borderColor != Color.Empty)
{
using (var pen = new Pen(_borderColor, _borderWidth))
{
pen.Alignment = PenAlignment.Inset;
g.DrawPath(pen, path);
}
}
}
// Text
TextRenderer.DrawText(g, Text, Font, ClientRectangle,
Enabled ? ForeColor : Color.FromArgb(160, ForeColor),
TextFormatFlags.HorizontalCenter | TextFormatFlags.VerticalCenter
| TextFormatFlags.SingleLine | TextFormatFlags.EndEllipsis);
}
}
/// <summary>
/// Win11 Mica + dark title-bar enabler via DWM API. Falls back gracefully on older Windows.
/// </summary>
public static class MicaHelper
{
[StructLayout(LayoutKind.Sequential)]
private struct MARGINS
{
public int cxLeftWidth;
public int cxRightWidth;
public int cyTopHeight;
public int cyBottomHeight;
}
[DllImport("dwmapi.dll")]
private static extern int DwmSetWindowAttribute(IntPtr hwnd, int attr, ref int attrValue, int attrSize);
[DllImport("dwmapi.dll")]
private static extern int DwmExtendFrameIntoClientArea(IntPtr hWnd, ref MARGINS pMarInset);
// Win11 22H2+
private const int DWMWA_USE_IMMERSIVE_DARK_MODE = 20;
private const int DWMWA_SYSTEMBACKDROP_TYPE = 38;
// DWM_SYSTEMBACKDROP_TYPE
private const int DWMSBT_AUTO = 0;
private const int DWMSBT_NONE = 1;
private const int DWMSBT_MAINWINDOW = 2; // Mica
private const int DWMSBT_TRANSIENTWINDOW = 3; // Acrylic
private const int DWMSBT_TABBEDWINDOW = 4; // Mica Alt
public static void Apply(Form form)
{
try
{
IntPtr h = form.Handle;
int dark = 1;
DwmSetWindowAttribute(h, DWMWA_USE_IMMERSIVE_DARK_MODE, ref dark, sizeof(int));
int backdrop = DWMSBT_MAINWINDOW;
DwmSetWindowAttribute(h, DWMWA_SYSTEMBACKDROP_TYPE, ref backdrop, sizeof(int));
// Extend frame so the backdrop shows through
MARGINS m = new MARGINS { cxLeftWidth = -1, cxRightWidth = -1, cyTopHeight = -1, cyBottomHeight = -1 };
DwmExtendFrameIntoClientArea(h, ref m);
}
catch
{
// Older Windows — silently no-op. The dark theme still looks great as a flat color.
}
}
}
}