From 74bf7c2fb892351708202d3de6a825576bd2c0b3 Mon Sep 17 00:00:00 2001 From: Stone_Red <56473591+Stone-Red-Code@users.noreply.github.com> Date: Sun, 19 Nov 2023 16:19:07 +0100 Subject: [PATCH] Refactor step 1 --- .../BuiltInWindowElements/DatePlugin.cs | 3 +- .../MusicVisualizerPlugin.cs | 11 +- .../BuiltInWindowElements/TimePlugin.cs | 3 +- src/DesktopMagic/DesktopMagic.csproj | 1 + src/DesktopMagic/GlobalSuppressions.cs | 3 +- src/DesktopMagic/Helpers/ColorConverter.cs | 10 + .../Helpers/SettingElementGenerator.cs | 16 +- src/DesktopMagic/MainWindow.xaml | 27 +- src/DesktopMagic/MainWindow.xaml.cs | 373 ++++++------------ src/DesktopMagic/MainWindowDataContext.cs | 33 ++ src/DesktopMagic/Plugins/InputElement.cs | 10 + src/DesktopMagic/Plugins/PluginData.cs | 12 +- src/DesktopMagic/Plugins/PluginWindow.xaml.cs | 123 +++--- src/DesktopMagic/Plugins/SettingElement.cs | 10 - src/DesktopMagic/Plugins/Theme.cs | 124 +++++- .../Settings/DesktopMagicSettings.cs | 44 +++ src/DesktopMagic/Settings/Layout.cs | 56 +++ src/DesktopMagic/Settings/PluginSettings.cs | 80 ++++ src/DesktopMagicPlugin.Test/PluginScript.cs | 5 +- src/DesktopMagicPluginAPI/IPluginData.cs | 15 +- .../{Inputs => Settings}/Button.cs | 4 +- .../{Inputs => Settings}/CheckBox.cs | 4 +- .../{Inputs => Settings}/ComboBox.cs | 8 +- .../{Inputs => Settings}/IntegerUpDown.cs | 4 +- .../{Inputs => Settings}/Label.cs | 6 +- .../{Inputs => Settings}/MouseButton.cs | 0 .../Element.cs => Settings/Setting.cs} | 4 +- .../SettingAttribute.cs} | 10 +- .../{Inputs => Settings}/Slider.cs | 4 +- .../{Inputs => Settings}/TextBox.cs | 4 +- 30 files changed, 595 insertions(+), 412 deletions(-) create mode 100644 src/DesktopMagic/MainWindowDataContext.cs create mode 100644 src/DesktopMagic/Plugins/InputElement.cs delete mode 100644 src/DesktopMagic/Plugins/SettingElement.cs create mode 100644 src/DesktopMagic/Settings/DesktopMagicSettings.cs create mode 100644 src/DesktopMagic/Settings/Layout.cs create mode 100644 src/DesktopMagic/Settings/PluginSettings.cs rename src/DesktopMagicPluginAPI/{Inputs => Settings}/Button.cs (93%) rename src/DesktopMagicPluginAPI/{Inputs => Settings}/CheckBox.cs (91%) rename src/DesktopMagicPluginAPI/{Inputs => Settings}/ComboBox.cs (87%) rename src/DesktopMagicPluginAPI/{Inputs => Settings}/IntegerUpDown.cs (95%) rename src/DesktopMagicPluginAPI/{Inputs => Settings}/Label.cs (90%) rename src/DesktopMagicPluginAPI/{Inputs => Settings}/MouseButton.cs (100%) rename src/DesktopMagicPluginAPI/{Inputs/Element.cs => Settings/Setting.cs} (84%) rename src/DesktopMagicPluginAPI/{Inputs/ElementAttribute.cs => Settings/SettingAttribute.cs} (81%) rename src/DesktopMagicPluginAPI/{Inputs => Settings}/Slider.cs (95%) rename src/DesktopMagicPluginAPI/{Inputs => Settings}/TextBox.cs (90%) diff --git a/src/DesktopMagic/BuiltInWindowElements/DatePlugin.cs b/src/DesktopMagic/BuiltInWindowElements/DatePlugin.cs index b47681a..b0df29b 100644 --- a/src/DesktopMagic/BuiltInWindowElements/DatePlugin.cs +++ b/src/DesktopMagic/BuiltInWindowElements/DatePlugin.cs @@ -1,5 +1,6 @@ using DesktopMagicPluginAPI; using DesktopMagicPluginAPI.Inputs; +using DesktopMagicPluginAPI.Settings; using System; using System.Drawing; @@ -9,7 +10,7 @@ namespace DesktopMagic.BuiltInWindowElements; internal class DatePlugin : Plugin { - [Element("Short date")] + [Setting("Short date")] private readonly CheckBox shortDatecheckBox = new CheckBox(true); private DateTime oldDateTime = DateTime.MinValue; diff --git a/src/DesktopMagic/BuiltInWindowElements/MusicVisualizerPlugin.cs b/src/DesktopMagic/BuiltInWindowElements/MusicVisualizerPlugin.cs index 68704ad..217f047 100644 --- a/src/DesktopMagic/BuiltInWindowElements/MusicVisualizerPlugin.cs +++ b/src/DesktopMagic/BuiltInWindowElements/MusicVisualizerPlugin.cs @@ -2,6 +2,7 @@ using DesktopMagicPluginAPI; using DesktopMagicPluginAPI.Inputs; +using DesktopMagicPluginAPI.Settings; using NAudio.Wave; @@ -21,19 +22,19 @@ internal class MusicVisualizerPlugin : Plugin private readonly Bitmap output = new Bitmap(880, 300); - [Element("Mirror")] + [Setting("Mirror")] private readonly CheckBox mirrorMode = new CheckBox(false); - [Element("Line")] + [Setting("Line")] private readonly CheckBox lineMode = new CheckBox(false); - [Element("Spectrum Mode")] + [Setting("Spectrum Mode")] private readonly ComboBox spectrumMode = new ComboBox("Bottom", "Middle", "Top"); - [Element("Amplification")] + [Setting("Amplification")] private readonly IntegerUpDown amplifierLevel = new IntegerUpDown(-50, 50, 0); - [Element("Line thickness")] + [Setting("Line thickness")] private readonly IntegerUpDown lineThickness = new IntegerUpDown(1, 10, 1); private WasapiLoopbackCapture waveIn; diff --git a/src/DesktopMagic/BuiltInWindowElements/TimePlugin.cs b/src/DesktopMagic/BuiltInWindowElements/TimePlugin.cs index 06530f9..b9c2df6 100644 --- a/src/DesktopMagic/BuiltInWindowElements/TimePlugin.cs +++ b/src/DesktopMagic/BuiltInWindowElements/TimePlugin.cs @@ -1,5 +1,6 @@ using DesktopMagicPluginAPI; using DesktopMagicPluginAPI.Inputs; +using DesktopMagicPluginAPI.Settings; using System; using System.Drawing; @@ -9,7 +10,7 @@ namespace DesktopMagic.BuiltInWindowElements; internal class TimePlugin : Plugin { - [Element("Display Seconds")] + [Setting("Display Seconds")] private readonly CheckBox displaySecondscheckBox = new CheckBox(true); public override int UpdateInterval => 1000; diff --git a/src/DesktopMagic/DesktopMagic.csproj b/src/DesktopMagic/DesktopMagic.csproj index dd6de0e..b6087ce 100644 --- a/src/DesktopMagic/DesktopMagic.csproj +++ b/src/DesktopMagic/DesktopMagic.csproj @@ -13,6 +13,7 @@ 0.0.3.2 0.0.3.2 net8.0-windows7.0 + enable diff --git a/src/DesktopMagic/GlobalSuppressions.cs b/src/DesktopMagic/GlobalSuppressions.cs index 35e3ca4..2691b65 100644 --- a/src/DesktopMagic/GlobalSuppressions.cs +++ b/src/DesktopMagic/GlobalSuppressions.cs @@ -8,4 +8,5 @@ using System.Diagnostics.CodeAnalysis; [assembly: SuppressMessage("Interoperability", "CA1416:Validate platform compatibility", Justification = "Windows only application")] [assembly: SuppressMessage("Performance", "CA1822:Mark members as static", Justification = "No need to")] [assembly: SuppressMessage("Minor Code Smell", "S1075:URIs should not be hardcoded", Justification = "")] -[assembly: SuppressMessage("Minor Code Smell", "S3604:Member initializer values should not be redundant", Justification = "False postives")] \ No newline at end of file +[assembly: SuppressMessage("Minor Code Smell", "S3604:Member initializer values should not be redundant", Justification = "False postives")] +[assembly: SuppressMessage("Critical Code Smell", "S2696:Instance members should not write to \"static\" fields", Justification = "", Scope = "member", Target = "~P:DesktopMagic.MainWindowDataContext.Settings")] \ No newline at end of file diff --git a/src/DesktopMagic/Helpers/ColorConverter.cs b/src/DesktopMagic/Helpers/ColorConverter.cs index 1504563..e2c337b 100644 --- a/src/DesktopMagic/Helpers/ColorConverter.cs +++ b/src/DesktopMagic/Helpers/ColorConverter.cs @@ -74,6 +74,16 @@ internal static partial class MultiColorConverter } } + public static System.Windows.Media.Color ConvertToMediaColor(System.Drawing.Color color) + { + return System.Windows.Media.Color.FromArgb(color.A, color.R, color.G, color.B); + } + + public static System.Drawing.Color ConvertToSystemColor(System.Windows.Media.Color color) + { + return System.Drawing.Color.FromArgb(color.A, color.R, color.G, color.B); + } + [GeneratedRegex("(?:[0-9a-fA-F]{8})")] private static partial Regex Hex8(); diff --git a/src/DesktopMagic/Helpers/SettingElementGenerator.cs b/src/DesktopMagic/Helpers/SettingElementGenerator.cs index fbdc34a..31591b4 100644 --- a/src/DesktopMagic/Helpers/SettingElementGenerator.cs +++ b/src/DesktopMagic/Helpers/SettingElementGenerator.cs @@ -10,11 +10,11 @@ internal class SettingElementGenerator(ComboBox optionsComboBox) { private readonly ComboBox optionsComboBox = optionsComboBox; - public void Generate(SettingElement settingElement, DockPanel dockPanel, TextBlock textBlock) + public void Generate(InputElement settingElement, DockPanel dockPanel, TextBlock textBlock) { dockPanel.UpdateLayout(); textBlock.UpdateLayout(); - if (settingElement.Element is DesktopMagicPluginAPI.Inputs.Label eLabel) + if (settingElement.Input is DesktopMagicPluginAPI.Inputs.Label eLabel) { textBlock.Text = eLabel.Value; textBlock.Margin = new Thickness(0, 5, 3, 0); @@ -33,7 +33,7 @@ internal class SettingElementGenerator(ComboBox optionsComboBox) }); }; } - else if (settingElement.Element is DesktopMagicPluginAPI.Inputs.Button eButton) + else if (settingElement.Input is DesktopMagicPluginAPI.Settings.Button eButton) { Button button = new() { @@ -66,7 +66,7 @@ internal class SettingElementGenerator(ComboBox optionsComboBox) _ = dockPanel.Children.Add(button); } - else if (settingElement.Element is DesktopMagicPluginAPI.Inputs.CheckBox eCheckBox) + else if (settingElement.Input is DesktopMagicPluginAPI.Settings.CheckBox eCheckBox) { CheckBox checkBox = new() { @@ -96,7 +96,7 @@ internal class SettingElementGenerator(ComboBox optionsComboBox) _ = dockPanel.Children.Add(checkBox); } - else if (settingElement.Element is DesktopMagicPluginAPI.Inputs.TextBox eTextBox) + else if (settingElement.Input is DesktopMagicPluginAPI.Settings.TextBox eTextBox) { TextBox textBox = new() { @@ -125,7 +125,7 @@ internal class SettingElementGenerator(ComboBox optionsComboBox) }; _ = dockPanel.Children.Add(textBox); } - else if (settingElement.Element is DesktopMagicPluginAPI.Inputs.IntegerUpDown eIntegerUpDown) + else if (settingElement.Input is DesktopMagicPluginAPI.Settings.IntegerUpDown eIntegerUpDown) { Xceed.Wpf.Toolkit.IntegerUpDown integerUpDown = new() { @@ -155,7 +155,7 @@ internal class SettingElementGenerator(ComboBox optionsComboBox) }; _ = dockPanel.Children.Add(integerUpDown); } - else if (settingElement.Element is DesktopMagicPluginAPI.Inputs.Slider eSlider) + else if (settingElement.Input is DesktopMagicPluginAPI.Settings.Slider eSlider) { Slider slider = new() { @@ -188,7 +188,7 @@ internal class SettingElementGenerator(ComboBox optionsComboBox) _ = dockPanel.Children.Add(slider); } - else if (settingElement.Element is DesktopMagicPluginAPI.Inputs.ComboBox eComboBox) + else if (settingElement.Input is DesktopMagicPluginAPI.Settings.ComboBox eComboBox) { ComboBox comboBox = new() { diff --git a/src/DesktopMagic/MainWindow.xaml b/src/DesktopMagic/MainWindow.xaml index 9c25e2a..3c532b8 100644 --- a/src/DesktopMagic/MainWindow.xaml +++ b/src/DesktopMagic/MainWindow.xaml @@ -2,6 +2,11 @@ xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation" xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" xmlns:materialDesign="http://materialdesigninxaml.net/winfx/xaml/themes" + xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006" + mc:Ignorable="d" + xmlns:d="http://schemas.microsoft.com/expression/blend/2008" + xmlns:local="clr-namespace:DesktopMagic" + d:DataContext="{d:DesignInstance Type=local:MainWindowDataContext}" Closing="Window_Closing" Closed="Window_Closed" ShowInTaskbar="True" @@ -34,14 +39,18 @@ - - - - - - - - + + + + + + + + + + + + @@ -121,7 +130,7 @@ - +