From 9dd40c7ae8b901159e7ee28092fc58557a5c7c1a Mon Sep 17 00:00:00 2001
From: Stone-Red-Code <56473591+Stone-Red-Code@users.noreply.github.com>
Date: Mon, 25 Oct 2021 22:38:45 +0200
Subject: [PATCH] - Better theming system - More code structure inmrovements
---
.../BuiltInWindowElements/CpuUsageWindow.xaml | 5 +-
.../CpuUsageWindow.xaml.cs | 27 ++-
.../BuiltInWindowElements/DateWindow.xaml.cs | 3 +-
.../MusicVisualizerWindow.xaml | 4 +-
.../MusicVisualizerWindow.xaml.cs | 3 +-
.../BuiltInWindowElements/TimeWindow.xaml.cs | 20 ++-
src/DesktopMagic/DesktopMagic.csproj | 6 +-
src/DesktopMagic/Dialogs/ColorDialog.xaml | 49 ++++++
src/DesktopMagic/Dialogs/ColorDialog.xaml.cs | 130 +++++++++++++++
.../{ => Dialogs}/InputDialog.xaml | 13 +-
.../{ => Dialogs}/InputDialog.xaml.cs | 2 +-
src/DesktopMagic/Helpers/ColorConverter.cs | 76 +++++++++
src/DesktopMagic/Helpers/StringUtilities.cs | 25 +++
src/DesktopMagic/MainWindow.xaml | 35 ++--
src/DesktopMagic/MainWindow.xaml.cs | 154 ++++++++++--------
src/DesktopMagic/Plugins/PluginWindow.xaml | 4 +-
src/DesktopMagic/Plugins/PluginWindow.xaml.cs | 4 +
src/DesktopMagic/Plugins/Theme.cs | 7 +-
.../DesktopMagicPluginAPI.csproj | 6 +-
.../DesktopMagicPluginAPI.md | 8 +
.../DesktopMagicPluginAPI.xml | 5 +
src/DesktopMagicPluginAPI/ITheme.cs | 5 +
22 files changed, 481 insertions(+), 110 deletions(-)
create mode 100644 src/DesktopMagic/Dialogs/ColorDialog.xaml
create mode 100644 src/DesktopMagic/Dialogs/ColorDialog.xaml.cs
rename src/DesktopMagic/{ => Dialogs}/InputDialog.xaml (80%)
rename src/DesktopMagic/{ => Dialogs}/InputDialog.xaml.cs (97%)
create mode 100644 src/DesktopMagic/Helpers/ColorConverter.cs
create mode 100644 src/DesktopMagic/Helpers/StringUtilities.cs
diff --git a/src/DesktopMagic/BuiltInWindowElements/CpuUsageWindow.xaml b/src/DesktopMagic/BuiltInWindowElements/CpuUsageWindow.xaml
index d326c01..6a5cc4a 100644
--- a/src/DesktopMagic/BuiltInWindowElements/CpuUsageWindow.xaml
+++ b/src/DesktopMagic/BuiltInWindowElements/CpuUsageWindow.xaml
@@ -15,7 +15,10 @@
-
+
+
+
+
diff --git a/src/DesktopMagic/BuiltInWindowElements/CpuUsageWindow.xaml.cs b/src/DesktopMagic/BuiltInWindowElements/CpuUsageWindow.xaml.cs
index aafc13b..7416764 100644
--- a/src/DesktopMagic/BuiltInWindowElements/CpuUsageWindow.xaml.cs
+++ b/src/DesktopMagic/BuiltInWindowElements/CpuUsageWindow.xaml.cs
@@ -1,4 +1,6 @@
-using Microsoft.Win32;
+using DesktopMagic.Helpers;
+
+using Microsoft.Win32;
using System;
using System.Diagnostics;
@@ -38,7 +40,7 @@ namespace DesktopMagic
cpuCounter.InstanceName = "_Total";
Timer t = new Timer();
- t.Interval = 100;
+ t.Interval = 500;
t.Elapsed += UpdateTimer_Elapsed;
t.Start();
@@ -81,8 +83,14 @@ namespace DesktopMagic
WindowPos.SetIsLocked(this, true);
}
+ textBlock.Background = MainWindow.Theme.BackgroundBrush;
textBlock.FontFamily = new FontFamily(MainWindow.Theme.Font);
textBlock.Foreground = MainWindow.Theme.PrimaryBrush;
+ valuetextBlock.Background = MainWindow.Theme.BackgroundBrush;
+ valuetextBlock.FontFamily = new FontFamily(MainWindow.Theme.Font);
+ valuetextBlock.Foreground = MainWindow.Theme.PrimaryBrush;
+
+ ClculateWidth();
});
}
@@ -91,13 +99,24 @@ namespace DesktopMagic
string cpuUsage = GetCpuUsage();
Dispatcher.Invoke(() =>
{
- textBlock.Text = cpuUsage;
+ valuetextBlock.Text = cpuUsage;
});
}
+ private void ClculateWidth()
+ {
+ string template = "CPU: ###%";
+ double lenght = 0;
+ for (int i = 0; i < 9; i++)
+ {
+ lenght = Math.Max(StringUtilities.MeasureString(template.Replace('#', i.ToString()[0]), textBlock).Width, lenght);
+ }
+ dockPanel.Width = lenght;
+ }
+
private string GetCpuUsage()
{
- return "CPU: " + ((int)cpuCounter.NextValue()).ToString().PadLeft(3, '0') + "%";
+ return $"{(int)cpuCounter.NextValue()}%";
}
private void Window_LocationChanged(object sender, EventArgs e)
diff --git a/src/DesktopMagic/BuiltInWindowElements/DateWindow.xaml.cs b/src/DesktopMagic/BuiltInWindowElements/DateWindow.xaml.cs
index c60264e..917d850 100644
--- a/src/DesktopMagic/BuiltInWindowElements/DateWindow.xaml.cs
+++ b/src/DesktopMagic/BuiltInWindowElements/DateWindow.xaml.cs
@@ -67,7 +67,8 @@ namespace DesktopMagic
}
textBlock.FontFamily = new FontFamily(MainWindow.Theme.Font);
textBlock.Foreground = MainWindow.Theme.PrimaryBrush;
- textBlock.Text = DateTime.Now.ToString("D");
+ textBlock.Text = DateTime.Now.ToLongDateString();
+ textBlock.Background = MainWindow.Theme.BackgroundBrush;
});
}
diff --git a/src/DesktopMagic/BuiltInWindowElements/MusicVisualizerWindow.xaml b/src/DesktopMagic/BuiltInWindowElements/MusicVisualizerWindow.xaml
index fd7b6b5..99b632e 100644
--- a/src/DesktopMagic/BuiltInWindowElements/MusicVisualizerWindow.xaml
+++ b/src/DesktopMagic/BuiltInWindowElements/MusicVisualizerWindow.xaml
@@ -18,7 +18,9 @@
-
+
+
+
\ No newline at end of file
diff --git a/src/DesktopMagic/BuiltInWindowElements/MusicVisualizerWindow.xaml.cs b/src/DesktopMagic/BuiltInWindowElements/MusicVisualizerWindow.xaml.cs
index b7e7cfb..38a735b 100644
--- a/src/DesktopMagic/BuiltInWindowElements/MusicVisualizerWindow.xaml.cs
+++ b/src/DesktopMagic/BuiltInWindowElements/MusicVisualizerWindow.xaml.cs
@@ -6,7 +6,6 @@ using System;
using System.Collections.Generic;
using System.Diagnostics;
using System.Drawing;
-using System.Drawing.Drawing2D;
using System.Drawing.Imaging;
using System.Linq;
using System.Runtime.InteropServices;
@@ -105,6 +104,7 @@ namespace DesktopMagic
{
calculate = true;
}
+ backgroundGrid.Background = MainWindow.Theme.BackgroundBrush;
});
}
@@ -244,7 +244,6 @@ namespace DesktopMagic
using (Graphics gr = Graphics.FromImage(bm))
{
- gr.SmoothingMode = SmoothingMode.None;
PointF[] points = new PointF[scaledFft.Count + 2];
int fftIndex = 0;
diff --git a/src/DesktopMagic/BuiltInWindowElements/TimeWindow.xaml.cs b/src/DesktopMagic/BuiltInWindowElements/TimeWindow.xaml.cs
index 2558e10..07063c4 100644
--- a/src/DesktopMagic/BuiltInWindowElements/TimeWindow.xaml.cs
+++ b/src/DesktopMagic/BuiltInWindowElements/TimeWindow.xaml.cs
@@ -1,4 +1,6 @@
-using Microsoft.Win32;
+using DesktopMagic.Helpers;
+
+using Microsoft.Win32;
using System;
using System.Timers;
@@ -29,7 +31,7 @@ namespace DesktopMagic
w.Hide();
Timer t = new Timer();
- t.Interval = 100;
+ t.Interval = 500;
t.Elapsed += UpdateTimer_Elapsed;
t.Start();
@@ -66,13 +68,27 @@ namespace DesktopMagic
WindowPos.SetIsLocked(this, true);
}
+ textBlock.Background = MainWindow.Theme.BackgroundBrush;
textBlock.FontFamily = new FontFamily(MainWindow.Theme.Font);
textBlock.Foreground = MainWindow.Theme.PrimaryBrush;
//textBlock.Text = DateTime.Now.ToString("hh:mm:ss tt");
textBlock.Text = DateTime.Now.ToString("HH:mm:ss");
+
+ ClculateWidth();
});
}
+ private void ClculateWidth()
+ {
+ string template = "##:##:##";
+ double lenght = 0;
+ for (int i = 0; i < 9; i++)
+ {
+ lenght = Math.Max(StringUtilities.MeasureString(template.Replace('#', i.ToString()[0]), textBlock).Width, lenght);
+ }
+ textBlock.Width = lenght;
+ }
+
private void Window_LocationChanged(object sender, EventArgs e)
{
key.SetValue("TimeWindowTop", Top);
diff --git a/src/DesktopMagic/DesktopMagic.csproj b/src/DesktopMagic/DesktopMagic.csproj
index 2e01db7..8f180ab 100644
--- a/src/DesktopMagic/DesktopMagic.csproj
+++ b/src/DesktopMagic/DesktopMagic.csproj
@@ -8,11 +8,11 @@
icon.ico
OnBuildSuccess
Stone_Red
- 0.0.3.0
+ 0.0.3.1
https://github.com/Stone-Red-Code/DesktopMagic
https://github.com/Stone-Red-Code/DesktopMagic
- 0.0.3.0
- 0.0.3.0
+ 0.0.3.1
+ 0.0.3.1
diff --git a/src/DesktopMagic/Dialogs/ColorDialog.xaml b/src/DesktopMagic/Dialogs/ColorDialog.xaml
new file mode 100644
index 0000000..abd2ee2
--- /dev/null
+++ b/src/DesktopMagic/Dialogs/ColorDialog.xaml
@@ -0,0 +1,49 @@
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
diff --git a/src/DesktopMagic/Dialogs/ColorDialog.xaml.cs b/src/DesktopMagic/Dialogs/ColorDialog.xaml.cs
new file mode 100644
index 0000000..1f6f896
--- /dev/null
+++ b/src/DesktopMagic/Dialogs/ColorDialog.xaml.cs
@@ -0,0 +1,130 @@
+using DesktopMagic.Helpers;
+
+using System;
+using System.Threading;
+using System.Windows;
+using System.Windows.Controls;
+using System.Windows.Media;
+
+namespace DesktopMagic.Dialogs
+{
+ ///
+ /// Interaction logic for ColorDialog.xaml
+ ///
+ public partial class ColorDialog : Window
+ {
+ public ColorDialog(string content, System.Drawing.Color defaultColor, string title = "ColorDialog")
+ {
+ InitializeComponent();
+ label.Content = content;
+ Title = title;
+ SetLanguageDictionary();
+
+ alphaSlider.Value = defaultColor.A;
+ redSlider.Value = defaultColor.R;
+ greenSlider.Value = defaultColor.G;
+ blueSlider.Value = defaultColor.B;
+ }
+
+ public System.Drawing.Color ResultColor { get; private set; }
+
+ public Brush ResultBrush { get; private set; }
+
+ private void OkButton_Click(object sender, RoutedEventArgs e)
+ {
+ DialogResult = true;
+ }
+
+ private void CancelButton_Click(object sender, RoutedEventArgs e)
+ {
+ DialogResult = false;
+ }
+
+ private void ColorSliders_ValueChanged(object sender, RoutedPropertyChangedEventArgs e)
+ {
+ colorHexTextBox.Select(colorHexTextBox.Text.Length, 0);
+ SetColorText();
+ }
+
+ private void ColorHexTextBox_TextChanged(object sender, TextChangedEventArgs e)
+ {
+ if (colorHexTextBox.Text.Length > 0)
+ {
+ if (colorHexTextBox.Text.ToCharArray()[0] != '#')
+ {
+ colorHexTextBox.Text = "#" + colorHexTextBox.Text.Replace("#", "");
+ }
+ }
+ else
+ {
+ colorHexTextBox.Text = "#";
+ colorHexTextBox.Select(colorHexTextBox.Text.Length, 0);
+ }
+
+ if (colorHexTextBox.SelectionStart == 0)
+ {
+ if (colorHexTextBox.Text.Length <= 2)
+ {
+ colorHexTextBox.Select(colorHexTextBox.Text.Length, 0);
+ }
+ else
+ {
+ colorHexTextBox.Select(1, 0);
+ }
+ }
+
+ string hex = colorHexTextBox.Text;
+
+ if (MultiColorConverter.TryConvertToMediaColor(hex, out Color color) && MultiColorConverter.TryConvertToSystemColor(hex, out System.Drawing.Color systemColor))
+ {
+ alphaSlider.Value = color.A;
+ redSlider.Value = color.R;
+ greenSlider.Value = color.G;
+ blueSlider.Value = color.B;
+
+ Brush brush = new SolidColorBrush(color);
+
+ ResultBrush = brush;
+ ResultColor = systemColor;
+ colorRechtangle.Fill = brush;
+ colorHexTextBox.Foreground = Brushes.Black;
+
+ return;
+ }
+ else
+ {
+ colorHexTextBox.Foreground = Brushes.Red;
+ }
+ }
+
+ private void SetColorText()
+ {
+ if (alphaSlider.Value == 255)
+ {
+ colorHexTextBox.Text = "#";
+ }
+ else
+ {
+ colorHexTextBox.Text = "#" + ((int)alphaSlider.Value).ToString("X2");
+ }
+
+ colorHexTextBox.Text += ((int)redSlider.Value).ToString("X2") + ((int)greenSlider.Value).ToString("X2") + ((int)blueSlider.Value).ToString("X2");
+ }
+
+ private void SetLanguageDictionary()
+ {
+ ResourceDictionary dict = new ResourceDictionary();
+ string currentCulture = Thread.CurrentThread.CurrentCulture.ToString();
+
+ if (currentCulture.Contains("de"))
+ {
+ dict.Source = new Uri("..\\Resources\\StringResources.de.xaml", UriKind.Relative);
+ }
+ else
+ {
+ dict.Source = new Uri("..\\Resources\\StringResources.en.xaml", UriKind.Relative);
+ }
+ Resources.MergedDictionaries.Add(dict);
+ }
+ }
+}
\ No newline at end of file
diff --git a/src/DesktopMagic/InputDialog.xaml b/src/DesktopMagic/Dialogs/InputDialog.xaml
similarity index 80%
rename from src/DesktopMagic/InputDialog.xaml
rename to src/DesktopMagic/Dialogs/InputDialog.xaml
index 790377a..f42c6f7 100644
--- a/src/DesktopMagic/InputDialog.xaml
+++ b/src/DesktopMagic/Dialogs/InputDialog.xaml
@@ -1,16 +1,17 @@
-
+ Title="InputDialog"
+ ResizeMode="NoResize"
+ SizeToContent="WidthAndHeight">
-
+
-
+
diff --git a/src/DesktopMagic/InputDialog.xaml.cs b/src/DesktopMagic/Dialogs/InputDialog.xaml.cs
similarity index 97%
rename from src/DesktopMagic/InputDialog.xaml.cs
rename to src/DesktopMagic/Dialogs/InputDialog.xaml.cs
index 812dc57..9d559f2 100644
--- a/src/DesktopMagic/InputDialog.xaml.cs
+++ b/src/DesktopMagic/Dialogs/InputDialog.xaml.cs
@@ -2,7 +2,7 @@
using System.Threading;
using System.Windows;
-namespace DesktopMagic
+namespace DesktopMagic.Dialogs
{
public partial class InputDialog : Window
{
diff --git a/src/DesktopMagic/Helpers/ColorConverter.cs b/src/DesktopMagic/Helpers/ColorConverter.cs
new file mode 100644
index 0000000..efdd6fc
--- /dev/null
+++ b/src/DesktopMagic/Helpers/ColorConverter.cs
@@ -0,0 +1,76 @@
+using System.Globalization;
+using System.Text.RegularExpressions;
+
+namespace DesktopMagic.Helpers
+{
+ internal static class MultiColorConverter
+ {
+ public static string ConvertToHex(System.Drawing.Color color)
+ {
+ return $"#{color.A:X2}{color.R:X2}{color.G:X2}{color.B:X2}";
+ }
+
+ public static string ConvertToHex(System.Windows.Media.Color color)
+ {
+ return $"#{color.A:X2}{color.R:X2}{color.G:X2}{color.B:X2}";
+ }
+
+ public static bool TryConvertToSystemColor(string hex, out System.Drawing.Color color)
+ {
+ hex = hex.Replace("#", "");
+
+ if (hex.Length == 8 && Regex.IsMatch(hex, "(?:[0-9a-fA-F]{8})"))
+ {
+ int a = int.Parse(hex.Substring(0, 2), NumberStyles.HexNumber, CultureInfo.InvariantCulture);
+ int r = int.Parse(hex.Substring(2, 2), NumberStyles.HexNumber, CultureInfo.InvariantCulture);
+ int g = int.Parse(hex.Substring(4, 2), NumberStyles.HexNumber, CultureInfo.InvariantCulture);
+ int b = int.Parse(hex.Substring(6, 2), NumberStyles.HexNumber, CultureInfo.InvariantCulture);
+ color = System.Drawing.Color.FromArgb((byte)a, (byte)r, (byte)g, (byte)b);
+ return true;
+ }
+ else if (hex.Length == 6 && Regex.IsMatch(hex, "(?:[0-9a-fA-F]{6})"))
+ {
+ int a = 255;
+ int r = int.Parse(hex.Substring(0, 2), NumberStyles.HexNumber, CultureInfo.InvariantCulture);
+ int g = int.Parse(hex.Substring(2, 2), NumberStyles.HexNumber, CultureInfo.InvariantCulture);
+ int b = int.Parse(hex.Substring(4, 2), NumberStyles.HexNumber, CultureInfo.InvariantCulture);
+ color = System.Drawing.Color.FromArgb((byte)a, (byte)r, (byte)g, (byte)b);
+ return true;
+ }
+ else
+ {
+ color = System.Drawing.Color.Transparent;
+ return false;
+ }
+ }
+
+ public static bool TryConvertToMediaColor(string hex, out System.Windows.Media.Color color)
+ {
+ hex = hex.Replace("#", "");
+
+ if (hex.Length == 8 && Regex.IsMatch(hex, "(?:[0-9a-fA-F]{8})"))
+ {
+ int a = int.Parse(hex.Substring(0, 2), NumberStyles.HexNumber, CultureInfo.InvariantCulture);
+ int r = int.Parse(hex.Substring(2, 2), NumberStyles.HexNumber, CultureInfo.InvariantCulture);
+ int g = int.Parse(hex.Substring(4, 2), NumberStyles.HexNumber, CultureInfo.InvariantCulture);
+ int b = int.Parse(hex.Substring(6, 2), NumberStyles.HexNumber, CultureInfo.InvariantCulture);
+ color = System.Windows.Media.Color.FromArgb((byte)a, (byte)r, (byte)g, (byte)b);
+ return true;
+ }
+ else if (hex.Length == 6 && Regex.IsMatch(hex, "(?:[0-9a-fA-F]{6})"))
+ {
+ int a = 255;
+ int r = int.Parse(hex.Substring(0, 2), NumberStyles.HexNumber, CultureInfo.InvariantCulture);
+ int g = int.Parse(hex.Substring(2, 2), NumberStyles.HexNumber, CultureInfo.InvariantCulture);
+ int b = int.Parse(hex.Substring(4, 2), NumberStyles.HexNumber, CultureInfo.InvariantCulture);
+ color = System.Windows.Media.Color.FromArgb((byte)a, (byte)r, (byte)g, (byte)b);
+ return true;
+ }
+ else
+ {
+ color = System.Windows.Media.Colors.Transparent;
+ return false;
+ }
+ }
+ }
+}
\ No newline at end of file
diff --git a/src/DesktopMagic/Helpers/StringUtilities.cs b/src/DesktopMagic/Helpers/StringUtilities.cs
new file mode 100644
index 0000000..1fd3eab
--- /dev/null
+++ b/src/DesktopMagic/Helpers/StringUtilities.cs
@@ -0,0 +1,25 @@
+using System.Globalization;
+using System.Windows;
+using System.Windows.Controls;
+using System.Windows.Media;
+
+namespace DesktopMagic.Helpers
+{
+ internal static class StringUtilities
+ {
+ public static Size MeasureString(string input, TextBlock element)
+ {
+ FormattedText formattedText = new FormattedText(
+ input,
+ CultureInfo.CurrentCulture,
+ FlowDirection.LeftToRight,
+ new Typeface(element.FontFamily, element.FontStyle, element.FontWeight, element.FontStretch),
+ element.FontSize,
+ Brushes.Black,
+ new NumberSubstitution(),
+ 1);
+
+ return new Size(formattedText.Width, formattedText.Height);
+ }
+ }
+}
\ No newline at end of file
diff --git a/src/DesktopMagic/MainWindow.xaml b/src/DesktopMagic/MainWindow.xaml
index 7098b94..aa9389e 100644
--- a/src/DesktopMagic/MainWindow.xaml
+++ b/src/DesktopMagic/MainWindow.xaml
@@ -38,7 +38,8 @@
-
+
+
@@ -73,9 +74,9 @@
-
-
-
+
+
+
+
-
+
-
-
-
-
-
-
+
+
+
+
+
+
+
+
+
+
+
+
+
+
diff --git a/src/DesktopMagic/MainWindow.xaml.cs b/src/DesktopMagic/MainWindow.xaml.cs
index af4dcf9..7309f75 100644
--- a/src/DesktopMagic/MainWindow.xaml.cs
+++ b/src/DesktopMagic/MainWindow.xaml.cs
@@ -1,4 +1,6 @@
-using DesktopMagic.Plugins;
+using DesktopMagic.Dialogs;
+using DesktopMagic.Helpers;
+using DesktopMagic.Plugins;
using Microsoft.Win32;
@@ -66,7 +68,12 @@ namespace DesktopMagic
InitializeComponent();
SetLanguageDictionary();
+
+#if DEBUG
+ Title = $"{App.AppName} - Dev {Assembly.GetExecutingAssembly().GetName().Version}";
+#else
Title = $"{App.AppName} - {Assembly.GetExecutingAssembly().GetName().Version}";
+#endif
}
catch (Exception ex)
{
@@ -205,12 +212,6 @@ namespace DesktopMagic
window = new CpuUsageWindow();
break;
- /*
- case "CalendarCb":
- window = new CalendarWindow();
- break;
- */
-
case "MusicVisualizerCb":
window = new MusicVisualizerWindow();
break;
@@ -391,13 +392,20 @@ namespace DesktopMagic
string hex = musicVisualizerColorTextBox.Text;
hex = hex.Replace("#", "");
- System.Drawing.Color systemColor = System.Drawing.Color.FromArgb((byte)int.Parse(hex.Substring(0, 2), System.Globalization.NumberStyles.HexNumber), (byte)int.Parse(hex.Substring(2, 2), System.Globalization.NumberStyles.HexNumber), (byte)int.Parse(hex.Substring(4, 2), System.Globalization.NumberStyles.HexNumber));
+ if (hex.Length == 6)
+ {
+ System.Drawing.Color systemColor = System.Drawing.Color.FromArgb((byte)int.Parse(hex.Substring(0, 2), System.Globalization.NumberStyles.HexNumber), (byte)int.Parse(hex.Substring(2, 2), System.Globalization.NumberStyles.HexNumber), (byte)int.Parse(hex.Substring(4, 2), System.Globalization.NumberStyles.HexNumber));
- MusicVisualzerColor = systemColor;
- musicVisualizerColorTextBox.Foreground = Brushes.Black;
+ MusicVisualzerColor = systemColor;
+ musicVisualizerColorTextBox.Foreground = Brushes.Black;
- key.SetValue("MusicVisualizerColor", musicVisualizerColorTextBox.Text);
- SaveLayout();
+ key.SetValue("MusicVisualizerColor", musicVisualizerColorTextBox.Text);
+ SaveLayout();
+ }
+ else
+ {
+ musicVisualizerColorTextBox.Foreground = Brushes.Red;
+ }
}
catch
{
@@ -445,8 +453,8 @@ namespace DesktopMagic
optionsPanel.Children.Clear();
optionsPanel.UpdateLayout();
- bool succ = PluginsSettings.TryGetValue(((Tuple)optionsComboBox.SelectedItem).Item1.ToString(), out List settingElements);
- if (!succ || settingElements?.Count == 0)
+ bool success = PluginsSettings.TryGetValue(((Tuple)optionsComboBox.SelectedItem).Item1.ToString(), out List settingElements);
+ if (!success || settingElements?.Count == 0)
{
_ = optionsPanel.Children.Add(new TextBlock() { Text = (string)FindResource("noOptions") });
return;
@@ -686,69 +694,52 @@ namespace DesktopMagic
}
}
- #region color
-
- private void ColorSliders_ValueChanged(object sender, RoutedPropertyChangedEventArgs e)
- {
- colorHexTextBox.Text = "#" + ((int)redSlider.Value).ToString("X2") + ((int)greenSlider.Value).ToString("X2") + ((int)blueSlider.Value).ToString("X2");
- colorHexTextBox.Select(colorHexTextBox.Text.Length, 0);
- }
-
private void ColorHexTextBox_TextChanged(object sender, TextChangedEventArgs e)
{
- try
+ }
+
+ private void ChangePrimaryColorButton_Click(object sender, RoutedEventArgs e)
+ {
+ ColorDialog colorDialog = new ColorDialog("Set Primary Color", Theme.PrimaryColor);
+ if (colorDialog.ShowDialog() == true)
{
- if (colorHexTextBox.Text.Length > 0)
- {
- if (colorHexTextBox.Text.ToCharArray()[0] != '#')
- {
- colorHexTextBox.Text = "#" + colorHexTextBox.Text.Replace("#", "");
- }
- }
- else
- {
- colorHexTextBox.Text = "#";
- colorHexTextBox.Select(colorHexTextBox.Text.Length, 0);
- }
+ Theme.PrimaryBrush = colorDialog.ResultBrush;
+ Theme.PrimaryColor = colorDialog.ResultColor;
+ primaryColorRechtangle.Fill = colorDialog.ResultBrush;
- if (colorHexTextBox.SelectionStart == 0)
- {
- if (colorHexTextBox.Text.Length <= 2)
- {
- colorHexTextBox.Select(colorHexTextBox.Text.Length, 0);
- }
- else
- {
- colorHexTextBox.Select(1, 0);
- }
- }
-
- string hex = colorHexTextBox.Text;
- hex = hex.Replace("#", "");
- Color color = Color.FromRgb((byte)int.Parse(hex.Substring(0, 2), System.Globalization.NumberStyles.HexNumber), (byte)int.Parse(hex.Substring(2, 2), System.Globalization.NumberStyles.HexNumber), (byte)int.Parse(hex.Substring(4, 2), System.Globalization.NumberStyles.HexNumber));
- System.Drawing.Color systemColor = System.Drawing.Color.FromArgb((byte)int.Parse(hex.Substring(0, 2), System.Globalization.NumberStyles.HexNumber), (byte)int.Parse(hex.Substring(2, 2), System.Globalization.NumberStyles.HexNumber), (byte)int.Parse(hex.Substring(4, 2), System.Globalization.NumberStyles.HexNumber));
-
- redSlider.Value = color.R;
- greenSlider.Value = color.G;
- blueSlider.Value = color.B;
-
- Brush brush = new SolidColorBrush(color);
-
- Theme.PrimaryBrush = brush;
- Theme.PrimaryColor = systemColor;
- colorRechtangle.Fill = brush;
- colorHexTextBox.Foreground = Brushes.Black;
-
- key.SetValue("Color", colorHexTextBox.Text);
+ key.SetValue("PrimaryColor", MultiColorConverter.ConvertToHex(Theme.PrimaryColor));
SaveLayout();
}
- catch
- {
- colorHexTextBox.Foreground = Brushes.Red;
- }
}
- #endregion color
+ private void ChangeSecondaryColorButton_Click(object sender, RoutedEventArgs e)
+ {
+ ColorDialog colorDialog = new ColorDialog("Set Secondary Color", Theme.SecondaryColor);
+
+ if (colorDialog.ShowDialog() == true)
+ {
+ Theme.SecondaryBrush = colorDialog.ResultBrush;
+ Theme.SecondaryColor = colorDialog.ResultColor;
+ secondaryColorRechtangle.Fill = colorDialog.ResultBrush;
+
+ key.SetValue("SecondaryColor", MultiColorConverter.ConvertToHex(Theme.SecondaryColor));
+ SaveLayout();
+ }
+ }
+
+ private void ChangeBackgroundColorButton_Click(object sender, RoutedEventArgs e)
+ {
+ ColorDialog colorDialog = new ColorDialog("Set Background Color", Theme.BackgroundColor);
+ if (colorDialog.ShowDialog() == true)
+ {
+ Theme.BackgroundBrush = colorDialog.ResultBrush;
+ Theme.BackgroundColor = colorDialog.ResultColor;
+ backgroundColorRechtangle.Fill = colorDialog.ResultBrush;
+
+ key.SetValue("BackgroundColor", MultiColorConverter.ConvertToHex(Theme.BackgroundColor));
+ SaveLayout();
+ }
+ }
#region Layout
@@ -867,9 +858,32 @@ namespace DesktopMagic
mirrorModeCheckBox.IsChecked = bool.Parse(key.GetValue("MirrorMode", "false").ToString());
lineModeCheckBox.IsChecked = bool.Parse(key.GetValue("LineMode", "false").ToString());
musicVisualizerColorTextBox.Text = key.GetValue("MusicVisualizerColor", "").ToString();
- colorHexTextBox.Text = key.GetValue("Color", "#FFFFFF").ToString();
blockWindowsClosing = false;
+ string primaryColorHex = key.GetValue("PrimaryColor", "#FFFFFFFF").ToString();
+ string secondaryColorHex = key.GetValue("SecondaryColor", "#FFFFFFFF").ToString();
+ string backgroundColorHex = key.GetValue("BackgroundColor", "#00FFFFFF").ToString();
+
+ _ = MultiColorConverter.TryConvertToSystemColor(primaryColorHex, out System.Drawing.Color primarySystemColor);
+ _ = MultiColorConverter.TryConvertToMediaColor(primaryColorHex, out Color primaryMediaColor);
+ _ = MultiColorConverter.TryConvertToSystemColor(secondaryColorHex, out System.Drawing.Color secondarySystemColor);
+ _ = MultiColorConverter.TryConvertToMediaColor(secondaryColorHex, out Color secondaryMediaColor);
+ _ = MultiColorConverter.TryConvertToSystemColor(backgroundColorHex, out System.Drawing.Color backgroundSystemColor);
+ _ = MultiColorConverter.TryConvertToMediaColor(backgroundColorHex, out Color backgroundMediaColor);
+
+ Theme.PrimaryColor = primarySystemColor;
+ Theme.PrimaryBrush = new SolidColorBrush(primaryMediaColor);
+
+ Theme.SecondaryColor = secondarySystemColor;
+ Theme.SecondaryBrush = new SolidColorBrush(secondaryMediaColor);
+
+ Theme.BackgroundColor = backgroundSystemColor;
+ Theme.BackgroundBrush = new SolidColorBrush(backgroundMediaColor);
+
+ primaryColorRechtangle.Fill = Theme.PrimaryBrush;
+ secondaryColorRechtangle.Fill = Theme.SecondaryBrush;
+ backgroundColorRechtangle.Fill = Theme.BackgroundBrush;
+
MusicVisualizerColorTextBox_TextChanged(null, null);
MirrorModeCheckBox_Click(null, null);
LineModeCheckBox_Click(null, null);
diff --git a/src/DesktopMagic/Plugins/PluginWindow.xaml b/src/DesktopMagic/Plugins/PluginWindow.xaml
index 2b39491..76db4fc 100644
--- a/src/DesktopMagic/Plugins/PluginWindow.xaml
+++ b/src/DesktopMagic/Plugins/PluginWindow.xaml
@@ -17,7 +17,9 @@
-
+
+
+
diff --git a/src/DesktopMagic/Plugins/PluginWindow.xaml.cs b/src/DesktopMagic/Plugins/PluginWindow.xaml.cs
index c89b745..1908158 100644
--- a/src/DesktopMagic/Plugins/PluginWindow.xaml.cs
+++ b/src/DesktopMagic/Plugins/PluginWindow.xaml.cs
@@ -115,6 +115,10 @@ namespace DesktopMagic
{
((System.Timers.Timer)sender).Stop();
}
+ else
+ {
+ backgroundGrid.Background = MainWindow.Theme.BackgroundBrush;
+ }
});
}
diff --git a/src/DesktopMagic/Plugins/Theme.cs b/src/DesktopMagic/Plugins/Theme.cs
index 08c60cb..3398839 100644
--- a/src/DesktopMagic/Plugins/Theme.cs
+++ b/src/DesktopMagic/Plugins/Theme.cs
@@ -6,13 +6,16 @@ namespace DesktopMagic.Plugins
{
internal class Theme : ITheme
{
- public Color PrimaryColor { get; internal set; } = Color.White;
+ public Color PrimaryColor { get; set; } = Color.White;
- public Color SecondaryColor { get; internal set; } = Color.White;
+ public Color SecondaryColor { get; set; } = Color.White;
+
+ public Color BackgroundColor { get; set; } = Color.Transparent;
public string Font { get; internal set; } = "Segoe UI";
public System.Windows.Media.Brush PrimaryBrush { get; set; } = System.Windows.Media.Brushes.White;
public System.Windows.Media.Brush SecondaryBrush { get; set; } = System.Windows.Media.Brushes.White;
+ public System.Windows.Media.Brush BackgroundBrush { get; set; } = System.Windows.Media.Brushes.Transparent;
}
}
\ No newline at end of file
diff --git a/src/DesktopMagicPluginAPI/DesktopMagicPluginAPI.csproj b/src/DesktopMagicPluginAPI/DesktopMagicPluginAPI.csproj
index b428bd2..bbf3af1 100644
--- a/src/DesktopMagicPluginAPI/DesktopMagicPluginAPI.csproj
+++ b/src/DesktopMagicPluginAPI/DesktopMagicPluginAPI.csproj
@@ -4,13 +4,13 @@
net5.0
Stone_Red
Stone_Red
- 0.0.0.4
+ 0.0.0.5
https://github.com/Stone-Red-Code/DesktopMagic
LICENSE
true
- 0.0.0.4
+ 0.0.0.5
- 0.0.0.4
+ 0.0.0.5
diff --git a/src/DesktopMagicPluginAPI/DesktopMagicPluginAPI.md b/src/DesktopMagicPluginAPI/DesktopMagicPluginAPI.md
index 83e995d..337e908 100644
--- a/src/DesktopMagicPluginAPI/DesktopMagicPluginAPI.md
+++ b/src/DesktopMagicPluginAPI/DesktopMagicPluginAPI.md
@@ -33,6 +33,7 @@
- [WindowSize](#P-DesktopMagicPluginAPI-IPluginData-WindowSize 'DesktopMagicPluginAPI.IPluginData.WindowSize')
- [UpdateWindow()](#M-DesktopMagicPluginAPI-IPluginData-UpdateWindow 'DesktopMagicPluginAPI.IPluginData.UpdateWindow')
- [ITheme](#T-DesktopMagicPluginAPI-ITheme 'DesktopMagicPluginAPI.ITheme')
+ - [BackgroundColor](#P-DesktopMagicPluginAPI-ITheme-BackgroundColor 'DesktopMagicPluginAPI.ITheme.BackgroundColor')
- [Font](#P-DesktopMagicPluginAPI-ITheme-Font 'DesktopMagicPluginAPI.ITheme.Font')
- [PrimaryColor](#P-DesktopMagicPluginAPI-ITheme-PrimaryColor 'DesktopMagicPluginAPI.ITheme.PrimaryColor')
- [SecondaryColor](#P-DesktopMagicPluginAPI-ITheme-SecondaryColor 'DesktopMagicPluginAPI.ITheme.SecondaryColor')
@@ -394,6 +395,13 @@ DesktopMagicPluginAPI
The theme settings of the main application.
+
+### BackgroundColor `property`
+
+##### Summary
+
+Gets the background color of the main application.
+
### Font `property`
diff --git a/src/DesktopMagicPluginAPI/DesktopMagicPluginAPI.xml b/src/DesktopMagicPluginAPI/DesktopMagicPluginAPI.xml
index a449dab..7b63b4f 100644
--- a/src/DesktopMagicPluginAPI/DesktopMagicPluginAPI.xml
+++ b/src/DesktopMagicPluginAPI/DesktopMagicPluginAPI.xml
@@ -336,6 +336,11 @@
Gets the secondary color of the main application.
+
+
+ Gets the background color of the main application.
+
+
Gets the font of the main application.
diff --git a/src/DesktopMagicPluginAPI/ITheme.cs b/src/DesktopMagicPluginAPI/ITheme.cs
index 007c9ca..43b587c 100644
--- a/src/DesktopMagicPluginAPI/ITheme.cs
+++ b/src/DesktopMagicPluginAPI/ITheme.cs
@@ -17,6 +17,11 @@ namespace DesktopMagicPluginAPI
///
Color SecondaryColor { get; }
+ ///
+ /// Gets the background color of the main application.
+ ///
+ Color BackgroundColor { get; }
+
///
/// Gets the font of the main application.
///