- Add Margin option

- Add `Margin` property to `ITheme`
- Add `Stop` method to the `Plugin` API
- Add `DrawStringNoLeftPadding` and `MeasureStringNoLeftPadding` to `GraphicsExtentions`
- Convert most inbuilt components to plugins.
- Minor code improvements
This commit is contained in:
Stone-Red-Code
2021-10-29 20:35:01 +02:00
parent aeb31af2f9
commit 2f6662caea
23 changed files with 463 additions and 698 deletions
@@ -1,38 +0,0 @@
<Window x:Class="DesktopMagic.CalendarWindow"
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="CalendarWindow" Height="450" Width="800"
Background="Transparent"
WindowStyle="None"
AllowsTransparency="True"
LocationChanged="Window_LocationChanged"
SizeChanged="Window_SizeChanged"
x:Name="window">
<Grid>
<Rectangle x:Name="panel" Fill="#4CBAFFEF" Stroke="White" Margin="0,0,0,0" Visibility="Collapsed" />
<Viewbox StretchDirection="Both" Stretch="Uniform">
<ListView x:Name="listBox" Height="Auto" Width="Auto" Background="Transparent" BorderBrush="Transparent" FontSize="999" Foreground="White">
<ListView.ItemTemplate>
<DataTemplate>
<Grid>
<Grid.ColumnDefinitions>
<ColumnDefinition />
<ColumnDefinition />
</Grid.ColumnDefinitions>
<StackPanel>
<TextBlock Text="{Binding eventname}" FontSize="10" FontFamily="{Binding font}" Foreground="{Binding color}" Margin="0,0" />
<TextBlock Text="{Binding dateTime}" FontSize="7" FontFamily="{Binding font}" Foreground="Gray" Margin="0,-3" />
</StackPanel>
</Grid>
</DataTemplate>
</ListView.ItemTemplate>
</ListView>
</Viewbox>
</Grid>
<WindowChrome.WindowChrome>
<WindowChrome x:Name="tileBar" CaptionHeight="3000" ResizeBorderThickness="{x:Static SystemParameters.WindowResizeBorderThickness}" />
</WindowChrome.WindowChrome>
</Window>
@@ -1,154 +0,0 @@
using Microsoft.Win32;
using System;
using System.Collections.Generic;
using System.Threading.Tasks;
using System.Timers;
using System.Windows;
using System.Windows.Interop;
using System.Windows.Media;
namespace DesktopMagic
{
[Obsolete("Disabled due to lack of support (too much work)")]
public partial class CalendarWindow : Window
{
private RegistryKey key;
private string oldFont = "";
private Brush oldColor;
private List<string> upcomingEventNames = new List<string>();
private List<string> upcomingEventTimes = new List<string>();
public CalendarWindow()
{
InitializeComponent();
Window w = new Window();
w.Top = -100;
w.Left = -100;
w.Width = 0;
w.Height = 0;
w.WindowStyle = WindowStyle.ToolWindow;
w.ShowInTaskbar = false;
w.Show();
Owner = w;
w.Hide();
Timer t = new Timer();
t.Interval = 100;
t.Elapsed += UpdateTimer_Elapsed;
t.Start();
Timer valueTimer = new Timer();
valueTimer.Interval = 600000;
valueTimer.Elapsed += ValueTimer_Elapsed;
;
valueTimer.Start();
key = Registry.CurrentUser.CreateSubKey(@"Software\" + App.AppName);
Top = double.Parse(key.GetValue("CalendarWindowTop", 100).ToString());
Left = double.Parse(key.GetValue("CalendarWindowLeft", 100).ToString());
Height = double.Parse(key.GetValue("CalendarWindowHeight", 200).ToString());
Width = double.Parse(key.GetValue("CalendarWindowWidth", 500).ToString());
//this.IsEnabled = false;
Task.Run(() =>
{
(upcomingEventNames, upcomingEventTimes) = new CalendarManagment().GetEvents();
Dispatcher.Invoke(() =>
{
LoadEvents();
});
});
}
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 ValueTimer_Elapsed(object sender, ElapsedEventArgs e)
{
Task.Run(() =>
{
(upcomingEventNames, upcomingEventTimes) = new CalendarManagment().GetEvents();
Dispatcher.Invoke(() =>
{
LoadEvents();
});
});
}
private void UpdateTimer_Elapsed(object sender, ElapsedEventArgs e)
{
Dispatcher.Invoke(() =>
{
if (MainWindow.EditMode)
{
panel.Visibility = Visibility.Visible;
WindowPos.SetIsLocked(this, false);
}
else
{
panel.Visibility = Visibility.Collapsed;
WindowPos.SetIsLocked(this, true);
}
if (MainWindow.Theme.Font != oldFont || MainWindow.Theme.PrimaryBrush != oldColor)
{
oldColor = MainWindow.Theme.PrimaryBrush;
oldFont = MainWindow.Theme.Font;
LoadEvents();
}
listBox.SelectedIndex = -1;
});
}
private void LoadEvents()
{
listBox.Items.Clear();
CalendarItems calendarItem = new CalendarItems();
calendarItem.Eventname = "Termine: ";
calendarItem.Font = MainWindow.Theme.Font;
calendarItem.Color = MainWindow.Theme.PrimaryColor.ToString();
listBox.Items.Add(calendarItem);
for (int i = 0; i < upcomingEventNames.Count; i++)
{
calendarItem = new CalendarItems();
calendarItem.Eventname = upcomingEventNames[i];
calendarItem.DateTime = DateTime.Now.ToString("dd-MM-yyyy");
calendarItem.Font = MainWindow.Theme.Font;
calendarItem.Color = MainWindow.Theme.PrimaryBrush.ToString();
if (DateTime.Now < DateTime.Today.AddMonths(12) || upcomingEventTimes[i] == "-")
{
listBox.Items.Add(calendarItem);
}
}
while (listBox.Items.Count < 10)
{
listBox.Items.Add("");
}
}
private void Window_LocationChanged(object sender, EventArgs e)
{
key.SetValue("CalendarWindowTop", Top);
key.SetValue("CalendarWindowLeft", Left);
}
private void Window_SizeChanged(object sender, SizeChangedEventArgs e)
{
key.SetValue("CalendarWindowHeight", Height);
key.SetValue("CalendarWindowWidth", Width);
tileBar.CaptionHeight = ActualHeight - 10;
}
}
}
@@ -14,14 +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" />
<Border x:Name="border" Width="{Binding ElementName=viewBox, Path=ActualWidth}" Height="{Binding ElementName=viewBox, Path=ActualHeight}"/> <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}" Rect="{Binding ElementName=border}"/> <RectangleGeometry x:Name="rectangleGeometry" RadiusX="{Binding ElementName=border, Path=CornerRadius.TopLeft}" RadiusY="{Binding ElementName=border, Path=CornerRadius.TopLeft}" Rect="{Binding ElementName=border}"/>
</Viewbox.Clip> </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" Foreground="White" FontSize="100" Text="CPU: " IsHitTestVisible="False" />
<TextBlock x:Name="valueTextBlock" FontSize="999" TextAlignment="Right" Foreground="White" Text="000%" IsHitTestVisible="False" /> <TextBlock x:Name="valueTextBlock" TextAlignment="Right" FontSize="100" Foreground="White" Text="000%" IsHitTestVisible="False" />
</DockPanel> </DockPanel>
</Viewbox> </Viewbox>
</Grid> </Grid>
@@ -90,6 +90,9 @@ namespace DesktopMagic
rectangleGeometry.Rect = new Rect(0, 0, border.ActualWidth, border.ActualHeight); rectangleGeometry.Rect = new Rect(0, 0, border.ActualWidth, border.ActualHeight);
border.Background = MainWindow.Theme.BackgroundBrush; border.Background = MainWindow.Theme.BackgroundBrush;
border.CornerRadius = new CornerRadius(MainWindow.Theme.CornerRadius); 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.FontFamily = new FontFamily(MainWindow.Theme.Font);
textBlock.Foreground = MainWindow.Theme.PrimaryBrush; textBlock.Foreground = MainWindow.Theme.PrimaryBrush;
valueTextBlock.FontFamily = new FontFamily(MainWindow.Theme.Font); valueTextBlock.FontFamily = new FontFamily(MainWindow.Theme.Font);
@@ -0,0 +1,50 @@
using DesktopMagicPluginAPI;
using System;
using System.Drawing;
using System.Drawing.Text;
namespace DesktopMagic.BuiltInWindowElements
{
internal class DatePlugin : Plugin
{
public override int UpdateInterval => 1000;
private DateTime oldDateTime = new DateTime();
private Color oldColor = Color.White;
private string oldFont;
public override Bitmap Main()
{
if (oldDateTime.Date == DateTime.Now.Date && oldColor == Application.Theme.PrimaryColor && oldFont == Application.Theme.Font)
{
return null;
}
oldDateTime = DateTime.Now;
oldColor = Application.Theme.PrimaryColor;
oldFont = Application.Theme.Font;
string date = DateTime.Now.ToLongDateString();
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(date, font);
bmp = new Bitmap((int)size.Width, (int)size.Height);
bmp.SetResolution(100, 100);
using Graphics gr = Graphics.FromImage(bmp);
gr.TextRenderingHint = TextRenderingHint.AntiAlias;
gr.DrawString(date, font, new SolidBrush(Application.Theme.PrimaryColor), 0, 0);
return bmp;
}
}
}
@@ -1,28 +0,0 @@
<Window x:Class="DesktopMagic.DateWindow"
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"
mc:Ignorable="d"
Title="DateWindow" Height="450" Width="800"
Background="Transparent"
WindowStyle="None"
AllowsTransparency="True"
LocationChanged="Window_LocationChanged"
SizeChanged="Window_SizeChanged"
x:Name="window">
<Grid>
<Rectangle x:Name="panel" Fill="#4CBAFFEF" Stroke="White" Margin="0,0,0,0" Visibility="Collapsed" />
<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>
<WindowChrome x:Name="tileBar" CaptionHeight="3000" ResizeBorderThickness="{x:Static SystemParameters.WindowResizeBorderThickness}" />
</WindowChrome.WindowChrome>
</Window>
@@ -1,95 +0,0 @@
using Microsoft.Win32;
using System;
using System.Timers;
using System.Windows;
using System.Windows.Interop;
using System.Windows.Media;
namespace DesktopMagic
{
public partial class DateWindow : Window
{
private RegistryKey key;
public DateWindow()
{
InitializeComponent();
Window w = new Window();
w.Top = -100;
w.Left = -100;
w.Width = 0;
w.Height = 0;
w.WindowStyle = WindowStyle.ToolWindow;
w.ShowInTaskbar = false;
w.Show();
Owner = w;
w.Hide();
Timer t = new Timer();
t.Interval = 100;
t.Elapsed += UpdateTimer_Elapsed;
t.Start();
key = Registry.CurrentUser.CreateSubKey(@"Software\" + App.AppName);
Top = double.Parse(key.GetValue("DateWindowTop", 100).ToString());
Left = double.Parse(key.GetValue("DateWindowLeft", 100).ToString());
Height = double.Parse(key.GetValue("DateWindowHeight", 200).ToString());
Width = double.Parse(key.GetValue("DateWindowWidth", 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);
textBlock.FontFamily = new FontFamily(MainWindow.Theme.Font);
textBlock.Foreground = MainWindow.Theme.PrimaryBrush;
textBlock.Text = DateTime.Now.ToLongDateString();
});
}
private void Window_LocationChanged(object sender, EventArgs e)
{
key.SetValue("DateWindowTop", Top);
key.SetValue("DateWindowLeft", Left);
}
private void Window_SizeChanged(object sender, SizeChangedEventArgs e)
{
key.SetValue("DateWindowHeight", Height);
key.SetValue("DateWindowWidth", Width);
tileBar.CaptionHeight = ActualHeight - 10;
}
}
}
@@ -1,51 +1,24 @@
using Microsoft.Win32; using DesktopMagicPluginAPI;
using NAudio.Wave; using NAudio.Wave;
using System; using System;
using System.Collections.Generic; using System.Collections.Generic;
using System.Drawing; using System.Drawing;
using System.Drawing.Imaging;
using System.Globalization;
using System.Linq; using System.Linq;
using System.Runtime.InteropServices;
using System.Timers;
using System.Windows;
using System.Windows.Interop;
using System.Windows.Media.Imaging;
using System.Windows.Threading;
namespace DesktopMagic namespace DesktopMagic.BuiltInWindowElements
{ {
public partial class MusicVisualizerWindow : Window internal class MusicVisualizerPlugin : Plugin
{ {
[DllImport("user32.dll")] private IWaveIn waveIn;
private static extern void SetParent(IntPtr hWndChild, IntPtr hWndNewParent);
private readonly RegistryKey key;
private readonly IWaveIn waveIn;
private const int fftLength = 1024; // NAudio fft wants powers of two! private const int fftLength = 1024; // NAudio fft wants powers of two!
private readonly SampleAggregator sampleAggregator = new SampleAggregator(fftLength); private readonly SampleAggregator sampleAggregator = new SampleAggregator(fftLength);
private volatile bool calculate = true; private volatile bool calculate = true;
private Bitmap output = new Bitmap(880, 300);
public MusicVisualizerWindow() public override void Start()
{ {
InitializeComponent();
Window w = new()
{
Top = -100,
Left = -100,
Width = 0,
Height = 0,
WindowStyle = WindowStyle.ToolWindow,
ShowInTaskbar = false
};
w.Show();
Owner = w;
w.Hide();
sampleAggregator.FftCalculated += new EventHandler<FftEventArgs>(FftCalculated); sampleAggregator.FftCalculated += new EventHandler<FftEventArgs>(FftCalculated);
sampleAggregator.PerformFFT = true; sampleAggregator.PerformFFT = true;
@@ -53,58 +26,6 @@ namespace DesktopMagic
waveIn.DataAvailable += OnDataAvailable; waveIn.DataAvailable += OnDataAvailable;
waveIn.StartRecording(); waveIn.StartRecording();
Timer t = new Timer();
t.Interval = 100;
t.Elapsed += UpdateTimer_Elapsed;
t.Start();
key = Registry.CurrentUser.CreateSubKey(@"Software\" + App.AppName);
Top = double.Parse(key.GetValue("MusicVisualizerWindowTop", 100).ToString(), CultureInfo.InvariantCulture);
Left = double.Parse(key.GetValue("MusicVisualizerWindowLeft", 100).ToString(), CultureInfo.InvariantCulture);
Height = double.Parse(key.GetValue("MusicVisualizerWindowHeight", 200).ToString(), CultureInfo.InvariantCulture);
Width = double.Parse(key.GetValue("MusicVisualizerWindowWidth", 500).ToString(), CultureInfo.InvariantCulture);
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;
}
calculate = IsLoaded;
rectangleGeometry.Rect = new Rect(0, 0, border.ActualWidth, border.ActualHeight);
border.CornerRadius = new CornerRadius(MainWindow.Theme.CornerRadius);
border.Background = MainWindow.Theme.BackgroundBrush;
});
} }
private void OnDataAvailable(object sender, WaveInEventArgs e) private void OnDataAvailable(object sender, WaveInEventArgs e)
@@ -226,7 +147,6 @@ namespace DesktopMagic
lastFft = fft; lastFft = fft;
try try
{ {
Bitmap bm = new Bitmap(880, 300);
int offset = 0; int offset = 0;
if (!MainWindow.MirrorMode && MainWindow.SpectrumMode != 1) if (!MainWindow.MirrorMode && MainWindow.SpectrumMode != 1)
@@ -239,8 +159,9 @@ namespace DesktopMagic
offset = 1; offset = 1;
} }
using (Graphics gr = Graphics.FromImage(bm)) using (Graphics gr = Graphics.FromImage(output))
{ {
gr.Clear(Color.Transparent);
PointF[] points = new PointF[scaledFft.Count + 2]; PointF[] points = new PointF[scaledFft.Count + 2];
int fftIndex = 0; int fftIndex = 0;
@@ -260,8 +181,8 @@ namespace DesktopMagic
if (!fftIndexReverse) if (!fftIndexReverse)
{ {
points[pointIndex + 1] = new PointF(bm.Width - (4 * pointIndex), (bm.Height / 2) + value); points[pointIndex + 1] = new PointF(output.Width - (4 * pointIndex), (output.Height / 2) + value);
points[(points.Length / 2) + pointIndex + 1] = new PointF(bm.Width - (4 * pointIndex), (bm.Height / 2) - value); points[(points.Length / 2) + pointIndex + 1] = new PointF(output.Width - (4 * pointIndex), (output.Height / 2) - value);
} }
break; break;
@@ -270,7 +191,7 @@ namespace DesktopMagic
break; break;
default: default:
points[pointIndex + 1] = new PointF(2 * pointIndex, bm.Height - value - 1 + offset); points[pointIndex + 1] = new PointF(2 * pointIndex, output.Height - value - 1 + offset);
break; break;
} }
@@ -292,7 +213,7 @@ namespace DesktopMagic
} }
} }
SetPoints(points, bm.Width, bm.Height, offset); SetPoints(points, output.Width, output.Height, offset);
Brush brush = MainWindow.MusicVisualzerColor.HasValue Brush brush = MainWindow.MusicVisualzerColor.HasValue
? new SolidBrush(MainWindow.MusicVisualzerColor.Value) ? new SolidBrush(MainWindow.MusicVisualzerColor.Value)
@@ -316,10 +237,7 @@ namespace DesktopMagic
} }
} }
_ = Dispatcher.BeginInvoke((Action)delegate Application.UpdateWindow();
{
image.Source = BitmapToImageSource(bm);
});
} }
catch { } catch { }
} }
@@ -348,33 +266,15 @@ namespace DesktopMagic
} }
} }
private BitmapSource BitmapToImageSource(Bitmap bitmap) public override Bitmap Main()
{ {
BitmapData bitmapData = bitmap.LockBits( return output;
new Rectangle(0, 0, bitmap.Width, bitmap.Height),
ImageLockMode.ReadOnly, bitmap.PixelFormat);
BitmapSource bitmapSource = BitmapSource.Create(
bitmapData.Width, bitmapData.Height,
bitmap.HorizontalResolution, bitmap.VerticalResolution,
System.Windows.Media.PixelFormats.Bgra32, null,
bitmapData.Scan0, bitmapData.Stride * bitmapData.Height, bitmapData.Stride);
bitmap.UnlockBits(bitmapData);
return bitmapSource;
} }
private void Window_LocationChanged(object sender, EventArgs e) public override void Stop()
{ {
key.SetValue("MusicVisualizerWindowTop", Top); calculate = false;
key.SetValue("MusicVisualizerWindowLeft", Left); waveIn?.StopRecording();
}
private void Window_SizeChanged(object sender, SizeChangedEventArgs e)
{
key.SetValue("MusicVisualizerWindowHeight", Height);
key.SetValue("MusicVisualizerWindowWidth", Width);
tileBar.CaptionHeight = ActualHeight - 10;
} }
} }
} }
@@ -1,28 +0,0 @@
<Window
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:System="clr-namespace:System;assembly=mscorlib" x:Class="DesktopMagic.MusicVisualizerWindow"
mc:Ignorable="d"
Title="MusicVisualizerWindow" Height="450" Width="800"
Background="Transparent"
WindowStyle="None"
AllowsTransparency="True"
LocationChanged="Window_LocationChanged"
SizeChanged="Window_SizeChanged"
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" />
<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>
@@ -0,0 +1,51 @@
using DesktopMagicPluginAPI;
using DesktopMagicPluginAPI.Drawing;
using System;
using System.Drawing;
using System.Drawing.Text;
namespace DesktopMagic.BuiltInWindowElements
{
internal class TimePlugin : Plugin
{
public override int UpdateInterval => 1000;
public override Bitmap Main()
{
string time = DateTime.Now.ToLongTimeString();
Font font = new Font(Application.Theme.Font, 200);
Bitmap bmp = new Bitmap(1, 1);
using Graphics tmpGr = Graphics.FromImage(bmp);
tmpGr.TextRenderingHint = TextRenderingHint.AntiAlias;
SizeF size = CalculateSize(tmpGr, font);
bmp = new Bitmap((int)size.Width, (int)size.Height);
bmp.SetResolution(100, 100);
using Graphics gr = Graphics.FromImage(bmp);
gr.TextRenderingHint = TextRenderingHint.AntiAlias;
gr.DrawStringNoLeftPadding(time, font, new SolidBrush(Application.Theme.PrimaryColor), 0, 0);
return bmp;
}
private SizeF CalculateSize(Graphics graphics, Font font)
{
string template = "##:##:##";
SizeF size = new SizeF();
for (int i = 0; i < 9; i++)
{
SizeF newSize = graphics.MeasureStringNoLeftPadding(template.Replace("#", i.ToString()), font);
size.Width = Math.Max(size.Width, newSize.Width);
size.Height = Math.Max(size.Height, newSize.Height);
}
return size;
}
}
}
@@ -1,27 +0,0 @@
<Window x:Class="DesktopMagic.TimeWindow"
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"
mc:Ignorable="d"
Title="TimeWindow" Height="450" Width="800"
Background="Transparent"
WindowStyle="None"
AllowsTransparency="True"
LocationChanged="Window_LocationChanged"
SizeChanged="Window_SizeChanged"
x:Name="window">
<Grid>
<Rectangle x:Name="panel" Fill="#4CBAFFEF" Stroke="White" Margin="0,0,0,0" Visibility="Collapsed" />
<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>
<WindowChrome.WindowChrome>
<WindowChrome x:Name="tileBar" CaptionHeight="30" ResizeBorderThickness="{x:Static SystemParameters.WindowResizeBorderThickness}" />
</WindowChrome.WindowChrome>
</Window>
@@ -1,111 +0,0 @@
using DesktopMagic.Helpers;
using Microsoft.Win32;
using System;
using System.Timers;
using System.Windows;
using System.Windows.Interop;
using System.Windows.Media;
namespace DesktopMagic
{
public partial class TimeWindow : Window
{
private RegistryKey key;
public TimeWindow()
{
InitializeComponent();
Window w = new Window();
w.Top = -100;
w.Left = -100;
w.Width = 0;
w.Height = 0;
w.WindowStyle = WindowStyle.ToolWindow;
w.ShowInTaskbar = false;
w.Show();
Owner = w;
w.Hide();
Timer t = new Timer();
t.Interval = 100;
t.Elapsed += UpdateTimer_Elapsed;
t.Start();
key = Registry.CurrentUser.CreateSubKey(@"Software\" + App.AppName);
Top = double.Parse(key.GetValue("TimeWindowTop", 100).ToString());
Left = double.Parse(key.GetValue("TimeWindowLeft", 100).ToString());
Height = double.Parse(key.GetValue("TimeWindowHeight", 200).ToString());
Width = double.Parse(key.GetValue("TimeWindowWidth", 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);
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);
key.SetValue("TimeWindowLeft", Left);
}
private void Window_SizeChanged(object sender, SizeChangedEventArgs e)
{
key.SetValue("TimeWindowHeight", Height);
key.SetValue("TimeWindowWidth", Width);
tileBar.CaptionHeight = ActualHeight - 10;
}
}
}
@@ -199,7 +199,7 @@ namespace DesktopMagic.Helpers
{ {
App.Logger.Log(message, "PluginInput"); App.Logger.Log(message, "PluginInput");
_ = MessageBox.Show("File execution error:\n" + message, "Error", MessageBoxButton.OK, MessageBoxImage.Error); _ = MessageBox.Show("File execution error:\n" + message, "Error", MessageBoxButton.OK, MessageBoxImage.Error);
int index = MainWindow.WindowNames.IndexOf(((Tuple<string, int>)optionsComboBox.SelectedItem).Item1.ToString()); int index = MainWindow.WindowNames.IndexOf(optionsComboBox.SelectedItem.ToString());
PluginWindow window = MainWindow.Windows[index] as PluginWindow; PluginWindow window = MainWindow.Windows[index] as PluginWindow;
window?.Exit(); window?.Exit();
+10 -2
View File
@@ -46,7 +46,7 @@
</DockPanel> </DockPanel>
<DockPanel Grid.Column="1" Margin="2.5,0,0,0"> <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" SelectionChanged="OptionsComboBox_SelectionChanged" Background="#FFECECEC" Padding="4" VerticalAlignment="Center"/>
<ScrollViewer Background="#FFBBBBBB"> <ScrollViewer Background="#FFBBBBBB">
<Grid> <Grid>
<StackPanel x:Name="optionsPanel" Margin="3,3,3,0" HorizontalAlignment="Stretch" Visibility="Collapsed" > <StackPanel x:Name="optionsPanel" Margin="3,3,3,0" HorizontalAlignment="Stretch" Visibility="Collapsed" >
@@ -86,13 +86,21 @@
<Grid.RowDefinitions> <Grid.RowDefinitions>
<RowDefinition Height="Auto"/> <RowDefinition Height="Auto"/>
<RowDefinition Height="Auto"/> <RowDefinition Height="Auto"/>
<RowDefinition Height="Auto"/>
</Grid.RowDefinitions> </Grid.RowDefinitions>
<TextBlock Text="Display Font: " Grid.Column="0" Grid.Row="0" VerticalAlignment="Center"></TextBlock> <TextBlock Text="Display Font: " Grid.Column="0" Grid.Row="0" VerticalAlignment="Center"></TextBlock>
<ComboBox x:Name="fontComboBox" Grid.Column="1" Grid.Row="0" HorizontalAlignment="Stretch" VerticalAlignment="Top" SelectionChanged="FontComboBox_SelectionChanged" Margin="0,0,0,5" /> <ComboBox x:Name="fontComboBox" Grid.Column="1" Grid.Row="0" HorizontalAlignment="Stretch" VerticalAlignment="Top" SelectionChanged="FontComboBox_SelectionChanged" Margin="0,0,0,5" />
<TextBlock Text="Corner Radius: " Grid.Column="0" Grid.Row="1" VerticalAlignment="Center"></TextBlock> <TextBlock Text="Corner Radius: " Grid.Column="0" Grid.Row="1" VerticalAlignment="Center"></TextBlock>
<TextBox x:Name="cornerRadiusTextBox" Grid.Column="1" Grid.Row="1" Text="10" TextChanged="CornerRadiusTextBox_TextChanged" materialDesign:HintAssist.HelperText="In px" materialDesign:HintAssist.Hint="Enter a number"> <TextBox x:Name="cornerRadiusTextBox" Grid.Column="1" Grid.Row="1" TextChanged="CornerRadiusTextBox_TextChanged" materialDesign:HintAssist.Hint="Enter a number">
<materialDesign:TextFieldAssist.CharacterCounterStyle>
<Style TargetType="TextBlock" />
</materialDesign:TextFieldAssist.CharacterCounterStyle>
</TextBox>
<TextBlock Text="Margin: " Grid.Column="0" Grid.Row="3" VerticalAlignment="Center"></TextBlock>
<TextBox x:Name="marginTextBox" Grid.Column="1" Grid.Row="3" TextChanged="MarginTextBox_TextChanged" materialDesign:HintAssist.Hint="Enter a number">
<materialDesign:TextFieldAssist.CharacterCounterStyle> <materialDesign:TextFieldAssist.CharacterCounterStyle>
<Style TargetType="TextBlock" /> <Style TargetType="TextBlock" />
</materialDesign:TextFieldAssist.CharacterCounterStyle> </materialDesign:TextFieldAssist.CharacterCounterStyle>
+54 -33
View File
@@ -1,4 +1,5 @@
using DesktopMagic.Dialogs; using DesktopMagic.BuiltInWindowElements;
using DesktopMagic.Dialogs;
using DesktopMagic.Helpers; using DesktopMagic.Helpers;
using DesktopMagic.Plugins; using DesktopMagic.Plugins;
@@ -46,7 +47,7 @@ namespace DesktopMagic
#endregion Plugins settings #endregion Plugins settings
public static List<Window> Windows { get; } = new List<Window>(); public static List<PluginWindow> Windows { get; } = new List<PluginWindow>();
public static List<string> WindowNames { get; } = 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();
@@ -199,75 +200,68 @@ namespace DesktopMagic
private void CheckBox_Click(object sender, RoutedEventArgs e) private void CheckBox_Click(object sender, RoutedEventArgs e)
{ {
CheckBox checkBox = (CheckBox)sender; CheckBox checkBox = (CheckBox)sender;
Window window; PluginWindow window = null;
blockWindowsClosing = false; blockWindowsClosing = false;
switch (checkBox.Name) switch (checkBox.Name)
{ {
case "TimeCb": case "TimeCb":
window = new TimeWindow(); window = new PluginWindow(new TimePlugin());
break; break;
case "DateCb": case "DateCb":
window = new DateWindow(); window = new PluginWindow(new DatePlugin());
break; break;
case "CpuUsageCb": case "CpuUsageCb":
window = new CpuUsageWindow(); //window = new PluginWindow();
break; break;
case "MusicVisualizerCb": case "MusicVisualizerCb":
window = new MusicVisualizerWindow(); window = new PluginWindow(new MusicVisualizerPlugin());
break; break;
default: default:
if (checkBox.Name.Contains("_PluginCb_")) if (!checkBox.Name.Contains("_PluginCb_"))
{
window = new PluginWindow(checkBox.Content.ToString())
{
Title = checkBox.Content.ToString()
};
break;
}
else
{ {
return; return;
} }
window = new PluginWindow(checkBox.Content.ToString());
break;
} }
if (!WindowNames.Contains(window.Title)) if (window is null)
{
return;
}
window.Title = checkBox.Content.ToString();
if (!WindowNames.Contains(window.Title) && checkBox.IsChecked == true)
{ {
_ = Task.Run(() => _ = Task.Run(() =>
{ {
Dispatcher.Invoke(() => Dispatcher.Invoke(() =>
{
if (window is PluginWindow pluginWindow)
{ {
Action onPluginLoaded = null; Action onPluginLoaded = null;
onPluginLoaded = () => onPluginLoaded = () =>
{ {
Dispatcher.Invoke(() => Dispatcher.Invoke(() =>
{ {
if (!optionsComboBox.Items.Contains(new Tuple<string, int>(checkBox.Content.ToString(), 0))) if (!optionsComboBox.Items.Contains(checkBox.Content.ToString()))
{ {
_ = optionsComboBox.Items.Add(new Tuple<string, int>(checkBox.Content.ToString(), 0)); _ = optionsComboBox.Items.Add(checkBox.Content.ToString());
} }
optionsComboBox.SelectedIndex = -1; optionsComboBox.SelectedIndex = -1;
optionsComboBox.SelectedIndex = optionsComboBox.Items.IndexOf(new Tuple<string, int>(checkBox.Content.ToString(), 0)); optionsComboBox.SelectedIndex = optionsComboBox.Items.IndexOf(checkBox.Content.ToString());
pluginWindow.PluginLoaded -= onPluginLoaded; window.PluginLoaded -= onPluginLoaded;
}); });
}; };
pluginWindow.OnExit += () => window.OnExit += () =>
{ {
checkBox.IsChecked = false; checkBox.IsChecked = false;
CheckBox_Click(checkBox, null); CheckBox_Click(checkBox, null);
}; };
pluginWindow.PluginLoaded += onPluginLoaded; window.PluginLoaded += onPluginLoaded;
}
else if (window is MusicVisualizerWindow musicVisualizerWindow)
{
optionsComboBox.SelectedIndex = optionsComboBox.Items.IndexOf(new Tuple<string, int>(checkBox.Content.ToString(), 0));
}
window.ShowInTaskbar = false; window.ShowInTaskbar = false;
window.Show(); window.Show();
@@ -282,10 +276,19 @@ namespace DesktopMagic
{ {
int index = WindowNames.IndexOf(window.Title); int index = WindowNames.IndexOf(window.Title);
if (index >= 0)
{
//Not sure how to handle this
try
{
Windows[index].Close(); Windows[index].Close();
Windows.RemoveAt(index); Windows.RemoveAt(index);
WindowNames.RemoveAt(index); WindowNames.RemoveAt(index);
window.Close(); //window.Close();
}
catch { }
}
} }
key.SetValue(checkBox.Name, checkBox.IsChecked.ToString()); key.SetValue(checkBox.Name, checkBox.IsChecked.ToString());
blockWindowsClosing = true; blockWindowsClosing = true;
@@ -447,7 +450,7 @@ namespace DesktopMagic
optionsPanel.Children.Clear(); optionsPanel.Children.Clear();
optionsPanel.UpdateLayout(); optionsPanel.UpdateLayout();
bool success = PluginsSettings.TryGetValue(((Tuple<string, int>)optionsComboBox.SelectedItem).Item1.ToString(), out List<SettingElement> settingElements); bool success = PluginsSettings.TryGetValue(optionsComboBox.SelectedItem.ToString(), out List<SettingElement> settingElements);
if (!success || settingElements?.Count == 0) if (!success || settingElements?.Count == 0)
{ {
_ = optionsPanel.Children.Add(new TextBlock() { Text = (string)FindResource("noOptions") }); _ = optionsPanel.Children.Add(new TextBlock() { Text = (string)FindResource("noOptions") });
@@ -562,6 +565,22 @@ namespace DesktopMagic
} }
} }
private void MarginTextBox_TextChanged(object sender, TextChangedEventArgs e)
{
bool sucess = int.TryParse(marginTextBox.Text, out int margin);
if (sucess)
{
marginTextBox.Foreground = Brushes.Black;
Theme.Margin = margin;
key.SetValue("Margin", margin);
SaveLayout();
}
else
{
marginTextBox.Foreground = Brushes.Red;
}
}
#region Layout #region Layout
private void LayoutsComboBox_SelectionChanged(object sender, SelectionChangedEventArgs e) private void LayoutsComboBox_SelectionChanged(object sender, SelectionChangedEventArgs e)
@@ -685,6 +704,7 @@ namespace DesktopMagic
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(); cornerRadiusTextBox.Text = key.GetValue("CornerRadius", "0").ToString();
marginTextBox.Text = key.GetValue("Margin", "0").ToString();
blockWindowsClosing = false; blockWindowsClosing = false;
string primaryColorHex = key.GetValue("PrimaryColor", "#FFFFFFFF").ToString(); string primaryColorHex = key.GetValue("PrimaryColor", "#FFFFFFFF").ToString();
@@ -717,6 +737,7 @@ namespace DesktopMagic
SpectrumModeComboBox_SelectionChanged(null, null); SpectrumModeComboBox_SelectionChanged(null, null);
AmplifierLevelSlider_ValueChanged(null, null); AmplifierLevelSlider_ValueChanged(null, null);
CornerRadiusTextBox_TextChanged(null, null); CornerRadiusTextBox_TextChanged(null, null);
MarginTextBox_TextChanged(null, null);
foreach (Window window in Windows) foreach (Window window in Windows)
{ {
@@ -730,7 +751,7 @@ namespace DesktopMagic
WindowNames.Clear(); WindowNames.Clear();
optionsComboBox.Items.Clear(); optionsComboBox.Items.Clear();
_ = optionsComboBox.Items.Add(new Tuple<string, int>((string)FindResource("musicVisualizer"), 0)); _ = optionsComboBox.Items.Add((string)FindResource("musicVisualizer"));
IEnumerable<CheckBox> list = stackPanel.Children.OfType<CheckBox>(); IEnumerable<CheckBox> list = stackPanel.Children.OfType<CheckBox>();
bool showWindow = true; bool showWindow = true;
+2 -2
View File
@@ -17,10 +17,10 @@
<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" Width="{Binding ElementName=viewBox, Path=ActualWidth}" Height="{Binding ElementName=viewBox, Path=ActualHeight}"/> <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}" Rect="{Binding ElementName=border}"/> <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"/> <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> </Viewbox>
+33 -14
View File
@@ -27,9 +27,10 @@ namespace DesktopMagic
private readonly RegistryKey key; private readonly RegistryKey key;
private Thread pluginThread; private Thread pluginThread;
private System.Timers.Timer valueTimer; private System.Timers.Timer valueTimer;
private bool stop = false;
private Plugin pluginClassInstance; private Plugin pluginClassInstance;
public bool IsRunning { get; private set; } = true;
public string PluginName { get; private set; } public string PluginName { get; private set; }
public string PluginFolderPath { get; private set; } public string PluginFolderPath { get; private set; }
@@ -69,6 +70,11 @@ namespace DesktopMagic
Width = double.Parse(key.GetValue(pluginName + "WindowWidth", 500).ToString()); Width = double.Parse(key.GetValue(pluginName + "WindowWidth", 500).ToString());
} }
public PluginWindow(Plugin pluginClassInstance) : this(pluginClassInstance.GetType().Name)
{
this.pluginClassInstance = pluginClassInstance;
}
protected override void OnSourceInitialized(EventArgs e) protected override void OnSourceInitialized(EventArgs e)
{ {
base.OnSourceInitialized(e); base.OnSourceInitialized(e);
@@ -111,13 +117,17 @@ namespace DesktopMagic
tileBar.CaptionHeight = 0; tileBar.CaptionHeight = 0;
ResizeMode = ResizeMode.NoResize; ResizeMode = ResizeMode.NoResize;
} }
if (stop)
if (!IsRunning)
{ {
((System.Timers.Timer)sender).Stop(); ((System.Timers.Timer)sender).Stop();
} }
else else
{ {
rectangleGeometry.Rect = new Rect(0, 0, border.ActualWidth, border.ActualHeight); viewBox.Margin = new Thickness(MainWindow.Theme.Margin);
border.Width = viewBox.ActualWidth + MainWindow.Theme.Margin * 2;
border.Height = viewBox.ActualHeight + MainWindow.Theme.Margin * 2;
rectangleGeometry.Rect = new Rect(-MainWindow.Theme.Margin, -MainWindow.Theme.Margin, border.ActualWidth, border.ActualHeight);
border.Background = MainWindow.Theme.BackgroundBrush; border.Background = MainWindow.Theme.BackgroundBrush;
border.CornerRadius = new CornerRadius(MainWindow.Theme.CornerRadius); border.CornerRadius = new CornerRadius(MainWindow.Theme.CornerRadius);
} }
@@ -125,6 +135,8 @@ namespace DesktopMagic
} }
private void LoadPlugin() private void LoadPlugin()
{
if (pluginClassInstance is null)
{ {
PluginFolderPath = $"{Environment.GetFolderPath(Environment.SpecialFolder.ApplicationData)}\\{App.AppName}\\Plugins\\{PluginName}"; PluginFolderPath = $"{Environment.GetFolderPath(Environment.SpecialFolder.ApplicationData)}\\{App.AppName}\\Plugins\\{PluginName}";
@@ -134,6 +146,7 @@ namespace DesktopMagic
Exit(); Exit();
return; return;
} }
}
try try
{ {
@@ -150,6 +163,9 @@ namespace DesktopMagic
} }
private void ExecuteSource() private void ExecuteSource()
{
object instance = pluginClassInstance;
if (instance is null)
{ {
byte[] assemblyBytes = File.ReadAllBytes($"{PluginFolderPath}\\{PluginName}.dll"); byte[] assemblyBytes = File.ReadAllBytes($"{PluginFolderPath}\\{PluginName}.dll");
Assembly dll = Assembly.Load(assemblyBytes); Assembly dll = Assembly.Load(assemblyBytes);
@@ -162,7 +178,8 @@ namespace DesktopMagic
return; return;
} }
object instance = Activator.CreateInstance(instanceType); instance = Activator.CreateInstance(instanceType);
}
if (instance is Plugin) if (instance is Plugin)
{ {
pluginClassInstance = instance as Plugin; pluginClassInstance = instance as Plugin;
@@ -226,7 +243,7 @@ namespace DesktopMagic
} }
catch (Exception ex) catch (Exception ex)
{ {
stop = true; IsRunning = false;
App.Logger.Log(ex.ToString(), "Plugin"); App.Logger.Log(ex.ToString(), "Plugin");
_ = MessageBox.Show("File execution error:\n" + ex, "Error", MessageBoxButton.OK, MessageBoxImage.Error); _ = MessageBox.Show("File execution error:\n" + ex, "Error", MessageBoxButton.OK, MessageBoxImage.Error);
Exit(); Exit();
@@ -238,7 +255,7 @@ namespace DesktopMagic
{ {
try try
{ {
if (!stop) if (IsRunning)
{ {
Bitmap result = pluginClassInstance.Main(); Bitmap result = pluginClassInstance.Main();
@@ -272,14 +289,14 @@ namespace DesktopMagic
} }
catch (Exception ex) catch (Exception ex)
{ {
stop = true; IsRunning = false;
App.Logger.Log(ex.ToString(), "Plugin"); App.Logger.Log(ex.ToString(), "Plugin");
_ = MessageBox.Show("File execution error:\n" + ex, "Error", MessageBoxButton.OK, MessageBoxImage.Error); _ = MessageBox.Show("File execution error:\n" + ex, "Error", MessageBoxButton.OK, MessageBoxImage.Error);
Exit(); Exit();
return; return;
} }
if (stop) if (!IsRunning)
{ {
valueTimer.Stop(); valueTimer.Stop();
} }
@@ -303,13 +320,20 @@ namespace DesktopMagic
public void Exit() public void Exit()
{ {
stop = true; IsRunning = false;
Dispatcher.Invoke(() => Dispatcher.Invoke(() =>
{ {
OnExit?.Invoke(); OnExit?.Invoke();
}); });
} }
private void Window_Closing(object sender, System.ComponentModel.CancelEventArgs e)
{
pluginClassInstance?.Stop();
IsRunning = false;
}
#region Window Events #region Window Events
private void Window_LocationChanged(object sender, EventArgs e) private void Window_LocationChanged(object sender, EventArgs e)
@@ -325,11 +349,6 @@ namespace DesktopMagic
tileBar.CaptionHeight = ActualHeight - 10; tileBar.CaptionHeight = ActualHeight - 10;
} }
private void Window_Closing(object sender, System.ComponentModel.CancelEventArgs e)
{
stop = true;
}
private void Window_MouseDown(object sender, System.Windows.Input.MouseButtonEventArgs e) private void Window_MouseDown(object sender, System.Windows.Input.MouseButtonEventArgs e)
{ {
ImageSource imageSource = image.Source; ImageSource imageSource = image.Source;
+1
View File
@@ -12,6 +12,7 @@ namespace DesktopMagic.Plugins
public string Font { get; set; } = "Segoe UI"; public string Font { get; set; } = "Segoe UI";
public int CornerRadius { get; set; } public int CornerRadius { get; set; }
public int Margin { 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;
@@ -23,6 +23,9 @@
- [DrawStringFixedWidth(graphics,s,font,brush,point,width)](#M-DesktopMagicPluginAPI-Drawing-GraphicsExtentions-DrawStringFixedWidth-System-Drawing-Graphics,System-String,System-Drawing-Font,System-Drawing-Brush,System-Drawing-PointF,System-Single- 'DesktopMagicPluginAPI.Drawing.GraphicsExtentions.DrawStringFixedWidth(System.Drawing.Graphics,System.String,System.Drawing.Font,System.Drawing.Brush,System.Drawing.PointF,System.Single)') - [DrawStringFixedWidth(graphics,s,font,brush,point,width)](#M-DesktopMagicPluginAPI-Drawing-GraphicsExtentions-DrawStringFixedWidth-System-Drawing-Graphics,System-String,System-Drawing-Font,System-Drawing-Brush,System-Drawing-PointF,System-Single- 'DesktopMagicPluginAPI.Drawing.GraphicsExtentions.DrawStringFixedWidth(System.Drawing.Graphics,System.String,System.Drawing.Font,System.Drawing.Brush,System.Drawing.PointF,System.Single)')
- [DrawStringMonospace(graphics,s,font,brush,x,y)](#M-DesktopMagicPluginAPI-Drawing-GraphicsExtentions-DrawStringMonospace-System-Drawing-Graphics,System-String,System-Drawing-Font,System-Drawing-Brush,System-Single,System-Single- 'DesktopMagicPluginAPI.Drawing.GraphicsExtentions.DrawStringMonospace(System.Drawing.Graphics,System.String,System.Drawing.Font,System.Drawing.Brush,System.Single,System.Single)') - [DrawStringMonospace(graphics,s,font,brush,x,y)](#M-DesktopMagicPluginAPI-Drawing-GraphicsExtentions-DrawStringMonospace-System-Drawing-Graphics,System-String,System-Drawing-Font,System-Drawing-Brush,System-Single,System-Single- 'DesktopMagicPluginAPI.Drawing.GraphicsExtentions.DrawStringMonospace(System.Drawing.Graphics,System.String,System.Drawing.Font,System.Drawing.Brush,System.Single,System.Single)')
- [DrawStringMonospace(graphics,s,font,brush,point)](#M-DesktopMagicPluginAPI-Drawing-GraphicsExtentions-DrawStringMonospace-System-Drawing-Graphics,System-String,System-Drawing-Font,System-Drawing-Brush,System-Drawing-PointF- 'DesktopMagicPluginAPI.Drawing.GraphicsExtentions.DrawStringMonospace(System.Drawing.Graphics,System.String,System.Drawing.Font,System.Drawing.Brush,System.Drawing.PointF)') - [DrawStringMonospace(graphics,s,font,brush,point)](#M-DesktopMagicPluginAPI-Drawing-GraphicsExtentions-DrawStringMonospace-System-Drawing-Graphics,System-String,System-Drawing-Font,System-Drawing-Brush,System-Drawing-PointF- 'DesktopMagicPluginAPI.Drawing.GraphicsExtentions.DrawStringMonospace(System.Drawing.Graphics,System.String,System.Drawing.Font,System.Drawing.Brush,System.Drawing.PointF)')
- [DrawStringNoLeftPadding(graphics,s,font,brush,x,y)](#M-DesktopMagicPluginAPI-Drawing-GraphicsExtentions-DrawStringNoLeftPadding-System-Drawing-Graphics,System-String,System-Drawing-Font,System-Drawing-Brush,System-Single,System-Single- 'DesktopMagicPluginAPI.Drawing.GraphicsExtentions.DrawStringNoLeftPadding(System.Drawing.Graphics,System.String,System.Drawing.Font,System.Drawing.Brush,System.Single,System.Single)')
- [DrawStringNoLeftPadding(graphics,s,font,brush,point)](#M-DesktopMagicPluginAPI-Drawing-GraphicsExtentions-DrawStringNoLeftPadding-System-Drawing-Graphics,System-String,System-Drawing-Font,System-Drawing-Brush,System-Drawing-PointF- 'DesktopMagicPluginAPI.Drawing.GraphicsExtentions.DrawStringNoLeftPadding(System.Drawing.Graphics,System.String,System.Drawing.Font,System.Drawing.Brush,System.Drawing.PointF)')
- [MeasureStringNoLeftPadding(graphics,text,font)](#M-DesktopMagicPluginAPI-Drawing-GraphicsExtentions-MeasureStringNoLeftPadding-System-Drawing-Graphics,System-String,System-Drawing-Font- 'DesktopMagicPluginAPI.Drawing.GraphicsExtentions.MeasureStringNoLeftPadding(System.Drawing.Graphics,System.String,System.Drawing.Font)')
- [IPluginData](#T-DesktopMagicPluginAPI-IPluginData 'DesktopMagicPluginAPI.IPluginData') - [IPluginData](#T-DesktopMagicPluginAPI-IPluginData 'DesktopMagicPluginAPI.IPluginData')
- [Color](#P-DesktopMagicPluginAPI-IPluginData-Color 'DesktopMagicPluginAPI.IPluginData.Color') - [Color](#P-DesktopMagicPluginAPI-IPluginData-Color 'DesktopMagicPluginAPI.IPluginData.Color')
- [Font](#P-DesktopMagicPluginAPI-IPluginData-Font 'DesktopMagicPluginAPI.IPluginData.Font') - [Font](#P-DesktopMagicPluginAPI-IPluginData-Font 'DesktopMagicPluginAPI.IPluginData.Font')
@@ -36,6 +39,7 @@
- [BackgroundColor](#P-DesktopMagicPluginAPI-ITheme-BackgroundColor 'DesktopMagicPluginAPI.ITheme.BackgroundColor') - [BackgroundColor](#P-DesktopMagicPluginAPI-ITheme-BackgroundColor 'DesktopMagicPluginAPI.ITheme.BackgroundColor')
- [CornerRadius](#P-DesktopMagicPluginAPI-ITheme-CornerRadius 'DesktopMagicPluginAPI.ITheme.CornerRadius') - [CornerRadius](#P-DesktopMagicPluginAPI-ITheme-CornerRadius 'DesktopMagicPluginAPI.ITheme.CornerRadius')
- [Font](#P-DesktopMagicPluginAPI-ITheme-Font 'DesktopMagicPluginAPI.ITheme.Font') - [Font](#P-DesktopMagicPluginAPI-ITheme-Font 'DesktopMagicPluginAPI.ITheme.Font')
- [Margin](#P-DesktopMagicPluginAPI-ITheme-Margin 'DesktopMagicPluginAPI.ITheme.Margin')
- [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')
- [IntegerUpDown](#T-DesktopMagicPluginAPI-Inputs-IntegerUpDown 'DesktopMagicPluginAPI.Inputs.IntegerUpDown') - [IntegerUpDown](#T-DesktopMagicPluginAPI-Inputs-IntegerUpDown 'DesktopMagicPluginAPI.Inputs.IntegerUpDown')
@@ -60,6 +64,7 @@
- [OnMouseMove(position)](#M-DesktopMagicPluginAPI-Plugin-OnMouseMove-System-Drawing-Point- 'DesktopMagicPluginAPI.Plugin.OnMouseMove(System.Drawing.Point)') - [OnMouseMove(position)](#M-DesktopMagicPluginAPI-Plugin-OnMouseMove-System-Drawing-Point- 'DesktopMagicPluginAPI.Plugin.OnMouseMove(System.Drawing.Point)')
- [OnMouseWheel(position,delta)](#M-DesktopMagicPluginAPI-Plugin-OnMouseWheel-System-Drawing-Point,System-Int32- 'DesktopMagicPluginAPI.Plugin.OnMouseWheel(System.Drawing.Point,System.Int32)') - [OnMouseWheel(position,delta)](#M-DesktopMagicPluginAPI-Plugin-OnMouseWheel-System-Drawing-Point,System-Int32- 'DesktopMagicPluginAPI.Plugin.OnMouseWheel(System.Drawing.Point,System.Int32)')
- [Start()](#M-DesktopMagicPluginAPI-Plugin-Start 'DesktopMagicPluginAPI.Plugin.Start') - [Start()](#M-DesktopMagicPluginAPI-Plugin-Start 'DesktopMagicPluginAPI.Plugin.Start')
- [Stop()](#M-DesktopMagicPluginAPI-Plugin-Stop 'DesktopMagicPluginAPI.Plugin.Stop')
- [RenderQuality](#T-DesktopMagicPluginAPI-Drawing-RenderQuality 'DesktopMagicPluginAPI.Drawing.RenderQuality') - [RenderQuality](#T-DesktopMagicPluginAPI-Drawing-RenderQuality 'DesktopMagicPluginAPI.Drawing.RenderQuality')
- [High](#F-DesktopMagicPluginAPI-Drawing-RenderQuality-High 'DesktopMagicPluginAPI.Drawing.RenderQuality.High') - [High](#F-DesktopMagicPluginAPI-Drawing-RenderQuality-High 'DesktopMagicPluginAPI.Drawing.RenderQuality.High')
- [Low](#F-DesktopMagicPluginAPI-Drawing-RenderQuality-Low 'DesktopMagicPluginAPI.Drawing.RenderQuality.Low') - [Low](#F-DesktopMagicPluginAPI-Drawing-RenderQuality-Low 'DesktopMagicPluginAPI.Drawing.RenderQuality.Low')
@@ -240,14 +245,14 @@ DesktopMagicPluginAPI.Drawing
##### Summary ##### Summary
Extentions for the [Graphics](http://msdn.microsoft.com/query/dev14.query?appId=Dev14IDEF1&l=EN-US&k=k:System.Drawing.Graphics 'System.Drawing.Graphics') class. Extensions for the [Graphics](http://msdn.microsoft.com/query/dev14.query?appId=Dev14IDEF1&l=EN-US&k=k:System.Drawing.Graphics 'System.Drawing.Graphics') class.
<a name='M-DesktopMagicPluginAPI-Drawing-GraphicsExtentions-DrawStringFixedWidth-System-Drawing-Graphics,System-String,System-Drawing-Font,System-Drawing-Brush,System-Single,System-Single,System-Single-'></a> <a name='M-DesktopMagicPluginAPI-Drawing-GraphicsExtentions-DrawStringFixedWidth-System-Drawing-Graphics,System-String,System-Drawing-Font,System-Drawing-Brush,System-Single,System-Single,System-Single-'></a>
### DrawStringFixedWidth(graphics,s,font,brush,x,y,width) `method` ### DrawStringFixedWidth(graphics,s,font,brush,x,y,width) `method`
##### Summary ##### Summary
Draws the specified text string at the specified location with the specified [Brush](http://msdn.microsoft.com/query/dev14.query?appId=Dev14IDEF1&l=EN-US&k=k:System.Drawing.Brush 'System.Drawing.Brush') and [Font](http://msdn.microsoft.com/query/dev14.query?appId=Dev14IDEF1&l=EN-US&k=k:System.Drawing.Font 'System.Drawing.Font') objects.
##### Parameters ##### Parameters
@@ -266,7 +271,7 @@ Draws the specified text string at the specified location with the specified [Br
##### Summary ##### Summary
Draws the specified text string at the specified location with the specified [Brush](http://msdn.microsoft.com/query/dev14.query?appId=Dev14IDEF1&l=EN-US&k=k:System.Drawing.Brush 'System.Drawing.Brush') and [Font](http://msdn.microsoft.com/query/dev14.query?appId=Dev14IDEF1&l=EN-US&k=k:System.Drawing.Font 'System.Drawing.Font') objects.
##### Parameters ##### Parameters
@@ -284,7 +289,7 @@ Draws the specified text string at the specified location with the specified [Br
##### Summary ##### Summary
Draws the specified text string at the specified location with the specified [Brush](http://msdn.microsoft.com/query/dev14.query?appId=Dev14IDEF1&l=EN-US&k=k:System.Drawing.Brush 'System.Drawing.Brush') and [Font](http://msdn.microsoft.com/query/dev14.query?appId=Dev14IDEF1&l=EN-US&k=k:System.Drawing.Font 'System.Drawing.Font') objects.
##### Parameters ##### Parameters
@@ -302,7 +307,7 @@ Draws the specified text string at the specified location with the specified [Br
##### Summary ##### Summary
Draws the specified text string at the specified location with the specified [Brush](http://msdn.microsoft.com/query/dev14.query?appId=Dev14IDEF1&l=EN-US&k=k:System.Drawing.Brush 'System.Drawing.Brush') and [Font](http://msdn.microsoft.com/query/dev14.query?appId=Dev14IDEF1&l=EN-US&k=k:System.Drawing.Font 'System.Drawing.Font') objects.
##### Parameters ##### Parameters
@@ -314,6 +319,60 @@ Draws the specified text string at the specified location with the specified [Br
| brush | [System.Drawing.Brush](http://msdn.microsoft.com/query/dev14.query?appId=Dev14IDEF1&l=EN-US&k=k:System.Drawing.Brush 'System.Drawing.Brush') | [Brush](http://msdn.microsoft.com/query/dev14.query?appId=Dev14IDEF1&l=EN-US&k=k:System.Drawing.Brush 'System.Drawing.Brush') that determines the color and texture of the drawn text. | | brush | [System.Drawing.Brush](http://msdn.microsoft.com/query/dev14.query?appId=Dev14IDEF1&l=EN-US&k=k:System.Drawing.Brush 'System.Drawing.Brush') | [Brush](http://msdn.microsoft.com/query/dev14.query?appId=Dev14IDEF1&l=EN-US&k=k:System.Drawing.Brush 'System.Drawing.Brush') that determines the color and texture of the drawn text. |
| point | [System.Drawing.PointF](http://msdn.microsoft.com/query/dev14.query?appId=Dev14IDEF1&l=EN-US&k=k:System.Drawing.PointF 'System.Drawing.PointF') | [PointF](http://msdn.microsoft.com/query/dev14.query?appId=Dev14IDEF1&l=EN-US&k=k:System.Drawing.PointF 'System.Drawing.PointF') structure that specifies the upper-left corner of the drawn text. | | point | [System.Drawing.PointF](http://msdn.microsoft.com/query/dev14.query?appId=Dev14IDEF1&l=EN-US&k=k:System.Drawing.PointF 'System.Drawing.PointF') | [PointF](http://msdn.microsoft.com/query/dev14.query?appId=Dev14IDEF1&l=EN-US&k=k:System.Drawing.PointF 'System.Drawing.PointF') structure that specifies the upper-left corner of the drawn text. |
<a name='M-DesktopMagicPluginAPI-Drawing-GraphicsExtentions-DrawStringNoLeftPadding-System-Drawing-Graphics,System-String,System-Drawing-Font,System-Drawing-Brush,System-Single,System-Single-'></a>
### DrawStringNoLeftPadding(graphics,s,font,brush,x,y) `method`
##### Summary
##### Parameters
| Name | Type | Description |
| ---- | ---- | ----------- |
| graphics | [System.Drawing.Graphics](http://msdn.microsoft.com/query/dev14.query?appId=Dev14IDEF1&l=EN-US&k=k:System.Drawing.Graphics 'System.Drawing.Graphics') | Graphics object. |
| s | [System.String](http://msdn.microsoft.com/query/dev14.query?appId=Dev14IDEF1&l=EN-US&k=k:System.String 'System.String') | String to draw. |
| font | [System.Drawing.Font](http://msdn.microsoft.com/query/dev14.query?appId=Dev14IDEF1&l=EN-US&k=k:System.Drawing.Font 'System.Drawing.Font') | [Font](http://msdn.microsoft.com/query/dev14.query?appId=Dev14IDEF1&l=EN-US&k=k:System.Drawing.Font 'System.Drawing.Font') that defines the text format of the string. |
| brush | [System.Drawing.Brush](http://msdn.microsoft.com/query/dev14.query?appId=Dev14IDEF1&l=EN-US&k=k:System.Drawing.Brush 'System.Drawing.Brush') | [Brush](http://msdn.microsoft.com/query/dev14.query?appId=Dev14IDEF1&l=EN-US&k=k:System.Drawing.Brush 'System.Drawing.Brush') that determines the color and texture of the drawn text. |
| x | [System.Single](http://msdn.microsoft.com/query/dev14.query?appId=Dev14IDEF1&l=EN-US&k=k:System.Single 'System.Single') | The x-coordinate of the upper-left corner of the drawn text. |
| y | [System.Single](http://msdn.microsoft.com/query/dev14.query?appId=Dev14IDEF1&l=EN-US&k=k:System.Single 'System.Single') | The y-coordinate of the upper-left corner of the drawn text. |
<a name='M-DesktopMagicPluginAPI-Drawing-GraphicsExtentions-DrawStringNoLeftPadding-System-Drawing-Graphics,System-String,System-Drawing-Font,System-Drawing-Brush,System-Drawing-PointF-'></a>
### DrawStringNoLeftPadding(graphics,s,font,brush,point) `method`
##### Summary
##### Parameters
| Name | Type | Description |
| ---- | ---- | ----------- |
| graphics | [System.Drawing.Graphics](http://msdn.microsoft.com/query/dev14.query?appId=Dev14IDEF1&l=EN-US&k=k:System.Drawing.Graphics 'System.Drawing.Graphics') | Graphics object. |
| s | [System.String](http://msdn.microsoft.com/query/dev14.query?appId=Dev14IDEF1&l=EN-US&k=k:System.String 'System.String') | String to draw. |
| font | [System.Drawing.Font](http://msdn.microsoft.com/query/dev14.query?appId=Dev14IDEF1&l=EN-US&k=k:System.Drawing.Font 'System.Drawing.Font') | [Font](http://msdn.microsoft.com/query/dev14.query?appId=Dev14IDEF1&l=EN-US&k=k:System.Drawing.Font 'System.Drawing.Font') that defines the text format of the string. |
| brush | [System.Drawing.Brush](http://msdn.microsoft.com/query/dev14.query?appId=Dev14IDEF1&l=EN-US&k=k:System.Drawing.Brush 'System.Drawing.Brush') | [Brush](http://msdn.microsoft.com/query/dev14.query?appId=Dev14IDEF1&l=EN-US&k=k:System.Drawing.Brush 'System.Drawing.Brush') that determines the color and texture of the drawn text. |
| point | [System.Drawing.PointF](http://msdn.microsoft.com/query/dev14.query?appId=Dev14IDEF1&l=EN-US&k=k:System.Drawing.PointF 'System.Drawing.PointF') | [PointF](http://msdn.microsoft.com/query/dev14.query?appId=Dev14IDEF1&l=EN-US&k=k:System.Drawing.PointF 'System.Drawing.PointF') structure that specifies the upper-left corner of the drawn text. |
<a name='M-DesktopMagicPluginAPI-Drawing-GraphicsExtentions-MeasureStringNoLeftPadding-System-Drawing-Graphics,System-String,System-Drawing-Font-'></a>
### MeasureStringNoLeftPadding(graphics,text,font) `method`
##### Summary
##### Returns
##### Parameters
| Name | Type | Description |
| ---- | ---- | ----------- |
| graphics | [System.Drawing.Graphics](http://msdn.microsoft.com/query/dev14.query?appId=Dev14IDEF1&l=EN-US&k=k:System.Drawing.Graphics 'System.Drawing.Graphics') | Graphics object. |
| text | [System.String](http://msdn.microsoft.com/query/dev14.query?appId=Dev14IDEF1&l=EN-US&k=k:System.String 'System.String') | String to measure. |
| font | [System.Drawing.Font](http://msdn.microsoft.com/query/dev14.query?appId=Dev14IDEF1&l=EN-US&k=k:System.Drawing.Font 'System.Drawing.Font') | [Font](http://msdn.microsoft.com/query/dev14.query?appId=Dev14IDEF1&l=EN-US&k=k:System.Drawing.Font 'System.Drawing.Font') that defines the text format of the string. |
<a name='T-DesktopMagicPluginAPI-IPluginData'></a> <a name='T-DesktopMagicPluginAPI-IPluginData'></a>
## IPluginData `type` ## IPluginData `type`
@@ -417,6 +476,13 @@ Gets the corner radius of the current theme.
Gets the font of the current theme. Gets the font of the current theme.
<a name='P-DesktopMagicPluginAPI-ITheme-Margin'></a>
### Margin `property`
##### Summary
Gets the corner radius of the current theme.
<a name='P-DesktopMagicPluginAPI-ITheme-PrimaryColor'></a> <a name='P-DesktopMagicPluginAPI-ITheme-PrimaryColor'></a>
### PrimaryColor `property` ### PrimaryColor `property`
@@ -654,6 +720,17 @@ Occurs once when the plugin gets activated.
This method has no parameters. This method has no parameters.
<a name='M-DesktopMagicPluginAPI-Plugin-Stop'></a>
### Stop() `method`
##### Summary
Occurs once when the plugin gets deactivated.
##### Parameters
This method has no parameters.
<a name='T-DesktopMagicPluginAPI-Drawing-RenderQuality'></a> <a name='T-DesktopMagicPluginAPI-Drawing-RenderQuality'></a>
## RenderQuality `type` ## RenderQuality `type`
@@ -6,12 +6,12 @@
<members> <members>
<member name="T:DesktopMagicPluginAPI.Drawing.GraphicsExtentions"> <member name="T:DesktopMagicPluginAPI.Drawing.GraphicsExtentions">
<summary> <summary>
Extentions for the <see cref="T:System.Drawing.Graphics"/> class. Extensions for the <see cref="T:System.Drawing.Graphics"/> class.
</summary> </summary>
</member> </member>
<member name="M:DesktopMagicPluginAPI.Drawing.GraphicsExtentions.DrawStringMonospace(System.Drawing.Graphics,System.String,System.Drawing.Font,System.Drawing.Brush,System.Single,System.Single)"> <member name="M:DesktopMagicPluginAPI.Drawing.GraphicsExtentions.DrawStringMonospace(System.Drawing.Graphics,System.String,System.Drawing.Font,System.Drawing.Brush,System.Single,System.Single)">
<summary> <summary>
Draws the specified text string at the specified location with the specified <see cref="T:System.Drawing.Brush"/> and <see cref="T:System.Drawing.Font"/> objects. <inheritdoc cref="M:System.Drawing.Graphics.DrawString(System.String,System.Drawing.Font,System.Drawing.Brush,System.Single,System.Single)"/>
</summary> </summary>
<param name="graphics">Graphics object.</param> <param name="graphics">Graphics object.</param>
<param name="s">String to draw.</param> <param name="s">String to draw.</param>
@@ -22,7 +22,7 @@
</member> </member>
<member name="M:DesktopMagicPluginAPI.Drawing.GraphicsExtentions.DrawStringMonospace(System.Drawing.Graphics,System.String,System.Drawing.Font,System.Drawing.Brush,System.Drawing.PointF)"> <member name="M:DesktopMagicPluginAPI.Drawing.GraphicsExtentions.DrawStringMonospace(System.Drawing.Graphics,System.String,System.Drawing.Font,System.Drawing.Brush,System.Drawing.PointF)">
<summary> <summary>
Draws the specified text string at the specified location with the specified <see cref="T:System.Drawing.Brush"/> and <see cref="T:System.Drawing.Font"/> objects. <inheritdoc cref="M:System.Drawing.Graphics.DrawString(System.String,System.Drawing.Font,System.Drawing.Brush,System.Drawing.PointF)"/>
</summary> </summary>
<param name="graphics">Graphics object.</param> <param name="graphics">Graphics object.</param>
<param name="s">String to draw.</param> <param name="s">String to draw.</param>
@@ -32,7 +32,7 @@
</member> </member>
<member name="M:DesktopMagicPluginAPI.Drawing.GraphicsExtentions.DrawStringFixedWidth(System.Drawing.Graphics,System.String,System.Drawing.Font,System.Drawing.Brush,System.Single,System.Single,System.Single)"> <member name="M:DesktopMagicPluginAPI.Drawing.GraphicsExtentions.DrawStringFixedWidth(System.Drawing.Graphics,System.String,System.Drawing.Font,System.Drawing.Brush,System.Single,System.Single,System.Single)">
<summary> <summary>
Draws the specified text string at the specified location with the specified <see cref="T:System.Drawing.Brush"/> and <see cref="T:System.Drawing.Font"/> objects. <inheritdoc cref="M:System.Drawing.Graphics.DrawString(System.String,System.Drawing.Font,System.Drawing.Brush,System.Single,System.Single)"/>
</summary> </summary>
<param name="graphics">Graphics object.</param> <param name="graphics">Graphics object.</param>
<param name="s">String to draw.</param> <param name="s">String to draw.</param>
@@ -44,7 +44,7 @@
</member> </member>
<member name="M:DesktopMagicPluginAPI.Drawing.GraphicsExtentions.DrawStringFixedWidth(System.Drawing.Graphics,System.String,System.Drawing.Font,System.Drawing.Brush,System.Drawing.PointF,System.Single)"> <member name="M:DesktopMagicPluginAPI.Drawing.GraphicsExtentions.DrawStringFixedWidth(System.Drawing.Graphics,System.String,System.Drawing.Font,System.Drawing.Brush,System.Drawing.PointF,System.Single)">
<summary> <summary>
Draws the specified text string at the specified location with the specified <see cref="T:System.Drawing.Brush"/> and <see cref="T:System.Drawing.Font"/> objects. <inheritdoc cref="M:System.Drawing.Graphics.DrawString(System.String,System.Drawing.Font,System.Drawing.Brush,System.Drawing.PointF)"/>
</summary> </summary>
<param name="graphics">Graphics object.</param> <param name="graphics">Graphics object.</param>
<param name="s">String to draw.</param> <param name="s">String to draw.</param>
@@ -53,6 +53,36 @@
<param name="point"><see cref="T:System.Drawing.PointF"/> structure that specifies the upper-left corner of the drawn text.</param> <param name="point"><see cref="T:System.Drawing.PointF"/> structure that specifies the upper-left corner of the drawn text.</param>
<param name="width">The specified width.</param> <param name="width">The specified width.</param>
</member> </member>
<member name="M:DesktopMagicPluginAPI.Drawing.GraphicsExtentions.DrawStringNoLeftPadding(System.Drawing.Graphics,System.String,System.Drawing.Font,System.Drawing.Brush,System.Single,System.Single)">
<summary>
<inheritdoc cref="M:System.Drawing.Graphics.DrawString(System.String,System.Drawing.Font,System.Drawing.Brush,System.Single,System.Single)"/>
</summary>
<param name="graphics">Graphics object.</param>
<param name="s">String to draw.</param>
<param name="font"><see cref="T:System.Drawing.Font"/> that defines the text format of the string.</param>
<param name="brush"><see cref="T:System.Drawing.Brush"/> that determines the color and texture of the drawn text.</param>
<param name="x">The x-coordinate of the upper-left corner of the drawn text.</param>
<param name="y">The y-coordinate of the upper-left corner of the drawn text.</param>
</member>
<member name="M:DesktopMagicPluginAPI.Drawing.GraphicsExtentions.DrawStringNoLeftPadding(System.Drawing.Graphics,System.String,System.Drawing.Font,System.Drawing.Brush,System.Drawing.PointF)">
<summary>
<inheritdoc cref="M:System.Drawing.Graphics.DrawString(System.String,System.Drawing.Font,System.Drawing.Brush,System.Drawing.PointF)"/>
</summary>
<param name="graphics">Graphics object.</param>
<param name="s">String to draw.</param>
<param name="font"><see cref="T:System.Drawing.Font"/> that defines the text format of the string.</param>
<param name="brush"><see cref="T:System.Drawing.Brush"/> that determines the color and texture of the drawn text.</param>
<param name="point"><see cref="T:System.Drawing.PointF"/> structure that specifies the upper-left corner of the drawn text.</param>
</member>
<member name="M:DesktopMagicPluginAPI.Drawing.GraphicsExtentions.MeasureStringNoLeftPadding(System.Drawing.Graphics,System.String,System.Drawing.Font)">
<summary>
<inheritdoc cref="M:System.Drawing.Graphics.MeasureString(System.String,System.Drawing.Font)"/>
</summary>
<param name="graphics">Graphics object.</param>
<param name="text">String to measure.</param>
<param name="font"><see cref="T:System.Drawing.Font"/> that defines the text format of the string.</param>
<returns></returns>
</member>
<member name="T:DesktopMagicPluginAPI.Drawing.RenderQuality"> <member name="T:DesktopMagicPluginAPI.Drawing.RenderQuality">
<summary> <summary>
Specifies which render quality is used to display the bitmap images. Specifies which render quality is used to display the bitmap images.
@@ -351,6 +381,11 @@
Gets the corner radius of the current theme. Gets the corner radius of the current theme.
</summary> </summary>
</member> </member>
<member name="P:DesktopMagicPluginAPI.ITheme.Margin">
<summary>
Gets the corner radius of the current theme.
</summary>
</member>
<member name="T:DesktopMagicPluginAPI.Plugin"> <member name="T:DesktopMagicPluginAPI.Plugin">
<summary> <summary>
The plugin class. The plugin class.
@@ -376,6 +411,11 @@
Occurs once when the plugin gets activated. Occurs once when the plugin gets activated.
</summary> </summary>
</member> </member>
<member name="M:DesktopMagicPluginAPI.Plugin.Stop">
<summary>
Occurs once when the plugin gets deactivated.
</summary>
</member>
<member name="M:DesktopMagicPluginAPI.Plugin.Main"> <member name="M:DesktopMagicPluginAPI.Plugin.Main">
<summary> <summary>
Occurs when the <see cref="P:DesktopMagicPluginAPI.Plugin.UpdateInterval"/> elapses. Occurs when the <see cref="P:DesktopMagicPluginAPI.Plugin.UpdateInterval"/> elapses.
@@ -5,14 +5,14 @@ using System.Drawing;
namespace DesktopMagicPluginAPI.Drawing namespace DesktopMagicPluginAPI.Drawing
{ {
/// <summary> /// <summary>
/// Extentions for the <see cref="Graphics"/> class. /// Extensions for the <see cref="Graphics"/> class.
/// </summary> /// </summary>
public static class GraphicsExtentions public static class GraphicsExtentions
{ {
private static readonly Dictionary<Font, int> fonts = new Dictionary<Font, int>(new FontComparer()); private static readonly Dictionary<Font, int> fonts = new Dictionary<Font, int>(new FontComparer());
/// <summary> /// <summary>
/// Draws the specified text string at the specified location with the specified <see cref="Brush"/> and <see cref="Font"/> objects. /// <inheritdoc cref="Graphics.DrawString(string?, Font, Brush, float, float)"/>
/// </summary> /// </summary>
/// <param name="graphics">Graphics object.</param> /// <param name="graphics">Graphics object.</param>
/// <param name="s">String to draw.</param> /// <param name="s">String to draw.</param>
@@ -22,7 +22,7 @@ namespace DesktopMagicPluginAPI.Drawing
/// <param name="y">The y-coordinate of the upper-left corner of the drawn text.</param> /// <param name="y">The y-coordinate of the upper-left corner of the drawn text.</param>
public static void DrawStringMonospace(this Graphics graphics, string s, Font font, Brush brush, float x, float y) public static void DrawStringMonospace(this Graphics graphics, string s, Font font, Brush brush, float x, float y)
{ {
int widest = GetWidestChar(font); int widest = graphics.GetWidestChar(font);
for (int i = 0; i < s.Length; i++) for (int i = 0; i < s.Length; i++)
{ {
@@ -33,7 +33,7 @@ namespace DesktopMagicPluginAPI.Drawing
} }
/// <summary> /// <summary>
/// Draws the specified text string at the specified location with the specified <see cref="Brush"/> and <see cref="Font"/> objects. /// <inheritdoc cref="Graphics.DrawString(string?, Font, Brush, PointF)"/>
/// </summary> /// </summary>
/// <param name="graphics">Graphics object.</param> /// <param name="graphics">Graphics object.</param>
/// <param name="s">String to draw.</param> /// <param name="s">String to draw.</param>
@@ -42,7 +42,7 @@ namespace DesktopMagicPluginAPI.Drawing
/// <param name="point"><see cref="PointF"/> structure that specifies the upper-left corner of the drawn text.</param> /// <param name="point"><see cref="PointF"/> structure that specifies the upper-left corner of the drawn text.</param>
public static void DrawStringMonospace(this Graphics graphics, string s, Font font, Brush brush, PointF point) public static void DrawStringMonospace(this Graphics graphics, string s, Font font, Brush brush, PointF point)
{ {
int widest = GetWidestChar(font); int widest = graphics.GetWidestChar(font);
for (int i = 0; i < s.Length; i++) for (int i = 0; i < s.Length; i++)
{ {
@@ -53,7 +53,7 @@ namespace DesktopMagicPluginAPI.Drawing
} }
/// <summary> /// <summary>
/// Draws the specified text string at the specified location with the specified <see cref="Brush"/> and <see cref="Font"/> objects. /// <inheritdoc cref="Graphics.DrawString(string?, Font, Brush, float, float)"/>
/// </summary> /// </summary>
/// <param name="graphics">Graphics object.</param> /// <param name="graphics">Graphics object.</param>
/// <param name="s">String to draw.</param> /// <param name="s">String to draw.</param>
@@ -73,7 +73,7 @@ namespace DesktopMagicPluginAPI.Drawing
} }
/// <summary> /// <summary>
/// Draws the specified text string at the specified location with the specified <see cref="Brush"/> and <see cref="Font"/> objects. /// <inheritdoc cref="Graphics.DrawString(string?, Font, Brush, PointF)"/>
/// </summary> /// </summary>
/// <param name="graphics">Graphics object.</param> /// <param name="graphics">Graphics object.</param>
/// <param name="s">String to draw.</param> /// <param name="s">String to draw.</param>
@@ -91,12 +91,76 @@ namespace DesktopMagicPluginAPI.Drawing
} }
} }
private static int GetWidestChar(Font font) /// <summary>
///<inheritdoc cref="Graphics.DrawString(string?, Font, Brush, float, float)"/>
/// </summary>
/// <param name="graphics">Graphics object.</param>
/// <param name="s">String to draw.</param>
/// <param name="font"><see cref="Font"/> that defines the text format of the string.</param>
/// <param name="brush"><see cref="Brush"/> that determines the color and texture of the drawn text.</param>
/// <param name="x">The x-coordinate of the upper-left corner of the drawn text.</param>
/// <param name="y">The y-coordinate of the upper-left corner of the drawn text.</param>
public static void DrawStringNoLeftPadding(this Graphics graphics, string s, Font font, Brush brush, float x, float y)
{
// measure left padding
StringFormat sf = new StringFormat(StringFormatFlags.NoClip);
sf.SetMeasurableCharacterRanges(new CharacterRange[] { new CharacterRange(0, 1) });
Region[] r = graphics.MeasureCharacterRanges(s, font, new RectangleF(0, 0, 1000, 100), sf);
float leftPadding = r[0].GetBounds(graphics).Left;
// draw string
sf = new StringFormat(StringFormatFlags.NoClip);
graphics.DrawString(s, font, brush, x - leftPadding, y, sf);
}
/// <summary>
/// <inheritdoc cref="Graphics.DrawString(string?, Font, Brush, PointF)"/>
/// </summary>
/// <param name="graphics">Graphics object.</param>
/// <param name="s">String to draw.</param>
/// <param name="font"><see cref="Font"/> that defines the text format of the string.</param>
/// <param name="brush"><see cref="Brush"/> that determines the color and texture of the drawn text.</param>
/// <param name="point"><see cref="PointF"/> structure that specifies the upper-left corner of the drawn text.</param>
public static void DrawStringNoLeftPadding(this Graphics graphics, string s, Font font, Brush brush, PointF point)
{
// measure left padding
StringFormat sf = new StringFormat(StringFormatFlags.NoClip);
sf.SetMeasurableCharacterRanges(new CharacterRange[] { new CharacterRange(0, 1) });
Region[] r = graphics.MeasureCharacterRanges(s, font, new RectangleF(0, 0, 1000, 100), sf);
float leftPadding = r[0].GetBounds(graphics).Left;
// draw string
sf = new StringFormat(StringFormatFlags.NoClip);
graphics.DrawString(s, font, brush, point.X - leftPadding, point.Y, sf);
}
/// <summary>
/// <inheritdoc cref="Graphics.MeasureString(string, Font)"/>
/// </summary>
/// <param name="graphics">Graphics object.</param>
/// <param name="text">String to measure.</param>
/// <param name="font"><see cref="Font"/> that defines the text format of the string.</param>
/// <returns></returns>
public static SizeF MeasureStringNoLeftPadding(this Graphics graphics, string text, Font font)
{
SizeF size = graphics.MeasureString(text, font, int.MaxValue);
StringFormat sf = new StringFormat(StringFormatFlags.NoClip);
sf.SetMeasurableCharacterRanges(new CharacterRange[] { new CharacterRange(0, 1) });
Region[] r = graphics.MeasureCharacterRanges(text, font, new RectangleF(0, 0, 1000, 100), sf);
float leftPadding = r[0].GetBounds(graphics).Left;
size.Width -= leftPadding / 1.5f;
return size;
}
private static int GetWidestChar(this Graphics graphics, Font font)
{ {
if (fonts.ContainsKey(font)) if (fonts.ContainsKey(font))
{
return fonts[font]; return fonts[font];
}
Graphics graphics = Graphics.FromImage(new Bitmap(1, 1));
float max = 0; float max = 0;
char maxx = ' '; char maxx = ' ';
for (int i = 0; i <= 255; i++) for (int i = 0; i <= 255; i++)
+5
View File
@@ -31,5 +31,10 @@ namespace DesktopMagicPluginAPI
/// Gets the corner radius of the current theme. /// Gets the corner radius of the current theme.
/// </summary> /// </summary>
int CornerRadius { get; } int CornerRadius { get; }
/// <summary>
/// Gets the corner radius of the current theme.
/// </summary>
int Margin { get; }
} }
} }
+7
View File
@@ -49,6 +49,13 @@ namespace DesktopMagicPluginAPI
{ {
} }
/// <summary>
/// Occurs once when the plugin gets deactivated.
/// </summary>
public virtual void Stop()
{
}
/// <summary> /// <summary>
/// Occurs when the <see cref="UpdateInterval"/> elapses. /// Occurs when the <see cref="UpdateInterval"/> elapses.
/// </summary> /// </summary>