mirror of
https://github.com/Stone-Red-Code/DesktopMagic.git
synced 2026-09-04 00:46:12 +02:00
Fix built in plugins and some UI issues
This commit is contained in:
@@ -9,8 +9,6 @@ Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "DesktopMagic.Api", "Desktop
|
|||||||
EndProject
|
EndProject
|
||||||
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "DesktopMagic.PluginTest", "DesktopMagicPlugin.Test\DesktopMagic.PluginTest.csproj", "{EF8407AB-28AE-4B5E-AC2E-D4C4A575FBC7}"
|
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "DesktopMagic.PluginTest", "DesktopMagicPlugin.Test\DesktopMagic.PluginTest.csproj", "{EF8407AB-28AE-4B5E-AC2E-D4C4A575FBC7}"
|
||||||
EndProject
|
EndProject
|
||||||
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "DesktopMagic.Installer", "DesktopMagic.Installer\DesktopMagic.Installer.csproj", "{A06BD685-7F92-4799-846B-3EC38345108E}"
|
|
||||||
EndProject
|
|
||||||
Global
|
Global
|
||||||
GlobalSection(SolutionConfigurationPlatforms) = preSolution
|
GlobalSection(SolutionConfigurationPlatforms) = preSolution
|
||||||
Debug|Any CPU = Debug|Any CPU
|
Debug|Any CPU = Debug|Any CPU
|
||||||
@@ -29,10 +27,6 @@ Global
|
|||||||
{EF8407AB-28AE-4B5E-AC2E-D4C4A575FBC7}.Debug|Any CPU.Build.0 = Debug|Any CPU
|
{EF8407AB-28AE-4B5E-AC2E-D4C4A575FBC7}.Debug|Any CPU.Build.0 = Debug|Any CPU
|
||||||
{EF8407AB-28AE-4B5E-AC2E-D4C4A575FBC7}.Release|Any CPU.ActiveCfg = Release|Any CPU
|
{EF8407AB-28AE-4B5E-AC2E-D4C4A575FBC7}.Release|Any CPU.ActiveCfg = Release|Any CPU
|
||||||
{EF8407AB-28AE-4B5E-AC2E-D4C4A575FBC7}.Release|Any CPU.Build.0 = Release|Any CPU
|
{EF8407AB-28AE-4B5E-AC2E-D4C4A575FBC7}.Release|Any CPU.Build.0 = Release|Any CPU
|
||||||
{A06BD685-7F92-4799-846B-3EC38345108E}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
|
|
||||||
{A06BD685-7F92-4799-846B-3EC38345108E}.Debug|Any CPU.Build.0 = Debug|Any CPU
|
|
||||||
{A06BD685-7F92-4799-846B-3EC38345108E}.Release|Any CPU.ActiveCfg = Release|Any CPU
|
|
||||||
{A06BD685-7F92-4799-846B-3EC38345108E}.Release|Any CPU.Build.0 = Release|Any CPU
|
|
||||||
EndGlobalSection
|
EndGlobalSection
|
||||||
GlobalSection(SolutionProperties) = preSolution
|
GlobalSection(SolutionProperties) = preSolution
|
||||||
HideSolutionNode = FALSE
|
HideSolutionNode = FALSE
|
||||||
|
|||||||
@@ -0,0 +1,60 @@
|
|||||||
|
using DesktopMagic.Api;
|
||||||
|
using DesktopMagic.Api.Settings;
|
||||||
|
|
||||||
|
using System.Diagnostics;
|
||||||
|
using System.Drawing;
|
||||||
|
using System.Drawing.Text;
|
||||||
|
|
||||||
|
using SettingAttribute = DesktopMagic.Api.Settings.SettingAttribute;
|
||||||
|
|
||||||
|
namespace DesktopMagic.BuiltInWindowElements;
|
||||||
|
|
||||||
|
internal class CpuMonitorPlugin : Plugin
|
||||||
|
{
|
||||||
|
private readonly PerformanceCounter cpuCounter = new PerformanceCounter("Processor Information", "% Processor Utility", "_Total");
|
||||||
|
|
||||||
|
[Setting("usage-circle", "Show pie")]
|
||||||
|
private readonly CheckBox usageCircleCheckBox = new CheckBox(false);
|
||||||
|
|
||||||
|
public override int UpdateInterval => 1000;
|
||||||
|
|
||||||
|
public override Bitmap Main()
|
||||||
|
{
|
||||||
|
float cpuUsage = cpuCounter.NextValue();
|
||||||
|
|
||||||
|
string cpuUsageString = $"{cpuUsage:000}%";
|
||||||
|
|
||||||
|
Font font = new Font(Application.Theme.Font, 200);
|
||||||
|
|
||||||
|
Bitmap bmp = new Bitmap(1, 1);
|
||||||
|
bmp.SetResolution(100, 100);
|
||||||
|
using Graphics tmpGr = Graphics.FromImage(bmp);
|
||||||
|
tmpGr.TextRenderingHint = TextRenderingHint.AntiAlias;
|
||||||
|
|
||||||
|
SizeF size = tmpGr.MeasureString(cpuUsageString, font);
|
||||||
|
|
||||||
|
bmp = new Bitmap((int)size.Width, usageCircleCheckBox.Value ? (int)size.Width : (int)size.Height);
|
||||||
|
bmp.SetResolution(100, 100);
|
||||||
|
|
||||||
|
using Graphics gr = Graphics.FromImage(bmp);
|
||||||
|
|
||||||
|
gr.TextRenderingHint = TextRenderingHint.AntiAlias;
|
||||||
|
|
||||||
|
if (usageCircleCheckBox.Value)
|
||||||
|
{
|
||||||
|
gr.FillPie(new SolidBrush(Application.Theme.SecondaryColor), 0, 0, size.Width, size.Width, 0, 360f / 100f * cpuUsage);
|
||||||
|
|
||||||
|
gr.DrawArc(new Pen(Color.FromArgb(Application.Theme.PrimaryColor.A, Color.Green), 10), 5, 5, size.Width - 10, size.Width - 10, 0, 120);
|
||||||
|
gr.DrawArc(new Pen(Color.FromArgb(Application.Theme.PrimaryColor.A, Color.Orange), 10), 5, 5, size.Width - 10, size.Width - 10, 120, 120);
|
||||||
|
gr.DrawArc(new Pen(Color.FromArgb(Application.Theme.PrimaryColor.A, Color.Red), 10), 5, 5, size.Width - 10, size.Width - 10, 240, 120);
|
||||||
|
|
||||||
|
gr.DrawString(cpuUsageString, font, new SolidBrush(Application.Theme.PrimaryColor), 0, (size.Width / 2) - (size.Height / 2));
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
gr.DrawString(cpuUsageString, font, new SolidBrush(Application.Theme.PrimaryColor), 0, (size.Width / 2) - size.Height);
|
||||||
|
}
|
||||||
|
|
||||||
|
return bmp;
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -1,31 +0,0 @@
|
|||||||
<Window x:Class="DesktopMagic.CpuUsageWindow"
|
|
||||||
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
|
|
||||||
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
|
|
||||||
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
|
|
||||||
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
|
|
||||||
mc:Ignorable="d"
|
|
||||||
Title="CpuUsageWindow" Height="450" Width="800"
|
|
||||||
Background="Transparent"
|
|
||||||
WindowStyle="None"
|
|
||||||
AllowsTransparency="True"
|
|
||||||
LocationChanged="Window_LocationChanged"
|
|
||||||
SizeChanged="Window_SizeChanged"
|
|
||||||
ShowActivated="False"
|
|
||||||
x:Name="window">
|
|
||||||
<Grid>
|
|
||||||
<Rectangle x:Name="panel" Fill="#4CBAFFEF" Stroke="White" Margin="0,0,0,0" Visibility="Collapsed" />
|
|
||||||
<Border x:Name="border"/>
|
|
||||||
<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" Foreground="White" FontSize="100" Text="CPU: " IsHitTestVisible="False" />
|
|
||||||
<TextBlock x:Name="valueTextBlock" TextAlignment="Right" FontSize="100" Foreground="White" Text="000%" IsHitTestVisible="False" />
|
|
||||||
</DockPanel>
|
|
||||||
</Viewbox>
|
|
||||||
</Grid>
|
|
||||||
<WindowChrome.WindowChrome>
|
|
||||||
<WindowChrome x:Name="tileBar" CaptionHeight="3000" ResizeBorderThickness="{x:Static SystemParameters.WindowResizeBorderThickness}" />
|
|
||||||
</WindowChrome.WindowChrome>
|
|
||||||
</Window>
|
|
||||||
@@ -1,146 +0,0 @@
|
|||||||
using DesktopMagic.Helpers;
|
|
||||||
|
|
||||||
using Microsoft.Win32;
|
|
||||||
|
|
||||||
using System;
|
|
||||||
using System.Diagnostics;
|
|
||||||
using System.Timers;
|
|
||||||
using System.Windows;
|
|
||||||
using System.Windows.Interop;
|
|
||||||
using System.Windows.Media;
|
|
||||||
using System.Windows.Threading;
|
|
||||||
|
|
||||||
namespace DesktopMagic;
|
|
||||||
|
|
||||||
public partial class CpuUsageWindow : Window
|
|
||||||
{
|
|
||||||
private readonly RegistryKey key;
|
|
||||||
private readonly PerformanceCounter cpuCounter = new PerformanceCounter();
|
|
||||||
|
|
||||||
public CpuUsageWindow()
|
|
||||||
{
|
|
||||||
InitializeComponent();
|
|
||||||
|
|
||||||
Window w = new()
|
|
||||||
{
|
|
||||||
Top = -100,
|
|
||||||
Left = -100,
|
|
||||||
Width = 0,
|
|
||||||
Height = 0,
|
|
||||||
|
|
||||||
WindowStyle = WindowStyle.ToolWindow,
|
|
||||||
ShowInTaskbar = false
|
|
||||||
};
|
|
||||||
w.Show();
|
|
||||||
Owner = w;
|
|
||||||
w.Hide();
|
|
||||||
|
|
||||||
cpuCounter.CategoryName = "Processor";
|
|
||||||
cpuCounter.CounterName = "% Processor Time";
|
|
||||||
cpuCounter.InstanceName = "_Total";
|
|
||||||
|
|
||||||
Timer t = new Timer
|
|
||||||
{
|
|
||||||
Interval = 100
|
|
||||||
};
|
|
||||||
t.Elapsed += UpdateTimer_Elapsed;
|
|
||||||
t.Start();
|
|
||||||
|
|
||||||
Timer valueTimer = new Timer
|
|
||||||
{
|
|
||||||
Interval = 1000
|
|
||||||
};
|
|
||||||
valueTimer.Elapsed += ValueTimer_Elapsed;
|
|
||||||
|
|
||||||
valueTimer.Start();
|
|
||||||
|
|
||||||
key = Registry.CurrentUser.CreateSubKey(@"Software\" + App.AppName);
|
|
||||||
Top = double.Parse(key.GetValue("CpuUsageWindowTop", 100).ToString());
|
|
||||||
Left = double.Parse(key.GetValue("CpuUsageWindowLeft", 100).ToString());
|
|
||||||
Height = double.Parse(key.GetValue("CpuUsageWindowHeight", 200).ToString());
|
|
||||||
Width = double.Parse(key.GetValue("CpuUsageWindowWidth", 500).ToString());
|
|
||||||
IsEnabled = false;
|
|
||||||
}
|
|
||||||
|
|
||||||
protected override void OnSourceInitialized(EventArgs e)
|
|
||||||
{
|
|
||||||
base.OnSourceInitialized(e);
|
|
||||||
|
|
||||||
//Set the window style to noactivate.
|
|
||||||
WindowInteropHelper helper = new WindowInteropHelper(this);
|
|
||||||
_ = WindowPos.SetWindowLong(helper.Handle, WindowPos.GWL_EXSTYLE,
|
|
||||||
WindowPos.GetWindowLong(helper.Handle, WindowPos.GWL_EXSTYLE) | WindowPos.WS_EX_NOACTIVATE);
|
|
||||||
}
|
|
||||||
|
|
||||||
private void UpdateTimer_Elapsed(object sender, ElapsedEventArgs e)
|
|
||||||
{
|
|
||||||
Dispatcher.Invoke(() =>
|
|
||||||
{
|
|
||||||
if (MainWindow.EditMode)
|
|
||||||
{
|
|
||||||
panel.Visibility = Visibility.Visible;
|
|
||||||
tileBar.CaptionHeight = tileBar.CaptionHeight = ActualHeight - 10 < 0 ? 0 : ActualHeight - 10;
|
|
||||||
WindowPos.SetIsLocked(this, false);
|
|
||||||
ResizeMode = ResizeMode.CanResize;
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
panel.Visibility = Visibility.Collapsed;
|
|
||||||
tileBar.CaptionHeight = 0;
|
|
||||||
WindowPos.SetIsLocked(this, true);
|
|
||||||
ResizeMode = ResizeMode.NoResize;
|
|
||||||
}
|
|
||||||
|
|
||||||
rectangleGeometry.Rect = new Rect(0, 0, border.ActualWidth, border.ActualHeight);
|
|
||||||
border.Background = MainWindow.Theme.BackgroundBrush;
|
|
||||||
border.CornerRadius = new CornerRadius(MainWindow.Theme.CornerRadius);
|
|
||||||
viewBox.Margin = new Thickness(MainWindow.Theme.Margin);
|
|
||||||
border.Width = viewBox.ActualWidth + (MainWindow.Theme.Margin * 2);
|
|
||||||
border.Height = viewBox.ActualHeight + (MainWindow.Theme.Margin * 2);
|
|
||||||
textBlock.FontFamily = new FontFamily(MainWindow.Theme.Font);
|
|
||||||
textBlock.Foreground = MainWindow.Theme.PrimaryBrush;
|
|
||||||
valueTextBlock.FontFamily = new FontFamily(MainWindow.Theme.Font);
|
|
||||||
valueTextBlock.Foreground = MainWindow.Theme.PrimaryBrush;
|
|
||||||
|
|
||||||
ClculateWidth();
|
|
||||||
});
|
|
||||||
}
|
|
||||||
|
|
||||||
private void ValueTimer_Elapsed(object sender, ElapsedEventArgs e)
|
|
||||||
{
|
|
||||||
string cpuUsage = GetCpuUsage();
|
|
||||||
Dispatcher.Invoke(() =>
|
|
||||||
{
|
|
||||||
valueTextBlock.Text = cpuUsage;
|
|
||||||
});
|
|
||||||
}
|
|
||||||
|
|
||||||
private void ClculateWidth()
|
|
||||||
{
|
|
||||||
string template = "CPU: ###%";
|
|
||||||
double lenght = 0;
|
|
||||||
for (int i = 0; i < 9; i++)
|
|
||||||
{
|
|
||||||
lenght = Math.Max(StringUtilities.MeasureString(template.Replace('#', i.ToString()[0]), textBlock).Width, lenght);
|
|
||||||
}
|
|
||||||
dockPanel.Width = lenght;
|
|
||||||
}
|
|
||||||
|
|
||||||
private string GetCpuUsage()
|
|
||||||
{
|
|
||||||
return $"{(int)cpuCounter.NextValue()}%";
|
|
||||||
}
|
|
||||||
|
|
||||||
private void Window_LocationChanged(object sender, EventArgs e)
|
|
||||||
{
|
|
||||||
key.SetValue("CpuUsageWindowTop", Top);
|
|
||||||
key.SetValue("CpuUsageWindowLeft", Left);
|
|
||||||
}
|
|
||||||
|
|
||||||
private void Window_SizeChanged(object sender, SizeChangedEventArgs e)
|
|
||||||
{
|
|
||||||
key.SetValue("CpuUsageWindowHeight", Height);
|
|
||||||
key.SetValue("CpuUsageWindowWidth", Width);
|
|
||||||
tileBar.CaptionHeight = ActualHeight - 10;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@@ -12,8 +12,6 @@ internal class TimePlugin : Plugin
|
|||||||
[Setting("display-seconds", "Display Seconds")]
|
[Setting("display-seconds", "Display Seconds")]
|
||||||
private readonly CheckBox displaySecondsCheckBox = new CheckBox(true);
|
private readonly CheckBox displaySecondsCheckBox = new CheckBox(true);
|
||||||
|
|
||||||
private string? oldFont = null;
|
|
||||||
private float maxWidth = 0;
|
|
||||||
public override int UpdateInterval => 1000;
|
public override int UpdateInterval => 1000;
|
||||||
|
|
||||||
public override Bitmap Main()
|
public override Bitmap Main()
|
||||||
@@ -29,18 +27,7 @@ internal class TimePlugin : Plugin
|
|||||||
|
|
||||||
SizeF size = tmpGr.MeasureString(time, font);
|
SizeF size = tmpGr.MeasureString(time, font);
|
||||||
|
|
||||||
if (oldFont != Application.Theme.Font)
|
bmp = new Bitmap((int)size.Width, (int)size.Height);
|
||||||
{
|
|
||||||
oldFont = Application.Theme.Font;
|
|
||||||
maxWidth = 0;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (size.Width > maxWidth)
|
|
||||||
{
|
|
||||||
maxWidth = size.Width;
|
|
||||||
}
|
|
||||||
|
|
||||||
bmp = new Bitmap((int)maxWidth, (int)size.Height);
|
|
||||||
bmp.SetResolution(100, 100);
|
bmp.SetResolution(100, 100);
|
||||||
|
|
||||||
using Graphics gr = Graphics.FromImage(bmp);
|
using Graphics gr = Graphics.FromImage(bmp);
|
||||||
|
|||||||
@@ -20,25 +20,12 @@
|
|||||||
<DefineConstants>DEBUG;TRACE</DefineConstants>
|
<DefineConstants>DEBUG;TRACE</DefineConstants>
|
||||||
</PropertyGroup>
|
</PropertyGroup>
|
||||||
|
|
||||||
<ItemGroup>
|
|
||||||
<Compile Remove="BuiltInWindowElements\CpuUsageWindow.xaml.cs" />
|
|
||||||
</ItemGroup>
|
|
||||||
|
|
||||||
<ItemGroup>
|
<ItemGroup>
|
||||||
<None Remove="icon.ico" />
|
<None Remove="icon.ico" />
|
||||||
<None Remove="icons8_volunteering_26_85L_icon.ico" />
|
<None Remove="icons8_volunteering_26_85L_icon.ico" />
|
||||||
<None Remove="icon_Dark.ico" />
|
<None Remove="icon_Dark.ico" />
|
||||||
</ItemGroup>
|
</ItemGroup>
|
||||||
|
|
||||||
<ItemGroup>
|
|
||||||
<Page Remove="BuiltInWindowElements\CpuUsageWindow.xaml" />
|
|
||||||
</ItemGroup>
|
|
||||||
|
|
||||||
<ItemGroup>
|
|
||||||
<None Include="BuiltInWindowElements\CpuUsageWindow.xaml" />
|
|
||||||
<None Include="BuiltInWindowElements\CpuUsageWindow.xaml.cs" />
|
|
||||||
</ItemGroup>
|
|
||||||
|
|
||||||
<ItemGroup>
|
<ItemGroup>
|
||||||
<PackageReference Include="AlwaysUpToDate" Version="1.0.0.4" />
|
<PackageReference Include="AlwaysUpToDate" Version="1.0.0.4" />
|
||||||
<PackageReference Include="Extended.Wpf.Toolkit" Version="4.5.1" />
|
<PackageReference Include="Extended.Wpf.Toolkit" Version="4.5.1" />
|
||||||
|
|||||||
@@ -29,7 +29,8 @@ namespace DesktopMagic
|
|||||||
{
|
{
|
||||||
{"Music Visualizer", typeof(MusicVisualizerPlugin)},
|
{"Music Visualizer", typeof(MusicVisualizerPlugin)},
|
||||||
{"Time", typeof(TimePlugin)},
|
{"Time", typeof(TimePlugin)},
|
||||||
{"Date", typeof(DatePlugin)}
|
{"Date", typeof(DatePlugin)},
|
||||||
|
{"Cpu Usage", typeof(CpuMonitorPlugin)}
|
||||||
};
|
};
|
||||||
|
|
||||||
private bool loaded = false;
|
private bool loaded = false;
|
||||||
@@ -338,7 +339,8 @@ namespace DesktopMagic
|
|||||||
DockPanel dockPanel = new()
|
DockPanel dockPanel = new()
|
||||||
{
|
{
|
||||||
LastChildFill = true,
|
LastChildFill = true,
|
||||||
HorizontalAlignment = HorizontalAlignment.Stretch
|
HorizontalAlignment = HorizontalAlignment.Stretch,
|
||||||
|
Margin = new Thickness(0, 0, 0, 5)
|
||||||
};
|
};
|
||||||
_ = optionsPanel.Children.Add(dockPanel);
|
_ = optionsPanel.Children.Add(dockPanel);
|
||||||
|
|
||||||
|
|||||||
@@ -17,12 +17,14 @@
|
|||||||
<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" />
|
||||||
|
|
||||||
<Border x:Name="border"/>
|
<Border x:Name="border" />
|
||||||
<Viewbox x:Name="viewBox" StretchDirection="Both" Stretch="Uniform">
|
<Viewbox x:Name="viewBox" StretchDirection="Both" Stretch="Uniform">
|
||||||
<Viewbox.Clip>
|
<Viewbox.Clip>
|
||||||
<RectangleGeometry x:Name="rectangleGeometry" RadiusX="{Binding ElementName=border, Path=CornerRadius.TopLeft}" RadiusY="{Binding ElementName=border, Path=CornerRadius.TopLeft}"/>
|
<RectangleGeometry x:Name="rectangleGeometry" RadiusX="{Binding ElementName=border, Path=CornerRadius.TopLeft}" RadiusY="{Binding ElementName=border, Path=CornerRadius.TopLeft}" />
|
||||||
</Viewbox.Clip>
|
</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"/>
|
<Border x:Name="imageBorder" BorderBrush="#BAFFEF">
|
||||||
|
<Image x:Name="image" 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" />
|
||||||
|
</Border>
|
||||||
</Viewbox>
|
</Viewbox>
|
||||||
</Grid>
|
</Grid>
|
||||||
<WindowChrome.WindowChrome>
|
<WindowChrome.WindowChrome>
|
||||||
|
|||||||
@@ -131,6 +131,8 @@ public partial class PluginWindow : Window
|
|||||||
if (MainWindow.EditMode)
|
if (MainWindow.EditMode)
|
||||||
{
|
{
|
||||||
panel.Visibility = Visibility.Visible;
|
panel.Visibility = Visibility.Visible;
|
||||||
|
imageBorder.BorderThickness = new Thickness(3);
|
||||||
|
image.Margin = new(-3);
|
||||||
WindowPos.SetIsLocked(this, false);
|
WindowPos.SetIsLocked(this, false);
|
||||||
tileBar.CaptionHeight = tileBar.CaptionHeight = ActualHeight - 10 < 0 ? 0 : ActualHeight - 10;
|
tileBar.CaptionHeight = tileBar.CaptionHeight = ActualHeight - 10 < 0 ? 0 : ActualHeight - 10;
|
||||||
ResizeMode = ResizeMode.CanResize;
|
ResizeMode = ResizeMode.CanResize;
|
||||||
@@ -138,6 +140,8 @@ public partial class PluginWindow : Window
|
|||||||
else
|
else
|
||||||
{
|
{
|
||||||
panel.Visibility = Visibility.Collapsed;
|
panel.Visibility = Visibility.Collapsed;
|
||||||
|
imageBorder.BorderThickness = new Thickness(0);
|
||||||
|
image.Margin = new Thickness(0);
|
||||||
WindowPos.SetIsLocked(this, true);
|
WindowPos.SetIsLocked(this, true);
|
||||||
tileBar.CaptionHeight = 0;
|
tileBar.CaptionHeight = 0;
|
||||||
ResizeMode = ResizeMode.NoResize;
|
ResizeMode = ResizeMode.NoResize;
|
||||||
@@ -224,7 +228,8 @@ public partial class PluginWindow : Window
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
LoadOptions(instance);
|
LoadOptions(pluginClassInstance);
|
||||||
|
BindDefaultSettings(pluginClassInstance);
|
||||||
|
|
||||||
valueTimer = new System.Timers.Timer
|
valueTimer = new System.Timers.Timer
|
||||||
{
|
{
|
||||||
@@ -242,6 +247,40 @@ public partial class PluginWindow : Window
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private void BindDefaultSettings(Plugin pluginClassInstance)
|
||||||
|
{
|
||||||
|
Dispatcher.Invoke(() =>
|
||||||
|
{
|
||||||
|
SetHorizontalAlignment();
|
||||||
|
SetVerticalAlignment();
|
||||||
|
|
||||||
|
pluginClassInstance.horizontalAlignment.OnValueChanged += SetHorizontalAlignment;
|
||||||
|
pluginClassInstance.verticalAlignment.OnValueChanged += SetVerticalAlignment;
|
||||||
|
});
|
||||||
|
|
||||||
|
void SetVerticalAlignment()
|
||||||
|
{
|
||||||
|
viewBox.VerticalAlignment = pluginClassInstance.verticalAlignment.Value switch
|
||||||
|
{
|
||||||
|
"Top" => VerticalAlignment.Top,
|
||||||
|
"Center" => VerticalAlignment.Center,
|
||||||
|
"Bottom" => VerticalAlignment.Bottom,
|
||||||
|
_ => VerticalAlignment.Center
|
||||||
|
};
|
||||||
|
}
|
||||||
|
|
||||||
|
void SetHorizontalAlignment()
|
||||||
|
{
|
||||||
|
viewBox.HorizontalAlignment = pluginClassInstance.horizontalAlignment.Value switch
|
||||||
|
{
|
||||||
|
"Left" => HorizontalAlignment.Left,
|
||||||
|
"Center" => HorizontalAlignment.Center,
|
||||||
|
"Right" => HorizontalAlignment.Right,
|
||||||
|
_ => HorizontalAlignment.Center
|
||||||
|
};
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
private void LoadOptions(object instance)
|
private void LoadOptions(object instance)
|
||||||
{
|
{
|
||||||
App.Logger.Log($"\"{PluginName}\" - Loading plugin options", "Plugin");
|
App.Logger.Log($"\"{PluginName}\" - Loading plugin options", "Plugin");
|
||||||
@@ -294,7 +333,7 @@ public partial class PluginWindow : Window
|
|||||||
{
|
{
|
||||||
if (IsRunning && pluginClassInstance is not null)
|
if (IsRunning && pluginClassInstance is not null)
|
||||||
{
|
{
|
||||||
Bitmap result = pluginClassInstance.Main();
|
Bitmap? result = pluginClassInstance.Main();
|
||||||
|
|
||||||
if (pluginClassInstance.UpdateInterval > 0)
|
if (pluginClassInstance.UpdateInterval > 0)
|
||||||
{
|
{
|
||||||
|
|||||||
@@ -11,7 +11,13 @@ namespace DesktopMagic.Api;
|
|||||||
/// </summary>
|
/// </summary>
|
||||||
public abstract class Plugin
|
public abstract class Plugin
|
||||||
{
|
{
|
||||||
private IPluginData application = null;
|
[Setting("horizontalAlignment", "Horizontal Alignment", -999)]
|
||||||
|
internal ComboBox horizontalAlignment = new ComboBox("Center", "Left", "Right");
|
||||||
|
|
||||||
|
[Setting("verticalAlignment", "Vertical Alignment", -998)]
|
||||||
|
internal ComboBox verticalAlignment = new ComboBox("Center", "Top", "Bottom");
|
||||||
|
|
||||||
|
private IPluginData application = null!;
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Informations about the main application.
|
/// Informations about the main application.
|
||||||
|
|||||||
@@ -1,5 +1,4 @@
|
|||||||
using System.Collections.ObjectModel;
|
using System.Collections.ObjectModel;
|
||||||
using System.Text.Json;
|
|
||||||
|
|
||||||
namespace DesktopMagic.Api.Settings;
|
namespace DesktopMagic.Api.Settings;
|
||||||
|
|
||||||
@@ -8,7 +7,7 @@ namespace DesktopMagic.Api.Settings;
|
|||||||
/// </summary>
|
/// </summary>
|
||||||
public class ComboBox : Setting
|
public class ComboBox : Setting
|
||||||
{
|
{
|
||||||
private string _value;
|
private string _value = string.Empty;
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Gets the collection used to generate the content of the <see cref="ComboBox"/>.
|
/// Gets the collection used to generate the content of the <see cref="ComboBox"/>.
|
||||||
@@ -38,6 +37,8 @@ public class ComboBox : Setting
|
|||||||
/// <param name="items"></param>
|
/// <param name="items"></param>
|
||||||
public ComboBox(params string[] items)
|
public ComboBox(params string[] items)
|
||||||
{
|
{
|
||||||
|
Value = items[0];
|
||||||
|
|
||||||
foreach (string item in items)
|
foreach (string item in items)
|
||||||
{
|
{
|
||||||
Items.Add(item);
|
Items.Add(item);
|
||||||
@@ -46,7 +47,7 @@ public class ComboBox : Setting
|
|||||||
|
|
||||||
internal override string GetJsonValue()
|
internal override string GetJsonValue()
|
||||||
{
|
{
|
||||||
return JsonSerializer.Serialize(new { Value, Items });
|
return Value;
|
||||||
}
|
}
|
||||||
|
|
||||||
internal override void SetJsonValue(string value)
|
internal override void SetJsonValue(string value)
|
||||||
@@ -56,12 +57,6 @@ public class ComboBox : Setting
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
JsonElement json = JsonSerializer.Deserialize<JsonElement>(value);
|
Value = value;
|
||||||
Items.Clear();
|
|
||||||
foreach (JsonElement item in json.GetProperty(nameof(Items)).EnumerateArray())
|
|
||||||
{
|
|
||||||
Items.Add(item.GetString() ?? string.Empty);
|
|
||||||
}
|
|
||||||
Value = json.GetProperty(nameof(Value)).GetString() ?? string.Empty;
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -5,13 +5,13 @@ namespace DesktopMagic.Api.Settings;
|
|||||||
/// <summary>
|
/// <summary>
|
||||||
/// Marks a Property as element.
|
/// Marks a Property as element.
|
||||||
/// </summary>
|
/// </summary>
|
||||||
[AttributeUsage(AttributeTargets.Field)]
|
[AttributeUsage(AttributeTargets.Field | AttributeTargets.Property)]
|
||||||
public class SettingAttribute : Attribute
|
public class SettingAttribute : Attribute
|
||||||
{
|
{
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// The name of the element.
|
/// The name of the element.
|
||||||
/// </summary>
|
/// </summary>
|
||||||
public string Name { get; set; }
|
public string Name { get; set; } = string.Empty;
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// The order index of the element.
|
/// The order index of the element.
|
||||||
|
|||||||
Reference in New Issue
Block a user