- 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">
<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}"/>
<Border x:Name="border"/>
<Viewbox x:Name="viewBox" StretchDirection="Both" Stretch="Uniform">
<Viewbox.Clip>
<RectangleGeometry x:Name="rectangleGeometry" RadiusX="{Binding ElementName=border, Path=CornerRadius.TopLeft}" RadiusY="{Binding ElementName=border, Path=CornerRadius.TopLeft}" Rect="{Binding ElementName=border}"/>
</Viewbox.Clip>
<DockPanel x:Name="dockPanel">
<TextBlock x:Name="textBlock" FontSize="999" Foreground="White" Text="CPU: " IsHitTestVisible="False" />
<TextBlock x:Name="valueTextBlock" FontSize="999" TextAlignment="Right" Foreground="White" Text="000%" IsHitTestVisible="False" />
<TextBlock x:Name="textBlock" Foreground="White" FontSize="100" Text="CPU: " IsHitTestVisible="False" />
<TextBlock x:Name="valueTextBlock" TextAlignment="Right" FontSize="100" Foreground="White" Text="000%" IsHitTestVisible="False" />
</DockPanel>
</Viewbox>
</Grid>
@@ -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);
@@ -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 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<FftEventArgs>(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();
}
}
}
@@ -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");
_ = 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;
window?.Exit();
+10 -2
View File
@@ -46,7 +46,7 @@
</DockPanel>
<DockPanel Grid.Column="1" Margin="2.5,0,0,0">
<ComboBox x:Name="optionsComboBox" DockPanel.Dock="Top" Height="24" SelectedIndex="0" DisplayMemberPath="Item1" SelectionChanged="OptionsComboBox_SelectionChanged" Background="#FFECECEC" Padding="4" VerticalAlignment="Center"/>
<ComboBox x:Name="optionsComboBox" DockPanel.Dock="Top" Height="24" SelectedIndex="0" SelectionChanged="OptionsComboBox_SelectionChanged" Background="#FFECECEC" Padding="4" VerticalAlignment="Center"/>
<ScrollViewer Background="#FFBBBBBB">
<Grid>
<StackPanel x:Name="optionsPanel" Margin="3,3,3,0" HorizontalAlignment="Stretch" Visibility="Collapsed" >
@@ -86,13 +86,21 @@
<Grid.RowDefinitions>
<RowDefinition Height="Auto"/>
<RowDefinition Height="Auto"/>
<RowDefinition Height="Auto"/>
</Grid.RowDefinitions>
<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" />
<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>
<Style TargetType="TextBlock" />
</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.Plugins;
@@ -46,7 +47,7 @@ namespace DesktopMagic
#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>();
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 = () =>
{
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 = optionsComboBox.Items.IndexOf(new Tuple<string, int>(checkBox.Content.ToString(), 0));
pluginWindow.PluginLoaded -= onPluginLoaded;
optionsComboBox.SelectedIndex = optionsComboBox.Items.IndexOf(checkBox.Content.ToString());
window.PluginLoaded -= onPluginLoaded;
});
};
pluginWindow.OnExit += () =>
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<string, int>(checkBox.Content.ToString(), 0));
}
window.PluginLoaded += onPluginLoaded;
window.ShowInTaskbar = false;
window.Show();
@@ -282,10 +276,19 @@ namespace DesktopMagic
{
int index = WindowNames.IndexOf(window.Title);
if (index >= 0)
{
//Not sure how to handle this
try
{
Windows[index].Close();
Windows.RemoveAt(index);
WindowNames.RemoveAt(index);
window.Close();
//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<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)
{
_ = 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, int>((string)FindResource("musicVisualizer"), 0));
_ = optionsComboBox.Items.Add((string)FindResource("musicVisualizer"));
IEnumerable<CheckBox> list = stackPanel.Children.OfType<CheckBox>();
bool showWindow = true;
+2 -2
View File
@@ -17,10 +17,10 @@
<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}"/>
<Border x:Name="border"/>
<Viewbox x:Name="viewBox" StretchDirection="Both" Stretch="Uniform">
<Viewbox.Clip>
<RectangleGeometry x:Name="rectangleGeometry" RadiusX="{Binding ElementName=border, Path=CornerRadius.TopLeft}" RadiusY="{Binding ElementName=border, Path=CornerRadius.TopLeft}" Rect="{Binding ElementName=border}"/>
<RectangleGeometry x:Name="rectangleGeometry" RadiusX="{Binding ElementName=border, Path=CornerRadius.TopLeft}" RadiusY="{Binding ElementName=border, Path=CornerRadius.TopLeft}"/>
</Viewbox.Clip>
<Image x:Name="image" HorizontalAlignment="Left" RenderOptions.EdgeMode="Aliased" Margin="0,0,0,0" VerticalAlignment="Top" RenderTransformOrigin="0.5,0.5" Stretch="Uniform" MouseDown="Window_MouseDown" MouseMove="Window_MouseMove" MouseWheel="Window_MouseWheel"/>
</Viewbox>
+33 -14
View File
@@ -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);
}
@@ -125,6 +135,8 @@ namespace DesktopMagic
}
private void LoadPlugin()
{
if (pluginClassInstance is null)
{
PluginFolderPath = $"{Environment.GetFolderPath(Environment.SpecialFolder.ApplicationData)}\\{App.AppName}\\Plugins\\{PluginName}";
@@ -134,6 +146,7 @@ namespace DesktopMagic
Exit();
return;
}
}
try
{
@@ -150,6 +163,9 @@ namespace DesktopMagic
}
private void ExecuteSource()
{
object instance = pluginClassInstance;
if (instance is null)
{
byte[] assemblyBytes = File.ReadAllBytes($"{PluginFolderPath}\\{PluginName}.dll");
Assembly dll = Assembly.Load(assemblyBytes);
@@ -162,7 +178,8 @@ namespace DesktopMagic
return;
}
object instance = Activator.CreateInstance(instanceType);
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;
+1
View File
@@ -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;
@@ -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.
<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`
##### 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. |
<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>
## IPluginData `type`
@@ -417,6 +476,13 @@ Gets the corner radius 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>
### PrimaryColor `property`
@@ -654,6 +720,17 @@ Occurs once when the plugin gets activated.
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>
## RenderQuality `type`
@@ -6,12 +6,12 @@
<members>
<member name="T:DesktopMagicPluginAPI.Drawing.GraphicsExtentions">
<summary>
Extentions for the <see cref="T:System.Drawing.Graphics"/> class.
Extensions for the <see cref="T:System.Drawing.Graphics"/> class.
</summary>
</member>
<member name="M:DesktopMagicPluginAPI.Drawing.GraphicsExtentions.DrawStringMonospace(System.Drawing.Graphics,System.String,System.Drawing.Font,System.Drawing.Brush,System.Single,System.Single)">
<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>
<param name="graphics">Graphics object.</param>
<param name="s">String to draw.</param>
@@ -22,7 +22,7 @@
</member>
<member name="M:DesktopMagicPluginAPI.Drawing.GraphicsExtentions.DrawStringMonospace(System.Drawing.Graphics,System.String,System.Drawing.Font,System.Drawing.Brush,System.Drawing.PointF)">
<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>
<param name="graphics">Graphics object.</param>
<param name="s">String to draw.</param>
@@ -32,7 +32,7 @@
</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)">
<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>
<param name="graphics">Graphics object.</param>
<param name="s">String to draw.</param>
@@ -44,7 +44,7 @@
</member>
<member name="M:DesktopMagicPluginAPI.Drawing.GraphicsExtentions.DrawStringFixedWidth(System.Drawing.Graphics,System.String,System.Drawing.Font,System.Drawing.Brush,System.Drawing.PointF,System.Single)">
<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>
<param name="graphics">Graphics object.</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="width">The specified width.</param>
</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">
<summary>
Specifies which render quality is used to display the bitmap images.
@@ -351,6 +381,11 @@
Gets the corner radius of the current theme.
</summary>
</member>
<member name="P:DesktopMagicPluginAPI.ITheme.Margin">
<summary>
Gets the corner radius of the current theme.
</summary>
</member>
<member name="T:DesktopMagicPluginAPI.Plugin">
<summary>
The plugin class.
@@ -376,6 +411,11 @@
Occurs once when the plugin gets activated.
</summary>
</member>
<member name="M:DesktopMagicPluginAPI.Plugin.Stop">
<summary>
Occurs once when the plugin gets deactivated.
</summary>
</member>
<member name="M:DesktopMagicPluginAPI.Plugin.Main">
<summary>
Occurs when the <see cref="P:DesktopMagicPluginAPI.Plugin.UpdateInterval"/> elapses.
@@ -5,14 +5,14 @@ using System.Drawing;
namespace DesktopMagicPluginAPI.Drawing
{
/// <summary>
/// Extentions for the <see cref="Graphics"/> class.
/// Extensions for the <see cref="Graphics"/> class.
/// </summary>
public static class GraphicsExtentions
{
private static readonly Dictionary<Font, int> fonts = new Dictionary<Font, int>(new FontComparer());
/// <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>
/// <param name="graphics">Graphics object.</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>
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
}
/// <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>
/// <param name="graphics">Graphics object.</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>
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
}
/// <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>
/// <param name="graphics">Graphics object.</param>
/// <param name="s">String to draw.</param>
@@ -73,7 +73,7 @@ namespace DesktopMagicPluginAPI.Drawing
}
/// <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>
/// <param name="graphics">Graphics object.</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))
{
return fonts[font];
}
Graphics graphics = Graphics.FromImage(new Bitmap(1, 1));
float max = 0;
char maxx = ' ';
for (int i = 0; i <= 255; i++)
+5
View File
@@ -31,5 +31,10 @@ namespace DesktopMagicPluginAPI
/// Gets the corner radius of the current theme.
/// </summary>
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>
/// Occurs when the <see cref="UpdateInterval"/> elapses.
/// </summary>