forked from ArduPilot/MissionPlanner
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathThemeManager.cs
More file actions
1430 lines (1277 loc) · 64.3 KB
/
ThemeManager.cs
File metadata and controls
1430 lines (1277 loc) · 64.3 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
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
using BrightIdeasSoftware;
using log4net;
using MissionPlanner.Controls;
using MissionPlanner.Controls.BackstageView;
using MissionPlanner.Controls.PreFlight;
using System;
using System.Drawing;
using System.IO;
using System.Linq;
using System.Reflection;
using System.Windows.Forms;
using System.Collections.Generic;
using System.Xml.Serialization;
using System.Xml;
namespace MissionPlanner.Utilities
{
//ThemeColor class is describe an item in a theme.
// strColorItemName is the variable name of the
public class ThemeColor
{
public String strColorItemName { get; set; }
[XmlElement(Type = typeof(XmlColor))]
public Color clrColor { get; set; }
public String strVariableName { get; set; }
}
public class ThemeColorList : List<ThemeColor>
{
public void Add(String _strColor, Color _clrColor, String _strVariable)
{
var data = new ThemeColor
{
strColorItemName = _strColor,
clrColor = _clrColor,
strVariableName = _strVariable
};
this.Add(data);
}
}
public class ThemeColorTable
{
public enum IconSet
{
BurnKermitIconSet,
HighContrastIconSet,
}
public String strThemeName { get; set; }
public ThemeColorList colors { get; set; }
public IconSet iconSet { get; set; }
public bool terminalTheming { get; set; }
public ThemeColorTable()
{
colors = new ThemeColorList();
}
public void InitColors()
{
iconSet = IconSet.BurnKermitIconSet;
terminalTheming = true;
strThemeName = "BurntKermit.mpsystheme";
colors.Add("Background", Color.FromArgb(0x26, 0x27, 0x28), "BGColor"); // This changes the colour of the main menu background
colors.Add("Control Background", Color.FromArgb(0x43, 0x44, 0x45), "ControlBGColor"); // This changes the colour of the sub menu backgrounds
colors.Add("Text", Color.White, "TextColor"); // This changes the colour of text
colors.Add("TextBox Background", Color.FromArgb(0x43, 0x44, 0x45), "BGColorTextBox"); // This changes the colour of the background of textboxes
colors.Add("Button Text", Color.FromArgb(64, 87, 4), "ButtonTextColor"); // This changes the colour of button text
colors.Add("Button Background top", Color.FromArgb(148, 193, 31), "ButBG"); // This changes the colour of button backgrounds (Top)
colors.Add("Button Background bottom", Color.FromArgb(205, 226, 150), "ButBGBot"); // This changes the colour of button backgrounds (Bot)
colors.Add("ProgressBar Top", Color.FromArgb(102, 139, 26), "ProgressBarColorTop"); // These three variables change the colours of progress bars
colors.Add("ProgressBar Bottom", Color.FromArgb(124, 164, 40), "ProgressBarColorBot");
colors.Add("ProgressBar Outline", Color.FromArgb(150, 174, 112), "ProgressBarOutlineColor");
colors.Add("BannerColor1", Color.FromArgb(0x40, 0x57, 0x04), "BannerColor1"); // These two variables change the colours of banners such as "planner" umder configuration
colors.Add("BannerColor2", Color.FromArgb(0x94, 0xC1, 0x1F), "BannerColor2");
colors.Add("Disabled Button", Color.FromArgb(150, 43, 58, 3), "ColorNotEnabled"); // This changes the background color of buttons when not enabled
colors.Add("Button Mouseover", Color.FromArgb(73, 43, 58, 3), "ColorMouseOver"); // This changes the background color of buttons when the mouse is hovering over a button
colors.Add("Button Mousedown", Color.FromArgb(73, 43, 58, 3), "ColorMouseDown"); // This changes the background color of buttons when the mouse is clicked down on a button
colors.Add("CurrentPPM Background", Color.Green, "CurrentPPMBackground"); // This changes the background colour of the current PPM setting in the flight modes tab
colors.Add("Graph Chart Fill", Color.FromArgb(0x1F, 0x1F, 0x20), "ZedGraphChartFill"); // These three variables change the fill colours of Zed Graphs
colors.Add("Graph Pane Fill", Color.FromArgb(0x37, 0x37, 0x38), "ZedGraphPaneFill");
colors.Add("Graph Legend Fill", Color.FromArgb(0x85, 0x84, 0x83), "ZedGraphLegendFill");
colors.Add("Rich Text Box text", Color.WhiteSmoke, "RTBForeColor"); // This changes the colour of text in rich text boxes
colors.Add("BackStageView Button Area", Color.Black, "BSVButtonAreaBGColor"); // This changes the colour of a backstageview button area
colors.Add("BSV Unselected Text", Color.WhiteSmoke, "UnselectedTextColour"); // This changes the colour of unselected text in a BSV button
colors.Add("Horizontal ProgressBar", Color.FromArgb(148, 193, 31), "HorizontalPBValueColor"); // This changes the colour of the horizontal progressbar
colors.Add("HUD text and drawings", Color.LightGray, "HudText");
colors.Add("HUD Ground top", Color.FromArgb(0x9b, 0xb8, 0x24), "HudGroundTop");
colors.Add("HUD Ground bottom", Color.FromArgb(0x41, 0x4f, 0x07), "HudGroundBot");
colors.Add("HUD Sky top", Color.Blue, "HudSkyTop");
colors.Add("HUD Sky bottom", Color.LightBlue, "HudSkyBot");
}
public void SetTheme()
{
foreach (ThemeColor _color in colors)
{
Type objType = typeof(ThemeManager);
FieldInfo info = objType.GetField(_color.strVariableName);
if (info != null && info.FieldType.Name.Equals("Color") )
{
info.SetValue(objType, _color.clrColor);
Console.WriteLine(_color.strColorItemName + " to " + _color.clrColor);
}
else
{
Console.WriteLine("No such field as :" + _color.strVariableName);
}
}
if (MainV2.instance != null)
{
switch (iconSet)
{
case IconSet.BurnKermitIconSet:
MainV2.instance.switchicons(new MainV2.burntkermitmenuicons());
break;
case IconSet.HighContrastIconSet:
MainV2.instance.switchicons(new MainV2.highcontrastmenuicons());
break;
default:
MainV2.instance.switchicons(new MainV2.burntkermitmenuicons()); //Fall back to BurntKermit
break;
}
}
MainV2.TerminalTheming = terminalTheming;
Settings.Instance["terminaltheming"] = terminalTheming.ToString();
//HUD Color setting
if (GCSViews.FlightData.myhud != null)
{
GCSViews.FlightData.myhud.groundColor1 = ThemeManager.HudGroundTop;
GCSViews.FlightData.myhud.groundColor2 = ThemeManager.HudGroundBot;
GCSViews.FlightData.myhud.skyColor1 = ThemeManager.HudSkyTop;
GCSViews.FlightData.myhud.skyColor2 = ThemeManager.HudSkyBot;
GCSViews.FlightData.myhud.hudcolor = ThemeManager.HudText;
}
}
}
/// <summary>
/// An attribute which prevents the automatic theming of components
/// </summary>
public class PreventThemingAttribute : Attribute { };
/// <summary>
/// Helper class for the stylng 'theming' of forms and controls, and provides MessageBox
/// replacements which are also styled
/// </summary>
public class ThemeManager
{
private static readonly ILog log =
LogManager.GetLogger(System.Reflection.MethodBase.GetCurrentMethod().DeclaringType);
// Initialize to the default theme (BurntKermit)
public static Color BGColor = Color.FromArgb(0x26, 0x27, 0x28);
public static Color ControlBGColor = Color.FromArgb(0x43, 0x44, 0x45);
public static Color TextColor = Color.White;
public static Color BGColorTextBox;
public static Color ButBG;
public static Color ButBGBot;
public static Color ButBorder;
public static Color ProgressBarColorTop;
public static Color ProgressBarColorBot;
public static Color ProgressBarOutlineColor;
public static Color ColorNotEnabled;
public static Color ColorMouseOver;
public static Color ColorMouseDown;
public static Color BannerColor1;
public static Color BannerColor2;
public static Color ButtonTextColor;
public static Color ButtonTextColorNotEnabled;
public static Color CurrentPPMBackground;
public static Color ZedGraphChartFill;
public static Color ZedGraphPaneFill;
public static Color ZedGraphLegendFill;
public static Color RTBForeColor;
public static Color BSVButtonAreaBGColor;
public static Color UnselectedTextColour;
public static Color HorizontalPBValueColor;
public static Color HudText;
public static Color HudGroundTop;
public static Color HudGroundBot;
public static Color HudSkyTop;
public static Color HudSkyBot;
public static ThemeColorTable thmColor;
public static List<String> ThemeNames;
public static void GetThemesList()
{
String runningDir = Settings.GetRunningDirectory();
String userDir = Settings.GetUserDataDirectory();
if (ThemeNames == null)
{
ThemeNames = new List<String>();
}
else
{
ThemeNames.Clear();
}
try
{
//Get default themes from program directory (system themes are read only)
var themeFiles = Directory.EnumerateFiles(runningDir, "*.mpsystheme");
foreach (string currentFile in themeFiles)
{
ThemeNames.Add(Path.GetFileName(currentFile));
}
}
catch (Exception ex)
{
log.Error(ex);
}
try
{
//Get theme files from user directory (user themes can be overwritten)
var themeFiles = Directory.EnumerateFiles(userDir, "*.mpusertheme");
foreach (string currentFile in themeFiles)
{
ThemeNames.Add(Path.GetFileName(currentFile));
}
}
catch (Exception ex)
{
log.Error(ex);
}
}
public static void LoadTheme(string strThemeName)
{
string themeFileToLoad = "";
Console.WriteLine(strThemeName + " theme is loading");
ThemeManager.GetThemesList();
//check theme extension to determine location (mpsystheme is in the program directory, mpusertheme is in the userdata directory)
if (Path.GetExtension(strThemeName).Equals(".mpsystheme", StringComparison.OrdinalIgnoreCase))
{
themeFileToLoad = Settings.GetRunningDirectory() + strThemeName;
}
else
{
themeFileToLoad = Settings.GetUserDataDirectory() + strThemeName;
}
try
{
ThemeManager.thmColor = ThemeManager.ReadFromXmlFile<ThemeColorTable>(themeFileToLoad);
if (ThemeManager.thmColor != null)
ThemeManager.thmColor.strThemeName = strThemeName;
}
catch
{
ThemeManager.thmColor = new ThemeColorTable(); //Init colortable
ThemeManager.thmColor.InitColors();
}
if (ThemeManager.thmColor == null)
{
ThemeManager.thmColor = new ThemeColorTable(); //Init colortable
ThemeManager.thmColor.InitColors();
}
//Copy color values to the ThemeManager color variables
ThemeManager.thmColor.SetTheme();
Settings.Instance["theme"] = ThemeManager.thmColor.strThemeName;
}
public static void StartThemeEditor()
{
new ThemeEditor().ShowDialog();
}
public static void ApplyThemeTo(object control)
{
if (control is Control)
ApplyThemeTo(control as Control);
}
/// <summary>
/// Will recursively apply the current theme to 'control' unless the control has the
/// PreventTheming attribute
/// </summary>
/// <param name="control"></param>
public static void ApplyThemeTo(Control control)
{
if (control is ContainerControl)
((ContainerControl)control).AutoScaleMode = AutoScaleMode.None;
if (control.GetType().IsDefined(typeof(PreventThemingAttribute)))
return;
ApplyTheme(control, 0);
}
public static Color getQvNumberColor()
{
//The mix color is set to the inverse of background color, so white background will get dark colors
Color mix = Color.FromArgb(ThemeManager.BGColor.ToArgb() ^ 0xffffff);
Random random = new Random();
int red = random.Next(256);
int green = random.Next(256);
int blue = random.Next(256);
// mix the color
if (mix != null)
{
red = (red + mix.R) / 2;
green = (green + mix.G) / 2;
blue = (blue + mix.B) / 2;
}
var col = Color.FromArgb(red, green, blue);
return col;
}
public static void doxamlgen()
{
var asm = Assembly.GetExecutingAssembly();
var temp = asm.GetTypes().Select(a =>
{
if (a.IsSubclassOf(typeof(Control)))
{
try
{
return (Control)Activator.CreateInstance(a);
}
catch { }
}
return null;
}).ToList();
asm = typeof(ImageLabel).Assembly;
var temp2 = asm.GetTypes().Select(a =>
{
if (a.IsSubclassOf(typeof(Control)))
{
try
{
return (Control)Activator.CreateInstance(a);
}
catch { }
}
return null;
}).ToList();
temp.AddRange(temp2);
foreach (var ctl in temp)
{
if (ctl == null)
continue;
xaml(ctl);
html(ctl);
}
}
public static void html(Control control)
{
Type ty = control.GetType();
StreamWriter st = new StreamWriter(File.Open(ty.FullName + ".html", FileMode.Create));
dohtmlctls(control, st);
st.Close();
}
private static void dohtmlctls(Control control, StreamWriter st, int x = 0, int y = 0)
{
foreach (Control ctl in control.Controls)
{
var font = "font-family:" + ctl.Font.FontFamily + ";";
var fontsize = "font-size:" + ctl.Font.SizeInPoints + "pt;";
var fontcol = "color:" + System.Drawing.ColorTranslator.ToHtml(ctl.ForeColor) + ";";
var bgcol = "background-color:" + System.Drawing.ColorTranslator.ToHtml(ctl.BackColor) + ";";
if (ctl.Parent != null)
{
if (ctl.Parent.Font == ctl.Font)
font = "";
if (ctl.Parent.ForeColor == ctl.ForeColor)
font = "";
if (ctl.Parent.BackColor == ctl.BackColor)
font = "";
}
if (ctl.AutoSize == false)
{
st.WriteLine(@"<div class='" + ctl.GetType() + " " + ctl.Name + @"' " +
"style='" + font + fontsize + fontcol + bgcol +
"overflow:hidden;position: absolute; top: " + (y + ctl.Location.Y) + "; left: " +
(x + ctl.Location.X) + ";width:" + ctl.Width + ";height:" + ctl.Height + ";' >");
}
else
{
st.WriteLine(@"<div class='" + ctl.GetType() + " " + ctl.Name + @"' " +
"style='" + font + fontsize + fontcol + bgcol +
"overflow:hidden;position: absolute; top: " + (y + ctl.Location.Y) + "; left: " +
(x + ctl.Location.X) + ";' >");
}
if (ctl.GetType() == typeof(ComboBox) || ctl.GetType() == typeof(MavlinkComboBox))
{
st.WriteLine(@"<select name='{0}'>", ctl.Name);
(ctl as ComboBox).Items.ForEach(a => st.WriteLine(@"<option value='{0}'>{1}</option>", a, a));
st.WriteLine(@"</select>");
}
else if (ctl.GetType() == typeof(TextBox))
{
st.WriteLine(@"<input name='{0}' value='{1}'>", ctl.Name, ctl.Text);
st.WriteLine(@"</input>");
}
else if (ctl.GetType() == typeof(TrackBar))
{
var tb = ctl as TrackBar;
st.WriteLine(@"<input name='{0}' type='range' style=' width:100%; height:100%;' value='{1}' orient='{2}'>", ctl.Name, ctl.Text, tb.Orientation == Orientation.Vertical ? "vertical" : "horizontal");
st.WriteLine(@"</input>");
}
else if (ctl.GetType() == typeof(NumericUpDown))
{
st.WriteLine(@"<input name='{0}' type='number'>", ctl.Name);
st.Write(ctl.Text);
st.WriteLine(@"</input>");
}
else if (ctl.GetType() == typeof(DomainUpDown))
{
st.WriteLine(@"<input name='{0}' type='number'>", ctl.Name);
st.Write(ctl.Text);
st.WriteLine(@"</input>");
}
else if (ctl.GetType() == typeof(RadioButton))
{
st.WriteLine(@"<input name='{0}' type='radio'>", ctl.Name);
st.Write(ctl.Text);
st.WriteLine(@"</input>");
}
else if (ctl.GetType() == typeof(CheckBox))
{
st.WriteLine(@"<input name='{0}' type='checkbox'>", ctl.Name);
st.Write(ctl.Text);
st.WriteLine(@"</input>");
}
else if (ctl.GetType() == typeof(MyButton) || ctl.GetType() == typeof(Button))
{
st.WriteLine(@"<input name='{0}' type='button' value='{1}'>", ctl.Name, ctl.Text);
st.WriteLine(@"</input>");
}
else if (ctl.GetType() == typeof(MyLabel) || ctl.GetType() == typeof(Label))
{
st.Write(ctl.Text);
}
else if (ctl.GetType() == typeof(FlowLayoutPanel))
{
var flow = ctl as FlowLayoutPanel;
st.Write(ctl.Text);
}
else if (ctl.GetType() == typeof(VerticalProgressBar2))
{
st.WriteLine(@"<progress name='{0}' type='button' value='{1}' style=' width:100%; height:100%; margin-top: 100px; margin-left: -50px; transform: rotate(90deg);'>", ctl.Name, ctl.Text);
st.WriteLine(@"</progress>");
}
else
{
st.Write(ctl.Text);
}
if (ctl.Controls.Count > 0)
{
dohtmlctls(ctl, st, 0, 0);
}
st.WriteLine(@"</div>");
}
}
static object locker = new object();
public static void xaml(Control control)
{
try
{
lock (locker)
{
Type ty = control.GetType();
StreamWriter st = new StreamWriter(File.Open(ty.FullName + ".xaml", FileMode.Create));
string header = @"<UserControl x:Class=""" + ty.FullName + @""" d:DesignHeight=""" + control.Height +
@""" d:DesignWidth=""" + control.Width + @"""
xmlns=""http://schemas.microsoft.com/winfx/2006/xaml/presentation""
xmlns:x=""http://schemas.microsoft.com/winfx/2006/xaml""
xmlns:mc=""http://schemas.openxmlformats.org/markup-compatibility/2006""
xmlns:d=""http://schemas.microsoft.com/expression/blend/2008""
xmlns:xctk=""http://schemas.xceed.com/wpf/xaml/toolkit""
xmlns:BackstageView=""using:MissionPlanner.Controls.BackstageView""
xmlns:Controls=""using:MissionPlanner.Controls""
xmlns:GCSViews=""using:MissionPlanner.GCSViews""
xmlns:Wizard=""using:MissionPlanner.Wizard""
xmlns:ConfigurationView=""using:MissionPlanner.GCSViews.ConfigurationView""
xmlns:Custom=""using:Custom""
xmlns:controls=""using:Microsoft.Toolkit.Uwp.UI.Controls""
xmlns:PreFlight=""using:MissionPlanner.Controls.PreFlight""
mc:Ignorable=""d""
> <Grid>";
st.Write(header);
doxamlctls(control, st);
string footer = "</Grid></UserControl>";
st.Write(footer);
st.Close();
var ctl = control;
File.WriteAllText(ctl.GetType().FullName + ".xaml.cs", @"namespace " + ctl.GetType().Namespace + " { public partial class " + ctl.GetType().Name + "{public " + ctl.GetType().Name + "(){this.InitializeComponent();}}}");
}
}
catch
{
}
}
private static void doxamlctls(Control control, StreamWriter st)
{
foreach (Control ctl in control.Controls)
{
if (ctl is QuickView || ctl is ServoOptions || ctl is ModifyandSet
|| ctl is Coords /*|| ctl is AGaugeApp.AGauge*/|| ctl is MissionPlanner.Controls.HUD
|| ctl is ImageLabel || ctl is RelayOptions || ctl is CheckListControl
|| ctl is MavlinkCheckBox)
{
// st.WriteLine(@"<WindowsFormsHost HorizontalAlignment=""Left"" VerticalAlignment=""Top"" Margin=""" + ctl.Location.X + "," + ctl.Location.Y + @",0,0"" Width=""" + ctl.Width + @""" Height=""" + ctl.Height + @""">");
string[] names = ctl.GetType().FullName.Split(new char[] { '.' });
string name = names[names.Length - 2] + ":" + names[names.Length - 1];
st.WriteLine(@"<" + name + @" HorizontalAlignment=""Left"" VerticalAlignment=""Top"" Margin=""" +
ctl.Location.X + "," + ctl.Location.Y + @",0,0"" Width=""" + ctl.Width +
@""" Height=""" + ctl.Height + @"""></" + name + ">");
//st.WriteLine(@"</WindowsFormsHost>");
}
else if (ctl is Label || ctl is MyLabel)
{
var label = String.Format(
"<{0} Name=\"{1}\" HorizontalAlignment=\"Left\" VerticalAlignment=\"Top\" " +
"FontFamily=\"Microsoft Sans Serif\" FontSize=\"{7}\" Margin=\"{3},{4},0,0\" Width=\"{6}\" Height=\"{5}\">{2}</{0}>",
"TextBlock", ctl.Name, ctl.Text, ctl.Location.X, ctl.Location.Y,
ctl.Size.Height, ctl.Size.Width, ctl.Font.Size);
st.WriteLine(label);
}
else if (ctl is ComboBox)
{
var label = String.Format(
"<{0} Name=\"{1}\" HorizontalAlignment=\"Left\" VerticalAlignment=\"Top\" " +
"FontFamily=\"Microsoft Sans Serif\" FontSize=\"{7}\" Margin=\"{3},{4},0,0\" Width=\"{6}\" Height=\"{5}\"></{0}>",
"ComboBox", ctl.Name, ctl.Text, ctl.Location.X, ctl.Location.Y,
ctl.Size.Height, ctl.Size.Width, ctl.Font.Size);
st.WriteLine(label);
}
else if (ctl is TextBox)
{
var label = String.Format(
"<{0} Name=\"{1}\" HorizontalAlignment=\"Left\" VerticalAlignment=\"Top\" " +
"FontFamily=\"Microsoft Sans Serif\" Text=\"{2}\" FontSize=\"{7}\" Margin=\"{3},{4},0,0\" Width=\"{6}\" Height=\"{5}\"></{0}>",
"TextBox", ctl.Name, ctl.Text, ctl.Location.X, ctl.Location.Y,
ctl.Size.Height, ctl.Size.Width, ctl.Font.Size);
st.WriteLine(label);
}
else if (ctl is NumericUpDown)
{
st.WriteLine(@"<Custom:DecimalUpDown Name=""" + ctl.Name +
@""" HorizontalAlignment=""Left"" VerticalAlignment=""Top"" Margin=""" + ctl.Location.X +
"," + ctl.Location.Y + @",0,0"" Width=""" + ctl.Width + @"""></Custom:DecimalUpDown>");
}
else if (ctl is RichTextBox)
{
st.WriteLine(@"<TextBlock Name=""" + ctl.Name +
@""" HorizontalAlignment=""Left"" VerticalAlignment=""Top"" Margin=""" + ctl.Location.X +
"," + ctl.Location.Y + @",0,0"" Width=""" + ctl.Width + @""" Height=""" + ctl.Height +
@""">" + ctl.Text + "</TextBlock>");
}
else if (ctl is MyButton)
{
var label = String.Format(
"<{0} Name=\"{1}\" HorizontalAlignment=\"Left\" VerticalAlignment=\"Top\" " +
"FontFamily=\"Microsoft Sans Serif\" FontSize=\"{7}\" Margin=\"{3},{4},0,0\" Width=\"{6}\" Height=\"{5}\">{2}</{0}>",
"Button", ctl.Name, ctl.Text, ctl.Location.X, ctl.Location.Y,
ctl.Size.Height, ctl.Size.Width, ctl.Font.Size);
st.WriteLine(label);
}
else if (ctl is Button)
{
var label = String.Format(
"<{0} Name=\"{1}\" HorizontalAlignment=\"Left\" VerticalAlignment=\"Top\" " +
"FontFamily=\"Microsoft Sans Serif\" FontSize=\"{7}\" Margin=\"{3},{4},0,0\" Width=\"{6}\" Height=\"{5}\">{2}</{0}>",
"Button", ctl.Name, ctl.Text, ctl.Location.X, ctl.Location.Y,
ctl.Size.Height, ctl.Size.Width, ctl.Font.Size);
st.WriteLine(label);
}
else if (ctl is CheckBox)
{
var label = String.Format(
"<{0} Name=\"{1}\" HorizontalAlignment=\"Left\" VerticalAlignment=\"Top\" " +
"FontFamily=\"Microsoft Sans Serif\" FontSize=\"{7}\" Margin=\"{3},{4},0,0\" Width=\"{6}\" Height=\"{5}\">{2}</{0}>",
"CheckBox", ctl.Name, ctl.Text, ctl.Location.X, ctl.Location.Y,
ctl.Size.Height, ctl.Size.Width, ctl.Font.Size);
st.WriteLine(label);
}
else if (ctl is RadioButton)
{
var label = String.Format(
"<{0} Name=\"{1}\" HorizontalAlignment=\"Left\" VerticalAlignment=\"Top\" " +
"FontFamily=\"Microsoft Sans Serif\" FontSize=\"{7}\" Margin=\"{3},{4},0,0\" Width=\"{6}\" Height=\"{5}\">{2}</{0}>",
"RadioButton", ctl.Name, ctl.Text, ctl.Location.X, ctl.Location.Y,
ctl.Size.Height, ctl.Size.Width, ctl.Font.Size);
st.WriteLine(label);
}
else if (ctl is PictureBox)
{
st.WriteLine(@"<Image Name=""" + ctl.Name +
@""" HorizontalAlignment=""Left"" VerticalAlignment=""Top"" Margin=""" + ctl.Location.X +
"," + ctl.Location.Y + @",0,0"" Width=""" + ctl.Width + @""" Height=""" + ctl.Height +
@""">" + ctl.Text + "</Image>");
}
else if (ctl is TrackBar)
{
if (((TrackBar)ctl).Orientation == Orientation.Horizontal)
st.WriteLine(@"<Slider Name=""" + ctl.Name +
@""" HorizontalAlignment=""Left"" VerticalAlignment=""Top"" Margin=""" +
ctl.Location.X + "," + ctl.Location.Y + @",0,0"" Width=""" + ctl.Width +
@""" Height=""" + ctl.Height + @""">" + ctl.Text + "</Slider>");
else
st.WriteLine(@"<Slider Name=""" + ctl.Name +
@""" HorizontalAlignment=""Left"" VerticalAlignment=""Top"" Margin=""" +
ctl.Location.X + "," + ctl.Location.Y + @",0,0"" Width=""" + ctl.Width +
@""" Height=""" + ctl.Height + @""" Orientation=""Vertical"">" + ctl.Text +
"</Slider>");
}
else if (ctl is VerticalProgressBar || ctl is VerticalProgressBar2)
{
st.WriteLine(@"<ProgressBar Name=""" + ctl.Name +
@""" HorizontalAlignment=""Left"" VerticalAlignment=""Top"" Margin=""" +
ctl.Location.X +
"," + ctl.Location.Y + @",0,0"" Width=""" + ctl.Height + @""" Height=""" + ctl.Width +
@""" >" + @" <ProgressBar.RenderTransform>
<CompositeTransform Rotation=""90"" TranslateX=""" + ctl.Width + @"""/>
</ProgressBar.RenderTransform>" + ctl.Text + " </ProgressBar>");
}
else if (ctl is ProgressBar || ctl is HorizontalProgressBar2 || ctl is HorizontalProgressBar)
{
st.WriteLine(@"<ProgressBar Name=""" + ctl.Name +
@""" HorizontalAlignment=""Left"" VerticalAlignment=""Top"" Margin=""" + ctl.Location.X +
"," + ctl.Location.Y + @",0,0"" Width=""" + ctl.Width + @""" Height=""" + ctl.Height +
@""">" + ctl.Text + "</ProgressBar>");
}
else if (ctl is DataGridView)
{
st.WriteLine(@"<controls:DataGrid Name=""" + ctl.Name +
@""" HorizontalAlignment=""Left"" VerticalAlignment=""Top"" Margin=""" + ctl.Location.X +
"," + ctl.Location.Y + @",0,0"" Width=""" + ctl.Width + @""">" + ctl.Text +
"</controls:DataGrid>");
}
else if (ctl is GroupBox)
{
st.WriteLine(@"<Grid Name=""" + ctl.Name +
@""" HorizontalAlignment=""Left"" VerticalAlignment=""Top"" Margin=""" + ctl.Location.X +
"," + ctl.Location.Y + @",0,0"" Width=""" + ctl.Width + @""" Height=""" + ctl.Height +
@""">");
if (ctl.Controls.Count > 0)
doxamlctls(ctl, st);
st.WriteLine(@"</Grid>");
}
else if (ctl is TabControl)
{/*
st.WriteLine(@"<TabView Name=""" + ctl.Name +
@""" HorizontalAlignment=""Left"" VerticalAlignment=""Top"" Margin=""" + ctl.Location.X +
"," + ctl.Location.Y + @",0,0"" Width=""" + ctl.Width + @""" Height=""" + ctl.Height +
@""">");
if (ctl.Controls.Count > 0)
doxamlctls(ctl, st);
st.WriteLine(@"</TabView>");*/
}
else if (ctl is TabPage)
{
/*
st.WriteLine(@"<TabViewItem Name=""" + ctl.Name + @""" Header=""" + ctl.Text +
@""" HorizontalAlignment=""Left"" VerticalAlignment=""Top"" ><Grid Width=""" +
ctl.Width + @""" Height=""" + ctl.Height + @""">");
if (ctl.Controls.Count > 0)
doxamlctls(ctl, st);
st.WriteLine(@"</Grid></TabViewItem>");
*/
}
else if (ctl is SplitContainer)
{
st.WriteLine(@"<Grid Name=""" + ctl.Name +
@""" HorizontalAlignment=""Left"" VerticalAlignment=""Top"" Margin=""" + ctl.Location.X +
"," + ctl.Location.Y + @",0,0"" Width=""" + ctl.Width + @""" Height=""" + ctl.Height +
@""">");
if (ctl.Controls.Count > 0)
doxamlctls(ctl, st);
st.WriteLine(@"</Grid>");
}
else if (ctl is SplitterPanel)
{
st.WriteLine(@"<Grid HorizontalAlignment=""Left"" VerticalAlignment=""Top"" Margin=""" +
ctl.Location.X + "," + ctl.Location.Y + @",0,0"" Width=""" + ctl.Width +
@""" Height=""" + ctl.Height + @""">");
if (ctl.Controls.Count > 0)
doxamlctls(ctl, st);
st.WriteLine(@"</Grid>");
}
else if (ctl is Panel || ctl is BSE.Windows.Forms.Panel)
{
st.WriteLine(@"<Grid Name=""" + ctl.Name +
@""" HorizontalAlignment=""Left"" VerticalAlignment=""Top"" Margin=""" + ctl.Location.X +
"," + ctl.Location.Y + @",0,0"" Width=""" + ctl.Width + @""" Height=""" + ctl.Height +
@""">");
if (ctl.Controls.Count > 0)
doxamlctls(ctl, st);
st.WriteLine(@"</Grid>");
}
else
{
//<WindowsFormsHost HorizontalAlignment="Left" Height="185.075" Margin="35.821,477.612,0,0" VerticalAlignment="Top" Width="608.179"/>
Console.WriteLine("XAML fail " + ctl.GetType().FullName);
if (ctl.Controls.Count > 0)
{
doxamlctls(ctl, st);
}
}
}
}
private static void ApplyCustomTheme(Control temp, int level)
{
if (level == 0)
{
temp.BackColor = BGColor;
temp.ForeColor = TextColor;
}
foreach (Control ctl in temp.Controls)
{
if (ctl.GetType() == typeof(Panel))
{
ctl.BackColor = BGColor;
ctl.ForeColor = TextColor;
}
else if (ctl.GetType() == typeof(GroupBox))
{
ctl.BackColor = BGColor;
ctl.ForeColor = TextColor;
}
else if (ctl.GetType() == typeof(TreeView))
{
ctl.BackColor = BGColor;
ctl.ForeColor = TextColor;
TreeView txtr = (TreeView)ctl;
txtr.LineColor = TextColor;
}
else if (ctl.GetType() == typeof(ListView))
{
ctl.BackColor = BGColor;
ctl.ForeColor = TextColor;
}
else if (ctl.GetType() == typeof(SplitContainer))
{
ctl.BackColor = BGColor;
ctl.ForeColor = TextColor;
SplitContainer txtr = (SplitContainer)ctl;
ApplyCustomTheme(txtr.Panel1, level);
ApplyCustomTheme(txtr.Panel2, level);
}
else if (ctl.GetType() == typeof(MyLabel))
{
ctl.BackColor = BGColor;
ctl.ForeColor = TextColor;
}
else if (ctl.GetType() == typeof(Button))
{
ctl.ForeColor = TextColor;
ctl.BackColor = ButBG;
}
else if (ctl.GetType() == typeof(MyButton))
{
Controls.MyButton but = (MyButton)ctl;
but.BGGradTop = ButBG;
try
{
but.BGGradBot = Color.FromArgb(ButBG.ToArgb() - 0x333333);
}
catch
{
}
but.TextColor = TextColor;
but.Outline = ButBorder;
}
else if (ctl.GetType() == typeof(TextBox))
{
ctl.BackColor = ControlBGColor;
ctl.ForeColor = TextColor;
TextBox txt = (TextBox)ctl;
txt.BorderStyle = BorderStyle.None;
}
else if (ctl.GetType() == typeof(DomainUpDown))
{
ctl.BackColor = ControlBGColor;
ctl.ForeColor = TextColor;
DomainUpDown txt = (DomainUpDown)ctl;
txt.BorderStyle = BorderStyle.None;
}
else if (ctl.GetType() == typeof(GroupBox) || ctl.GetType() == typeof(UserControl))
{
ctl.BackColor = BGColor;
ctl.ForeColor = TextColor;
}
else if (ctl.GetType() == typeof(ZedGraph.ZedGraphControl))
{
var zg1 = (ZedGraph.ZedGraphControl)ctl;
zg1.GraphPane.Chart.Fill = new ZedGraph.Fill(ControlBGColor);
zg1.GraphPane.Fill = new ZedGraph.Fill(BGColor);
foreach (ZedGraph.LineItem li in zg1.GraphPane.CurveList)
li.Line.Width = 2;
zg1.GraphPane.Title.FontSpec.FontColor = TextColor;
zg1.GraphPane.XAxis.MajorTic.Color = TextColor;
zg1.GraphPane.XAxis.MinorTic.Color = TextColor;
zg1.GraphPane.YAxis.MajorTic.Color = TextColor;
zg1.GraphPane.YAxis.MinorTic.Color = TextColor;
zg1.GraphPane.Y2Axis.MajorTic.Color = TextColor;
zg1.GraphPane.Y2Axis.MinorTic.Color = TextColor;
zg1.GraphPane.XAxis.MajorGrid.Color = TextColor;
zg1.GraphPane.YAxis.MajorGrid.Color = TextColor;
zg1.GraphPane.Y2Axis.MajorGrid.Color = TextColor;
zg1.GraphPane.YAxis.Scale.FontSpec.FontColor = TextColor;
zg1.GraphPane.YAxis.Title.FontSpec.FontColor = TextColor;
zg1.GraphPane.Y2Axis.Title.FontSpec.FontColor = TextColor;
zg1.GraphPane.Y2Axis.Scale.FontSpec.FontColor = TextColor;
zg1.GraphPane.XAxis.Scale.FontSpec.FontColor = TextColor;
zg1.GraphPane.XAxis.Title.FontSpec.FontColor = TextColor;
zg1.GraphPane.Legend.Fill = new ZedGraph.Fill(ControlBGColor);
zg1.GraphPane.Legend.FontSpec.FontColor = TextColor;
}
else if (ctl.GetType() == typeof(BSE.Windows.Forms.Panel) || ctl.GetType() == typeof(SplitterPanel))
{
ctl.BackColor = BGColor;
ctl.ForeColor = TextColor; // Color.FromArgb(0xe6, 0xe8, 0xea);
}
else if (ctl.GetType() == typeof(RadialGradientBG))
{
var rbg = ctl as RadialGradientBG;
rbg.CenterColor = ControlBGColor;
rbg.OutsideColor = ButBG;
}
else if (ctl.GetType() == typeof(GradientBG))
{
var rbg = ctl as GradientBG;
rbg.CenterColor = ControlBGColor;
rbg.OutsideColor = ButBG;
}
else if (ctl.GetType() == typeof(Form))
{
ctl.BackColor = BGColor;
ctl.ForeColor = TextColor;
if (Program.IconFile != null)
((Form)ctl).Icon = Icon.FromHandle(((Bitmap)Program.IconFile).GetHicon());
}
else if (ctl.GetType() == typeof(RichTextBox))
{
if ((ctl.Name == "TXT_terminal") && !MainV2.TerminalTheming)
{
RichTextBox txtr = (RichTextBox)ctl;
txtr.BorderStyle = BorderStyle.None;
txtr.ForeColor = Color.White;
txtr.BackColor = Color.Black;
}
else
{
ctl.BackColor = ControlBGColor;
ctl.ForeColor = TextColor;
RichTextBox txtr = (RichTextBox)ctl;
txtr.BorderStyle = BorderStyle.None;
}
}
else if (ctl.GetType() == typeof(CheckedListBox))
{
ctl.BackColor = ControlBGColor;
ctl.ForeColor = TextColor;
CheckedListBox txtr = (CheckedListBox)ctl;
txtr.BorderStyle = BorderStyle.None;
}
else if (ctl.GetType() == typeof(TabPage))
{
ctl.BackColor = BGColor; //ControlBGColor
ctl.ForeColor = TextColor;
TabPage txtr = (TabPage)ctl;
txtr.BorderStyle = BorderStyle.None;
}
else if (ctl.GetType() == typeof(TabControl))
{
ctl.BackColor = BGColor; //ControlBGColor
ctl.ForeColor = TextColor;
TabControl txtr = (TabControl)ctl;
}
else if (ctl.GetType() == typeof(DataGridView) || ctl.GetType() == typeof(MyDataGridView))
{
ctl.ForeColor = TextColor;
DataGridView dgv = (DataGridView)ctl;
dgv.EnableHeadersVisualStyles = false;
dgv.BorderStyle = BorderStyle.None;
dgv.BackgroundColor = BGColor;
DataGridViewCellStyle rs = new DataGridViewCellStyle();
rs.BackColor = ControlBGColor;
rs.ForeColor = TextColor;
dgv.RowsDefaultCellStyle = rs;
DataGridViewCellStyle hs = new DataGridViewCellStyle(dgv.ColumnHeadersDefaultCellStyle);
hs.BackColor = BGColor;
hs.ForeColor = TextColor;
dgv.ColumnHeadersDefaultCellStyle = hs;
dgv.RowHeadersDefaultCellStyle = hs;
dgv.AlternatingRowsDefaultCellStyle.BackColor = BGColor;
}
else if (ctl.GetType() == typeof(CheckBox) || ctl.GetType() == typeof(MavlinkCheckBox))
{
ctl.BackColor = BGColor;