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,138 +10,137 @@ using System.Windows.Interop;
using System.Windows.Media;
using System.Windows.Threading;
namespace DesktopMagic
namespace DesktopMagic;
public partial class CpuUsageWindow : Window
{
public partial class CpuUsageWindow : Window
private readonly RegistryKey key;
private readonly PerformanceCounter cpuCounter = new PerformanceCounter();
public CpuUsageWindow()
{
private readonly RegistryKey key;
private readonly PerformanceCounter cpuCounter = new PerformanceCounter();
InitializeComponent();
public CpuUsageWindow()
Window w = new()
{
InitializeComponent();
Top = -100,
Left = -100,
Width = 0,
Height = 0,
Window w = new()
{
Top = -100,
Left = -100,
Width = 0,
Height = 0,
WindowStyle = WindowStyle.ToolWindow,
ShowInTaskbar = false
};
w.Show();
Owner = w;
w.Hide();
WindowStyle = WindowStyle.ToolWindow,
ShowInTaskbar = false
};
w.Show();
Owner = w;
w.Hide();
cpuCounter.CategoryName = "Processor";
cpuCounter.CounterName = "% Processor Time";
cpuCounter.InstanceName = "_Total";
cpuCounter.CategoryName = "Processor";
cpuCounter.CounterName = "% Processor Time";
cpuCounter.InstanceName = "_Total";
Timer t = new Timer
{
Interval = 100
};
t.Elapsed += UpdateTimer_Elapsed;
t.Start();
Timer valueTimer = new Timer
{
Interval = 1000
};
valueTimer.Elapsed += ValueTimer_Elapsed;
valueTimer.Start();
key = Registry.CurrentUser.CreateSubKey(@"Software\" + App.AppName);
Top = double.Parse(key.GetValue("CpuUsageWindowTop", 100).ToString());
Left = double.Parse(key.GetValue("CpuUsageWindowLeft", 100).ToString());
Height = double.Parse(key.GetValue("CpuUsageWindowHeight", 200).ToString());
Width = double.Parse(key.GetValue("CpuUsageWindowWidth", 500).ToString());
IsEnabled = false;
}
protected override void OnSourceInitialized(EventArgs e)
Timer t = new Timer
{
base.OnSourceInitialized(e);
Interval = 100
};
t.Elapsed += UpdateTimer_Elapsed;
t.Start();
//Set the window style to noactivate.
WindowInteropHelper helper = new WindowInteropHelper(this);
WindowPos.SetWindowLong(helper.Handle, WindowPos.GWL_EXSTYLE,
WindowPos.GetWindowLong(helper.Handle, WindowPos.GWL_EXSTYLE) | WindowPos.WS_EX_NOACTIVATE);
}
private void UpdateTimer_Elapsed(object sender, ElapsedEventArgs e)
Timer valueTimer = new Timer
{
Dispatcher.Invoke(() =>
{
if (MainWindow.EditMode)
{
panel.Visibility = Visibility.Visible;
tileBar.CaptionHeight = tileBar.CaptionHeight = ActualHeight - 10 < 0 ? 0 : ActualHeight - 10;
WindowPos.SetIsLocked(this, false);
ResizeMode = ResizeMode.CanResize;
}
else
{
panel.Visibility = Visibility.Collapsed;
tileBar.CaptionHeight = 0;
WindowPos.SetIsLocked(this, true);
ResizeMode = ResizeMode.NoResize;
}
Interval = 1000
};
valueTimer.Elapsed += ValueTimer_Elapsed;
rectangleGeometry.Rect = new Rect(0, 0, border.ActualWidth, border.ActualHeight);
border.Background = MainWindow.Theme.BackgroundBrush;
border.CornerRadius = new CornerRadius(MainWindow.Theme.CornerRadius);
viewBox.Margin = new Thickness(MainWindow.Theme.Margin);
border.Width = viewBox.ActualWidth + MainWindow.Theme.Margin * 2;
border.Height = viewBox.ActualHeight + MainWindow.Theme.Margin * 2;
textBlock.FontFamily = new FontFamily(MainWindow.Theme.Font);
textBlock.Foreground = MainWindow.Theme.PrimaryBrush;
valueTextBlock.FontFamily = new FontFamily(MainWindow.Theme.Font);
valueTextBlock.Foreground = MainWindow.Theme.PrimaryBrush;
valueTimer.Start();
ClculateWidth();
});
}
key = Registry.CurrentUser.CreateSubKey(@"Software\" + App.AppName);
Top = double.Parse(key.GetValue("CpuUsageWindowTop", 100).ToString());
Left = double.Parse(key.GetValue("CpuUsageWindowLeft", 100).ToString());
Height = double.Parse(key.GetValue("CpuUsageWindowHeight", 200).ToString());
Width = double.Parse(key.GetValue("CpuUsageWindowWidth", 500).ToString());
IsEnabled = false;
}
private void ValueTimer_Elapsed(object sender, ElapsedEventArgs e)
protected override void OnSourceInitialized(EventArgs e)
{
base.OnSourceInitialized(e);
//Set the window style to noactivate.
WindowInteropHelper helper = new WindowInteropHelper(this);
_ = WindowPos.SetWindowLong(helper.Handle, WindowPos.GWL_EXSTYLE,
WindowPos.GetWindowLong(helper.Handle, WindowPos.GWL_EXSTYLE) | WindowPos.WS_EX_NOACTIVATE);
}
private void UpdateTimer_Elapsed(object sender, ElapsedEventArgs e)
{
Dispatcher.Invoke(() =>
{
string cpuUsage = GetCpuUsage();
Dispatcher.Invoke(() =>
if (MainWindow.EditMode)
{
valueTextBlock.Text = cpuUsage;
});
}
private void ClculateWidth()
{
string template = "CPU: ###%";
double lenght = 0;
for (int i = 0; i < 9; i++)
panel.Visibility = Visibility.Visible;
tileBar.CaptionHeight = tileBar.CaptionHeight = ActualHeight - 10 < 0 ? 0 : ActualHeight - 10;
WindowPos.SetIsLocked(this, false);
ResizeMode = ResizeMode.CanResize;
}
else
{
lenght = Math.Max(StringUtilities.MeasureString(template.Replace('#', i.ToString()[0]), textBlock).Width, lenght);
panel.Visibility = Visibility.Collapsed;
tileBar.CaptionHeight = 0;
WindowPos.SetIsLocked(this, true);
ResizeMode = ResizeMode.NoResize;
}
dockPanel.Width = lenght;
}
private string GetCpuUsage()
{
return $"{(int)cpuCounter.NextValue()}%";
}
rectangleGeometry.Rect = new Rect(0, 0, border.ActualWidth, border.ActualHeight);
border.Background = MainWindow.Theme.BackgroundBrush;
border.CornerRadius = new CornerRadius(MainWindow.Theme.CornerRadius);
viewBox.Margin = new Thickness(MainWindow.Theme.Margin);
border.Width = viewBox.ActualWidth + (MainWindow.Theme.Margin * 2);
border.Height = viewBox.ActualHeight + (MainWindow.Theme.Margin * 2);
textBlock.FontFamily = new FontFamily(MainWindow.Theme.Font);
textBlock.Foreground = MainWindow.Theme.PrimaryBrush;
valueTextBlock.FontFamily = new FontFamily(MainWindow.Theme.Font);
valueTextBlock.Foreground = MainWindow.Theme.PrimaryBrush;
private void Window_LocationChanged(object sender, EventArgs e)
{
key.SetValue("CpuUsageWindowTop", Top);
key.SetValue("CpuUsageWindowLeft", Left);
}
ClculateWidth();
});
}
private void Window_SizeChanged(object sender, SizeChangedEventArgs e)
private void ValueTimer_Elapsed(object sender, ElapsedEventArgs e)
{
string cpuUsage = GetCpuUsage();
Dispatcher.Invoke(() =>
{
key.SetValue("CpuUsageWindowHeight", Height);
key.SetValue("CpuUsageWindowWidth", Width);
tileBar.CaptionHeight = ActualHeight - 10;
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 $"{(int)cpuCounter.NextValue()}%";
}
private void Window_LocationChanged(object sender, EventArgs e)
{
key.SetValue("CpuUsageWindowTop", Top);
key.SetValue("CpuUsageWindowLeft", Left);
}
private void Window_SizeChanged(object sender, SizeChangedEventArgs e)
{
key.SetValue("CpuUsageWindowHeight", Height);
key.SetValue("CpuUsageWindowWidth", Width);
tileBar.CaptionHeight = ActualHeight - 10;
}
}
@@ -9,7 +9,7 @@ namespace DesktopMagic.BuiltInWindowElements;
internal class DatePlugin : Plugin
{
[Element("Short date:")]
[Element("Short date")]
private readonly CheckBox shortDatecheckBox = new CheckBox(true);
private DateTime oldDateTime = DateTime.MinValue;
@@ -1,6 +1,7 @@
using DesktopMagic.Helpers;
using DesktopMagicPluginAPI;
using DesktopMagicPluginAPI.Inputs;
using NAudio.Wave;
@@ -19,6 +20,22 @@ internal class MusicVisualizerPlugin : Plugin
private readonly SampleAggregator sampleAggregator = new SampleAggregator(fftLength);
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 volatile bool calculate = true;
private List<double> lastFft = [];
@@ -78,7 +95,7 @@ internal class MusicVisualizerPlugin : Plugin
v = 20;
}
int multiplier = 100 - (MainWindow.AmplifierLevel * 2);
int multiplier = 100 - (amplifierLevel.Value * 2);
multiplier = multiplier == 0 ? 1 : multiplier;
fft.Add(Math.Abs(e.Result[i].Y * v / multiplier));
}
@@ -165,12 +182,12 @@ internal class MusicVisualizerPlugin : Plugin
{
int offset = 0;
if (!MainWindow.MirrorMode && MainWindow.SpectrumMode != 1)
if (!mirrorMode.Value && spectrumMode.Value != "Middle")
{
scaledFft.Insert(0, 0);
}
if (!MainWindow.LineMode)
if (!lineMode.Value)
{
offset = 1;
}
@@ -183,17 +200,18 @@ internal class MusicVisualizerPlugin : Plugin
int fftIndex = 0;
bool fftIndexReverse = false;
if (MainWindow.MirrorMode || MainWindow.SpectrumMode == 1)
if (mirrorMode.Value || spectrumMode.Value == "Middle")
{
fftIndex = scaledFft.Count - 1;
}
for (int pointIndex = 0; pointIndex < scaledFft.Count; pointIndex += 1)
{
int value = (int)Math.Max(scaledFft[fftIndex] * 50000, 0);
switch (MainWindow.SpectrumMode)
switch (spectrumMode.Value)
{
case 1:
case "Middle":
if (!fftIndexReverse)
{
@@ -202,7 +220,7 @@ internal class MusicVisualizerPlugin : Plugin
}
break;
case 2:
case "Top":
points[pointIndex + 1] = new PointF(2 * pointIndex, value);
break;
@@ -211,7 +229,7 @@ internal class MusicVisualizerPlugin : Plugin
break;
}
if (MainWindow.MirrorMode || MainWindow.SpectrumMode == 1)
if (mirrorMode.Value || spectrumMode.Value == "Middle")
{
if (!fftIndexReverse)
{
@@ -231,20 +249,18 @@ internal class MusicVisualizerPlugin : Plugin
SetPoints(points, output.Width, output.Height, offset);
Brush brush = MainWindow.MusicVisualzerColor.HasValue
? new SolidBrush(MainWindow.MusicVisualzerColor.Value)
: new SolidBrush(MainWindow.Theme.PrimaryColor);
Brush brush = new SolidBrush(Application.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), points.Skip(points.Length / 2).ToArray());
gr.DrawLines(new Pen(brush, lineThickness.Value), points.Take(points.Length / 2).ToArray());
gr.DrawLines(new Pen(brush, lineThickness.Value), points.Skip(points.Length / 2).ToArray());
}
else
{
gr.DrawLines(new Pen(brush), points);
gr.DrawLines(new Pen(brush, lineThickness.Value), points);
}
}
else
@@ -263,9 +279,9 @@ internal class MusicVisualizerPlugin : Plugin
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[^1] = new PointF(0, height / 2);
@@ -273,7 +289,7 @@ internal class MusicVisualizerPlugin : Plugin
points[(points.Length / 2) - 1] = new PointF(0, height / 2);
break;
case 2:
case "Top":
points[0] = new PointF(0, 0 - offset);
points[^1] = new PointF(points[^2].X, 0 - offset);
break;
@@ -9,7 +9,7 @@ namespace DesktopMagic.BuiltInWindowElements;
internal class TimePlugin : Plugin
{
[Element("Display Seconds:")]
[Element("Display Seconds")]
private readonly CheckBox displaySecondscheckBox = new CheckBox(true);
public override int UpdateInterval => 1000;
+13
View File
@@ -19,12 +19,25 @@
<DefineConstants>DEBUG;TRACE</DefineConstants>
</PropertyGroup>
<ItemGroup>
<Compile Remove="BuiltInWindowElements\CpuUsageWindow.xaml.cs" />
</ItemGroup>
<ItemGroup>
<None Remove="icon.ico" />
<None Remove="icons8_volunteering_26_85L_icon.ico" />
<None Remove="icon_Dark.ico" />
</ItemGroup>
<ItemGroup>
<Page Remove="BuiltInWindowElements\CpuUsageWindow.xaml" />
</ItemGroup>
<ItemGroup>
<None Include="BuiltInWindowElements\CpuUsageWindow.xaml" />
<None Include="BuiltInWindowElements\CpuUsageWindow.xaml.cs" />
</ItemGroup>
<ItemGroup>
<PackageReference Include="AlwaysUpToDate" Version="1.0.0.4" />
<PackageReference Include="Extended.Wpf.Toolkit" Version="4.5.1" />
+13 -27
View File
@@ -31,14 +31,14 @@
<DockPanel Margin="0,0,2.5,0">
<Grid DockPanel.Dock="Top">
<Rectangle Grid.Row="1" Fill="#FFECECEC" Height="24" />
<CheckBox x:Name="EditCheckBox" VerticalAlignment="Center" Grid.Row="1" Content="{DynamicResource edit}" Click="EditCheckBox_Click" Foreground="Black" BorderBrush="#FF323232" Style="{StaticResource MaterialDesignDarkCheckBox}" IsChecked="True"/>
<CheckBox x:Name="EditCheckBox" VerticalAlignment="Center" Grid.Row="1" Content="{DynamicResource edit}" Click="EditCheckBox_Click" Foreground="Black" BorderBrush="#FF323232" Style="{StaticResource MaterialDesignDarkCheckBox}" IsChecked="True" />
</Grid>
<ScrollViewer Background="#FFBBBBBB" PreviewMouseWheel="ScrollViewer_PreviewMouseWheel">
<StackPanel x:Name="stackPanel">
<CheckBox x:Name="TimeCb" Content="{DynamicResource time}" Click="CheckBox_Click" Style="{StaticResource MaterialDesignDarkCheckBox}" />
<CheckBox x:Name="DateCb" Content="{DynamicResource date}" Click="CheckBox_Click" Style="{StaticResource MaterialDesignDarkCheckBox}" />
<CheckBox x:Name="CpuUsageCb" Content="{DynamicResource cpuUsage}" Click="CheckBox_Click" Style="{StaticResource MaterialDesignDarkCheckBox}" />
<CheckBox x:Name="CalendarCb" Content="{DynamicResource googleCalendar}" Click="CheckBox_Click" Style="{StaticResource MaterialDesignDarkCheckBox}" Visibility="Collapsed"/>
<CheckBox x:Name="CalendarCb" Content="{DynamicResource googleCalendar}" Click="CheckBox_Click" Style="{StaticResource MaterialDesignDarkCheckBox}" Visibility="Collapsed" />
<!--Currently disabled because it's not working-->
<CheckBox x:Name="MusicVisualizerCb" Content="{DynamicResource musicVisualizer}" HorizontalAlignment="Left" VerticalAlignment="Top" Click="CheckBox_Click" Style="{StaticResource MaterialDesignDarkCheckBox}" />
</StackPanel>
@@ -46,24 +46,10 @@
</DockPanel>
<DockPanel Grid.Column="1" Margin="2.5,0,0,0">
<ComboBox x:Name="optionsComboBox" DockPanel.Dock="Top" Height="24" SelectedIndex="0" SelectionChanged="OptionsComboBox_SelectionChanged" Background="#FFECECEC" Padding="4" VerticalAlignment="Center"/>
<ComboBox x:Name="optionsComboBox" DockPanel.Dock="Top" Height="24" SelectedIndex="0" SelectionChanged="OptionsComboBox_SelectionChanged" Background="#FFECECEC" Padding="4" VerticalAlignment="Center" />
<ScrollViewer Background="#FFBBBBBB">
<Grid>
<StackPanel x:Name="optionsPanel" Margin="3,3,3,0" HorizontalAlignment="Stretch" Visibility="Collapsed" >
</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 x:Name="optionsPanel" Margin="3,3,3,0" HorizontalAlignment="Stretch" Visibility="Collapsed">
</StackPanel>
</Grid>
</ScrollViewer>
@@ -75,20 +61,20 @@
<RowDefinition Height="110" />
</Grid.RowDefinitions>
<Grid.ColumnDefinitions>
<ColumnDefinition/>
<ColumnDefinition/>
<ColumnDefinition />
<ColumnDefinition />
</Grid.ColumnDefinitions>
<Grid Grid.Column="0" Margin="{StaticResource DefaultMargin}" HorizontalAlignment="Stretch">
<Grid.ColumnDefinitions>
<ColumnDefinition Width="Auto"/>
<ColumnDefinition Width="*"/>
<ColumnDefinition Width="Auto" />
<ColumnDefinition Width="*" />
</Grid.ColumnDefinitions>
<Grid.RowDefinitions>
<RowDefinition Height="Auto"/>
<RowDefinition Height="Auto"/>
<RowDefinition Height="Auto"/>
<RowDefinition Height="Auto" />
<RowDefinition Height="Auto" />
<RowDefinition Height="Auto" />
</Grid.RowDefinitions>
<TextBlock Text="Display Font: " Grid.Column="0" Grid.Row="0" VerticalAlignment="Center"></TextBlock>
<ComboBox x:Name="fontComboBox" Grid.Column="1" Grid.Row="0" HorizontalAlignment="Stretch" VerticalAlignment="Top" SelectionChanged="FontComboBox_SelectionChanged" Margin="0,0,0,5" />
@@ -111,7 +97,7 @@
<Border CornerRadius="1" BorderThickness="1.5" BorderBrush="Gray" Height="23" Width="23" Margin="0,0,5,0">
<Rectangle x:Name="primaryColorRechtangle" Fill="White" />
</Border>
<Button Content="Change Primary Color" Height="23" FontSize="12" FontWeight="Regular" Click="ChangePrimaryColorButton_Click"/>
<Button Content="Change Primary Color" Height="23" FontSize="12" FontWeight="Regular" Click="ChangePrimaryColorButton_Click" />
</DockPanel>
<DockPanel Margin="0,0,0,5">
<Border CornerRadius="1" BorderThickness="1.5" BorderBrush="Gray" Height="23" Width="23" Margin="0,0,5,0">
+29 -139
View File
@@ -25,21 +25,11 @@ namespace DesktopMagic
{
#region Global settings
public static bool EditMode { get; private set; } = false;
internal static Theme Theme { get; } = new Theme();
internal static bool EditMode { get; private set; } = false;
#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
internal static Dictionary<string, List<SettingElement>> PluginsSettings { get; } = [];
@@ -336,80 +326,6 @@ namespace DesktopMagic
#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)
{
Theme.Font = fontComboBox.SelectedValue.ToString().Replace("System.Windows.Controls.ComboBoxItem: ", "");
@@ -417,60 +333,44 @@ namespace DesktopMagic
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)
{
if (optionsComboBox.SelectedIndex < 1)
optionsPanel.Visibility = Visibility.Visible;
optionsPanel.Children.Clear();
optionsPanel.UpdateLayout();
if (optionsComboBox.SelectedItem is null)
{
if (musicVisualizerOptionsPanel != null)
{
musicVisualizerOptionsPanel.Visibility = Visibility.Visible;
optionsPanel.Visibility = Visibility.Collapsed;
}
return;
}
else
bool success = PluginsSettings.TryGetValue(optionsComboBox.SelectedItem.ToString(), out List<SettingElement> settingElements);
if (!success || settingElements is null || settingElements.Count == 0)
{
musicVisualizerOptionsPanel.Visibility = Visibility.Collapsed;
optionsPanel.Visibility = Visibility.Visible;
optionsPanel.Children.Clear();
optionsPanel.UpdateLayout();
_ = optionsPanel.Children.Add(new TextBlock() { Text = (string)FindResource("noOptions") });
return;
}
bool success = PluginsSettings.TryGetValue(optionsComboBox.SelectedItem.ToString(), out List<SettingElement> settingElements);
if (!success || settingElements is null || settingElements.Count == 0)
SettingElementGenerator settingElementGenerator = new SettingElementGenerator(optionsComboBox);
foreach (SettingElement settingElement in settingElements)
{
DockPanel dockPanel = new()
{
_ = optionsPanel.Children.Add(new TextBlock() { Text = (string)FindResource("noOptions") });
return;
}
LastChildFill = true,
HorizontalAlignment = HorizontalAlignment.Stretch
};
_ = optionsPanel.Children.Add(dockPanel);
SettingElementGenerator settingElementGenerator = new SettingElementGenerator(optionsComboBox);
foreach (SettingElement settingElement in settingElements)
TextBlock textBlock = new()
{
DockPanel dockPanel = new()
{
LastChildFill = true,
HorizontalAlignment = HorizontalAlignment.Stretch
};
_ = optionsPanel.Children.Add(dockPanel);
Text = $"{settingElement.Name}:",
Padding = new Thickness(0, 0, 3, 0),
VerticalAlignment = VerticalAlignment.Center
};
TextBlock textBlock = new()
{
Text = settingElement.Name,
Padding = new Thickness(0, 0, 3, 0),
VerticalAlignment = VerticalAlignment.Center
};
_ = dockPanel.Children.Add(textBlock);
settingElementGenerator.Generate(settingElement, dockPanel, textBlock);
}
_ = dockPanel.Children.Add(textBlock);
settingElementGenerator.Generate(settingElement, dockPanel, textBlock);
}
}
@@ -689,11 +589,6 @@ namespace DesktopMagic
private void LoadLayout(bool minimize = true)
{
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();
marginTextBox.Text = key.GetValue("Margin", "0").ToString();
blockWindowsClosing = false;
@@ -722,11 +617,6 @@ namespace DesktopMagic
secondaryColorRechtangle.Fill = Theme.SecondaryBrush;
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);
MarginTextBox_TextChanged(null, null);
@@ -44,14 +44,6 @@ public class IntegerUpDown : Element
/// <exception cref="ArgumentException"></exception>
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)
{
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>
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)
{
throw new ArgumentException($"{nameof(min)} is greater than or equal to {nameof(max)}!");