Fix built in plugins

This commit is contained in:
Stone_Red
2023-11-16 22:34:23 +01:00
parent aca4e84148
commit 336de2ca42
9 changed files with 202 additions and 314 deletions
@@ -10,8 +10,8 @@ using System.Windows.Interop;
using System.Windows.Media; using System.Windows.Media;
using System.Windows.Threading; using System.Windows.Threading;
namespace DesktopMagic namespace DesktopMagic;
{
public partial class CpuUsageWindow : Window public partial class CpuUsageWindow : Window
{ {
private readonly RegistryKey key; private readonly RegistryKey key;
@@ -68,7 +68,7 @@ namespace DesktopMagic
//Set the window style to noactivate. //Set the window style to noactivate.
WindowInteropHelper helper = new WindowInteropHelper(this); WindowInteropHelper helper = new WindowInteropHelper(this);
WindowPos.SetWindowLong(helper.Handle, WindowPos.GWL_EXSTYLE, _ = WindowPos.SetWindowLong(helper.Handle, WindowPos.GWL_EXSTYLE,
WindowPos.GetWindowLong(helper.Handle, WindowPos.GWL_EXSTYLE) | WindowPos.WS_EX_NOACTIVATE); WindowPos.GetWindowLong(helper.Handle, WindowPos.GWL_EXSTYLE) | WindowPos.WS_EX_NOACTIVATE);
} }
@@ -95,8 +95,8 @@ namespace DesktopMagic
border.Background = MainWindow.Theme.BackgroundBrush; border.Background = MainWindow.Theme.BackgroundBrush;
border.CornerRadius = new CornerRadius(MainWindow.Theme.CornerRadius); border.CornerRadius = new CornerRadius(MainWindow.Theme.CornerRadius);
viewBox.Margin = new Thickness(MainWindow.Theme.Margin); viewBox.Margin = new Thickness(MainWindow.Theme.Margin);
border.Width = viewBox.ActualWidth + MainWindow.Theme.Margin * 2; border.Width = viewBox.ActualWidth + (MainWindow.Theme.Margin * 2);
border.Height = viewBox.ActualHeight + MainWindow.Theme.Margin * 2; border.Height = viewBox.ActualHeight + (MainWindow.Theme.Margin * 2);
textBlock.FontFamily = new FontFamily(MainWindow.Theme.Font); textBlock.FontFamily = new FontFamily(MainWindow.Theme.Font);
textBlock.Foreground = MainWindow.Theme.PrimaryBrush; textBlock.Foreground = MainWindow.Theme.PrimaryBrush;
valueTextBlock.FontFamily = new FontFamily(MainWindow.Theme.Font); valueTextBlock.FontFamily = new FontFamily(MainWindow.Theme.Font);
@@ -144,4 +144,3 @@ namespace DesktopMagic
tileBar.CaptionHeight = ActualHeight - 10; tileBar.CaptionHeight = ActualHeight - 10;
} }
} }
}
@@ -9,7 +9,7 @@ namespace DesktopMagic.BuiltInWindowElements;
internal class DatePlugin : Plugin internal class DatePlugin : Plugin
{ {
[Element("Short date:")] [Element("Short date")]
private readonly CheckBox shortDatecheckBox = new CheckBox(true); private readonly CheckBox shortDatecheckBox = new CheckBox(true);
private DateTime oldDateTime = DateTime.MinValue; private DateTime oldDateTime = DateTime.MinValue;
@@ -1,6 +1,7 @@
using DesktopMagic.Helpers; using DesktopMagic.Helpers;
using DesktopMagicPluginAPI; using DesktopMagicPluginAPI;
using DesktopMagicPluginAPI.Inputs;
using NAudio.Wave; using NAudio.Wave;
@@ -19,6 +20,22 @@ internal class MusicVisualizerPlugin : Plugin
private readonly SampleAggregator sampleAggregator = new SampleAggregator(fftLength); private readonly SampleAggregator sampleAggregator = new SampleAggregator(fftLength);
private readonly Bitmap output = new Bitmap(880, 300); private readonly Bitmap output = new Bitmap(880, 300);
[Element("Mirror")]
private readonly CheckBox mirrorMode = new CheckBox(false);
[Element("Line")]
private readonly CheckBox lineMode = new CheckBox(false);
[Element("Spectrum Mode")]
private readonly ComboBox spectrumMode = new ComboBox("Bottom", "Middle", "Top");
[Element("Amplification")]
private readonly IntegerUpDown amplifierLevel = new IntegerUpDown(-50, 50, 0);
[Element("Line thickness")]
private readonly IntegerUpDown lineThickness = new IntegerUpDown(1, 10, 1);
private WasapiLoopbackCapture waveIn; private WasapiLoopbackCapture waveIn;
private volatile bool calculate = true; private volatile bool calculate = true;
private List<double> lastFft = []; private List<double> lastFft = [];
@@ -78,7 +95,7 @@ internal class MusicVisualizerPlugin : Plugin
v = 20; v = 20;
} }
int multiplier = 100 - (MainWindow.AmplifierLevel * 2); int multiplier = 100 - (amplifierLevel.Value * 2);
multiplier = multiplier == 0 ? 1 : multiplier; multiplier = multiplier == 0 ? 1 : multiplier;
fft.Add(Math.Abs(e.Result[i].Y * v / multiplier)); fft.Add(Math.Abs(e.Result[i].Y * v / multiplier));
} }
@@ -165,12 +182,12 @@ internal class MusicVisualizerPlugin : Plugin
{ {
int offset = 0; int offset = 0;
if (!MainWindow.MirrorMode && MainWindow.SpectrumMode != 1) if (!mirrorMode.Value && spectrumMode.Value != "Middle")
{ {
scaledFft.Insert(0, 0); scaledFft.Insert(0, 0);
} }
if (!MainWindow.LineMode) if (!lineMode.Value)
{ {
offset = 1; offset = 1;
} }
@@ -183,17 +200,18 @@ internal class MusicVisualizerPlugin : Plugin
int fftIndex = 0; int fftIndex = 0;
bool fftIndexReverse = false; bool fftIndexReverse = false;
if (MainWindow.MirrorMode || MainWindow.SpectrumMode == 1) if (mirrorMode.Value || spectrumMode.Value == "Middle")
{ {
fftIndex = scaledFft.Count - 1; fftIndex = scaledFft.Count - 1;
} }
for (int pointIndex = 0; pointIndex < scaledFft.Count; pointIndex += 1) for (int pointIndex = 0; pointIndex < scaledFft.Count; pointIndex += 1)
{ {
int value = (int)Math.Max(scaledFft[fftIndex] * 50000, 0); int value = (int)Math.Max(scaledFft[fftIndex] * 50000, 0);
switch (MainWindow.SpectrumMode) switch (spectrumMode.Value)
{ {
case 1: case "Middle":
if (!fftIndexReverse) if (!fftIndexReverse)
{ {
@@ -202,7 +220,7 @@ internal class MusicVisualizerPlugin : Plugin
} }
break; break;
case 2: case "Top":
points[pointIndex + 1] = new PointF(2 * pointIndex, value); points[pointIndex + 1] = new PointF(2 * pointIndex, value);
break; break;
@@ -211,7 +229,7 @@ internal class MusicVisualizerPlugin : Plugin
break; break;
} }
if (MainWindow.MirrorMode || MainWindow.SpectrumMode == 1) if (mirrorMode.Value || spectrumMode.Value == "Middle")
{ {
if (!fftIndexReverse) if (!fftIndexReverse)
{ {
@@ -231,20 +249,18 @@ internal class MusicVisualizerPlugin : Plugin
SetPoints(points, output.Width, output.Height, offset); SetPoints(points, output.Width, output.Height, offset);
Brush brush = MainWindow.MusicVisualzerColor.HasValue Brush brush = new SolidBrush(Application.Theme.PrimaryColor);
? new SolidBrush(MainWindow.MusicVisualzerColor.Value)
: new SolidBrush(MainWindow.Theme.PrimaryColor);
if (MainWindow.LineMode) if (lineMode.Value)
{ {
if (MainWindow.SpectrumMode == 1) if (spectrumMode.Value == "Middle")
{ {
gr.DrawLines(new Pen(brush), points.Take(points.Length / 2).ToArray()); gr.DrawLines(new Pen(brush, lineThickness.Value), points.Take(points.Length / 2).ToArray());
gr.DrawLines(new Pen(brush), points.Skip(points.Length / 2).ToArray()); gr.DrawLines(new Pen(brush, lineThickness.Value), points.Skip(points.Length / 2).ToArray());
} }
else else
{ {
gr.DrawLines(new Pen(brush), points); gr.DrawLines(new Pen(brush, lineThickness.Value), points);
} }
} }
else else
@@ -263,9 +279,9 @@ internal class MusicVisualizerPlugin : Plugin
private void SetPoints(PointF[] points, int width, int height, int offset) private void SetPoints(PointF[] points, int width, int height, int offset)
{ {
switch (MainWindow.SpectrumMode) switch (spectrumMode.Value)
{ {
case 1: case "Middle":
points[0] = new PointF(width, height / 2); points[0] = new PointF(width, height / 2);
points[^1] = new PointF(0, height / 2); points[^1] = new PointF(0, height / 2);
@@ -273,7 +289,7 @@ internal class MusicVisualizerPlugin : Plugin
points[(points.Length / 2) - 1] = new PointF(0, height / 2); points[(points.Length / 2) - 1] = new PointF(0, height / 2);
break; break;
case 2: case "Top":
points[0] = new PointF(0, 0 - offset); points[0] = new PointF(0, 0 - offset);
points[^1] = new PointF(points[^2].X, 0 - offset); points[^1] = new PointF(points[^2].X, 0 - offset);
break; break;
@@ -9,7 +9,7 @@ namespace DesktopMagic.BuiltInWindowElements;
internal class TimePlugin : Plugin internal class TimePlugin : Plugin
{ {
[Element("Display Seconds:")] [Element("Display Seconds")]
private readonly CheckBox displaySecondscheckBox = new CheckBox(true); private readonly CheckBox displaySecondscheckBox = new CheckBox(true);
public override int UpdateInterval => 1000; public override int UpdateInterval => 1000;
+13
View File
@@ -19,12 +19,25 @@
<DefineConstants>DEBUG;TRACE</DefineConstants> <DefineConstants>DEBUG;TRACE</DefineConstants>
</PropertyGroup> </PropertyGroup>
<ItemGroup>
<Compile Remove="BuiltInWindowElements\CpuUsageWindow.xaml.cs" />
</ItemGroup>
<ItemGroup> <ItemGroup>
<None Remove="icon.ico" /> <None Remove="icon.ico" />
<None Remove="icons8_volunteering_26_85L_icon.ico" /> <None Remove="icons8_volunteering_26_85L_icon.ico" />
<None Remove="icon_Dark.ico" /> <None Remove="icon_Dark.ico" />
</ItemGroup> </ItemGroup>
<ItemGroup>
<Page Remove="BuiltInWindowElements\CpuUsageWindow.xaml" />
</ItemGroup>
<ItemGroup>
<None Include="BuiltInWindowElements\CpuUsageWindow.xaml" />
<None Include="BuiltInWindowElements\CpuUsageWindow.xaml.cs" />
</ItemGroup>
<ItemGroup> <ItemGroup>
<PackageReference Include="AlwaysUpToDate" Version="1.0.0.4" /> <PackageReference Include="AlwaysUpToDate" Version="1.0.0.4" />
<PackageReference Include="Extended.Wpf.Toolkit" Version="4.5.1" /> <PackageReference Include="Extended.Wpf.Toolkit" Version="4.5.1" />
-14
View File
@@ -51,20 +51,6 @@
<Grid> <Grid>
<StackPanel x:Name="optionsPanel" Margin="3,3,3,0" HorizontalAlignment="Stretch" Visibility="Collapsed"> <StackPanel x:Name="optionsPanel" Margin="3,3,3,0" HorizontalAlignment="Stretch" Visibility="Collapsed">
</StackPanel> </StackPanel>
<StackPanel x:Name="musicVisualizerOptionsPanel" Margin="3,3,3,0">
<Label Content="{DynamicResource color}" HorizontalAlignment="Left" VerticalAlignment="Top" Padding="0,1" />
<TextBox x:Name="musicVisualizerColorTextBox" Text="" TextChanged="MusicVisualizerColorTextBox_TextChanged" MaxLength="7" CharacterCasing="Upper">
<materialDesign:TextFieldAssist.CharacterCounterStyle>
<Style TargetType="TextBlock" />
</materialDesign:TextFieldAssist.CharacterCounterStyle>
</TextBox>
<ComboBox x:Name="spectrumModeComboBox" ItemsSource="{DynamicResource musicVisualizerOptionsComboboxItems}" HorizontalAlignment="Left" VerticalAlignment="Top" Width="120" SelectionChanged="SpectrumModeComboBox_SelectionChanged" />
<CheckBox x:Name="mirrorModeCheckBox" Content="{DynamicResource mirrorMode}" Click="MirrorModeCheckBox_Click" Style="{StaticResource MaterialDesignDarkCheckBox}" />
<CheckBox x:Name="lineModeCheckBox" Content="{DynamicResource lineMode}" Click="LineModeCheckBox_Click" Style="{StaticResource MaterialDesignDarkCheckBox}" />
<Label Content="{DynamicResource amplifier}" HorizontalAlignment="Left" VerticalAlignment="Top" Padding="0,1" />
<Slider x:Name="amplifierLevelSlider" HorizontalAlignment="Stretch" VerticalAlignment="Top" ValueChanged="AmplifierLevelSlider_ValueChanged" Maximum="50" Minimum="-50" SmallChange="1" LargeChange="5" Foreground="Gray" />
<Label x:Name="amplifierLevelLabel" Content="Label" HorizontalAlignment="Left" VerticalAlignment="Top" Padding="0,1" />
</StackPanel>
</Grid> </Grid>
</ScrollViewer> </ScrollViewer>
</DockPanel> </DockPanel>
+7 -117
View File
@@ -25,21 +25,11 @@ namespace DesktopMagic
{ {
#region Global settings #region Global settings
public static bool EditMode { get; private set; } = false;
internal static Theme Theme { get; } = new Theme(); internal static Theme Theme { get; } = new Theme();
internal static bool EditMode { get; private set; } = false;
#endregion Global settings #endregion Global settings
#region Music Visualizer Settings
public static int SpectrumMode { get; private set; } = 0;
public static int AmplifierLevel { get; private set; } = 0;
public static bool MirrorMode { get; private set; } = false;
public static bool LineMode { get; private set; } = false;
public static System.Drawing.Color? MusicVisualzerColor { get; private set; }
#endregion Music Visualizer Settings
#region Plugins settings #region Plugins settings
internal static Dictionary<string, List<SettingElement>> PluginsSettings { get; } = []; internal static Dictionary<string, List<SettingElement>> PluginsSettings { get; } = [];
@@ -336,80 +326,6 @@ namespace DesktopMagic
#region Options #region Options
private void AmplifierLevelSlider_ValueChanged(object sender, RoutedPropertyChangedEventArgs<double> e)
{
amplifierLevelLabel.Content = (int)amplifierLevelSlider.Value;
AmplifierLevel = (int)amplifierLevelSlider.Value;
key.SetValue("AmplifierLevel", AmplifierLevel);
SaveLayout();
}
private void MirrorModeCheckBox_Click(object sender, RoutedEventArgs e)
{
MirrorMode = (bool)mirrorModeCheckBox.IsChecked;
key.SetValue("MirrorMode", mirrorModeCheckBox.IsChecked.ToString());
SaveLayout();
}
private void LineModeCheckBox_Click(object sender, RoutedEventArgs e)
{
LineMode = (bool)lineModeCheckBox.IsChecked;
key.SetValue("LineMode", lineModeCheckBox.IsChecked.ToString());
SaveLayout();
}
private void MusicVisualizerColorTextBox_TextChanged(object sender, TextChangedEventArgs e)
{
if (!string.IsNullOrWhiteSpace(musicVisualizerColorTextBox.Text) && musicVisualizerColorTextBox.Text != "Default")
{
if (musicVisualizerColorTextBox.Text.Length > 0)
{
if (musicVisualizerColorTextBox.Text[0] != '#')
{
musicVisualizerColorTextBox.Text = "#" + musicVisualizerColorTextBox.Text.Replace("#", "");
}
}
else
{
musicVisualizerColorTextBox.Text = "#";
musicVisualizerColorTextBox.Select(musicVisualizerColorTextBox.Text.Length, 0);
}
if (musicVisualizerColorTextBox.SelectionStart == 0)
{
if (musicVisualizerColorTextBox.Text.Length <= 2)
{
musicVisualizerColorTextBox.Select(musicVisualizerColorTextBox.Text.Length, 0);
}
else
{
musicVisualizerColorTextBox.Select(1, 0);
}
}
string hex = musicVisualizerColorTextBox.Text;
if (MultiColorConverter.TryConvertToSystemColor(hex, out System.Drawing.Color systemColor))
{
MusicVisualzerColor = systemColor;
musicVisualizerColorTextBox.Foreground = Brushes.Black;
key.SetValue("MusicVisualizerColor", musicVisualizerColorTextBox.Text);
SaveLayout();
}
else
{
musicVisualizerColorTextBox.Foreground = Brushes.Red;
}
}
else
{
MusicVisualzerColor = null;
key.SetValue("MusicVisualizerColor", musicVisualizerColorTextBox.Text);
SaveLayout();
}
}
private void FontComboBox_SelectionChanged(object sender, SelectionChangedEventArgs e) private void FontComboBox_SelectionChanged(object sender, SelectionChangedEventArgs e)
{ {
Theme.Font = fontComboBox.SelectedValue.ToString().Replace("System.Windows.Controls.ComboBoxItem: ", ""); Theme.Font = fontComboBox.SelectedValue.ToString().Replace("System.Windows.Controls.ComboBoxItem: ", "");
@@ -417,32 +333,17 @@ namespace DesktopMagic
SaveLayout(); SaveLayout();
} }
private void SpectrumModeComboBox_SelectionChanged(object sender, SelectionChangedEventArgs e)
{
SpectrumMode = spectrumModeComboBox.SelectedIndex;
key.SetValue("SpectrumMode", spectrumModeComboBox.SelectedIndex);
mirrorModeCheckBox.IsEnabled = spectrumModeComboBox.SelectedIndex != 1;
SaveLayout();
}
private void OptionsComboBox_SelectionChanged(object sender, SelectionChangedEventArgs e) private void OptionsComboBox_SelectionChanged(object sender, SelectionChangedEventArgs e)
{ {
if (optionsComboBox.SelectedIndex < 1)
{
if (musicVisualizerOptionsPanel != null)
{
musicVisualizerOptionsPanel.Visibility = Visibility.Visible;
optionsPanel.Visibility = Visibility.Collapsed;
}
}
else
{
musicVisualizerOptionsPanel.Visibility = Visibility.Collapsed;
optionsPanel.Visibility = Visibility.Visible; optionsPanel.Visibility = Visibility.Visible;
optionsPanel.Children.Clear(); optionsPanel.Children.Clear();
optionsPanel.UpdateLayout(); optionsPanel.UpdateLayout();
if (optionsComboBox.SelectedItem is null)
{
return;
}
bool success = PluginsSettings.TryGetValue(optionsComboBox.SelectedItem.ToString(), out List<SettingElement> settingElements); bool success = PluginsSettings.TryGetValue(optionsComboBox.SelectedItem.ToString(), out List<SettingElement> settingElements);
if (!success || settingElements is null || settingElements.Count == 0) if (!success || settingElements is null || settingElements.Count == 0)
{ {
@@ -463,7 +364,7 @@ namespace DesktopMagic
TextBlock textBlock = new() TextBlock textBlock = new()
{ {
Text = settingElement.Name, Text = $"{settingElement.Name}:",
Padding = new Thickness(0, 0, 3, 0), Padding = new Thickness(0, 0, 3, 0),
VerticalAlignment = VerticalAlignment.Center VerticalAlignment = VerticalAlignment.Center
}; };
@@ -472,7 +373,6 @@ namespace DesktopMagic
settingElementGenerator.Generate(settingElement, dockPanel, textBlock); settingElementGenerator.Generate(settingElement, dockPanel, textBlock);
} }
} }
}
#endregion Options #endregion Options
@@ -689,11 +589,6 @@ namespace DesktopMagic
private void LoadLayout(bool minimize = true) private void LoadLayout(bool minimize = true)
{ {
Theme.Font = key.GetValue("Font", "Segoe UI").ToString(); Theme.Font = key.GetValue("Font", "Segoe UI").ToString();
spectrumModeComboBox.SelectedIndex = int.Parse(key.GetValue("SpectrumMode", "0").ToString(), CultureInfo.InvariantCulture);
amplifierLevelSlider.Value = int.Parse(key.GetValue("AmplifierLevel", "0").ToString(), CultureInfo.InvariantCulture);
mirrorModeCheckBox.IsChecked = bool.Parse(key.GetValue("MirrorMode", "false").ToString());
lineModeCheckBox.IsChecked = bool.Parse(key.GetValue("LineMode", "false").ToString());
musicVisualizerColorTextBox.Text = key.GetValue("MusicVisualizerColor", "").ToString();
cornerRadiusTextBox.Text = key.GetValue("CornerRadius", "0").ToString(); cornerRadiusTextBox.Text = key.GetValue("CornerRadius", "0").ToString();
marginTextBox.Text = key.GetValue("Margin", "0").ToString(); marginTextBox.Text = key.GetValue("Margin", "0").ToString();
blockWindowsClosing = false; blockWindowsClosing = false;
@@ -722,11 +617,6 @@ namespace DesktopMagic
secondaryColorRechtangle.Fill = Theme.SecondaryBrush; secondaryColorRechtangle.Fill = Theme.SecondaryBrush;
backgroundColorRechtangle.Fill = Theme.BackgroundBrush; backgroundColorRechtangle.Fill = Theme.BackgroundBrush;
MusicVisualizerColorTextBox_TextChanged(null, null);
MirrorModeCheckBox_Click(null, null);
LineModeCheckBox_Click(null, null);
SpectrumModeComboBox_SelectionChanged(null, null);
AmplifierLevelSlider_ValueChanged(null, null);
CornerRadiusTextBox_TextChanged(null, null); CornerRadiusTextBox_TextChanged(null, null);
MarginTextBox_TextChanged(null, null); MarginTextBox_TextChanged(null, null);
@@ -44,14 +44,6 @@ public class IntegerUpDown : Element
/// <exception cref="ArgumentException"></exception> /// <exception cref="ArgumentException"></exception>
public IntegerUpDown(int min, int max, int value = 0) public IntegerUpDown(int min, int max, int value = 0)
{ {
if (min < 0)
{
throw new ArgumentException("Value can not be negative!", nameof(min));
}
if (max < 0)
{
throw new ArgumentException("Value can not be negative!", nameof(max));
}
if (min > max) if (min > max)
{ {
throw new ArgumentException($"{nameof(min)} is greater than or equal to {nameof(max)}!"); throw new ArgumentException($"{nameof(min)} is greater than or equal to {nameof(max)}!");
@@ -43,14 +43,6 @@ public sealed class Slider : Element
/// <param name="value">The value assigned to the <see cref="Slider"/> element.</param> /// <param name="value">The value assigned to the <see cref="Slider"/> element.</param>
public Slider(double min, double max, double value = 0) public Slider(double min, double max, double value = 0)
{ {
if (min < 0)
{
throw new ArgumentException("Value can not be negative!", nameof(min));
}
if (max < 0)
{
throw new ArgumentException("Value can not be negative!", nameof(max));
}
if (min > max) if (min > max)
{ {
throw new ArgumentException($"{nameof(min)} is greater than or equal to {nameof(max)}!"); throw new ArgumentException($"{nameof(min)} is greater than or equal to {nameof(max)}!");