-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathModernTheme.cs
More file actions
850 lines (713 loc) · 34.4 KB
/
Copy pathModernTheme.cs
File metadata and controls
850 lines (713 loc) · 34.4 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
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
// Design-Rule / UI standards:
// This file defines the shared visual values for the application.
// Forms should reuse these values to keep layout, spacing, colors, sizes, and fonts consistent.
// 03.05.2026 /dc
using System;
using System.Drawing;
namespace EasyVersionBackup
{
public static class ModernTheme
{
// window color settings start
public static readonly Color WindowBackColor = Color.FromArgb(27, 40, 56);
public static readonly Color TitleBarBackColor = Color.FromArgb(23, 26, 33);
public static readonly Color ControlBackColor = Color.FromArgb(42, 71, 94);
public static readonly Color ControlHoverBackColor = Color.FromArgb(55, 90, 120);
public static readonly Color AccentColor = Color.FromArgb(102, 192, 244);
public static readonly Color AccentHoverColor = Color.FromArgb(143, 212, 255);
public static readonly Color TextColor = Color.FromArgb(199, 213, 224);
public static readonly Color DarkTextColor = Color.FromArgb(23, 26, 33);
public static readonly Color CloseButtonHoverColor = Color.FromArgb(196, 43, 28);
public static readonly Color DestructiveActionColor = Color.FromArgb(196, 43, 28);
public static readonly Color DestructiveActionHoverColor = Color.FromArgb(220, 58, 42);
public static readonly Color DestructiveActionPressedColor = Color.FromArgb(154, 32, 22);
// window color settings end
// status color settings start
public static readonly Color BackupInfoDefaultColor = Color.FromArgb(0, 120, 215);
public static readonly Color BackupInfoOkColor = Color.FromArgb(0, 160, 80);
public static readonly Color BackupInfoWarningColor = Color.FromArgb(230, 180, 0);
public static readonly Color BackupInfoCleanupColor = Color.FromArgb(128, 0, 160);
public static readonly Color BackupInfoErrorColor = Color.FromArgb(200, 0, 0);
public static readonly Color BackupInfoTextColor = Color.White;
public static readonly Color ActiveExclusionColor = Color.LimeGreen;
public static readonly Color ActiveRetentionColor = Color.FromArgb(196, 43, 28);
public static readonly Color ActiveSourceCleanupColor = Color.FromArgb(40, 225, 255);
public static readonly Color BackupProgressFillColor = Color.FromArgb(72, 160, 170, 178);
public static readonly Color BackupProgressPulseColor = Color.FromArgb(96, 190, 200, 208);
// public static readonly Color DisabledTextColor = WindowBorderColor;
public static readonly Color DisabledTextColor = Color.FromArgb(92, 104, 112);
public static readonly Color DisabledControlBackColor = Color.FromArgb(32, 43, 56);
// status color settings end
// window border settings start
public static readonly Color WindowBorderColor = Color.FromArgb(92, 104, 112);
public const float WindowBorderWidth = 1F;
// window border settings end
// window font settings start
public const string FontFamilyName = "Segoe UI";
public const float DefaultFontSize = 9F;
public const float TitleFontSize = 9F;
public const float HeaderFontSize = 9F;
// window font settings end
// title bar settings start
public const int TitleBarHeight = 32;
public static readonly Size TitleBarButtonSize = new Size(36, 32);
public const int TitleBarIconSize = 16;
public const int TitleBarIconLeft = 8;
public const int TitleBarIconTop = 8;
public const int TitleBarTextLeft = 30;
// title bar settings end
// backup info dialog layout settings start
public static readonly Size BackupInfoDialogDefaultSize = new Size(760, 430);
public static readonly Size BackupInfoDialogMinimumClientSize = new Size(620, 330);
public const int BackupInfoDialogMargin = 12;
public const int BackupInfoDialogInfoTop = 44;
public const int BackupInfoDialogInfoHeight = 54;
public const int BackupInfoDialogSpacing = 8;
public const int BackupInfoDialogButtonBottomMargin = 12;
public const int BackupInfoDialogResizeGripReservedWidth = 22;
public const int BackupInfoDialogStatusColumnWidth = 56;
public const int BackupInfoDialogDateColumnWidth = 145;
public const int BackupInfoDialogTextColumnMinimumWidth = 260;
public const int BackupInfoDialogMinimumGridHeight = 120;
// backup info dialog layout settings end
// settings layout settings start
public const int SettingsLabelLeft = 26;
public const int SettingsLabelWidth = 145;
public const int SettingsControlLeft = 177;
public const int SettingsInputLeft = 209;
public const int SettingsContentTop = 20;
public const int SettingsRowHeight = 32;
public const int SettingsLabelTopOffset = 3;
public const int SettingsControlHeight = 23;
public const int SettingsLabelHeight = 20;
public const int SettingsComboBoxWidth = 180;
public const int SettingsTimerInputWidth = 70;
public const int SettingsCheckBoxWidth = 18;
public const int SettingsCheckBoxTopOffset = -3;
public const int SettingsHintSpacing = 6;
public static readonly Size SettingsTabButtonSize = new Size(90, 30);
public static readonly Size SettingsHintIconSize = new Size(18, 18);
public const int SettingsHintIconInnerPadding = 1;
public const float SettingsHintIconFontSize = 8F;
public const int SettingsHintIconTextOffsetX = 5;
public const int SettingsHintIconTextOffsetY = 0;
public static int SettingsRowTop(int rowIndex)
{
return SettingsContentTop + SettingsRowHeight * rowIndex;
}
public static int SettingsLabelTop(int rowIndex)
{
return SettingsRowTop(rowIndex) + SettingsLabelTopOffset;
}
public static int SettingsCheckBoxTop(int rowTop)
{
return rowTop + SettingsCheckBoxTopOffset;
}
public static System.Windows.Forms.CheckBox CreateSettingsCheckBox(string name, Point location)
{
return new System.Windows.Forms.CheckBox
{
Name = name,
Text = string.Empty,
Location = location,
Size = new Size(SettingsCheckBoxWidth, SettingsRowHeight),
AutoSize = false,
CheckAlign = System.Drawing.ContentAlignment.MiddleLeft,
BackColor = WindowBackColor,
ForeColor = TextColor,
UseVisualStyleBackColor = false
};
}
// settings layout settings end
// message dialog layout settings start
public static readonly Size MessageDialogDefaultSize = new Size(460, 170);
public static readonly Size MessageDialogMinimumSize = new Size(460, 170);
public const int MessageDialogContentLeft = 18;
public const int MessageDialogContentTop = 50;
public const int MessageDialogContentRightMargin = 18;
public const int MessageDialogButtonBottomMargin = 18;
public const int MessageDialogButtonRightMargin = 18;
public const int MessageDialogButtonAreaHeight = 58;
// message dialog layout settings end
// backup dialog layout settings start
public static readonly Size BackupDialogDefaultSize = new Size(420, 190);
public static readonly Size BackupDialogMinimumSize = new Size(420, 190);
public static readonly Size BackupDialogDestinationConflictMinimumSize = BackupDialogDefaultSize;
public const int BackupDialogContentLeft = 22;
public const int BackupDialogContentTop = 58;
public const int BackupDialogContentRightMargin = 22;
public const int BackupDialogBottomMargin = 20;
public const int BackupDialogPathLabelHeight = 20;
public const int BackupDialogMessageHeight = 82;
public const int BackupDialogControlSpacing = 10;
public const int BackupDialogComboBoxWidth = 180;
public const int BackupDialogResizeGripSize = 16;
// backup dialog layout settings end
// button text positioning settings start
public static readonly System.Windows.Forms.Padding DefaultButtonTextPadding = System.Windows.Forms.Padding.Empty;
public static readonly System.Windows.Forms.Padding DialogButtonTextPadding = System.Windows.Forms.Padding.Empty;
public static readonly System.Windows.Forms.Padding DialogPrimaryButtonTextPadding = new System.Windows.Forms.Padding(0, 0, 0, 1);
public static readonly System.Windows.Forms.Padding DialogSecondaryButtonTextPadding = new System.Windows.Forms.Padding(0, 0, 0, 2);
public static readonly System.Windows.Forms.Padding ToolbarPlusButtonTextPadding = new System.Windows.Forms.Padding(0, 0, 0, 2);
public static readonly System.Windows.Forms.Padding ToolbarMinusButtonTextPadding = new System.Windows.Forms.Padding(0, 0, 0, 2);
public static readonly System.Windows.Forms.Padding MainToolbarButtonTextPadding = new System.Windows.Forms.Padding(0, 0, 0, 2);
// button text positioning settings end
// button size settings start
public static readonly Size DialogButtonSize = new Size(75, 27);
public static readonly Size ToolbarButtonSize = new Size(32, 32);
public static readonly Size MainToolbarButtonSize = ToolbarButtonSize;
public const int ToolbarButtonSpacing = 6;
// button size settings end
// resizable dialog helper start
public static bool IsInResizeGripArea(Size clientSize, Point clientPoint)
{
return clientPoint.X >= clientSize.Width - BackupDialogResizeGripSize &&
clientPoint.Y >= clientSize.Height - BackupDialogResizeGripSize;
}
public static void DrawResizeGrip(Graphics graphics, Size clientSize)
{
using Pen pen = new Pen(WindowBorderColor, 1F);
int right = clientSize.Width - 5;
int bottom = clientSize.Height - 5;
graphics.DrawLine(pen, right - 10, bottom, right, bottom - 10);
graphics.DrawLine(pen, right - 6, bottom, right, bottom - 6);
graphics.DrawLine(pen, right - 2, bottom, right, bottom - 2);
}
// resizable dialog helper end
public static void ApplyInactiveComboBoxStyle(System.Windows.Forms.ComboBox comboBox)
{
comboBox.Enabled = false;
comboBox.TabStop = false;
comboBox.Cursor = System.Windows.Forms.Cursors.Default;
comboBox.BackColor = DisabledControlBackColor;
comboBox.ForeColor = DisabledTextColor;
}
// themed scroll bar start
public static readonly Color DataGridViewScrollBarTrackColor = ControlBackColor;
public static readonly Color DataGridViewScrollBarThumbColor = ControlBackColor;
public const int DataGridViewScrollBarSize = 14;
public const int DataGridViewScrollBarMinimumThumbSize = 24;
public sealed class ModernScrollBar : System.Windows.Forms.Control
{
private bool _isDragging;
private int _dragOffset;
private int _value;
public event EventHandler? ScrollValueChanged;
public System.Windows.Forms.Orientation Orientation { get; set; }
public int Minimum { get; set; }
public int Maximum { get; set; }
public int LargeChange { get; set; } = 1;
public int Value
{
get => _value;
set
{
int normalizedValue = Math.Max(Minimum, Math.Min(Maximum, value));
if (_value == normalizedValue)
{
return;
}
_value = normalizedValue;
Invalidate();
ScrollValueChanged?.Invoke(this, EventArgs.Empty);
}
}
public ModernScrollBar()
{
SetStyle(
System.Windows.Forms.ControlStyles.AllPaintingInWmPaint |
System.Windows.Forms.ControlStyles.UserPaint |
System.Windows.Forms.ControlStyles.OptimizedDoubleBuffer |
System.Windows.Forms.ControlStyles.ResizeRedraw,
true);
BackColor = DataGridViewScrollBarTrackColor;
ForeColor = DataGridViewScrollBarThumbColor;
Cursor = System.Windows.Forms.Cursors.Hand;
}
protected override void OnPaint(System.Windows.Forms.PaintEventArgs e)
{
base.OnPaint(e);
using SolidBrush trackBrush = new SolidBrush(WindowBackColor);
e.Graphics.FillRectangle(trackBrush, ClientRectangle);
if (Maximum <= Minimum)
{
return;
}
using SolidBrush thumbBrush = new SolidBrush(ControlBackColor);
e.Graphics.FillRectangle(thumbBrush, GetThumbRectangle());
}
protected override void OnMouseDown(System.Windows.Forms.MouseEventArgs e)
{
base.OnMouseDown(e);
if (e.Button != System.Windows.Forms.MouseButtons.Left || Maximum <= Minimum)
{
return;
}
Rectangle thumbRectangle = GetThumbRectangle();
int mousePosition = Orientation == System.Windows.Forms.Orientation.Vertical ? e.Y : e.X;
if (thumbRectangle.Contains(e.Location))
{
_isDragging = true;
_dragOffset = mousePosition - (Orientation == System.Windows.Forms.Orientation.Vertical ? thumbRectangle.Top : thumbRectangle.Left);
Capture = true;
return;
}
Value += mousePosition < (Orientation == System.Windows.Forms.Orientation.Vertical ? thumbRectangle.Top : thumbRectangle.Left)
? -LargeChange
: LargeChange;
}
protected override void OnMouseMove(System.Windows.Forms.MouseEventArgs e)
{
base.OnMouseMove(e);
if (!_isDragging || Maximum <= Minimum)
{
return;
}
int length = Orientation == System.Windows.Forms.Orientation.Vertical ? Height : Width;
Rectangle thumbRectangle = GetThumbRectangle();
int availableTrack = Math.Max(1, length - (Orientation == System.Windows.Forms.Orientation.Vertical ? thumbRectangle.Height : thumbRectangle.Width));
int mousePosition = Orientation == System.Windows.Forms.Orientation.Vertical ? e.Y : e.X;
int thumbStart = Math.Max(0, Math.Min(availableTrack, mousePosition - _dragOffset));
Value = Minimum + (int)Math.Round((double)thumbStart / availableTrack * (Maximum - Minimum));
}
protected override void OnMouseUp(System.Windows.Forms.MouseEventArgs e)
{
base.OnMouseUp(e);
_isDragging = false;
Capture = false;
}
protected override void OnMouseWheel(System.Windows.Forms.MouseEventArgs e)
{
base.OnMouseWheel(e);
if (Maximum <= Minimum)
{
return;
}
Value += e.Delta > 0 ? -1 : 1;
}
private Rectangle GetThumbRectangle()
{
int length = Orientation == System.Windows.Forms.Orientation.Vertical ? Height : Width;
int thickness = Orientation == System.Windows.Forms.Orientation.Vertical ? Width : Height;
if (length <= 0 || thickness <= 0)
{
return Rectangle.Empty;
}
int scrollableRange = Math.Max(0, Maximum - Minimum);
int largeChange = Math.Max(1, LargeChange);
int virtualItemCount = Math.Max(1, scrollableRange + largeChange);
int thumbLength = scrollableRange == 0
? length
: (int)Math.Round(length * ((double)largeChange / virtualItemCount));
thumbLength = Math.Max(DataGridViewScrollBarMinimumThumbSize, thumbLength);
thumbLength = Math.Min(length, thumbLength);
int availableTrack = Math.Max(1, length - thumbLength);
int thumbStart = scrollableRange == 0
? 0
: (int)Math.Round((double)(Value - Minimum) / scrollableRange * availableTrack);
thumbStart = Math.Max(0, Math.Min(availableTrack, thumbStart));
return Orientation == System.Windows.Forms.Orientation.Vertical
? new Rectangle(0, thumbStart, thickness, thumbLength)
: new Rectangle(thumbStart, 0, thumbLength, thickness);
}
}
// themed scroll bar end
// shared icon drawing start
public static void DrawSettingsIcon(Graphics graphics, Rectangle bounds, Color outlineColor, float penWidth)
{
System.Drawing.Drawing2D.SmoothingMode previousSmoothingMode = graphics.SmoothingMode;
graphics.SmoothingMode = System.Drawing.Drawing2D.SmoothingMode.AntiAlias;
using Pen pen = new Pen(outlineColor, penWidth)
{
StartCap = System.Drawing.Drawing2D.LineCap.Square,
EndCap = System.Drawing.Drawing2D.LineCap.Square,
LineJoin = System.Drawing.Drawing2D.LineJoin.Miter
};
int left = bounds.Left + (bounds.Width - 18) / 2;
int top = bounds.Top + (bounds.Height - 19) / 2;
Point[] gearPoints =
{
new Point(left + 7, top),
new Point(left + 11, top),
new Point(left + 11, top + 3),
new Point(left + 12, top + 4),
new Point(left + 15, top + 2),
new Point(left + 17, top + 4),
new Point(left + 15, top + 7),
new Point(left + 16, top + 8),
new Point(left + 18, top + 8),
new Point(left + 18, top + 10),
new Point(left + 16, top + 10),
new Point(left + 15, top + 12),
new Point(left + 17, top + 15),
new Point(left + 15, top + 17),
new Point(left + 12, top + 15),
new Point(left + 11, top + 16),
new Point(left + 11, top + 19),
new Point(left + 7, top + 19),
new Point(left + 7, top + 16),
new Point(left + 6, top + 15),
new Point(left + 3, top + 17),
new Point(left + 1, top + 15),
new Point(left + 3, top + 12),
new Point(left + 2, top + 10),
new Point(left, top + 10),
new Point(left, top + 8),
new Point(left + 2, top + 8),
new Point(left + 3, top + 7),
new Point(left + 1, top + 4),
new Point(left + 3, top + 2),
new Point(left + 6, top + 4),
new Point(left + 7, top + 3)
};
graphics.DrawPolygon(pen, gearPoints);
graphics.DrawEllipse(pen, left + 6, top + 6, 6, 6);
graphics.SmoothingMode = previousSmoothingMode;
}
public static void DrawSettingsIcon(
Graphics graphics,
Rectangle bounds,
Color outlineColor,
float penWidth,
Color fillColor)
{
System.Drawing.Drawing2D.SmoothingMode previousSmoothingMode =
graphics.SmoothingMode;
graphics.SmoothingMode =
System.Drawing.Drawing2D.SmoothingMode.AntiAlias;
int left = bounds.Left + (bounds.Width - 18) / 2;
int top = bounds.Top + (bounds.Height - 19) / 2;
Point[] gearPoints =
{
new Point(left + 7, top),
new Point(left + 11, top),
new Point(left + 11, top + 3),
new Point(left + 12, top + 4),
new Point(left + 15, top + 2),
new Point(left + 17, top + 4),
new Point(left + 15, top + 7),
new Point(left + 16, top + 8),
new Point(left + 18, top + 8),
new Point(left + 18, top + 10),
new Point(left + 16, top + 10),
new Point(left + 15, top + 12),
new Point(left + 17, top + 15),
new Point(left + 15, top + 17),
new Point(left + 12, top + 15),
new Point(left + 11, top + 16),
new Point(left + 11, top + 19),
new Point(left + 7, top + 19),
new Point(left + 7, top + 16),
new Point(left + 6, top + 15),
new Point(left + 3, top + 17),
new Point(left + 1, top + 15),
new Point(left + 3, top + 12),
new Point(left + 2, top + 10),
new Point(left, top + 10),
new Point(left, top + 8),
new Point(left + 2, top + 8),
new Point(left + 3, top + 7),
new Point(left + 1, top + 4),
new Point(left + 3, top + 2),
new Point(left + 6, top + 4),
new Point(left + 7, top + 3)
};
using SolidBrush fillBrush = new SolidBrush(fillColor);
graphics.FillPolygon(fillBrush, gearPoints);
using Pen pen = new Pen(outlineColor, penWidth)
{
StartCap = System.Drawing.Drawing2D.LineCap.Square,
EndCap = System.Drawing.Drawing2D.LineCap.Square,
LineJoin = System.Drawing.Drawing2D.LineJoin.Miter
};
graphics.DrawPolygon(pen, gearPoints);
using SolidBrush centerBrush =
new SolidBrush(WindowBackColor);
graphics.FillEllipse(
centerBrush,
left + 6,
top + 6,
6,
6);
graphics.DrawEllipse(
pen,
left + 6,
top + 6,
6,
6);
graphics.SmoothingMode = previousSmoothingMode;
}
public static void DrawSettingsIcon(
Graphics graphics,
Rectangle bounds,
Color outlineColor,
float penWidth,
Color leftFillColor,
Color rightFillColor)
{
System.Drawing.Drawing2D.SmoothingMode previousSmoothingMode =
graphics.SmoothingMode;
graphics.SmoothingMode =
System.Drawing.Drawing2D.SmoothingMode.AntiAlias;
int left = bounds.Left + (bounds.Width - 18) / 2;
int top = bounds.Top + (bounds.Height - 19) / 2;
Point[] gearPoints =
{
new Point(left + 7, top),
new Point(left + 11, top),
new Point(left + 11, top + 3),
new Point(left + 12, top + 4),
new Point(left + 15, top + 2),
new Point(left + 17, top + 4),
new Point(left + 15, top + 7),
new Point(left + 16, top + 8),
new Point(left + 18, top + 8),
new Point(left + 18, top + 10),
new Point(left + 16, top + 10),
new Point(left + 15, top + 12),
new Point(left + 17, top + 15),
new Point(left + 15, top + 17),
new Point(left + 12, top + 15),
new Point(left + 11, top + 16),
new Point(left + 11, top + 19),
new Point(left + 7, top + 19),
new Point(left + 7, top + 16),
new Point(left + 6, top + 15),
new Point(left + 3, top + 17),
new Point(left + 1, top + 15),
new Point(left + 3, top + 12),
new Point(left + 2, top + 10),
new Point(left, top + 10),
new Point(left, top + 8),
new Point(left + 2, top + 8),
new Point(left + 3, top + 7),
new Point(left + 1, top + 4),
new Point(left + 3, top + 2),
new Point(left + 6, top + 4),
new Point(left + 7, top + 3)
};
System.Drawing.Drawing2D.GraphicsState graphicsState =
graphics.Save();
using System.Drawing.Drawing2D.GraphicsPath gearPath =
new System.Drawing.Drawing2D.GraphicsPath();
gearPath.AddPolygon(gearPoints);
graphics.SetClip(gearPath);
using SolidBrush leftFillBrush =
new SolidBrush(leftFillColor);
using SolidBrush rightFillBrush =
new SolidBrush(rightFillColor);
graphics.FillRectangle(
leftFillBrush,
left,
top,
9,
19);
graphics.FillRectangle(
rightFillBrush,
left + 9,
top,
9,
19);
graphics.Restore(graphicsState);
using Pen pen = new Pen(outlineColor, penWidth)
{
StartCap =
System.Drawing.Drawing2D.LineCap.Square,
EndCap =
System.Drawing.Drawing2D.LineCap.Square,
LineJoin =
System.Drawing.Drawing2D.LineJoin.Miter
};
graphics.DrawPolygon(pen, gearPoints);
using SolidBrush centerBrush =
new SolidBrush(WindowBackColor);
graphics.FillEllipse(
centerBrush,
left + 6,
top + 6,
6,
6);
graphics.DrawEllipse(
pen,
left + 6,
top + 6,
6,
6);
graphics.SmoothingMode = previousSmoothingMode;
}
public static void DrawSettingsStatusMarker(
Graphics graphics,
Rectangle bounds,
string markerText,
Color markerColor,
Color markerTextColor,
bool topLeft)
{
System.Drawing.Drawing2D.SmoothingMode previousSmoothingMode =
graphics.SmoothingMode;
graphics.SmoothingMode =
System.Drawing.Drawing2D.SmoothingMode.AntiAlias;
const int markerSize = 11;
int gearLeft =
bounds.Left +
(bounds.Width - 18) / 2;
int gearTop =
bounds.Top +
(bounds.Height - 19) / 2;
int markerLeft =
topLeft
? gearLeft - 4
: gearLeft + 11;
int markerTop =
topLeft
? gearTop - 3
: gearTop + 12;
Rectangle markerBounds =
new Rectangle(
markerLeft,
markerTop,
markerSize,
markerSize);
using SolidBrush markerBrush =
new SolidBrush(markerColor);
graphics.FillEllipse(
markerBrush,
markerBounds);
using Pen markerOutlinePen =
new Pen(WindowBackColor, 1F);
graphics.DrawEllipse(
markerOutlinePen,
markerBounds);
using Font markerFont =
new Font(
FontFamilyName,
6.5F,
FontStyle.Bold,
GraphicsUnit.Point);
TextRenderer.DrawText(
graphics,
markerText,
markerFont,
markerBounds,
markerTextColor,
TextFormatFlags.HorizontalCenter |
TextFormatFlags.VerticalCenter |
TextFormatFlags.NoPadding |
TextFormatFlags.SingleLine);
graphics.SmoothingMode =
previousSmoothingMode;
}
public static void DrawBackupInfoStatusIcon(Graphics graphics, Rectangle bounds, Color color)
{
System.Drawing.Drawing2D.SmoothingMode previousSmoothingMode = graphics.SmoothingMode;
graphics.SmoothingMode = System.Drawing.Drawing2D.SmoothingMode.AntiAlias;
using SolidBrush circleBrush = new SolidBrush(color);
graphics.FillEllipse(circleBrush, bounds);
using SolidBrush iconBrush = new SolidBrush(BackupInfoTextColor);
int centerX = bounds.Left + bounds.Width / 2;
graphics.FillEllipse(iconBrush, centerX - 1, bounds.Top + 3, 2, 2);
graphics.FillRectangle(iconBrush, centerX - 1, bounds.Top + 7, 2, bounds.Height - 10);
graphics.SmoothingMode = previousSmoothingMode;
}
public static void DrawBackupInfoCleanupStatusIcon(Graphics graphics, Rectangle bounds)
{
System.Drawing.Drawing2D.SmoothingMode previousSmoothingMode = graphics.SmoothingMode;
graphics.SmoothingMode = System.Drawing.Drawing2D.SmoothingMode.AntiAlias;
using SolidBrush circleBrush = new SolidBrush(BackupInfoCleanupColor);
graphics.FillEllipse(circleBrush, bounds);
using Font iconFont = new Font(
FontFamilyName,
8F,
FontStyle.Bold,
GraphicsUnit.Point);
using SolidBrush iconBrush = new SolidBrush(BackupInfoTextColor);
SizeF textSize = graphics.MeasureString("C", iconFont);
float textX = bounds.Left + (bounds.Width - textSize.Width) / 2F;
float textY = bounds.Top + (bounds.Height - textSize.Height) / 2F - 0.5F;
graphics.DrawString("C", iconFont, iconBrush, textX, textY);
graphics.SmoothingMode = previousSmoothingMode;
}
// shared icon drawing end
// dialog button factory start
public static System.Windows.Forms.Button CreateDialogPrimaryButton(string name, string text)
{
System.Windows.Forms.Button button = CreateDialogButton(name, text, AccentColor, DarkTextColor, System.Windows.Forms.DialogResult.None);
button.FlatAppearance.BorderSize = 0;
return button;
}
public static System.Windows.Forms.Button CreateDialogSecondaryButton(string name, string text, System.Windows.Forms.DialogResult dialogResult)
{
System.Windows.Forms.Button button = CreateDialogButton(name, text, ControlBackColor, TextColor, dialogResult);
button.FlatAppearance.BorderColor = AccentColor;
button.FlatAppearance.BorderSize = 1;
return button;
}
public static void PositionSingleDialogButton(System.Windows.Forms.Control parent, System.Windows.Forms.Button button, bool reserveResizeGrip)
{
int rightMargin = reserveResizeGrip
? MessageDialogButtonRightMargin + BackupDialogResizeGripSize
: MessageDialogButtonRightMargin;
button.Location = new Point(
parent.ClientSize.Width - rightMargin - DialogButtonSize.Width,
parent.ClientSize.Height - MessageDialogButtonBottomMargin - DialogButtonSize.Height);
}
public static void PositionDialogButtons(System.Windows.Forms.Control parent, System.Windows.Forms.Button primaryButton, System.Windows.Forms.Button secondaryButton)
{
PositionDialogButtons(parent, primaryButton, secondaryButton, false);
}
public static void PositionDialogButtons(System.Windows.Forms.Control parent, System.Windows.Forms.Button primaryButton, System.Windows.Forms.Button secondaryButton, bool reserveResizeGrip)
{
int rightMargin = reserveResizeGrip
? BackupDialogContentRightMargin + BackupDialogResizeGripSize
: BackupDialogContentRightMargin;
secondaryButton.Location = new Point(
parent.ClientSize.Width - rightMargin - DialogButtonSize.Width,
parent.ClientSize.Height - BackupDialogBottomMargin - DialogButtonSize.Height);
primaryButton.Location = new Point(
secondaryButton.Left - ToolbarButtonSpacing - DialogButtonSize.Width,
secondaryButton.Top);
}
private static System.Windows.Forms.Button CreateDialogButton(string name, string text, Color backColor, Color foreColor, System.Windows.Forms.DialogResult dialogResult)
{
System.Windows.Forms.Button button = new System.Windows.Forms.Button
{
Name = name,
Text = string.Empty,
Tag = text,
Size = DialogButtonSize,
Anchor = System.Windows.Forms.AnchorStyles.Right | System.Windows.Forms.AnchorStyles.Bottom,
DialogResult = dialogResult,
FlatStyle = System.Windows.Forms.FlatStyle.Flat,
BackColor = backColor,
ForeColor = foreColor,
Cursor = System.Windows.Forms.Cursors.Hand,
TextAlign = ContentAlignment.MiddleCenter,
Padding = DialogButtonTextPadding,
UseVisualStyleBackColor = false
};
button.FlatAppearance.MouseOverBackColor = ControlHoverBackColor;
button.FlatAppearance.MouseDownBackColor = AccentColor;
button.Paint += DialogButton_Paint;
return button;
}
private static void DialogButton_Paint(object? sender, System.Windows.Forms.PaintEventArgs e)
{
if (sender is not System.Windows.Forms.Button button)
{
return;
}
string text = button.Tag as string ?? string.Empty;
System.Windows.Forms.TextRenderer.DrawText(
e.Graphics,
text,
button.Font,
button.ClientRectangle,
button.ForeColor,
System.Windows.Forms.TextFormatFlags.HorizontalCenter |
System.Windows.Forms.TextFormatFlags.VerticalCenter |
System.Windows.Forms.TextFormatFlags.NoPadding |
System.Windows.Forms.TextFormatFlags.EndEllipsis);
}
// dialog button factory end
}
}