Update project to .NET 8 and code improvements

This commit is contained in:
Stone_Red
2023-11-16 19:27:21 +01:00
parent adfedcb876
commit 2c883787f7
43 changed files with 2168 additions and 2790 deletions
@@ -1,50 +1,54 @@
using DesktopMagicPluginAPI; using DesktopMagicPluginAPI;
using DesktopMagicPluginAPI.Inputs;
using System; using System;
using System.Drawing; using System.Drawing;
using System.Drawing.Text; using System.Drawing.Text;
namespace DesktopMagic.BuiltInWindowElements namespace DesktopMagic.BuiltInWindowElements;
internal class DatePlugin : Plugin
{ {
internal class DatePlugin : Plugin [Element("Short date:")]
private readonly CheckBox shortDatecheckBox = new CheckBox(true);
private DateTime oldDateTime = DateTime.MinValue;
private Color oldColor = Color.White;
private string oldFont;
private bool oldShortDatecheckBoxValue;
public override int UpdateInterval => 1000;
public override Bitmap Main()
{ {
public override int UpdateInterval => 1000; if (oldDateTime.Date == DateTime.Now.Date && oldColor == Application.Theme.PrimaryColor && oldFont == Application.Theme.Font && oldShortDatecheckBoxValue == shortDatecheckBox.Value)
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;
{
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;
} }
oldDateTime = DateTime.Now;
oldColor = Application.Theme.PrimaryColor;
oldFont = Application.Theme.Font;
oldShortDatecheckBoxValue = shortDatecheckBox.Value;
string date = shortDatecheckBox.Value ? DateTime.Now.ToShortDateString() : 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,4 +1,6 @@
using DesktopMagicPluginAPI; using DesktopMagic.Helpers;
using DesktopMagicPluginAPI;
using NAudio.Wave; using NAudio.Wave;
@@ -7,279 +9,279 @@ using System.Collections.Generic;
using System.Drawing; using System.Drawing;
using System.Linq; using System.Linq;
namespace DesktopMagic.BuiltInWindowElements namespace DesktopMagic.BuiltInWindowElements;
internal class MusicVisualizerPlugin : Plugin
{ {
internal class MusicVisualizerPlugin : Plugin private const int fftLength = 1024;
// NAudio fft wants powers of two!
private readonly SampleAggregator sampleAggregator = new SampleAggregator(fftLength);
private readonly Bitmap output = new Bitmap(880, 300);
private WasapiLoopbackCapture waveIn;
private volatile bool calculate = true;
private List<double> lastFft = [];
public override int UpdateInterval => 0;
public override void Start()
{ {
private IWaveIn waveIn; sampleAggregator.FftCalculated += FftCalculated;
private const int fftLength = 1024; // NAudio fft wants powers of two! sampleAggregator.PerformFFT = true;
private readonly SampleAggregator sampleAggregator = new SampleAggregator(fftLength);
private volatile bool calculate = true;
private readonly Bitmap output = new Bitmap(880, 300);
public override int UpdateInterval => 0; waveIn = new WasapiLoopbackCapture();
public override void Start() waveIn.DataAvailable += OnDataAvailable;
waveIn.StartRecording();
}
public override Bitmap Main()
{
return output;
}
public override void Stop()
{
calculate = false;
waveIn?.StopRecording();
}
private void OnDataAvailable(object sender, WaveInEventArgs e)
{
if (calculate)
{ {
sampleAggregator.FftCalculated += FftCalculated; byte[] buffer = e.Buffer;
sampleAggregator.PerformFFT = true; int bytesRecorded = e.BytesRecorded;
int bufferIncrement = waveIn.WaveFormat.BlockAlign;
waveIn = new WasapiLoopbackCapture(); for (int index = 0; index < bytesRecorded; index += bufferIncrement)
{
float sample32 = BitConverter.ToSingle(buffer, index);
sampleAggregator.Add(sample32);
}
}
}
waveIn.DataAvailable += OnDataAvailable; private void FftCalculated(object sender, FftEventArgs e)
waveIn.StartRecording(); {
if (!calculate)
{
return;
} }
private void OnDataAvailable(object sender, WaveInEventArgs e) List<double> fft = [];
for (int i = 0; i < (e.Result.Length / 2) - 70; i++)
{ {
if (calculate) int v = i;
if (v < 20)
{ {
byte[] buffer = e.Buffer; v = 20;
int bytesRecorded = e.BytesRecorded; }
int bufferIncrement = waveIn.WaveFormat.BlockAlign;
for (int index = 0; index < bytesRecorded; index += bufferIncrement) int multiplier = 100 - (MainWindow.AmplifierLevel * 2);
multiplier = multiplier == 0 ? 1 : multiplier;
fft.Add(Math.Abs(e.Result[i].Y * v / multiplier));
}
if (lastFft.Count != 0)
{
for (int i = 0; i < fft.Count; i++)
{
if (fft[i] > lastFft[i])
{ {
float sample32 = BitConverter.ToSingle(buffer, index); fft[i] = (fft[i] + lastFft[i]) / 2.05;
sampleAggregator.Add(sample32); }
else
{
fft[i] = lastFft[i] - 0.0005;
} }
} }
} }
private List<double> lastFft = new List<double>(); int barCount = 0;
List<double> scaledFft = [];
private void FftCalculated(object sender, FftEventArgs e) if (barCount > 0)
{ {
if (!calculate) int count = fft.Count / barCount;
Console.WriteLine(count);
for (int i = 0; i < barCount; i++)
{ {
return; double temp = 0;
} int j;
for (j = i * count; j < count + (i * count); j++)
List<double> fft = new List<double>();
for (int i = 0; i < (e.Result.Length / 2) - 70; i++)
{
int v = i;
if (v < 20)
{ {
v = 20; temp += fft[j];
} }
int multiplier = 100 - (MainWindow.AmplifierLevel * 2); scaledFft.Add(temp);
multiplier = multiplier == 0 ? 1 : multiplier;
fft.Add(Math.Abs(e.Result[i].Y * v / multiplier));
} }
}
else
{
scaledFft.AddRange(fft);
}
if (lastFft.Count != 0) #region flatten
int flattenValue = 4;
for (int i = 0; i < scaledFft.Count; i++)
{
if (flattenValue > 0)
{ {
for (int i = 0; i < fft.Count; i++) double temp = 0;
for (int j = 0; j < flattenValue; j++)
{ {
if (fft[i] > lastFft[i]) if (i + j < scaledFft.Count)
{ {
fft[i] = (fft[i] + lastFft[i]) / 2.05; temp += scaledFft[i + j];
}
else
{
fft[i] = lastFft[i] - 0.0005;
} }
} }
scaledFft[i] = temp / flattenValue;
} }
}
int barCount = 0; for (int i = 0; i < scaledFft.Count; i++)
List<double> scaledFft = new List<double>(); {
if (flattenValue > 0)
if (barCount > 0)
{ {
int count = fft.Count / barCount; double temp = 0;
Console.WriteLine(count); for (int j = 0; j < flattenValue; j++)
for (int i = 0; i < barCount; i++)
{ {
double temp = 0; if (i - j >= 0)
int j;
for (j = i * count; j < count + (i * count); j++)
{ {
temp += fft[j]; temp += scaledFft[i - j];
} }
scaledFft.Add(temp);
} }
scaledFft[i] = temp / flattenValue;
} }
else }
#endregion flatten
lastFft = fft;
try
{
int offset = 0;
if (!MainWindow.MirrorMode && MainWindow.SpectrumMode != 1)
{ {
scaledFft.AddRange(fft); scaledFft.Insert(0, 0);
} }
#region flatten if (!MainWindow.LineMode)
int flattenValue = 4;
for (int i = 0; i < scaledFft.Count; i++)
{ {
if (flattenValue > 0) offset = 1;
}
using (Graphics gr = Graphics.FromImage(output))
{
gr.Clear(Color.Transparent);
PointF[] points = new PointF[scaledFft.Count + 2];
int fftIndex = 0;
bool fftIndexReverse = false;
if (MainWindow.MirrorMode || MainWindow.SpectrumMode == 1)
{ {
double temp = 0; fftIndex = scaledFft.Count - 1;
for (int j = 0; j < flattenValue; j++) }
for (int pointIndex = 0; pointIndex < scaledFft.Count; pointIndex += 1)
{
int value = (int)Math.Max(scaledFft[fftIndex] * 50000, 0);
switch (MainWindow.SpectrumMode)
{ {
if (i + j < scaledFft.Count) case 1:
{
temp += scaledFft[i + j]; if (!fftIndexReverse)
} {
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;
case 2:
points[pointIndex + 1] = new PointF(2 * pointIndex, value);
break;
default:
points[pointIndex + 1] = new PointF(2 * pointIndex, output.Height - value - 1 + offset);
break;
} }
scaledFft[i] = temp / flattenValue;
}
}
for (int i = 0; i < scaledFft.Count; i++)
{
if (flattenValue > 0)
{
double temp = 0;
for (int j = 0; j < flattenValue; j++)
{
if (i - j >= 0)
{
temp += scaledFft[i - j];
}
}
scaledFft[i] = temp / flattenValue;
}
}
#endregion flatten
lastFft = fft;
try
{
int offset = 0;
if (!MainWindow.MirrorMode && MainWindow.SpectrumMode != 1)
{
scaledFft.Insert(0, 0);
}
if (!MainWindow.LineMode)
{
offset = 1;
}
using (Graphics gr = Graphics.FromImage(output))
{
gr.Clear(Color.Transparent);
PointF[] points = new PointF[scaledFft.Count + 2];
int fftIndex = 0;
bool fftIndexReverse = false;
if (MainWindow.MirrorMode || MainWindow.SpectrumMode == 1) if (MainWindow.MirrorMode || MainWindow.SpectrumMode == 1)
{ {
fftIndex = scaledFft.Count - 1; if (!fftIndexReverse)
}
for (int pointIndex = 0; pointIndex < scaledFft.Count; pointIndex += 1)
{
int value = (int)Math.Max(scaledFft[fftIndex] * 50000, 0);
switch (MainWindow.SpectrumMode)
{ {
case 1: fftIndex -= 2;
if (!fftIndexReverse)
{
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;
case 2:
points[pointIndex + 1] = new PointF(2 * pointIndex, value);
break;
default:
points[pointIndex + 1] = new PointF(2 * pointIndex, output.Height - value - 1 + offset);
break;
} }
if (fftIndex <= 0 || fftIndexReverse)
if (MainWindow.MirrorMode || MainWindow.SpectrumMode == 1)
{ {
if (!fftIndexReverse) fftIndexReverse = true;
{ fftIndex += 2;
fftIndex -= 2;
}
if (fftIndex <= 0 || fftIndexReverse)
{
fftIndexReverse = true;
fftIndex += 2;
}
}
else
{
fftIndex++;
}
}
SetPoints(points, output.Width, output.Height, offset);
Brush brush = MainWindow.MusicVisualzerColor.HasValue
? new SolidBrush(MainWindow.MusicVisualzerColor.Value)
: new SolidBrush(MainWindow.Theme.PrimaryColor);
if (MainWindow.LineMode)
{
if (MainWindow.SpectrumMode == 1)
{
gr.DrawLines(new Pen(brush), points.Take(points.Length / 2).ToArray());
gr.DrawLines(new Pen(brush), points.Skip(points.Length / 2).ToArray());
}
else
{
gr.DrawLines(new Pen(brush), points);
} }
} }
else else
{ {
gr.FillPolygon(brush, points); fftIndex++;
} }
} }
Application.UpdateWindow(); SetPoints(points, output.Width, output.Height, offset);
}
catch (Exception ex) Brush brush = MainWindow.MusicVisualzerColor.HasValue
{ ? new SolidBrush(MainWindow.MusicVisualzerColor.Value)
App.Logger.Log(ex.Message, "Music Visualizer", LogSeverity.Error); : new SolidBrush(MainWindow.Theme.PrimaryColor);
if (MainWindow.LineMode)
{
if (MainWindow.SpectrumMode == 1)
{
gr.DrawLines(new Pen(brush), points.Take(points.Length / 2).ToArray());
gr.DrawLines(new Pen(brush), points.Skip(points.Length / 2).ToArray());
}
else
{
gr.DrawLines(new Pen(brush), points);
}
}
else
{
gr.FillPolygon(brush, points);
}
} }
Application.UpdateWindow();
} }
catch (Exception ex)
private void SetPoints(PointF[] points, int width, int height, int offset)
{ {
switch (MainWindow.SpectrumMode) App.Logger.Log(ex.Message, "Music Visualizer", LogSeverity.Error);
{
case 1:
points[0] = new PointF(width, height / 2);
points[^1] = new PointF(0, height / 2);
points[points.Length / 2] = new PointF(width, height / 2);
points[(points.Length / 2) - 1] = new PointF(0, height / 2);
break;
case 2:
points[0] = new PointF(0, 0 - offset);
points[^1] = new PointF(points[^2].X, 0 - offset);
break;
default:
points[0] = new PointF(0, height);
points[^1] = new PointF(points[^2].X, height);
break;
}
} }
}
public override Bitmap Main() private void SetPoints(PointF[] points, int width, int height, int offset)
{
switch (MainWindow.SpectrumMode)
{ {
return output; case 1:
} points[0] = new PointF(width, height / 2);
points[^1] = new PointF(0, height / 2);
public override void Stop() points[points.Length / 2] = new PointF(width, height / 2);
{ points[(points.Length / 2) - 1] = new PointF(0, height / 2);
calculate = false; break;
waveIn?.StopRecording();
case 2:
points[0] = new PointF(0, 0 - offset);
points[^1] = new PointF(points[^2].X, 0 - offset);
break;
default:
points[0] = new PointF(0, height);
points[^1] = new PointF(points[^2].X, height);
break;
} }
} }
} }
@@ -1,55 +1,40 @@
using DesktopMagicPluginAPI; using DesktopMagicPluginAPI;
using DesktopMagicPluginAPI.Drawing;
using DesktopMagicPluginAPI.Inputs; using DesktopMagicPluginAPI.Inputs;
using System; using System;
using System.Drawing; using System.Drawing;
using System.Drawing.Text; using System.Drawing.Text;
namespace DesktopMagic.BuiltInWindowElements namespace DesktopMagic.BuiltInWindowElements;
internal class TimePlugin : Plugin
{ {
internal class TimePlugin : Plugin [Element("Display Seconds:")]
private readonly CheckBox displaySecondscheckBox = new CheckBox(true);
public override int UpdateInterval => 1000;
public override Bitmap Main()
{ {
[Element("Display Seconds:")] string time = displaySecondscheckBox.Value ? DateTime.Now.ToLongTimeString() : DateTime.Now.ToShortTimeString();
private readonly CheckBox checkBox = new CheckBox(true);
public override int UpdateInterval => 1000; Font font = new Font(Application.Theme.Font, 200);
public override Bitmap Main() Bitmap bmp = new Bitmap(1, 1);
{ bmp.SetResolution(100, 100);
string time = checkBox.Value ? DateTime.Now.ToLongTimeString() : DateTime.Now.ToShortTimeString(); using Graphics tmpGr = Graphics.FromImage(bmp);
tmpGr.TextRenderingHint = TextRenderingHint.AntiAlias;
Font font = new Font(Application.Theme.Font, 200); SizeF size = tmpGr.MeasureString(time, font);
Bitmap bmp = new Bitmap(1, 1); bmp = new Bitmap((int)size.Width, (int)size.Height);
using Graphics tmpGr = Graphics.FromImage(bmp); bmp.SetResolution(100, 100);
tmpGr.TextRenderingHint = TextRenderingHint.AntiAlias;
SizeF size = CalculateSize(tmpGr, font); using Graphics gr = Graphics.FromImage(bmp);
bmp = new Bitmap((int)size.Width, (int)size.Height); gr.TextRenderingHint = TextRenderingHint.AntiAlias;
bmp.SetResolution(100, 100); gr.DrawString(time, font, new SolidBrush(Application.Theme.PrimaryColor), 0, 0);
using Graphics gr = Graphics.FromImage(bmp); return 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 = checkBox.Value ? "##:##:##" : "##:##";
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;
}
} }
} }
+6 -6
View File
@@ -12,7 +12,7 @@
<RepositoryUrl>https://github.com/Stone-Red-Code/DesktopMagic</RepositoryUrl> <RepositoryUrl>https://github.com/Stone-Red-Code/DesktopMagic</RepositoryUrl>
<AssemblyVersion>0.0.3.2</AssemblyVersion> <AssemblyVersion>0.0.3.2</AssemblyVersion>
<FileVersion>0.0.3.2</FileVersion> <FileVersion>0.0.3.2</FileVersion>
<TargetFramework>net6.0-windows</TargetFramework> <TargetFramework>net8.0-windows7.0</TargetFramework>
</PropertyGroup> </PropertyGroup>
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|AnyCPU'"> <PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|AnyCPU'">
@@ -27,12 +27,12 @@
<ItemGroup> <ItemGroup>
<PackageReference Include="AlwaysUpToDate" Version="1.0.0.4" /> <PackageReference Include="AlwaysUpToDate" Version="1.0.0.4" />
<PackageReference Include="Extended.Wpf.Toolkit" Version="4.1.0" /> <PackageReference Include="Extended.Wpf.Toolkit" Version="4.5.1" />
<PackageReference Include="Google.Apis.Calendar.v3" Version="1.55.0.2410" /> <PackageReference Include="Google.Apis.Calendar.v3" Version="1.64.0.3171" />
<PackageReference Include="MaterialDesignThemes" Version="4.0.0" /> <PackageReference Include="MaterialDesignThemes" Version="4.9.0" />
<PackageReference Include="NAudio" Version="2.0.1" /> <PackageReference Include="NAudio" Version="2.2.1" />
<PackageReference Include="Stone_Red-C-Sharp-Utilities" Version="1.0.3.1" /> <PackageReference Include="Stone_Red-C-Sharp-Utilities" Version="1.0.3.1" />
<PackageReference Include="System.Management" Version="5.0.0" /> <PackageReference Include="System.Management" Version="8.0.0" />
</ItemGroup> </ItemGroup>
<ItemGroup> <ItemGroup>
+100 -101
View File
@@ -6,123 +6,122 @@ using System.Windows;
using System.Windows.Controls; using System.Windows.Controls;
using System.Windows.Media; using System.Windows.Media;
namespace DesktopMagic.Dialogs namespace DesktopMagic.Dialogs;
/// <summary>
/// Interaction logic for ColorDialog.xaml
/// </summary>
public partial class ColorDialog : Window
{ {
/// <summary> public System.Drawing.Color ResultColor { get; private set; }
/// Interaction logic for ColorDialog.xaml
/// </summary> public Brush ResultBrush { get; private set; }
public partial class ColorDialog : Window
public ColorDialog(string content, System.Drawing.Color defaultColor, string title = "ColorDialog")
{ {
public ColorDialog(string content, System.Drawing.Color defaultColor, string title = "ColorDialog") InitializeComponent();
label.Content = content;
Title = title;
SetLanguageDictionary();
alphaSlider.Value = defaultColor.A;
redSlider.Value = defaultColor.R;
greenSlider.Value = defaultColor.G;
blueSlider.Value = defaultColor.B;
}
private void OkButton_Click(object sender, RoutedEventArgs e)
{
DialogResult = true;
}
private void CancelButton_Click(object sender, RoutedEventArgs e)
{
DialogResult = false;
}
private void ColorSliders_ValueChanged(object sender, RoutedPropertyChangedEventArgs<double> e)
{
colorHexTextBox.Select(colorHexTextBox.Text.Length, 0);
SetColorText();
}
private void ColorHexTextBox_TextChanged(object sender, TextChangedEventArgs e)
{
if (colorHexTextBox.Text.Length > 0)
{ {
InitializeComponent(); if (colorHexTextBox.Text[0] != '#')
label.Content = content;
Title = title;
SetLanguageDictionary();
alphaSlider.Value = defaultColor.A;
redSlider.Value = defaultColor.R;
greenSlider.Value = defaultColor.G;
blueSlider.Value = defaultColor.B;
}
public System.Drawing.Color ResultColor { get; private set; }
public Brush ResultBrush { get; private set; }
private void OkButton_Click(object sender, RoutedEventArgs e)
{
DialogResult = true;
}
private void CancelButton_Click(object sender, RoutedEventArgs e)
{
DialogResult = false;
}
private void ColorSliders_ValueChanged(object sender, RoutedPropertyChangedEventArgs<double> e)
{
colorHexTextBox.Select(colorHexTextBox.Text.Length, 0);
SetColorText();
}
private void ColorHexTextBox_TextChanged(object sender, TextChangedEventArgs e)
{
if (colorHexTextBox.Text.Length > 0)
{ {
if (colorHexTextBox.Text[0] != '#') colorHexTextBox.Text = "#" + colorHexTextBox.Text.Replace("#", "");
{
colorHexTextBox.Text = "#" + colorHexTextBox.Text.Replace("#", "");
}
} }
else }
else
{
colorHexTextBox.Text = "#";
colorHexTextBox.Select(colorHexTextBox.Text.Length, 0);
}
if (colorHexTextBox.SelectionStart == 0)
{
if (colorHexTextBox.Text.Length <= 2)
{ {
colorHexTextBox.Text = "#";
colorHexTextBox.Select(colorHexTextBox.Text.Length, 0); colorHexTextBox.Select(colorHexTextBox.Text.Length, 0);
} }
if (colorHexTextBox.SelectionStart == 0)
{
if (colorHexTextBox.Text.Length <= 2)
{
colorHexTextBox.Select(colorHexTextBox.Text.Length, 0);
}
else
{
colorHexTextBox.Select(1, 0);
}
}
string hex = colorHexTextBox.Text;
if (MultiColorConverter.TryConvertToMediaColor(hex, out Color color) && MultiColorConverter.TryConvertToSystemColor(hex, out System.Drawing.Color systemColor))
{
alphaSlider.Value = color.A;
redSlider.Value = color.R;
greenSlider.Value = color.G;
blueSlider.Value = color.B;
Brush brush = new SolidColorBrush(color);
ResultBrush = brush;
ResultColor = systemColor;
colorRechtangle.Fill = brush;
colorHexTextBox.Foreground = Brushes.Black;
}
else else
{ {
colorHexTextBox.Foreground = Brushes.Red; colorHexTextBox.Select(1, 0);
} }
} }
private void SetColorText() string hex = colorHexTextBox.Text;
{
if (alphaSlider.Value == 255)
{
colorHexTextBox.Text = "#";
}
else
{
colorHexTextBox.Text = "#" + ((int)alphaSlider.Value).ToString("X2");
}
colorHexTextBox.Text += ((int)redSlider.Value).ToString("X2") + ((int)greenSlider.Value).ToString("X2") + ((int)blueSlider.Value).ToString("X2"); if (MultiColorConverter.TryConvertToMediaColor(hex, out Color color) && MultiColorConverter.TryConvertToSystemColor(hex, out System.Drawing.Color systemColor))
{
alphaSlider.Value = color.A;
redSlider.Value = color.R;
greenSlider.Value = color.G;
blueSlider.Value = color.B;
Brush brush = new SolidColorBrush(color);
ResultBrush = brush;
ResultColor = systemColor;
colorRechtangle.Fill = brush;
colorHexTextBox.Foreground = Brushes.Black;
} }
else
private void SetLanguageDictionary()
{ {
ResourceDictionary dict = new ResourceDictionary(); colorHexTextBox.Foreground = Brushes.Red;
string currentCulture = Thread.CurrentThread.CurrentCulture.ToString();
if (currentCulture.Contains("de"))
{
dict.Source = new Uri("..\\Resources\\StringResources.de.xaml", UriKind.Relative);
}
else
{
dict.Source = new Uri("..\\Resources\\StringResources.en.xaml", UriKind.Relative);
}
Resources.MergedDictionaries.Add(dict);
} }
} }
private void SetColorText()
{
if (alphaSlider.Value == 255)
{
colorHexTextBox.Text = "#";
}
else
{
colorHexTextBox.Text = "#" + ((int)alphaSlider.Value).ToString("X2");
}
colorHexTextBox.Text += ((int)redSlider.Value).ToString("X2") + ((int)greenSlider.Value).ToString("X2") + ((int)blueSlider.Value).ToString("X2");
}
private void SetLanguageDictionary()
{
ResourceDictionary dict = [];
string currentCulture = Thread.CurrentThread.CurrentCulture.ToString();
if (currentCulture.Contains("de"))
{
dict.Source = new Uri("..\\Resources\\StringResources.de.xaml", UriKind.Relative);
}
else
{
dict.Source = new Uri("..\\Resources\\StringResources.en.xaml", UriKind.Relative);
}
Resources.MergedDictionaries.Add(dict);
}
} }
+34 -35
View File
@@ -2,48 +2,47 @@
using System.Threading; using System.Threading;
using System.Windows; using System.Windows;
namespace DesktopMagic.Dialogs namespace DesktopMagic.Dialogs;
public partial class InputDialog : Window
{ {
public partial class InputDialog : Window public string ResponseText
{ {
public InputDialog(string content, string title = "InputDialog") get => textBox.Text;
{ set => textBox.Text = value;
InitializeComponent(); }
label.Content = content;
Title = title;
SetLanguageDictionary();
}
public string ResponseText public InputDialog(string content, string title = "InputDialog")
{ {
get => textBox.Text; InitializeComponent();
set => textBox.Text = value; label.Content = content;
} Title = title;
SetLanguageDictionary();
}
private void OkButton_Click(object sender, RoutedEventArgs e) private void OkButton_Click(object sender, RoutedEventArgs e)
{ {
DialogResult = true; DialogResult = true;
} }
private void CancelButton_Click(object sender, RoutedEventArgs e) private void CancelButton_Click(object sender, RoutedEventArgs e)
{ {
DialogResult = false; DialogResult = false;
} }
private void SetLanguageDictionary() private void SetLanguageDictionary()
{ {
ResourceDictionary dict = new ResourceDictionary(); ResourceDictionary dict = [];
string currentCulture = Thread.CurrentThread.CurrentCulture.ToString(); string currentCulture = Thread.CurrentThread.CurrentCulture.ToString();
if (currentCulture.Contains("de")) if (currentCulture.Contains("de"))
{ {
dict.Source = new Uri("..\\Resources\\StringResources.de.xaml", UriKind.Relative); dict.Source = new Uri("..\\Resources\\StringResources.de.xaml", UriKind.Relative);
}
else
{
dict.Source = new Uri("..\\Resources\\StringResources.en.xaml", UriKind.Relative);
}
Resources.MergedDictionaries.Add(dict);
} }
else
{
dict.Source = new Uri("..\\Resources\\StringResources.en.xaml", UriKind.Relative);
}
Resources.MergedDictionaries.Add(dict);
} }
} }
+3 -1
View File
@@ -6,4 +6,6 @@
using System.Diagnostics.CodeAnalysis; using System.Diagnostics.CodeAnalysis;
[assembly: SuppressMessage("Interoperability", "CA1416:Validate platform compatibility", Justification = "Windows only application")] [assembly: SuppressMessage("Interoperability", "CA1416:Validate platform compatibility", Justification = "Windows only application")]
[assembly: SuppressMessage("Performance", "CA1822:Mark members as static", Justification = "No need to")] [assembly: SuppressMessage("Performance", "CA1822:Mark members as static", Justification = "No need to")]
[assembly: SuppressMessage("Minor Code Smell", "S1075:URIs should not be hardcoded", Justification = "<Pending>")]
[assembly: SuppressMessage("Minor Code Smell", "S3604:Member initializer values should not be redundant", Justification = "False postives")]
+70 -64
View File
@@ -1,76 +1,82 @@
using System.Globalization; using System;
using System.Globalization;
using System.Text.RegularExpressions; using System.Text.RegularExpressions;
namespace DesktopMagic.Helpers namespace DesktopMagic.Helpers;
internal static partial class MultiColorConverter
{ {
internal static class MultiColorConverter public static string ConvertToHex(System.Drawing.Color color)
{ {
public static string ConvertToHex(System.Drawing.Color color) return $"#{color.A:X2}{color.R:X2}{color.G:X2}{color.B:X2}";
}
public static string ConvertToHex(System.Windows.Media.Color color)
{
return $"#{color.A:X2}{color.R:X2}{color.G:X2}{color.B:X2}";
}
public static bool TryConvertToSystemColor(string hex, out System.Drawing.Color color)
{
hex = hex.Replace("#", "");
if (hex.Length == 8 && Hex8().IsMatch(hex))
{ {
return $"#{color.A:X2}{color.R:X2}{color.G:X2}{color.B:X2}"; int a = int.Parse(hex.AsSpan(0, 2), NumberStyles.HexNumber, CultureInfo.InvariantCulture);
int r = int.Parse(hex.AsSpan(2, 2), NumberStyles.HexNumber, CultureInfo.InvariantCulture);
int g = int.Parse(hex.AsSpan(4, 2), NumberStyles.HexNumber, CultureInfo.InvariantCulture);
int b = int.Parse(hex.AsSpan(6, 2), NumberStyles.HexNumber, CultureInfo.InvariantCulture);
color = System.Drawing.Color.FromArgb((byte)a, (byte)r, (byte)g, (byte)b);
return true;
} }
else if (hex.Length == 6 && Hex6().IsMatch(hex))
public static string ConvertToHex(System.Windows.Media.Color color)
{ {
return $"#{color.A:X2}{color.R:X2}{color.G:X2}{color.B:X2}"; int a = 255;
int r = int.Parse(hex.AsSpan(0, 2), NumberStyles.HexNumber, CultureInfo.InvariantCulture);
int g = int.Parse(hex.AsSpan(2, 2), NumberStyles.HexNumber, CultureInfo.InvariantCulture);
int b = int.Parse(hex.AsSpan(4, 2), NumberStyles.HexNumber, CultureInfo.InvariantCulture);
color = System.Drawing.Color.FromArgb((byte)a, (byte)r, (byte)g, (byte)b);
return true;
} }
else
public static bool TryConvertToSystemColor(string hex, out System.Drawing.Color color)
{ {
hex = hex.Replace("#", ""); color = System.Drawing.Color.Transparent;
return false;
if (hex.Length == 8 && Regex.IsMatch(hex, "(?:[0-9a-fA-F]{8})"))
{
int a = int.Parse(hex.Substring(0, 2), NumberStyles.HexNumber, CultureInfo.InvariantCulture);
int r = int.Parse(hex.Substring(2, 2), NumberStyles.HexNumber, CultureInfo.InvariantCulture);
int g = int.Parse(hex.Substring(4, 2), NumberStyles.HexNumber, CultureInfo.InvariantCulture);
int b = int.Parse(hex.Substring(6, 2), NumberStyles.HexNumber, CultureInfo.InvariantCulture);
color = System.Drawing.Color.FromArgb((byte)a, (byte)r, (byte)g, (byte)b);
return true;
}
else if (hex.Length == 6 && Regex.IsMatch(hex, "(?:[0-9a-fA-F]{6})"))
{
int a = 255;
int r = int.Parse(hex.Substring(0, 2), NumberStyles.HexNumber, CultureInfo.InvariantCulture);
int g = int.Parse(hex.Substring(2, 2), NumberStyles.HexNumber, CultureInfo.InvariantCulture);
int b = int.Parse(hex.Substring(4, 2), NumberStyles.HexNumber, CultureInfo.InvariantCulture);
color = System.Drawing.Color.FromArgb((byte)a, (byte)r, (byte)g, (byte)b);
return true;
}
else
{
color = System.Drawing.Color.Transparent;
return false;
}
}
public static bool TryConvertToMediaColor(string hex, out System.Windows.Media.Color color)
{
hex = hex.Replace("#", "");
if (hex.Length == 8 && Regex.IsMatch(hex, "(?:[0-9a-fA-F]{8})"))
{
int a = int.Parse(hex.Substring(0, 2), NumberStyles.HexNumber, CultureInfo.InvariantCulture);
int r = int.Parse(hex.Substring(2, 2), NumberStyles.HexNumber, CultureInfo.InvariantCulture);
int g = int.Parse(hex.Substring(4, 2), NumberStyles.HexNumber, CultureInfo.InvariantCulture);
int b = int.Parse(hex.Substring(6, 2), NumberStyles.HexNumber, CultureInfo.InvariantCulture);
color = System.Windows.Media.Color.FromArgb((byte)a, (byte)r, (byte)g, (byte)b);
return true;
}
else if (hex.Length == 6 && Regex.IsMatch(hex, "(?:[0-9a-fA-F]{6})"))
{
int a = 255;
int r = int.Parse(hex.Substring(0, 2), NumberStyles.HexNumber, CultureInfo.InvariantCulture);
int g = int.Parse(hex.Substring(2, 2), NumberStyles.HexNumber, CultureInfo.InvariantCulture);
int b = int.Parse(hex.Substring(4, 2), NumberStyles.HexNumber, CultureInfo.InvariantCulture);
color = System.Windows.Media.Color.FromArgb((byte)a, (byte)r, (byte)g, (byte)b);
return true;
}
else
{
color = System.Windows.Media.Colors.Transparent;
return false;
}
} }
} }
public static bool TryConvertToMediaColor(string hex, out System.Windows.Media.Color color)
{
hex = hex.Replace("#", "");
if (hex.Length == 8 && Hex8().IsMatch(hex))
{
int a = int.Parse(hex.AsSpan(0, 2), NumberStyles.HexNumber, CultureInfo.InvariantCulture);
int r = int.Parse(hex.AsSpan(2, 2), NumberStyles.HexNumber, CultureInfo.InvariantCulture);
int g = int.Parse(hex.AsSpan(4, 2), NumberStyles.HexNumber, CultureInfo.InvariantCulture);
int b = int.Parse(hex.AsSpan(6, 2), NumberStyles.HexNumber, CultureInfo.InvariantCulture);
color = System.Windows.Media.Color.FromArgb((byte)a, (byte)r, (byte)g, (byte)b);
return true;
}
else if (hex.Length == 6 && Hex6().IsMatch(hex))
{
int a = 255;
int r = int.Parse(hex.AsSpan(0, 2), NumberStyles.HexNumber, CultureInfo.InvariantCulture);
int g = int.Parse(hex.AsSpan(2, 2), NumberStyles.HexNumber, CultureInfo.InvariantCulture);
int b = int.Parse(hex.AsSpan(4, 2), NumberStyles.HexNumber, CultureInfo.InvariantCulture);
color = System.Windows.Media.Color.FromArgb((byte)a, (byte)r, (byte)g, (byte)b);
return true;
}
else
{
color = System.Windows.Media.Colors.Transparent;
return false;
}
}
[GeneratedRegex("(?:[0-9a-fA-F]{8})")]
private static partial Regex Hex8();
[GeneratedRegex("(?:[0-9a-fA-F]{6})")]
private static partial Regex Hex6();
} }
+42 -48
View File
@@ -1,65 +1,59 @@
using NAudio.Dsp; using NAudio.Dsp;
using System; using System;
namespace DesktopMagic namespace DesktopMagic.Helpers;
internal class SampleAggregator
{ {
internal class SampleAggregator // FFT
public event EventHandler<FftEventArgs> FftCalculated;
// This Complex is NAudio's own!
private readonly Complex[] fftBuffer;
private readonly FftEventArgs fftArgs;
private readonly int fftLength;
private readonly int m;
private int fftPos;
public bool PerformFFT { get; set; }
public SampleAggregator(int fftLength)
{ {
// FFT if (!IsPowerOfTwo(fftLength))
public event EventHandler<FftEventArgs> FftCalculated;
public bool PerformFFT { get; set; }
// This Complex is NAudio's own!
private readonly Complex[] fftBuffer;
private readonly FftEventArgs fftArgs;
private readonly int fftLength;
private readonly int m;
private int fftPos;
public SampleAggregator(int fftLength)
{ {
if (!IsPowerOfTwo(fftLength)) throw new ArgumentException("FFT Length must be a power of two");
{
throw new ArgumentException("FFT Length must be a power of two");
}
this.m = (int)Math.Log(fftLength, 2.0);
this.fftLength = fftLength;
this.fftBuffer = new Complex[fftLength];
this.fftArgs = new FftEventArgs(fftBuffer);
} }
m = (int)Math.Log(fftLength, 2.0);
this.fftLength = fftLength;
fftBuffer = new Complex[fftLength];
fftArgs = new FftEventArgs(fftBuffer);
}
private bool IsPowerOfTwo(int x) public void Add(float value)
{
if (PerformFFT && FftCalculated != null)
{ {
return (x & (x - 1)) == 0; // Remember the window function! There are many others as well.
} fftBuffer[fftPos].X = (float)(value * FastFourierTransform.HammingWindow(fftPos, fftLength));
fftBuffer[fftPos].Y = 0; // This is always zero with audio.
public void Add(float value) fftPos++;
{ if (fftPos >= fftLength)
if (PerformFFT && FftCalculated != null)
{ {
// Remember the window function! There are many others as well. fftPos = 0;
fftBuffer[fftPos].X = (float)(value * FastFourierTransform.HammingWindow(fftPos, fftLength)); FastFourierTransform.FFT(true, m, fftBuffer);
fftBuffer[fftPos].Y = 0; // This is always zero with audio. FftCalculated(this, fftArgs);
fftPos++;
if (fftPos >= fftLength)
{
fftPos = 0;
FastFourierTransform.FFT(true, m, fftBuffer);
FftCalculated(this, fftArgs);
}
} }
} }
} }
public class FftEventArgs : EventArgs private bool IsPowerOfTwo(int x)
{ {
public FftEventArgs(Complex[] result) return (x & (x - 1)) == 0;
{
this.Result = result;
}
public Complex[] Result { get; private set; }
} }
}
public class FftEventArgs(Complex[] result) : EventArgs
{
public Complex[] Result { get; private set; } = result;
} }
@@ -4,235 +4,229 @@ using System;
using System.Windows; using System.Windows;
using System.Windows.Controls; using System.Windows.Controls;
namespace DesktopMagic.Helpers namespace DesktopMagic.Helpers;
internal class SettingElementGenerator(ComboBox optionsComboBox)
{ {
internal class SettingElementGenerator private readonly ComboBox optionsComboBox = optionsComboBox;
public void Generate(SettingElement settingElement, DockPanel dockPanel, TextBlock textBlock)
{ {
private readonly ComboBox optionsComboBox; dockPanel.UpdateLayout();
textBlock.UpdateLayout();
public SettingElementGenerator(ComboBox optionsComboBox) if (settingElement.Element is DesktopMagicPluginAPI.Inputs.Label eLabel)
{ {
this.optionsComboBox = optionsComboBox; textBlock.Text = eLabel.Value;
} textBlock.Margin = new Thickness(0, 5, 3, 0);
textBlock.HorizontalAlignment = HorizontalAlignment.Stretch;
textBlock.TextWrapping = TextWrapping.WrapWithOverflow;
public void Generate(SettingElement settingElement, DockPanel dockPanel, TextBlock textBlock) if (eLabel.Bold)
{
dockPanel.UpdateLayout();
textBlock.UpdateLayout();
if (settingElement.Element is DesktopMagicPluginAPI.Inputs.Label eLabel)
{ {
textBlock.Text = eLabel.Value; textBlock.FontWeight = FontWeights.Bold;
textBlock.Margin = new Thickness(0, 5, 3, 0); }
textBlock.HorizontalAlignment = HorizontalAlignment.Stretch; eLabel.OnValueChanged += () =>
textBlock.TextWrapping = TextWrapping.WrapWithOverflow; {
textBlock.Dispatcher.Invoke(() =>
if (eLabel.Bold)
{ {
textBlock.FontWeight = FontWeights.Bold; textBlock.Text = eLabel.Value;
});
};
}
else if (settingElement.Element is DesktopMagicPluginAPI.Inputs.Button eButton)
{
Button button = new()
{
Content = eButton.Value,
FontSize = 10,
Height = 20,
Margin = new Thickness(0, 10, 0, 10),
Padding = new Thickness(0),
VerticalAlignment = VerticalAlignment.Center,
HorizontalAlignment = HorizontalAlignment.Stretch
};
button.Click += (_s, _e) =>
{
try
{
eButton.Click();
} }
eLabel.OnValueChanged += () => catch (Exception ex)
{ {
textBlock.Dispatcher.Invoke(() => DisplayException(ex.Message);
{ }
textBlock.Text = eLabel.Value; };
}); eButton.OnValueChanged += () =>
};
}
else if (settingElement.Element is DesktopMagicPluginAPI.Inputs.Button eButton)
{ {
Button button = new() button.Dispatcher.Invoke(() =>
{ {
Content = eButton.Value, button.Content = eButton.Value;
FontSize = 10, });
Height = 20, };
Margin = new Thickness(0, 10, 0, 10),
Padding = new Thickness(0),
VerticalAlignment = VerticalAlignment.Center,
HorizontalAlignment = HorizontalAlignment.Stretch
};
button.Click += (_s, _e) =>
{
try
{
eButton.Click();
}
catch (Exception ex)
{
DisplayException(ex.Message);
}
};
eButton.OnValueChanged += () =>
{
button.Dispatcher.Invoke(() =>
{
button.Content = eButton.Value;
});
};
_ = dockPanel.Children.Add(button); _ = dockPanel.Children.Add(button);
}
else if (settingElement.Element is DesktopMagicPluginAPI.Inputs.CheckBox eCheckBox)
{
CheckBox checkBox = new()
{
IsChecked = eCheckBox.Value,
Style = (Style)dockPanel.FindResource("MaterialDesignDarkCheckBox"),
VerticalAlignment = VerticalAlignment.Center,
HorizontalAlignment = HorizontalAlignment.Stretch
};
checkBox.Click += (_s, _e) =>
{
try
{
eCheckBox.Value = checkBox.IsChecked.GetValueOrDefault();
}
catch (Exception ex)
{
DisplayException(ex.Message);
}
};
eCheckBox.OnValueChanged += () =>
{
checkBox.Dispatcher.Invoke(() =>
{
checkBox.IsChecked = eCheckBox.Value;
});
};
_ = dockPanel.Children.Add(checkBox);
}
else if (settingElement.Element is DesktopMagicPluginAPI.Inputs.TextBox eTextBox)
{
TextBox textBox = new()
{
Text = eTextBox.Value,
TextWrapping = TextWrapping.Wrap,
VerticalAlignment = VerticalAlignment.Center,
HorizontalAlignment = HorizontalAlignment.Stretch
};
textBox.TextChanged += (_s, _e) =>
{
try
{
eTextBox.Value = textBox.Text;
}
catch (Exception ex)
{
DisplayException(ex.Message);
}
};
eTextBox.OnValueChanged += () =>
{
textBox.Dispatcher.Invoke(() =>
{
textBox.Text = eTextBox.Value;
});
};
_ = dockPanel.Children.Add(textBox);
}
else if (settingElement.Element is DesktopMagicPluginAPI.Inputs.IntegerUpDown eIntegerUpDown)
{
Xceed.Wpf.Toolkit.IntegerUpDown integerUpDown = new()
{
Value = eIntegerUpDown.Value,
Minimum = eIntegerUpDown.Minimum,
Maximum = eIntegerUpDown.Maximum,
VerticalAlignment = VerticalAlignment.Center,
HorizontalAlignment = HorizontalAlignment.Stretch
};
integerUpDown.ValueChanged += (_s, _e) =>
{
try
{
eIntegerUpDown.Value = integerUpDown.Value.GetValueOrDefault();
}
catch (Exception ex)
{
DisplayException(ex.Message);
}
};
eIntegerUpDown.OnValueChanged += () =>
{
integerUpDown.Dispatcher.Invoke(() =>
{
integerUpDown.Value = eIntegerUpDown.Value;
});
};
_ = dockPanel.Children.Add(integerUpDown);
}
else if (settingElement.Element is DesktopMagicPluginAPI.Inputs.Slider eSlider)
{
Slider slider = new()
{
Value = eSlider.Value,
Minimum = eSlider.Minimum,
Maximum = eSlider.Maximum,
TickFrequency = 1,
IsSnapToTickEnabled = true,
VerticalAlignment = VerticalAlignment.Center,
HorizontalAlignment = HorizontalAlignment.Stretch
};
slider.ValueChanged += (_s, _e) =>
{
try
{
eSlider.Value = slider.Value;
}
catch (Exception ex)
{
DisplayException(ex.Message);
}
};
eSlider.OnValueChanged += () =>
{
slider.Dispatcher.Invoke(() =>
{
slider.Value = eSlider.Value;
});
};
_ = dockPanel.Children.Add(slider);
}
else if (settingElement.Element is DesktopMagicPluginAPI.Inputs.ComboBox eComboBox)
{
ComboBox comboBox = new()
{
ItemsSource = eComboBox.Items,
IsEditable = false,
VerticalAlignment = VerticalAlignment.Center,
HorizontalAlignment = HorizontalAlignment.Stretch,
SelectedIndex = 0
};
comboBox.SelectionChanged += (_s, _e) =>
{
try
{
eComboBox.Value = comboBox.Text;
}
catch (Exception ex)
{
DisplayException(ex.Message);
}
};
eComboBox.OnValueChanged += () =>
{
comboBox.SelectedItem = eComboBox.Value;
};
_ = dockPanel.Children.Add(comboBox);
}
} }
else if (settingElement.Element is DesktopMagicPluginAPI.Inputs.CheckBox eCheckBox)
private void DisplayException(string message)
{ {
App.Logger.Log(message, "PluginInput"); CheckBox checkBox = new()
_ = MessageBox.Show("File execution error:\n" + message, "Error", MessageBoxButton.OK, MessageBoxImage.Error); {
int index = MainWindow.WindowNames.IndexOf(optionsComboBox.SelectedItem.ToString()); IsChecked = eCheckBox.Value,
Style = (Style)dockPanel.FindResource("MaterialDesignDarkCheckBox"),
VerticalAlignment = VerticalAlignment.Center,
HorizontalAlignment = HorizontalAlignment.Stretch
};
checkBox.Click += (_s, _e) =>
{
try
{
eCheckBox.Value = checkBox.IsChecked.GetValueOrDefault();
}
catch (Exception ex)
{
DisplayException(ex.Message);
}
};
eCheckBox.OnValueChanged += () =>
{
checkBox.Dispatcher.Invoke(() =>
{
checkBox.IsChecked = eCheckBox.Value;
});
};
PluginWindow window = MainWindow.Windows[index]; _ = dockPanel.Children.Add(checkBox);
window?.Exit(); }
else if (settingElement.Element is DesktopMagicPluginAPI.Inputs.TextBox eTextBox)
{
TextBox textBox = new()
{
Text = eTextBox.Value,
TextWrapping = TextWrapping.Wrap,
VerticalAlignment = VerticalAlignment.Center,
HorizontalAlignment = HorizontalAlignment.Stretch
};
textBox.TextChanged += (_s, _e) =>
{
try
{
eTextBox.Value = textBox.Text;
}
catch (Exception ex)
{
DisplayException(ex.Message);
}
};
eTextBox.OnValueChanged += () =>
{
textBox.Dispatcher.Invoke(() =>
{
textBox.Text = eTextBox.Value;
});
};
_ = dockPanel.Children.Add(textBox);
}
else if (settingElement.Element is DesktopMagicPluginAPI.Inputs.IntegerUpDown eIntegerUpDown)
{
Xceed.Wpf.Toolkit.IntegerUpDown integerUpDown = new()
{
Value = eIntegerUpDown.Value,
Minimum = eIntegerUpDown.Minimum,
Maximum = eIntegerUpDown.Maximum,
VerticalAlignment = VerticalAlignment.Center,
HorizontalAlignment = HorizontalAlignment.Stretch
};
integerUpDown.ValueChanged += (_s, _e) =>
{
try
{
eIntegerUpDown.Value = integerUpDown.Value.GetValueOrDefault();
}
catch (Exception ex)
{
DisplayException(ex.Message);
}
};
eIntegerUpDown.OnValueChanged += () =>
{
integerUpDown.Dispatcher.Invoke(() =>
{
integerUpDown.Value = eIntegerUpDown.Value;
});
};
_ = dockPanel.Children.Add(integerUpDown);
}
else if (settingElement.Element is DesktopMagicPluginAPI.Inputs.Slider eSlider)
{
Slider slider = new()
{
Value = eSlider.Value,
Minimum = eSlider.Minimum,
Maximum = eSlider.Maximum,
TickFrequency = 1,
IsSnapToTickEnabled = true,
VerticalAlignment = VerticalAlignment.Center,
HorizontalAlignment = HorizontalAlignment.Stretch
};
slider.ValueChanged += (_s, _e) =>
{
try
{
eSlider.Value = slider.Value;
}
catch (Exception ex)
{
DisplayException(ex.Message);
}
};
eSlider.OnValueChanged += () =>
{
slider.Dispatcher.Invoke(() =>
{
slider.Value = eSlider.Value;
});
};
_ = dockPanel.Children.Add(slider);
}
else if (settingElement.Element is DesktopMagicPluginAPI.Inputs.ComboBox eComboBox)
{
ComboBox comboBox = new()
{
ItemsSource = eComboBox.Items,
IsEditable = false,
VerticalAlignment = VerticalAlignment.Center,
HorizontalAlignment = HorizontalAlignment.Stretch,
SelectedIndex = 0
};
comboBox.SelectionChanged += (_s, _e) =>
{
try
{
eComboBox.Value = comboBox.Text;
}
catch (Exception ex)
{
DisplayException(ex.Message);
}
};
eComboBox.OnValueChanged += () =>
{
comboBox.SelectedItem = eComboBox.Value;
};
_ = dockPanel.Children.Add(comboBox);
} }
} }
private void DisplayException(string message)
{
App.Logger.Log(message, "PluginInput");
_ = MessageBox.Show("File execution error:\n" + message, "Error", MessageBoxButton.OK, MessageBoxImage.Error);
int index = MainWindow.WindowNames.IndexOf(optionsComboBox.SelectedItem.ToString());
PluginWindow window = MainWindow.Windows[index];
window?.Exit();
}
} }
File diff suppressed because it is too large Load Diff
+15 -17
View File
@@ -25,8 +25,8 @@ namespace DesktopMagic
{ {
#region Global settings #region Global settings
internal static Theme Theme { get; } = new Theme();
public static bool EditMode { get; private set; } = false; public static bool EditMode { get; private set; } = false;
internal static Theme Theme { get; } = new Theme();
#endregion Global settings #endregion Global settings
@@ -42,18 +42,16 @@ namespace DesktopMagic
#region Plugins settings #region Plugins settings
internal static Dictionary<string, List<SettingElement>> PluginsSettings { get; } = new Dictionary<string, List<SettingElement>>(); internal static Dictionary<string, List<SettingElement>> PluginsSettings { get; } = [];
#endregion Plugins settings #endregion Plugins settings
public static List<PluginWindow> Windows { get; } = new List<PluginWindow>();
public static List<string> WindowNames { get; } = new List<string>();
private readonly RegistryKey key; private readonly RegistryKey key;
private readonly System.Windows.Forms.NotifyIcon notifyIcon = new(); private readonly System.Windows.Forms.NotifyIcon notifyIcon = new();
private bool loaded = false; private bool loaded = false;
private bool blockWindowsClosing = true; private bool blockWindowsClosing = true;
public static List<PluginWindow> Windows { get; } = [];
public static List<string> WindowNames { get; } = [];
public MainWindow() public MainWindow()
{ {
@@ -126,7 +124,7 @@ namespace DesktopMagic
foreach (string fileName in Directory.GetFiles(PluginsPath, "*.dll")) foreach (string fileName in Directory.GetFiles(PluginsPath, "*.dll"))
{ {
string PluginName = fileName[(fileName.LastIndexOf("\\", StringComparison.InvariantCulture) + 1)..].Replace(fileName[fileName.LastIndexOf(".", StringComparison.InvariantCulture)..], ""); string PluginName = fileName[(fileName.LastIndexOf('\\') + 1)..].Replace(fileName[fileName.LastIndexOf('.')..], "");
try try
{ {
_ = Directory.CreateDirectory(Path.Combine(PluginsPath, PluginName)); _ = Directory.CreateDirectory(Path.Combine(PluginsPath, PluginName));
@@ -143,10 +141,10 @@ namespace DesktopMagic
foreach (string fileName in Directory.GetFiles(directory).Where(s => s.EndsWith(".dll", StringComparison.InvariantCulture) || s.EndsWith(".cs", StringComparison.InvariantCulture))) foreach (string fileName in Directory.GetFiles(directory).Where(s => s.EndsWith(".dll", StringComparison.InvariantCulture) || s.EndsWith(".cs", StringComparison.InvariantCulture)))
{ {
string badChars = ",#-<>?!=()*,. "; string badChars = ",#-<>?!=()*,. ";
string PluginName = fileName[(fileName.LastIndexOf("\\", StringComparison.InvariantCulture) + 1)..].Replace(fileName[fileName.LastIndexOf(".", StringComparison.InvariantCulture)..], ""); string PluginName = fileName[(fileName.LastIndexOf('\\') + 1)..].Replace(fileName[fileName.LastIndexOf('.')..], "");
string clearPluginName = PluginName; string clearPluginName = PluginName;
if (PluginName == directory[(directory.LastIndexOf("\\", StringComparison.InvariantCulture) + 1)..]) if (PluginName == directory[(directory.LastIndexOf('\\') + 1)..])
{ {
foreach (char c in badChars) foreach (char c in badChars)
{ {
@@ -156,9 +154,9 @@ namespace DesktopMagic
CheckBox checkBox = new() CheckBox checkBox = new()
{ {
Name = "_PluginCb_" + clearPluginName, Name = "_PluginCb_" + clearPluginName,
Content = PluginName Content = PluginName,
Style = (Style)FindResource("MaterialDesignDarkCheckBox")
}; };
checkBox.Style = (Style)FindResource("MaterialDesignDarkCheckBox");
checkBox.Click += CheckBox_Click; checkBox.Click += CheckBox_Click;
bool exists = false; bool exists = false;
@@ -446,7 +444,7 @@ namespace DesktopMagic
optionsPanel.UpdateLayout(); optionsPanel.UpdateLayout();
bool success = PluginsSettings.TryGetValue(optionsComboBox.SelectedItem.ToString(), out List<SettingElement> settingElements); bool success = PluginsSettings.TryGetValue(optionsComboBox.SelectedItem.ToString(), out List<SettingElement> settingElements);
if (!success || settingElements?.Count == 0) if (!success || settingElements is null || settingElements.Count == 0)
{ {
_ = optionsPanel.Children.Add(new TextBlock() { Text = (string)FindResource("noOptions") }); _ = optionsPanel.Children.Add(new TextBlock() { Text = (string)FindResource("noOptions") });
return; return;
@@ -593,7 +591,7 @@ namespace DesktopMagic
string[] data = lines[layoutsComboBox.SelectedIndex].Split(';'); string[] data = lines[layoutsComboBox.SelectedIndex].Split(';');
foreach (string dat in data.Where(dat => dat.Contains(':'))) foreach (string dat in data.Where(dat => dat.Contains(':')))
{ {
string value = dat[(dat.LastIndexOf(":", StringComparison.InvariantCulture) + 1)..]; string value = dat[(dat.LastIndexOf(':') + 1)..];
string name = dat.Replace(":" + value, ""); string name = dat.Replace(":" + value, "");
key.SetValue(name, value); key.SetValue(name, value);
} }
@@ -638,7 +636,7 @@ namespace DesktopMagic
return; return;
} }
List<string> lines = File.ReadAllLines(App.ApplicationDataPath + "\\layouts.save").ToList(); List<string> lines = [.. File.ReadAllLines(App.ApplicationDataPath + "\\layouts.save")];
lines.RemoveAt(layoutsComboBox.SelectedIndex); lines.RemoveAt(layoutsComboBox.SelectedIndex);
File.WriteAllLines(App.ApplicationDataPath + "\\layouts.save", lines); File.WriteAllLines(App.ApplicationDataPath + "\\layouts.save", lines);
LoadLayoutNames(); LoadLayoutNames();
@@ -656,7 +654,7 @@ namespace DesktopMagic
{ {
lock (App.ApplicationDataPath) lock (App.ApplicationDataPath)
{ {
List<string> lines = File.ReadAllLines(App.ApplicationDataPath + "\\layouts.save").ToList(); List<string> lines = [.. File.ReadAllLines(App.ApplicationDataPath + "\\layouts.save")];
StringBuilder content = new StringBuilder(); StringBuilder content = new StringBuilder();
foreach (string valueName in key.GetValueNames()) foreach (string valueName in key.GetValueNames())
{ {
@@ -682,7 +680,7 @@ namespace DesktopMagic
foreach (string line in lines) foreach (string line in lines)
{ {
string name = line[(line.LastIndexOf(";", StringComparison.InvariantCulture) + 1)..]; string name = line[(line.LastIndexOf(';') + 1)..];
_ = layoutsComboBox.Items.Add(name); _ = layoutsComboBox.Items.Add(name);
} }
layoutsComboBox.SelectedIndex = int.Parse(key.GetValue("SelectedLayout", "0").ToString(), CultureInfo.InvariantCulture); layoutsComboBox.SelectedIndex = int.Parse(key.GetValue("SelectedLayout", "0").ToString(), CultureInfo.InvariantCulture);
@@ -857,7 +855,7 @@ namespace DesktopMagic
private void SetLanguageDictionary() private void SetLanguageDictionary()
{ {
ResourceDictionary dict = new ResourceDictionary(); ResourceDictionary dict = [];
string currentCulture = Thread.CurrentThread.CurrentUICulture.ToString(); string currentCulture = Thread.CurrentThread.CurrentUICulture.ToString();
if (currentCulture.Contains("de")) if (currentCulture.Contains("de"))
+2 -7
View File
@@ -4,14 +4,9 @@ using System.Drawing;
namespace DesktopMagic.Plugins; namespace DesktopMagic.Plugins;
internal class PluginData : IPluginData internal class PluginData(PluginWindow window) : IPluginData
{ {
private readonly PluginWindow window; private readonly PluginWindow window = window;
public PluginData(PluginWindow window)
{
this.window = window;
}
public string Font => Theme.Font; public string Font => Theme.Font;
+39 -46
View File
@@ -24,6 +24,10 @@ namespace DesktopMagic;
public partial class PluginWindow : Window public partial class PluginWindow : Window
{ {
public event Action PluginLoaded;
public event Action OnExit;
private readonly RegistryKey key; private readonly RegistryKey key;
private Thread pluginThread; private Thread pluginThread;
private System.Timers.Timer valueTimer; private System.Timers.Timer valueTimer;
@@ -34,10 +38,6 @@ public partial class PluginWindow : Window
public string PluginName { get; private set; } public string PluginName { get; private set; }
public string PluginFolderPath { get; private set; } public string PluginFolderPath { get; private set; }
public event Action PluginLoaded;
public event Action OnExit;
public PluginWindow(string pluginName) public PluginWindow(string pluginName)
{ {
InitializeComponent(); InitializeComponent();
@@ -77,6 +77,21 @@ public partial class PluginWindow : Window
this.pluginClassInstance = pluginClassInstance; this.pluginClassInstance = pluginClassInstance;
} }
public void UpdatePluginWindow()
{
ValueTimer_Elapsed(valueTimer, null);
}
public void Exit()
{
IsRunning = false;
Dispatcher.Invoke(() =>
{
OnExit?.Invoke();
});
}
protected override void OnSourceInitialized(EventArgs e) protected override void OnSourceInitialized(EventArgs e)
{ {
base.OnSourceInitialized(e); base.OnSourceInitialized(e);
@@ -87,18 +102,26 @@ public partial class PluginWindow : Window
WindowPos.GetWindowLong(helper.Handle, WindowPos.GWL_EXSTYLE) | WindowPos.WS_EX_NOACTIVATE); WindowPos.GetWindowLong(helper.Handle, WindowPos.GWL_EXSTYLE) | WindowPos.WS_EX_NOACTIVATE);
} }
private void Window_ContentRendered(object sender, EventArgs e) private static BitmapSource BitmapToImageSource(Bitmap bitmap)
{ {
pluginThread = new Thread(() => BitmapData bitmapData = bitmap.LockBits(
{ new Rectangle(0, 0, bitmap.Width, bitmap.Height),
LoadPlugin(); ImageLockMode.ReadOnly, bitmap.PixelFormat);
});
pluginThread.Start(); BitmapSource bitmapSource = BitmapSource.Create(
bitmapData.Width, bitmapData.Height,
bitmap.HorizontalResolution, bitmap.VerticalResolution,
PixelFormats.Bgra32, null,
bitmapData.Scan0, bitmapData.Stride * bitmapData.Height, bitmapData.Stride);
bitmap.UnlockBits(bitmapData);
return bitmapSource;
} }
public void UpdatePluginWindow() private void Window_ContentRendered(object sender, EventArgs e)
{ {
ValueTimer_Elapsed(valueTimer, null); pluginThread = new Thread(LoadPlugin);
pluginThread.Start();
} }
private void UpdateTimer_Elapsed(object sender, ElapsedEventArgs e) private void UpdateTimer_Elapsed(object sender, ElapsedEventArgs e)
@@ -171,7 +194,7 @@ public partial class PluginWindow : Window
{ {
byte[] assemblyBytes = File.ReadAllBytes($"{PluginFolderPath}\\{PluginName}.dll"); byte[] assemblyBytes = File.ReadAllBytes($"{PluginFolderPath}\\{PluginName}.dll");
Assembly dll = Assembly.Load(assemblyBytes); Assembly dll = Assembly.Load(assemblyBytes);
Type instanceType = dll.GetTypes().FirstOrDefault(type => type.GetTypeInfo().BaseType == typeof(Plugin)); Type instanceType = Array.Find(dll.GetTypes(), type => type.GetTypeInfo().BaseType == typeof(Plugin));
if (instanceType is null) if (instanceType is null)
{ {
@@ -220,7 +243,7 @@ public partial class PluginWindow : Window
FieldInfo[] props = instance.GetType().GetFields(BindingFlags.Instance | BindingFlags.NonPublic | BindingFlags.Public | BindingFlags.GetField); FieldInfo[] props = instance.GetType().GetFields(BindingFlags.Instance | BindingFlags.NonPublic | BindingFlags.Public | BindingFlags.GetField);
#pragma warning restore S3011 // Reflection should not be used to increase accessibility of classes, methods, or fields #pragma warning restore S3011 // Reflection should not be used to increase accessibility of classes, methods, or fields
List<SettingElement> settingElements = new List<SettingElement>(); List<SettingElement> settingElements = [];
foreach (FieldInfo prop in props) foreach (FieldInfo prop in props)
{ {
if (prop.GetValue(instance) is Element element) if (prop.GetValue(instance) is Element element)
@@ -237,15 +260,11 @@ public partial class PluginWindow : Window
} }
} }
settingElements = settingElements.OrderBy(x => x.OrderIndex).ToList(); settingElements = [.. settingElements.OrderBy(x => x.OrderIndex)];
if (MainWindow.PluginsSettings.ContainsKey(PluginName)) if (!MainWindow.PluginsSettings.TryAdd(PluginName, settingElements))
{ {
MainWindow.PluginsSettings[PluginName] = settingElements; MainWindow.PluginsSettings[PluginName] = settingElements;
} }
else
{
MainWindow.PluginsSettings.Add(PluginName, settingElements);
}
} }
catch (Exception ex) catch (Exception ex)
{ {
@@ -307,32 +326,6 @@ public partial class PluginWindow : Window
} }
} }
private static BitmapSource BitmapToImageSource(Bitmap bitmap)
{
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,
PixelFormats.Bgra32, null,
bitmapData.Scan0, bitmapData.Stride * bitmapData.Height, bitmapData.Stride);
bitmap.UnlockBits(bitmapData);
return bitmapSource;
}
public void Exit()
{
IsRunning = false;
Dispatcher.Invoke(() =>
{
OnExit?.Invoke();
});
}
private void Window_Closing(object sender, System.ComponentModel.CancelEventArgs e) private void Window_Closing(object sender, System.ComponentModel.CancelEventArgs e)
{ {
pluginClassInstance?.Stop(); pluginClassInstance?.Stop();
+4 -11
View File
@@ -2,16 +2,9 @@
namespace DesktopMagic.Plugins; namespace DesktopMagic.Plugins;
internal class SettingElement internal class SettingElement(Element element, string name, int orderIndex)
{ {
public Element Element { get; } public Element Element { get; } = element;
public string Name { get; } public string Name { get; } = name;
public int OrderIndex { get; } public int OrderIndex { get; } = orderIndex;
public SettingElement(Element element, string name, int orderIndex)
{
Element = element;
Name = name;
OrderIndex = orderIndex;
}
} }
@@ -1,11 +1,12 @@
<Project Sdk="Microsoft.NET.Sdk"> <Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup> <PropertyGroup>
<TargetFramework>net6.0</TargetFramework> <TargetFramework>net8.0-windows</TargetFramework>
<OutputType>Library</OutputType>
</PropertyGroup> </PropertyGroup>
<ItemGroup> <ItemGroup>
<PackageReference Include="System.Drawing.Common" Version="5.0.2" /> <PackageReference Include="System.Drawing.Common" Version="8.0.0" />
</ItemGroup> </ItemGroup>
<ItemGroup> <ItemGroup>
+72 -73
View File
@@ -8,82 +8,81 @@ using System.Drawing.Imaging;
using System.IO; using System.IO;
using System.Threading.Tasks; using System.Threading.Tasks;
namespace DesktopMagicPlugin.Test namespace DesktopMagicPlugin.Test;
public class GifPlugin : Plugin
{ {
public class GifPlugin : Plugin private const string SaveFilePath = "gifPath.txt";
[Element("Gif path:")]
private readonly TextBox input = new TextBox("");
[Element]
private readonly Label info = new Label("");
private readonly List<Bitmap> bitmaps = [];
private int frameCount = -1;
public override void Start()
{ {
[Element("Gif path:")] input.OnValueChanged += Input_OnValueChanged;
private readonly TextBox input = new TextBox(""); if (File.Exists(SaveFilePath))
[Element]
private readonly Label info = new Label("");
private readonly List<Bitmap> bitmaps = new List<Bitmap>();
private int frameCount = -1;
private const string SaveFilePath = "gifPath.txt";
public override void Start()
{ {
input.OnValueChanged += Input_OnValueChanged; input.Value = File.ReadAllText(SaveFilePath);
if (File.Exists(SaveFilePath))
{
input.Value = File.ReadAllText(SaveFilePath);
}
}
private void Input_OnValueChanged()
{
_ = Task.Run(() =>
{
try
{
if (File.Exists(input.Value))
{
info.Value = "Loading...";
Image gif = Image.FromFile(input.Value);
PropertyItem item = gif.GetPropertyItem(0x5100); // FrameDelay in libgdiplus
UpdateInterval = (item.Value[0] + item.Value[1] * 256) * 10; //FrameDelay in ms
bitmaps.Clear();
for (int i = 0; i < gif.GetFrameCount(FrameDimension.Time); i++)
{
gif.SelectActiveFrame(FrameDimension.Time, i);
bitmaps.Add(new Bitmap(gif));
}
File.WriteAllText(SaveFilePath, input.Value);
info.Value = string.Empty;
}
else
{
info.Value = "File not found!";
}
}
catch (Exception ex)
{
info.Value = $"Error: {ex.Message}";
}
});
}
public override Bitmap Main()
{
if (bitmaps.Count == 0)
{
return new Bitmap(1, 1);
}
frameCount++;
if (frameCount >= bitmaps.Count)
{
frameCount = 0;
}
return bitmaps[frameCount];
} }
} }
public override Bitmap Main()
{
if (bitmaps.Count == 0)
{
return new Bitmap(1, 1);
}
frameCount++;
if (frameCount >= bitmaps.Count)
{
frameCount = 0;
}
return bitmaps[frameCount];
}
private void Input_OnValueChanged()
{
_ = Task.Run(() =>
{
try
{
if (File.Exists(input.Value))
{
info.Value = "Loading...";
Image gif = Image.FromFile(input.Value);
PropertyItem item = gif.GetPropertyItem(0x5100); // FrameDelay in libgdiplus
UpdateInterval = (item.Value[0] + (item.Value[1] * 256)) * 10; //FrameDelay in ms
bitmaps.Clear();
for (int i = 0; i < gif.GetFrameCount(FrameDimension.Time); i++)
{
_ = gif.SelectActiveFrame(FrameDimension.Time, i);
bitmaps.Add(new Bitmap(gif));
}
File.WriteAllText(SaveFilePath, input.Value);
info.Value = string.Empty;
}
else
{
info.Value = "File not found!";
}
}
catch (Exception ex)
{
info.Value = $"Error: {ex.Message}";
}
});
}
} }
-9
View File
@@ -1,9 +0,0 @@
###############
# folder #
###############
/**/DROP/
/**/TEMP/
/**/packages/
/**/bin/
/**/obj/
_site
@@ -1,7 +1,7 @@
<Project Sdk="Microsoft.NET.Sdk"> <Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup> <PropertyGroup>
<TargetFramework>net6.0</TargetFramework> <TargetFramework>net8.0-windows</TargetFramework>
<Company>Stone_Red</Company> <Company>Stone_Red</Company>
<Product>Stone_Red</Product> <Product>Stone_Red</Product>
<Version>0.0.0.5</Version> <Version>0.0.0.5</Version>
@@ -22,11 +22,7 @@
</PropertyGroup> </PropertyGroup>
<ItemGroup> <ItemGroup>
<PackageReference Include="docfx.console" Version="2.58.9"> <PackageReference Include="System.Drawing.Common" Version="8.0.0" />
<PrivateAssets>all</PrivateAssets>
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
</PackageReference>
<PackageReference Include="System.Drawing.Common" Version="5.0.2" />
</ItemGroup> </ItemGroup>
<ItemGroup> <ItemGroup>
@@ -1,468 +0,0 @@
<?xml version="1.0"?>
<doc>
<assembly>
<name>DesktopMagicPluginAPI</name>
</assembly>
<members>
<member name="T:DesktopMagicPluginAPI.Drawing.GraphicsExtentions">
<summary>
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>
<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.DrawStringMonospace(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.DrawStringFixedWidth(System.Drawing.Graphics,System.String,System.Drawing.Font,System.Drawing.Brush,System.Single,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>
/// <param name="width">The specified width.</param>
</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>
<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>
<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.
</summary>
</member>
<member name="F:DesktopMagicPluginAPI.Drawing.RenderQuality.High">
<summary>
Slower then <see cref="F:DesktopMagicPluginAPI.Drawing.RenderQuality.Low"/> but produces higher quality output.
</summary>
</member>
<member name="F:DesktopMagicPluginAPI.Drawing.RenderQuality.Low">
<summary>
Faster then <see cref="F:DesktopMagicPluginAPI.Drawing.RenderQuality.High"/> but produces lower quality output.
</summary>
</member>
<member name="F:DesktopMagicPluginAPI.Drawing.RenderQuality.Performance">
<summary>
Provides performance benefits over <see cref="F:DesktopMagicPluginAPI.Drawing.RenderQuality.Low"/>
</summary>
</member>
<member name="T:DesktopMagicPluginAPI.Inputs.Button">
<summary>
Represents a button control.
</summary>
</member>
<member name="E:DesktopMagicPluginAPI.Inputs.Button.OnClick">
<summary>
Occurs when the button gets clicked.
</summary>
</member>
<member name="P:DesktopMagicPluginAPI.Inputs.Button.Value">
<summary>
Gets or sets the text caption displayed in the <see cref="T:DesktopMagicPluginAPI.Inputs.Button"/> element.
</summary>
</member>
<member name="M:DesktopMagicPluginAPI.Inputs.Button.#ctor(System.String)">
<summary>
Initializes a new instance of the <see cref="T:DesktopMagicPluginAPI.Inputs.Button"/> class with the provided <paramref name="value"/>.
</summary>
<param name="value">The text caption displayed in the <see cref="T:DesktopMagicPluginAPI.Inputs.Button"/> control.</param>
</member>
<member name="M:DesktopMagicPluginAPI.Inputs.Button.Click">
<summary>
Triggers the <see cref="E:DesktopMagicPluginAPI.Inputs.Button.OnClick"/> event.
</summary>
</member>
<member name="T:DesktopMagicPluginAPI.Inputs.CheckBox">
<summary>
Represents a check box control.
</summary>
</member>
<member name="P:DesktopMagicPluginAPI.Inputs.CheckBox.Value">
<summary>
Gets or set a value indicating whether the <see cref="T:DesktopMagicPluginAPI.Inputs.CheckBox"/> is in the checked state.
</summary>
</member>
<member name="M:DesktopMagicPluginAPI.Inputs.CheckBox.#ctor(System.Boolean)">
<summary>
Initializes a new instance of the <see cref="T:DesktopMagicPluginAPI.Inputs.CheckBox"/> class with the provided <paramref name="value"/>.
</summary>
<param name="value">A value indicating whether the <see cref="T:DesktopMagicPluginAPI.Inputs.CheckBox"/> is in the checked state.</param>
</member>
<member name="T:DesktopMagicPluginAPI.Inputs.ComboBox">
<summary>
Represents a selection control with a drop-down list.
</summary>
</member>
<member name="P:DesktopMagicPluginAPI.Inputs.ComboBox.Items">
<summary>
Gets the collection used to generate the content of the <see cref="T:DesktopMagicPluginAPI.Inputs.ComboBox"/>.
</summary>
</member>
<member name="P:DesktopMagicPluginAPI.Inputs.ComboBox.Value">
<summary>
Gets the currently selected item associated with this <see cref="T:DesktopMagicPluginAPI.Inputs.ComboBox"/>.
</summary>
<remarks>If you assign a value to this property, the displayed text in the user interface will not be changed.</remarks>
</member>
<member name="M:DesktopMagicPluginAPI.Inputs.ComboBox.#ctor(System.String[])">
<summary>
Initializes a new instance of the <see cref="T:DesktopMagicPluginAPI.Inputs.Label"/> class with the provided <paramref name="items"/>.
</summary>
<param name="items"></param>
</member>
<member name="T:DesktopMagicPluginAPI.Inputs.Element">
<summary>
The element base class.
</summary>
</member>
<member name="E:DesktopMagicPluginAPI.Inputs.Element.OnValueChanged">
<summary>
Occurs when the value has been changed.
</summary>
</member>
<member name="M:DesktopMagicPluginAPI.Inputs.Element.ValueChanged">
<summary>
Triggers the <see cref="E:DesktopMagicPluginAPI.Inputs.Element.OnValueChanged"/> event.
</summary>
</member>
<member name="T:DesktopMagicPluginAPI.Inputs.ElementAttribute">
<summary>
Marks a Property as element.
</summary>
</member>
<member name="P:DesktopMagicPluginAPI.Inputs.ElementAttribute.Name">
<summary>
The name of the element.
</summary>
</member>
<member name="P:DesktopMagicPluginAPI.Inputs.ElementAttribute.OrderIndex">
<summary>
The order index of the element.
</summary>
</member>
<member name="M:DesktopMagicPluginAPI.Inputs.ElementAttribute.#ctor(System.String,System.Int32)">
<summary>
Marks a Property as element with the provided <paramref name="name"/> and <paramref name="orderIndex"/>.
</summary>
<param name="name">The name of the element.</param>
<param name="orderIndex">The order index of the element.</param>
</member>
<member name="M:DesktopMagicPluginAPI.Inputs.ElementAttribute.#ctor(System.Int32)">
<summary>
Marks a Property as element with the provided <paramref name="orderIndex"/>.
</summary>
<param name="orderIndex">The order index of the element.</param>
</member>
<member name="M:DesktopMagicPluginAPI.Inputs.ElementAttribute.#ctor">
<inheritdoc cref="T:DesktopMagicPluginAPI.Inputs.ElementAttribute"/>
</member>
<member name="T:DesktopMagicPluginAPI.Inputs.IntegerUpDown">
<summary>
Represents a up-down control.
</summary>
</member>
<member name="P:DesktopMagicPluginAPI.Inputs.IntegerUpDown.Maximum">
<summary>
Gets or sets the maximum value for the <see cref="T:DesktopMagicPluginAPI.Inputs.IntegerUpDown"/> element.
</summary>
</member>
<member name="P:DesktopMagicPluginAPI.Inputs.IntegerUpDown.Minimum">
<summary>
Gets or sets the minimum value for the <see cref="T:DesktopMagicPluginAPI.Inputs.IntegerUpDown"/> element.
</summary>
</member>
<member name="P:DesktopMagicPluginAPI.Inputs.IntegerUpDown.Value">
<summary>
Gets or sets the value assigned to the <see cref="T:DesktopMagicPluginAPI.Inputs.IntegerUpDown"/> element.
</summary>
</member>
<member name="M:DesktopMagicPluginAPI.Inputs.IntegerUpDown.#ctor(System.Int32,System.Int32,System.Int32)">
<summary>
Initializes a new instance of the <see cref="T:DesktopMagicPluginAPI.Inputs.IntegerUpDown"/> class with the provided <paramref name="min"/> value, <paramref name="max"/> value and <paramref name="value"/>.
</summary>
<param name="min">The maximum value for the <see cref="T:DesktopMagicPluginAPI.Inputs.IntegerUpDown"/> element.</param>
<param name="max">The minimum value for the <see cref="T:DesktopMagicPluginAPI.Inputs.IntegerUpDown"/> element.</param>
<param name="value">The value assigned to the <see cref="T:DesktopMagicPluginAPI.Inputs.IntegerUpDown"/> element.</param>
<exception cref="T:System.ArgumentException"></exception>
</member>
<member name="T:DesktopMagicPluginAPI.Inputs.Label">
<summary>
Represents a label control.
</summary>
</member>
<member name="P:DesktopMagicPluginAPI.Inputs.Label.Value">
<summary>
Gets or sets the text associated with this <see cref="T:DesktopMagicPluginAPI.Inputs.Label"/>.
</summary>
</member>
<member name="P:DesktopMagicPluginAPI.Inputs.Label.Bold">
<summary>
Gets or set a value indicating whether the content of the <see cref="T:DesktopMagicPluginAPI.Inputs.Label"/> is bold or not.
</summary>
</member>
<member name="M:DesktopMagicPluginAPI.Inputs.Label.#ctor(System.String,System.Boolean)">
<summary>
Initializes a new instance of the <see cref="T:DesktopMagicPluginAPI.Inputs.Label"/> class with the provided <paramref name="value"/>.
</summary>
<param name="value">The text associated with this <see cref="T:DesktopMagicPluginAPI.Inputs.Label"/></param>
<param name="bold">A value indicating whether the content of the <see cref="T:DesktopMagicPluginAPI.Inputs.Label"/> is bold or not.</param>
</member>
<member name="T:DesktopMagicPluginAPI.Inputs.MouseButton">
<summary>
Mouse Buttons
</summary>
</member>
<member name="F:DesktopMagicPluginAPI.Inputs.MouseButton.Left">
<summary>
The left mouse button.
</summary>
</member>
<member name="F:DesktopMagicPluginAPI.Inputs.MouseButton.Middle">
<summary>
The middle mouse button.
</summary>
</member>
<member name="F:DesktopMagicPluginAPI.Inputs.MouseButton.Right">
<summary>
The right mouse button.
</summary>
</member>
<member name="T:DesktopMagicPluginAPI.Inputs.Slider">
<summary>
Represents a slider control.
</summary>
</member>
<member name="P:DesktopMagicPluginAPI.Inputs.Slider.Maximum">
<summary>
Gets or sets the maximum value for the <see cref="T:DesktopMagicPluginAPI.Inputs.Slider"/> element.
</summary>
</member>
<member name="P:DesktopMagicPluginAPI.Inputs.Slider.Minimum">
<summary>
Gets or sets the minimum value for the <see cref="T:DesktopMagicPluginAPI.Inputs.Slider"/> element.
</summary>
</member>
<member name="P:DesktopMagicPluginAPI.Inputs.Slider.Value">
<summary>
Gets or sets the value assigned to the <see cref="T:DesktopMagicPluginAPI.Inputs.Slider"/> element.
</summary>
</member>
<member name="M:DesktopMagicPluginAPI.Inputs.Slider.#ctor(System.Double,System.Double,System.Double)">
<summary>
Initializes a new instance of the <see cref="T:DesktopMagicPluginAPI.Inputs.Slider"/> class with the provided <paramref name="min"/> value, <paramref name="max"/> value and <paramref name="value"/>.
</summary>
<param name="min">The maximum value for the <see cref="T:DesktopMagicPluginAPI.Inputs.Slider"/> element.</param>
<param name="max">The minimum value for the <see cref="T:DesktopMagicPluginAPI.Inputs.Slider"/> element.</param>
<param name="value">The value assigned to the <see cref="T:DesktopMagicPluginAPI.Inputs.Slider"/> element.</param>
</member>
<member name="T:DesktopMagicPluginAPI.Inputs.TextBox">
<summary>
Represents a text box control.
</summary>
</member>
<member name="P:DesktopMagicPluginAPI.Inputs.TextBox.Value">
<summary>
Gets or sets the text associated with this <see cref="T:DesktopMagicPluginAPI.Inputs.TextBox"/>.
</summary>
</member>
<member name="M:DesktopMagicPluginAPI.Inputs.TextBox.#ctor(System.String)">
<summary>
Initializes a new instance of the <see cref="T:DesktopMagicPluginAPI.Inputs.TextBox"/> class with the provided <paramref name="value"/>.
</summary>
<param name="value">The text associated with this control.</param>
</member>
<member name="T:DesktopMagicPluginAPI.IPluginData">
<summary>
Defines properties and methods that provide information about the main application.
</summary>
</member>
<member name="P:DesktopMagicPluginAPI.IPluginData.Font">
<summary>
Gets the current font of the current theme.
</summary>
</member>
<member name="P:DesktopMagicPluginAPI.IPluginData.Color">
<summary>
Gets the current color of the current theme.
</summary>
</member>
<member name="P:DesktopMagicPluginAPI.IPluginData.Theme">
<summary>
Gets the current theme setting of the main application.
</summary>
</member>
<member name="P:DesktopMagicPluginAPI.IPluginData.WindowSize">
<summary>
Gets the window size of the plugin window.
</summary>
</member>
<member name="P:DesktopMagicPluginAPI.IPluginData.WindowPosition">
<summary>
Gets the window position of the plugin window.
</summary>
</member>
<member name="P:DesktopMagicPluginAPI.IPluginData.PluginName">
<summary>
Gets the name of the plugin.
</summary>
</member>
<member name="P:DesktopMagicPluginAPI.IPluginData.PluginPath">
<summary>
Gets the path of the parent directory of the plugin.
</summary>
</member>
<member name="M:DesktopMagicPluginAPI.IPluginData.UpdateWindow">
<summary>
Updates the plugin window.
</summary>
</member>
<member name="T:DesktopMagicPluginAPI.ITheme">
<summary>
The theme settings of the main application.
</summary>
</member>
<member name="P:DesktopMagicPluginAPI.ITheme.PrimaryColor">
<summary>
Gets the primary color of the current theme.
</summary>
</member>
<member name="P:DesktopMagicPluginAPI.ITheme.SecondaryColor">
<summary>
Gets the secondary color of the current theme.
</summary>
</member>
<member name="P:DesktopMagicPluginAPI.ITheme.BackgroundColor">
<summary>
Gets the background color of the current theme.
</summary>
</member>
<member name="P:DesktopMagicPluginAPI.ITheme.Font">
<summary>
Gets the font of the current theme.
</summary>
</member>
<member name="P:DesktopMagicPluginAPI.ITheme.CornerRadius">
<summary>
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.
</summary>
</member>
<member name="P:DesktopMagicPluginAPI.Plugin.Application">
<summary>
Informations about the main application.
</summary>
</member>
<member name="P:DesktopMagicPluginAPI.Plugin.UpdateInterval">
<summary>
Gets or sets the interval, expressed in milliseconds, at which to call the <see cref="M:DesktopMagicPluginAPI.Plugin.Main"/> method.
</summary>
</member>
<member name="P:DesktopMagicPluginAPI.Plugin.RenderQuality">
<summary>
Gets or sets the render quality of the bitmap image.
</summary>
</member>
<member name="M:DesktopMagicPluginAPI.Plugin.Start">
<summary>
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.
</summary>
<returns></returns>
</member>
<member name="M:DesktopMagicPluginAPI.Plugin.OnMouseClick(System.Drawing.Point,DesktopMagicPluginAPI.Inputs.MouseButton)">
<summary>
Occurs when the window is clicked by the mouse.
</summary>
<param name="position">The x- and y-coordinates of the mouse pointer position relative to the plugin window.</param>
<param name="mouseButton">The button associated with the event.</param>
</member>
<member name="M:DesktopMagicPluginAPI.Plugin.OnMouseMove(System.Drawing.Point)">
<summary>
Occurs when the mouse pointer is moved over the control.
</summary>
<param name="position">The x- and y-coordinates of the mouse pointer position relative to the plugin window.</param>
</member>
<member name="M:DesktopMagicPluginAPI.Plugin.OnMouseWheel(System.Drawing.Point,System.Int32)">
<summary>
Occurs when the user rotates the mouse wheel while the mouse pointer is over this element.
</summary>
<param name="position">The x- and y-coordinates of the mouse pointer position relative to the plugin window.</param>
<param name="delta">A value that indicates the amount that the mouse wheel has changed.</param>
</member>
</members>
</doc>
@@ -1,26 +1,33 @@
using System; using System.Collections.Generic;
using System.Collections.Generic;
using System.Diagnostics.CodeAnalysis; using System.Diagnostics.CodeAnalysis;
using System.Drawing; using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace DesktopMagicPluginAPI.Drawing namespace DesktopMagicPluginAPI.Drawing;
internal class FontComparer : IEqualityComparer<Font>
{ {
internal class FontComparer : IEqualityComparer<Font> public bool Equals(Font font1, Font font2)
{ {
public bool Equals(Font font1, Font font2) if (font1.Name != font2.Name)
{ {
if (font1.Name != font2.Name) return false; return false;
if (font1.SizeInPoints != font2.SizeInPoints) return false;
if (font1.Style != font2.Style) return false;
return true;
} }
public int GetHashCode([DisallowNull] Font obj) if (font1.SizeInPoints != font2.SizeInPoints)
{ {
return obj.GetHashCode(); return false;
} }
if (font1.Style != font2.Style)
{
return false;
}
return true;
}
public int GetHashCode([DisallowNull] Font obj)
{
return obj.GetHashCode();
} }
} }
@@ -2,184 +2,183 @@
using System.Collections.Generic; using System.Collections.Generic;
using System.Drawing; using System.Drawing;
namespace DesktopMagicPluginAPI.Drawing namespace DesktopMagicPluginAPI.Drawing;
/// <summary>
/// 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> /// <summary>
/// Extensions for the <see cref="Graphics"/> class. /// <inheritdoc cref="Graphics.DrawString(string?, Font, Brush, float, float)"/>
/// </summary> /// </summary>
public static class GraphicsExtentions /// <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 DrawStringMonospace(this Graphics graphics, string s, Font font, Brush brush, float x, float y)
{ {
private static readonly Dictionary<Font, int> fonts = new Dictionary<Font, int>(new FontComparer()); int widest = graphics.GetWidestChar(font);
/// <summary> for (int i = 0; i < s.Length; i++)
/// <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 DrawStringMonospace(this Graphics graphics, string s, Font font, Brush brush, float x, float y)
{ {
int widest = graphics.GetWidestChar(font); graphics.DrawString(s[i].ToString(), font, brush, x, y);
for (int i = 0; i < s.Length; i++) x += widest;
{
graphics.DrawString(s[i].ToString(), font, brush, x, y);
x += widest;
}
}
/// <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 DrawStringMonospace(this Graphics graphics, string s, Font font, Brush brush, PointF point)
{
int widest = graphics.GetWidestChar(font);
for (int i = 0; i < s.Length; i++)
{
graphics.DrawString(s[i].ToString(), font, brush, point);
point.X += widest;
}
}
/// <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>
/// /// <param name="width">The specified width.</param>
public static void DrawStringFixedWidth(this Graphics graphics, string s, Font font, Brush brush, float x, float y, float width)
{
for (int i = 0; i < s.Length; i++)
{
graphics.DrawString(s[i].ToString(), font, brush, x, y);
x += width;
}
}
/// <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>
/// <param name="width">The specified width.</param>
public static void DrawStringFixedWidth(this Graphics graphics, string s, Font font, Brush brush, PointF point, float width)
{
for (int i = 0; i < s.Length; i++)
{
graphics.DrawString(s[i].ToString(), font, brush, point);
point.X += width;
}
}
/// <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];
}
float max = 0;
char maxx = ' ';
for (int i = 0; i <= 255; i++)
{
char c = (char)i;
if (char.IsLetterOrDigit(c))
{
float neww = graphics.MeasureString(c.ToString(), font).Width;
if (neww >= max)
{
max = neww;
maxx = c;
}
}
}
Console.WriteLine((int)Math.Round(max, 0));
Console.WriteLine(maxx);
fonts.Add(font, (int)Math.Round(max, 0));
return (int)Math.Round(max, 0);
} }
} }
/// <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 DrawStringMonospace(this Graphics graphics, string s, Font font, Brush brush, PointF point)
{
int widest = graphics.GetWidestChar(font);
for (int i = 0; i < s.Length; i++)
{
graphics.DrawString(s[i].ToString(), font, brush, point);
point.X += widest;
}
}
/// <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>
/// /// <param name="width">The specified width.</param>
public static void DrawStringFixedWidth(this Graphics graphics, string s, Font font, Brush brush, float x, float y, float width)
{
for (int i = 0; i < s.Length; i++)
{
graphics.DrawString(s[i].ToString(), font, brush, x, y);
x += width;
}
}
/// <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>
/// <param name="width">The specified width.</param>
public static void DrawStringFixedWidth(this Graphics graphics, string s, Font font, Brush brush, PointF point, float width)
{
for (int i = 0; i < s.Length; i++)
{
graphics.DrawString(s[i].ToString(), font, brush, point);
point.X += width;
}
}
/// <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(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(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(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.TryGetValue(font, out int value))
{
return value;
}
float max = 0;
char maxx = ' ';
for (int i = 0; i <= 255; i++)
{
char c = (char)i;
if (char.IsLetterOrDigit(c))
{
float neww = graphics.MeasureString(c.ToString(), font).Width;
if (neww >= max)
{
max = neww;
maxx = c;
}
}
}
Console.WriteLine((int)Math.Round(max, 0));
Console.WriteLine(maxx);
fonts.Add(font, (int)Math.Round(max, 0));
return (int)Math.Round(max, 0);
}
} }
@@ -1,29 +1,22 @@
using System; namespace DesktopMagicPluginAPI.Drawing;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace DesktopMagicPluginAPI.Drawing /// <summary>
/// Specifies which render quality is used to display the bitmap images.
/// </summary>
public enum RenderQuality
{ {
/// <summary> /// <summary>
/// Specifies which render quality is used to display the bitmap images. /// Slower then <see cref="Low"/> but produces higher quality output.
/// </summary> /// </summary>
public enum RenderQuality High,
{
/// <summary>
/// Slower then <see cref="Low"/> but produces higher quality output.
/// </summary>
High,
/// <summary> /// <summary>
/// Faster then <see cref="High"/> but produces lower quality output. /// Faster then <see cref="High"/> but produces lower quality output.
/// </summary> /// </summary>
Low, Low,
/// <summary> /// <summary>
/// Provides performance benefits over <see cref="Low"/> /// Provides performance benefits over <see cref="Low"/>
/// </summary> /// </summary>
Performance Performance
}
} }
+38 -39
View File
@@ -1,53 +1,52 @@
using System; using System;
using System.Drawing; using System.Drawing;
namespace DesktopMagicPluginAPI namespace DesktopMagicPluginAPI;
/// <summary>
/// Defines properties and methods that provide information about the main application.
/// </summary>
public interface IPluginData
{ {
/// <summary> /// <summary>
/// Defines properties and methods that provide information about the main application. /// Gets the current font of the current theme.
/// </summary> /// </summary>
public interface IPluginData [Obsolete("Use the \"Theme\" property instead")]
{ string Font { get; }
/// <summary>
/// Gets the current font of the current theme.
/// </summary>
[Obsolete("Use the \"Theme\" property instead")]
string Font { get; }
/// <summary> /// <summary>
/// Gets the current color of the current theme. /// Gets the current color of the current theme.
/// </summary> /// </summary>
[Obsolete("Use the \"Theme\" property instead")] [Obsolete("Use the \"Theme\" property instead")]
Color Color { get; } Color Color { get; }
/// <summary> /// <summary>
/// Gets the current theme setting of the main application. /// Gets the current theme setting of the main application.
/// </summary> /// </summary>
ITheme Theme { get; } ITheme Theme { get; }
/// <summary> /// <summary>
/// Gets the window size of the plugin window. /// Gets the window size of the plugin window.
/// </summary> /// </summary>
Size WindowSize { get; } Size WindowSize { get; }
/// <summary> /// <summary>
/// Gets the window position of the plugin window. /// Gets the window position of the plugin window.
/// </summary> /// </summary>
Point WindowPosition { get; } Point WindowPosition { get; }
/// <summary> /// <summary>
/// Gets the name of the plugin. /// Gets the name of the plugin.
/// </summary> /// </summary>
string PluginName { get; } string PluginName { get; }
/// <summary> /// <summary>
/// Gets the path of the parent directory of the plugin. /// Gets the path of the parent directory of the plugin.
/// </summary> /// </summary>
string PluginPath { get; } string PluginPath { get; }
/// <summary> /// <summary>
/// Updates the plugin window. /// Updates the plugin window.
/// </summary> /// </summary>
void UpdateWindow(); void UpdateWindow();
}
} }
+28 -29
View File
@@ -1,40 +1,39 @@
using System.Drawing; using System.Drawing;
namespace DesktopMagicPluginAPI namespace DesktopMagicPluginAPI;
/// <summary>
/// The theme settings of the main application.
/// </summary>
public interface ITheme
{ {
/// <summary> /// <summary>
/// The theme settings of the main application. /// Gets the primary color of the current theme.
/// </summary> /// </summary>
public interface ITheme Color PrimaryColor { get; }
{
/// <summary>
/// Gets the primary color of the current theme.
/// </summary>
Color PrimaryColor { get; }
/// <summary> /// <summary>
/// Gets the secondary color of the current theme. /// Gets the secondary color of the current theme.
/// </summary> /// </summary>
Color SecondaryColor { get; } Color SecondaryColor { get; }
/// <summary> /// <summary>
/// Gets the background color of the current theme. /// Gets the background color of the current theme.
/// </summary> /// </summary>
Color BackgroundColor { get; } Color BackgroundColor { get; }
/// <summary> /// <summary>
/// Gets the font of the current theme. /// Gets the font of the current theme.
/// </summary> /// </summary>
string Font { get; } string Font { get; }
/// <summary> /// <summary>
/// Gets the corner radius of the current theme. /// Gets the corner radius of the current theme.
/// </summary> /// </summary>
int CornerRadius { get; } int CornerRadius { get; }
/// <summary> /// <summary>
/// Gets the corner radius of the current theme. /// Gets the corner radius of the current theme.
/// </summary> /// </summary>
int Margin { get; } int Margin { get; }
}
} }
+35 -36
View File
@@ -1,50 +1,49 @@
using System; using System;
namespace DesktopMagicPluginAPI.Inputs namespace DesktopMagicPluginAPI.Inputs;
/// <summary>
/// Represents a button control.
/// </summary>
public class Button : Element
{ {
/// <summary> /// <summary>
/// Represents a button control. /// Occurs when the button gets clicked.
/// </summary> /// </summary>
public class Button : Element public event Action OnClick;
private string _value;
/// <summary>
/// Gets or sets the text caption displayed in the <see cref="Button"/> element.
/// </summary>
public string Value
{ {
/// <summary> get => _value;
/// Occurs when the button gets clicked. set
/// </summary>
public event Action OnClick;
private string _value;
/// <summary>
/// Gets or sets the text caption displayed in the <see cref="Button"/> element.
/// </summary>
public string Value
{ {
get => _value; if (_value != value)
set
{ {
if (_value != value) _value = value;
{ ValueChanged();
_value = value;
ValueChanged();
}
} }
} }
}
/// <summary> /// <summary>
/// Initializes a new instance of the <see cref="Button"/> class with the provided <paramref name="value"/>. /// Initializes a new instance of the <see cref="Button"/> class with the provided <paramref name="value"/>.
/// </summary> /// </summary>
/// <param name="value">The text caption displayed in the <see cref="Button"/> control.</param> /// <param name="value">The text caption displayed in the <see cref="Button"/> control.</param>
public Button(string value) public Button(string value)
{ {
Value = value; Value = value;
} }
/// <summary> /// <summary>
/// Triggers the <see cref="OnClick"/> event. /// Triggers the <see cref="OnClick"/> event.
/// </summary> /// </summary>
public void Click() public void Click()
{ {
OnClick?.Invoke(); OnClick?.Invoke();
}
} }
} }
+26 -27
View File
@@ -1,35 +1,34 @@
namespace DesktopMagicPluginAPI.Inputs namespace DesktopMagicPluginAPI.Inputs;
{
/// <summary>
/// Represents a check box control.
/// </summary>
public class CheckBox : Element
{
private bool _value;
/// <summary> /// <summary>
/// Gets or set a value indicating whether the <see cref="CheckBox"/> is in the checked state. /// Represents a check box control.
/// </summary> /// </summary>
public bool Value public class CheckBox : Element
{
private bool _value;
/// <summary>
/// Gets or set a value indicating whether the <see cref="CheckBox"/> is in the checked state.
/// </summary>
public bool Value
{
get => _value;
set
{ {
get => _value; if (_value != value)
set
{ {
if (_value != value) _value = value;
{ ValueChanged();
_value = value;
ValueChanged();
}
} }
} }
}
/// <summary> /// <summary>
/// Initializes a new instance of the <see cref="CheckBox"/> class with the provided <paramref name="value"/>. /// Initializes a new instance of the <see cref="CheckBox"/> class with the provided <paramref name="value"/>.
/// </summary> /// </summary>
/// <param name="value">A value indicating whether the <see cref="CheckBox"/> is in the checked state.</param> /// <param name="value">A value indicating whether the <see cref="CheckBox"/> is in the checked state.</param>
public CheckBox(bool value) public CheckBox(bool value)
{ {
Value = value; Value = value;
}
} }
} }
+33 -34
View File
@@ -1,46 +1,45 @@
using System.Collections.ObjectModel; using System.Collections.ObjectModel;
namespace DesktopMagicPluginAPI.Inputs namespace DesktopMagicPluginAPI.Inputs;
/// <summary>
/// Represents a selection control with a drop-down list.
/// </summary>
public class ComboBox : Element
{ {
private string _value;
/// <summary> /// <summary>
/// Represents a selection control with a drop-down list. /// Gets the collection used to generate the content of the <see cref="ComboBox"/>.
/// </summary> /// </summary>
public class ComboBox : Element public ObservableCollection<string> Items { get; } = [];
/// <summary>
/// Gets the currently selected item associated with this <see cref="ComboBox"/>.
/// </summary>
/// <remarks>If you assign a value to this property, the displayed text in the user interface will not be changed.</remarks>
public string Value
{ {
private string _value; get => _value;
set
/// <summary>
/// Gets the collection used to generate the content of the <see cref="ComboBox"/>.
/// </summary>
public ObservableCollection<string> Items { get; } = new ObservableCollection<string>();
/// <summary>
/// Gets the currently selected item associated with this <see cref="ComboBox"/>.
/// </summary>
/// <remarks>If you assign a value to this property, the displayed text in the user interface will not be changed.</remarks>
public string Value
{ {
get => _value; if (_value != value)
set
{ {
if (_value != value) _value = value;
{ ValueChanged();
_value = value;
ValueChanged();
}
}
}
/// <summary>
/// Initializes a new instance of the <see cref="Label"/> class with the provided <paramref name="items"/>.
/// </summary>
/// <param name="items"></param>
public ComboBox(params string[] items)
{
foreach (string item in items)
{
Items.Add(item);
} }
} }
} }
/// <summary>
/// Initializes a new instance of the <see cref="Label"/> class with the provided <paramref name="items"/>.
/// </summary>
/// <param name="items"></param>
public ComboBox(params string[] items)
{
foreach (string item in items)
{
Items.Add(item);
}
}
} }
+14 -15
View File
@@ -1,23 +1,22 @@
using System; using System;
namespace DesktopMagicPluginAPI.Inputs namespace DesktopMagicPluginAPI.Inputs;
/// <summary>
/// The element base class.
/// </summary>
public abstract class Element
{ {
/// <summary> /// <summary>
/// The element base class. /// Occurs when the value has been changed.
/// </summary> /// </summary>
public abstract class Element public event Action OnValueChanged;
{
/// <summary>
/// Occurs when the value has been changed.
/// </summary>
public event Action OnValueChanged;
/// <summary> /// <summary>
/// Triggers the <see cref="OnValueChanged"/> event. /// Triggers the <see cref="OnValueChanged"/> event.
/// </summary> /// </summary>
protected void ValueChanged() protected void ValueChanged()
{ {
OnValueChanged?.Invoke(); OnValueChanged?.Invoke();
}
} }
} }
@@ -1,46 +1,45 @@
using System; using System;
namespace DesktopMagicPluginAPI.Inputs namespace DesktopMagicPluginAPI.Inputs;
/// <summary>
/// Marks a Property as element.
/// </summary>
[AttributeUsage(AttributeTargets.Field)]
public class ElementAttribute : Attribute
{ {
/// <summary> /// <summary>
/// Marks a Property as element. /// The name of the element.
/// </summary> /// </summary>
[AttributeUsage(AttributeTargets.Field)] public string Name { get; }
public class ElementAttribute : Attribute
/// <summary>
/// The order index of the element.
/// </summary>
public int OrderIndex { get; }
/// <summary>
/// Marks a Property as element with the provided <paramref name="name"/> and <paramref name="orderIndex"/>.
/// </summary>
/// <param name="name">The name of the element.</param>
/// <param name="orderIndex">The order index of the element.</param>
public ElementAttribute(string name, int orderIndex = 0)
{ {
/// <summary> Name = name;
/// The name of the element. OrderIndex = orderIndex;
/// </summary> }
public string Name { get; }
/// <summary> /// <summary>
/// The order index of the element. /// Marks a Property as element with the provided <paramref name="orderIndex"/>.
/// </summary> /// </summary>
public int OrderIndex { get; } /// <param name="orderIndex">The order index of the element.</param>
public ElementAttribute(int orderIndex)
{
OrderIndex = orderIndex;
}
/// <summary> /// <inheritdoc cref="ElementAttribute"/>
/// Marks a Property as element with the provided <paramref name="name"/> and <paramref name="orderIndex"/>. public ElementAttribute()
/// </summary> {
/// <param name="name">The name of the element.</param>
/// <param name="orderIndex">The order index of the element.</param>
public ElementAttribute(string name, int orderIndex = 0)
{
Name = name;
OrderIndex = orderIndex;
}
/// <summary>
/// Marks a Property as element with the provided <paramref name="orderIndex"/>.
/// </summary>
/// <param name="orderIndex">The order index of the element.</param>
public ElementAttribute(int orderIndex)
{
OrderIndex = orderIndex;
}
/// <inheritdoc cref="ElementAttribute"/>
public ElementAttribute()
{
}
} }
} }
@@ -1,73 +1,72 @@
using System; using System;
namespace DesktopMagicPluginAPI.Inputs namespace DesktopMagicPluginAPI.Inputs;
/// <summary>
/// Represents a up-down control.
/// </summary>
public class IntegerUpDown : Element
{ {
private int _value;
/// <summary> /// <summary>
/// Represents a up-down control. /// Gets or sets the maximum value for the <see cref="IntegerUpDown"/> element.
/// </summary> /// </summary>
public class IntegerUpDown : Element public int Maximum { get; }
/// <summary>
/// Gets or sets the minimum value for the <see cref="IntegerUpDown"/> element.
/// </summary>
public int Minimum { get; }
/// <summary>
/// Gets or sets the value assigned to the <see cref="IntegerUpDown"/> element.
/// </summary>
public int Value
{ {
private int _value; get => _value;
set
/// <summary>
/// Gets or sets the maximum value for the <see cref="IntegerUpDown"/> element.
/// </summary>
public int Maximum { get; }
/// <summary>
/// Gets or sets the minimum value for the <see cref="IntegerUpDown"/> element.
/// </summary>
public int Minimum { get; }
/// <summary>
/// Gets or sets the value assigned to the <see cref="IntegerUpDown"/> element.
/// </summary>
public int Value
{ {
get => _value; if (_value != value)
set
{ {
if (_value != value) _value = value;
{ ValueChanged();
_value = value;
ValueChanged();
}
} }
} }
}
/// <summary> /// <summary>
/// Initializes a new instance of the <see cref="IntegerUpDown"/> class with the provided <paramref name="min"/> value, <paramref name="max"/> value and <paramref name="value"/>. /// Initializes a new instance of the <see cref="IntegerUpDown"/> class with the provided <paramref name="min"/> value, <paramref name="max"/> value and <paramref name="value"/>.
/// </summary> /// </summary>
/// <param name="min">The maximum value for the <see cref="IntegerUpDown"/> element.</param> /// <param name="min">The maximum value for the <see cref="IntegerUpDown"/> element.</param>
/// <param name="max">The minimum value for the <see cref="IntegerUpDown"/> element.</param> /// <param name="max">The minimum value for the <see cref="IntegerUpDown"/> element.</param>
/// <param name="value">The value assigned to the <see cref="IntegerUpDown"/> element.</param> /// <param name="value">The value assigned to the <see cref="IntegerUpDown"/> element.</param>
/// <exception cref="ArgumentException"></exception> /// <exception cref="ArgumentException"></exception>
public IntegerUpDown(int min, int max, int value = 0) public IntegerUpDown(int min, int max, int value = 0)
{
if (min < 0)
{ {
if (min < 0) throw new ArgumentException("Value can not be negative!", nameof(min));
{ }
throw new ArgumentException("Value can not be negative!", nameof(min)); if (max < 0)
} {
if (max < 0) throw new ArgumentException("Value can not be negative!", nameof(max));
{ }
throw new ArgumentException("Value can not be negative!", nameof(max)); if (min > max)
} {
if (min > max) throw new ArgumentException($"{nameof(min)} is greater than or equal to {nameof(max)}!");
{ }
throw new ArgumentException($"{nameof(min)} is greater than or equal to {nameof(max)}!"); if (value > max)
} {
if (value > max) throw new ArgumentException($"{nameof(value)} is greater than {nameof(max)}!");
{ }
throw new ArgumentException($"{nameof(value)} is greater than {nameof(max)}!"); if (value < min)
} {
if (value < min) throw new ArgumentException($"{nameof(value)} is less than {nameof(min)}!");
{ }
throw new ArgumentException($"{nameof(value)} is less than {nameof(min)}!");
}
Minimum = min; Minimum = min;
Maximum = max; Maximum = max;
Value = value; Value = value;
}
} }
} }
+32 -33
View File
@@ -1,42 +1,41 @@
namespace DesktopMagicPluginAPI.Inputs namespace DesktopMagicPluginAPI.Inputs;
{
/// <summary>
/// Represents a label control.
/// </summary>
public class Label : Element
{
private string _value;
/// <summary> /// <summary>
/// Gets or sets the text associated with this <see cref="Label"/>. /// Represents a label control.
/// </summary> /// </summary>
public string Value public class Label : Element
{
private string _value;
/// <summary>
/// Gets or sets the text associated with this <see cref="Label"/>.
/// </summary>
public string Value
{
get => _value;
set
{ {
get => _value; if (_value != value)
set
{ {
if (_value != value) _value = value;
{ ValueChanged();
_value = value;
ValueChanged();
}
} }
} }
}
/// <summary> /// <summary>
/// Gets or set a value indicating whether the content of the <see cref="Label"/> is bold or not. /// Gets or set a value indicating whether the content of the <see cref="Label"/> is bold or not.
/// </summary> /// </summary>
public bool Bold { get; set; } public bool Bold { get; set; }
/// <summary> /// <summary>
/// Initializes a new instance of the <see cref="Label"/> class with the provided <paramref name="value"/>. /// Initializes a new instance of the <see cref="Label"/> class with the provided <paramref name="value"/>.
/// </summary> /// </summary>
/// <param name="value">The text associated with this <see cref="Label"/></param> /// <param name="value">The text associated with this <see cref="Label"/></param>
/// <param name="bold">A value indicating whether the content of the <see cref="Label"/> is bold or not.</param> /// <param name="bold">A value indicating whether the content of the <see cref="Label"/> is bold or not.</param>
public Label(string value, bool bold = false) public Label(string value, bool bold = false)
{ {
Value = value; Value = value;
Bold = bold; Bold = bold;
}
} }
} }
+15 -22
View File
@@ -1,29 +1,22 @@
using System; namespace DesktopMagicPluginAPI.Inputs;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace DesktopMagicPluginAPI.Inputs /// <summary>
/// Mouse Buttons
/// </summary>
public enum MouseButton
{ {
/// <summary> /// <summary>
/// Mouse Buttons /// The left mouse button.
/// </summary> /// </summary>
public enum MouseButton Left,
{
/// <summary>
/// The left mouse button.
/// </summary>
Left,
/// <summary> /// <summary>
/// The middle mouse button. /// The middle mouse button.
/// </summary> /// </summary>
Middle, Middle,
/// <summary> /// <summary>
/// The right mouse button. /// The right mouse button.
/// </summary> /// </summary>
Right, Right,
}
} }
+56 -57
View File
@@ -1,72 +1,71 @@
using System; using System;
namespace DesktopMagicPluginAPI.Inputs namespace DesktopMagicPluginAPI.Inputs;
/// <summary>
/// Represents a slider control.
/// </summary>
public sealed class Slider : Element
{ {
private double _value;
/// <summary> /// <summary>
/// Represents a slider control. /// Gets or sets the maximum value for the <see cref="Slider"/> element.
/// </summary> /// </summary>
public sealed class Slider : Element public double Maximum { get; }
/// <summary>
/// Gets or sets the minimum value for the <see cref="Slider"/> element.
/// </summary>
public double Minimum { get; }
/// <summary>
/// Gets or sets the value assigned to the <see cref="Slider"/> element.
/// </summary>
public double Value
{ {
private double _value; get => _value;
set
/// <summary>
/// Gets or sets the maximum value for the <see cref="Slider"/> element.
/// </summary>
public double Maximum { get; }
/// <summary>
/// Gets or sets the minimum value for the <see cref="Slider"/> element.
/// </summary>
public double Minimum { get; }
/// <summary>
/// Gets or sets the value assigned to the <see cref="Slider"/> element.
/// </summary>
public double Value
{ {
get => _value; if (_value != value)
set
{ {
if (_value != value) _value = value;
{ ValueChanged();
_value = value;
ValueChanged();
}
} }
} }
}
/// <summary> /// <summary>
/// Initializes a new instance of the <see cref="Slider"/> class with the provided <paramref name="min"/> value, <paramref name="max"/> value and <paramref name="value"/>. /// Initializes a new instance of the <see cref="Slider"/> class with the provided <paramref name="min"/> value, <paramref name="max"/> value and <paramref name="value"/>.
/// </summary> /// </summary>
/// <param name="min">The maximum value for the <see cref="Slider"/> element.</param> /// <param name="min">The maximum value for the <see cref="Slider"/> element.</param>
/// <param name="max">The minimum value for the <see cref="Slider"/> element.</param> /// <param name="max">The minimum value for the <see cref="Slider"/> element.</param>
/// <param name="value">The value assigned to the <see cref="Slider"/> element.</param> /// <param name="value">The value assigned to the <see cref="Slider"/> element.</param>
public Slider(double min, double max, double value = 0) public Slider(double min, double max, double value = 0)
{
if (min < 0)
{ {
if (min < 0) throw new ArgumentException("Value can not be negative!", nameof(min));
{ }
throw new ArgumentException("Value can not be negative!", nameof(min)); if (max < 0)
} {
if (max < 0) throw new ArgumentException("Value can not be negative!", nameof(max));
{ }
throw new ArgumentException("Value can not be negative!", nameof(max)); if (min > max)
} {
if (min > max) throw new ArgumentException($"{nameof(min)} is greater than or equal to {nameof(max)}!");
{ }
throw new ArgumentException($"{nameof(min)} is greater than or equal to {nameof(max)}!"); if (value > max)
} {
if (value > max) throw new ArgumentException($"{nameof(value)} is greater than {nameof(max)}!");
{ }
throw new ArgumentException($"{nameof(value)} is greater than {nameof(max)}!"); if (value < min)
} {
if (value < min) throw new ArgumentException($"{nameof(value)} is less than {nameof(min)}!");
{ }
throw new ArgumentException($"{nameof(value)} is less than {nameof(min)}!");
}
Minimum = min; Minimum = min;
Maximum = max; Maximum = max;
Value = value; Value = value;
}
} }
} }
+26 -27
View File
@@ -1,35 +1,34 @@
namespace DesktopMagicPluginAPI.Inputs namespace DesktopMagicPluginAPI.Inputs;
{
/// <summary>
/// Represents a text box control.
/// </summary>
public class TextBox : Element
{
private string _value;
/// <summary> /// <summary>
/// Gets or sets the text associated with this <see cref="TextBox"/>. /// Represents a text box control.
/// </summary> /// </summary>
public string Value public class TextBox : Element
{
private string _value;
/// <summary>
/// Gets or sets the text associated with this <see cref="TextBox"/>.
/// </summary>
public string Value
{
get => _value;
set
{ {
get => _value; if (_value != value)
set
{ {
if (_value != value) _value = value;
{ ValueChanged();
_value = value;
ValueChanged();
}
} }
} }
}
/// <summary> /// <summary>
/// Initializes a new instance of the <see cref="TextBox"/> class with the provided <paramref name="value"/>. /// Initializes a new instance of the <see cref="TextBox"/> class with the provided <paramref name="value"/>.
/// </summary> /// </summary>
/// <param name="value">The text associated with this control.</param> /// <param name="value">The text associated with this control.</param>
public TextBox(string value) public TextBox(string value)
{ {
Value = value; Value = value;
}
} }
} }
+60 -61
View File
@@ -4,78 +4,77 @@ using DesktopMagicPluginAPI.Inputs;
using System; using System;
using System.Drawing; using System.Drawing;
namespace DesktopMagicPluginAPI namespace DesktopMagicPluginAPI;
/// <summary>
/// The plugin class.
/// </summary>
public abstract class Plugin
{ {
private IPluginData application = null;
/// <summary> /// <summary>
/// The plugin class. /// Informations about the main application.
/// </summary> /// </summary>
public abstract class Plugin public IPluginData Application
{ {
private IPluginData application = null; get => application;
set => application = application is null ? value : throw new InvalidOperationException($"You cannot set the value of the {nameof(Application)} property");
}
/// <summary> /// <summary>
/// Informations about the main application. /// Gets or sets the interval, expressed in milliseconds, at which to call the <see cref="Main"/> method.
/// </summary> /// </summary>
public IPluginData Application public virtual int UpdateInterval { get; set; } = 1000;
{
get => application;
set => application = application is null ? value : throw new InvalidOperationException($"You cannot set the value of the {nameof(Application)} property");
}
/// <summary> /// <summary>
/// Gets or sets the interval, expressed in milliseconds, at which to call the <see cref="Main"/> method. /// Gets or sets the render quality of the bitmap image.
/// </summary> /// </summary>
public virtual int UpdateInterval { get; set; } = 1000; public virtual RenderQuality RenderQuality { get; set; } = RenderQuality.High;
/// <summary> /// <summary>
/// Gets or sets the render quality of the bitmap image. /// Occurs once when the plugin gets activated.
/// </summary> /// </summary>
public virtual RenderQuality RenderQuality { get; set; } = RenderQuality.High; public virtual void Start()
{
}
/// <summary> /// <summary>
/// Occurs once when the plugin gets activated. /// Occurs once when the plugin gets deactivated.
/// </summary> /// </summary>
public virtual void Start() public virtual void Stop()
{ {
} }
/// <summary> /// <summary>
/// Occurs once when the plugin gets deactivated. /// Occurs when the <see cref="UpdateInterval"/> elapses.
/// </summary> /// </summary>
public virtual void Stop() /// <returns></returns>
{ public abstract Bitmap Main();
}
/// <summary> /// <summary>
/// Occurs when the <see cref="UpdateInterval"/> elapses. /// Occurs when the window is clicked by the mouse.
/// </summary> /// </summary>
/// <returns></returns> /// <param name="position">The x- and y-coordinates of the mouse pointer position relative to the plugin window.</param>
public abstract Bitmap Main(); /// <param name="mouseButton">The button associated with the event.</param>
public virtual void OnMouseClick(Point position, MouseButton mouseButton)
{
}
/// <summary> /// <summary>
/// Occurs when the window is clicked by the mouse. /// Occurs when the mouse pointer is moved over the control.
/// </summary> /// </summary>
/// <param name="position">The x- and y-coordinates of the mouse pointer position relative to the plugin window.</param> /// <param name="position">The x- and y-coordinates of the mouse pointer position relative to the plugin window.</param>
/// <param name="mouseButton">The button associated with the event.</param> public virtual void OnMouseMove(Point position)
public virtual void OnMouseClick(Point position, MouseButton mouseButton) {
{ }
}
/// <summary> /// <summary>
/// Occurs when the mouse pointer is moved over the control. /// Occurs when the user rotates the mouse wheel while the mouse pointer is over this element.
/// </summary> /// </summary>
/// <param name="position">The x- and y-coordinates of the mouse pointer position relative to the plugin window.</param> /// <param name="position">The x- and y-coordinates of the mouse pointer position relative to the plugin window.</param>
public virtual void OnMouseMove(Point position) /// <param name="delta">A value that indicates the amount that the mouse wheel has changed.</param>
{ public virtual void OnMouseWheel(Point position, int delta)
} {
/// <summary>
/// Occurs when the user rotates the mouse wheel while the mouse pointer is over this element.
/// </summary>
/// <param name="position">The x- and y-coordinates of the mouse pointer position relative to the plugin window.</param>
/// <param name="delta">A value that indicates the amount that the mouse wheel has changed.</param>
public virtual void OnMouseWheel(Point position, int delta)
{
}
} }
} }
-5
View File
@@ -1,5 +0,0 @@
###############
# temp file #
###############
*.yml
.manifest
-2
View File
@@ -1,2 +0,0 @@
# PLACEHOLDER
TODO: Add .NET projects to the *src* folder and run `docfx` to generate **REAL** *API Documentation*!
@@ -1 +0,0 @@
# Add your introductions here!
@@ -1,2 +0,0 @@
- name: Introduction
href: intro.md
-65
View File
@@ -1,65 +0,0 @@
{
"metadata": [
{
"src": [
{
"files": [
"**.csproj"
],
"src": "C:\\Users\\David\\Programmieren\\DesktopMagic\\src\\DesktopMagicPluginAPI"
}
],
"dest": "api",
"disableGitFeatures": false,
"disableDefaultFilter": false
}
],
"build": {
"content": [
{
"files": [
"api/**.yml",
"api/index.md"
]
},
{
"files": [
"articles/**.md",
"articles/**/toc.yml",
"toc.yml",
"*.md"
]
}
],
"resource": [
{
"files": [
"images/**"
]
}
],
"overwrite": [
{
"files": [
"apidoc/**.md"
],
"exclude": [
"obj/**",
"_site/**"
]
}
],
"dest": "_site",
"globalMetadataFiles": [],
"fileMetadataFiles": [],
"template": [
"default"
],
"postProcessors": [],
"markdownEngineName": "markdig",
"noLangKeyword": false,
"keepFileLink": false,
"cleanupCacheHistory": false,
"disableGitFeatures": false
}
}
-4
View File
@@ -1,4 +0,0 @@
# This is the **HOMEPAGE**.
Refer to [Markdown](http://daringfireball.net/projects/markdown/) for how to write markdown files.
## Quick Start Notes:
1. Add images to the *images* folder if the file is referencing an image.
-5
View File
@@ -1,5 +0,0 @@
- name: Articles
href: articles/
- name: Api Documentation
href: api/
homepage: api/index.md