- 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
private readonly Updater updater = new Updater(TimeSpan.FromDays(1), "https://raw.githubusercontent.com/Stone-Red-Code/DesktopMagic/develop/update/updateInfo.json");
#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
public const string AppName = "Desktop Magic";
@@ -104,7 +104,7 @@ namespace DesktopMagic
InfoConfig = new OutputConfig()
{
Color = ConsoleColor.White,
LogTarget = LogTarget.Console | LogTarget.File,
LogTarget = LogTarget.DebugConsole | LogTarget.File,
FilePath = logFilePath
},
DebugConfig = new OutputConfig()
@@ -14,10 +14,14 @@
x:Name="window">
<Grid>
<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">
<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>
</Viewbox>
</Grid>
@@ -87,12 +87,13 @@ namespace DesktopMagic
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.Foreground = MainWindow.Theme.PrimaryBrush;
valuetextBlock.Background = MainWindow.Theme.BackgroundBrush;
valuetextBlock.FontFamily = new FontFamily(MainWindow.Theme.Font);
valuetextBlock.Foreground = MainWindow.Theme.PrimaryBrush;
valueTextBlock.FontFamily = new FontFamily(MainWindow.Theme.Font);
valueTextBlock.Foreground = MainWindow.Theme.PrimaryBrush;
ClculateWidth();
});
@@ -103,7 +104,7 @@ namespace DesktopMagic
string cpuUsage = GetCpuUsage();
Dispatcher.Invoke(() =>
{
valuetextBlock.Text = cpuUsage;
valueTextBlock.Text = cpuUsage;
});
}
@@ -13,8 +13,13 @@
x:Name="window">
<Grid>
<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>
</Grid>
<WindowChrome.WindowChrome>
@@ -69,10 +69,13 @@ namespace DesktopMagic
WindowPos.SetIsLocked(this, true);
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.Foreground = MainWindow.Theme.PrimaryBrush;
textBlock.Text = DateTime.Now.ToLongDateString();
textBlock.Background = MainWindow.Theme.BackgroundBrush;
});
}
@@ -11,16 +11,18 @@
AllowsTransparency="True"
LocationChanged="Window_LocationChanged"
SizeChanged="Window_SizeChanged"
x:Name="window">
x:Name="window">
<WindowChrome.WindowChrome>
<WindowChrome x:Name="tileBar" CaptionHeight="30" ResizeBorderThickness="{x:Static SystemParameters.WindowResizeBorderThickness}" />
</WindowChrome.WindowChrome>
<Grid x:Name="grid">
<Rectangle x:Name="panel" Fill="#4CBAFFEF" Stroke="White" Margin="0,0,0,0" Visibility="Collapsed" />
<Viewbox StretchDirection="Both" Stretch="Uniform">
<Grid x:Name="backgroundGrid">
<Image x:Name="image" HorizontalAlignment="Left" Height="759" Margin="0,0,0,0" VerticalAlignment="Top" Width="1747" RenderTransformOrigin="0.5,0.5" Stretch="Fill" />
</Grid>
<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" Margin="0,0,0,0" VerticalAlignment="Top" Stretch="Fill" />
</Viewbox>
</Grid>
</Window>
@@ -102,7 +102,9 @@ namespace DesktopMagic
ResizeMode = ResizeMode.NoResize;
}
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">
<Grid>
<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" />
</Viewbox>
</Grid>
@@ -72,7 +72,9 @@ namespace DesktopMagic
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.Foreground = MainWindow.Theme.PrimaryBrush;
//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();
}
}
}
+34 -21
View File
@@ -46,7 +46,7 @@
</DockPanel>
<DockPanel Grid.Column="1" Margin="2.5,0,0,0">
<ComboBox x:Name="optionsComboBox" DockPanel.Dock="Top" Height="24" SelectedIndex="0" DisplayMemberPath="Item1" SelectionChanged="OptionsComboBox_SelectionChanged" Background="#FFECECEC" Padding="4" VerticalAlignment="Center"/>
<ComboBox x:Name="optionsComboBox" DockPanel.Dock="Top" Height="24" SelectedIndex="0" DisplayMemberPath="Item1" 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" >
@@ -62,7 +62,7 @@
<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" 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" />
</StackPanel>
</Grid>
@@ -74,23 +74,36 @@
<RowDefinition Height="*" />
<RowDefinition Height="110" />
</Grid.RowDefinitions>
<StackPanel DockPanel.Dock="Top" Margin="{StaticResource DefaultMargin}" HorizontalAlignment="Left">
<ComboBox x:Name="fontComboBox" HorizontalAlignment="Stretch" VerticalAlignment="Top" SelectionChanged="FontComboBox_SelectionChanged" Margin="0,0,0,5" />
<!--
<DockPanel>
<Label Content="R:" Width="20" />
<Slider x:Name="redSlider" Maximum="255" ValueChanged="ColorSliders_ValueChanged" TickFrequency="1" IsSnapToTickEnabled="True" Background="#00030000" />
</DockPanel>
<DockPanel>
<Label Content="G:" Width="20" />
<Slider x:Name="greenSlider" Maximum="255" ValueChanged="ColorSliders_ValueChanged" TickFrequency="1" IsSnapToTickEnabled="True" Background="#0000FF00" />
</DockPanel>
<DockPanel>
<Label Content="B:" Width="20" />
<Slider x:Name="blueSlider" Maximum="255" ValueChanged="ColorSliders_ValueChanged" TickFrequency="1" IsSnapToTickEnabled="True" Background="#000000FF" />
</DockPanel>
-->
<DockPanel Margin="0,0,0,5" Width="200">
<Grid.ColumnDefinitions>
<ColumnDefinition/>
<ColumnDefinition/>
</Grid.ColumnDefinitions>
<StackPanel Grid.Column="0" Margin="{StaticResource DefaultMargin}" HorizontalAlignment="Stretch">
<Grid>
<Grid.ColumnDefinitions>
<ColumnDefinition Width="1*"/>
<ColumnDefinition Width="2*"/>
</Grid.ColumnDefinitions>
<TextBlock Text="Display Font: " Grid.Column="0" VerticalAlignment="Center"></TextBlock>
<ComboBox x:Name="fontComboBox" Grid.Column="1" HorizontalAlignment="Stretch" VerticalAlignment="Top" SelectionChanged="FontComboBox_SelectionChanged" Margin="0,0,0,5" />
</Grid>
<Grid>
<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">
<Rectangle x:Name="primaryColorRechtangle" Fill="White" />
</Border>
@@ -102,14 +115,14 @@
</Border>
<Button Content="Change Secondary Color" Height="23" FontSize="12" FontWeight="Regular" Click="ChangeSecondaryColorButton_Click" />
</DockPanel>
<DockPanel >
<DockPanel>
<Border CornerRadius="1" BorderThickness="1.5" BorderBrush="Gray" Height="23" Width="23" Margin="0,0,5,0">
<Rectangle x:Name="backgroundColorRechtangle" Fill="White" />
</Border>
<Button Content="Change Background Color" Height="23" FontSize="12" FontWeight="Regular" Click="ChangeBackgroundColorButton_Click" />
</DockPanel>
</StackPanel>
<Grid Grid.Row="1" VerticalAlignment="Bottom">
<Grid Grid.Row="1" Grid.ColumnSpan="2" VerticalAlignment="Bottom">
<Grid.ColumnDefinitions>
<ColumnDefinition />
<ColumnDefinition />
+59 -221
View File
@@ -26,28 +26,28 @@ namespace DesktopMagic
#region Global settings
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
#region Music Visualizer Settings
public static int SpectrumMode { get; protected set; } = 0;
public static int AmplifierLevel { get; protected set; } = 0;
public static bool MirrorMode { get; protected set; } = false;
public static bool LineMode { get; protected set; } = false;
public static System.Drawing.Color? MusicVisualzerColor { get; protected set; }
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; set; } = new Dictionary<string, List<SettingElement>>();
internal static Dictionary<string, List<SettingElement>> PluginsSettings { get; } = new Dictionary<string, List<SettingElement>>();
#endregion Plugins settings
public static List<Window> Windows { get; protected set; } = new List<Window>();
public static List<string> WindowNames { get; protected set; } = new List<string>();
public static List<Window> Windows { get; } = new List<Window>();
public static List<string> WindowNames { get; } = new List<string>();
private readonly RegistryKey key;
private readonly System.Windows.Forms.NotifyIcon notifyIcon = new();
@@ -66,7 +66,6 @@ namespace DesktopMagic
notifyIcon.Visible = true;
notifyIcon.Text = App.AppName;
notifyIcon.Icon = new System.Drawing.Icon(iconStream);
notifyIcon.ContextMenuStrip = new System.Windows.Forms.ContextMenuStrip();
InitializeComponent();
@@ -455,214 +454,30 @@ namespace DesktopMagic
return;
}
SettingElementGenerator settingElementGenerator = new SettingElementGenerator(optionsComboBox);
foreach (SettingElement settingElement in settingElements)
{
DockPanel stackPanel = new()
DockPanel dockPanel = new()
{
LastChildFill = true,
HorizontalAlignment = HorizontalAlignment.Stretch
};
_ = optionsPanel.Children.Add(stackPanel);
_ = optionsPanel.Children.Add(dockPanel);
TextBlock label = new()
TextBlock textBlock = new()
{
Text = settingElement.Name,
Padding = new Thickness(0, 0, 3, 0),
VerticalAlignment = VerticalAlignment.Center
};
_ = stackPanel.Children.Add(label);
stackPanel.UpdateLayout();
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);
}
_ = dockPanel.Children.Add(textBlock);
settingElementGenerator.Generate(settingElement, dockPanel, textBlock);
}
}
}
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
private void TextBlock_Loaded(object sender, RoutedEventArgs e)
@@ -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
private void LayoutsComboBox_SelectionChanged(object sender, SelectionChangedEventArgs e)
@@ -804,27 +635,32 @@ namespace DesktopMagic
private void SaveLayout()
{
if (!loaded)
{
return;
}
_ = Task.Run(() =>
{
lock (App.ApplicationDataPath)
{
List<string> lines = File.ReadAllLines(App.ApplicationDataPath + "\\layouts.save").ToList();
string content = "";
foreach (string valueName in key.GetValueNames())
{
if (valueName != "SelectedLayout")
{
content += valueName + ":" + key.GetValue(valueName).ToString() + ";";
}
}
Dispatcher.Invoke(() =>
{
content += layoutsComboBox.SelectedItem.ToString();
lines[layoutsComboBox.SelectedIndex] = content;
});
File.WriteAllLines(App.ApplicationDataPath + "\\layouts.save", lines);
}
});
{
lock (App.ApplicationDataPath)
{
List<string> lines = File.ReadAllLines(App.ApplicationDataPath + "\\layouts.save").ToList();
string content = "";
foreach (string valueName in key.GetValueNames())
{
if (valueName != "SelectedLayout")
{
content += valueName + ":" + key.GetValue(valueName).ToString() + ";";
}
}
Dispatcher.Invoke(() =>
{
content += layoutsComboBox.SelectedItem.ToString();
lines[layoutsComboBox.SelectedIndex] = content;
});
File.WriteAllLines(App.ApplicationDataPath + "\\layouts.save", lines);
}
});
}
private void LoadLayoutNames()
@@ -848,6 +684,7 @@ namespace DesktopMagic
mirrorModeCheckBox.IsChecked = bool.Parse(key.GetValue("MirrorMode", "false").ToString());
lineModeCheckBox.IsChecked = bool.Parse(key.GetValue("LineMode", "false").ToString());
musicVisualizerColorTextBox.Text = key.GetValue("MusicVisualizerColor", "").ToString();
cornerRadiusTextBox.Text = key.GetValue("CornerRadius", "0").ToString();
blockWindowsClosing = false;
string primaryColorHex = key.GetValue("PrimaryColor", "#FFFFFFFF").ToString();
@@ -879,6 +716,7 @@ namespace DesktopMagic
LineModeCheckBox_Click(null, null);
SpectrumModeComboBox_SelectionChanged(null, null);
AmplifierLevelSlider_ValueChanged(null, null);
CornerRadiusTextBox_TextChanged(null, null);
foreach (Window window in Windows)
{
+1 -1
View File
@@ -20,7 +20,7 @@ namespace DesktopMagic.Plugins
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);
+7 -4
View File
@@ -16,10 +16,13 @@
x:Name="window">
<Grid>
<Rectangle x:Name="panel" Fill="#4CBAFFEF" Stroke="White" Margin="0,0,0,0" Visibility="Collapsed" />
<Viewbox StretchDirection="Both" Stretch="Uniform">
<Grid x:Name="backgroundGrid">
<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>
<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"/>
</Viewbox>
</Grid>
<WindowChrome.WindowChrome>
@@ -117,7 +117,9 @@ namespace DesktopMagic
}
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
{
public Color PrimaryColor { get; set; } = Color.White;
public Color SecondaryColor { get; set; } = Color.White;
public Color BackgroundColor { get; set; } = Color.Transparent;
public string Font { get; internal set; } = "Segoe UI";
public 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 SecondaryBrush { get; set; } = System.Windows.Media.Brushes.White;
@@ -34,6 +34,7 @@
- [UpdateWindow()](#M-DesktopMagicPluginAPI-IPluginData-UpdateWindow 'DesktopMagicPluginAPI.IPluginData.UpdateWindow')
- [ITheme](#T-DesktopMagicPluginAPI-ITheme 'DesktopMagicPluginAPI.ITheme')
- [BackgroundColor](#P-DesktopMagicPluginAPI-ITheme-BackgroundColor 'DesktopMagicPluginAPI.ITheme.BackgroundColor')
- [CornerRadius](#P-DesktopMagicPluginAPI-ITheme-CornerRadius 'DesktopMagicPluginAPI.ITheme.CornerRadius')
- [Font](#P-DesktopMagicPluginAPI-ITheme-Font 'DesktopMagicPluginAPI.ITheme.Font')
- [PrimaryColor](#P-DesktopMagicPluginAPI-ITheme-PrimaryColor 'DesktopMagicPluginAPI.ITheme.PrimaryColor')
- [SecondaryColor](#P-DesktopMagicPluginAPI-ITheme-SecondaryColor 'DesktopMagicPluginAPI.ITheme.SecondaryColor')
@@ -329,14 +330,14 @@ Defines properties and methods that provide information about the main applicati
##### Summary
Gets the current color of the main application.
Gets the current color of the current theme.
<a name='P-DesktopMagicPluginAPI-IPluginData-Font'></a>
### Font `property`
##### Summary
Gets the current font of the main application.
Gets the current font of the current theme.
<a name='P-DesktopMagicPluginAPI-IPluginData-PluginName'></a>
### PluginName `property`
@@ -400,28 +401,35 @@ The theme settings of the main application.
##### 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>
### Font `property`
##### Summary
Gets the font of the main application.
Gets the font of the current theme.
<a name='P-DesktopMagicPluginAPI-ITheme-PrimaryColor'></a>
### PrimaryColor `property`
##### Summary
Gets the primary color of the main application.
Gets the primary color of the current theme.
<a name='P-DesktopMagicPluginAPI-ITheme-SecondaryColor'></a>
### SecondaryColor `property`
##### Summary
Gets the secondary color of the main application.
Gets the secondary color of the current theme.
<a name='T-DesktopMagicPluginAPI-Inputs-IntegerUpDown'></a>
## IntegerUpDown `type`
@@ -283,12 +283,12 @@
</member>
<member name="P:DesktopMagicPluginAPI.IPluginData.Font">
<summary>
Gets the current font of the main application.
Gets the current font of the current theme.
</summary>
</member>
<member name="P:DesktopMagicPluginAPI.IPluginData.Color">
<summary>
Gets the current color of the main application.
Gets the current color of the current theme.
</summary>
</member>
<member name="P:DesktopMagicPluginAPI.IPluginData.Theme">
@@ -328,22 +328,27 @@
</member>
<member name="P:DesktopMagicPluginAPI.ITheme.PrimaryColor">
<summary>
Gets the primary color of the main application.
Gets the primary color of the current theme.
</summary>
</member>
<member name="P:DesktopMagicPluginAPI.ITheme.SecondaryColor">
<summary>
Gets the secondary color of the main application.
Gets the secondary color of the current theme.
</summary>
</member>
<member name="P:DesktopMagicPluginAPI.ITheme.BackgroundColor">
<summary>
Gets the background color of the main application.
Gets the background color of the current theme.
</summary>
</member>
<member name="P:DesktopMagicPluginAPI.ITheme.Font">
<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>
</member>
<member name="T:DesktopMagicPluginAPI.Plugin">
+3 -3
View File
@@ -9,13 +9,13 @@ namespace DesktopMagicPluginAPI
public interface IPluginData
{
/// <summary>
/// Gets the current font of the main application.
/// Gets the current font of the current theme.
/// </summary>
[Obsolete("Use the \"Theme\" property instead")]
string Font { get; }
/// <summary>
/// Gets the current color of the main application.
/// Gets the current color of the current theme.
/// </summary>
[Obsolete("Use the \"Theme\" property instead")]
Color Color { get; }
@@ -28,7 +28,7 @@ namespace DesktopMagicPluginAPI
/// <summary>
/// Gets the window size of the plugin window.
/// </summary>
Point WindowSize { get; }
Size WindowSize { get; }
/// <summary>
/// Gets the window position of the plugin window.
+9 -4
View File
@@ -8,23 +8,28 @@ namespace DesktopMagicPluginAPI
public interface ITheme
{
/// <summary>
/// Gets the primary color of the main application.
/// Gets the primary color of the current theme.
/// </summary>
Color PrimaryColor { get; }
/// <summary>
/// Gets the secondary color of the main application.
/// Gets the secondary color of the current theme.
/// </summary>
Color SecondaryColor { get; }
/// <summary>
/// Gets the background color of the main application.
/// Gets the background color of the current theme.
/// </summary>
Color BackgroundColor { get; }
/// <summary>
/// Gets the font of the main application.
/// Gets the font of the current theme.
/// </summary>
string Font { get; }
/// <summary>
/// Gets the corner radius of the current theme.
/// </summary>
int CornerRadius { get; }
}
}