-
Notifications
You must be signed in to change notification settings - Fork 11
Expand file tree
/
Copy pathTheming.cs
More file actions
701 lines (573 loc) · 29.8 KB
/
Theming.cs
File metadata and controls
701 lines (573 loc) · 29.8 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
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
/////////////////////////////////////////////////////////////////////////////////
// CodeLab for Paint.NET
// Copyright 2018 Jason Wendt. All Rights Reserved.
// Portions Copyright ©Microsoft Corporation. All Rights Reserved.
//
// THE DEVELOPERS MAKE NO WARRANTY OF ANY KIND REGARDING THE CODE. THEY
// SPECIFICALLY DISCLAIM ANY WARRANTY OF FITNESS FOR ANY PARTICULAR PURPOSE OR
// ANY OTHER WARRANTY. THE CODELAB DEVELOPERS DISCLAIM ALL LIABILITY RELATING
// TO THE USE OF THIS CODE. NO LICENSE, EXPRESS OR IMPLIED, BY ESTOPPEL OR
// OTHERWISE, TO ANY INTELLECTUAL PROPERTY RIGHTS IS GRANTED HEREIN.
//
// Latest distribution: https://www.BoltBait.com/pdn/codelab
/////////////////////////////////////////////////////////////////////////////////
using PaintDotNet;
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Drawing;
using System.Linq;
using System.Runtime.CompilerServices;
using System.Runtime.InteropServices;
using System.Windows.Forms;
using Windows.UI.ViewManagement;
namespace PdnCodeLab
{
public enum Theme
{
Auto,
Light,
Dark
}
[Flags]
internal enum ItemSelectionFlags
{
//None = 0,
Fill = 1,
Outline = 2,
AccentMark = 4,
AccentOutline = 8
}
internal interface IIntelliTipHost
{
void ThemeToolTip(Color toolTipFore, Color toolTipBack);
}
internal interface IToolTipHost
{
void ThemeToolTip();
}
internal static class ThemeUtil
{
private static bool isAppThemeDark;
private static Color originalForeColor;
private static Color originalBackColor;
private static Theme currentTheme;
private static Color foreColor;
private static Color backColor;
private static ThemeRenderer themeRenderer;
private static TabRenderer tabRenderer;
private static Color accentColor;
private static readonly UISettings uiSettings = new UISettings();
internal static void Initialize(bool PdnDarkTheme, Color foreColor, Color backColor, Theme userTheme)
{
isAppThemeDark = PdnDarkTheme;
originalForeColor = foreColor;
originalBackColor = backColor;
SetTheme(userTheme);
}
private static void SetTheme(Theme value)
{
switch (value)
{
case Theme.Auto:
foreColor = originalForeColor;
backColor = originalBackColor;
break;
case Theme.Dark:
foreColor = Color.White;
backColor = Color.FromArgb(40, 40, 40);
break;
case Theme.Light:
foreColor = Color.Black;
backColor = Color.FromArgb(240, 240, 240);
break;
}
currentTheme = value;
themeRenderer = null;
tabRenderer = null;
}
private static ThemeRenderer ToolStripRenderer => themeRenderer ??= new ThemeRenderer();
private static TabRenderer TabBarRenderer => tabRenderer ??= new TabRenderer();
private static Color AccentColor
{
get
{
if (accentColor.IsEmpty)
{
accentColor = uiSettings.GetColorValue(UIColorType.AccentLight2).ToGdiColor();
}
return accentColor;
}
}
internal static void UpdateTheme(this Form form, Theme theme)
{
SetTheme(theme);
UpdateTheme(form);
}
internal static void UpdateTheme(this Form form)
{
if (LicenseManager.UsageMode == LicenseUsageMode.Designtime)
{
return;
}
bool effectiveDarkMode = currentTheme == Theme.Dark || (currentTheme == Theme.Auto && isAppThemeDark);
form.ForeColor = foreColor;
form.BackColor = backColor;
if (form is IToolTipHost toolTipHost)
{
toolTipHost.ThemeToolTip();
}
foreach (Control c in form.Descendants<Control>())
{
if (c.Parent is TabPage || c.Parent is TabControl)
{
continue;
}
switch (c)
{
case ToolStrip toolStrip:
toolStrip.Renderer = (toolStrip.Parent is TabStrip)
? TabBarRenderer
: ToolStripRenderer;
foreach (ToolStrip ts in toolStrip.Descendants())
{
ts.GetToolTip().UpdateTheme();
if (ts is ToolStripDropDown dropDown)
{
dropDown.Opening -= AddMenuPadding;
dropDown.Opening += AddMenuPadding;
SetWindowCorners(dropDown.Handle, DWM_WINDOW_CORNER_PREFERENCE.DWMWCP_ROUNDSMALL);
}
}
break;
case Button button:
button.FlatStyle = FlatStyle.System;
break;
case Panel:
case SettingsPageList:
c.BackColor = backColor;
c.ForeColor = foreColor;
break;
case TextBox:
case ListBox:
case ListView:
c.BackColor = effectiveDarkMode ? backColor : default;
c.ForeColor = foreColor;
break;
case RichTextBox richTextBox:
c.BackColor = richTextBox.ReadOnly ? backColor : default;
c.ForeColor = richTextBox.ReadOnly ? foreColor : default;
break;
case ComboBox comboBox:
comboBox.FlatStyle = effectiveDarkMode ? FlatStyle.Flat : FlatStyle.Standard;
comboBox.BackColor = effectiveDarkMode ? backColor : default;
comboBox.ForeColor = foreColor;
break;
case CodeTextBox scintilla:
scintilla.Theme = effectiveDarkMode ? Theme.Dark : Theme.Light;
break;
case LinkLabel linkLabel:
linkLabel.ActiveLinkColor = foreColor;
linkLabel.LinkColor = foreColor;
linkLabel.BackColor = Color.Transparent;
break;
case Label:
case CheckBox:
c.BackColor = Color.Transparent;
break;
case IndicatorBar indicatorBar:
indicatorBar.Theme = effectiveDarkMode ? Theme.Dark : Theme.Light;
break;
}
if (c is IIntelliTipHost intelliTipHost)
{
intelliTipHost.ThemeToolTip(
effectiveDarkMode ? Color.White : Color.FromArgb(30, 30, 30),
effectiveDarkMode ? Color.FromArgb(40, 40, 40) : Color.WhiteSmoke);
}
EnableUxThemeDarkMode(c.Handle, effectiveDarkMode);
}
}
private static void AddMenuPadding(object sender, CancelEventArgs e)
{
if (sender is ToolStripDropDownMenu dropDown && dropDown.Items.Count > 0)
{
const int menuPadding = 2;
foreach (ToolStripItem item in dropDown.Items)
{
item.Margin = new Padding(menuPadding, 0, menuPadding, 0);
}
dropDown.Items[0].Margin = new Padding(menuPadding, menuPadding, menuPadding, 0);
dropDown.Items[^1].Margin = new Padding(menuPadding, 0, menuPadding, menuPadding);
dropDown.AutoSize = true;
dropDown.AutoSize = false;
dropDown.Size = new Size(dropDown.Width + (menuPadding * 2), dropDown.Height);
}
}
private static IEnumerable<T> Descendants<T>(this Control control)
where T : Control
{
foreach (Control child in control.Controls)
{
if (child is T childOfT)
{
yield return childOfT;
}
if (child.HasChildren)
{
foreach (T descendant in Descendants<T>(child))
{
yield return descendant;
}
}
if (child.ContextMenuStrip is T contextMenuOfT)
{
yield return contextMenuOfT;
}
}
}
[DllImport("uxtheme.dll", SetLastError = true, ExactSpelling = true, CharSet = CharSet.Unicode)]
private static extern int SetWindowTheme(IntPtr hWnd, string pszSubAppName, string pszSubIdList);
/// <summary>
/// Use to set dark scroll bars
/// </summary>
private static void EnableUxThemeDarkMode(IntPtr hwnd, bool enable)
{
string themeName = enable ? "DarkMode_Explorer" : null;
SetWindowTheme(hwnd, themeName, null);
}
internal static void UpdateTheme(this ToolTip toolTip)
{
IntPtr handle = toolTip.GetHandle();
bool effectiveDarkMode = currentTheme == Theme.Dark || (currentTheme == Theme.Auto && isAppThemeDark);
EnableUxThemeDarkMode(handle, effectiveDarkMode);
SetWindowCorners(handle, DWM_WINDOW_CORNER_PREFERENCE.DWMWCP_ROUNDSMALL);
}
internal static void DrawItemSelection(this Graphics graphics, Color backColor, Rectangle bounds, ItemSelectionFlags itemSelectionFlags = ItemSelectionFlags.Fill | ItemSelectionFlags.Outline)
{
if (itemSelectionFlags == 0)
{
throw new InvalidEnumArgumentException($"No value provided for {nameof(ItemSelectionFlags)}.");
}
graphics.SmoothingMode = System.Drawing.Drawing2D.SmoothingMode.AntiAlias;
Size rectRadius = UIUtil.ScaleSize(6, 6);
Color selectedColor = ColorBgra.Blend([Color.Gray, backColor]);
const float pixelOffset = 0.5f; // allows 2px lines to actually be 2px width, and edges of rectangles to be sharp;
if (itemSelectionFlags.HasFlag(ItemSelectionFlags.Fill))
{
RectangleF fillRect = RectangleF.FromLTRB(bounds.Left - pixelOffset, bounds.Top - pixelOffset, bounds.Right - pixelOffset, bounds.Bottom - pixelOffset);
Color fillColor = Color.FromArgb(128, selectedColor);
using SolidBrush backBrush = new SolidBrush(fillColor);
graphics.FillRoundedRectangle(backBrush, fillRect, rectRadius);
}
if (itemSelectionFlags.HasFlag(ItemSelectionFlags.AccentOutline) ||
itemSelectionFlags.HasFlag(ItemSelectionFlags.Outline))
{
int outlineWidth = Math.Min(UIUtil.Scale(1), 2); // limit width to 2, because GDI sucks
float outlineOffset = outlineWidth > 1 ? pixelOffset : 0;
RectangleF outlineRect = RectangleF.FromLTRB(
bounds.Left + outlineOffset,
bounds.Top + outlineOffset,
bounds.Right - outlineOffset - 1,
bounds.Bottom - outlineOffset - 1);
Color outlineColor = itemSelectionFlags.HasFlag(ItemSelectionFlags.AccentOutline)
? AccentColor
: selectedColor;
using Pen outlinePen = new Pen(outlineColor, outlineWidth);
graphics.DrawRoundedRectangle(outlinePen, outlineRect, rectRadius);
}
if (itemSelectionFlags.HasFlag(ItemSelectionFlags.AccentMark))
{
Size accentRadius = UIUtil.ScaleSize(3, 3);
int accentWidth = UIUtil.Scale(3);
RectangleF accentRect = new RectangleF(bounds.X - pixelOffset, bounds.Y - pixelOffset + (int)Math.Round(bounds.Height / 4f), accentWidth, (int)Math.Round(bounds.Height / 2f));
using SolidBrush accentBrush = new SolidBrush(AccentColor);
graphics.FillRoundedRectangle(accentBrush, accentRect, accentRadius);
}
graphics.SmoothingMode = System.Drawing.Drawing2D.SmoothingMode.None;
}
private static IEnumerable<ToolStrip> Descendants(this ToolStrip toolStrip)
{
yield return toolStrip;
foreach (ToolStripDropDownItem items in toolStrip.Items.OfType<ToolStripDropDownItem>())
{
foreach (ToolStrip descendant in items.DropDown.Descendants())
{
yield return descendant;
}
}
}
private static Color ToGdiColor(this Windows.UI.Color color)
{
return Color.FromArgb(color.A, color.R, color.G, color.B);
}
private enum DWM_WINDOW_CORNER_PREFERENCE
{
DWMWCP_DEFAULT = 0,
DWMWCP_DONOTROUND = 1,
DWMWCP_ROUND = 2,
DWMWCP_ROUNDSMALL = 3
}
[Flags]
private enum DWMWINDOWATTRIBUTE : uint
{
/// <summary>
/// Use with DwmSetWindowAttribute. Specifies the rounded corner preference for a window. The pvAttribute parameter points to a value of type DWM_WINDOW_CORNER_PREFERENCE. This value is supported starting with Windows 11 Build 22000.
/// </summary>
DWMWA_WINDOW_CORNER_PREFERENCE = 33,
}
[DllImport("dwmapi.dll", CharSet = CharSet.Unicode, PreserveSig = false)]
private static extern int DwmSetWindowAttribute(IntPtr hwnd, DWMWINDOWATTRIBUTE dwAttribute, ref uint pvAttribute, int cbAttribute);
private static void SetWindowCorners(IntPtr hwnd, DWM_WINDOW_CORNER_PREFERENCE cornerPreference)
{
if (!OperatingSystem.IsWindowsVersionAtLeast(10, 0, 22000))
{
return;
}
uint cornerPreferenceUInt = (uint)cornerPreference;
DwmSetWindowAttribute(hwnd, DWMWINDOWATTRIBUTE.DWMWA_WINDOW_CORNER_PREFERENCE, ref cornerPreferenceUInt, sizeof(DWM_WINDOW_CORNER_PREFERENCE));
}
[UnsafeAccessor(UnsafeAccessorKind.Method, Name = "get_ToolTip")]
private static extern ToolTip GetToolTip(this ToolStrip toolStrip);
[UnsafeAccessor(UnsafeAccessorKind.Method, Name = "get_Handle")]
private static extern IntPtr GetHandle(this ToolTip toolStrip);
internal static void InvalidateCache()
{
accentColor = Color.Empty;
}
private sealed class ThemeRenderer : ToolStripProfessionalRenderer
{
internal ThemeRenderer() : base(new ThemeColorTable())
{
RoundedEdges = false;
}
private Dictionary<ToolStripItem, ToolStripArrowRenderEventArgs> itemArrowArgs = new Dictionary<ToolStripItem, ToolStripArrowRenderEventArgs>();
protected override void OnRenderItemText(ToolStripItemTextRenderEventArgs e)
{
e.TextColor = ThemeUtil.foreColor;
base.OnRenderItemText(e);
}
protected override void OnRenderArrow(ToolStripArrowRenderEventArgs e)
{
if (e.Item.Enabled)
{
e.ArrowColor = ThemeUtil.foreColor;
}
itemArrowArgs[e.Item] = e;
base.OnRenderArrow(e);
}
protected override void OnRenderItemBackground(ToolStripItemRenderEventArgs e)
{
base.OnRenderItemBackground(e);
e.Graphics.FillRoundedRectangle(Brushes.Red, e.Item.ContentRectangle, new Size(6, 6));
}
protected override void OnRenderMenuItemBackground(ToolStripItemRenderEventArgs e)
{
base.OnRenderMenuItemBackground(e);
if (e.Item.Selected || e.Item.Pressed)
{
Rectangle itemRect = e.ToolStrip is MenuStrip
? new Rectangle(Point.Empty, e.Item.Bounds.Size)
: e.Item.ContentRectangle;
using SolidBrush clearBrush = new SolidBrush(ColorTable.ToolStripDropDownBackground);
e.Graphics.FillRectangle(clearBrush, itemRect);
e.Graphics.DrawItemSelection(ColorTable.ToolStripDropDownBackground, itemRect);
}
}
protected override void OnRenderButtonBackground(ToolStripItemRenderEventArgs e)
{
base.OnRenderButtonBackground(e);
bool isChecked = e.Item is ToolStripButton button && button.Checked;
if (e.Item.Selected || e.Item.Pressed)
{
Rectangle itemRect = new Rectangle(Point.Empty, e.Item.Bounds.Size);
using SolidBrush clearBrush = new SolidBrush(ColorTable.ToolStripDropDownBackground);
e.Graphics.FillRectangle(clearBrush, itemRect);
ItemSelectionFlags selectionFlags = isChecked
? ItemSelectionFlags.Fill | ItemSelectionFlags.AccentOutline
: ItemSelectionFlags.Fill | ItemSelectionFlags.Outline;
e.Graphics.DrawItemSelection(ColorTable.ToolStripDropDownBackground, itemRect, selectionFlags);
}
else if (isChecked)
{
Rectangle itemRect = new Rectangle(Point.Empty, e.Item.Bounds.Size);
using SolidBrush clearBrush = new SolidBrush(ColorTable.ToolStripDropDownBackground);
e.Graphics.FillRectangle(clearBrush, itemRect);
e.Graphics.DrawItemSelection(ColorTable.ToolStripDropDownBackground, itemRect, ItemSelectionFlags.AccentOutline);
}
}
protected override void OnRenderItemCheck(ToolStripItemImageRenderEventArgs e)
{
//base.OnRenderItemCheck(e);
e.Graphics.DrawImage(e.Image, e.ImageRectangle);
}
protected override void OnRenderDropDownButtonBackground(ToolStripItemRenderEventArgs e)
{
base.OnRenderDropDownButtonBackground(e);
if (e.Item.Selected || e.Item.Pressed)
{
Rectangle itemRect = new Rectangle(e.Item.ContentRectangle.Location, e.Item.Bounds.Size);
using SolidBrush clearBrush = new SolidBrush(ColorTable.ToolStripDropDownBackground);
e.Graphics.FillRectangle(clearBrush, itemRect);
e.Graphics.DrawItemSelection(ColorTable.ToolStripDropDownBackground, itemRect);
if (itemArrowArgs.TryGetValue(e.Item, out ToolStripArrowRenderEventArgs arrowArgs))
{
ToolStripArrowRenderEventArgs newArrowArgs = new ToolStripArrowRenderEventArgs(
e.Graphics, arrowArgs.Item, arrowArgs.ArrowRectangle, arrowArgs.ArrowColor, arrowArgs.Direction);
OnRenderArrow(newArrowArgs);
}
}
}
protected override void OnRenderSplitButtonBackground(ToolStripItemRenderEventArgs e)
{
base.OnRenderSplitButtonBackground(e);
if (e.Item.Selected || e.Item.Pressed)
{
using SolidBrush clearBrush = new SolidBrush(ColorTable.ToolStripDropDownBackground);
e.Graphics.FillRectangle(clearBrush, e.Item.ContentRectangle);
e.Graphics.DrawItemSelection(ColorTable.ToolStripDropDownBackground, e.Item.ContentRectangle);
if (itemArrowArgs.TryGetValue(e.Item, out ToolStripArrowRenderEventArgs arrowArgs))
{
if (!e.Item.Pressed)
{
using Pen linePen = new Pen(ColorTable.MenuBorder, UIUtil.Scale(1));
e.Graphics.DrawLine(
linePen,
arrowArgs.ArrowRectangle.Left - 1,
arrowArgs.ArrowRectangle.Top + UIUtil.Scale(1),
arrowArgs.ArrowRectangle.Left - 1,
arrowArgs.ArrowRectangle.Bottom - UIUtil.Scale(1));
}
OnRenderArrow(arrowArgs);
}
}
}
private sealed class ThemeColorTable : ProfessionalColorTable
{
private readonly Color BackColor = ThemeUtil.backColor;
private readonly Color BorderColor = ThemeUtil.backColor; //Color.FromArgb(186, 0, 105, 210);
private readonly Color HiliteColor = ThemeUtil.backColor; //Color.FromArgb(62, 0, 103, 206);
private readonly Color CheckedColor = ThemeUtil.AccentColor; //Color.FromArgb(129, 52, 153, 254);
private readonly Color CheckedBorderColor = ThemeUtil.backColor; //Color.FromArgb(52, 153, 254);
public override Color ButtonSelectedHighlight => HiliteColor;
public override Color ButtonSelectedBorder => BorderColor;
public override Color ButtonSelectedGradientBegin => HiliteColor;
public override Color ButtonSelectedGradientMiddle => HiliteColor;
public override Color ButtonSelectedGradientEnd => HiliteColor;
public override Color ButtonSelectedHighlightBorder => BorderColor;
public override Color ButtonPressedHighlight => HiliteColor;
public override Color ButtonPressedGradientBegin => CheckedColor;
public override Color ButtonPressedGradientMiddle => CheckedColor;
public override Color ButtonPressedGradientEnd => CheckedColor;
public override Color ButtonPressedBorder => CheckedBorderColor;
public override Color ButtonPressedHighlightBorder => CheckedBorderColor;
public override Color ButtonCheckedGradientBegin => CheckedColor;
public override Color ButtonCheckedGradientMiddle => CheckedColor;
public override Color ButtonCheckedGradientEnd => CheckedColor;
public override Color ButtonCheckedHighlight => CheckedColor;
public override Color ButtonCheckedHighlightBorder => CheckedBorderColor;
public override Color ToolStripBorder => Color.Transparent;
public override Color ToolStripGradientBegin => BackColor;
public override Color ToolStripGradientMiddle => BackColor;
public override Color ToolStripGradientEnd => BackColor;
public override Color ToolStripDropDownBackground => BackColor;
public override Color MenuItemBorder => BorderColor;
public override Color MenuItemPressedGradientBegin => BackColor;
public override Color MenuItemPressedGradientMiddle => BackColor;
public override Color MenuItemPressedGradientEnd => BackColor;
public override Color MenuItemSelected => HiliteColor;
public override Color MenuItemSelectedGradientBegin => HiliteColor;
public override Color MenuItemSelectedGradientEnd => HiliteColor;
public override Color CheckBackground => CheckedColor;
public override Color CheckSelectedBackground => HiliteColor;
public override Color CheckPressedBackground => CheckedColor;
public override Color MenuStripGradientBegin => BackColor;
public override Color MenuStripGradientEnd => BackColor;
public override Color MenuBorder => ColorBgra.Blend([Color.Gray, BackColor]);
public override Color ImageMarginGradientBegin => BackColor;
public override Color ImageMarginGradientMiddle => BackColor;
public override Color ImageMarginGradientEnd => BackColor;
public override Color SeparatorLight => BackColor;
public override Color SeparatorDark => Color.FromArgb(85, 85, 85);
}
}
private sealed class TabRenderer : ToolStripProfessionalRenderer
{
internal TabRenderer() : base(new TabColorTable())
{
RoundedEdges = false;
}
protected override void OnRenderItemText(ToolStripItemTextRenderEventArgs e)
{
e.TextColor = ThemeUtil.foreColor;
e.TextRectangle = new Rectangle(e.TextRectangle.X + UIUtil.Scale(e.Item.Padding.Left), e.TextRectangle.Y, e.TextRectangle.Width, e.TextRectangle.Height);
base.OnRenderItemText(e);
}
protected override void OnRenderButtonBackground(ToolStripItemRenderEventArgs e)
{
base.OnRenderButtonBackground(e);
bool isChecked = e.Item is ToolStripButton button && button.Checked;
if (e.Item.Selected || e.Item.Pressed)
{
Rectangle itemRect = new Rectangle(Point.Empty, e.Item.Bounds.Size);
using SolidBrush clearBrush = new SolidBrush(ColorTable.ToolStripDropDownBackground);
e.Graphics.FillRectangle(clearBrush, itemRect);
ItemSelectionFlags selectionFlags = isChecked
? ItemSelectionFlags.Fill | ItemSelectionFlags.AccentOutline
: ItemSelectionFlags.Fill | ItemSelectionFlags.Outline;
e.Graphics.DrawItemSelection(ColorTable.ToolStripDropDownBackground, itemRect, selectionFlags);
}
else if (isChecked)
{
Rectangle itemRect = new Rectangle(Point.Empty, e.Item.Bounds.Size);
using SolidBrush clearBrush = new SolidBrush(ColorTable.ToolStripDropDownBackground);
e.Graphics.FillRectangle(clearBrush, itemRect);
e.Graphics.DrawItemSelection(ColorTable.ToolStripDropDownBackground, itemRect, ItemSelectionFlags.AccentOutline);
}
}
protected override void OnRenderItemImage(ToolStripItemImageRenderEventArgs e)
{
Rectangle newImageRect = new Rectangle(e.ImageRectangle.X + UIUtil.Scale(e.Item.Padding.Left), e.ImageRectangle.Y, e.ImageRectangle.Width, e.ImageRectangle.Height);
ToolStripItemImageRenderEventArgs newEventArgs = new ToolStripItemImageRenderEventArgs(e.Graphics, e.Item, e.Image, newImageRect);
base.OnRenderItemImage(newEventArgs);
}
private sealed class TabColorTable : ProfessionalColorTable
{
internal TabColorTable()
{
UseSystemColors = false;
}
private readonly Color BackColor = Color.FromArgb(255, ColorBgra.Blend(new ColorBgra[] { ColorBgra.FromBgra(128, 128, 128, 64), ThemeUtil.backColor }));
private readonly Color BorderColor = ThemeUtil.backColor; // Color.FromArgb(186, 0, 105, 210);
private readonly Color HiliteColor = Color.FromArgb(62, 0, 103, 206);
private readonly Color CheckedColor = Color.FromArgb(255, ColorBgra.Blend(new ColorBgra[] { ColorBgra.FromBgra(128, 128, 128, 64), ThemeUtil.backColor })); //Color.FromArgb(129, 52, 153, 254);
private readonly Color ActiveTabColor = ThemeUtil.AccentColor; // Color.FromArgb(255, 52, 153, 254);
public override Color ButtonSelectedHighlight => HiliteColor;
public override Color ButtonSelectedBorder => ActiveTabColor;
public override Color ButtonSelectedGradientBegin => HiliteColor;
public override Color ButtonSelectedGradientMiddle => HiliteColor;
public override Color ButtonSelectedGradientEnd => HiliteColor;
public override Color ButtonSelectedHighlightBorder => BorderColor;
public override Color ButtonPressedHighlight => HiliteColor;
public override Color ButtonPressedGradientBegin => CheckedColor;
public override Color ButtonPressedGradientMiddle => CheckedColor;
public override Color ButtonPressedGradientEnd => CheckedColor;
public override Color ButtonPressedBorder => BorderColor;
public override Color ButtonPressedHighlightBorder => BorderColor;
public override Color ButtonCheckedGradientBegin => CheckedColor;
public override Color ButtonCheckedGradientMiddle => CheckedColor;
public override Color ButtonCheckedGradientEnd => CheckedColor;
public override Color ButtonCheckedHighlight => CheckedColor;
public override Color ButtonCheckedHighlightBorder => ActiveTabColor;
public override Color ToolStripBorder => Color.Transparent;
public override Color ToolStripGradientBegin => BackColor;
public override Color ToolStripGradientMiddle => BackColor;
public override Color ToolStripGradientEnd => BackColor;
public override Color ToolStripDropDownBackground => BackColor;
public override Color OverflowButtonGradientBegin => BackColor;
public override Color OverflowButtonGradientMiddle => BackColor;
public override Color OverflowButtonGradientEnd => BackColor;
}
}
}
}