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.Inputs;
using System;
using System.Drawing;
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;
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 && oldShortDatecheckBoxValue == shortDatecheckBox.Value)
{
if (oldDateTime.Date == DateTime.Now.Date && oldColor == Application.Theme.PrimaryColor && oldFont == Application.Theme.Font)
{
return null;
}
oldDateTime = DateTime.Now;
oldColor = Application.Theme.PrimaryColor;
oldFont = Application.Theme.Font;
string date = DateTime.Now.ToLongDateString();
Font font = new Font(Application.Theme.Font, 200);
Bitmap bmp = new Bitmap(1, 1);
bmp.SetResolution(100, 100);
using Graphics tmpGr = Graphics.FromImage(bmp);
tmpGr.TextRenderingHint = TextRenderingHint.AntiAlias;
SizeF size = tmpGr.MeasureString(date, font);
bmp = new Bitmap((int)size.Width, (int)size.Height);
bmp.SetResolution(100, 100);
using Graphics gr = Graphics.FromImage(bmp);
gr.TextRenderingHint = TextRenderingHint.AntiAlias;
gr.DrawString(date, font, new SolidBrush(Application.Theme.PrimaryColor), 0, 0);
return bmp;
return null;
}
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;
@@ -7,279 +9,279 @@ using System.Collections.Generic;
using System.Drawing;
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;
private const int fftLength = 1024; // NAudio fft wants powers of two!
private readonly SampleAggregator sampleAggregator = new SampleAggregator(fftLength);
private volatile bool calculate = true;
private readonly Bitmap output = new Bitmap(880, 300);
sampleAggregator.FftCalculated += FftCalculated;
sampleAggregator.PerformFFT = true;
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;
sampleAggregator.PerformFFT = true;
byte[] buffer = e.Buffer;
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;
waveIn.StartRecording();
private void FftCalculated(object sender, FftEventArgs e)
{
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;
int bytesRecorded = e.BytesRecorded;
int bufferIncrement = waveIn.WaveFormat.BlockAlign;
v = 20;
}
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);
sampleAggregator.Add(sample32);
fft[i] = (fft[i] + lastFft[i]) / 2.05;
}
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;
}
List<double> fft = new List<double>();
for (int i = 0; i < (e.Result.Length / 2) - 70; i++)
{
int v = i;
if (v < 20)
double temp = 0;
int j;
for (j = i * count; j < count + (i * count); j++)
{
v = 20;
temp += fft[j];
}
int multiplier = 100 - (MainWindow.AmplifierLevel * 2);
multiplier = multiplier == 0 ? 1 : multiplier;
fft.Add(Math.Abs(e.Result[i].Y * v / multiplier));
scaledFft.Add(temp);
}
}
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;
}
else
{
fft[i] = lastFft[i] - 0.0005;
temp += scaledFft[i + j];
}
}
scaledFft[i] = temp / flattenValue;
}
}
int barCount = 0;
List<double> scaledFft = new List<double>();
if (barCount > 0)
for (int i = 0; i < scaledFft.Count; i++)
{
if (flattenValue > 0)
{
int count = fft.Count / barCount;
Console.WriteLine(count);
for (int i = 0; i < barCount; i++)
double temp = 0;
for (int j = 0; j < flattenValue; j++)
{
double temp = 0;
int j;
for (j = i * count; j < count + (i * count); j++)
if (i - j >= 0)
{
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
int flattenValue = 4;
for (int i = 0; i < scaledFft.Count; i++)
if (!MainWindow.LineMode)
{
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;
for (int j = 0; j < flattenValue; j++)
fftIndex = scaledFft.Count - 1;
}
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)
{
temp += scaledFft[i + j];
}
case 1:
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)
{
fftIndex = scaledFft.Count - 1;
}
for (int pointIndex = 0; pointIndex < scaledFft.Count; pointIndex += 1)
{
int value = (int)Math.Max(scaledFft[fftIndex] * 50000, 0);
switch (MainWindow.SpectrumMode)
if (!fftIndexReverse)
{
case 1:
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;
fftIndex -= 2;
}
if (MainWindow.MirrorMode || MainWindow.SpectrumMode == 1)
if (fftIndex <= 0 || fftIndexReverse)
{
if (!fftIndexReverse)
{
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);
fftIndexReverse = true;
fftIndex += 2;
}
}
else
{
gr.FillPolygon(brush, points);
fftIndex++;
}
}
Application.UpdateWindow();
}
catch (Exception ex)
{
App.Logger.Log(ex.Message, "Music Visualizer", LogSeverity.Error);
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
{
gr.FillPolygon(brush, points);
}
}
Application.UpdateWindow();
}
private void SetPoints(PointF[] points, int width, int height, int offset)
catch (Exception ex)
{
switch (MainWindow.SpectrumMode)
{
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;
}
App.Logger.Log(ex.Message, "Music Visualizer", LogSeverity.Error);
}
}
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()
{
calculate = false;
waveIn?.StopRecording();
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;
}
}
}
@@ -1,55 +1,40 @@
using DesktopMagicPluginAPI;
using DesktopMagicPluginAPI.Drawing;
using DesktopMagicPluginAPI.Inputs;
using System;
using System.Drawing;
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:")]
private readonly CheckBox checkBox = new CheckBox(true);
string time = displaySecondscheckBox.Value ? DateTime.Now.ToLongTimeString() : DateTime.Now.ToShortTimeString();
public override int UpdateInterval => 1000;
Font font = new Font(Application.Theme.Font, 200);
public override Bitmap Main()
{
string time = checkBox.Value ? DateTime.Now.ToLongTimeString() : DateTime.Now.ToShortTimeString();
Bitmap bmp = new Bitmap(1, 1);
bmp.SetResolution(100, 100);
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);
using Graphics tmpGr = Graphics.FromImage(bmp);
tmpGr.TextRenderingHint = TextRenderingHint.AntiAlias;
bmp = new Bitmap((int)size.Width, (int)size.Height);
bmp.SetResolution(100, 100);
SizeF size = CalculateSize(tmpGr, font);
using Graphics gr = Graphics.FromImage(bmp);
bmp = new Bitmap((int)size.Width, (int)size.Height);
bmp.SetResolution(100, 100);
gr.TextRenderingHint = TextRenderingHint.AntiAlias;
gr.DrawString(time, font, new SolidBrush(Application.Theme.PrimaryColor), 0, 0);
using Graphics gr = Graphics.FromImage(bmp);
gr.TextRenderingHint = TextRenderingHint.AntiAlias;
gr.DrawStringNoLeftPadding(time, font, new SolidBrush(Application.Theme.PrimaryColor), 0, 0);
return bmp;
}
private SizeF CalculateSize(Graphics graphics, Font font)
{
string template = 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;
}
return bmp;
}
}
+6 -6
View File
@@ -12,7 +12,7 @@
<RepositoryUrl>https://github.com/Stone-Red-Code/DesktopMagic</RepositoryUrl>
<AssemblyVersion>0.0.3.2</AssemblyVersion>
<FileVersion>0.0.3.2</FileVersion>
<TargetFramework>net6.0-windows</TargetFramework>
<TargetFramework>net8.0-windows7.0</TargetFramework>
</PropertyGroup>
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|AnyCPU'">
@@ -27,12 +27,12 @@
<ItemGroup>
<PackageReference Include="AlwaysUpToDate" Version="1.0.0.4" />
<PackageReference Include="Extended.Wpf.Toolkit" Version="4.1.0" />
<PackageReference Include="Google.Apis.Calendar.v3" Version="1.55.0.2410" />
<PackageReference Include="MaterialDesignThemes" Version="4.0.0" />
<PackageReference Include="NAudio" Version="2.0.1" />
<PackageReference Include="Extended.Wpf.Toolkit" Version="4.5.1" />
<PackageReference Include="Google.Apis.Calendar.v3" Version="1.64.0.3171" />
<PackageReference Include="MaterialDesignThemes" Version="4.9.0" />
<PackageReference Include="NAudio" Version="2.2.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>
+100 -101
View File
@@ -6,123 +6,122 @@ using System.Windows;
using System.Windows.Controls;
using System.Windows.Media;
namespace DesktopMagic.Dialogs
namespace DesktopMagic.Dialogs;
/// <summary>
/// Interaction logic for ColorDialog.xaml
/// </summary>
public partial class ColorDialog : Window
{
/// <summary>
/// Interaction logic for ColorDialog.xaml
/// </summary>
public partial class ColorDialog : Window
public System.Drawing.Color ResultColor { get; private set; }
public Brush ResultBrush { get; private set; }
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();
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] != '#')
{
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);
}
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
{
colorHexTextBox.Foreground = Brushes.Red;
colorHexTextBox.Select(1, 0);
}
}
private void SetColorText()
{
if (alphaSlider.Value == 255)
{
colorHexTextBox.Text = "#";
}
else
{
colorHexTextBox.Text = "#" + ((int)alphaSlider.Value).ToString("X2");
}
string hex = colorHexTextBox.Text;
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;
}
private void SetLanguageDictionary()
else
{
ResourceDictionary dict = new ResourceDictionary();
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);
colorHexTextBox.Foreground = Brushes.Red;
}
}
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.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")
{
InitializeComponent();
label.Content = content;
Title = title;
SetLanguageDictionary();
}
get => textBox.Text;
set => textBox.Text = value;
}
public string ResponseText
{
get => textBox.Text;
set => textBox.Text = value;
}
public InputDialog(string content, string title = "InputDialog")
{
InitializeComponent();
label.Content = content;
Title = title;
SetLanguageDictionary();
}
private void OkButton_Click(object sender, RoutedEventArgs e)
{
DialogResult = true;
}
private void OkButton_Click(object sender, RoutedEventArgs e)
{
DialogResult = true;
}
private void CancelButton_Click(object sender, RoutedEventArgs e)
{
DialogResult = false;
}
private void CancelButton_Click(object sender, RoutedEventArgs e)
{
DialogResult = false;
}
private void SetLanguageDictionary()
{
ResourceDictionary dict = new ResourceDictionary();
string currentCulture = Thread.CurrentThread.CurrentCulture.ToString();
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);
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);
}
}
+3 -1
View File
@@ -6,4 +6,6 @@
using System.Diagnostics.CodeAnalysis;
[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;
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;
}
public static string ConvertToHex(System.Windows.Media.Color color)
else if (hex.Length == 6 && Hex6().IsMatch(hex))
{
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;
}
public static bool TryConvertToSystemColor(string hex, out System.Drawing.Color color)
else
{
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.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;
}
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 && 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 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
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))
{
if (!IsPowerOfTwo(fftLength))
{
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);
throw new ArgumentException("FFT Length must be a power of two");
}
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;
}
public void Add(float value)
{
if (PerformFFT && FftCalculated != null)
// 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.
fftPos++;
if (fftPos >= fftLength)
{
// 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.
fftPos++;
if (fftPos >= fftLength)
{
fftPos = 0;
FastFourierTransform.FFT(true, m, fftBuffer);
FftCalculated(this, fftArgs);
}
fftPos = 0;
FastFourierTransform.FFT(true, m, fftBuffer);
FftCalculated(this, fftArgs);
}
}
}
public class FftEventArgs : EventArgs
private bool IsPowerOfTwo(int x)
{
public FftEventArgs(Complex[] result)
{
this.Result = result;
}
public Complex[] Result { get; private set; }
return (x & (x - 1)) == 0;
}
}
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.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;
public SettingElementGenerator(ComboBox optionsComboBox)
dockPanel.UpdateLayout();
textBlock.UpdateLayout();
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)
{
dockPanel.UpdateLayout();
textBlock.UpdateLayout();
if (settingElement.Element is DesktopMagicPluginAPI.Inputs.Label eLabel)
if (eLabel.Bold)
{
textBlock.Text = eLabel.Value;
textBlock.Margin = new Thickness(0, 5, 3, 0);
textBlock.HorizontalAlignment = HorizontalAlignment.Stretch;
textBlock.TextWrapping = TextWrapping.WrapWithOverflow;
if (eLabel.Bold)
textBlock.FontWeight = FontWeights.Bold;
}
eLabel.OnValueChanged += () =>
{
textBlock.Dispatcher.Invoke(() =>
{
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(() =>
{
textBlock.Text = eLabel.Value;
});
};
}
else if (settingElement.Element is DesktopMagicPluginAPI.Inputs.Button eButton)
DisplayException(ex.Message);
}
};
eButton.OnValueChanged += () =>
{
Button button = new()
button.Dispatcher.Invoke(() =>
{
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;
});
};
button.Content = eButton.Value;
});
};
_ = 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);
}
_ = dockPanel.Children.Add(button);
}
private void DisplayException(string message)
else if (settingElement.Element is DesktopMagicPluginAPI.Inputs.CheckBox eCheckBox)
{
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());
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;
});
};
PluginWindow window = MainWindow.Windows[index];
window?.Exit();
_ = 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);
}
}
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
internal static Theme Theme { get; } = new Theme();
public static bool EditMode { get; private set; } = false;
internal static Theme Theme { get; } = new Theme();
#endregion Global settings
@@ -42,18 +42,16 @@ namespace DesktopMagic
#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
public static List<PluginWindow> Windows { get; } = new List<PluginWindow>();
public static List<string> WindowNames { get; } = new List<string>();
private readonly RegistryKey key;
private readonly System.Windows.Forms.NotifyIcon notifyIcon = new();
private bool loaded = false;
private bool blockWindowsClosing = true;
public static List<PluginWindow> Windows { get; } = [];
public static List<string> WindowNames { get; } = [];
public MainWindow()
{
@@ -126,7 +124,7 @@ namespace DesktopMagic
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
{
_ = 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)))
{
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;
if (PluginName == directory[(directory.LastIndexOf("\\", StringComparison.InvariantCulture) + 1)..])
if (PluginName == directory[(directory.LastIndexOf('\\') + 1)..])
{
foreach (char c in badChars)
{
@@ -156,9 +154,9 @@ namespace DesktopMagic
CheckBox checkBox = new()
{
Name = "_PluginCb_" + clearPluginName,
Content = PluginName
Content = PluginName,
Style = (Style)FindResource("MaterialDesignDarkCheckBox")
};
checkBox.Style = (Style)FindResource("MaterialDesignDarkCheckBox");
checkBox.Click += CheckBox_Click;
bool exists = false;
@@ -446,7 +444,7 @@ namespace DesktopMagic
optionsPanel.UpdateLayout();
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") });
return;
@@ -593,7 +591,7 @@ namespace DesktopMagic
string[] data = lines[layoutsComboBox.SelectedIndex].Split(';');
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, "");
key.SetValue(name, value);
}
@@ -638,7 +636,7 @@ namespace DesktopMagic
return;
}
List<string> lines = File.ReadAllLines(App.ApplicationDataPath + "\\layouts.save").ToList();
List<string> lines = [.. File.ReadAllLines(App.ApplicationDataPath + "\\layouts.save")];
lines.RemoveAt(layoutsComboBox.SelectedIndex);
File.WriteAllLines(App.ApplicationDataPath + "\\layouts.save", lines);
LoadLayoutNames();
@@ -656,7 +654,7 @@ namespace DesktopMagic
{
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();
foreach (string valueName in key.GetValueNames())
{
@@ -682,7 +680,7 @@ namespace DesktopMagic
foreach (string line in lines)
{
string name = line[(line.LastIndexOf(";", StringComparison.InvariantCulture) + 1)..];
string name = line[(line.LastIndexOf(';') + 1)..];
_ = layoutsComboBox.Items.Add(name);
}
layoutsComboBox.SelectedIndex = int.Parse(key.GetValue("SelectedLayout", "0").ToString(), CultureInfo.InvariantCulture);
@@ -857,7 +855,7 @@ namespace DesktopMagic
private void SetLanguageDictionary()
{
ResourceDictionary dict = new ResourceDictionary();
ResourceDictionary dict = [];
string currentCulture = Thread.CurrentThread.CurrentUICulture.ToString();
if (currentCulture.Contains("de"))
+2 -7
View File
@@ -4,14 +4,9 @@ using System.Drawing;
namespace DesktopMagic.Plugins;
internal class PluginData : IPluginData
internal class PluginData(PluginWindow window) : IPluginData
{
private readonly PluginWindow window;
public PluginData(PluginWindow window)
{
this.window = window;
}
private readonly PluginWindow window = window;
public string Font => Theme.Font;
+39 -46
View File
@@ -24,6 +24,10 @@ namespace DesktopMagic;
public partial class PluginWindow : Window
{
public event Action PluginLoaded;
public event Action OnExit;
private readonly RegistryKey key;
private Thread pluginThread;
private System.Timers.Timer valueTimer;
@@ -34,10 +38,6 @@ public partial class PluginWindow : Window
public string PluginName { get; private set; }
public string PluginFolderPath { get; private set; }
public event Action PluginLoaded;
public event Action OnExit;
public PluginWindow(string pluginName)
{
InitializeComponent();
@@ -77,6 +77,21 @@ public partial class PluginWindow : Window
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)
{
base.OnSourceInitialized(e);
@@ -87,18 +102,26 @@ public partial class PluginWindow : Window
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(() =>
{
LoadPlugin();
});
pluginThread.Start();
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 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)
@@ -171,7 +194,7 @@ public partial class PluginWindow : Window
{
byte[] assemblyBytes = File.ReadAllBytes($"{PluginFolderPath}\\{PluginName}.dll");
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)
{
@@ -220,7 +243,7 @@ public partial class PluginWindow : Window
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
List<SettingElement> settingElements = new List<SettingElement>();
List<SettingElement> settingElements = [];
foreach (FieldInfo prop in props)
{
if (prop.GetValue(instance) is Element element)
@@ -237,15 +260,11 @@ public partial class PluginWindow : Window
}
}
settingElements = settingElements.OrderBy(x => x.OrderIndex).ToList();
if (MainWindow.PluginsSettings.ContainsKey(PluginName))
settingElements = [.. settingElements.OrderBy(x => x.OrderIndex)];
if (!MainWindow.PluginsSettings.TryAdd(PluginName, settingElements))
{
MainWindow.PluginsSettings[PluginName] = settingElements;
}
else
{
MainWindow.PluginsSettings.Add(PluginName, settingElements);
}
}
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)
{
pluginClassInstance?.Stop();
+4 -11
View File
@@ -2,16 +2,9 @@
namespace DesktopMagic.Plugins;
internal class SettingElement
internal class SettingElement(Element element, string name, int orderIndex)
{
public Element Element { get; }
public string Name { get; }
public int OrderIndex { get; }
public SettingElement(Element element, string name, int orderIndex)
{
Element = element;
Name = name;
OrderIndex = orderIndex;
}
public Element Element { get; } = element;
public string Name { get; } = name;
public int OrderIndex { get; } = orderIndex;
}
@@ -1,11 +1,12 @@
<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<TargetFramework>net6.0</TargetFramework>
<TargetFramework>net8.0-windows</TargetFramework>
<OutputType>Library</OutputType>
</PropertyGroup>
<ItemGroup>
<PackageReference Include="System.Drawing.Common" Version="5.0.2" />
<PackageReference Include="System.Drawing.Common" Version="8.0.0" />
</ItemGroup>
<ItemGroup>
+72 -73
View File
@@ -8,82 +8,81 @@ using System.Drawing.Imaging;
using System.IO;
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:")]
private readonly TextBox input = new TextBox("");
[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;
if (File.Exists(SaveFilePath))
{
input.OnValueChanged += Input_OnValueChanged;
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];
input.Value = File.ReadAllText(SaveFilePath);
}
}
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">
<PropertyGroup>
<TargetFramework>net6.0</TargetFramework>
<TargetFramework>net8.0-windows</TargetFramework>
<Company>Stone_Red</Company>
<Product>Stone_Red</Product>
<Version>0.0.0.5</Version>
@@ -22,11 +22,7 @@
</PropertyGroup>
<ItemGroup>
<PackageReference Include="docfx.console" Version="2.58.9">
<PrivateAssets>all</PrivateAssets>
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
</PackageReference>
<PackageReference Include="System.Drawing.Common" Version="5.0.2" />
<PackageReference Include="System.Drawing.Common" Version="8.0.0" />
</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.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;
if (font1.SizeInPoints != font2.SizeInPoints) return false;
if (font1.Style != font2.Style) return false;
return true;
return false;
}
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.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>
/// Extensions for the <see cref="Graphics"/> class.
/// <inheritdoc cref="Graphics.DrawString(string?, Font, Brush, float, float)"/>
/// </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>
/// <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)
for (int i = 0; i < s.Length; i++)
{
int widest = graphics.GetWidestChar(font);
graphics.DrawString(s[i].ToString(), font, brush, x, y);
for (int i = 0; i < s.Length; i++)
{
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);
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(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;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace DesktopMagicPluginAPI.Drawing;
namespace DesktopMagicPluginAPI.Drawing
/// <summary>
/// Specifies which render quality is used to display the bitmap images.
/// </summary>
public enum RenderQuality
{
/// <summary>
/// Specifies which render quality is used to display the bitmap images.
/// Slower then <see cref="Low"/> but produces higher quality output.
/// </summary>
public enum RenderQuality
{
/// <summary>
/// Slower then <see cref="Low"/> but produces higher quality output.
/// </summary>
High,
High,
/// <summary>
/// Faster then <see cref="High"/> but produces lower quality output.
/// </summary>
Low,
/// <summary>
/// Faster then <see cref="High"/> but produces lower quality output.
/// </summary>
Low,
/// <summary>
/// Provides performance benefits over <see cref="Low"/>
/// </summary>
Performance
}
/// <summary>
/// Provides performance benefits over <see cref="Low"/>
/// </summary>
Performance
}
+38 -39
View File
@@ -1,53 +1,52 @@
using System;
using System.Drawing;
namespace DesktopMagicPluginAPI
namespace DesktopMagicPluginAPI;
/// <summary>
/// Defines properties and methods that provide information about the main application.
/// </summary>
public interface IPluginData
{
/// <summary>
/// Defines properties and methods that provide information about the main application.
/// Gets the current font of the current theme.
/// </summary>
public interface IPluginData
{
/// <summary>
/// Gets the current font of the current theme.
/// </summary>
[Obsolete("Use the \"Theme\" property instead")]
string Font { get; }
[Obsolete("Use the \"Theme\" property instead")]
string Font { get; }
/// <summary>
/// Gets the current color of the current theme.
/// </summary>
[Obsolete("Use the \"Theme\" property instead")]
Color Color { get; }
/// <summary>
/// Gets the current color of the current theme.
/// </summary>
[Obsolete("Use the \"Theme\" property instead")]
Color Color { get; }
/// <summary>
/// Gets the current theme setting of the main application.
/// </summary>
ITheme Theme { get; }
/// <summary>
/// Gets the current theme setting of the main application.
/// </summary>
ITheme Theme { get; }
/// <summary>
/// Gets the window size of the plugin window.
/// </summary>
Size WindowSize { get; }
/// <summary>
/// Gets the window size of the plugin window.
/// </summary>
Size WindowSize { get; }
/// <summary>
/// Gets the window position of the plugin window.
/// </summary>
Point WindowPosition { get; }
/// <summary>
/// Gets the window position of the plugin window.
/// </summary>
Point WindowPosition { get; }
/// <summary>
/// Gets the name of the plugin.
/// </summary>
string PluginName { get; }
/// <summary>
/// Gets the name of the plugin.
/// </summary>
string PluginName { get; }
/// <summary>
/// Gets the path of the parent directory of the plugin.
/// </summary>
string PluginPath { get; }
/// <summary>
/// Gets the path of the parent directory of the plugin.
/// </summary>
string PluginPath { get; }
/// <summary>
/// Updates the plugin window.
/// </summary>
void UpdateWindow();
}
/// <summary>
/// Updates the plugin window.
/// </summary>
void UpdateWindow();
}
+28 -29
View File
@@ -1,40 +1,39 @@
using System.Drawing;
namespace DesktopMagicPluginAPI
namespace DesktopMagicPluginAPI;
/// <summary>
/// The theme settings of the main application.
/// </summary>
public interface ITheme
{
/// <summary>
/// The theme settings of the main application.
/// Gets the primary color of the current theme.
/// </summary>
public interface ITheme
{
/// <summary>
/// Gets the primary color of the current theme.
/// </summary>
Color PrimaryColor { get; }
Color PrimaryColor { get; }
/// <summary>
/// Gets the secondary color of the current theme.
/// </summary>
Color SecondaryColor { get; }
/// <summary>
/// Gets the secondary color of the current theme.
/// </summary>
Color SecondaryColor { get; }
/// <summary>
/// Gets the background color of the current theme.
/// </summary>
Color BackgroundColor { get; }
/// <summary>
/// Gets the background color of the current theme.
/// </summary>
Color BackgroundColor { get; }
/// <summary>
/// Gets the font of the current theme.
/// </summary>
string Font { get; }
/// <summary>
/// Gets the font of the current theme.
/// </summary>
string Font { get; }
/// <summary>
/// Gets the corner radius of the current theme.
/// </summary>
int CornerRadius { get; }
/// <summary>
/// Gets the corner radius of the current theme.
/// </summary>
int CornerRadius { get; }
/// <summary>
/// Gets the corner radius of the current theme.
/// </summary>
int Margin { get; }
}
/// <summary>
/// Gets the corner radius of the current theme.
/// </summary>
int Margin { get; }
}
+35 -36
View File
@@ -1,50 +1,49 @@
using System;
namespace DesktopMagicPluginAPI.Inputs
namespace DesktopMagicPluginAPI.Inputs;
/// <summary>
/// Represents a button control.
/// </summary>
public class Button : Element
{
/// <summary>
/// Represents a button control.
/// Occurs when the button gets clicked.
/// </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>
/// Occurs when the button gets clicked.
/// </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;
set
{
get => _value;
set
if (_value != value)
{
if (_value != value)
{
_value = value;
ValueChanged();
}
_value = value;
ValueChanged();
}
}
}
/// <summary>
/// Initializes a new instance of the <see cref="Button"/> class with the provided <paramref name="value"/>.
/// </summary>
/// <param name="value">The text caption displayed in the <see cref="Button"/> control.</param>
public Button(string value)
{
Value = value;
}
/// <summary>
/// Initializes a new instance of the <see cref="Button"/> class with the provided <paramref name="value"/>.
/// </summary>
/// <param name="value">The text caption displayed in the <see cref="Button"/> control.</param>
public Button(string value)
{
Value = value;
}
/// <summary>
/// Triggers the <see cref="OnClick"/> event.
/// </summary>
public void Click()
{
OnClick?.Invoke();
}
/// <summary>
/// Triggers the <see cref="OnClick"/> event.
/// </summary>
public void Click()
{
OnClick?.Invoke();
}
}
+26 -27
View File
@@ -1,35 +1,34 @@
namespace DesktopMagicPluginAPI.Inputs
{
/// <summary>
/// Represents a check box control.
/// </summary>
public class CheckBox : Element
{
private bool _value;
namespace DesktopMagicPluginAPI.Inputs;
/// <summary>
/// Gets or set a value indicating whether the <see cref="CheckBox"/> is in the checked state.
/// </summary>
public bool Value
/// <summary>
/// Represents a check box control.
/// </summary>
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;
set
if (_value != value)
{
if (_value != value)
{
_value = value;
ValueChanged();
}
_value = value;
ValueChanged();
}
}
}
/// <summary>
/// Initializes a new instance of the <see cref="CheckBox"/> class with the provided <paramref name="value"/>.
/// </summary>
/// <param name="value">A value indicating whether the <see cref="CheckBox"/> is in the checked state.</param>
public CheckBox(bool value)
{
Value = value;
}
/// <summary>
/// Initializes a new instance of the <see cref="CheckBox"/> class with the provided <paramref name="value"/>.
/// </summary>
/// <param name="value">A value indicating whether the <see cref="CheckBox"/> is in the checked state.</param>
public CheckBox(bool value)
{
Value = value;
}
}
+33 -34
View File
@@ -1,46 +1,45 @@
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>
/// Represents a selection control with a drop-down list.
/// Gets the collection used to generate the content of the <see cref="ComboBox"/>.
/// </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;
/// <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;
set
{
get => _value;
set
if (_value != value)
{
if (_value != value)
{
_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);
_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);
}
}
}
+14 -15
View File
@@ -1,23 +1,22 @@
using System;
namespace DesktopMagicPluginAPI.Inputs
namespace DesktopMagicPluginAPI.Inputs;
/// <summary>
/// The element base class.
/// </summary>
public abstract class Element
{
/// <summary>
/// The element base class.
/// Occurs when the value has been changed.
/// </summary>
public abstract class Element
{
/// <summary>
/// Occurs when the value has been changed.
/// </summary>
public event Action OnValueChanged;
public event Action OnValueChanged;
/// <summary>
/// Triggers the <see cref="OnValueChanged"/> event.
/// </summary>
protected void ValueChanged()
{
OnValueChanged?.Invoke();
}
/// <summary>
/// Triggers the <see cref="OnValueChanged"/> event.
/// </summary>
protected void ValueChanged()
{
OnValueChanged?.Invoke();
}
}
@@ -1,46 +1,45 @@
using System;
namespace DesktopMagicPluginAPI.Inputs
namespace DesktopMagicPluginAPI.Inputs;
/// <summary>
/// Marks a Property as element.
/// </summary>
[AttributeUsage(AttributeTargets.Field)]
public class ElementAttribute : Attribute
{
/// <summary>
/// Marks a Property as element.
/// The name of the element.
/// </summary>
[AttributeUsage(AttributeTargets.Field)]
public class ElementAttribute : Attribute
public string Name { get; }
/// <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>
/// The name of the element.
/// </summary>
public string Name { get; }
Name = name;
OrderIndex = orderIndex;
}
/// <summary>
/// The order index of the element.
/// </summary>
public int OrderIndex { get; }
/// <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;
}
/// <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)
{
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()
{
}
/// <inheritdoc cref="ElementAttribute"/>
public ElementAttribute()
{
}
}
@@ -1,73 +1,72 @@
using System;
namespace DesktopMagicPluginAPI.Inputs
namespace DesktopMagicPluginAPI.Inputs;
/// <summary>
/// Represents a up-down control.
/// </summary>
public class IntegerUpDown : Element
{
private int _value;
/// <summary>
/// Represents a up-down control.
/// Gets or sets the maximum value for the <see cref="IntegerUpDown"/> element.
/// </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;
/// <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;
set
{
get => _value;
set
if (_value != value)
{
if (_value != value)
{
_value = value;
ValueChanged();
}
_value = value;
ValueChanged();
}
}
}
/// <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"/>.
/// </summary>
/// <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="value">The value assigned to the <see cref="IntegerUpDown"/> element.</param>
/// <exception cref="ArgumentException"></exception>
public IntegerUpDown(int min, int max, int value = 0)
/// <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"/>.
/// </summary>
/// <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="value">The value assigned to the <see cref="IntegerUpDown"/> element.</param>
/// <exception cref="ArgumentException"></exception>
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));
}
if (max < 0)
{
throw new ArgumentException("Value can not be negative!", nameof(max));
}
if (min > max)
{
throw new ArgumentException($"{nameof(min)} is greater than or equal to {nameof(max)}!");
}
if (value > max)
{
throw new ArgumentException($"{nameof(value)} is greater than {nameof(max)}!");
}
if (value < min)
{
throw new ArgumentException($"{nameof(value)} is less than {nameof(min)}!");
}
throw new ArgumentException("Value can not be negative!", nameof(min));
}
if (max < 0)
{
throw new ArgumentException("Value can not be negative!", nameof(max));
}
if (min > max)
{
throw new ArgumentException($"{nameof(min)} is greater than or equal to {nameof(max)}!");
}
if (value > max)
{
throw new ArgumentException($"{nameof(value)} is greater than {nameof(max)}!");
}
if (value < min)
{
throw new ArgumentException($"{nameof(value)} is less than {nameof(min)}!");
}
Minimum = min;
Maximum = max;
Value = value;
}
Minimum = min;
Maximum = max;
Value = value;
}
}
+32 -33
View File
@@ -1,42 +1,41 @@
namespace DesktopMagicPluginAPI.Inputs
{
/// <summary>
/// Represents a label control.
/// </summary>
public class Label : Element
{
private string _value;
namespace DesktopMagicPluginAPI.Inputs;
/// <summary>
/// Gets or sets the text associated with this <see cref="Label"/>.
/// </summary>
public string Value
/// <summary>
/// Represents a label control.
/// </summary>
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;
set
if (_value != value)
{
if (_value != value)
{
_value = value;
ValueChanged();
}
_value = value;
ValueChanged();
}
}
}
/// <summary>
/// Gets or set a value indicating whether the content of the <see cref="Label"/> is bold or not.
/// </summary>
public bool Bold { get; set; }
/// <summary>
/// Gets or set a value indicating whether the content of the <see cref="Label"/> is bold or not.
/// </summary>
public bool Bold { get; set; }
/// <summary>
/// Initializes a new instance of the <see cref="Label"/> class with the provided <paramref name="value"/>.
/// </summary>
/// <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>
public Label(string value, bool bold = false)
{
Value = value;
Bold = bold;
}
/// <summary>
/// Initializes a new instance of the <see cref="Label"/> class with the provided <paramref name="value"/>.
/// </summary>
/// <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>
public Label(string value, bool bold = false)
{
Value = value;
Bold = bold;
}
}
+15 -22
View File
@@ -1,29 +1,22 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace DesktopMagicPluginAPI.Inputs;
namespace DesktopMagicPluginAPI.Inputs
/// <summary>
/// Mouse Buttons
/// </summary>
public enum MouseButton
{
/// <summary>
/// Mouse Buttons
/// The left mouse button.
/// </summary>
public enum MouseButton
{
/// <summary>
/// The left mouse button.
/// </summary>
Left,
Left,
/// <summary>
/// The middle mouse button.
/// </summary>
Middle,
/// <summary>
/// The middle mouse button.
/// </summary>
Middle,
/// <summary>
/// The right mouse button.
/// </summary>
Right,
}
/// <summary>
/// The right mouse button.
/// </summary>
Right,
}
+56 -57
View File
@@ -1,72 +1,71 @@
using System;
namespace DesktopMagicPluginAPI.Inputs
namespace DesktopMagicPluginAPI.Inputs;
/// <summary>
/// Represents a slider control.
/// </summary>
public sealed class Slider : Element
{
private double _value;
/// <summary>
/// Represents a slider control.
/// Gets or sets the maximum value for the <see cref="Slider"/> element.
/// </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;
/// <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;
set
{
get => _value;
set
if (_value != value)
{
if (_value != value)
{
_value = value;
ValueChanged();
}
_value = value;
ValueChanged();
}
}
}
/// <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"/>.
/// </summary>
/// <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="value">The value assigned to the <see cref="Slider"/> element.</param>
public Slider(double min, double max, double value = 0)
/// <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"/>.
/// </summary>
/// <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="value">The value assigned to the <see cref="Slider"/> element.</param>
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));
}
if (max < 0)
{
throw new ArgumentException("Value can not be negative!", nameof(max));
}
if (min > max)
{
throw new ArgumentException($"{nameof(min)} is greater than or equal to {nameof(max)}!");
}
if (value > max)
{
throw new ArgumentException($"{nameof(value)} is greater than {nameof(max)}!");
}
if (value < min)
{
throw new ArgumentException($"{nameof(value)} is less than {nameof(min)}!");
}
throw new ArgumentException("Value can not be negative!", nameof(min));
}
if (max < 0)
{
throw new ArgumentException("Value can not be negative!", nameof(max));
}
if (min > max)
{
throw new ArgumentException($"{nameof(min)} is greater than or equal to {nameof(max)}!");
}
if (value > max)
{
throw new ArgumentException($"{nameof(value)} is greater than {nameof(max)}!");
}
if (value < min)
{
throw new ArgumentException($"{nameof(value)} is less than {nameof(min)}!");
}
Minimum = min;
Maximum = max;
Value = value;
}
Minimum = min;
Maximum = max;
Value = value;
}
}
+26 -27
View File
@@ -1,35 +1,34 @@
namespace DesktopMagicPluginAPI.Inputs
{
/// <summary>
/// Represents a text box control.
/// </summary>
public class TextBox : Element
{
private string _value;
namespace DesktopMagicPluginAPI.Inputs;
/// <summary>
/// Gets or sets the text associated with this <see cref="TextBox"/>.
/// </summary>
public string Value
/// <summary>
/// Represents a text box control.
/// </summary>
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;
set
if (_value != value)
{
if (_value != value)
{
_value = value;
ValueChanged();
}
_value = value;
ValueChanged();
}
}
}
/// <summary>
/// Initializes a new instance of the <see cref="TextBox"/> class with the provided <paramref name="value"/>.
/// </summary>
/// <param name="value">The text associated with this control.</param>
public TextBox(string value)
{
Value = value;
}
/// <summary>
/// Initializes a new instance of the <see cref="TextBox"/> class with the provided <paramref name="value"/>.
/// </summary>
/// <param name="value">The text associated with this control.</param>
public TextBox(string value)
{
Value = value;
}
}
+60 -61
View File
@@ -4,78 +4,77 @@ using DesktopMagicPluginAPI.Inputs;
using System;
using System.Drawing;
namespace DesktopMagicPluginAPI
namespace DesktopMagicPluginAPI;
/// <summary>
/// The plugin class.
/// </summary>
public abstract class Plugin
{
private IPluginData application = null;
/// <summary>
/// The plugin class.
/// Informations about the main application.
/// </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>
/// Informations about the main application.
/// </summary>
public IPluginData Application
{
get => application;
set => application = application is null ? value : throw new InvalidOperationException($"You cannot set the value of the {nameof(Application)} property");
}
/// <summary>
/// Gets or sets the interval, expressed in milliseconds, at which to call the <see cref="Main"/> method.
/// </summary>
public virtual int UpdateInterval { get; set; } = 1000;
/// <summary>
/// Gets or sets the interval, expressed in milliseconds, at which to call the <see cref="Main"/> method.
/// </summary>
public virtual int UpdateInterval { get; set; } = 1000;
/// <summary>
/// Gets or sets the render quality of the bitmap image.
/// </summary>
public virtual RenderQuality RenderQuality { get; set; } = RenderQuality.High;
/// <summary>
/// Gets or sets the render quality of the bitmap image.
/// </summary>
public virtual RenderQuality RenderQuality { get; set; } = RenderQuality.High;
/// <summary>
/// Occurs once when the plugin gets activated.
/// </summary>
public virtual void Start()
{
}
/// <summary>
/// Occurs once when the plugin gets activated.
/// </summary>
public virtual void Start()
{
}
/// <summary>
/// Occurs once when the plugin gets deactivated.
/// </summary>
public virtual void Stop()
{
}
/// <summary>
/// Occurs once when the plugin gets deactivated.
/// </summary>
public virtual void Stop()
{
}
/// <summary>
/// Occurs when the <see cref="UpdateInterval"/> elapses.
/// </summary>
/// <returns></returns>
public abstract Bitmap Main();
/// <summary>
/// Occurs when the <see cref="UpdateInterval"/> elapses.
/// </summary>
/// <returns></returns>
public abstract Bitmap Main();
/// <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>
public virtual void OnMouseClick(Point position, MouseButton 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>
public virtual void OnMouseClick(Point position, MouseButton mouseButton)
{
}
/// <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>
public virtual void OnMouseMove(Point position)
{
}
/// <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>
public virtual void OnMouseMove(Point position)
{
}
/// <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)
{
}
/// <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