From 2f6662caea892606a49bb2c6cc526642a349b45e Mon Sep 17 00:00:00 2001
From: Stone-Red-Code <56473591+Stone-Red-Code@users.noreply.github.com>
Date: Fri, 29 Oct 2021 20:31:16 +0200
Subject: [PATCH] - 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
---
.../BuiltInWindowElements/CalendarWindow.xaml | 38 -----
.../CalendarWindow.xaml.cs | 154 ------------------
.../BuiltInWindowElements/CpuUsageWindow.xaml | 6 +-
.../CpuUsageWindow.xaml.cs | 3 +
.../BuiltInWindowElements/DatePlugin.cs | 50 ++++++
.../BuiltInWindowElements/DateWindow.xaml | 28 ----
.../BuiltInWindowElements/DateWindow.xaml.cs | 95 -----------
...indow.xaml.cs => MusicVisualizerPlugin.cs} | 136 ++--------------
.../MusicVisualizerWindow.xaml | 28 ----
.../BuiltInWindowElements/TimePlugin.cs | 51 ++++++
.../BuiltInWindowElements/TimeWindow.xaml | 27 ---
.../BuiltInWindowElements/TimeWindow.xaml.cs | 111 -------------
.../Helpers/SettingElementGenerator.cs | 2 +-
src/DesktopMagic/MainWindow.xaml | 12 +-
src/DesktopMagic/MainWindow.xaml.cs | 107 +++++++-----
src/DesktopMagic/Plugins/PluginWindow.xaml | 4 +-
src/DesktopMagic/Plugins/PluginWindow.xaml.cs | 77 +++++----
src/DesktopMagic/Plugins/Theme.cs | 1 +
.../DesktopMagicPluginAPI.md | 87 +++++++++-
.../DesktopMagicPluginAPI.xml | 50 +++++-
.../Drawing/GraphicsExtentions.cs | 82 +++++++++-
src/DesktopMagicPluginAPI/ITheme.cs | 5 +
src/DesktopMagicPluginAPI/Plugin.cs | 7 +
23 files changed, 463 insertions(+), 698 deletions(-)
delete mode 100644 src/DesktopMagic/BuiltInWindowElements/CalendarWindow.xaml
delete mode 100644 src/DesktopMagic/BuiltInWindowElements/CalendarWindow.xaml.cs
create mode 100644 src/DesktopMagic/BuiltInWindowElements/DatePlugin.cs
delete mode 100644 src/DesktopMagic/BuiltInWindowElements/DateWindow.xaml
delete mode 100644 src/DesktopMagic/BuiltInWindowElements/DateWindow.xaml.cs
rename src/DesktopMagic/BuiltInWindowElements/{MusicVisualizerWindow.xaml.cs => MusicVisualizerPlugin.cs} (62%)
delete mode 100644 src/DesktopMagic/BuiltInWindowElements/MusicVisualizerWindow.xaml
create mode 100644 src/DesktopMagic/BuiltInWindowElements/TimePlugin.cs
delete mode 100644 src/DesktopMagic/BuiltInWindowElements/TimeWindow.xaml
delete mode 100644 src/DesktopMagic/BuiltInWindowElements/TimeWindow.xaml.cs
diff --git a/src/DesktopMagic/BuiltInWindowElements/CalendarWindow.xaml b/src/DesktopMagic/BuiltInWindowElements/CalendarWindow.xaml
deleted file mode 100644
index 27c433c..0000000
--- a/src/DesktopMagic/BuiltInWindowElements/CalendarWindow.xaml
+++ /dev/null
@@ -1,38 +0,0 @@
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
\ No newline at end of file
diff --git a/src/DesktopMagic/BuiltInWindowElements/CalendarWindow.xaml.cs b/src/DesktopMagic/BuiltInWindowElements/CalendarWindow.xaml.cs
deleted file mode 100644
index 1c3c7af..0000000
--- a/src/DesktopMagic/BuiltInWindowElements/CalendarWindow.xaml.cs
+++ /dev/null
@@ -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 upcomingEventNames = new List();
- private List upcomingEventTimes = new List();
-
- 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;
- }
- }
-}
\ No newline at end of file
diff --git a/src/DesktopMagic/BuiltInWindowElements/CpuUsageWindow.xaml b/src/DesktopMagic/BuiltInWindowElements/CpuUsageWindow.xaml
index 59cad89..a1b19b6 100644
--- a/src/DesktopMagic/BuiltInWindowElements/CpuUsageWindow.xaml
+++ b/src/DesktopMagic/BuiltInWindowElements/CpuUsageWindow.xaml
@@ -14,14 +14,14 @@
x:Name="window">
-
+
-
-
+
+
diff --git a/src/DesktopMagic/BuiltInWindowElements/CpuUsageWindow.xaml.cs b/src/DesktopMagic/BuiltInWindowElements/CpuUsageWindow.xaml.cs
index 1ba4cc1..db0dcce 100644
--- a/src/DesktopMagic/BuiltInWindowElements/CpuUsageWindow.xaml.cs
+++ b/src/DesktopMagic/BuiltInWindowElements/CpuUsageWindow.xaml.cs
@@ -90,6 +90,9 @@ namespace DesktopMagic
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);
diff --git a/src/DesktopMagic/BuiltInWindowElements/DatePlugin.cs b/src/DesktopMagic/BuiltInWindowElements/DatePlugin.cs
new file mode 100644
index 0000000..06d6a57
--- /dev/null
+++ b/src/DesktopMagic/BuiltInWindowElements/DatePlugin.cs
@@ -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;
+ }
+ }
+}
\ No newline at end of file
diff --git a/src/DesktopMagic/BuiltInWindowElements/DateWindow.xaml b/src/DesktopMagic/BuiltInWindowElements/DateWindow.xaml
deleted file mode 100644
index 432daf9..0000000
--- a/src/DesktopMagic/BuiltInWindowElements/DateWindow.xaml
+++ /dev/null
@@ -1,28 +0,0 @@
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
\ No newline at end of file
diff --git a/src/DesktopMagic/BuiltInWindowElements/DateWindow.xaml.cs b/src/DesktopMagic/BuiltInWindowElements/DateWindow.xaml.cs
deleted file mode 100644
index 71fe0d9..0000000
--- a/src/DesktopMagic/BuiltInWindowElements/DateWindow.xaml.cs
+++ /dev/null
@@ -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;
- }
- }
-}
\ No newline at end of file
diff --git a/src/DesktopMagic/BuiltInWindowElements/MusicVisualizerWindow.xaml.cs b/src/DesktopMagic/BuiltInWindowElements/MusicVisualizerPlugin.cs
similarity index 62%
rename from src/DesktopMagic/BuiltInWindowElements/MusicVisualizerWindow.xaml.cs
rename to src/DesktopMagic/BuiltInWindowElements/MusicVisualizerPlugin.cs
index 37fea35..24216a0 100644
--- a/src/DesktopMagic/BuiltInWindowElements/MusicVisualizerWindow.xaml.cs
+++ b/src/DesktopMagic/BuiltInWindowElements/MusicVisualizerPlugin.cs
@@ -1,51 +1,24 @@
-using Microsoft.Win32;
+using DesktopMagicPluginAPI;
using NAudio.Wave;
using System;
using System.Collections.Generic;
using System.Drawing;
-using System.Drawing.Imaging;
-using System.Globalization;
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 static extern void SetParent(IntPtr hWndChild, IntPtr hWndNewParent);
-
- private readonly RegistryKey key;
- private readonly IWaveIn waveIn;
+ private IWaveIn waveIn;
private const int fftLength = 1024; // NAudio fft wants powers of two!
private readonly SampleAggregator sampleAggregator = new SampleAggregator(fftLength);
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(FftCalculated);
sampleAggregator.PerformFFT = true;
@@ -53,58 +26,6 @@ namespace DesktopMagic
waveIn.DataAvailable += OnDataAvailable;
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)
@@ -226,7 +147,6 @@ namespace DesktopMagic
lastFft = fft;
try
{
- Bitmap bm = new Bitmap(880, 300);
int offset = 0;
if (!MainWindow.MirrorMode && MainWindow.SpectrumMode != 1)
@@ -239,8 +159,9 @@ namespace DesktopMagic
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];
int fftIndex = 0;
@@ -260,8 +181,8 @@ namespace DesktopMagic
if (!fftIndexReverse)
{
- points[pointIndex + 1] = new PointF(bm.Width - (4 * pointIndex), (bm.Height / 2) + value);
- points[(points.Length / 2) + 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(output.Width - (4 * pointIndex), (output.Height / 2) - value);
}
break;
@@ -270,7 +191,7 @@ namespace DesktopMagic
break;
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;
}
@@ -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
? new SolidBrush(MainWindow.MusicVisualzerColor.Value)
@@ -316,10 +237,7 @@ namespace DesktopMagic
}
}
- _ = Dispatcher.BeginInvoke((Action)delegate
- {
- image.Source = BitmapToImageSource(bm);
- });
+ Application.UpdateWindow();
}
catch { }
}
@@ -348,33 +266,15 @@ namespace DesktopMagic
}
}
- private BitmapSource BitmapToImageSource(Bitmap bitmap)
+ public override Bitmap Main()
{
- BitmapData bitmapData = bitmap.LockBits(
- 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;
+ return output;
}
- private void Window_LocationChanged(object sender, EventArgs e)
+ public override void Stop()
{
- key.SetValue("MusicVisualizerWindowTop", Top);
- key.SetValue("MusicVisualizerWindowLeft", Left);
- }
-
- private void Window_SizeChanged(object sender, SizeChangedEventArgs e)
- {
- key.SetValue("MusicVisualizerWindowHeight", Height);
- key.SetValue("MusicVisualizerWindowWidth", Width);
- tileBar.CaptionHeight = ActualHeight - 10;
+ calculate = false;
+ waveIn?.StopRecording();
}
}
}
\ No newline at end of file
diff --git a/src/DesktopMagic/BuiltInWindowElements/MusicVisualizerWindow.xaml b/src/DesktopMagic/BuiltInWindowElements/MusicVisualizerWindow.xaml
deleted file mode 100644
index bca74e6..0000000
--- a/src/DesktopMagic/BuiltInWindowElements/MusicVisualizerWindow.xaml
+++ /dev/null
@@ -1,28 +0,0 @@
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
\ No newline at end of file
diff --git a/src/DesktopMagic/BuiltInWindowElements/TimePlugin.cs b/src/DesktopMagic/BuiltInWindowElements/TimePlugin.cs
new file mode 100644
index 0000000..ae45b58
--- /dev/null
+++ b/src/DesktopMagic/BuiltInWindowElements/TimePlugin.cs
@@ -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;
+ }
+ }
+}
\ No newline at end of file
diff --git a/src/DesktopMagic/BuiltInWindowElements/TimeWindow.xaml b/src/DesktopMagic/BuiltInWindowElements/TimeWindow.xaml
deleted file mode 100644
index b70eedd..0000000
--- a/src/DesktopMagic/BuiltInWindowElements/TimeWindow.xaml
+++ /dev/null
@@ -1,27 +0,0 @@
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
\ No newline at end of file
diff --git a/src/DesktopMagic/BuiltInWindowElements/TimeWindow.xaml.cs b/src/DesktopMagic/BuiltInWindowElements/TimeWindow.xaml.cs
deleted file mode 100644
index edc65b9..0000000
--- a/src/DesktopMagic/BuiltInWindowElements/TimeWindow.xaml.cs
+++ /dev/null
@@ -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;
- }
- }
-}
\ No newline at end of file
diff --git a/src/DesktopMagic/Helpers/SettingElementGenerator.cs b/src/DesktopMagic/Helpers/SettingElementGenerator.cs
index 50248ef..95e9362 100644
--- a/src/DesktopMagic/Helpers/SettingElementGenerator.cs
+++ b/src/DesktopMagic/Helpers/SettingElementGenerator.cs
@@ -199,7 +199,7 @@ namespace DesktopMagic.Helpers
{
App.Logger.Log(message, "PluginInput");
_ = MessageBox.Show("File execution error:\n" + message, "Error", MessageBoxButton.OK, MessageBoxImage.Error);
- int index = MainWindow.WindowNames.IndexOf(((Tuple)optionsComboBox.SelectedItem).Item1.ToString());
+ int index = MainWindow.WindowNames.IndexOf(optionsComboBox.SelectedItem.ToString());
PluginWindow window = MainWindow.Windows[index] as PluginWindow;
window?.Exit();
diff --git a/src/DesktopMagic/MainWindow.xaml b/src/DesktopMagic/MainWindow.xaml
index 9c998bc..1f0ff02 100644
--- a/src/DesktopMagic/MainWindow.xaml
+++ b/src/DesktopMagic/MainWindow.xaml
@@ -46,7 +46,7 @@
-
+
@@ -86,13 +86,21 @@
+
-
+
+
+
+
+
+
+
+
diff --git a/src/DesktopMagic/MainWindow.xaml.cs b/src/DesktopMagic/MainWindow.xaml.cs
index 9c4549f..22fe8a5 100644
--- a/src/DesktopMagic/MainWindow.xaml.cs
+++ b/src/DesktopMagic/MainWindow.xaml.cs
@@ -1,4 +1,5 @@
-using DesktopMagic.Dialogs;
+using DesktopMagic.BuiltInWindowElements;
+using DesktopMagic.Dialogs;
using DesktopMagic.Helpers;
using DesktopMagic.Plugins;
@@ -46,7 +47,7 @@ namespace DesktopMagic
#endregion Plugins settings
- public static List Windows { get; } = new List();
+ public static List Windows { get; } = new List();
public static List WindowNames { get; } = new List();
private readonly RegistryKey key;
private readonly System.Windows.Forms.NotifyIcon notifyIcon = new();
@@ -199,75 +200,68 @@ namespace DesktopMagic
private void CheckBox_Click(object sender, RoutedEventArgs e)
{
CheckBox checkBox = (CheckBox)sender;
- Window window;
+ PluginWindow window = null;
blockWindowsClosing = false;
switch (checkBox.Name)
{
case "TimeCb":
- window = new TimeWindow();
+ window = new PluginWindow(new TimePlugin());
break;
case "DateCb":
- window = new DateWindow();
+ window = new PluginWindow(new DatePlugin());
break;
case "CpuUsageCb":
- window = new CpuUsageWindow();
+ //window = new PluginWindow();
break;
case "MusicVisualizerCb":
- window = new MusicVisualizerWindow();
+ window = new PluginWindow(new MusicVisualizerPlugin());
break;
default:
- if (checkBox.Name.Contains("_PluginCb_"))
- {
- window = new PluginWindow(checkBox.Content.ToString())
- {
- Title = checkBox.Content.ToString()
- };
- break;
- }
- else
+ if (!checkBox.Name.Contains("_PluginCb_"))
{
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(() =>
{
Dispatcher.Invoke(() =>
{
- if (window is PluginWindow pluginWindow)
+ Action onPluginLoaded = null;
+ onPluginLoaded = () =>
{
- Action onPluginLoaded = null;
- onPluginLoaded = () =>
+ Dispatcher.Invoke(() =>
{
- Dispatcher.Invoke(() =>
+ if (!optionsComboBox.Items.Contains(checkBox.Content.ToString()))
{
- if (!optionsComboBox.Items.Contains(new Tuple(checkBox.Content.ToString(), 0)))
- {
- _ = optionsComboBox.Items.Add(new Tuple(checkBox.Content.ToString(), 0));
- }
- optionsComboBox.SelectedIndex = -1;
- optionsComboBox.SelectedIndex = optionsComboBox.Items.IndexOf(new Tuple(checkBox.Content.ToString(), 0));
- pluginWindow.PluginLoaded -= onPluginLoaded;
- });
- };
- pluginWindow.OnExit += () =>
+ _ = optionsComboBox.Items.Add(checkBox.Content.ToString());
+ }
+ optionsComboBox.SelectedIndex = -1;
+ optionsComboBox.SelectedIndex = optionsComboBox.Items.IndexOf(checkBox.Content.ToString());
+ window.PluginLoaded -= onPluginLoaded;
+ });
+ };
+ window.OnExit += () =>
{
checkBox.IsChecked = false;
CheckBox_Click(checkBox, null);
};
- pluginWindow.PluginLoaded += onPluginLoaded;
- }
- else if (window is MusicVisualizerWindow musicVisualizerWindow)
- {
- optionsComboBox.SelectedIndex = optionsComboBox.Items.IndexOf(new Tuple(checkBox.Content.ToString(), 0));
- }
+ window.PluginLoaded += onPluginLoaded;
window.ShowInTaskbar = false;
window.Show();
@@ -282,10 +276,19 @@ namespace DesktopMagic
{
int index = WindowNames.IndexOf(window.Title);
- Windows[index].Close();
- Windows.RemoveAt(index);
- WindowNames.RemoveAt(index);
- window.Close();
+ if (index >= 0)
+ {
+ //Not sure how to handle this
+ try
+ {
+ Windows[index].Close();
+
+ Windows.RemoveAt(index);
+ WindowNames.RemoveAt(index);
+ //window.Close();
+ }
+ catch { }
+ }
}
key.SetValue(checkBox.Name, checkBox.IsChecked.ToString());
blockWindowsClosing = true;
@@ -447,7 +450,7 @@ namespace DesktopMagic
optionsPanel.Children.Clear();
optionsPanel.UpdateLayout();
- bool success = PluginsSettings.TryGetValue(((Tuple)optionsComboBox.SelectedItem).Item1.ToString(), out List settingElements);
+ bool success = PluginsSettings.TryGetValue(optionsComboBox.SelectedItem.ToString(), out List settingElements);
if (!success || settingElements?.Count == 0)
{
_ = 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
private void LayoutsComboBox_SelectionChanged(object sender, SelectionChangedEventArgs e)
@@ -685,6 +704,7 @@ namespace DesktopMagic
lineModeCheckBox.IsChecked = bool.Parse(key.GetValue("LineMode", "false").ToString());
musicVisualizerColorTextBox.Text = key.GetValue("MusicVisualizerColor", "").ToString();
cornerRadiusTextBox.Text = key.GetValue("CornerRadius", "0").ToString();
+ marginTextBox.Text = key.GetValue("Margin", "0").ToString();
blockWindowsClosing = false;
string primaryColorHex = key.GetValue("PrimaryColor", "#FFFFFFFF").ToString();
@@ -717,6 +737,7 @@ namespace DesktopMagic
SpectrumModeComboBox_SelectionChanged(null, null);
AmplifierLevelSlider_ValueChanged(null, null);
CornerRadiusTextBox_TextChanged(null, null);
+ MarginTextBox_TextChanged(null, null);
foreach (Window window in Windows)
{
@@ -730,7 +751,7 @@ namespace DesktopMagic
WindowNames.Clear();
optionsComboBox.Items.Clear();
- _ = optionsComboBox.Items.Add(new Tuple((string)FindResource("musicVisualizer"), 0));
+ _ = optionsComboBox.Items.Add((string)FindResource("musicVisualizer"));
IEnumerable list = stackPanel.Children.OfType();
bool showWindow = true;
diff --git a/src/DesktopMagic/Plugins/PluginWindow.xaml b/src/DesktopMagic/Plugins/PluginWindow.xaml
index 25c0ef6..d2cd1b9 100644
--- a/src/DesktopMagic/Plugins/PluginWindow.xaml
+++ b/src/DesktopMagic/Plugins/PluginWindow.xaml
@@ -17,10 +17,10 @@
-
+
-
+
diff --git a/src/DesktopMagic/Plugins/PluginWindow.xaml.cs b/src/DesktopMagic/Plugins/PluginWindow.xaml.cs
index cde49bd..5198894 100644
--- a/src/DesktopMagic/Plugins/PluginWindow.xaml.cs
+++ b/src/DesktopMagic/Plugins/PluginWindow.xaml.cs
@@ -27,9 +27,10 @@ namespace DesktopMagic
private readonly RegistryKey key;
private Thread pluginThread;
private System.Timers.Timer valueTimer;
- private bool stop = false;
private Plugin pluginClassInstance;
+
+ public bool IsRunning { get; private set; } = true;
public string PluginName { get; private set; }
public string PluginFolderPath { get; private set; }
@@ -69,6 +70,11 @@ namespace DesktopMagic
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)
{
base.OnSourceInitialized(e);
@@ -111,13 +117,17 @@ namespace DesktopMagic
tileBar.CaptionHeight = 0;
ResizeMode = ResizeMode.NoResize;
}
- if (stop)
+
+ if (!IsRunning)
{
((System.Timers.Timer)sender).Stop();
}
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.CornerRadius = new CornerRadius(MainWindow.Theme.CornerRadius);
}
@@ -126,13 +136,16 @@ namespace DesktopMagic
private void LoadPlugin()
{
- PluginFolderPath = $"{Environment.GetFolderPath(Environment.SpecialFolder.ApplicationData)}\\{App.AppName}\\Plugins\\{PluginName}";
-
- if (!File.Exists($"{PluginFolderPath}\\{PluginName}.dll"))
+ if (pluginClassInstance is null)
{
- _ = MessageBox.Show("File does not exist!", "Error", MessageBoxButton.OK, MessageBoxImage.Error);
- Exit();
- return;
+ PluginFolderPath = $"{Environment.GetFolderPath(Environment.SpecialFolder.ApplicationData)}\\{App.AppName}\\Plugins\\{PluginName}";
+
+ if (!File.Exists($"{PluginFolderPath}\\{PluginName}.dll"))
+ {
+ _ = MessageBox.Show("File does not exist!", "Error", MessageBoxButton.OK, MessageBoxImage.Error);
+ Exit();
+ return;
+ }
}
try
@@ -151,18 +164,22 @@ namespace DesktopMagic
private void ExecuteSource()
{
- byte[] assemblyBytes = File.ReadAllBytes($"{PluginFolderPath}\\{PluginName}.dll");
- Assembly dll = Assembly.Load(assemblyBytes);
- Type instanceType = dll.GetTypes().FirstOrDefault(type => type.GetTypeInfo().BaseType == typeof(Plugin));
-
- if (instanceType is null)
+ object instance = pluginClassInstance;
+ if (instance is null)
{
- _ = MessageBox.Show($"The \"Plugin\" class could not be found! It has to inherit from \"{typeof(Plugin).FullName}\"", "Error", MessageBoxButton.OK, MessageBoxImage.Error);
- Exit();
- return;
- }
+ byte[] assemblyBytes = File.ReadAllBytes($"{PluginFolderPath}\\{PluginName}.dll");
+ Assembly dll = Assembly.Load(assemblyBytes);
+ Type instanceType = dll.GetTypes().FirstOrDefault(type => type.GetTypeInfo().BaseType == typeof(Plugin));
- object instance = Activator.CreateInstance(instanceType);
+ if (instanceType is null)
+ {
+ _ = MessageBox.Show($"The \"Plugin\" class could not be found! It has to inherit from \"{typeof(Plugin).FullName}\"", "Error", MessageBoxButton.OK, MessageBoxImage.Error);
+ Exit();
+ return;
+ }
+
+ instance = Activator.CreateInstance(instanceType);
+ }
if (instance is Plugin)
{
pluginClassInstance = instance as Plugin;
@@ -226,7 +243,7 @@ namespace DesktopMagic
}
catch (Exception ex)
{
- stop = true;
+ IsRunning = false;
App.Logger.Log(ex.ToString(), "Plugin");
_ = MessageBox.Show("File execution error:\n" + ex, "Error", MessageBoxButton.OK, MessageBoxImage.Error);
Exit();
@@ -238,7 +255,7 @@ namespace DesktopMagic
{
try
{
- if (!stop)
+ if (IsRunning)
{
Bitmap result = pluginClassInstance.Main();
@@ -272,14 +289,14 @@ namespace DesktopMagic
}
catch (Exception ex)
{
- stop = true;
+ IsRunning = false;
App.Logger.Log(ex.ToString(), "Plugin");
_ = MessageBox.Show("File execution error:\n" + ex, "Error", MessageBoxButton.OK, MessageBoxImage.Error);
Exit();
return;
}
- if (stop)
+ if (!IsRunning)
{
valueTimer.Stop();
}
@@ -303,13 +320,20 @@ namespace DesktopMagic
public void Exit()
{
- stop = true;
+ IsRunning = false;
+
Dispatcher.Invoke(() =>
{
OnExit?.Invoke();
});
}
+ private void Window_Closing(object sender, System.ComponentModel.CancelEventArgs e)
+ {
+ pluginClassInstance?.Stop();
+ IsRunning = false;
+ }
+
#region Window Events
private void Window_LocationChanged(object sender, EventArgs e)
@@ -325,11 +349,6 @@ namespace DesktopMagic
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)
{
ImageSource imageSource = image.Source;
diff --git a/src/DesktopMagic/Plugins/Theme.cs b/src/DesktopMagic/Plugins/Theme.cs
index 0cd89fe..23d74bd 100644
--- a/src/DesktopMagic/Plugins/Theme.cs
+++ b/src/DesktopMagic/Plugins/Theme.cs
@@ -12,6 +12,7 @@ namespace DesktopMagic.Plugins
public string Font { get; set; } = "Segoe UI";
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 SecondaryBrush { get; set; } = System.Windows.Media.Brushes.White;
diff --git a/src/DesktopMagicPluginAPI/DesktopMagicPluginAPI.md b/src/DesktopMagicPluginAPI/DesktopMagicPluginAPI.md
index deaeb57..1d1c374 100644
--- a/src/DesktopMagicPluginAPI/DesktopMagicPluginAPI.md
+++ b/src/DesktopMagicPluginAPI/DesktopMagicPluginAPI.md
@@ -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)')
- [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)')
+ - [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')
- [Color](#P-DesktopMagicPluginAPI-IPluginData-Color 'DesktopMagicPluginAPI.IPluginData.Color')
- [Font](#P-DesktopMagicPluginAPI-IPluginData-Font 'DesktopMagicPluginAPI.IPluginData.Font')
@@ -36,6 +39,7 @@
- [BackgroundColor](#P-DesktopMagicPluginAPI-ITheme-BackgroundColor 'DesktopMagicPluginAPI.ITheme.BackgroundColor')
- [CornerRadius](#P-DesktopMagicPluginAPI-ITheme-CornerRadius 'DesktopMagicPluginAPI.ITheme.CornerRadius')
- [Font](#P-DesktopMagicPluginAPI-ITheme-Font 'DesktopMagicPluginAPI.ITheme.Font')
+ - [Margin](#P-DesktopMagicPluginAPI-ITheme-Margin 'DesktopMagicPluginAPI.ITheme.Margin')
- [PrimaryColor](#P-DesktopMagicPluginAPI-ITheme-PrimaryColor 'DesktopMagicPluginAPI.ITheme.PrimaryColor')
- [SecondaryColor](#P-DesktopMagicPluginAPI-ITheme-SecondaryColor 'DesktopMagicPluginAPI.ITheme.SecondaryColor')
- [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)')
- [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')
+ - [Stop()](#M-DesktopMagicPluginAPI-Plugin-Stop 'DesktopMagicPluginAPI.Plugin.Stop')
- [RenderQuality](#T-DesktopMagicPluginAPI-Drawing-RenderQuality 'DesktopMagicPluginAPI.Drawing.RenderQuality')
- [High](#F-DesktopMagicPluginAPI-Drawing-RenderQuality-High 'DesktopMagicPluginAPI.Drawing.RenderQuality.High')
- [Low](#F-DesktopMagicPluginAPI-Drawing-RenderQuality-Low 'DesktopMagicPluginAPI.Drawing.RenderQuality.Low')
@@ -240,14 +245,14 @@ DesktopMagicPluginAPI.Drawing
##### 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.
### DrawStringFixedWidth(graphics,s,font,brush,x,y,width) `method`
##### 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
@@ -266,7 +271,7 @@ Draws the specified text string at the specified location with the specified [Br
##### 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
@@ -284,7 +289,7 @@ Draws the specified text string at the specified location with the specified [Br
##### 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
@@ -302,7 +307,7 @@ Draws the specified text string at the specified location with the specified [Br
##### 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
@@ -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. |
| 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. |
+
+### 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. |
+
+
+### 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. |
+
+
+### 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. |
+
## IPluginData `type`
@@ -417,6 +476,13 @@ Gets the corner radius of the current theme.
Gets the font of the current theme.
+
+### Margin `property`
+
+##### Summary
+
+Gets the corner radius of the current theme.
+
### PrimaryColor `property`
@@ -654,6 +720,17 @@ Occurs once when the plugin gets activated.
This method has no parameters.
+
+### Stop() `method`
+
+##### Summary
+
+Occurs once when the plugin gets deactivated.
+
+##### Parameters
+
+This method has no parameters.
+
## RenderQuality `type`
diff --git a/src/DesktopMagicPluginAPI/DesktopMagicPluginAPI.xml b/src/DesktopMagicPluginAPI/DesktopMagicPluginAPI.xml
index fe9d03f..e5780db 100644
--- a/src/DesktopMagicPluginAPI/DesktopMagicPluginAPI.xml
+++ b/src/DesktopMagicPluginAPI/DesktopMagicPluginAPI.xml
@@ -6,12 +6,12 @@
- Extentions for the class.
+ Extensions for the class.
- Draws the specified text string at the specified location with the specified and objects.
+
Graphics object.
String to draw.
@@ -22,7 +22,7 @@
- Draws the specified text string at the specified location with the specified and objects.
+
Graphics object.
String to draw.
@@ -32,7 +32,7 @@
- Draws the specified text string at the specified location with the specified and objects.
+
Graphics object.
String to draw.
@@ -44,7 +44,7 @@
- Draws the specified text string at the specified location with the specified and objects.
+
Graphics object.
String to draw.
@@ -53,6 +53,36 @@
structure that specifies the upper-left corner of the drawn text.
The specified width.
+
+
+
+
+ Graphics object.
+ String to draw.
+ that defines the text format of the string.
+ that determines the color and texture of the drawn text.
+ The x-coordinate of the upper-left corner of the drawn text.
+ The y-coordinate of the upper-left corner of the drawn text.
+
+
+
+
+
+ Graphics object.
+ String to draw.
+ that defines the text format of the string.
+ that determines the color and texture of the drawn text.
+ structure that specifies the upper-left corner of the drawn text.
+
+
+
+
+
+ Graphics object.
+ String to measure.
+ that defines the text format of the string.
+
+
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.
+
+
The plugin class.
@@ -376,6 +411,11 @@
Occurs once when the plugin gets activated.
+
+
+ Occurs once when the plugin gets deactivated.
+
+
Occurs when the elapses.
diff --git a/src/DesktopMagicPluginAPI/Drawing/GraphicsExtentions.cs b/src/DesktopMagicPluginAPI/Drawing/GraphicsExtentions.cs
index af38757..a984bb4 100644
--- a/src/DesktopMagicPluginAPI/Drawing/GraphicsExtentions.cs
+++ b/src/DesktopMagicPluginAPI/Drawing/GraphicsExtentions.cs
@@ -5,14 +5,14 @@ using System.Drawing;
namespace DesktopMagicPluginAPI.Drawing
{
///
- /// Extentions for the class.
+ /// Extensions for the class.
///
public static class GraphicsExtentions
{
private static readonly Dictionary fonts = new Dictionary(new FontComparer());
///
- /// Draws the specified text string at the specified location with the specified and objects.
+ ///
///
/// Graphics object.
/// String to draw.
@@ -22,7 +22,7 @@ namespace DesktopMagicPluginAPI.Drawing
/// The y-coordinate of the upper-left corner of the drawn text.
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++)
{
@@ -33,7 +33,7 @@ namespace DesktopMagicPluginAPI.Drawing
}
///
- /// Draws the specified text string at the specified location with the specified and objects.
+ ///
///
/// Graphics object.
/// String to draw.
@@ -42,7 +42,7 @@ namespace DesktopMagicPluginAPI.Drawing
/// structure that specifies the upper-left corner of the drawn text.
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++)
{
@@ -53,7 +53,7 @@ namespace DesktopMagicPluginAPI.Drawing
}
///
- /// Draws the specified text string at the specified location with the specified and objects.
+ ///
///
/// Graphics object.
/// String to draw.
@@ -73,7 +73,7 @@ namespace DesktopMagicPluginAPI.Drawing
}
///
- /// Draws the specified text string at the specified location with the specified and objects.
+ ///
///
/// Graphics object.
/// String to draw.
@@ -91,12 +91,76 @@ namespace DesktopMagicPluginAPI.Drawing
}
}
- private static int GetWidestChar(Font font)
+ ///
+ ///
+ ///
+ /// Graphics object.
+ /// String to draw.
+ /// that defines the text format of the string.
+ /// that determines the color and texture of the drawn text.
+ /// The x-coordinate of the upper-left corner of the drawn text.
+ /// The y-coordinate of the upper-left corner of the drawn text.
+ 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);
+ }
+
+ ///
+ ///
+ ///
+ /// Graphics object.
+ /// String to draw.
+ /// that defines the text format of the string.
+ /// that determines the color and texture of the drawn text.
+ /// structure that specifies the upper-left corner of the drawn text.
+ 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);
+ }
+
+ ///
+ ///
+ ///
+ /// Graphics object.
+ /// String to measure.
+ /// that defines the text format of the string.
+ ///
+ 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))
+ {
return fonts[font];
+ }
- Graphics graphics = Graphics.FromImage(new Bitmap(1, 1));
float max = 0;
char maxx = ' ';
for (int i = 0; i <= 255; i++)
diff --git a/src/DesktopMagicPluginAPI/ITheme.cs b/src/DesktopMagicPluginAPI/ITheme.cs
index 4f61901..7d5f8f9 100644
--- a/src/DesktopMagicPluginAPI/ITheme.cs
+++ b/src/DesktopMagicPluginAPI/ITheme.cs
@@ -31,5 +31,10 @@ namespace DesktopMagicPluginAPI
/// Gets the corner radius of the current theme.
///
int CornerRadius { get; }
+
+ ///
+ /// Gets the corner radius of the current theme.
+ ///
+ int Margin { get; }
}
}
\ No newline at end of file
diff --git a/src/DesktopMagicPluginAPI/Plugin.cs b/src/DesktopMagicPluginAPI/Plugin.cs
index 5c0f235..a52aee4 100644
--- a/src/DesktopMagicPluginAPI/Plugin.cs
+++ b/src/DesktopMagicPluginAPI/Plugin.cs
@@ -49,6 +49,13 @@ namespace DesktopMagicPluginAPI
{
}
+ ///
+ /// Occurs once when the plugin gets deactivated.
+ ///
+ public virtual void Stop()
+ {
+ }
+
///
/// Occurs when the elapses.
///