- Add Corner Radius option

- Improved API documentation
- Fix updater check time
- Fix logging
This commit is contained in:
Stone-Red-Code
2021-10-27 22:01:20 +02:00
parent b69bba68bb
commit 8f650ac35a
20 changed files with 394 additions and 290 deletions
+2 -2
View File
@@ -18,7 +18,7 @@ namespace DesktopMagic
#if DEBUG #if DEBUG
private readonly Updater updater = new Updater(TimeSpan.FromDays(1), "https://raw.githubusercontent.com/Stone-Red-Code/DesktopMagic/develop/update/updateInfo.json"); private readonly Updater updater = new Updater(TimeSpan.FromDays(1), "https://raw.githubusercontent.com/Stone-Red-Code/DesktopMagic/develop/update/updateInfo.json");
#else #else
private readonly Updater updater = new Updater(TimeSpan.FromHours(1), "https://raw.githubusercontent.com/Stone-Red-Code/DesktopMagic/main/update/updateInfo.json"); private readonly Updater updater = new Updater(TimeSpan.FromDays(1), "https://raw.githubusercontent.com/Stone-Red-Code/DesktopMagic/main/update/updateInfo.json");
#endif #endif
public const string AppName = "Desktop Magic"; public const string AppName = "Desktop Magic";
@@ -104,7 +104,7 @@ namespace DesktopMagic
InfoConfig = new OutputConfig() InfoConfig = new OutputConfig()
{ {
Color = ConsoleColor.White, Color = ConsoleColor.White,
LogTarget = LogTarget.Console | LogTarget.File, LogTarget = LogTarget.DebugConsole | LogTarget.File,
FilePath = logFilePath FilePath = logFilePath
}, },
DebugConfig = new OutputConfig() DebugConfig = new OutputConfig()
@@ -14,10 +14,14 @@
x:Name="window"> x:Name="window">
<Grid> <Grid>
<Rectangle x:Name="panel" Fill="#4CBAFFEF" Stroke="White" Margin="0,0,0,0" Visibility="Collapsed" /> <Rectangle x:Name="panel" Fill="#4CBAFFEF" Stroke="White" Margin="0,0,0,0" Visibility="Collapsed" />
<Viewbox StretchDirection="DownOnly" Stretch="Uniform"> <Border x:Name="border" Width="{Binding ElementName=viewBox, Path=ActualWidth}" Height="{Binding ElementName=viewBox, Path=ActualHeight}"/>
<Viewbox x:Name="viewBox" StretchDirection="Both" Stretch="Uniform">
<Viewbox.Clip>
<RectangleGeometry x:Name="rectangleGeometry" RadiusX="{Binding ElementName=border, Path=CornerRadius.TopLeft}" RadiusY="{Binding ElementName=border, Path=CornerRadius.TopLeft}" Rect="{Binding ElementName=border}"/>
</Viewbox.Clip>
<DockPanel x:Name="dockPanel"> <DockPanel x:Name="dockPanel">
<TextBlock x:Name="textBlock" FontSize="999" Foreground="White" Text="CPU: " IsHitTestVisible="False" /> <TextBlock x:Name="textBlock" FontSize="999" Foreground="White" Text="CPU: " IsHitTestVisible="False" />
<TextBlock x:Name="valuetextBlock" FontSize="999" TextAlignment="Right" Foreground="White" Text="000%" IsHitTestVisible="False" /> <TextBlock x:Name="valueTextBlock" FontSize="999" TextAlignment="Right" Foreground="White" Text="000%" IsHitTestVisible="False" />
</DockPanel> </DockPanel>
</Viewbox> </Viewbox>
</Grid> </Grid>
@@ -87,12 +87,13 @@ namespace DesktopMagic
ResizeMode = ResizeMode.NoResize; ResizeMode = ResizeMode.NoResize;
} }
textBlock.Background = MainWindow.Theme.BackgroundBrush; rectangleGeometry.Rect = new Rect(0, 0, border.ActualWidth, border.ActualHeight);
border.Background = MainWindow.Theme.BackgroundBrush;
border.CornerRadius = new CornerRadius(MainWindow.Theme.CornerRadius);
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.Background = MainWindow.Theme.BackgroundBrush; valueTextBlock.FontFamily = new FontFamily(MainWindow.Theme.Font);
valuetextBlock.FontFamily = new FontFamily(MainWindow.Theme.Font); valueTextBlock.Foreground = MainWindow.Theme.PrimaryBrush;
valuetextBlock.Foreground = MainWindow.Theme.PrimaryBrush;
ClculateWidth(); ClculateWidth();
}); });
@@ -103,7 +104,7 @@ namespace DesktopMagic
string cpuUsage = GetCpuUsage(); string cpuUsage = GetCpuUsage();
Dispatcher.Invoke(() => Dispatcher.Invoke(() =>
{ {
valuetextBlock.Text = cpuUsage; valueTextBlock.Text = cpuUsage;
}); });
} }
@@ -13,8 +13,13 @@
x:Name="window"> x:Name="window">
<Grid> <Grid>
<Rectangle x:Name="panel" Fill="#4CBAFFEF" Stroke="White" Margin="0,0,0,0" Visibility="Collapsed" /> <Rectangle x:Name="panel" Fill="#4CBAFFEF" Stroke="White" Margin="0,0,0,0" Visibility="Collapsed" />
<Viewbox StretchDirection="DownOnly" Stretch="Uniform">
<TextBlock x:Name="textBlock" FontSize="999" Foreground="White" Text=" " IsHitTestVisible="False" /> <Border x:Name="border" Width="{Binding ElementName=viewBox, Path=ActualWidth}" Height="{Binding ElementName=viewBox, Path=ActualHeight}"/>
<Viewbox x:Name="viewBox" StretchDirection="Both" Stretch="Uniform">
<Viewbox.Clip>
<RectangleGeometry x:Name="rectangleGeometry" RadiusX="{Binding ElementName=border, Path=CornerRadius.TopLeft}" RadiusY="{Binding ElementName=border, Path=CornerRadius.TopLeft}" Rect="{Binding ElementName=border}"/>
</Viewbox.Clip>
<TextBlock x:Name="textBlock" Foreground="White" Text=" " IsHitTestVisible="False" />
</Viewbox> </Viewbox>
</Grid> </Grid>
<WindowChrome.WindowChrome> <WindowChrome.WindowChrome>
@@ -69,10 +69,13 @@ namespace DesktopMagic
WindowPos.SetIsLocked(this, true); WindowPos.SetIsLocked(this, true);
ResizeMode = ResizeMode.NoResize; ResizeMode = ResizeMode.NoResize;
} }
rectangleGeometry.Rect = new Rect(0, 0, border.ActualWidth, border.ActualHeight);
border.Background = MainWindow.Theme.BackgroundBrush;
border.CornerRadius = new CornerRadius(MainWindow.Theme.CornerRadius);
textBlock.FontFamily = new FontFamily(MainWindow.Theme.Font); textBlock.FontFamily = new FontFamily(MainWindow.Theme.Font);
textBlock.Foreground = MainWindow.Theme.PrimaryBrush; textBlock.Foreground = MainWindow.Theme.PrimaryBrush;
textBlock.Text = DateTime.Now.ToLongDateString(); textBlock.Text = DateTime.Now.ToLongDateString();
textBlock.Background = MainWindow.Theme.BackgroundBrush;
}); });
} }
@@ -17,10 +17,12 @@
</WindowChrome.WindowChrome> </WindowChrome.WindowChrome>
<Grid x:Name="grid"> <Grid x:Name="grid">
<Rectangle x:Name="panel" Fill="#4CBAFFEF" Stroke="White" Margin="0,0,0,0" Visibility="Collapsed" /> <Rectangle x:Name="panel" Fill="#4CBAFFEF" Stroke="White" Margin="0,0,0,0" Visibility="Collapsed" />
<Viewbox StretchDirection="Both" Stretch="Uniform"> <Border x:Name="border" Width="{Binding ElementName=viewBox, Path=ActualWidth}" Height="{Binding ElementName=viewBox, Path=ActualHeight}"/>
<Grid x:Name="backgroundGrid"> <Viewbox x:Name="viewBox" StretchDirection="Both" Stretch="Uniform">
<Image x:Name="image" HorizontalAlignment="Left" Height="759" Margin="0,0,0,0" VerticalAlignment="Top" Width="1747" RenderTransformOrigin="0.5,0.5" Stretch="Fill" /> <Viewbox.Clip>
</Grid> <RectangleGeometry x:Name="rectangleGeometry" RadiusX="{Binding ElementName=border, Path=CornerRadius.TopLeft}" RadiusY="{Binding ElementName=border, Path=CornerRadius.TopLeft}" Rect="{Binding ElementName=border}"/>
</Viewbox.Clip>
<Image x:Name="image" HorizontalAlignment="Left" Margin="0,0,0,0" VerticalAlignment="Top" Stretch="Fill" />
</Viewbox> </Viewbox>
</Grid> </Grid>
</Window> </Window>
@@ -102,7 +102,9 @@ namespace DesktopMagic
ResizeMode = ResizeMode.NoResize; ResizeMode = ResizeMode.NoResize;
} }
calculate = IsLoaded; calculate = IsLoaded;
backgroundGrid.Background = MainWindow.Theme.BackgroundBrush; rectangleGeometry.Rect = new Rect(0, 0, border.ActualWidth, border.ActualHeight);
border.CornerRadius = new CornerRadius(MainWindow.Theme.CornerRadius);
border.Background = MainWindow.Theme.BackgroundBrush;
}); });
} }
@@ -13,7 +13,11 @@
x:Name="window"> x:Name="window">
<Grid> <Grid>
<Rectangle x:Name="panel" Fill="#4CBAFFEF" Stroke="White" Margin="0,0,0,0" Visibility="Collapsed" /> <Rectangle x:Name="panel" Fill="#4CBAFFEF" Stroke="White" Margin="0,0,0,0" Visibility="Collapsed" />
<Viewbox StretchDirection="DownOnly" Stretch="Uniform"> <Border x:Name="border" Width="{Binding ElementName=viewBox, Path=ActualWidth}" Height="{Binding ElementName=viewBox, Path=ActualHeight}"/>
<Viewbox x:Name="viewBox" StretchDirection="Both" Stretch="Uniform">
<Viewbox.Clip>
<RectangleGeometry x:Name="rectangleGeometry" RadiusX="{Binding ElementName=border, Path=CornerRadius.TopLeft}" RadiusY="{Binding ElementName=border, Path=CornerRadius.TopLeft}" Rect="{Binding ElementName=border}"/>
</Viewbox.Clip>
<TextBlock x:Name="textBlock" FontSize="999" Foreground="White" Text=" " IsHitTestVisible="False" /> <TextBlock x:Name="textBlock" FontSize="999" Foreground="White" Text=" " IsHitTestVisible="False" />
</Viewbox> </Viewbox>
</Grid> </Grid>
@@ -72,7 +72,9 @@ namespace DesktopMagic
ResizeMode = ResizeMode.NoResize; ResizeMode = ResizeMode.NoResize;
} }
textBlock.Background = MainWindow.Theme.BackgroundBrush; rectangleGeometry.Rect = new Rect(0, 0, border.ActualWidth, border.ActualHeight);
border.Background = MainWindow.Theme.BackgroundBrush;
border.CornerRadius = new CornerRadius(MainWindow.Theme.CornerRadius);
textBlock.FontFamily = new FontFamily(MainWindow.Theme.Font); textBlock.FontFamily = new FontFamily(MainWindow.Theme.Font);
textBlock.Foreground = MainWindow.Theme.PrimaryBrush; textBlock.Foreground = MainWindow.Theme.PrimaryBrush;
//textBlock.Text = DateTime.Now.ToString("hh:mm:ss tt"); //textBlock.Text = DateTime.Now.ToString("hh:mm:ss tt");
@@ -0,0 +1,208 @@
using DesktopMagic.Plugins;
using System;
using System.Windows;
using System.Windows.Controls;
namespace DesktopMagic.Helpers
{
internal class SettingElementGenerator
{
private readonly ComboBox optionsComboBox;
public SettingElementGenerator(ComboBox optionsComboBox)
{
this.optionsComboBox = optionsComboBox;
}
public void Generate(SettingElement settingElement, DockPanel dockPanel, TextBlock textBlock)
{
dockPanel.UpdateLayout();
textBlock.UpdateLayout();
if (settingElement.Element is DesktopMagicPluginAPI.Inputs.Label eLabel)
{
textBlock.Text = eLabel.Value;
textBlock.Margin = new Thickness(0, 5, 3, 0);
textBlock.HorizontalAlignment = HorizontalAlignment.Stretch;
textBlock.TextWrapping = TextWrapping.WrapWithOverflow;
if (eLabel.Bold)
{
textBlock.FontWeight = FontWeights.Bold;
}
eLabel.OnValueChanged += () =>
{
textBlock.Dispatcher.Invoke(() =>
{
textBlock.Text = eLabel.Value;
});
};
}
else if (settingElement.Element is DesktopMagicPluginAPI.Inputs.Button eButton)
{
Button button = new()
{
Content = eButton.Value,
FontSize = 10,
Height = 20,
Margin = new Thickness(0, 10, 0, 10),
Padding = new Thickness(0),
VerticalAlignment = VerticalAlignment.Center,
HorizontalAlignment = HorizontalAlignment.Stretch
};
button.Click += (_s, _e) =>
{
try
{
eButton.Click();
}
catch (Exception ex)
{
DisplayException(ex.Message);
}
};
eButton.OnValueChanged += () =>
{
button.Dispatcher.Invoke(() =>
{
button.Content = eButton.Value;
});
};
_ = dockPanel.Children.Add(button);
}
else if (settingElement.Element is DesktopMagicPluginAPI.Inputs.CheckBox eCheckBox)
{
CheckBox checkBox = new()
{
IsChecked = eCheckBox.Value,
Style = (Style)dockPanel.FindResource("MaterialDesignDarkCheckBox"),
VerticalAlignment = VerticalAlignment.Center,
HorizontalAlignment = HorizontalAlignment.Stretch
};
checkBox.Click += (_s, _e) =>
{
try
{
eCheckBox.Value = checkBox.IsChecked.GetValueOrDefault();
}
catch (Exception ex)
{
DisplayException(ex.Message);
}
};
eCheckBox.OnValueChanged += () =>
{
checkBox.Dispatcher.Invoke(() =>
{
checkBox.IsChecked = eCheckBox.Value;
});
};
_ = dockPanel.Children.Add(checkBox);
}
else if (settingElement.Element is DesktopMagicPluginAPI.Inputs.TextBox eTextBox)
{
TextBox textBox = new()
{
Text = eTextBox.Value,
TextWrapping = TextWrapping.Wrap,
VerticalAlignment = VerticalAlignment.Center,
HorizontalAlignment = HorizontalAlignment.Stretch
};
textBox.TextChanged += (_s, _e) =>
{
try
{
eTextBox.Value = textBox.Text;
}
catch (Exception ex)
{
DisplayException(ex.Message);
}
};
eTextBox.OnValueChanged += () =>
{
textBox.Dispatcher.Invoke(() =>
{
textBox.Text = eTextBox.Value;
});
};
_ = dockPanel.Children.Add(textBox);
}
else if (settingElement.Element is DesktopMagicPluginAPI.Inputs.IntegerUpDown eIntegerUpDown)
{
Xceed.Wpf.Toolkit.IntegerUpDown integerUpDown = new()
{
Value = eIntegerUpDown.Value,
Minimum = eIntegerUpDown.Minimum,
Maximum = eIntegerUpDown.Maximum,
VerticalAlignment = VerticalAlignment.Center,
HorizontalAlignment = HorizontalAlignment.Stretch
};
integerUpDown.ValueChanged += (_s, _e) =>
{
try
{
eIntegerUpDown.Value = integerUpDown.Value.GetValueOrDefault();
}
catch (Exception ex)
{
DisplayException(ex.Message);
}
};
eIntegerUpDown.OnValueChanged += () =>
{
integerUpDown.Dispatcher.Invoke(() =>
{
integerUpDown.Value = eIntegerUpDown.Value;
});
};
_ = dockPanel.Children.Add(integerUpDown);
}
else if (settingElement.Element is DesktopMagicPluginAPI.Inputs.Slider eSlider)
{
Slider slider = new()
{
Value = eSlider.Value,
Minimum = eSlider.Minimum,
Maximum = eSlider.Maximum,
TickFrequency = 1,
IsSnapToTickEnabled = true,
VerticalAlignment = VerticalAlignment.Center,
HorizontalAlignment = HorizontalAlignment.Stretch
};
slider.ValueChanged += (_s, _e) =>
{
try
{
eSlider.Value = slider.Value;
}
catch (Exception ex)
{
DisplayException(ex.Message);
}
};
eSlider.OnValueChanged += () =>
{
slider.Dispatcher.Invoke(() =>
{
slider.Value = eSlider.Value;
});
};
_ = dockPanel.Children.Add(slider);
}
}
private void DisplayException(string message)
{
App.Logger.Log(message, "PluginInput");
_ = MessageBox.Show("File execution error:\n" + message, "Error", MessageBoxButton.OK, MessageBoxImage.Error);
int index = MainWindow.WindowNames.IndexOf(((Tuple<string, int>)optionsComboBox.SelectedItem).Item1.ToString());
PluginWindow window = MainWindow.Windows[index] as PluginWindow;
window?.Exit();
}
}
}
+32 -19
View File
@@ -62,7 +62,7 @@
<CheckBox x:Name="mirrorModeCheckBox" Content="{DynamicResource mirrorMode}" Click="MirrorModeCheckBox_Click" Style="{StaticResource MaterialDesignDarkCheckBox}" /> <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}" /> <CheckBox x:Name="lineModeCheckBox" Content="{DynamicResource lineMode}" Click="LineModeCheckBox_Click" Style="{StaticResource MaterialDesignDarkCheckBox}" />
<Label Content="{DynamicResource amplifier}" HorizontalAlignment="Left" VerticalAlignment="Top" Padding="0,1" /> <Label Content="{DynamicResource amplifier}" HorizontalAlignment="Left" VerticalAlignment="Top" Padding="0,1" />
<Slider x:Name="amplifierLevelSlider" Margin="-2,0,10,0" HorizontalAlignment="Stretch" VerticalAlignment="Top" ValueChanged="AmplifierLevelSlider_ValueChanged" Maximum="50" Minimum="-50" SmallChange="1" LargeChange="5" Foreground="Gray" /> <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" /> <Label x:Name="amplifierLevelLabel" Content="Label" HorizontalAlignment="Left" VerticalAlignment="Top" Padding="0,1" />
</StackPanel> </StackPanel>
</Grid> </Grid>
@@ -74,23 +74,36 @@
<RowDefinition Height="*" /> <RowDefinition Height="*" />
<RowDefinition Height="110" /> <RowDefinition Height="110" />
</Grid.RowDefinitions> </Grid.RowDefinitions>
<StackPanel DockPanel.Dock="Top" Margin="{StaticResource DefaultMargin}" HorizontalAlignment="Left"> <Grid.ColumnDefinitions>
<ComboBox x:Name="fontComboBox" HorizontalAlignment="Stretch" VerticalAlignment="Top" SelectionChanged="FontComboBox_SelectionChanged" Margin="0,0,0,5" /> <ColumnDefinition/>
<!-- <ColumnDefinition/>
<DockPanel> </Grid.ColumnDefinitions>
<Label Content="R:" Width="20" /> <StackPanel Grid.Column="0" Margin="{StaticResource DefaultMargin}" HorizontalAlignment="Stretch">
<Slider x:Name="redSlider" Maximum="255" ValueChanged="ColorSliders_ValueChanged" TickFrequency="1" IsSnapToTickEnabled="True" Background="#00030000" />
</DockPanel> <Grid>
<DockPanel> <Grid.ColumnDefinitions>
<Label Content="G:" Width="20" /> <ColumnDefinition Width="1*"/>
<Slider x:Name="greenSlider" Maximum="255" ValueChanged="ColorSliders_ValueChanged" TickFrequency="1" IsSnapToTickEnabled="True" Background="#0000FF00" /> <ColumnDefinition Width="2*"/>
</DockPanel> </Grid.ColumnDefinitions>
<DockPanel> <TextBlock Text="Display Font: " Grid.Column="0" VerticalAlignment="Center"></TextBlock>
<Label Content="B:" Width="20" /> <ComboBox x:Name="fontComboBox" Grid.Column="1" HorizontalAlignment="Stretch" VerticalAlignment="Top" SelectionChanged="FontComboBox_SelectionChanged" Margin="0,0,0,5" />
<Slider x:Name="blueSlider" Maximum="255" ValueChanged="ColorSliders_ValueChanged" TickFrequency="1" IsSnapToTickEnabled="True" Background="#000000FF" /> </Grid>
</DockPanel>
--> <Grid>
<DockPanel Margin="0,0,0,5" Width="200"> <Grid.ColumnDefinitions>
<ColumnDefinition Width="1*"/>
<ColumnDefinition Width="2*"/>
</Grid.ColumnDefinitions>
<TextBlock Text="Corner Radius: " Grid.Column="0" VerticalAlignment="Center"></TextBlock>
<TextBox x:Name="cornerRadiusTextBox" Grid.Column="1" Text="10" TextChanged="CornerRadiusTextBox_TextChanged" materialDesign:HintAssist.HelperText="In px" materialDesign:HintAssist.Hint="Enter a number">
<materialDesign:TextFieldAssist.CharacterCounterStyle>
<Style TargetType="TextBlock" />
</materialDesign:TextFieldAssist.CharacterCounterStyle>
</TextBox>
</Grid>
</StackPanel>
<StackPanel Grid.Column="1" Margin="{StaticResource DefaultMargin}" HorizontalAlignment="Left">
<DockPanel Margin="0,0,0,5">
<Border CornerRadius="1" BorderThickness="1.5" BorderBrush="Gray" Height="23" Width="23" Margin="0,0,5,0"> <Border CornerRadius="1" BorderThickness="1.5" BorderBrush="Gray" Height="23" Width="23" Margin="0,0,5,0">
<Rectangle x:Name="primaryColorRechtangle" Fill="White" /> <Rectangle x:Name="primaryColorRechtangle" Fill="White" />
</Border> </Border>
@@ -109,7 +122,7 @@
<Button Content="Change Background Color" Height="23" FontSize="12" FontWeight="Regular" Click="ChangeBackgroundColorButton_Click" /> <Button Content="Change Background Color" Height="23" FontSize="12" FontWeight="Regular" Click="ChangeBackgroundColorButton_Click" />
</DockPanel> </DockPanel>
</StackPanel> </StackPanel>
<Grid Grid.Row="1" VerticalAlignment="Bottom"> <Grid Grid.Row="1" Grid.ColumnSpan="2" VerticalAlignment="Bottom">
<Grid.ColumnDefinitions> <Grid.ColumnDefinitions>
<ColumnDefinition /> <ColumnDefinition />
<ColumnDefinition /> <ColumnDefinition />
+39 -201
View File
@@ -26,28 +26,28 @@ namespace DesktopMagic
#region Global settings #region Global settings
internal static Theme Theme = new Theme(); internal static Theme Theme = new Theme();
public static bool EditMode { get; protected set; } = false; public static bool EditMode { get; private set; } = false;
#endregion Global settings #endregion Global settings
#region Music Visualizer Settings #region Music Visualizer Settings
public static int SpectrumMode { get; protected set; } = 0; public static int SpectrumMode { get; private set; } = 0;
public static int AmplifierLevel { get; protected set; } = 0; public static int AmplifierLevel { get; private set; } = 0;
public static bool MirrorMode { get; protected set; } = false; public static bool MirrorMode { get; private set; } = false;
public static bool LineMode { get; protected set; } = false; public static bool LineMode { get; private set; } = false;
public static System.Drawing.Color? MusicVisualzerColor { get; protected set; } public static System.Drawing.Color? MusicVisualzerColor { get; private set; }
#endregion Music Visualizer Settings #endregion Music Visualizer Settings
#region Plugins settings #region Plugins settings
internal static Dictionary<string, List<SettingElement>> PluginsSettings { get; set; } = new Dictionary<string, List<SettingElement>>(); internal static Dictionary<string, List<SettingElement>> PluginsSettings { get; } = new Dictionary<string, List<SettingElement>>();
#endregion Plugins settings #endregion Plugins settings
public static List<Window> Windows { get; protected set; } = new List<Window>(); public static List<Window> Windows { get; } = new List<Window>();
public static List<string> WindowNames { get; protected set; } = new List<string>(); public static List<string> WindowNames { get; } = new List<string>();
private readonly RegistryKey key; private readonly RegistryKey key;
private readonly System.Windows.Forms.NotifyIcon notifyIcon = new(); private readonly System.Windows.Forms.NotifyIcon notifyIcon = new();
@@ -66,7 +66,6 @@ namespace DesktopMagic
notifyIcon.Visible = true; notifyIcon.Visible = true;
notifyIcon.Text = App.AppName; notifyIcon.Text = App.AppName;
notifyIcon.Icon = new System.Drawing.Icon(iconStream); notifyIcon.Icon = new System.Drawing.Icon(iconStream);
notifyIcon.ContextMenuStrip = new System.Windows.Forms.ContextMenuStrip();
InitializeComponent(); InitializeComponent();
@@ -455,213 +454,29 @@ namespace DesktopMagic
return; return;
} }
SettingElementGenerator settingElementGenerator = new SettingElementGenerator(optionsComboBox);
foreach (SettingElement settingElement in settingElements) foreach (SettingElement settingElement in settingElements)
{ {
DockPanel stackPanel = new() DockPanel dockPanel = new()
{ {
LastChildFill = true, LastChildFill = true,
HorizontalAlignment = HorizontalAlignment.Stretch HorizontalAlignment = HorizontalAlignment.Stretch
}; };
_ = optionsPanel.Children.Add(stackPanel); _ = optionsPanel.Children.Add(dockPanel);
TextBlock label = 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
}; };
_ = stackPanel.Children.Add(label); _ = dockPanel.Children.Add(textBlock);
stackPanel.UpdateLayout(); settingElementGenerator.Generate(settingElement, dockPanel, textBlock);
label.UpdateLayout();
if (settingElement.Element is DesktopMagicPluginAPI.Inputs.Label eLabel)
{
label.Text = eLabel.Value;
label.Margin = new Thickness(0, 5, 3, 0);
label.HorizontalAlignment = HorizontalAlignment.Stretch;
label.TextWrapping = TextWrapping.WrapWithOverflow;
if (eLabel.Bold)
{
label.FontWeight = FontWeights.Bold;
}
eLabel.OnValueChanged += () =>
{
Dispatcher.Invoke(() =>
{
label.Text = eLabel.Value;
});
};
}
else if (settingElement.Element is DesktopMagicPluginAPI.Inputs.Button eButton)
{
Button button = new()
{
Content = eButton.Value,
FontSize = 10,
Height = 20,
Margin = new Thickness(0, 10, 0, 10),
Padding = new Thickness(0),
VerticalAlignment = VerticalAlignment.Center,
HorizontalAlignment = HorizontalAlignment.Stretch
};
button.Click += (_s, _e) =>
{
try
{
eButton.Click();
}
catch (Exception ex)
{
DisplayException(ex.Message);
}
};
eButton.OnValueChanged += () =>
{
Dispatcher.Invoke(() =>
{
button.Content = eButton.Value;
});
};
_ = stackPanel.Children.Add(button);
}
else if (settingElement.Element is DesktopMagicPluginAPI.Inputs.CheckBox eCheckBox)
{
CheckBox checkBox = new()
{
IsChecked = eCheckBox.Value,
Style = (Style)FindResource("MaterialDesignDarkCheckBox"),
VerticalAlignment = VerticalAlignment.Center,
HorizontalAlignment = HorizontalAlignment.Stretch
};
checkBox.Click += (_s, _e) =>
{
try
{
eCheckBox.Value = checkBox.IsChecked.GetValueOrDefault();
}
catch (Exception ex)
{
DisplayException(ex.Message);
}
};
eCheckBox.OnValueChanged += () =>
{
Dispatcher.Invoke(() =>
{
checkBox.IsChecked = eCheckBox.Value;
});
};
_ = stackPanel.Children.Add(checkBox);
}
else if (settingElement.Element is DesktopMagicPluginAPI.Inputs.TextBox eTextBox)
{
TextBox textBox = new()
{
Text = eTextBox.Value,
TextWrapping = TextWrapping.Wrap,
VerticalAlignment = VerticalAlignment.Center,
HorizontalAlignment = HorizontalAlignment.Stretch
};
textBox.TextChanged += (_s, _e) =>
{
try
{
eTextBox.Value = textBox.Text;
}
catch (Exception ex)
{
DisplayException(ex.Message);
}
};
eTextBox.OnValueChanged += () =>
{
Dispatcher.Invoke(() =>
{
textBox.Text = eTextBox.Value;
});
};
_ = stackPanel.Children.Add(textBox);
}
else if (settingElement.Element is DesktopMagicPluginAPI.Inputs.IntegerUpDown eIntegerUpDown)
{
Xceed.Wpf.Toolkit.IntegerUpDown integerUpDown = new()
{
Value = eIntegerUpDown.Value,
Minimum = eIntegerUpDown.Minimum,
Maximum = eIntegerUpDown.Maximum,
VerticalAlignment = VerticalAlignment.Center,
HorizontalAlignment = HorizontalAlignment.Stretch
};
integerUpDown.ValueChanged += (_s, _e) =>
{
try
{
eIntegerUpDown.Value = integerUpDown.Value.GetValueOrDefault();
}
catch (Exception ex)
{
DisplayException(ex.Message);
}
};
eIntegerUpDown.OnValueChanged += () =>
{
Dispatcher.Invoke(() =>
{
integerUpDown.Value = eIntegerUpDown.Value;
});
};
_ = stackPanel.Children.Add(integerUpDown);
}
else if (settingElement.Element is DesktopMagicPluginAPI.Inputs.Slider eSlider)
{
Slider slider = new()
{
Value = eSlider.Value,
Minimum = eSlider.Minimum,
Maximum = eSlider.Maximum,
TickFrequency = 1,
IsSnapToTickEnabled = true,
VerticalAlignment = VerticalAlignment.Center,
HorizontalAlignment = HorizontalAlignment.Stretch
};
slider.ValueChanged += (_s, _e) =>
{
try
{
eSlider.Value = slider.Value;
}
catch (Exception ex)
{
DisplayException(ex.Message);
}
};
eSlider.OnValueChanged += () =>
{
Dispatcher.Invoke(() =>
{
slider.Value = eSlider.Value;
});
};
_ = stackPanel.Children.Add(slider);
} }
} }
} }
}
private void DisplayException(string message)
{
App.Logger.Log(message, "PluginInput");
_ = MessageBox.Show("File execution error:\n" + message, "Error", MessageBoxButton.OK, MessageBoxImage.Error);
int index = WindowNames.IndexOf(((Tuple<string, int>)optionsComboBox.SelectedItem).Item1.ToString());
PluginWindow window = Windows[index] as PluginWindow;
window?.Exit();
}
#endregion Options #endregion Options
@@ -731,6 +546,22 @@ namespace DesktopMagic
} }
} }
private void CornerRadiusTextBox_TextChanged(object sender, TextChangedEventArgs e)
{
bool sucess = int.TryParse(cornerRadiusTextBox.Text, out int cornerRadius);
if (sucess)
{
cornerRadiusTextBox.Foreground = Brushes.Black;
Theme.CornerRadius = cornerRadius;
key.SetValue("CornerRadius", cornerRadius);
SaveLayout();
}
else
{
cornerRadiusTextBox.Foreground = Brushes.Red;
}
}
#region Layout #region Layout
private void LayoutsComboBox_SelectionChanged(object sender, SelectionChangedEventArgs e) private void LayoutsComboBox_SelectionChanged(object sender, SelectionChangedEventArgs e)
@@ -804,6 +635,11 @@ namespace DesktopMagic
private void SaveLayout() private void SaveLayout()
{ {
if (!loaded)
{
return;
}
_ = Task.Run(() => _ = Task.Run(() =>
{ {
lock (App.ApplicationDataPath) lock (App.ApplicationDataPath)
@@ -848,6 +684,7 @@ namespace DesktopMagic
mirrorModeCheckBox.IsChecked = bool.Parse(key.GetValue("MirrorMode", "false").ToString()); mirrorModeCheckBox.IsChecked = bool.Parse(key.GetValue("MirrorMode", "false").ToString());
lineModeCheckBox.IsChecked = bool.Parse(key.GetValue("LineMode", "false").ToString()); lineModeCheckBox.IsChecked = bool.Parse(key.GetValue("LineMode", "false").ToString());
musicVisualizerColorTextBox.Text = key.GetValue("MusicVisualizerColor", "").ToString(); musicVisualizerColorTextBox.Text = key.GetValue("MusicVisualizerColor", "").ToString();
cornerRadiusTextBox.Text = key.GetValue("CornerRadius", "0").ToString();
blockWindowsClosing = false; blockWindowsClosing = false;
string primaryColorHex = key.GetValue("PrimaryColor", "#FFFFFFFF").ToString(); string primaryColorHex = key.GetValue("PrimaryColor", "#FFFFFFFF").ToString();
@@ -879,6 +716,7 @@ namespace DesktopMagic
LineModeCheckBox_Click(null, null); LineModeCheckBox_Click(null, null);
SpectrumModeComboBox_SelectionChanged(null, null); SpectrumModeComboBox_SelectionChanged(null, null);
AmplifierLevelSlider_ValueChanged(null, null); AmplifierLevelSlider_ValueChanged(null, null);
CornerRadiusTextBox_TextChanged(null, null);
foreach (Window window in Windows) foreach (Window window in Windows)
{ {
+1 -1
View File
@@ -20,7 +20,7 @@ namespace DesktopMagic.Plugins
public ITheme Theme { get; } public ITheme Theme { get; }
public Point WindowSize => new Point((int)window.ActualWidth, (int)window.ActualHeight); public Size WindowSize => new Size((int)window.ActualWidth, (int)window.ActualHeight);
public Point WindowPosition => new Point((int)window.Left, (int)window.Top); public Point WindowPosition => new Point((int)window.Left, (int)window.Top);
+6 -3
View File
@@ -16,10 +16,13 @@
x:Name="window"> x:Name="window">
<Grid> <Grid>
<Rectangle x:Name="panel" Fill="#4CBAFFEF" Stroke="White" Margin="0,0,0,0" Visibility="Collapsed" /> <Rectangle x:Name="panel" Fill="#4CBAFFEF" Stroke="White" Margin="0,0,0,0" Visibility="Collapsed" />
<Viewbox StretchDirection="Both" Stretch="Uniform">
<Grid x:Name="backgroundGrid"> <Border x:Name="border" Width="{Binding ElementName=viewBox, Path=ActualWidth}" Height="{Binding ElementName=viewBox, Path=ActualHeight}"/>
<Viewbox x:Name="viewBox" StretchDirection="Both" Stretch="Uniform">
<Viewbox.Clip>
<RectangleGeometry x:Name="rectangleGeometry" RadiusX="{Binding ElementName=border, Path=CornerRadius.TopLeft}" RadiusY="{Binding ElementName=border, Path=CornerRadius.TopLeft}" Rect="{Binding ElementName=border}"/>
</Viewbox.Clip>
<Image x:Name="image" HorizontalAlignment="Left" RenderOptions.EdgeMode="Aliased" Margin="0,0,0,0" VerticalAlignment="Top" RenderTransformOrigin="0.5,0.5" Stretch="Uniform" MouseDown="Window_MouseDown" MouseMove="Window_MouseMove" MouseWheel="Window_MouseWheel"/> <Image x:Name="image" HorizontalAlignment="Left" RenderOptions.EdgeMode="Aliased" Margin="0,0,0,0" VerticalAlignment="Top" RenderTransformOrigin="0.5,0.5" Stretch="Uniform" MouseDown="Window_MouseDown" MouseMove="Window_MouseMove" MouseWheel="Window_MouseWheel"/>
</Grid>
</Viewbox> </Viewbox>
</Grid> </Grid>
<WindowChrome.WindowChrome> <WindowChrome.WindowChrome>
@@ -117,7 +117,9 @@ namespace DesktopMagic
} }
else else
{ {
backgroundGrid.Background = MainWindow.Theme.BackgroundBrush; rectangleGeometry.Rect = new Rect(0, 0, border.ActualWidth, border.ActualHeight);
border.Background = MainWindow.Theme.BackgroundBrush;
border.CornerRadius = new CornerRadius(MainWindow.Theme.CornerRadius);
} }
}); });
} }
+2 -3
View File
@@ -7,12 +7,11 @@ namespace DesktopMagic.Plugins
internal class Theme : ITheme internal class Theme : ITheme
{ {
public Color PrimaryColor { get; set; } = Color.White; public Color PrimaryColor { get; set; } = Color.White;
public Color SecondaryColor { get; set; } = Color.White; public Color SecondaryColor { get; set; } = Color.White;
public Color BackgroundColor { get; set; } = Color.Transparent; public Color BackgroundColor { get; set; } = Color.Transparent;
public string Font { get; internal set; } = "Segoe UI"; public string Font { get; set; } = "Segoe UI";
public int CornerRadius { get; set; }
public System.Windows.Media.Brush PrimaryBrush { get; set; } = System.Windows.Media.Brushes.White; 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 SecondaryBrush { get; set; } = System.Windows.Media.Brushes.White;
@@ -34,6 +34,7 @@
- [UpdateWindow()](#M-DesktopMagicPluginAPI-IPluginData-UpdateWindow 'DesktopMagicPluginAPI.IPluginData.UpdateWindow') - [UpdateWindow()](#M-DesktopMagicPluginAPI-IPluginData-UpdateWindow 'DesktopMagicPluginAPI.IPluginData.UpdateWindow')
- [ITheme](#T-DesktopMagicPluginAPI-ITheme 'DesktopMagicPluginAPI.ITheme') - [ITheme](#T-DesktopMagicPluginAPI-ITheme 'DesktopMagicPluginAPI.ITheme')
- [BackgroundColor](#P-DesktopMagicPluginAPI-ITheme-BackgroundColor 'DesktopMagicPluginAPI.ITheme.BackgroundColor') - [BackgroundColor](#P-DesktopMagicPluginAPI-ITheme-BackgroundColor 'DesktopMagicPluginAPI.ITheme.BackgroundColor')
- [CornerRadius](#P-DesktopMagicPluginAPI-ITheme-CornerRadius 'DesktopMagicPluginAPI.ITheme.CornerRadius')
- [Font](#P-DesktopMagicPluginAPI-ITheme-Font 'DesktopMagicPluginAPI.ITheme.Font') - [Font](#P-DesktopMagicPluginAPI-ITheme-Font 'DesktopMagicPluginAPI.ITheme.Font')
- [PrimaryColor](#P-DesktopMagicPluginAPI-ITheme-PrimaryColor 'DesktopMagicPluginAPI.ITheme.PrimaryColor') - [PrimaryColor](#P-DesktopMagicPluginAPI-ITheme-PrimaryColor 'DesktopMagicPluginAPI.ITheme.PrimaryColor')
- [SecondaryColor](#P-DesktopMagicPluginAPI-ITheme-SecondaryColor 'DesktopMagicPluginAPI.ITheme.SecondaryColor') - [SecondaryColor](#P-DesktopMagicPluginAPI-ITheme-SecondaryColor 'DesktopMagicPluginAPI.ITheme.SecondaryColor')
@@ -329,14 +330,14 @@ Defines properties and methods that provide information about the main applicati
##### Summary ##### Summary
Gets the current color of the main application. Gets the current color of the current theme.
<a name='P-DesktopMagicPluginAPI-IPluginData-Font'></a> <a name='P-DesktopMagicPluginAPI-IPluginData-Font'></a>
### Font `property` ### Font `property`
##### Summary ##### Summary
Gets the current font of the main application. Gets the current font of the current theme.
<a name='P-DesktopMagicPluginAPI-IPluginData-PluginName'></a> <a name='P-DesktopMagicPluginAPI-IPluginData-PluginName'></a>
### PluginName `property` ### PluginName `property`
@@ -400,28 +401,35 @@ The theme settings of the main application.
##### Summary ##### Summary
Gets the background color of the main application. Gets the background color of the current theme.
<a name='P-DesktopMagicPluginAPI-ITheme-CornerRadius'></a>
### CornerRadius `property`
##### Summary
Gets the corner radius of the current theme.
<a name='P-DesktopMagicPluginAPI-ITheme-Font'></a> <a name='P-DesktopMagicPluginAPI-ITheme-Font'></a>
### Font `property` ### Font `property`
##### Summary ##### Summary
Gets the font of the main application. Gets the font of the current theme.
<a name='P-DesktopMagicPluginAPI-ITheme-PrimaryColor'></a> <a name='P-DesktopMagicPluginAPI-ITheme-PrimaryColor'></a>
### PrimaryColor `property` ### PrimaryColor `property`
##### Summary ##### Summary
Gets the primary color of the main application. Gets the primary color of the current theme.
<a name='P-DesktopMagicPluginAPI-ITheme-SecondaryColor'></a> <a name='P-DesktopMagicPluginAPI-ITheme-SecondaryColor'></a>
### SecondaryColor `property` ### SecondaryColor `property`
##### Summary ##### Summary
Gets the secondary color of the main application. Gets the secondary color of the current theme.
<a name='T-DesktopMagicPluginAPI-Inputs-IntegerUpDown'></a> <a name='T-DesktopMagicPluginAPI-Inputs-IntegerUpDown'></a>
## IntegerUpDown `type` ## IntegerUpDown `type`
@@ -283,12 +283,12 @@
</member> </member>
<member name="P:DesktopMagicPluginAPI.IPluginData.Font"> <member name="P:DesktopMagicPluginAPI.IPluginData.Font">
<summary> <summary>
Gets the current font of the main application. Gets the current font of the current theme.
</summary> </summary>
</member> </member>
<member name="P:DesktopMagicPluginAPI.IPluginData.Color"> <member name="P:DesktopMagicPluginAPI.IPluginData.Color">
<summary> <summary>
Gets the current color of the main application. Gets the current color of the current theme.
</summary> </summary>
</member> </member>
<member name="P:DesktopMagicPluginAPI.IPluginData.Theme"> <member name="P:DesktopMagicPluginAPI.IPluginData.Theme">
@@ -328,22 +328,27 @@
</member> </member>
<member name="P:DesktopMagicPluginAPI.ITheme.PrimaryColor"> <member name="P:DesktopMagicPluginAPI.ITheme.PrimaryColor">
<summary> <summary>
Gets the primary color of the main application. Gets the primary color of the current theme.
</summary> </summary>
</member> </member>
<member name="P:DesktopMagicPluginAPI.ITheme.SecondaryColor"> <member name="P:DesktopMagicPluginAPI.ITheme.SecondaryColor">
<summary> <summary>
Gets the secondary color of the main application. Gets the secondary color of the current theme.
</summary> </summary>
</member> </member>
<member name="P:DesktopMagicPluginAPI.ITheme.BackgroundColor"> <member name="P:DesktopMagicPluginAPI.ITheme.BackgroundColor">
<summary> <summary>
Gets the background color of the main application. Gets the background color of the current theme.
</summary> </summary>
</member> </member>
<member name="P:DesktopMagicPluginAPI.ITheme.Font"> <member name="P:DesktopMagicPluginAPI.ITheme.Font">
<summary> <summary>
Gets the font of the main application. Gets the font of the current theme.
</summary>
</member>
<member name="P:DesktopMagicPluginAPI.ITheme.CornerRadius">
<summary>
Gets the corner radius of the current theme.
</summary> </summary>
</member> </member>
<member name="T:DesktopMagicPluginAPI.Plugin"> <member name="T:DesktopMagicPluginAPI.Plugin">
+3 -3
View File
@@ -9,13 +9,13 @@ namespace DesktopMagicPluginAPI
public interface IPluginData public interface IPluginData
{ {
/// <summary> /// <summary>
/// Gets the current font of the main application. /// Gets the current font of the current theme.
/// </summary> /// </summary>
[Obsolete("Use the \"Theme\" property instead")] [Obsolete("Use the \"Theme\" property instead")]
string Font { get; } string Font { get; }
/// <summary> /// <summary>
/// Gets the current color of the main application. /// Gets the current color of the current theme.
/// </summary> /// </summary>
[Obsolete("Use the \"Theme\" property instead")] [Obsolete("Use the \"Theme\" property instead")]
Color Color { get; } Color Color { get; }
@@ -28,7 +28,7 @@ namespace DesktopMagicPluginAPI
/// <summary> /// <summary>
/// Gets the window size of the plugin window. /// Gets the window size of the plugin window.
/// </summary> /// </summary>
Point WindowSize { get; } Size WindowSize { get; }
/// <summary> /// <summary>
/// Gets the window position of the plugin window. /// Gets the window position of the plugin window.
+9 -4
View File
@@ -8,23 +8,28 @@ namespace DesktopMagicPluginAPI
public interface ITheme public interface ITheme
{ {
/// <summary> /// <summary>
/// Gets the primary color of the main application. /// Gets the primary color of the current theme.
/// </summary> /// </summary>
Color PrimaryColor { get; } Color PrimaryColor { get; }
/// <summary> /// <summary>
/// Gets the secondary color of the main application. /// Gets the secondary color of the current theme.
/// </summary> /// </summary>
Color SecondaryColor { get; } Color SecondaryColor { get; }
/// <summary> /// <summary>
/// Gets the background color of the main application. /// Gets the background color of the current theme.
/// </summary> /// </summary>
Color BackgroundColor { get; } Color BackgroundColor { get; }
/// <summary> /// <summary>
/// Gets the font of the main application. /// Gets the font of the current theme.
/// </summary> /// </summary>
string Font { get; } string Font { get; }
/// <summary>
/// Gets the corner radius of the current theme.
/// </summary>
int CornerRadius { get; }
} }
} }