- Better theming system

- More code structure inmrovements
This commit is contained in:
Stone-Red-Code
2021-10-25 22:38:45 +02:00
parent 520f145eb0
commit 9dd40c7ae8
22 changed files with 481 additions and 110 deletions
@@ -15,7 +15,10 @@
<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="CPU: 000%" IsHitTestVisible="False" />
<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" />
</DockPanel>
</Viewbox>
</Grid>
<WindowChrome.WindowChrome>
@@ -1,4 +1,6 @@
using Microsoft.Win32;
using DesktopMagic.Helpers;
using Microsoft.Win32;
using System;
using System.Diagnostics;
@@ -38,7 +40,7 @@ namespace DesktopMagic
cpuCounter.InstanceName = "_Total";
Timer t = new Timer();
t.Interval = 100;
t.Interval = 500;
t.Elapsed += UpdateTimer_Elapsed;
t.Start();
@@ -81,8 +83,14 @@ namespace DesktopMagic
WindowPos.SetIsLocked(this, true);
}
textBlock.Background = MainWindow.Theme.BackgroundBrush;
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;
ClculateWidth();
});
}
@@ -91,13 +99,24 @@ namespace DesktopMagic
string cpuUsage = GetCpuUsage();
Dispatcher.Invoke(() =>
{
textBlock.Text = cpuUsage;
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 "CPU: " + ((int)cpuCounter.NextValue()).ToString().PadLeft(3, '0') + "%";
return $"{(int)cpuCounter.NextValue()}%";
}
private void Window_LocationChanged(object sender, EventArgs e)
@@ -67,7 +67,8 @@ namespace DesktopMagic
}
textBlock.FontFamily = new FontFamily(MainWindow.Theme.Font);
textBlock.Foreground = MainWindow.Theme.PrimaryBrush;
textBlock.Text = DateTime.Now.ToString("D");
textBlock.Text = DateTime.Now.ToLongDateString();
textBlock.Background = MainWindow.Theme.BackgroundBrush;
});
}
@@ -18,7 +18,9 @@
<Grid x:Name="grid">
<Rectangle x:Name="panel" Fill="#4CBAFFEF" Stroke="White" Margin="0,0,0,0" Visibility="Collapsed" />
<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" />
<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>
</Viewbox>
</Grid>
</Window>
@@ -6,7 +6,6 @@ using System;
using System.Collections.Generic;
using System.Diagnostics;
using System.Drawing;
using System.Drawing.Drawing2D;
using System.Drawing.Imaging;
using System.Linq;
using System.Runtime.InteropServices;
@@ -105,6 +104,7 @@ namespace DesktopMagic
{
calculate = true;
}
backgroundGrid.Background = MainWindow.Theme.BackgroundBrush;
});
}
@@ -244,7 +244,6 @@ namespace DesktopMagic
using (Graphics gr = Graphics.FromImage(bm))
{
gr.SmoothingMode = SmoothingMode.None;
PointF[] points = new PointF[scaledFft.Count + 2];
int fftIndex = 0;
@@ -1,4 +1,6 @@
using Microsoft.Win32;
using DesktopMagic.Helpers;
using Microsoft.Win32;
using System;
using System.Timers;
@@ -29,7 +31,7 @@ namespace DesktopMagic
w.Hide();
Timer t = new Timer();
t.Interval = 100;
t.Interval = 500;
t.Elapsed += UpdateTimer_Elapsed;
t.Start();
@@ -66,13 +68,27 @@ namespace DesktopMagic
WindowPos.SetIsLocked(this, true);
}
textBlock.Background = MainWindow.Theme.BackgroundBrush;
textBlock.FontFamily = new FontFamily(MainWindow.Theme.Font);
textBlock.Foreground = MainWindow.Theme.PrimaryBrush;
//textBlock.Text = DateTime.Now.ToString("hh:mm:ss tt");
textBlock.Text = DateTime.Now.ToString("HH:mm:ss");
ClculateWidth();
});
}
private void ClculateWidth()
{
string template = "##:##:##";
double lenght = 0;
for (int i = 0; i < 9; i++)
{
lenght = Math.Max(StringUtilities.MeasureString(template.Replace('#', i.ToString()[0]), textBlock).Width, lenght);
}
textBlock.Width = lenght;
}
private void Window_LocationChanged(object sender, EventArgs e)
{
key.SetValue("TimeWindowTop", Top);
+3 -3
View File
@@ -8,11 +8,11 @@
<ApplicationIcon>icon.ico</ApplicationIcon>
<RunPostBuildEvent>OnBuildSuccess</RunPostBuildEvent>
<Authors>Stone_Red</Authors>
<Version>0.0.3.0</Version>
<Version>0.0.3.1</Version>
<PackageProjectUrl>https://github.com/Stone-Red-Code/DesktopMagic</PackageProjectUrl>
<RepositoryUrl>https://github.com/Stone-Red-Code/DesktopMagic</RepositoryUrl>
<AssemblyVersion>0.0.3.0</AssemblyVersion>
<FileVersion>0.0.3.0</FileVersion>
<AssemblyVersion>0.0.3.1</AssemblyVersion>
<FileVersion>0.0.3.1</FileVersion>
</PropertyGroup>
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|AnyCPU'">
+49
View File
@@ -0,0 +1,49 @@
<Window x:Class="DesktopMagic.Dialogs.ColorDialog"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
xmlns:materialDesign="http://materialdesigninxaml.net/winfx/xaml/themes"
xmlns:local="clr-namespace:DesktopMagic.Dialogs"
mc:Ignorable="d"
ResizeMode="NoResize"
Title="ColorDialog"
SizeToContent="WidthAndHeight">
<Grid>
<StackPanel Margin="15">
<Label x:Name="label" Content="Label" HorizontalAlignment="Left" VerticalAlignment="Top"/>
<DockPanel>
<Label Content="A:" Width="20" />
<Slider x:Name="alphaSlider" VerticalAlignment="Center" Maximum="255" ValueChanged="ColorSliders_ValueChanged" TickFrequency="1" IsSnapToTickEnabled="True" Background="#00030000" />
</DockPanel>
<DockPanel>
<Label Content="R:" Width="20" />
<Slider x:Name="redSlider" VerticalAlignment="Center" Maximum="255" ValueChanged="ColorSliders_ValueChanged" TickFrequency="1" IsSnapToTickEnabled="True" Background="#00030000" />
</DockPanel>
<DockPanel>
<Label Content="G:" Width="20" />
<Slider x:Name="greenSlider" VerticalAlignment="Center" Maximum="255" ValueChanged="ColorSliders_ValueChanged" TickFrequency="1" IsSnapToTickEnabled="True" Background="#0000FF00" />
</DockPanel>
<DockPanel>
<Label Content="B:" Width="20" />
<Slider x:Name="blueSlider" VerticalAlignment="Center" Maximum="255" ValueChanged="ColorSliders_ValueChanged" TickFrequency="1" IsSnapToTickEnabled="True" Background="#000000FF" />
</DockPanel>
<StackPanel Orientation="Horizontal">
<Border CornerRadius="1" BorderThickness="1.5" BorderBrush="Gray" Height="23" Width="23" Margin="0,0,5,0">
<Rectangle x:Name="colorRechtangle" Fill="White" />
</Border>
<TextBox x:Name="colorHexTextBox" MaxLength="9" CharacterCasing="Upper" Height="23" TextWrapping="Wrap" Width="350" TextChanged="ColorHexTextBox_TextChanged" RenderTransformOrigin="0.5,0.5" VerticalContentAlignment="Center">
<materialDesign:TextFieldAssist.CharacterCounterStyle>
<Style TargetType="TextBlock" />
</materialDesign:TextFieldAssist.CharacterCounterStyle>
</TextBox>
</StackPanel>
<StackPanel Orientation="Horizontal" HorizontalAlignment="Right" Margin="0,10,0,0">
<Button x:Name="okButton" Content="{DynamicResource ok }" HorizontalAlignment="Left" Margin="0,0,10,0" VerticalAlignment="Top" Width="100" Click="OkButton_Click" Cursor="Hand"/>
<Button x:Name="cancelButton" Content="{DynamicResource cancel }" HorizontalAlignment="Left" Margin="0,0,0,0" VerticalAlignment="Top" Width="100" Click="CancelButton_Click"/>
</StackPanel>
</StackPanel>
</Grid>
</Window>
@@ -0,0 +1,130 @@
using DesktopMagic.Helpers;
using System;
using System.Threading;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Media;
namespace DesktopMagic.Dialogs
{
/// <summary>
/// Interaction logic for ColorDialog.xaml
/// </summary>
public partial class ColorDialog : Window
{
public ColorDialog(string content, System.Drawing.Color defaultColor, string title = "ColorDialog")
{
InitializeComponent();
label.Content = content;
Title = title;
SetLanguageDictionary();
alphaSlider.Value = defaultColor.A;
redSlider.Value = defaultColor.R;
greenSlider.Value = defaultColor.G;
blueSlider.Value = defaultColor.B;
}
public System.Drawing.Color ResultColor { get; private set; }
public Brush ResultBrush { get; private set; }
private void OkButton_Click(object sender, RoutedEventArgs e)
{
DialogResult = true;
}
private void CancelButton_Click(object sender, RoutedEventArgs e)
{
DialogResult = false;
}
private void ColorSliders_ValueChanged(object sender, RoutedPropertyChangedEventArgs<double> e)
{
colorHexTextBox.Select(colorHexTextBox.Text.Length, 0);
SetColorText();
}
private void ColorHexTextBox_TextChanged(object sender, TextChangedEventArgs e)
{
if (colorHexTextBox.Text.Length > 0)
{
if (colorHexTextBox.Text.ToCharArray()[0] != '#')
{
colorHexTextBox.Text = "#" + colorHexTextBox.Text.Replace("#", "");
}
}
else
{
colorHexTextBox.Text = "#";
colorHexTextBox.Select(colorHexTextBox.Text.Length, 0);
}
if (colorHexTextBox.SelectionStart == 0)
{
if (colorHexTextBox.Text.Length <= 2)
{
colorHexTextBox.Select(colorHexTextBox.Text.Length, 0);
}
else
{
colorHexTextBox.Select(1, 0);
}
}
string hex = colorHexTextBox.Text;
if (MultiColorConverter.TryConvertToMediaColor(hex, out Color color) && MultiColorConverter.TryConvertToSystemColor(hex, out System.Drawing.Color systemColor))
{
alphaSlider.Value = color.A;
redSlider.Value = color.R;
greenSlider.Value = color.G;
blueSlider.Value = color.B;
Brush brush = new SolidColorBrush(color);
ResultBrush = brush;
ResultColor = systemColor;
colorRechtangle.Fill = brush;
colorHexTextBox.Foreground = Brushes.Black;
return;
}
else
{
colorHexTextBox.Foreground = Brushes.Red;
}
}
private void SetColorText()
{
if (alphaSlider.Value == 255)
{
colorHexTextBox.Text = "#";
}
else
{
colorHexTextBox.Text = "#" + ((int)alphaSlider.Value).ToString("X2");
}
colorHexTextBox.Text += ((int)redSlider.Value).ToString("X2") + ((int)greenSlider.Value).ToString("X2") + ((int)blueSlider.Value).ToString("X2");
}
private void SetLanguageDictionary()
{
ResourceDictionary dict = new ResourceDictionary();
string currentCulture = Thread.CurrentThread.CurrentCulture.ToString();
if (currentCulture.Contains("de"))
{
dict.Source = new Uri("..\\Resources\\StringResources.de.xaml", UriKind.Relative);
}
else
{
dict.Source = new Uri("..\\Resources\\StringResources.en.xaml", UriKind.Relative);
}
Resources.MergedDictionaries.Add(dict);
}
}
}
@@ -1,16 +1,17 @@
<Window x:Class="DesktopMagic.InputDialog"
<Window x:Class="DesktopMagic.Dialogs.InputDialog"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
xmlns:local="clr-namespace:DesktopMagic"
xmlns:local="clr-namespace:DesktopMagic.Dialogs"
mc:Ignorable="d"
Title="InputDialog" Height="152.812" Width="322.812"
ResizeMode="NoResize">
Title="InputDialog"
ResizeMode="NoResize"
SizeToContent="WidthAndHeight">
<Grid>
<StackPanel VerticalAlignment="Center" HorizontalAlignment="Center" Margin="10">
<StackPanel VerticalAlignment="Center" HorizontalAlignment="Center" Margin="15">
<Label x:Name="label" Content="Label" HorizontalAlignment="Left" VerticalAlignment="Top"/>
<TextBox x:Name="textBox" HorizontalAlignment="Left" Height="23" TextWrapping="Wrap" VerticalAlignment="Top" Width="279" VerticalContentAlignment="Center"/>
<TextBox x:Name="textBox" HorizontalAlignment="Left" Height="23" TextWrapping="Wrap" VerticalAlignment="Top" Width="280" VerticalContentAlignment="Center"/>
<StackPanel Orientation="Horizontal" HorizontalAlignment="Right" Margin="0,10,0,0">
<Button x:Name="okButton" Content="{DynamicResource ok }" HorizontalAlignment="Left" Margin="0,0,10,0" VerticalAlignment="Top" Width="100" Click="OkButton_Click" Cursor="Hand"/>
<Button x:Name="cancelButton" Content="{DynamicResource cancel }" HorizontalAlignment="Left" Margin="0,0,0,0" VerticalAlignment="Top" Width="100" Click="CancelButton_Click"/>
@@ -2,7 +2,7 @@
using System.Threading;
using System.Windows;
namespace DesktopMagic
namespace DesktopMagic.Dialogs
{
public partial class InputDialog : Window
{
@@ -0,0 +1,76 @@
using System.Globalization;
using System.Text.RegularExpressions;
namespace DesktopMagic.Helpers
{
internal static class MultiColorConverter
{
public static string ConvertToHex(System.Drawing.Color color)
{
return $"#{color.A:X2}{color.R:X2}{color.G:X2}{color.B:X2}";
}
public static string ConvertToHex(System.Windows.Media.Color color)
{
return $"#{color.A:X2}{color.R:X2}{color.G:X2}{color.B:X2}";
}
public static bool TryConvertToSystemColor(string hex, out System.Drawing.Color color)
{
hex = hex.Replace("#", "");
if (hex.Length == 8 && Regex.IsMatch(hex, "(?:[0-9a-fA-F]{8})"))
{
int a = int.Parse(hex.Substring(0, 2), NumberStyles.HexNumber, CultureInfo.InvariantCulture);
int r = int.Parse(hex.Substring(2, 2), NumberStyles.HexNumber, CultureInfo.InvariantCulture);
int g = int.Parse(hex.Substring(4, 2), NumberStyles.HexNumber, CultureInfo.InvariantCulture);
int b = int.Parse(hex.Substring(6, 2), NumberStyles.HexNumber, CultureInfo.InvariantCulture);
color = System.Drawing.Color.FromArgb((byte)a, (byte)r, (byte)g, (byte)b);
return true;
}
else if (hex.Length == 6 && Regex.IsMatch(hex, "(?:[0-9a-fA-F]{6})"))
{
int a = 255;
int r = int.Parse(hex.Substring(0, 2), NumberStyles.HexNumber, CultureInfo.InvariantCulture);
int g = int.Parse(hex.Substring(2, 2), NumberStyles.HexNumber, CultureInfo.InvariantCulture);
int b = int.Parse(hex.Substring(4, 2), NumberStyles.HexNumber, CultureInfo.InvariantCulture);
color = System.Drawing.Color.FromArgb((byte)a, (byte)r, (byte)g, (byte)b);
return true;
}
else
{
color = System.Drawing.Color.Transparent;
return false;
}
}
public static bool TryConvertToMediaColor(string hex, out System.Windows.Media.Color color)
{
hex = hex.Replace("#", "");
if (hex.Length == 8 && Regex.IsMatch(hex, "(?:[0-9a-fA-F]{8})"))
{
int a = int.Parse(hex.Substring(0, 2), NumberStyles.HexNumber, CultureInfo.InvariantCulture);
int r = int.Parse(hex.Substring(2, 2), NumberStyles.HexNumber, CultureInfo.InvariantCulture);
int g = int.Parse(hex.Substring(4, 2), NumberStyles.HexNumber, CultureInfo.InvariantCulture);
int b = int.Parse(hex.Substring(6, 2), NumberStyles.HexNumber, CultureInfo.InvariantCulture);
color = System.Windows.Media.Color.FromArgb((byte)a, (byte)r, (byte)g, (byte)b);
return true;
}
else if (hex.Length == 6 && Regex.IsMatch(hex, "(?:[0-9a-fA-F]{6})"))
{
int a = 255;
int r = int.Parse(hex.Substring(0, 2), NumberStyles.HexNumber, CultureInfo.InvariantCulture);
int g = int.Parse(hex.Substring(2, 2), NumberStyles.HexNumber, CultureInfo.InvariantCulture);
int b = int.Parse(hex.Substring(4, 2), NumberStyles.HexNumber, CultureInfo.InvariantCulture);
color = System.Windows.Media.Color.FromArgb((byte)a, (byte)r, (byte)g, (byte)b);
return true;
}
else
{
color = System.Windows.Media.Colors.Transparent;
return false;
}
}
}
}
@@ -0,0 +1,25 @@
using System.Globalization;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Media;
namespace DesktopMagic.Helpers
{
internal static class StringUtilities
{
public static Size MeasureString(string input, TextBlock element)
{
FormattedText formattedText = new FormattedText(
input,
CultureInfo.CurrentCulture,
FlowDirection.LeftToRight,
new Typeface(element.FontFamily, element.FontStyle, element.FontWeight, element.FontStretch),
element.FontSize,
Brushes.Black,
new NumberSubstitution(),
1);
return new Size(formattedText.Width, formattedText.Height);
}
}
}
+22 -13
View File
@@ -38,7 +38,8 @@
<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"/> <!--Currently disabled because it's not working-->
<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>
</ScrollViewer>
@@ -73,9 +74,9 @@
<RowDefinition Height="*" />
<RowDefinition Height="110" />
</Grid.RowDefinitions>
<StackPanel DockPanel.Dock="Top" Margin="{StaticResource DefaultMargin}">
<ComboBox x:Name="fontComboBox" HorizontalAlignment="Left" VerticalAlignment="Top" Width="181" SelectionChanged="FontComboBox_SelectionChanged" Margin="0,0,0,5" />
<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" />
@@ -88,17 +89,25 @@
<Label Content="B:" Width="20" />
<Slider x:Name="blueSlider" Maximum="255" ValueChanged="ColorSliders_ValueChanged" TickFrequency="1" IsSnapToTickEnabled="True" Background="#000000FF" />
</DockPanel>
<StackPanel Orientation="Horizontal">
-->
<DockPanel Margin="0,0,0,5" Width="200">
<Border CornerRadius="1" BorderThickness="1.5" BorderBrush="Gray" Height="23" Width="23" Margin="0,0,5,0">
<Rectangle x:Name="colorRechtangle" Fill="White" />
<Rectangle x:Name="primaryColorRechtangle" Fill="White" />
</Border>
<TextBox x:Name="colorHexTextBox" MaxLength="7" CharacterCasing="Upper" Height="23" TextWrapping="Wrap" Text="colorHexTextBox" Width="120" TextChanged="ColorHexTextBox_TextChanged" RenderTransformOrigin="0.5,0.5" VerticalContentAlignment="Center">
<materialDesign:TextFieldAssist.CharacterCounterStyle>
<Style TargetType="TextBlock" />
</materialDesign:TextFieldAssist.CharacterCounterStyle>
</TextBox>
</StackPanel>
<Button Content="Change Primary Color" Height="23" FontSize="10" 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">
<Rectangle x:Name="secondaryColorRechtangle" Fill="White" />
</Border>
<Button Content="Change Secondary Color" Height="23" FontSize="10" Click="ChangeSecondaryColorButton_Click" />
</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="10" Click="ChangeBackgroundColorButton_Click" />
</DockPanel>
</StackPanel>
<Grid Grid.Row="1" VerticalAlignment="Bottom">
<Grid.ColumnDefinitions>
+84 -70
View File
@@ -1,4 +1,6 @@
using DesktopMagic.Plugins;
using DesktopMagic.Dialogs;
using DesktopMagic.Helpers;
using DesktopMagic.Plugins;
using Microsoft.Win32;
@@ -66,7 +68,12 @@ namespace DesktopMagic
InitializeComponent();
SetLanguageDictionary();
#if DEBUG
Title = $"{App.AppName} - Dev {Assembly.GetExecutingAssembly().GetName().Version}";
#else
Title = $"{App.AppName} - {Assembly.GetExecutingAssembly().GetName().Version}";
#endif
}
catch (Exception ex)
{
@@ -205,12 +212,6 @@ namespace DesktopMagic
window = new CpuUsageWindow();
break;
/*
case "CalendarCb":
window = new CalendarWindow();
break;
*/
case "MusicVisualizerCb":
window = new MusicVisualizerWindow();
break;
@@ -391,13 +392,20 @@ namespace DesktopMagic
string hex = musicVisualizerColorTextBox.Text;
hex = hex.Replace("#", "");
System.Drawing.Color systemColor = System.Drawing.Color.FromArgb((byte)int.Parse(hex.Substring(0, 2), System.Globalization.NumberStyles.HexNumber), (byte)int.Parse(hex.Substring(2, 2), System.Globalization.NumberStyles.HexNumber), (byte)int.Parse(hex.Substring(4, 2), System.Globalization.NumberStyles.HexNumber));
if (hex.Length == 6)
{
System.Drawing.Color systemColor = System.Drawing.Color.FromArgb((byte)int.Parse(hex.Substring(0, 2), System.Globalization.NumberStyles.HexNumber), (byte)int.Parse(hex.Substring(2, 2), System.Globalization.NumberStyles.HexNumber), (byte)int.Parse(hex.Substring(4, 2), System.Globalization.NumberStyles.HexNumber));
MusicVisualzerColor = systemColor;
musicVisualizerColorTextBox.Foreground = Brushes.Black;
MusicVisualzerColor = systemColor;
musicVisualizerColorTextBox.Foreground = Brushes.Black;
key.SetValue("MusicVisualizerColor", musicVisualizerColorTextBox.Text);
SaveLayout();
key.SetValue("MusicVisualizerColor", musicVisualizerColorTextBox.Text);
SaveLayout();
}
else
{
musicVisualizerColorTextBox.Foreground = Brushes.Red;
}
}
catch
{
@@ -445,8 +453,8 @@ namespace DesktopMagic
optionsPanel.Children.Clear();
optionsPanel.UpdateLayout();
bool succ = PluginsSettings.TryGetValue(((Tuple<string, int>)optionsComboBox.SelectedItem).Item1.ToString(), out List<SettingElement> settingElements);
if (!succ || settingElements?.Count == 0)
bool success = PluginsSettings.TryGetValue(((Tuple<string, int>)optionsComboBox.SelectedItem).Item1.ToString(), out List<SettingElement> settingElements);
if (!success || settingElements?.Count == 0)
{
_ = optionsPanel.Children.Add(new TextBlock() { Text = (string)FindResource("noOptions") });
return;
@@ -686,69 +694,52 @@ namespace DesktopMagic
}
}
#region color
private void ColorSliders_ValueChanged(object sender, RoutedPropertyChangedEventArgs<double> e)
{
colorHexTextBox.Text = "#" + ((int)redSlider.Value).ToString("X2") + ((int)greenSlider.Value).ToString("X2") + ((int)blueSlider.Value).ToString("X2");
colorHexTextBox.Select(colorHexTextBox.Text.Length, 0);
}
private void ColorHexTextBox_TextChanged(object sender, TextChangedEventArgs e)
{
try
}
private void ChangePrimaryColorButton_Click(object sender, RoutedEventArgs e)
{
ColorDialog colorDialog = new ColorDialog("Set Primary Color", Theme.PrimaryColor);
if (colorDialog.ShowDialog() == true)
{
if (colorHexTextBox.Text.Length > 0)
{
if (colorHexTextBox.Text.ToCharArray()[0] != '#')
{
colorHexTextBox.Text = "#" + colorHexTextBox.Text.Replace("#", "");
}
}
else
{
colorHexTextBox.Text = "#";
colorHexTextBox.Select(colorHexTextBox.Text.Length, 0);
}
Theme.PrimaryBrush = colorDialog.ResultBrush;
Theme.PrimaryColor = colorDialog.ResultColor;
primaryColorRechtangle.Fill = colorDialog.ResultBrush;
if (colorHexTextBox.SelectionStart == 0)
{
if (colorHexTextBox.Text.Length <= 2)
{
colorHexTextBox.Select(colorHexTextBox.Text.Length, 0);
}
else
{
colorHexTextBox.Select(1, 0);
}
}
string hex = colorHexTextBox.Text;
hex = hex.Replace("#", "");
Color color = Color.FromRgb((byte)int.Parse(hex.Substring(0, 2), System.Globalization.NumberStyles.HexNumber), (byte)int.Parse(hex.Substring(2, 2), System.Globalization.NumberStyles.HexNumber), (byte)int.Parse(hex.Substring(4, 2), System.Globalization.NumberStyles.HexNumber));
System.Drawing.Color systemColor = System.Drawing.Color.FromArgb((byte)int.Parse(hex.Substring(0, 2), System.Globalization.NumberStyles.HexNumber), (byte)int.Parse(hex.Substring(2, 2), System.Globalization.NumberStyles.HexNumber), (byte)int.Parse(hex.Substring(4, 2), System.Globalization.NumberStyles.HexNumber));
redSlider.Value = color.R;
greenSlider.Value = color.G;
blueSlider.Value = color.B;
Brush brush = new SolidColorBrush(color);
Theme.PrimaryBrush = brush;
Theme.PrimaryColor = systemColor;
colorRechtangle.Fill = brush;
colorHexTextBox.Foreground = Brushes.Black;
key.SetValue("Color", colorHexTextBox.Text);
key.SetValue("PrimaryColor", MultiColorConverter.ConvertToHex(Theme.PrimaryColor));
SaveLayout();
}
catch
{
colorHexTextBox.Foreground = Brushes.Red;
}
}
#endregion color
private void ChangeSecondaryColorButton_Click(object sender, RoutedEventArgs e)
{
ColorDialog colorDialog = new ColorDialog("Set Secondary Color", Theme.SecondaryColor);
if (colorDialog.ShowDialog() == true)
{
Theme.SecondaryBrush = colorDialog.ResultBrush;
Theme.SecondaryColor = colorDialog.ResultColor;
secondaryColorRechtangle.Fill = colorDialog.ResultBrush;
key.SetValue("SecondaryColor", MultiColorConverter.ConvertToHex(Theme.SecondaryColor));
SaveLayout();
}
}
private void ChangeBackgroundColorButton_Click(object sender, RoutedEventArgs e)
{
ColorDialog colorDialog = new ColorDialog("Set Background Color", Theme.BackgroundColor);
if (colorDialog.ShowDialog() == true)
{
Theme.BackgroundBrush = colorDialog.ResultBrush;
Theme.BackgroundColor = colorDialog.ResultColor;
backgroundColorRechtangle.Fill = colorDialog.ResultBrush;
key.SetValue("BackgroundColor", MultiColorConverter.ConvertToHex(Theme.BackgroundColor));
SaveLayout();
}
}
#region Layout
@@ -867,9 +858,32 @@ 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();
colorHexTextBox.Text = key.GetValue("Color", "#FFFFFF").ToString();
blockWindowsClosing = false;
string primaryColorHex = key.GetValue("PrimaryColor", "#FFFFFFFF").ToString();
string secondaryColorHex = key.GetValue("SecondaryColor", "#FFFFFFFF").ToString();
string backgroundColorHex = key.GetValue("BackgroundColor", "#00FFFFFF").ToString();
_ = MultiColorConverter.TryConvertToSystemColor(primaryColorHex, out System.Drawing.Color primarySystemColor);
_ = MultiColorConverter.TryConvertToMediaColor(primaryColorHex, out Color primaryMediaColor);
_ = MultiColorConverter.TryConvertToSystemColor(secondaryColorHex, out System.Drawing.Color secondarySystemColor);
_ = MultiColorConverter.TryConvertToMediaColor(secondaryColorHex, out Color secondaryMediaColor);
_ = MultiColorConverter.TryConvertToSystemColor(backgroundColorHex, out System.Drawing.Color backgroundSystemColor);
_ = MultiColorConverter.TryConvertToMediaColor(backgroundColorHex, out Color backgroundMediaColor);
Theme.PrimaryColor = primarySystemColor;
Theme.PrimaryBrush = new SolidColorBrush(primaryMediaColor);
Theme.SecondaryColor = secondarySystemColor;
Theme.SecondaryBrush = new SolidColorBrush(secondaryMediaColor);
Theme.BackgroundColor = backgroundSystemColor;
Theme.BackgroundBrush = new SolidColorBrush(backgroundMediaColor);
primaryColorRechtangle.Fill = Theme.PrimaryBrush;
secondaryColorRechtangle.Fill = Theme.SecondaryBrush;
backgroundColorRechtangle.Fill = Theme.BackgroundBrush;
MusicVisualizerColorTextBox_TextChanged(null, null);
MirrorModeCheckBox_Click(null, null);
LineModeCheckBox_Click(null, null);
+3 -1
View File
@@ -17,7 +17,9 @@
<Grid>
<Rectangle x:Name="panel" Fill="#4CBAFFEF" Stroke="White" Margin="0,0,0,0" Visibility="Collapsed" />
<Viewbox StretchDirection="Both" Stretch="Uniform">
<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 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>
</Viewbox>
</Grid>
<WindowChrome.WindowChrome>
@@ -115,6 +115,10 @@ namespace DesktopMagic
{
((System.Timers.Timer)sender).Stop();
}
else
{
backgroundGrid.Background = MainWindow.Theme.BackgroundBrush;
}
});
}
+5 -2
View File
@@ -6,13 +6,16 @@ namespace DesktopMagic.Plugins
{
internal class Theme : ITheme
{
public Color PrimaryColor { get; internal set; } = Color.White;
public Color PrimaryColor { get; set; } = Color.White;
public Color SecondaryColor { get; internal 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 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 BackgroundBrush { get; set; } = System.Windows.Media.Brushes.Transparent;
}
}
@@ -4,13 +4,13 @@
<TargetFramework>net5.0</TargetFramework>
<Company>Stone_Red</Company>
<Product>Stone_Red</Product>
<Version>0.0.0.4</Version>
<Version>0.0.0.5</Version>
<RepositoryUrl>https://github.com/Stone-Red-Code/DesktopMagic</RepositoryUrl>
<PackageLicenseFile>LICENSE</PackageLicenseFile>
<GeneratePackageOnBuild>true</GeneratePackageOnBuild>
<AssemblyVersion>0.0.0.4</AssemblyVersion>
<AssemblyVersion>0.0.0.5</AssemblyVersion>
<PackageProjectUrl></PackageProjectUrl>
<FileVersion>0.0.0.4</FileVersion>
<FileVersion>0.0.0.5</FileVersion>
</PropertyGroup>
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|AnyCPU'">
@@ -33,6 +33,7 @@
- [WindowSize](#P-DesktopMagicPluginAPI-IPluginData-WindowSize 'DesktopMagicPluginAPI.IPluginData.WindowSize')
- [UpdateWindow()](#M-DesktopMagicPluginAPI-IPluginData-UpdateWindow 'DesktopMagicPluginAPI.IPluginData.UpdateWindow')
- [ITheme](#T-DesktopMagicPluginAPI-ITheme 'DesktopMagicPluginAPI.ITheme')
- [BackgroundColor](#P-DesktopMagicPluginAPI-ITheme-BackgroundColor 'DesktopMagicPluginAPI.ITheme.BackgroundColor')
- [Font](#P-DesktopMagicPluginAPI-ITheme-Font 'DesktopMagicPluginAPI.ITheme.Font')
- [PrimaryColor](#P-DesktopMagicPluginAPI-ITheme-PrimaryColor 'DesktopMagicPluginAPI.ITheme.PrimaryColor')
- [SecondaryColor](#P-DesktopMagicPluginAPI-ITheme-SecondaryColor 'DesktopMagicPluginAPI.ITheme.SecondaryColor')
@@ -394,6 +395,13 @@ DesktopMagicPluginAPI
The theme settings of the main application.
<a name='P-DesktopMagicPluginAPI-ITheme-BackgroundColor'></a>
### BackgroundColor `property`
##### Summary
Gets the background color of the main application.
<a name='P-DesktopMagicPluginAPI-ITheme-Font'></a>
### Font `property`
@@ -336,6 +336,11 @@
Gets the secondary color of the main application.
</summary>
</member>
<member name="P:DesktopMagicPluginAPI.ITheme.BackgroundColor">
<summary>
Gets the background color of the main application.
</summary>
</member>
<member name="P:DesktopMagicPluginAPI.ITheme.Font">
<summary>
Gets the font of the main application.
+5
View File
@@ -17,6 +17,11 @@ namespace DesktopMagicPluginAPI
/// </summary>
Color SecondaryColor { get; }
/// <summary>
/// Gets the background color of the main application.
/// </summary>
Color BackgroundColor { get; }
/// <summary>
/// Gets the font of the main application.
/// </summary>