diff --git a/.gitignore b/.gitignore
index 990e547..a6d3a11 100644
--- a/.gitignore
+++ b/.gitignore
@@ -12,6 +12,7 @@ obj/
*.user
*.userosscache
*.sln.docstates
+*GPUCache/
# User-specific files (MonoDevelop/Xamarin Studio)
*.userprefs
diff --git a/src/DesktopMagic.Installer/DesktopMagic-Installer.exe b/src/DesktopMagic.Installer/DesktopMagic-Installer.exe
index 00227d6..02ef4f5 100644
Binary files a/src/DesktopMagic.Installer/DesktopMagic-Installer.exe and b/src/DesktopMagic.Installer/DesktopMagic-Installer.exe differ
diff --git a/src/DesktopMagic.Installer/Installer.iss b/src/DesktopMagic.Installer/Installer.iss
index 3315a4f..14855d5 100644
--- a/src/DesktopMagic.Installer/Installer.iss
+++ b/src/DesktopMagic.Installer/Installer.iss
@@ -2,7 +2,7 @@
; SEE THE DOCUMENTATION FOR DETAILS ON CREATING INNO SETUP SCRIPT FILES!
#define MyAppName "DesktopMagic"
-#define MyAppVersion "0.0.3.0"
+#define MyAppVersion "0.0.3.1"
#define MyAppPublisher "Stone_Red"
#define MyAppExeName "DesktopMagic.exe"
diff --git a/src/DesktopMagic/App.xaml.cs b/src/DesktopMagic/App.xaml.cs
index e86d738..3b2842a 100644
--- a/src/DesktopMagic/App.xaml.cs
+++ b/src/DesktopMagic/App.xaml.cs
@@ -3,6 +3,7 @@
using Stone_Red_Utilities.Logging;
using System;
+using System.IO;
using System.Threading;
using System.Windows;
@@ -18,7 +19,7 @@ namespace DesktopMagic
#if DEBUG
private readonly Updater updater = new Updater(TimeSpan.FromDays(1), "https://raw.githubusercontent.com/Stone-Red-Code/DesktopMagic/develop/update/updateInfo.json");
#else
- private readonly Updater updater = new Updater(TimeSpan.FromHours(1), "https://raw.githubusercontent.com/Stone-Red-Code/DesktopMagic/main/update/updateInfo.json");
+ private readonly Updater updater = new Updater(TimeSpan.FromDays(1), "https://raw.githubusercontent.com/Stone-Red-Code/DesktopMagic/main/update/updateInfo.json");
#endif
public const string AppName = "Desktop Magic";
@@ -33,11 +34,11 @@ namespace DesktopMagic
// Try to grab mutex
_mutex = new Mutex(true, $"Stone_Red{AppName}", out bool createdNew);
- //check if creating new was succesfull
+ //check if creating new was successful
if (!createdNew)
{
Logger.Log("Shutting down because other instance already running.", "Setup");
- //Shutdown Aplication
+ //Shutdown Application
Current.Shutdown();
}
else
@@ -59,7 +60,7 @@ namespace DesktopMagic
private void Updater_NoUpdateAvailible()
{
- Logger.Log("No update avalible.", "Updater");
+ Logger.Log("No update available.", "Updater");
}
private void Updater_OnException(Exception exception)
@@ -104,7 +105,7 @@ namespace DesktopMagic
InfoConfig = new OutputConfig()
{
Color = ConsoleColor.White,
- LogTarget = LogTarget.Console | LogTarget.File,
+ LogTarget = LogTarget.DebugConsole | LogTarget.File,
FilePath = logFilePath
},
DebugConfig = new OutputConfig()
@@ -114,9 +115,24 @@ namespace DesktopMagic
},
FormatConfig = new FormatConfig()
{
- DebugConsoleFormat = $"> {{{LogFormatType.DateTime}:hh:mm:ss}} | {{{LogFormatType.LogSeverity},-5}} | {{{LogFormatType.Message}}}\n> at {{{LogFormatType.LineNumber},3}} | {{{LogFormatType.FilePath}}}"
+ DebugConsoleFormat = $"> {{{LogFormatType.DateTime}:hh:mm:ss}} | {{{LogFormatType.LogSeverity},-5}} | {{{LogFormatType.Message}}}\nat {{{LogFormatType.LineNumber}}} | {{{LogFormatType.FilePath}}}"
}
};
+
+ try
+ {
+ if (!Directory.Exists(ApplicationDataPath))
+ {
+ _ = Directory.CreateDirectory(ApplicationDataPath);
+ }
+ Logger.Log("Created ApplicationData Folder", "Main");
+ }
+ catch (Exception ex)
+ {
+ Logger.Log(ex.Message, "Setup", LogSeverity.Error);
+ _ = MessageBox.Show(ex.ToString());
+ }
+
Logger.ClearLogFile(LogSeverity.Info);
Logger.Log("Log setup complete.", "Setup");
}
diff --git a/src/DesktopMagic/CpuUsageWindow.xaml b/src/DesktopMagic/BuiltInWindowElements/CpuUsageWindow.xaml
similarity index 58%
rename from src/DesktopMagic/CpuUsageWindow.xaml
rename to src/DesktopMagic/BuiltInWindowElements/CpuUsageWindow.xaml
index d326c01..a1b19b6 100644
--- a/src/DesktopMagic/CpuUsageWindow.xaml
+++ b/src/DesktopMagic/BuiltInWindowElements/CpuUsageWindow.xaml
@@ -14,8 +14,15 @@
x:Name="window">
-
-
+
+
+
+
+
+
+
+
+
diff --git a/src/DesktopMagic/CpuUsageWindow.xaml.cs b/src/DesktopMagic/BuiltInWindowElements/CpuUsageWindow.xaml.cs
similarity index 65%
rename from src/DesktopMagic/CpuUsageWindow.xaml.cs
rename to src/DesktopMagic/BuiltInWindowElements/CpuUsageWindow.xaml.cs
index d5afd15..db0dcce 100644
--- a/src/DesktopMagic/CpuUsageWindow.xaml.cs
+++ b/src/DesktopMagic/BuiltInWindowElements/CpuUsageWindow.xaml.cs
@@ -1,4 +1,6 @@
-using Microsoft.Win32;
+using DesktopMagic.Helpers;
+
+using Microsoft.Win32;
using System;
using System.Diagnostics;
@@ -6,12 +8,10 @@ using System.Timers;
using System.Windows;
using System.Windows.Interop;
using System.Windows.Media;
+using System.Windows.Threading;
namespace DesktopMagic
{
- ///
- /// Interaktionslogik für TimeWindow.xaml
- ///
public partial class CpuUsageWindow : Window
{
private RegistryKey key;
@@ -41,7 +41,7 @@ namespace DesktopMagic
Timer t = new Timer();
t.Interval = 100;
- t.Elapsed += T_Elapsed;
+ t.Elapsed += UpdateTimer_Elapsed;
t.Start();
Timer valueTimer = new Timer();
@@ -68,23 +68,37 @@ namespace DesktopMagic
WindowPos.GetWindowLong(helper.Handle, WindowPos.GWL_EXSTYLE) | WindowPos.WS_EX_NOACTIVATE);
}
- private void T_Elapsed(object sender, ElapsedEventArgs e)
+ private void UpdateTimer_Elapsed(object sender, ElapsedEventArgs e)
{
Dispatcher.Invoke(() =>
{
if (MainWindow.EditMode)
{
panel.Visibility = Visibility.Visible;
+ tileBar.CaptionHeight = tileBar.CaptionHeight = ActualHeight - 10 < 0 ? 0 : ActualHeight - 10;
WindowPos.SetIsLocked(this, false);
+ ResizeMode = ResizeMode.CanResize;
}
else
{
panel.Visibility = Visibility.Collapsed;
+ tileBar.CaptionHeight = 0;
WindowPos.SetIsLocked(this, true);
+ ResizeMode = ResizeMode.NoResize;
}
- textBlock.FontFamily = new FontFamily(MainWindow.GlobalFont);
- textBlock.Foreground = MainWindow.GlobalColor;
+ rectangleGeometry.Rect = new Rect(0, 0, border.ActualWidth, border.ActualHeight);
+ border.Background = MainWindow.Theme.BackgroundBrush;
+ border.CornerRadius = new CornerRadius(MainWindow.Theme.CornerRadius);
+ viewBox.Margin = new Thickness(MainWindow.Theme.Margin);
+ border.Width = viewBox.ActualWidth + MainWindow.Theme.Margin * 2;
+ border.Height = viewBox.ActualHeight + MainWindow.Theme.Margin * 2;
+ textBlock.FontFamily = new FontFamily(MainWindow.Theme.Font);
+ textBlock.Foreground = MainWindow.Theme.PrimaryBrush;
+ valueTextBlock.FontFamily = new FontFamily(MainWindow.Theme.Font);
+ valueTextBlock.Foreground = MainWindow.Theme.PrimaryBrush;
+
+ ClculateWidth();
});
}
@@ -93,13 +107,24 @@ namespace DesktopMagic
string cpuUsage = GetCpuUsage();
Dispatcher.Invoke(() =>
{
- textBlock.Text = cpuUsage;
+ valueTextBlock.Text = cpuUsage;
});
}
+ private void ClculateWidth()
+ {
+ string template = "CPU: ###%";
+ double lenght = 0;
+ for (int i = 0; i < 9; i++)
+ {
+ lenght = Math.Max(StringUtilities.MeasureString(template.Replace('#', i.ToString()[0]), textBlock).Width, lenght);
+ }
+ dockPanel.Width = lenght;
+ }
+
private string GetCpuUsage()
{
- return "CPU: " + ((int)cpuCounter.NextValue()).ToString().PadLeft(3, '0') + "%";
+ return $"{(int)cpuCounter.NextValue()}%";
}
private void Window_LocationChanged(object sender, EventArgs e)
diff --git a/src/DesktopMagic/BuiltInWindowElements/DatePlugin.cs b/src/DesktopMagic/BuiltInWindowElements/DatePlugin.cs
new file mode 100644
index 0000000..06d6a57
--- /dev/null
+++ b/src/DesktopMagic/BuiltInWindowElements/DatePlugin.cs
@@ -0,0 +1,50 @@
+using DesktopMagicPluginAPI;
+
+using System;
+using System.Drawing;
+using System.Drawing.Text;
+
+namespace DesktopMagic.BuiltInWindowElements
+{
+ internal class DatePlugin : Plugin
+ {
+ public override int UpdateInterval => 1000;
+
+ private DateTime oldDateTime = new DateTime();
+ private Color oldColor = Color.White;
+ private string oldFont;
+
+ public override Bitmap Main()
+ {
+ if (oldDateTime.Date == DateTime.Now.Date && oldColor == Application.Theme.PrimaryColor && oldFont == Application.Theme.Font)
+ {
+ return null;
+ }
+
+ oldDateTime = DateTime.Now;
+ oldColor = Application.Theme.PrimaryColor;
+ oldFont = Application.Theme.Font;
+
+ string date = DateTime.Now.ToLongDateString();
+
+ Font font = new Font(Application.Theme.Font, 200);
+
+ Bitmap bmp = new Bitmap(1, 1);
+ bmp.SetResolution(100, 100);
+ using Graphics tmpGr = Graphics.FromImage(bmp);
+ tmpGr.TextRenderingHint = TextRenderingHint.AntiAlias;
+
+ SizeF size = tmpGr.MeasureString(date, font);
+
+ bmp = new Bitmap((int)size.Width, (int)size.Height);
+ bmp.SetResolution(100, 100);
+
+ using Graphics gr = Graphics.FromImage(bmp);
+
+ gr.TextRenderingHint = TextRenderingHint.AntiAlias;
+ gr.DrawString(date, font, new SolidBrush(Application.Theme.PrimaryColor), 0, 0);
+
+ return bmp;
+ }
+ }
+}
\ No newline at end of file
diff --git a/src/DesktopMagic/MusicVisualizerWindow.xaml.cs b/src/DesktopMagic/BuiltInWindowElements/MusicVisualizerPlugin.cs
similarity index 57%
rename from src/DesktopMagic/MusicVisualizerWindow.xaml.cs
rename to src/DesktopMagic/BuiltInWindowElements/MusicVisualizerPlugin.cs
index 8bb8ab9..79c8ad4 100644
--- a/src/DesktopMagic/MusicVisualizerWindow.xaml.cs
+++ b/src/DesktopMagic/BuiltInWindowElements/MusicVisualizerPlugin.cs
@@ -1,111 +1,33 @@
-using Microsoft.Win32;
+using DesktopMagicPluginAPI;
using NAudio.Wave;
using System;
using System.Collections.Generic;
-using System.Diagnostics;
using System.Drawing;
-using System.Drawing.Drawing2D;
-using System.Drawing.Imaging;
using System.Linq;
-using System.Runtime.InteropServices;
-using System.Timers;
-using System.Windows;
-using System.Windows.Interop;
-using System.Windows.Media.Imaging;
-using System.Windows.Threading;
-namespace DesktopMagic
+namespace DesktopMagic.BuiltInWindowElements
{
- public partial class MusicVisualizerWindow : Window
+ internal class MusicVisualizerPlugin : Plugin
{
- [DllImport("user32.dll")]
- private static extern void SetParent(IntPtr hWndChild, IntPtr hWndNewParent);
-
- private readonly RegistryKey key;
- private readonly IWaveIn waveIn;
+ private IWaveIn waveIn;
private const int fftLength = 1024; // NAudio fft wants powers of two!
private readonly SampleAggregator sampleAggregator = new SampleAggregator(fftLength);
private volatile bool calculate = true;
+ private Bitmap output = new Bitmap(880, 300);
- public MusicVisualizerWindow()
+ public override int UpdateInterval => 0;
+
+ public override void Start()
{
- InitializeComponent();
-
- Window w = new()
- {
- Top = -100,
- Left = -100,
- Width = 0,
- Height = 0,
- WindowStyle = WindowStyle.ToolWindow,
- ShowInTaskbar = false
- };
-
- w.Show();
- Owner = w;
- w.Hide();
-
- sampleAggregator.FftCalculated += new EventHandler(FftCalculated);
+ sampleAggregator.FftCalculated += FftCalculated;
sampleAggregator.PerformFFT = true;
waveIn = new WasapiLoopbackCapture();
waveIn.DataAvailable += OnDataAvailable;
waveIn.StartRecording();
-
- Timer t = new Timer();
- t.Interval = 100;
- t.Elapsed += T_Elapsed;
- t.Start();
-
- key = Registry.CurrentUser.CreateSubKey(@"Software\" + App.AppName);
-
- Top = double.Parse(key.GetValue("MusicVisualizerWindowTop", 100).ToString());
-
- Left = double.Parse(key.GetValue("MusicVisualizerWindowLeft", 100).ToString());
-
- Height = double.Parse(key.GetValue("MusicVisualizerWindowHeight", 200).ToString());
-
- Width = double.Parse(key.GetValue("MusicVisualizerWindowWidth", 500).ToString());
-
- IsEnabled = false;
- }
-
- protected override void OnSourceInitialized(EventArgs e)
- {
- base.OnSourceInitialized(e);
-
- //Set the window style to noactivate.
- WindowInteropHelper helper = new WindowInteropHelper(this);
- WindowPos.SetWindowLong(helper.Handle, WindowPos.GWL_EXSTYLE,
- WindowPos.GetWindowLong(helper.Handle, WindowPos.GWL_EXSTYLE) | WindowPos.WS_EX_NOACTIVATE);
- }
-
- private void T_Elapsed(object sender, ElapsedEventArgs e)
- {
- Dispatcher.Invoke(() =>
- {
- if (MainWindow.EditMode)
- {
- panel.Visibility = Visibility.Visible;
- WindowPos.SetIsLocked(this, false);
- }
- else
- {
- panel.Visibility = Visibility.Collapsed;
- WindowPos.SetIsLocked(this, true);
- }
- if (!IsLoaded)
- {
- calculate = false;
- }
- else
- {
- calculate = true;
- }
- });
}
private void OnDataAvailable(object sender, WaveInEventArgs e)
@@ -134,7 +56,7 @@ namespace DesktopMagic
}
List fft = new List();
- for (int i = 0; i < e.Result.Length / 2 - 70; i++)
+ for (int i = 0; i < (e.Result.Length / 2) - 70; i++)
{
int v = i;
if (v < 20)
@@ -142,7 +64,7 @@ namespace DesktopMagic
v = 20;
}
- int multiplier = 100 - MainWindow.AmplifierLevel * 2;
+ int multiplier = 100 - (MainWindow.AmplifierLevel * 2);
multiplier = multiplier == 0 ? 1 : multiplier;
fft.Add(Math.Abs(e.Result[i].Y * v / multiplier));
}
@@ -173,7 +95,7 @@ namespace DesktopMagic
{
double temp = 0;
int j;
- for (j = i * count; j < count + i * count; j++)
+ for (j = i * count; j < count + (i * count); j++)
{
temp += fft[j];
}
@@ -227,9 +149,6 @@ namespace DesktopMagic
lastFft = fft;
try
{
- Stopwatch sw = new Stopwatch();
- sw.Start();
- Bitmap bm = new Bitmap(885, 300);
int offset = 0;
if (!MainWindow.MirrorMode && MainWindow.SpectrumMode != 1)
@@ -242,9 +161,9 @@ namespace DesktopMagic
offset = 1;
}
- using (Graphics gr = Graphics.FromImage(bm))
+ using (Graphics gr = Graphics.FromImage(output))
{
- gr.SmoothingMode = SmoothingMode.None;
+ gr.Clear(Color.Transparent);
PointF[] points = new PointF[scaledFft.Count + 2];
int fftIndex = 0;
@@ -264,8 +183,8 @@ namespace DesktopMagic
if (!fftIndexReverse)
{
- points[pointIndex + 1] = new PointF(bm.Width - 4 * pointIndex, bm.Height / 2 + value);
- points[points.Length / 2 + pointIndex + 1] = new PointF(bm.Width - 4 * pointIndex, bm.Height / 2 - value);
+ points[pointIndex + 1] = new PointF(output.Width - (4 * pointIndex), (output.Height / 2) + value);
+ points[(points.Length / 2) + pointIndex + 1] = new PointF(output.Width - (4 * pointIndex), (output.Height / 2) - value);
}
break;
@@ -274,7 +193,7 @@ namespace DesktopMagic
break;
default:
- points[pointIndex + 1] = new PointF(2 * pointIndex, bm.Height - value - 1 + offset);
+ points[pointIndex + 1] = new PointF(2 * pointIndex, output.Height - value - 1 + offset);
break;
}
@@ -296,17 +215,11 @@ namespace DesktopMagic
}
}
- SetPoints(points, bm.Width, bm.Height, offset);
+ SetPoints(points, output.Width, output.Height, offset);
- Brush brush;
- if (MainWindow.MusicVisualzerColor == null)
- {
- brush = MainWindow.GlobalSystemColor;
- }
- else
- {
- brush = MainWindow.MusicVisualzerColor;
- }
+ Brush brush = MainWindow.MusicVisualzerColor.HasValue
+ ? new SolidBrush(MainWindow.MusicVisualzerColor.Value)
+ : new SolidBrush(MainWindow.Theme.PrimaryColor);
if (MainWindow.LineMode)
{
@@ -326,10 +239,7 @@ namespace DesktopMagic
}
}
- Dispatcher.BeginInvoke((Action)delegate
- {
- image.Source = BitmapToImageSource(bm);
- });
+ Application.UpdateWindow();
}
catch { }
}
@@ -340,51 +250,33 @@ namespace DesktopMagic
{
case 1:
points[0] = new PointF(width, height / 2);
- points[points.Length - 1] = new PointF(0, 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);
+ points[(points.Length / 2) - 1] = new PointF(0, height / 2);
break;
case 2:
points[0] = new PointF(0, 0 - offset);
- points[points.Length - 1] = new PointF(points[points.Length - 2].X, 0 - offset);
+ points[^1] = new PointF(points[^2].X, 0 - offset);
break;
default:
points[0] = new PointF(0, height);
- points[points.Length - 1] = new PointF(points[points.Length - 2].X, height);
+ points[^1] = new PointF(points[^2].X, height);
break;
}
}
- private BitmapSource BitmapToImageSource(Bitmap bitmap)
+ public override Bitmap Main()
{
- BitmapData bitmapData = bitmap.LockBits(
- new Rectangle(0, 0, bitmap.Width, bitmap.Height),
- ImageLockMode.ReadOnly, bitmap.PixelFormat);
-
- BitmapSource bitmapSource = BitmapSource.Create(
- bitmapData.Width, bitmapData.Height,
- bitmap.HorizontalResolution, bitmap.VerticalResolution,
- System.Windows.Media.PixelFormats.Bgra32, null,
- bitmapData.Scan0, bitmapData.Stride * bitmapData.Height, bitmapData.Stride);
-
- bitmap.UnlockBits(bitmapData);
- return bitmapSource;
+ return output;
}
- private void Window_LocationChanged(object sender, EventArgs e)
+ public override void Stop()
{
- key.SetValue("MusicVisualizerWindowTop", this.Top);
- key.SetValue("MusicVisualizerWindowLeft", this.Left);
- }
-
- private void Window_SizeChanged(object sender, SizeChangedEventArgs e)
- {
- key.SetValue("MusicVisualizerWindowHeight", Height);
- key.SetValue("MusicVisualizerWindowWidth", Width);
- tileBar.CaptionHeight = ActualHeight - 10;
+ calculate = false;
+ waveIn?.StopRecording();
}
}
}
\ No newline at end of file
diff --git a/src/DesktopMagic/BuiltInWindowElements/TimePlugin.cs b/src/DesktopMagic/BuiltInWindowElements/TimePlugin.cs
new file mode 100644
index 0000000..1cf8fa8
--- /dev/null
+++ b/src/DesktopMagic/BuiltInWindowElements/TimePlugin.cs
@@ -0,0 +1,55 @@
+using DesktopMagicPluginAPI;
+using DesktopMagicPluginAPI.Drawing;
+using DesktopMagicPluginAPI.Inputs;
+
+using System;
+using System.Drawing;
+using System.Drawing.Text;
+
+namespace DesktopMagic.BuiltInWindowElements
+{
+ internal class TimePlugin : Plugin
+ {
+ [Element("Display Seconds:")]
+ private CheckBox checkBox = new CheckBox(true);
+
+ public override int UpdateInterval => 1000;
+
+ public override Bitmap Main()
+ {
+ string time = checkBox.Value ? DateTime.Now.ToLongTimeString() : DateTime.Now.ToShortTimeString();
+
+ Font font = new Font(Application.Theme.Font, 200);
+
+ Bitmap bmp = new Bitmap(1, 1);
+ using Graphics tmpGr = Graphics.FromImage(bmp);
+ tmpGr.TextRenderingHint = TextRenderingHint.AntiAlias;
+
+ SizeF size = CalculateSize(tmpGr, font);
+
+ bmp = new Bitmap((int)size.Width, (int)size.Height);
+ bmp.SetResolution(100, 100);
+
+ using Graphics gr = Graphics.FromImage(bmp);
+
+ gr.TextRenderingHint = TextRenderingHint.AntiAlias;
+ gr.DrawStringNoLeftPadding(time, font, new SolidBrush(Application.Theme.PrimaryColor), 0, 0);
+
+ return bmp;
+ }
+
+ private SizeF CalculateSize(Graphics graphics, Font font)
+ {
+ string template = 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;
+ }
+ }
+}
\ No newline at end of file
diff --git a/src/DesktopMagic/CalendarManagment.cs b/src/DesktopMagic/CalendarManagment.cs
deleted file mode 100644
index 6a59223..0000000
--- a/src/DesktopMagic/CalendarManagment.cs
+++ /dev/null
@@ -1,91 +0,0 @@
-using Google.Apis.Auth.OAuth2;
-using Google.Apis.Calendar.v3;
-using Google.Apis.Calendar.v3.Data;
-using Google.Apis.Services;
-using Google.Apis.Util.Store;
-
-using System;
-using System.Collections.Generic;
-using System.Diagnostics;
-using System.IO;
-using System.Threading;
-
-namespace DesktopMagic
-{
- internal class CalendarManagment
- {
- private static string[] Scopes = { CalendarService.Scope.CalendarReadonly };
-
- private static string ApplicationName = "Google Calendar API .NET " + App.AppName;
-
- [Obsolete]
- public (List, List) GetEvents()
- {
- List upcomingEventNames = new List();
- List upcomingEventTimes = new List();
- UserCredential credential;
-
- if (!File.Exists("credentials.json"))
- {
- return (new(), new());
- }
-
- using (FileStream stream = new FileStream("credentials.json", FileMode.Open, FileAccess.Read))
- {
- // The file token.json stores the user's access and refresh tokens, and is created
- // automatically when the authorization flow completes for the first time.
- string credPath = "token.json";
- credential = GoogleWebAuthorizationBroker.AuthorizeAsync(
- GoogleClientSecrets.Load(stream).Secrets,
- Scopes,
- "user",
- CancellationToken.None,
- new FileDataStore(credPath, true)).Result;
- Debug.WriteLine("Credential file saved to: " + credPath);
- }
-
- // Create Google Calendar API service.
- CalendarService service = new CalendarService(new BaseClientService.Initializer()
- {
- HttpClientInitializer = credential,
- ApplicationName = ApplicationName,
- });
-
- // Define parameters of request.
- EventsResource.ListRequest request = service.Events.List("primary");
- request.TimeMin = DateTime.Now;
- request.ShowDeleted = false;
- request.SingleEvents = true;
- request.MaxResults = 10;
- request.OrderBy = EventsResource.ListRequest.OrderByEnum.StartTime;
-
- // List events.
- Events events = request.Execute();
- if (events.Items != null && events.Items.Count > 0)
- {
- foreach (Event eventItem in events.Items)
- {
- if (upcomingEventNames.Count < 10)
- {
- string when = eventItem.Start.DateTime.ToString();
- if (string.IsNullOrEmpty(when))
- {
- when = eventItem.Start.Date;
- }
- upcomingEventNames.Add(eventItem.Summary);
- upcomingEventTimes.Add(when);
- }
- }
- }
- return (upcomingEventNames, upcomingEventTimes);
- }
- }
-
- internal class CalendarItems
- {
- public string eventname { get; set; }
- public string dateTime { get; set; }
- public string font { get; set; }
- public string color { get; set; }
- }
-}
\ No newline at end of file
diff --git a/src/DesktopMagic/CalendarWindow.xaml b/src/DesktopMagic/CalendarWindow.xaml
deleted file mode 100644
index 27c433c..0000000
--- a/src/DesktopMagic/CalendarWindow.xaml
+++ /dev/null
@@ -1,38 +0,0 @@
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
\ No newline at end of file
diff --git a/src/DesktopMagic/CalendarWindow.xaml.cs b/src/DesktopMagic/CalendarWindow.xaml.cs
deleted file mode 100644
index 21fc554..0000000
--- a/src/DesktopMagic/CalendarWindow.xaml.cs
+++ /dev/null
@@ -1,159 +0,0 @@
-using Microsoft.Win32;
-
-using System;
-using System.Collections.Generic;
-using System.Threading.Tasks;
-using System.Timers;
-using System.Windows;
-using System.Windows.Interop;
-using System.Windows.Media;
-
-namespace DesktopMagic
-{
- ///
- /// Interaktionslogik für TimeWindow.xaml
- ///
- public partial class CalendarWindow : Window
- {
- private RegistryKey key;
- private string oldFont = "";
- private Brush oldColor;
- private List upcomingEventNames = new List();
- private List upcomingEventTimes = new List();
-
- public CalendarWindow()
- {
- InitializeComponent();
-
- Window w = new Window();
- w.Top = -100;
- w.Left = -100;
- w.Width = 0;
- w.Height = 0;
-
- w.WindowStyle = WindowStyle.ToolWindow;
- w.ShowInTaskbar = false;
- w.Show();
- Owner = w;
- w.Hide();
-
- Timer t = new Timer();
- t.Interval = 100;
- t.Elapsed += T_Elapsed;
- t.Start();
-
- Timer valueTimer = new Timer();
- valueTimer.Interval = 600000;
- valueTimer.Elapsed += ValueTimer_Elapsed;
- ;
- valueTimer.Start();
-
- key = Registry.CurrentUser.CreateSubKey(@"Software\" + App.AppName);
- Top = double.Parse(key.GetValue("CalendarWindowTop", 100).ToString());
- Left = double.Parse(key.GetValue("CalendarWindowLeft", 100).ToString());
- Height = double.Parse(key.GetValue("CalendarWindowHeight", 200).ToString());
- Width = double.Parse(key.GetValue("CalendarWindowWidth", 500).ToString());
- //this.IsEnabled = false;
-
- Task.Run(() =>
- {
- (upcomingEventNames, upcomingEventTimes) = new CalendarManagment().GetEvents();
- Dispatcher.Invoke(() =>
- {
- LoadEvents();
- });
- });
- }
-
- protected override void OnSourceInitialized(EventArgs e)
- {
- base.OnSourceInitialized(e);
-
- //Set the window style to noactivate.
- WindowInteropHelper helper = new WindowInteropHelper(this);
- WindowPos.SetWindowLong(helper.Handle, WindowPos.GWL_EXSTYLE,
- WindowPos.GetWindowLong(helper.Handle, WindowPos.GWL_EXSTYLE) | WindowPos.WS_EX_NOACTIVATE);
- }
-
- private void ValueTimer_Elapsed(object sender, ElapsedEventArgs e)
- {
- Task.Run(() =>
- {
- (upcomingEventNames, upcomingEventTimes) = new CalendarManagment().GetEvents();
- Dispatcher.Invoke(() =>
- {
- LoadEvents();
- });
- });
- }
-
- private void T_Elapsed(object sender, ElapsedEventArgs e)
- {
- Dispatcher.Invoke(() =>
- {
- if (MainWindow.EditMode)
- {
- panel.Visibility = Visibility.Visible;
- WindowPos.SetIsLocked(this, false);
- }
- else
- {
- panel.Visibility = Visibility.Collapsed;
- WindowPos.SetIsLocked(this, true);
- }
- if (MainWindow.GlobalFont != oldFont || MainWindow.GlobalColor != oldColor)
- {
- oldColor = MainWindow.GlobalColor;
- oldFont = MainWindow.GlobalFont;
- LoadEvents();
- }
- listBox.SelectedIndex = -1;
- });
- }
-
- private void LoadEvents()
- {
- listBox.Items.Clear();
- CalendarItems calendarItem = new CalendarItems();
- calendarItem.eventname = "Termine: ";
- calendarItem.font = MainWindow.GlobalFont;
- calendarItem.color = MainWindow.GlobalColor.ToString();
- listBox.Items.Add(calendarItem);
-
- for (int i = 0; i < upcomingEventNames.Count; i++)
- {
- DateTime dateTime = DateTime.Now;
- DateTime.TryParse(upcomingEventTimes[i], out dateTime);
-
- calendarItem = new CalendarItems();
- calendarItem.eventname = upcomingEventNames[i];
- calendarItem.dateTime = dateTime.ToString("dd-MM-yyyy");
- calendarItem.font = MainWindow.GlobalFont;
- calendarItem.color = MainWindow.GlobalColor.ToString();
-
- if (dateTime < DateTime.Today.AddMonths(12) || upcomingEventTimes[i] == "-")
- {
- listBox.Items.Add(calendarItem);
- }
- }
-
- while (listBox.Items.Count < 10)
- {
- listBox.Items.Add("");
- }
- }
-
- private void Window_LocationChanged(object sender, EventArgs e)
- {
- key.SetValue("CalendarWindowTop", Top);
- key.SetValue("CalendarWindowLeft", Left);
- }
-
- private void Window_SizeChanged(object sender, SizeChangedEventArgs e)
- {
- key.SetValue("CalendarWindowHeight", Height);
- key.SetValue("CalendarWindowWidth", Width);
- tileBar.CaptionHeight = ActualHeight - 10;
- }
- }
-}
\ No newline at end of file
diff --git a/src/DesktopMagic/DateWindow.xaml b/src/DesktopMagic/DateWindow.xaml
deleted file mode 100644
index 74d72b4..0000000
--- a/src/DesktopMagic/DateWindow.xaml
+++ /dev/null
@@ -1,23 +0,0 @@
-
-
-
-
-
-
-
-
-
-
-
\ No newline at end of file
diff --git a/src/DesktopMagic/DateWindow.xaml.cs b/src/DesktopMagic/DateWindow.xaml.cs
deleted file mode 100644
index ad58d75..0000000
--- a/src/DesktopMagic/DateWindow.xaml.cs
+++ /dev/null
@@ -1,90 +0,0 @@
-using Microsoft.Win32;
-
-using System;
-using System.Timers;
-using System.Windows;
-using System.Windows.Interop;
-using System.Windows.Media;
-
-namespace DesktopMagic
-{
- ///
- /// Interaktionslogik für TimeWindow.xaml
- ///
- public partial class DateWindow : Window
- {
- private RegistryKey key;
-
- public DateWindow()
- {
- InitializeComponent();
-
- Window w = new Window();
- w.Top = -100;
- w.Left = -100;
- w.Width = 0;
- w.Height = 0;
-
- w.WindowStyle = WindowStyle.ToolWindow;
- w.ShowInTaskbar = false;
- w.Show();
- Owner = w;
- w.Hide();
-
- Timer t = new Timer();
- t.Interval = 100;
- t.Elapsed += T_Elapsed;
- t.Start();
-
- key = Registry.CurrentUser.CreateSubKey(@"Software\" + App.AppName);
- Top = double.Parse(key.GetValue("DateWindowTop", 100).ToString());
- Left = double.Parse(key.GetValue("DateWindowLeft", 100).ToString());
- Height = double.Parse(key.GetValue("DateWindowHeight", 200).ToString());
- Width = double.Parse(key.GetValue("DateWindowWidth", 500).ToString());
- IsEnabled = false;
- }
-
- protected override void OnSourceInitialized(EventArgs e)
- {
- base.OnSourceInitialized(e);
-
- //Set the window style to noactivate.
- WindowInteropHelper helper = new WindowInteropHelper(this);
- WindowPos.SetWindowLong(helper.Handle, WindowPos.GWL_EXSTYLE,
- WindowPos.GetWindowLong(helper.Handle, WindowPos.GWL_EXSTYLE) | WindowPos.WS_EX_NOACTIVATE);
- }
-
- private void T_Elapsed(object sender, ElapsedEventArgs e)
- {
- Dispatcher.Invoke(() =>
- {
- if (MainWindow.EditMode)
- {
- panel.Visibility = Visibility.Visible;
- WindowPos.SetIsLocked(this, false);
- }
- else
- {
- panel.Visibility = Visibility.Collapsed;
- WindowPos.SetIsLocked(this, true);
- }
- textBlock.FontFamily = new FontFamily(MainWindow.GlobalFont);
- textBlock.Foreground = MainWindow.GlobalColor;
- textBlock.Text = DateTime.Now.ToString("D");
- });
- }
-
- private void Window_LocationChanged(object sender, EventArgs e)
- {
- key.SetValue("DateWindowTop", Top);
- key.SetValue("DateWindowLeft", Left);
- }
-
- private void Window_SizeChanged(object sender, SizeChangedEventArgs e)
- {
- key.SetValue("DateWindowHeight", Height);
- key.SetValue("DateWindowWidth", Width);
- tileBar.CaptionHeight = ActualHeight - 10;
- }
- }
-}
\ No newline at end of file
diff --git a/src/DesktopMagic/DesktopMagic.csproj b/src/DesktopMagic/DesktopMagic.csproj
index 2e01db7..8f180ab 100644
--- a/src/DesktopMagic/DesktopMagic.csproj
+++ b/src/DesktopMagic/DesktopMagic.csproj
@@ -8,11 +8,11 @@
icon.ico
OnBuildSuccess
Stone_Red
- 0.0.3.0
+ 0.0.3.1
https://github.com/Stone-Red-Code/DesktopMagic
https://github.com/Stone-Red-Code/DesktopMagic
- 0.0.3.0
- 0.0.3.0
+ 0.0.3.1
+ 0.0.3.1
diff --git a/src/DesktopMagic/Dialogs/ColorDialog.xaml b/src/DesktopMagic/Dialogs/ColorDialog.xaml
new file mode 100644
index 0000000..abd2ee2
--- /dev/null
+++ b/src/DesktopMagic/Dialogs/ColorDialog.xaml
@@ -0,0 +1,49 @@
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
diff --git a/src/DesktopMagic/Dialogs/ColorDialog.xaml.cs b/src/DesktopMagic/Dialogs/ColorDialog.xaml.cs
new file mode 100644
index 0000000..1f6f896
--- /dev/null
+++ b/src/DesktopMagic/Dialogs/ColorDialog.xaml.cs
@@ -0,0 +1,130 @@
+using DesktopMagic.Helpers;
+
+using System;
+using System.Threading;
+using System.Windows;
+using System.Windows.Controls;
+using System.Windows.Media;
+
+namespace DesktopMagic.Dialogs
+{
+ ///
+ /// Interaction logic for ColorDialog.xaml
+ ///
+ public partial class ColorDialog : Window
+ {
+ 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;
+ }
+
+ 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 e)
+ {
+ colorHexTextBox.Select(colorHexTextBox.Text.Length, 0);
+ SetColorText();
+ }
+
+ private void ColorHexTextBox_TextChanged(object sender, TextChangedEventArgs e)
+ {
+ if (colorHexTextBox.Text.Length > 0)
+ {
+ if (colorHexTextBox.Text.ToCharArray()[0] != '#')
+ {
+ colorHexTextBox.Text = "#" + colorHexTextBox.Text.Replace("#", "");
+ }
+ }
+ else
+ {
+ 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;
+
+ return;
+ }
+ else
+ {
+ 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 = 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);
+ }
+ }
+}
\ No newline at end of file
diff --git a/src/DesktopMagic/InputDialog.xaml b/src/DesktopMagic/Dialogs/InputDialog.xaml
similarity index 80%
rename from src/DesktopMagic/InputDialog.xaml
rename to src/DesktopMagic/Dialogs/InputDialog.xaml
index 790377a..f42c6f7 100644
--- a/src/DesktopMagic/InputDialog.xaml
+++ b/src/DesktopMagic/Dialogs/InputDialog.xaml
@@ -1,16 +1,17 @@
-
+ Title="InputDialog"
+ ResizeMode="NoResize"
+ SizeToContent="WidthAndHeight">
-
+
-
+
diff --git a/src/DesktopMagic/InputDialog.xaml.cs b/src/DesktopMagic/Dialogs/InputDialog.xaml.cs
similarity index 80%
rename from src/DesktopMagic/InputDialog.xaml.cs
rename to src/DesktopMagic/Dialogs/InputDialog.xaml.cs
index 8559ef7..9d559f2 100644
--- a/src/DesktopMagic/InputDialog.xaml.cs
+++ b/src/DesktopMagic/Dialogs/InputDialog.xaml.cs
@@ -2,25 +2,22 @@
using System.Threading;
using System.Windows;
-namespace DesktopMagic
+namespace DesktopMagic.Dialogs
{
- ///
- /// Interaktionslogik für InputDialog.xaml
- ///
public partial class InputDialog : Window
{
public InputDialog(string content, string title = "InputDialog")
{
InitializeComponent();
label.Content = content;
- this.Title = title;
+ Title = title;
SetLanguageDictionary();
}
public string ResponseText
{
- get { return textBox.Text; }
- set { textBox.Text = value; }
+ get => textBox.Text;
+ set => textBox.Text = value;
}
private void OkButton_Click(object sender, RoutedEventArgs e)
@@ -46,7 +43,7 @@ namespace DesktopMagic
{
dict.Source = new Uri("..\\Resources\\StringResources.en.xaml", UriKind.Relative);
}
- this.Resources.MergedDictionaries.Add(dict);
+ Resources.MergedDictionaries.Add(dict);
}
}
}
\ No newline at end of file
diff --git a/src/DesktopMagic/GlobalSuppressions.cs b/src/DesktopMagic/GlobalSuppressions.cs
index ba7f009..9bb0139 100644
--- a/src/DesktopMagic/GlobalSuppressions.cs
+++ b/src/DesktopMagic/GlobalSuppressions.cs
@@ -5,5 +5,5 @@
using System.Diagnostics.CodeAnalysis;
-[assembly: SuppressMessage("Performance", "CA1822:Member als statisch markieren", Justification = "", Scope = "member", Target = "~M:DesktopMagic.PluginWindow.LoadOptions(System.Object)")]
-[assembly: SuppressMessage("Style", "IDE0090:Use 'new(...)'", Justification = "", Scope = "member", Target = "~M:DesktopMagic.MainWindow.GithubButton_Click(System.Object,System.Windows.RoutedEventArgs)")]
\ No newline at end of file
+[assembly: SuppressMessage("Interoperability", "CA1416:Validate platform compatibility", Justification = "Windows only application")]
+[assembly: SuppressMessage("Performance", "CA1822:Mark members as static", Justification = "No need to")]
\ No newline at end of file
diff --git a/src/DesktopMagic/Helpers/ColorConverter.cs b/src/DesktopMagic/Helpers/ColorConverter.cs
new file mode 100644
index 0000000..efdd6fc
--- /dev/null
+++ b/src/DesktopMagic/Helpers/ColorConverter.cs
@@ -0,0 +1,76 @@
+using System.Globalization;
+using System.Text.RegularExpressions;
+
+namespace DesktopMagic.Helpers
+{
+ internal static class MultiColorConverter
+ {
+ 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 && 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;
+ }
+ }
+ }
+}
\ No newline at end of file
diff --git a/src/DesktopMagic/SampleAggregator.cs b/src/DesktopMagic/Helpers/SampleAggregator.cs
similarity index 100%
rename from src/DesktopMagic/SampleAggregator.cs
rename to src/DesktopMagic/Helpers/SampleAggregator.cs
diff --git a/src/DesktopMagic/Helpers/SettingElementGenerator.cs b/src/DesktopMagic/Helpers/SettingElementGenerator.cs
new file mode 100644
index 0000000..98e72e0
--- /dev/null
+++ b/src/DesktopMagic/Helpers/SettingElementGenerator.cs
@@ -0,0 +1,238 @@
+using DesktopMagic.Plugins;
+
+using System;
+using System.Windows;
+using System.Windows.Controls;
+
+namespace DesktopMagic.Helpers
+{
+ internal class SettingElementGenerator
+ {
+ private readonly ComboBox optionsComboBox;
+
+ public SettingElementGenerator(ComboBox optionsComboBox)
+ {
+ this.optionsComboBox = optionsComboBox;
+ }
+
+ public void Generate(SettingElement settingElement, DockPanel dockPanel, TextBlock textBlock)
+ {
+ dockPanel.UpdateLayout();
+ textBlock.UpdateLayout();
+ if (settingElement.Element is DesktopMagicPluginAPI.Inputs.Label eLabel)
+ {
+ 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.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();
+ }
+ catch (Exception ex)
+ {
+ DisplayException(ex.Message);
+ }
+ };
+ eButton.OnValueChanged += () =>
+ {
+ button.Dispatcher.Invoke(() =>
+ {
+ 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);
+ }
+ }
+
+ 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();
+ }
+ }
+}
\ No newline at end of file
diff --git a/src/DesktopMagic/Helpers/StringUtilities.cs b/src/DesktopMagic/Helpers/StringUtilities.cs
new file mode 100644
index 0000000..1fd3eab
--- /dev/null
+++ b/src/DesktopMagic/Helpers/StringUtilities.cs
@@ -0,0 +1,25 @@
+using System.Globalization;
+using System.Windows;
+using System.Windows.Controls;
+using System.Windows.Media;
+
+namespace DesktopMagic.Helpers
+{
+ internal static class StringUtilities
+ {
+ public static Size MeasureString(string input, TextBlock element)
+ {
+ FormattedText formattedText = new FormattedText(
+ input,
+ CultureInfo.CurrentCulture,
+ FlowDirection.LeftToRight,
+ new Typeface(element.FontFamily, element.FontStyle, element.FontWeight, element.FontStretch),
+ element.FontSize,
+ Brushes.Black,
+ new NumberSubstitution(),
+ 1);
+
+ return new Size(formattedText.Width, formattedText.Height);
+ }
+ }
+}
\ No newline at end of file
diff --git a/src/DesktopMagic/Win32Wrapper.cs b/src/DesktopMagic/Helpers/Win32Wrapper.cs
similarity index 97%
rename from src/DesktopMagic/Win32Wrapper.cs
rename to src/DesktopMagic/Helpers/Win32Wrapper.cs
index 35ce35b..90dace6 100644
--- a/src/DesktopMagic/Win32Wrapper.cs
+++ b/src/DesktopMagic/Helpers/Win32Wrapper.cs
@@ -541,7 +541,7 @@ namespace DesktopMagic
public static extern int GetSystemMetrics(int abc);
[DllImport("user32.dll", EntryPoint = "GetWindowDC")]
- public static extern IntPtr GetWindowDC(Int32 ptr);
+ public static extern IntPtr GetWindowDC(int ptr);
[DllImport("user32.dll")]
public static extern bool IsWindowVisible(IntPtr hWnd);
@@ -559,7 +559,7 @@ namespace DesktopMagic
public static extern IntPtr SelectObject(IntPtr hdc, IntPtr bmp);
[DllImport("user32.dll", CharSet = CharSet.Auto)]
- public static extern IntPtr SendMessage(IntPtr hWnd, UInt32 Msg, int wParam, IntPtr lParam);
+ public static extern IntPtr SendMessage(IntPtr hWnd, uint Msg, int wParam, IntPtr lParam);
[DllImport("user32.dll", SetLastError = true, CharSet = CharSet.Auto)]
public static extern IntPtr SendMessageTimeout(IntPtr windowHandle, uint Msg, IntPtr wParam, IntPtr lParam, SendMessageTimeoutFlags flags, uint timeout, out IntPtr result);
@@ -590,7 +590,7 @@ namespace DesktopMagic
public static extern bool SetWindowPos(IntPtr hWnd, IntPtr hWndInsertAfter, int X, int Y, int cx, int cy, SetWindowPosFlags uFlags);
[DllImport("user32.dll", CharSet = CharSet.Auto)]
- public static extern Int32 SystemParametersInfo(UInt32 action, UInt32 uParam, string vParam, UInt32 winIni);
+ public static extern int SystemParametersInfo(uint action, uint uParam, string vParam, uint winIni);
[StructLayout(LayoutKind.Sequential)]
public struct BbStruct //Blur Behind Structure
@@ -642,37 +642,37 @@ namespace DesktopMagic
public int X
{
- get { return Left; }
+ get => Left;
set { Right -= (Left - value); Left = value; }
}
public int Y
{
- get { return Top; }
+ get => Top;
set { Bottom -= (Top - value); Top = value; }
}
public int Height
{
- get { return Bottom - Top; }
- set { Bottom = value + Top; }
+ get => Bottom - Top;
+ set => Bottom = value + Top;
}
public int Width
{
- get { return Right - Left; }
- set { Right = value + Left; }
+ get => Right - Left;
+ set => Right = value + Left;
}
public System.Drawing.Point Location
{
- get { return new System.Drawing.Point(Left, Top); }
+ get => new System.Drawing.Point(Left, Top);
set { X = value.X; Y = value.Y; }
}
public System.Drawing.Size Size
{
- get { return new System.Drawing.Size(Width, Height); }
+ get => new System.Drawing.Size(Width, Height);
set { Width = value.Width; Height = value.Height; }
}
@@ -703,10 +703,15 @@ namespace DesktopMagic
public override bool Equals(object obj)
{
- if (obj is RECT)
- return Equals((RECT)obj);
- else if (obj is System.Drawing.Rectangle)
- return Equals(new RECT((System.Drawing.Rectangle)obj));
+ if (obj is RECT rECT)
+ {
+ return Equals(rECT);
+ }
+ else if (obj is System.Drawing.Rectangle rectangle)
+ {
+ return Equals(new RECT(rectangle));
+ }
+
return false;
}
diff --git a/src/DesktopMagic/WindowPos.cs b/src/DesktopMagic/Helpers/WindowPos.cs
similarity index 86%
rename from src/DesktopMagic/WindowPos.cs
rename to src/DesktopMagic/Helpers/WindowPos.cs
index 3170632..29e233d 100644
--- a/src/DesktopMagic/WindowPos.cs
+++ b/src/DesktopMagic/Helpers/WindowPos.cs
@@ -29,8 +29,8 @@ namespace DesktopMagic
int cy,
uint uFlags);
- private const UInt32 SWP_NOSIZE1 = 0x0001;
- private const UInt32 SWP_NOMOVE1 = 0x0002;
+ private const uint SWP_NOSIZE1 = 0x0001;
+ private const uint SWP_NOMOVE1 = 0x0002;
private static readonly IntPtr HWND_BOTTOM = new IntPtr(1);
@@ -42,7 +42,7 @@ namespace DesktopMagic
public static void SendWpfWindowBack(Window window)
{
- var hWnd = new WindowInteropHelper(window).Handle;
+ IntPtr hWnd = new WindowInteropHelper(window).Handle;
SetWindowPos(hWnd, HWND_BOTTOM, 0, 0, 0, 0, SWP_NOSIZE1 | SWP_NOMOVE1);
}
@@ -62,12 +62,12 @@ namespace DesktopMagic
private static void IsLocked_Changed(DependencyObject d, DependencyPropertyChangedEventArgs e)
{
- var window = (Window)d;
- var isHooked = d.GetValue(IsHookedProperty) != null;
+ Window window = (Window)d;
+ bool isHooked = d.GetValue(IsHookedProperty) != null;
if (!isHooked)
{
- var hook = new WindowLockHook(window);
+ WindowLockHook hook = new WindowLockHook(window);
d.SetValue(IsHookedProperty, hook);
}
}
@@ -82,10 +82,9 @@ namespace DesktopMagic
public WindowLockHook(Window window)
{
- this.Window = window;
+ Window = window;
- var source = PresentationSource.FromVisual(window) as HwndSource;
- if (source == null)
+ if (PresentationSource.FromVisual(window) is not HwndSource source)
{
// If there is no hWnd, we need to wait until there is
window.SourceInitialized += Window_SourceInitialized;
@@ -98,7 +97,7 @@ namespace DesktopMagic
private void Window_SourceInitialized(object sender, EventArgs e)
{
- var source = (HwndSource)PresentationSource.FromVisual(Window);
+ HwndSource source = (HwndSource)PresentationSource.FromVisual(Window);
source.AddHook(WndProc);
}
@@ -106,7 +105,7 @@ namespace DesktopMagic
{
if (msg == WM_WINDOWPOSCHANGING && GetIsLocked(Window))
{
- var wp = Marshal.PtrToStructure(lParam);
+ WINDOWPOS wp = Marshal.PtrToStructure(lParam);
wp.flags |= SWP_NOMOVE | SWP_NOSIZE;
Marshal.StructureToPtr(wp, lParam, false);
}
diff --git a/src/DesktopMagic/MainWindow.xaml b/src/DesktopMagic/MainWindow.xaml
index c73257b..1f0ff02 100644
--- a/src/DesktopMagic/MainWindow.xaml
+++ b/src/DesktopMagic/MainWindow.xaml
@@ -38,14 +38,15 @@
-
+
+
-
+
@@ -57,11 +58,11 @@
-
-
-
+
+
+
-
+
@@ -73,34 +74,59 @@
-
-
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
-
-
-
-
-
-
-
-
-
-
-
-
+
+
+
+
+
+
-
+
+
+
+
+
+
+
+
+
-
+
-
-
-
-
-
-
+
+
+
+
+
+
+
+
+
+
+
+
+
+
-
+
diff --git a/src/DesktopMagic/MainWindow.xaml.cs b/src/DesktopMagic/MainWindow.xaml.cs
index ab0c97f..985ee05 100644
--- a/src/DesktopMagic/MainWindow.xaml.cs
+++ b/src/DesktopMagic/MainWindow.xaml.cs
@@ -1,8 +1,16 @@
-using Microsoft.Win32;
+using DesktopMagic.BuiltInWindowElements;
+using DesktopMagic.Dialogs;
+using DesktopMagic.Helpers;
+using DesktopMagic.Plugins;
+
+using Microsoft.Win32;
+
+using Stone_Red_Utilities.Logging;
using System;
using System.Collections.Generic;
using System.Diagnostics;
+using System.Globalization;
using System.IO;
using System.Linq;
using System.Reflection;
@@ -14,39 +22,33 @@ using System.Windows.Media;
namespace DesktopMagic
{
- ///
- /// Interaktionslogik für MainWindow.xaml
- ///
-
public partial class MainWindow : Window
{
#region Global settings
- public static string GlobalFont { get; protected set; } = "Segoe UI";
- public static Brush GlobalColor { get; protected set; } = Brushes.White;
- public static System.Drawing.Brush GlobalSystemColor { get; protected set; } = System.Drawing.Brushes.White;
- public static bool EditMode { get; protected set; } = false;
+ internal static Theme Theme = new Theme();
+ public static bool EditMode { get; private set; } = false;
#endregion Global settings
#region Music Visualizer Settings
- public static int SpectrumMode { get; protected set; } = 0;
- public static int AmplifierLevel { get; protected set; } = 0;
- public static bool MirrorMode { get; protected set; } = false;
- public static bool LineMode { get; protected set; } = false;
- public static System.Drawing.Brush MusicVisualzerColor { get; protected set; }
+ public static int SpectrumMode { get; private set; } = 0;
+ public static int AmplifierLevel { get; private set; } = 0;
+ public static bool MirrorMode { get; private set; } = false;
+ public static bool LineMode { get; private set; } = false;
+ public static System.Drawing.Color? MusicVisualzerColor { get; private set; }
#endregion Music Visualizer Settings
#region Plugins settings
- internal static Dictionary> PluginsSettings { get; set; } = new Dictionary>();
+ internal static Dictionary> PluginsSettings { get; } = new Dictionary>();
#endregion Plugins settings
- public static List Windows { get; protected set; } = new List();
- public static List WindowNames { get; protected set; } = new List();
+ public static List Windows { get; } = new List();
+ public static List WindowNames { get; } = new List();
private readonly RegistryKey key;
private readonly System.Windows.Forms.NotifyIcon notifyIcon = new();
@@ -65,12 +67,16 @@ namespace DesktopMagic
notifyIcon.Visible = true;
notifyIcon.Text = App.AppName;
notifyIcon.Icon = new System.Drawing.Icon(iconStream);
- notifyIcon.ContextMenuStrip = new System.Windows.Forms.ContextMenuStrip();
InitializeComponent();
SetLanguageDictionary();
+
+#if DEBUG
+ Title = $"{App.AppName} - Dev {Assembly.GetExecutingAssembly().GetName().Version}";
+#else
Title = $"{App.AppName} - {Assembly.GetExecutingAssembly().GetName().Version}";
+#endif
}
catch (Exception ex)
{
@@ -78,18 +84,12 @@ namespace DesktopMagic
}
}
- #region load
+ #region Load
private void Window_Loaded(object sender, RoutedEventArgs e)
{
try
{
- if (!Directory.Exists(App.ApplicationDataPath))
- {
- _ = Directory.CreateDirectory(App.ApplicationDataPath);
- }
- App.Logger.Log("Created ApplicationData Folder", "Main");
-
if (!Directory.Exists(App.ApplicationDataPath + "\\Plugins"))
{
_ = Directory.CreateDirectory(App.ApplicationDataPath + "\\Plugins");
@@ -102,8 +102,6 @@ namespace DesktopMagic
}
App.Logger.Log("Created layouts.save file", "Main");
- _ = optionsComboBox.Items.Add(new Tuple((string)FindResource("musicVisualizer"), 0));
-
//Write To Log File and Load Elements
App.Logger.Log("Loading Plugin names", "Main");
@@ -118,7 +116,8 @@ namespace DesktopMagic
}
catch (Exception ex)
{
- MessageBox.Show(ex.ToString());
+ App.Logger.Log(ex.Message, "Main", LogSeverity.Error);
+ _ = MessageBox.Show(ex.ToString());
}
}
@@ -134,7 +133,10 @@ namespace DesktopMagic
_ = Directory.CreateDirectory(PluginsPath + "\\" + PluginName);
File.Move(fileName, $"{PluginsPath}\\{PluginName}\\{PluginName}.dll");
}
- catch { }
+ catch (Exception ex)
+ {
+ App.Logger.Log(ex.Message, "Main", LogSeverity.Error);
+ }
}
foreach (string directory in Directory.GetDirectories(PluginsPath))
@@ -160,17 +162,17 @@ namespace DesktopMagic
checkBox.Style = (Style)FindResource("MaterialDesignDarkCheckBox");
checkBox.Click += CheckBox_Click;
- bool exsists = false;
+ bool exists = false;
foreach (UIElement item in stackPanel.Children)
{
if (((CheckBox)item).Name == "_PluginCb_" + clearPluginName)
{
- exsists = true;
+ exists = true;
break;
}
}
- if (!exsists)
+ if (!exists)
{
_ = stackPanel.Children.Add(checkBox);
}
@@ -179,7 +181,7 @@ namespace DesktopMagic
}
}
- #endregion load
+ #endregion Load
#region Windows
@@ -192,83 +194,72 @@ namespace DesktopMagic
private void CheckBox_Click(object sender, RoutedEventArgs e)
{
CheckBox checkBox = (CheckBox)sender;
- Window window;
+ PluginWindow window = null;
blockWindowsClosing = false;
switch (checkBox.Name)
{
case "TimeCb":
- window = new TimeWindow();
+ window = new PluginWindow(new TimePlugin(), checkBox.Content.ToString());
break;
case "DateCb":
- window = new DateWindow();
+ window = new PluginWindow(new DatePlugin(), checkBox.Content.ToString());
break;
case "CpuUsageCb":
- window = new CpuUsageWindow();
- break;
-
- case "CalendarCb":
- window = new CalendarWindow();
+ //window = new PluginWindow();
break;
case "MusicVisualizerCb":
- window = new MusicVisualizerWindow();
+ window = new PluginWindow(new MusicVisualizerPlugin(), checkBox.Content.ToString());
break;
default:
- if (checkBox.Name.Contains("_PluginCb_"))
- {
- window = new PluginWindow(checkBox.Content.ToString())
- {
- Title = checkBox.Content.ToString()
- };
- break;
- }
- else
+ if (!checkBox.Name.Contains("_PluginCb_"))
{
return;
}
+
+ window = new PluginWindow(checkBox.Content.ToString());
+ break;
}
- if (!WindowNames.Contains(window.Title))
+ if (window is null)
+ {
+ return;
+ }
+ window.Title = checkBox.Content.ToString();
+ if (!WindowNames.Contains(window.Title) && checkBox.IsChecked == true)
{
_ = Task.Run(() =>
{
Dispatcher.Invoke(() =>
{
- if (window is PluginWindow pluginWindow)
+ Action onPluginLoaded = null;
+ onPluginLoaded = () =>
{
- Action onPluginLoaded = null;
- onPluginLoaded = () =>
+ Dispatcher.Invoke(() =>
{
- Dispatcher.Invoke(() =>
+ if (!optionsComboBox.Items.Contains(checkBox.Content.ToString()))
{
- if (!optionsComboBox.Items.Contains(new Tuple(checkBox.Content.ToString(), 0)))
- {
- _ = optionsComboBox.Items.Add(new Tuple(checkBox.Content.ToString(), 0));
- }
- optionsComboBox.SelectedIndex = -1;
- optionsComboBox.SelectedIndex = optionsComboBox.Items.IndexOf(new Tuple(checkBox.Content.ToString(), 0));
- pluginWindow.PluginLoaded -= onPluginLoaded;
- });
- };
- pluginWindow.OnExit += () =>
+ _ = optionsComboBox.Items.Add(checkBox.Content.ToString());
+ }
+ optionsComboBox.SelectedIndex = -1;
+ optionsComboBox.SelectedIndex = optionsComboBox.Items.IndexOf(checkBox.Content.ToString());
+ window.PluginLoaded -= onPluginLoaded;
+ });
+ };
+ window.OnExit += () =>
{
checkBox.IsChecked = false;
CheckBox_Click(checkBox, null);
};
- pluginWindow.PluginLoaded += onPluginLoaded;
- }
- else if (window is MusicVisualizerWindow musicVisualizerWindow)
- {
- optionsComboBox.SelectedIndex = optionsComboBox.Items.IndexOf(new Tuple(checkBox.Content.ToString(), 0));
- }
+ window.PluginLoaded += onPluginLoaded;
window.ShowInTaskbar = false;
window.Show();
- window.ContentRendered += PluginWindow_ContentRendered;
+ window.ContentRendered += DisplayWindow_ContentRendered;
window.Closing += DisplayWindow_Closing;
Windows.Add(window);
WindowNames.Add(window.Title);
@@ -279,17 +270,25 @@ namespace DesktopMagic
{
int index = WindowNames.IndexOf(window.Title);
- Windows[index].Close();
- Windows.RemoveAt(index);
- WindowNames.RemoveAt(index);
- window.Close();
+ if (index >= 0)
+ {
+ //Not sure how to handle this
+ try
+ {
+ Windows[index].Close();
+
+ Windows.RemoveAt(index);
+ WindowNames.RemoveAt(index);
+ }
+ catch { }
+ }
}
key.SetValue(checkBox.Name, checkBox.IsChecked.ToString());
blockWindowsClosing = true;
SaveLayout();
}
- private void PluginWindow_ContentRendered(object sender, EventArgs e)
+ private void DisplayWindow_ContentRendered(object sender, EventArgs e)
{
WindowPos.SendWpfWindowBack(sender as Window);
WindowPos.SendWpfWindowBack(sender as Window);
@@ -335,7 +334,7 @@ namespace DesktopMagic
#endregion Windows
- #region options
+ #region Options
private void AmplifierLevelSlider_ValueChanged(object sender, RoutedPropertyChangedEventArgs e)
{
@@ -345,17 +344,17 @@ namespace DesktopMagic
SaveLayout();
}
- private void MirrorPlugineCheckBox_Click(object sender, RoutedEventArgs e)
+ private void MirrorModeCheckBox_Click(object sender, RoutedEventArgs e)
{
- MirrorMode = (bool)mirrorPlugineCheckBox.IsChecked;
- key.SetValue("MirrorPlugine", mirrorPlugineCheckBox.IsChecked.ToString());
+ MirrorMode = (bool)mirrorModeCheckBox.IsChecked;
+ key.SetValue("MirrorMode", mirrorModeCheckBox.IsChecked.ToString());
SaveLayout();
}
- private void LinePlugineCheckBox_Click(object sender, RoutedEventArgs e)
+ private void LineModeCheckBox_Click(object sender, RoutedEventArgs e)
{
- LineMode = (bool)linePlugineCheckBox.IsChecked;
- key.SetValue("LinePlugine", linePlugineCheckBox.IsChecked.ToString());
+ LineMode = (bool)lineModeCheckBox.IsChecked;
+ key.SetValue("LineMode", lineModeCheckBox.IsChecked.ToString());
SaveLayout();
}
@@ -363,46 +362,42 @@ namespace DesktopMagic
{
if (!string.IsNullOrWhiteSpace(musicVisualizerColorTextBox.Text) && musicVisualizerColorTextBox.Text != "Default")
{
- try
+ if (musicVisualizerColorTextBox.Text.Length > 0)
{
- if (musicVisualizerColorTextBox.Text.Length > 0)
+ if (musicVisualizerColorTextBox.Text.ToCharArray()[0] != '#')
{
- if (musicVisualizerColorTextBox.Text.ToCharArray()[0] != '#')
- {
- musicVisualizerColorTextBox.Text = "#" + musicVisualizerColorTextBox.Text.Replace("#", "");
- }
+ musicVisualizerColorTextBox.Text = "#" + musicVisualizerColorTextBox.Text.Replace("#", "");
+ }
+ }
+ else
+ {
+ musicVisualizerColorTextBox.Text = "#";
+ musicVisualizerColorTextBox.Select(musicVisualizerColorTextBox.Text.Length, 0);
+ }
+
+ if (musicVisualizerColorTextBox.SelectionStart == 0)
+ {
+ if (musicVisualizerColorTextBox.Text.Length <= 2)
+ {
+ musicVisualizerColorTextBox.Select(musicVisualizerColorTextBox.Text.Length, 0);
}
else
{
- musicVisualizerColorTextBox.Text = "#";
- musicVisualizerColorTextBox.Select(musicVisualizerColorTextBox.Text.Length, 0);
+ musicVisualizerColorTextBox.Select(1, 0);
}
+ }
- if (musicVisualizerColorTextBox.SelectionStart == 0)
- {
- if (musicVisualizerColorTextBox.Text.Length <= 2)
- {
- musicVisualizerColorTextBox.Select(musicVisualizerColorTextBox.Text.Length, 0);
- }
- else
- {
- musicVisualizerColorTextBox.Select(1, 0);
- }
- }
+ string hex = musicVisualizerColorTextBox.Text;
- string hex = musicVisualizerColorTextBox.Text;
- hex = hex.Replace("#", "");
-
- System.Drawing.Color systemColor = System.Drawing.Color.FromArgb((byte)int.Parse(hex.Substring(0, 2), System.Globalization.NumberStyles.HexNumber), (byte)int.Parse(hex.Substring(2, 2), System.Globalization.NumberStyles.HexNumber), (byte)int.Parse(hex.Substring(4, 2), System.Globalization.NumberStyles.HexNumber));
- System.Drawing.Brush systemBrush = new System.Drawing.SolidBrush(systemColor);
-
- MusicVisualzerColor = systemBrush;
+ if (MultiColorConverter.TryConvertToSystemColor(hex, out System.Drawing.Color systemColor))
+ {
+ MusicVisualzerColor = systemColor;
musicVisualizerColorTextBox.Foreground = Brushes.Black;
key.SetValue("MusicVisualizerColor", musicVisualizerColorTextBox.Text);
SaveLayout();
}
- catch
+ else
{
musicVisualizerColorTextBox.Foreground = Brushes.Red;
}
@@ -417,17 +412,17 @@ namespace DesktopMagic
private void FontComboBox_SelectionChanged(object sender, SelectionChangedEventArgs e)
{
- GlobalFont = fontComboBox.SelectedValue.ToString().Replace("System.Windows.Controls.ComboBoxItem: ", "");
- key.SetValue("Font", GlobalFont);
+ Theme.Font = fontComboBox.SelectedValue.ToString().Replace("System.Windows.Controls.ComboBoxItem: ", "");
+ key.SetValue("Font", Theme.Font);
SaveLayout();
}
- private void SpectrumPlugineComboBox_SelectionChanged(object sender, SelectionChangedEventArgs e)
+ private void SpectrumModeComboBox_SelectionChanged(object sender, SelectionChangedEventArgs e)
{
- SpectrumMode = spectrumPlugineComboBox.SelectedIndex;
- key.SetValue("SpectrumPlugine", spectrumPlugineComboBox.SelectedIndex);
+ SpectrumMode = spectrumModeComboBox.SelectedIndex;
+ key.SetValue("SpectrumMode", spectrumModeComboBox.SelectedIndex);
- mirrorPlugineCheckBox.IsEnabled = spectrumPlugineComboBox.SelectedIndex != 1;
+ mirrorModeCheckBox.IsEnabled = spectrumModeComboBox.SelectedIndex != 1;
SaveLayout();
}
@@ -448,222 +443,38 @@ namespace DesktopMagic
optionsPanel.Children.Clear();
optionsPanel.UpdateLayout();
- bool succ = PluginsSettings.TryGetValue(((Tuple)optionsComboBox.SelectedItem).Item1.ToString(), out List settingElements);
- if (!succ || settingElements?.Count == 0)
+ bool success = PluginsSettings.TryGetValue(optionsComboBox.SelectedItem.ToString(), out List settingElements);
+ if (!success || settingElements?.Count == 0)
{
_ = optionsPanel.Children.Add(new TextBlock() { Text = (string)FindResource("noOptions") });
return;
}
+ SettingElementGenerator settingElementGenerator = new SettingElementGenerator(optionsComboBox);
+
foreach (SettingElement settingElement in settingElements)
{
- DockPanel stackPanel = new()
+ DockPanel dockPanel = new()
{
LastChildFill = true,
HorizontalAlignment = HorizontalAlignment.Stretch
};
- _ = optionsPanel.Children.Add(stackPanel);
+ _ = optionsPanel.Children.Add(dockPanel);
- TextBlock label = new()
+ TextBlock textBlock = new()
{
Text = settingElement.Name,
Padding = new Thickness(0, 0, 3, 0),
VerticalAlignment = VerticalAlignment.Center
};
- _ = stackPanel.Children.Add(label);
- stackPanel.UpdateLayout();
- label.UpdateLayout();
-
- if (settingElement.Element is DesktopMagicPluginAPI.Inputs.Label eLabel)
- {
- label.Text = eLabel.Value;
- label.Margin = new Thickness(0, 5, 3, 0);
- label.HorizontalAlignment = HorizontalAlignment.Stretch;
- label.TextWrapping = TextWrapping.WrapWithOverflow;
-
- if (eLabel.Bold)
- {
- label.FontWeight = FontWeights.Bold;
- }
- eLabel.OnValueChanged += () =>
- {
- Dispatcher.Invoke(() =>
- {
- label.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();
- }
- catch (Exception ex)
- {
- DisplayException(ex.Message);
- }
- };
- eButton.OnValueChanged += () =>
- {
- Dispatcher.Invoke(() =>
- {
- button.Content = eButton.Value;
- });
- };
-
- _ = stackPanel.Children.Add(button);
- }
- else if (settingElement.Element is DesktopMagicPluginAPI.Inputs.CheckBox eCheckBox)
- {
- CheckBox checkBox = new()
- {
- IsChecked = eCheckBox.Value,
- Style = (Style)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 += () =>
- {
- Dispatcher.Invoke(() =>
- {
- checkBox.IsChecked = eCheckBox.Value;
- });
- };
-
- _ = stackPanel.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 += () =>
- {
- Dispatcher.Invoke(() =>
- {
- textBox.Text = eTextBox.Value;
- });
- };
- _ = stackPanel.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 += () =>
- {
- Dispatcher.Invoke(() =>
- {
- integerUpDown.Value = eIntegerUpDown.Value;
- });
- };
- _ = stackPanel.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 += () =>
- {
- Dispatcher.Invoke(() =>
- {
- slider.Value = eSlider.Value;
- });
- };
-
- _ = stackPanel.Children.Add(slider);
- }
+ _ = dockPanel.Children.Add(textBlock);
+ settingElementGenerator.Generate(settingElement, dockPanel, textBlock);
}
}
}
- private void DisplayException(string message)
- {
- App.Logger.Log(message, "PluginInput");
- _ = MessageBox.Show("File execution error:\n" + message, "Error", MessageBoxButton.OK, MessageBoxImage.Error);
- int index = WindowNames.IndexOf(((Tuple)optionsComboBox.SelectedItem).Item1.ToString());
-
- PluginWindow window = Windows[index] as PluginWindow;
- window?.Exit();
- }
-
- #endregion options
+ #endregion Options
private void TextBlock_Loaded(object sender, RoutedEventArgs e)
{
@@ -677,7 +488,7 @@ namespace DesktopMagic
};
_ = fontComboBox.Items.Add(comboBoxItem);
- if (ff.ToString() == GlobalFont)
+ if (ff.ToString() == Theme.Font)
{
fontComboBox.SelectedIndex = index;
}
@@ -689,70 +500,79 @@ namespace DesktopMagic
}
}
- #region color
-
- private void ColorSliders_ValueChanged(object sender, RoutedPropertyChangedEventArgs e)
+ private void ChangePrimaryColorButton_Click(object sender, RoutedEventArgs e)
{
- colorHexTextBox.Text = "#" + ((int)redSlider.Value).ToString("X2") + ((int)greenSlider.Value).ToString("X2") + ((int)blueSlider.Value).ToString("X2");
- colorHexTextBox.Select(colorHexTextBox.Text.Length, 0);
- }
-
- private void ColorHexTextBox_TextChanged(object sender, TextChangedEventArgs e)
- {
- try
+ ColorDialog colorDialog = new ColorDialog("Set Primary Color", Theme.PrimaryColor);
+ if (colorDialog.ShowDialog() == true)
{
- if (colorHexTextBox.Text.Length > 0)
- {
- if (colorHexTextBox.Text.ToCharArray()[0] != '#')
- {
- colorHexTextBox.Text = "#" + colorHexTextBox.Text.Replace("#", "");
- }
- }
- else
- {
- colorHexTextBox.Text = "#";
- colorHexTextBox.Select(colorHexTextBox.Text.Length, 0);
- }
+ Theme.PrimaryBrush = colorDialog.ResultBrush;
+ Theme.PrimaryColor = colorDialog.ResultColor;
+ primaryColorRechtangle.Fill = colorDialog.ResultBrush;
- if (colorHexTextBox.SelectionStart == 0)
- {
- if (colorHexTextBox.Text.Length <= 2)
- {
- colorHexTextBox.Select(colorHexTextBox.Text.Length, 0);
- }
- else
- {
- colorHexTextBox.Select(1, 0);
- }
- }
-
- string hex = colorHexTextBox.Text;
- hex = hex.Replace("#", "");
- Color color = Color.FromRgb((byte)int.Parse(hex.Substring(0, 2), System.Globalization.NumberStyles.HexNumber), (byte)int.Parse(hex.Substring(2, 2), System.Globalization.NumberStyles.HexNumber), (byte)int.Parse(hex.Substring(4, 2), System.Globalization.NumberStyles.HexNumber));
- System.Drawing.Color systemColor = System.Drawing.Color.FromArgb((byte)int.Parse(hex.Substring(0, 2), System.Globalization.NumberStyles.HexNumber), (byte)int.Parse(hex.Substring(2, 2), System.Globalization.NumberStyles.HexNumber), (byte)int.Parse(hex.Substring(4, 2), System.Globalization.NumberStyles.HexNumber));
-
- redSlider.Value = color.R;
- greenSlider.Value = color.G;
- blueSlider.Value = color.B;
-
- Brush brush = new SolidColorBrush(color);
- System.Drawing.Brush systemBrush = new System.Drawing.SolidBrush(systemColor);
-
- GlobalColor = brush;
- GlobalSystemColor = systemBrush;
- colorRechtangle.Fill = brush;
- colorHexTextBox.Foreground = Brushes.Black;
-
- key.SetValue("Color", colorHexTextBox.Text);
+ key.SetValue("PrimaryColor", MultiColorConverter.ConvertToHex(Theme.PrimaryColor));
SaveLayout();
}
- catch
+ }
+
+ private void ChangeSecondaryColorButton_Click(object sender, RoutedEventArgs e)
+ {
+ ColorDialog colorDialog = new ColorDialog("Set Secondary Color", Theme.SecondaryColor);
+ if (colorDialog.ShowDialog() == true)
{
- colorHexTextBox.Foreground = Brushes.Red;
+ Theme.SecondaryBrush = colorDialog.ResultBrush;
+ Theme.SecondaryColor = colorDialog.ResultColor;
+ secondaryColorRechtangle.Fill = colorDialog.ResultBrush;
+
+ key.SetValue("SecondaryColor", MultiColorConverter.ConvertToHex(Theme.SecondaryColor));
+ SaveLayout();
}
}
- #endregion color
+ private void ChangeBackgroundColorButton_Click(object sender, RoutedEventArgs e)
+ {
+ ColorDialog colorDialog = new ColorDialog("Set Background Color", Theme.BackgroundColor);
+ if (colorDialog.ShowDialog() == true)
+ {
+ Theme.BackgroundBrush = colorDialog.ResultBrush;
+ Theme.BackgroundColor = colorDialog.ResultColor;
+ backgroundColorRechtangle.Fill = colorDialog.ResultBrush;
+
+ key.SetValue("BackgroundColor", MultiColorConverter.ConvertToHex(Theme.BackgroundColor));
+ SaveLayout();
+ }
+ }
+
+ private void CornerRadiusTextBox_TextChanged(object sender, TextChangedEventArgs e)
+ {
+ bool sucess = int.TryParse(cornerRadiusTextBox.Text, out int cornerRadius);
+ if (sucess)
+ {
+ cornerRadiusTextBox.Foreground = Brushes.Black;
+ Theme.CornerRadius = cornerRadius;
+ key.SetValue("CornerRadius", cornerRadius);
+ SaveLayout();
+ }
+ else
+ {
+ cornerRadiusTextBox.Foreground = Brushes.Red;
+ }
+ }
+
+ private void MarginTextBox_TextChanged(object sender, TextChangedEventArgs e)
+ {
+ bool sucess = int.TryParse(marginTextBox.Text, out int margin);
+ if (sucess)
+ {
+ marginTextBox.Foreground = Brushes.Black;
+ Theme.Margin = margin;
+ key.SetValue("Margin", margin);
+ SaveLayout();
+ }
+ else
+ {
+ marginTextBox.Foreground = Brushes.Red;
+ }
+ }
#region Layout
@@ -782,7 +602,7 @@ namespace DesktopMagic
for (int i = 0; i < fontComboBox.Items.Count; i++)
{
ComboBoxItem comboBoxItem = (ComboBoxItem)fontComboBox.Items[i];
- if (comboBoxItem.FontFamily.ToString() == GlobalFont)
+ if (comboBoxItem.FontFamily.ToString() == Theme.Font)
{
fontComboBox.SelectedIndex = i;
}
@@ -827,27 +647,32 @@ namespace DesktopMagic
private void SaveLayout()
{
+ if (!loaded)
+ {
+ return;
+ }
+
_ = Task.Run(() =>
- {
- lock (App.ApplicationDataPath)
- {
- List lines = File.ReadAllLines(App.ApplicationDataPath + "\\layouts.save").ToList();
- string content = "";
- foreach (string valueName in key.GetValueNames())
- {
- if (valueName != "SelectedLayout")
- {
- content += valueName + ":" + key.GetValue(valueName).ToString() + ";";
- }
- }
- Dispatcher.Invoke(() =>
- {
- content += layoutsComboBox.SelectedItem.ToString();
- lines[layoutsComboBox.SelectedIndex] = content;
- });
- File.WriteAllLines(App.ApplicationDataPath + "\\layouts.save", lines);
- }
- });
+ {
+ lock (App.ApplicationDataPath)
+ {
+ List lines = File.ReadAllLines(App.ApplicationDataPath + "\\layouts.save").ToList();
+ string content = "";
+ foreach (string valueName in key.GetValueNames())
+ {
+ if (valueName != "SelectedLayout")
+ {
+ content += valueName + ":" + key.GetValue(valueName).ToString() + ";";
+ }
+ }
+ Dispatcher.Invoke(() =>
+ {
+ content += layoutsComboBox.SelectedItem.ToString();
+ lines[layoutsComboBox.SelectedIndex] = content;
+ });
+ File.WriteAllLines(App.ApplicationDataPath + "\\layouts.save", lines);
+ }
+ });
}
private void LoadLayoutNames()
@@ -860,25 +685,52 @@ namespace DesktopMagic
string name = line[(line.LastIndexOf(";", StringComparison.InvariantCulture) + 1)..];
_ = layoutsComboBox.Items.Add(name);
}
- layoutsComboBox.SelectedIndex = int.Parse(key.GetValue("SelectedLayout", "0").ToString());
+ layoutsComboBox.SelectedIndex = int.Parse(key.GetValue("SelectedLayout", "0").ToString(), CultureInfo.InvariantCulture);
}
private void LoadLayout(bool minimize = true)
{
- GlobalFont = key.GetValue("Font", "Segoe UI").ToString();
- spectrumPlugineComboBox.SelectedIndex = int.Parse(key.GetValue("SpectrumPlugine", "0").ToString());
- amplifierLevelSlider.Value = int.Parse(key.GetValue("AmplifierLevel", "0").ToString());
- mirrorPlugineCheckBox.IsChecked = bool.Parse(key.GetValue("MirrorPlugine", "false").ToString());
- linePlugineCheckBox.IsChecked = bool.Parse(key.GetValue("LinePlugine", "false").ToString());
+ Theme.Font = key.GetValue("Font", "Segoe UI").ToString();
+ spectrumModeComboBox.SelectedIndex = int.Parse(key.GetValue("SpectrumMode", "0").ToString(), CultureInfo.InvariantCulture);
+ amplifierLevelSlider.Value = int.Parse(key.GetValue("AmplifierLevel", "0").ToString(), CultureInfo.InvariantCulture);
+ mirrorModeCheckBox.IsChecked = bool.Parse(key.GetValue("MirrorMode", "false").ToString());
+ lineModeCheckBox.IsChecked = bool.Parse(key.GetValue("LineMode", "false").ToString());
musicVisualizerColorTextBox.Text = key.GetValue("MusicVisualizerColor", "").ToString();
- colorHexTextBox.Text = key.GetValue("Color", "#FFFFFF").ToString();
+ cornerRadiusTextBox.Text = key.GetValue("CornerRadius", "0").ToString();
+ marginTextBox.Text = key.GetValue("Margin", "0").ToString();
blockWindowsClosing = false;
+ string primaryColorHex = key.GetValue("PrimaryColor", "#FFFFFFFF").ToString();
+ string secondaryColorHex = key.GetValue("SecondaryColor", "#FFFFFFFF").ToString();
+ string backgroundColorHex = key.GetValue("BackgroundColor", "#00FFFFFF").ToString();
+
+ _ = MultiColorConverter.TryConvertToSystemColor(primaryColorHex, out System.Drawing.Color primarySystemColor);
+ _ = MultiColorConverter.TryConvertToMediaColor(primaryColorHex, out Color primaryMediaColor);
+ _ = MultiColorConverter.TryConvertToSystemColor(secondaryColorHex, out System.Drawing.Color secondarySystemColor);
+ _ = MultiColorConverter.TryConvertToMediaColor(secondaryColorHex, out Color secondaryMediaColor);
+ _ = MultiColorConverter.TryConvertToSystemColor(backgroundColorHex, out System.Drawing.Color backgroundSystemColor);
+ _ = MultiColorConverter.TryConvertToMediaColor(backgroundColorHex, out Color backgroundMediaColor);
+
+ Theme.PrimaryColor = primarySystemColor;
+ Theme.PrimaryBrush = new SolidColorBrush(primaryMediaColor);
+
+ Theme.SecondaryColor = secondarySystemColor;
+ Theme.SecondaryBrush = new SolidColorBrush(secondaryMediaColor);
+
+ Theme.BackgroundColor = backgroundSystemColor;
+ Theme.BackgroundBrush = new SolidColorBrush(backgroundMediaColor);
+
+ primaryColorRechtangle.Fill = Theme.PrimaryBrush;
+ secondaryColorRechtangle.Fill = Theme.SecondaryBrush;
+ backgroundColorRechtangle.Fill = Theme.BackgroundBrush;
+
MusicVisualizerColorTextBox_TextChanged(null, null);
- MirrorPlugineCheckBox_Click(null, null);
- LinePlugineCheckBox_Click(null, null);
- SpectrumPlugineComboBox_SelectionChanged(null, null);
+ MirrorModeCheckBox_Click(null, null);
+ LineModeCheckBox_Click(null, null);
+ SpectrumModeComboBox_SelectionChanged(null, null);
AmplifierLevelSlider_ValueChanged(null, null);
+ CornerRadiusTextBox_TextChanged(null, null);
+ MarginTextBox_TextChanged(null, null);
foreach (Window window in Windows)
{
@@ -890,6 +742,9 @@ namespace DesktopMagic
blockWindowsClosing = true;
Windows.Clear();
WindowNames.Clear();
+ optionsComboBox.Items.Clear();
+
+ _ = optionsComboBox.Items.Add((string)FindResource("musicVisualizer"));
IEnumerable list = stackPanel.Children.OfType();
bool showWindow = true;
@@ -914,7 +769,7 @@ namespace DesktopMagic
catch (Exception ex)
{
App.Logger.Log(ex.ToString(), "Main");
- MessageBox.Show(ex.ToString());
+ _ = MessageBox.Show(ex.ToString());
}
}
}
@@ -941,16 +796,16 @@ namespace DesktopMagic
private void UpdatePluginsButton_Click(object sender, RoutedEventArgs e)
{
LoadPlugins();
- Task.Run(() =>
- {
- foreach (Window window in Windows.ToArray())
- {
- if (window.GetType() == typeof(PluginWindow))
- {
- ((PluginWindow)window).UpdatePluginWindow();
- }
- }
- });
+ _ = Task.Run(() =>
+ {
+ foreach (Window window in Windows.ToArray())
+ {
+ if (window.GetType() == typeof(PluginWindow))
+ {
+ ((PluginWindow)window).UpdatePluginWindow();
+ }
+ }
+ });
}
private void OpenPluginsFolderButton_Click(object sender, RoutedEventArgs e)
@@ -973,27 +828,11 @@ namespace DesktopMagic
Visibility = Visibility.Visible;
SystemCommands.RestoreWindow(this);
Topmost = true;
- Activate();
+ _ = Activate();
Topmost = false;
}
}
- private void SetLanguageDictionary()
- {
- ResourceDictionary dict = new ResourceDictionary();
- string currentCulture = Thread.CurrentThread.CurrentUICulture.ToString();
-
- if (currentCulture.Contains("de"))
- {
- dict.Source = new Uri("..\\Resources\\StringResources.de.xaml", UriKind.Relative);
- }
- else
- {
- dict.Source = new Uri("..\\Resources\\StringResources.en.xaml", UriKind.Relative);
- }
- Resources.MergedDictionaries.Add(dict);
- }
-
private void GithubButton_Click(object sender, RoutedEventArgs e)
{
string uri = "https://github.com/Stone-Red-Code/DesktopMagic";
@@ -1011,5 +850,21 @@ namespace DesktopMagic
psi.FileName = uri;
_ = Process.Start(psi);
}
+
+ private void SetLanguageDictionary()
+ {
+ ResourceDictionary dict = new ResourceDictionary();
+ string currentCulture = Thread.CurrentThread.CurrentUICulture.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);
+ }
}
}
\ No newline at end of file
diff --git a/src/DesktopMagic/MusicVisualizerWindow.xaml b/src/DesktopMagic/MusicVisualizerWindow.xaml
deleted file mode 100644
index fd7b6b5..0000000
--- a/src/DesktopMagic/MusicVisualizerWindow.xaml
+++ /dev/null
@@ -1,24 +0,0 @@
-
-
-
-
-
-
-
-
-
-
-
\ No newline at end of file
diff --git a/src/DesktopMagic/Plugin/PluginData.cs b/src/DesktopMagic/Plugin/PluginData.cs
deleted file mode 100644
index d812d8f..0000000
--- a/src/DesktopMagic/Plugin/PluginData.cs
+++ /dev/null
@@ -1,29 +0,0 @@
-using DesktopMagicPluginAPI;
-using System.Drawing;
-
-namespace DesktopMagic
-{
- internal class PluginData : IPluginData
- {
- private readonly PluginWindow window;
-
- public PluginData(PluginWindow win)
- {
- window = win;
- }
-
- public string Font => MainWindow.GlobalFont;
-
- public Color Color => (MainWindow.GlobalSystemColor as SolidBrush).Color;
-
- public Point WindowSize => new Point((int)window.ActualWidth, (int)window.ActualHeight);
-
- public Point WindowPosition => new Point((int)window.Left, (int)window.Top);
-
- public string PluginName => window.PluginName;
-
- public string PluginPath => window.PluginFolderPath;
-
- public void UpdateWindow() => window.UpdatePluginWindow();
- }
-}
\ No newline at end of file
diff --git a/src/DesktopMagic/Plugins/PluginData.cs b/src/DesktopMagic/Plugins/PluginData.cs
new file mode 100644
index 0000000..57ab715
--- /dev/null
+++ b/src/DesktopMagic/Plugins/PluginData.cs
@@ -0,0 +1,35 @@
+using DesktopMagicPluginAPI;
+
+using System.Drawing;
+
+namespace DesktopMagic.Plugins
+{
+ internal class PluginData : IPluginData
+ {
+ private readonly PluginWindow window;
+
+ public PluginData(PluginWindow window)
+ {
+ this.window = window;
+ }
+
+ public string Font => Theme.Font;
+
+ public Color Color => Theme.PrimaryColor;
+
+ public ITheme Theme { get; } = MainWindow.Theme;
+
+ public Size WindowSize => new Size((int)window.ActualWidth, (int)window.ActualHeight);
+
+ public Point WindowPosition => new Point((int)window.Left, (int)window.Top);
+
+ public string PluginName => window.PluginName;
+
+ public string PluginPath => window.PluginFolderPath;
+
+ public void UpdateWindow()
+ {
+ window.UpdatePluginWindow();
+ }
+ }
+}
\ No newline at end of file
diff --git a/src/DesktopMagic/Plugin/PluginWindow.xaml b/src/DesktopMagic/Plugins/PluginWindow.xaml
similarity index 79%
rename from src/DesktopMagic/Plugin/PluginWindow.xaml
rename to src/DesktopMagic/Plugins/PluginWindow.xaml
index 2b39491..d2cd1b9 100644
--- a/src/DesktopMagic/Plugin/PluginWindow.xaml
+++ b/src/DesktopMagic/Plugins/PluginWindow.xaml
@@ -16,7 +16,12 @@
x:Name="window">
-
+
+
+
+
+
+
diff --git a/src/DesktopMagic/Plugin/PluginWindow.xaml.cs b/src/DesktopMagic/Plugins/PluginWindow.xaml.cs
similarity index 80%
rename from src/DesktopMagic/Plugin/PluginWindow.xaml.cs
rename to src/DesktopMagic/Plugins/PluginWindow.xaml.cs
index c86dbd0..8655936 100644
--- a/src/DesktopMagic/Plugin/PluginWindow.xaml.cs
+++ b/src/DesktopMagic/Plugins/PluginWindow.xaml.cs
@@ -1,4 +1,6 @@
-using DesktopMagicPluginAPI;
+using DesktopMagic.Plugins;
+
+using DesktopMagicPluginAPI;
using DesktopMagicPluginAPI.Drawing;
using DesktopMagicPluginAPI.Inputs;
@@ -20,10 +22,6 @@ using System.Windows.Media.Imaging;
namespace DesktopMagic
{
- ///
- /// Interaktionslogik für PluginWindow.xaml
- ///
- ///
public partial class PluginWindow : Window
{
private readonly RegistryKey key;
@@ -31,9 +29,10 @@ namespace DesktopMagic
private System.Timers.Timer valueTimer;
private Plugin pluginClassInstance;
+
+ public bool IsRunning { get; private set; } = true;
public string PluginName { get; private set; }
public string PluginFolderPath { get; private set; }
- private bool stop = false;
public event Action PluginLoaded;
@@ -59,7 +58,7 @@ namespace DesktopMagic
System.Timers.Timer t = new System.Timers.Timer();
t.Interval = 100;
- t.Elapsed += Elapsed;
+ t.Elapsed += UpdateTimer_Elapsed;
t.Start();
PluginName = pluginName;
@@ -71,13 +70,18 @@ namespace DesktopMagic
Width = double.Parse(key.GetValue(pluginName + "WindowWidth", 500).ToString());
}
+ public PluginWindow(Plugin pluginClassInstance, string pluginName) : this(pluginName)
+ {
+ this.pluginClassInstance = pluginClassInstance;
+ }
+
protected override void OnSourceInitialized(EventArgs e)
{
base.OnSourceInitialized(e);
//Set the window style to noactivate.
WindowInteropHelper helper = new(this);
- WindowPos.SetWindowLong(helper.Handle, WindowPos.GWL_EXSTYLE,
+ _ = WindowPos.SetWindowLong(helper.Handle, WindowPos.GWL_EXSTYLE,
WindowPos.GetWindowLong(helper.Handle, WindowPos.GWL_EXSTYLE) | WindowPos.WS_EX_NOACTIVATE);
}
@@ -95,7 +99,7 @@ namespace DesktopMagic
ValueTimer_Elapsed(valueTimer, null);
}
- private void Elapsed(object sender, ElapsedEventArgs e)
+ private void UpdateTimer_Elapsed(object sender, ElapsedEventArgs e)
{
Dispatcher.Invoke(() =>
{
@@ -113,22 +117,35 @@ namespace DesktopMagic
tileBar.CaptionHeight = 0;
ResizeMode = ResizeMode.NoResize;
}
- if (stop)
+
+ if (!IsRunning)
{
((System.Timers.Timer)sender).Stop();
}
+ else
+ {
+ viewBox.Margin = new Thickness(MainWindow.Theme.Margin);
+ border.Width = viewBox.ActualWidth + (MainWindow.Theme.Margin * 2);
+ border.Height = viewBox.ActualHeight + (MainWindow.Theme.Margin * 2);
+ rectangleGeometry.Rect = new Rect(-MainWindow.Theme.Margin, -MainWindow.Theme.Margin, border.ActualWidth, border.ActualHeight);
+ border.Background = MainWindow.Theme.BackgroundBrush;
+ border.CornerRadius = new CornerRadius(MainWindow.Theme.CornerRadius);
+ }
});
}
private void LoadPlugin()
{
- PluginFolderPath = $"{Environment.GetFolderPath(Environment.SpecialFolder.ApplicationData)}\\{App.AppName}\\Plugins\\{PluginName}";
-
- if (!File.Exists($"{PluginFolderPath}\\{PluginName}.dll"))
+ if (pluginClassInstance is null)
{
- _ = MessageBox.Show("File does not exist!", "Error", MessageBoxButton.OK, MessageBoxImage.Error);
- Exit();
- return;
+ PluginFolderPath = $"{Environment.GetFolderPath(Environment.SpecialFolder.ApplicationData)}\\{App.AppName}\\Plugins\\{PluginName}";
+
+ if (!File.Exists($"{PluginFolderPath}\\{PluginName}.dll"))
+ {
+ _ = MessageBox.Show("File does not exist!", "Error", MessageBoxButton.OK, MessageBoxImage.Error);
+ Exit();
+ return;
+ }
}
try
@@ -147,18 +164,22 @@ namespace DesktopMagic
private void ExecuteSource()
{
- byte[] assemblyBytes = File.ReadAllBytes($"{PluginFolderPath}\\{PluginName}.dll");
- Assembly dll = Assembly.Load(assemblyBytes);
- Type instanceType = dll.GetTypes().FirstOrDefault(type => type.GetTypeInfo().BaseType == typeof(Plugin));
-
- if (instanceType is null)
+ object instance = pluginClassInstance;
+ if (instance is null)
{
- _ = MessageBox.Show($"The \"Plugin\" class could not be found! It has to inherit from \"{typeof(Plugin).FullName}\"", "Error", MessageBoxButton.OK, MessageBoxImage.Error);
- Exit();
- return;
- }
+ byte[] assemblyBytes = File.ReadAllBytes($"{PluginFolderPath}\\{PluginName}.dll");
+ Assembly dll = Assembly.Load(assemblyBytes);
+ Type instanceType = dll.GetTypes().FirstOrDefault(type => type.GetTypeInfo().BaseType == typeof(Plugin));
- object instance = Activator.CreateInstance(instanceType);
+ if (instanceType is null)
+ {
+ _ = MessageBox.Show($"The \"Plugin\" class could not be found! It has to inherit from \"{typeof(Plugin).FullName}\"", "Error", MessageBoxButton.OK, MessageBoxImage.Error);
+ Exit();
+ return;
+ }
+
+ instance = Activator.CreateInstance(instanceType);
+ }
if (instance is Plugin)
{
pluginClassInstance = instance as Plugin;
@@ -198,10 +219,10 @@ namespace DesktopMagic
{
if (prop.GetValue(instance) is Element element)
{
- object[] attrs = prop.GetCustomAttributes(true);
- foreach (object attr in attrs)
+ object[] attributes = prop.GetCustomAttributes(true);
+ foreach (object attribute in attributes)
{
- if (attr is ElementAttribute elementAttribute)
+ if (attribute is ElementAttribute elementAttribute)
{
settingElements.Add(new SettingElement(element, elementAttribute.Name, elementAttribute.OrderIndex));
break;
@@ -222,7 +243,7 @@ namespace DesktopMagic
}
catch (Exception ex)
{
- stop = true;
+ IsRunning = false;
App.Logger.Log(ex.ToString(), "Plugin");
_ = MessageBox.Show("File execution error:\n" + ex, "Error", MessageBoxButton.OK, MessageBoxImage.Error);
Exit();
@@ -234,7 +255,7 @@ namespace DesktopMagic
{
try
{
- if (!stop)
+ if (IsRunning)
{
Bitmap result = pluginClassInstance.Main();
@@ -268,20 +289,20 @@ namespace DesktopMagic
}
catch (Exception ex)
{
- stop = true;
+ IsRunning = false;
App.Logger.Log(ex.ToString(), "Plugin");
_ = MessageBox.Show("File execution error:\n" + ex, "Error", MessageBoxButton.OK, MessageBoxImage.Error);
Exit();
return;
}
- if (stop)
+ if (!IsRunning)
{
valueTimer.Stop();
}
}
- private BitmapSource BitmapToImageSource(Bitmap bitmap)
+ private static BitmapSource BitmapToImageSource(Bitmap bitmap)
{
BitmapData bitmapData = bitmap.LockBits(
new Rectangle(0, 0, bitmap.Width, bitmap.Height),
@@ -290,7 +311,7 @@ namespace DesktopMagic
BitmapSource bitmapSource = BitmapSource.Create(
bitmapData.Width, bitmapData.Height,
bitmap.HorizontalResolution, bitmap.VerticalResolution,
- System.Windows.Media.PixelFormats.Bgra32, null,
+ PixelFormats.Bgra32, null,
bitmapData.Scan0, bitmapData.Stride * bitmapData.Height, bitmapData.Stride);
bitmap.UnlockBits(bitmapData);
@@ -299,13 +320,20 @@ namespace DesktopMagic
public void Exit()
{
- stop = true;
+ IsRunning = false;
+
Dispatcher.Invoke(() =>
{
OnExit?.Invoke();
});
}
+ private void Window_Closing(object sender, System.ComponentModel.CancelEventArgs e)
+ {
+ pluginClassInstance?.Stop();
+ IsRunning = false;
+ }
+
#region Window Events
private void Window_LocationChanged(object sender, EventArgs e)
@@ -321,11 +349,6 @@ namespace DesktopMagic
tileBar.CaptionHeight = ActualHeight - 10;
}
- private void Window_Closing(object sender, System.ComponentModel.CancelEventArgs e)
- {
- stop = true;
- }
-
private void Window_MouseDown(object sender, System.Windows.Input.MouseButtonEventArgs e)
{
ImageSource imageSource = image.Source;
diff --git a/src/DesktopMagic/Plugin/SettingElement.cs b/src/DesktopMagic/Plugins/SettingElement.cs
similarity index 73%
rename from src/DesktopMagic/Plugin/SettingElement.cs
rename to src/DesktopMagic/Plugins/SettingElement.cs
index 315c659..37c9898 100644
--- a/src/DesktopMagic/Plugin/SettingElement.cs
+++ b/src/DesktopMagic/Plugins/SettingElement.cs
@@ -1,11 +1,6 @@
using DesktopMagicPluginAPI.Inputs;
-using System;
-using System.Collections.Generic;
-using System.Linq;
-using System.Text;
-using System.Threading.Tasks;
-namespace DesktopMagic
+namespace DesktopMagic.Plugins
{
internal class SettingElement
{
diff --git a/src/DesktopMagic/Plugins/Theme.cs b/src/DesktopMagic/Plugins/Theme.cs
new file mode 100644
index 0000000..23d74bd
--- /dev/null
+++ b/src/DesktopMagic/Plugins/Theme.cs
@@ -0,0 +1,21 @@
+using DesktopMagicPluginAPI;
+
+using System.Drawing;
+
+namespace DesktopMagic.Plugins
+{
+ internal class Theme : ITheme
+ {
+ public Color PrimaryColor { get; set; } = Color.White;
+ public Color SecondaryColor { get; set; } = Color.White;
+ public Color BackgroundColor { get; set; } = Color.Transparent;
+
+ public string Font { get; set; } = "Segoe UI";
+ public int CornerRadius { get; set; }
+ public int Margin { get; set; }
+
+ public System.Windows.Media.Brush PrimaryBrush { get; set; } = System.Windows.Media.Brushes.White;
+ public System.Windows.Media.Brush SecondaryBrush { get; set; } = System.Windows.Media.Brushes.White;
+ public System.Windows.Media.Brush BackgroundBrush { get; set; } = System.Windows.Media.Brushes.Transparent;
+ }
+}
\ No newline at end of file
diff --git a/src/DesktopMagic/Resources/StringResources.de.xaml b/src/DesktopMagic/Resources/StringResources.de.xaml
index 97c3d66..4d38a99 100644
--- a/src/DesktopMagic/Resources/StringResources.de.xaml
+++ b/src/DesktopMagic/Resources/StringResources.de.xaml
@@ -3,8 +3,8 @@
xmlns:col="clr-namespace:System.Collections;assembly=mscorlib"
xmlns:system="clr-namespace:System;assembly=mscorlib">
- Linie
- Spiegeln
+ Linie
+ Spiegeln
Plugins Neu Laden
Plugins Ordner Öffnen
Plugins Herunterladen
diff --git a/src/DesktopMagic/Resources/StringResources.en.xaml b/src/DesktopMagic/Resources/StringResources.en.xaml
index 8220783..8935929 100644
--- a/src/DesktopMagic/Resources/StringResources.en.xaml
+++ b/src/DesktopMagic/Resources/StringResources.en.xaml
@@ -3,8 +3,8 @@
xmlns:col="clr-namespace:System.Collections;assembly=mscorlib"
xmlns:system="clr-namespace:System;assembly=mscorlib">
- Line
- Mirror
+ Line
+ Mirror
Reload Plugins
Open Plugins Folder
Download Plugins
diff --git a/src/DesktopMagic/TimeWindow.xaml b/src/DesktopMagic/TimeWindow.xaml
deleted file mode 100644
index c69bf64..0000000
--- a/src/DesktopMagic/TimeWindow.xaml
+++ /dev/null
@@ -1,23 +0,0 @@
-
-
-
-
-
-
-
-
-
-
-
\ No newline at end of file
diff --git a/src/DesktopMagic/TimeWindow.xaml.cs b/src/DesktopMagic/TimeWindow.xaml.cs
deleted file mode 100644
index 4713c08..0000000
--- a/src/DesktopMagic/TimeWindow.xaml.cs
+++ /dev/null
@@ -1,92 +0,0 @@
-using Microsoft.Win32;
-
-using System;
-using System.Timers;
-using System.Windows;
-using System.Windows.Interop;
-using System.Windows.Media;
-
-namespace DesktopMagic
-{
- ///
- /// Interaktionslogik für TimeWindow.xaml
- ///
- public partial class TimeWindow : Window
- {
- private RegistryKey key;
-
- public TimeWindow()
- {
- InitializeComponent();
-
- Window w = new Window();
- w.Top = -100;
- w.Left = -100;
- w.Width = 0;
- w.Height = 0;
-
- w.WindowStyle = WindowStyle.ToolWindow;
- w.ShowInTaskbar = false;
- w.Show();
- Owner = w;
- w.Hide();
-
- Timer t = new Timer();
- t.Interval = 100;
- t.Elapsed += T_Elapsed;
- t.Start();
-
- key = Registry.CurrentUser.CreateSubKey(@"Software\" + App.AppName);
- Top = double.Parse(key.GetValue("TimeWindowTop", 100).ToString());
- Left = double.Parse(key.GetValue("TimeWindowLeft", 100).ToString());
- Height = double.Parse(key.GetValue("TimeWindowHeight", 200).ToString());
- Width = double.Parse(key.GetValue("TimeWindowWidth", 500).ToString());
- IsEnabled = false;
- }
-
- protected override void OnSourceInitialized(EventArgs e)
- {
- base.OnSourceInitialized(e);
-
- //Set the window style to noactivate.
- WindowInteropHelper helper = new WindowInteropHelper(this);
- WindowPos.SetWindowLong(helper.Handle, WindowPos.GWL_EXSTYLE,
- WindowPos.GetWindowLong(helper.Handle, WindowPos.GWL_EXSTYLE) | WindowPos.WS_EX_NOACTIVATE);
- }
-
- private void T_Elapsed(object sender, ElapsedEventArgs e)
- {
- Dispatcher.Invoke(() =>
- {
- if (MainWindow.EditMode)
- {
- panel.Visibility = Visibility.Visible;
- WindowPos.SetIsLocked(this, false);
- }
- else
- {
- panel.Visibility = Visibility.Collapsed;
- WindowPos.SetIsLocked(this, true);
- }
-
- textBlock.FontFamily = new FontFamily(MainWindow.GlobalFont);
- textBlock.Foreground = MainWindow.GlobalColor;
- //textBlock.Text = DateTime.Now.ToString("hh:mm:ss tt");
- textBlock.Text = DateTime.Now.ToString("HH:mm:ss");
- });
- }
-
- private void Window_LocationChanged(object sender, EventArgs e)
- {
- key.SetValue("TimeWindowTop", Top);
- key.SetValue("TimeWindowLeft", Left);
- }
-
- private void Window_SizeChanged(object sender, SizeChangedEventArgs e)
- {
- key.SetValue("TimeWindowHeight", Height);
- key.SetValue("TimeWindowWidth", Width);
- tileBar.CaptionHeight = ActualHeight - 10;
- }
- }
-}
\ No newline at end of file
diff --git a/src/DesktopMagicPlugin.Test/PluginScript.cs b/src/DesktopMagicPlugin.Test/PluginScript.cs
index 9bec824..5dccb5e 100644
--- a/src/DesktopMagicPlugin.Test/PluginScript.cs
+++ b/src/DesktopMagicPlugin.Test/PluginScript.cs
@@ -1,11 +1,12 @@
using DesktopMagicPluginAPI;
using DesktopMagicPluginAPI.Inputs;
+
+using System;
+using System.Collections.Generic;
using System.Drawing;
using System.Drawing.Imaging;
using System.IO;
-using System.Collections.Generic;
using System.Threading.Tasks;
-using System;
namespace DesktopMagicPlugin.Test
{
@@ -71,12 +72,16 @@ namespace DesktopMagicPlugin.Test
public override Bitmap Main()
{
if (bitmaps.Count == 0)
+ {
return new Bitmap(1, 1);
+ }
frameCount++;
if (frameCount >= bitmaps.Count)
+ {
frameCount = 0;
+ }
return bitmaps[frameCount];
}
diff --git a/src/DesktopMagicPluginAPI/DesktopMagicPluginAPI.csproj b/src/DesktopMagicPluginAPI/DesktopMagicPluginAPI.csproj
index b428bd2..bbf3af1 100644
--- a/src/DesktopMagicPluginAPI/DesktopMagicPluginAPI.csproj
+++ b/src/DesktopMagicPluginAPI/DesktopMagicPluginAPI.csproj
@@ -4,13 +4,13 @@
net5.0
Stone_Red
Stone_Red
- 0.0.0.4
+ 0.0.0.5
https://github.com/Stone-Red-Code/DesktopMagic
LICENSE
true
- 0.0.0.4
+ 0.0.0.5
- 0.0.0.4
+ 0.0.0.5
diff --git a/src/DesktopMagicPluginAPI/DesktopMagicPluginAPI.md b/src/DesktopMagicPluginAPI/DesktopMagicPluginAPI.md
index 7acedab..1326acc 100644
--- a/src/DesktopMagicPluginAPI/DesktopMagicPluginAPI.md
+++ b/src/DesktopMagicPluginAPI/DesktopMagicPluginAPI.md
@@ -10,6 +10,10 @@
- [CheckBox](#T-DesktopMagicPluginAPI-Inputs-CheckBox 'DesktopMagicPluginAPI.Inputs.CheckBox')
- [#ctor(value)](#M-DesktopMagicPluginAPI-Inputs-CheckBox-#ctor-System-Boolean- 'DesktopMagicPluginAPI.Inputs.CheckBox.#ctor(System.Boolean)')
- [Value](#P-DesktopMagicPluginAPI-Inputs-CheckBox-Value 'DesktopMagicPluginAPI.Inputs.CheckBox.Value')
+- [ComboBox](#T-DesktopMagicPluginAPI-Inputs-ComboBox 'DesktopMagicPluginAPI.Inputs.ComboBox')
+ - [#ctor(items)](#M-DesktopMagicPluginAPI-Inputs-ComboBox-#ctor-System-String[]- 'DesktopMagicPluginAPI.Inputs.ComboBox.#ctor(System.String[])')
+ - [Items](#P-DesktopMagicPluginAPI-Inputs-ComboBox-Items 'DesktopMagicPluginAPI.Inputs.ComboBox.Items')
+ - [Value](#P-DesktopMagicPluginAPI-Inputs-ComboBox-Value 'DesktopMagicPluginAPI.Inputs.ComboBox.Value')
- [Element](#T-DesktopMagicPluginAPI-Inputs-Element 'DesktopMagicPluginAPI.Inputs.Element')
- [ValueChanged()](#M-DesktopMagicPluginAPI-Inputs-Element-ValueChanged 'DesktopMagicPluginAPI.Inputs.Element.ValueChanged')
- [ElementAttribute](#T-DesktopMagicPluginAPI-Inputs-ElementAttribute 'DesktopMagicPluginAPI.Inputs.ElementAttribute')
@@ -23,14 +27,25 @@
- [DrawStringFixedWidth(graphics,s,font,brush,point,width)](#M-DesktopMagicPluginAPI-Drawing-GraphicsExtentions-DrawStringFixedWidth-System-Drawing-Graphics,System-String,System-Drawing-Font,System-Drawing-Brush,System-Drawing-PointF,System-Single- 'DesktopMagicPluginAPI.Drawing.GraphicsExtentions.DrawStringFixedWidth(System.Drawing.Graphics,System.String,System.Drawing.Font,System.Drawing.Brush,System.Drawing.PointF,System.Single)')
- [DrawStringMonospace(graphics,s,font,brush,x,y)](#M-DesktopMagicPluginAPI-Drawing-GraphicsExtentions-DrawStringMonospace-System-Drawing-Graphics,System-String,System-Drawing-Font,System-Drawing-Brush,System-Single,System-Single- 'DesktopMagicPluginAPI.Drawing.GraphicsExtentions.DrawStringMonospace(System.Drawing.Graphics,System.String,System.Drawing.Font,System.Drawing.Brush,System.Single,System.Single)')
- [DrawStringMonospace(graphics,s,font,brush,point)](#M-DesktopMagicPluginAPI-Drawing-GraphicsExtentions-DrawStringMonospace-System-Drawing-Graphics,System-String,System-Drawing-Font,System-Drawing-Brush,System-Drawing-PointF- 'DesktopMagicPluginAPI.Drawing.GraphicsExtentions.DrawStringMonospace(System.Drawing.Graphics,System.String,System.Drawing.Font,System.Drawing.Brush,System.Drawing.PointF)')
+ - [DrawStringNoLeftPadding(graphics,s,font,brush,x,y)](#M-DesktopMagicPluginAPI-Drawing-GraphicsExtentions-DrawStringNoLeftPadding-System-Drawing-Graphics,System-String,System-Drawing-Font,System-Drawing-Brush,System-Single,System-Single- 'DesktopMagicPluginAPI.Drawing.GraphicsExtentions.DrawStringNoLeftPadding(System.Drawing.Graphics,System.String,System.Drawing.Font,System.Drawing.Brush,System.Single,System.Single)')
+ - [DrawStringNoLeftPadding(graphics,s,font,brush,point)](#M-DesktopMagicPluginAPI-Drawing-GraphicsExtentions-DrawStringNoLeftPadding-System-Drawing-Graphics,System-String,System-Drawing-Font,System-Drawing-Brush,System-Drawing-PointF- 'DesktopMagicPluginAPI.Drawing.GraphicsExtentions.DrawStringNoLeftPadding(System.Drawing.Graphics,System.String,System.Drawing.Font,System.Drawing.Brush,System.Drawing.PointF)')
+ - [MeasureStringNoLeftPadding(graphics,text,font)](#M-DesktopMagicPluginAPI-Drawing-GraphicsExtentions-MeasureStringNoLeftPadding-System-Drawing-Graphics,System-String,System-Drawing-Font- 'DesktopMagicPluginAPI.Drawing.GraphicsExtentions.MeasureStringNoLeftPadding(System.Drawing.Graphics,System.String,System.Drawing.Font)')
- [IPluginData](#T-DesktopMagicPluginAPI-IPluginData 'DesktopMagicPluginAPI.IPluginData')
- [Color](#P-DesktopMagicPluginAPI-IPluginData-Color 'DesktopMagicPluginAPI.IPluginData.Color')
- [Font](#P-DesktopMagicPluginAPI-IPluginData-Font 'DesktopMagicPluginAPI.IPluginData.Font')
- [PluginName](#P-DesktopMagicPluginAPI-IPluginData-PluginName 'DesktopMagicPluginAPI.IPluginData.PluginName')
- [PluginPath](#P-DesktopMagicPluginAPI-IPluginData-PluginPath 'DesktopMagicPluginAPI.IPluginData.PluginPath')
+ - [Theme](#P-DesktopMagicPluginAPI-IPluginData-Theme 'DesktopMagicPluginAPI.IPluginData.Theme')
- [WindowPosition](#P-DesktopMagicPluginAPI-IPluginData-WindowPosition 'DesktopMagicPluginAPI.IPluginData.WindowPosition')
- [WindowSize](#P-DesktopMagicPluginAPI-IPluginData-WindowSize 'DesktopMagicPluginAPI.IPluginData.WindowSize')
- [UpdateWindow()](#M-DesktopMagicPluginAPI-IPluginData-UpdateWindow 'DesktopMagicPluginAPI.IPluginData.UpdateWindow')
+- [ITheme](#T-DesktopMagicPluginAPI-ITheme 'DesktopMagicPluginAPI.ITheme')
+ - [BackgroundColor](#P-DesktopMagicPluginAPI-ITheme-BackgroundColor 'DesktopMagicPluginAPI.ITheme.BackgroundColor')
+ - [CornerRadius](#P-DesktopMagicPluginAPI-ITheme-CornerRadius 'DesktopMagicPluginAPI.ITheme.CornerRadius')
+ - [Font](#P-DesktopMagicPluginAPI-ITheme-Font 'DesktopMagicPluginAPI.ITheme.Font')
+ - [Margin](#P-DesktopMagicPluginAPI-ITheme-Margin 'DesktopMagicPluginAPI.ITheme.Margin')
+ - [PrimaryColor](#P-DesktopMagicPluginAPI-ITheme-PrimaryColor 'DesktopMagicPluginAPI.ITheme.PrimaryColor')
+ - [SecondaryColor](#P-DesktopMagicPluginAPI-ITheme-SecondaryColor 'DesktopMagicPluginAPI.ITheme.SecondaryColor')
- [IntegerUpDown](#T-DesktopMagicPluginAPI-Inputs-IntegerUpDown 'DesktopMagicPluginAPI.Inputs.IntegerUpDown')
- [#ctor(min,max,value)](#M-DesktopMagicPluginAPI-Inputs-IntegerUpDown-#ctor-System-Int32,System-Int32,System-Int32- 'DesktopMagicPluginAPI.Inputs.IntegerUpDown.#ctor(System.Int32,System.Int32,System.Int32)')
- [Maximum](#P-DesktopMagicPluginAPI-Inputs-IntegerUpDown-Maximum 'DesktopMagicPluginAPI.Inputs.IntegerUpDown.Maximum')
@@ -51,8 +66,9 @@
- [Main()](#M-DesktopMagicPluginAPI-Plugin-Main 'DesktopMagicPluginAPI.Plugin.Main')
- [OnMouseClick(position,mouseButton)](#M-DesktopMagicPluginAPI-Plugin-OnMouseClick-System-Drawing-Point,DesktopMagicPluginAPI-Inputs-MouseButton- 'DesktopMagicPluginAPI.Plugin.OnMouseClick(System.Drawing.Point,DesktopMagicPluginAPI.Inputs.MouseButton)')
- [OnMouseMove(position)](#M-DesktopMagicPluginAPI-Plugin-OnMouseMove-System-Drawing-Point- 'DesktopMagicPluginAPI.Plugin.OnMouseMove(System.Drawing.Point)')
- - [OnMouseWheel(position,Delta)](#M-DesktopMagicPluginAPI-Plugin-OnMouseWheel-System-Drawing-Point,System-Int32- 'DesktopMagicPluginAPI.Plugin.OnMouseWheel(System.Drawing.Point,System.Int32)')
+ - [OnMouseWheel(position,delta)](#M-DesktopMagicPluginAPI-Plugin-OnMouseWheel-System-Drawing-Point,System-Int32- 'DesktopMagicPluginAPI.Plugin.OnMouseWheel(System.Drawing.Point,System.Int32)')
- [Start()](#M-DesktopMagicPluginAPI-Plugin-Start 'DesktopMagicPluginAPI.Plugin.Start')
+ - [Stop()](#M-DesktopMagicPluginAPI-Plugin-Stop 'DesktopMagicPluginAPI.Plugin.Stop')
- [RenderQuality](#T-DesktopMagicPluginAPI-Drawing-RenderQuality 'DesktopMagicPluginAPI.Drawing.RenderQuality')
- [High](#F-DesktopMagicPluginAPI-Drawing-RenderQuality-High 'DesktopMagicPluginAPI.Drawing.RenderQuality.High')
- [Low](#F-DesktopMagicPluginAPI-Drawing-RenderQuality-Low 'DesktopMagicPluginAPI.Drawing.RenderQuality.Low')
@@ -139,6 +155,48 @@ Initializes a new instance of the [CheckBox](#T-DesktopMagicPluginAPI-Inputs-Che
Gets or set a value indicating whether the [CheckBox](#T-DesktopMagicPluginAPI-Inputs-CheckBox 'DesktopMagicPluginAPI.Inputs.CheckBox') is in the checked state.
+
+## ComboBox `type`
+
+##### Namespace
+
+DesktopMagicPluginAPI.Inputs
+
+##### Summary
+
+Represents a selection control with a drop-down list.
+
+
+### #ctor(items) `constructor`
+
+##### Summary
+
+Initializes a new instance of the [Label](#T-DesktopMagicPluginAPI-Inputs-Label 'DesktopMagicPluginAPI.Inputs.Label') class with the provided `items`.
+
+##### Parameters
+
+| Name | Type | Description |
+| ---- | ---- | ----------- |
+| items | [System.String[]](http://msdn.microsoft.com/query/dev14.query?appId=Dev14IDEF1&l=EN-US&k=k:System.String[] 'System.String[]') | |
+
+
+### Items `property`
+
+##### Summary
+
+Gets the collection used to generate the content of the [ComboBox](#T-DesktopMagicPluginAPI-Inputs-ComboBox 'DesktopMagicPluginAPI.Inputs.ComboBox').
+
+
+### Value `property`
+
+##### Summary
+
+Gets the currently selected item associated with this [ComboBox](#T-DesktopMagicPluginAPI-Inputs-ComboBox 'DesktopMagicPluginAPI.Inputs.ComboBox').
+
+##### Remarks
+
+If you assign a value to this property, the displayed text in the user interface will not be changed.
+
## Element `type`
@@ -233,14 +291,14 @@ DesktopMagicPluginAPI.Drawing
##### Summary
-Extentions for the [Graphics](http://msdn.microsoft.com/query/dev14.query?appId=Dev14IDEF1&l=EN-US&k=k:System.Drawing.Graphics 'System.Drawing.Graphics') class.
+Extensions for the [Graphics](http://msdn.microsoft.com/query/dev14.query?appId=Dev14IDEF1&l=EN-US&k=k:System.Drawing.Graphics 'System.Drawing.Graphics') class.
### DrawStringFixedWidth(graphics,s,font,brush,x,y,width) `method`
##### Summary
-Draws the specified text string at the specified location with the specified [Brush](http://msdn.microsoft.com/query/dev14.query?appId=Dev14IDEF1&l=EN-US&k=k:System.Drawing.Brush 'System.Drawing.Brush') and [Font](http://msdn.microsoft.com/query/dev14.query?appId=Dev14IDEF1&l=EN-US&k=k:System.Drawing.Font 'System.Drawing.Font') objects.
+
##### Parameters
@@ -259,7 +317,7 @@ Draws the specified text string at the specified location with the specified [Br
##### Summary
-Draws the specified text string at the specified location with the specified [Brush](http://msdn.microsoft.com/query/dev14.query?appId=Dev14IDEF1&l=EN-US&k=k:System.Drawing.Brush 'System.Drawing.Brush') and [Font](http://msdn.microsoft.com/query/dev14.query?appId=Dev14IDEF1&l=EN-US&k=k:System.Drawing.Font 'System.Drawing.Font') objects.
+
##### Parameters
@@ -277,7 +335,7 @@ Draws the specified text string at the specified location with the specified [Br
##### Summary
-Draws the specified text string at the specified location with the specified [Brush](http://msdn.microsoft.com/query/dev14.query?appId=Dev14IDEF1&l=EN-US&k=k:System.Drawing.Brush 'System.Drawing.Brush') and [Font](http://msdn.microsoft.com/query/dev14.query?appId=Dev14IDEF1&l=EN-US&k=k:System.Drawing.Font 'System.Drawing.Font') objects.
+
##### Parameters
@@ -295,7 +353,7 @@ Draws the specified text string at the specified location with the specified [Br
##### Summary
-Draws the specified text string at the specified location with the specified [Brush](http://msdn.microsoft.com/query/dev14.query?appId=Dev14IDEF1&l=EN-US&k=k:System.Drawing.Brush 'System.Drawing.Brush') and [Font](http://msdn.microsoft.com/query/dev14.query?appId=Dev14IDEF1&l=EN-US&k=k:System.Drawing.Font 'System.Drawing.Font') objects.
+
##### Parameters
@@ -307,6 +365,60 @@ Draws the specified text string at the specified location with the specified [Br
| brush | [System.Drawing.Brush](http://msdn.microsoft.com/query/dev14.query?appId=Dev14IDEF1&l=EN-US&k=k:System.Drawing.Brush 'System.Drawing.Brush') | [Brush](http://msdn.microsoft.com/query/dev14.query?appId=Dev14IDEF1&l=EN-US&k=k:System.Drawing.Brush 'System.Drawing.Brush') that determines the color and texture of the drawn text. |
| point | [System.Drawing.PointF](http://msdn.microsoft.com/query/dev14.query?appId=Dev14IDEF1&l=EN-US&k=k:System.Drawing.PointF 'System.Drawing.PointF') | [PointF](http://msdn.microsoft.com/query/dev14.query?appId=Dev14IDEF1&l=EN-US&k=k:System.Drawing.PointF 'System.Drawing.PointF') structure that specifies the upper-left corner of the drawn text. |
+
+### DrawStringNoLeftPadding(graphics,s,font,brush,x,y) `method`
+
+##### Summary
+
+
+
+##### Parameters
+
+| Name | Type | Description |
+| ---- | ---- | ----------- |
+| graphics | [System.Drawing.Graphics](http://msdn.microsoft.com/query/dev14.query?appId=Dev14IDEF1&l=EN-US&k=k:System.Drawing.Graphics 'System.Drawing.Graphics') | Graphics object. |
+| s | [System.String](http://msdn.microsoft.com/query/dev14.query?appId=Dev14IDEF1&l=EN-US&k=k:System.String 'System.String') | String to draw. |
+| font | [System.Drawing.Font](http://msdn.microsoft.com/query/dev14.query?appId=Dev14IDEF1&l=EN-US&k=k:System.Drawing.Font 'System.Drawing.Font') | [Font](http://msdn.microsoft.com/query/dev14.query?appId=Dev14IDEF1&l=EN-US&k=k:System.Drawing.Font 'System.Drawing.Font') that defines the text format of the string. |
+| brush | [System.Drawing.Brush](http://msdn.microsoft.com/query/dev14.query?appId=Dev14IDEF1&l=EN-US&k=k:System.Drawing.Brush 'System.Drawing.Brush') | [Brush](http://msdn.microsoft.com/query/dev14.query?appId=Dev14IDEF1&l=EN-US&k=k:System.Drawing.Brush 'System.Drawing.Brush') that determines the color and texture of the drawn text. |
+| x | [System.Single](http://msdn.microsoft.com/query/dev14.query?appId=Dev14IDEF1&l=EN-US&k=k:System.Single 'System.Single') | The x-coordinate of the upper-left corner of the drawn text. |
+| y | [System.Single](http://msdn.microsoft.com/query/dev14.query?appId=Dev14IDEF1&l=EN-US&k=k:System.Single 'System.Single') | The y-coordinate of the upper-left corner of the drawn text. |
+
+
+### DrawStringNoLeftPadding(graphics,s,font,brush,point) `method`
+
+##### Summary
+
+
+
+##### Parameters
+
+| Name | Type | Description |
+| ---- | ---- | ----------- |
+| graphics | [System.Drawing.Graphics](http://msdn.microsoft.com/query/dev14.query?appId=Dev14IDEF1&l=EN-US&k=k:System.Drawing.Graphics 'System.Drawing.Graphics') | Graphics object. |
+| s | [System.String](http://msdn.microsoft.com/query/dev14.query?appId=Dev14IDEF1&l=EN-US&k=k:System.String 'System.String') | String to draw. |
+| font | [System.Drawing.Font](http://msdn.microsoft.com/query/dev14.query?appId=Dev14IDEF1&l=EN-US&k=k:System.Drawing.Font 'System.Drawing.Font') | [Font](http://msdn.microsoft.com/query/dev14.query?appId=Dev14IDEF1&l=EN-US&k=k:System.Drawing.Font 'System.Drawing.Font') that defines the text format of the string. |
+| brush | [System.Drawing.Brush](http://msdn.microsoft.com/query/dev14.query?appId=Dev14IDEF1&l=EN-US&k=k:System.Drawing.Brush 'System.Drawing.Brush') | [Brush](http://msdn.microsoft.com/query/dev14.query?appId=Dev14IDEF1&l=EN-US&k=k:System.Drawing.Brush 'System.Drawing.Brush') that determines the color and texture of the drawn text. |
+| point | [System.Drawing.PointF](http://msdn.microsoft.com/query/dev14.query?appId=Dev14IDEF1&l=EN-US&k=k:System.Drawing.PointF 'System.Drawing.PointF') | [PointF](http://msdn.microsoft.com/query/dev14.query?appId=Dev14IDEF1&l=EN-US&k=k:System.Drawing.PointF 'System.Drawing.PointF') structure that specifies the upper-left corner of the drawn text. |
+
+
+### MeasureStringNoLeftPadding(graphics,text,font) `method`
+
+##### Summary
+
+
+
+##### Returns
+
+
+
+##### Parameters
+
+| Name | Type | Description |
+| ---- | ---- | ----------- |
+| graphics | [System.Drawing.Graphics](http://msdn.microsoft.com/query/dev14.query?appId=Dev14IDEF1&l=EN-US&k=k:System.Drawing.Graphics 'System.Drawing.Graphics') | Graphics object. |
+| text | [System.String](http://msdn.microsoft.com/query/dev14.query?appId=Dev14IDEF1&l=EN-US&k=k:System.String 'System.String') | String to measure. |
+| font | [System.Drawing.Font](http://msdn.microsoft.com/query/dev14.query?appId=Dev14IDEF1&l=EN-US&k=k:System.Drawing.Font 'System.Drawing.Font') | [Font](http://msdn.microsoft.com/query/dev14.query?appId=Dev14IDEF1&l=EN-US&k=k:System.Drawing.Font 'System.Drawing.Font') that defines the text format of the string. |
+
## IPluginData `type`
@@ -323,14 +435,14 @@ Defines properties and methods that provide information about the main applicati
##### Summary
-Gets the color of the main application.
+Gets the current color of the current theme.
### Font `property`
##### Summary
-Gets the font of the main application.
+Gets the current font of the current theme.
### PluginName `property`
@@ -346,6 +458,13 @@ Gets the name of the plugin.
Gets the path of the parent directory of the plugin.
+
+### Theme `property`
+
+##### Summary
+
+Gets the current theme setting of the main application.
+
### WindowPosition `property`
@@ -371,6 +490,59 @@ Updates the plugin window.
This method has no parameters.
+
+## ITheme `type`
+
+##### Namespace
+
+DesktopMagicPluginAPI
+
+##### Summary
+
+The theme settings of the main application.
+
+
+### BackgroundColor `property`
+
+##### Summary
+
+Gets the background color of the current theme.
+
+
+### CornerRadius `property`
+
+##### Summary
+
+Gets the corner radius of the current theme.
+
+
+### Font `property`
+
+##### Summary
+
+Gets the font of the current theme.
+
+
+### Margin `property`
+
+##### Summary
+
+Gets the corner radius of the current theme.
+
+
+### PrimaryColor `property`
+
+##### Summary
+
+Gets the primary color of the current theme.
+
+
+### SecondaryColor `property`
+
+##### Summary
+
+Gets the secondary color of the current theme.
+
## IntegerUpDown `type`
@@ -570,7 +742,7 @@ Occurs when the mouse pointer is moved over the control.
| position | [System.Drawing.Point](http://msdn.microsoft.com/query/dev14.query?appId=Dev14IDEF1&l=EN-US&k=k:System.Drawing.Point 'System.Drawing.Point') | The x- and y-coordinates of the mouse pointer position relative to the plugin window. |
-### OnMouseWheel(position,Delta) `method`
+### OnMouseWheel(position,delta) `method`
##### Summary
@@ -581,14 +753,25 @@ Occurs when the user rotates the mouse wheel while the mouse pointer is over thi
| Name | Type | Description |
| ---- | ---- | ----------- |
| position | [System.Drawing.Point](http://msdn.microsoft.com/query/dev14.query?appId=Dev14IDEF1&l=EN-US&k=k:System.Drawing.Point 'System.Drawing.Point') | The x- and y-coordinates of the mouse pointer position relative to the plugin window. |
-| Delta | [System.Int32](http://msdn.microsoft.com/query/dev14.query?appId=Dev14IDEF1&l=EN-US&k=k:System.Int32 'System.Int32') | A value that indicates the amount that the mouse wheel has changed. |
+| delta | [System.Int32](http://msdn.microsoft.com/query/dev14.query?appId=Dev14IDEF1&l=EN-US&k=k:System.Int32 'System.Int32') | A value that indicates the amount that the mouse wheel has changed. |
### Start() `method`
##### Summary
-Occurs once when the pugin gets activated.
+Occurs once when the plugin gets activated.
+
+##### Parameters
+
+This method has no parameters.
+
+
+### Stop() `method`
+
+##### Summary
+
+Occurs once when the plugin gets deactivated.
##### Parameters
diff --git a/src/DesktopMagicPluginAPI/DesktopMagicPluginAPI.xml b/src/DesktopMagicPluginAPI/DesktopMagicPluginAPI.xml
index 2974b49..e11ef9c 100644
--- a/src/DesktopMagicPluginAPI/DesktopMagicPluginAPI.xml
+++ b/src/DesktopMagicPluginAPI/DesktopMagicPluginAPI.xml
@@ -6,12 +6,12 @@
- Extentions for the class.
+ Extensions for the class.
- Draws the specified text string at the specified location with the specified and objects.
+
Graphics object.
String to draw.
@@ -22,7 +22,7 @@
- Draws the specified text string at the specified location with the specified and objects.
+
Graphics object.
String to draw.
@@ -32,7 +32,7 @@
- Draws the specified text string at the specified location with the specified and objects.
+
Graphics object.
String to draw.
@@ -44,7 +44,7 @@
- Draws the specified text string at the specified location with the specified and objects.
+
Graphics object.
String to draw.
@@ -53,6 +53,36 @@
structure that specifies the upper-left corner of the drawn text.
The specified width.
+
+
+
+
+ Graphics object.
+ String to draw.
+ that defines the text format of the string.
+ that determines the color and texture of the drawn text.
+ The x-coordinate of the upper-left corner of the drawn text.
+ The y-coordinate of the upper-left corner of the drawn text.
+
+
+
+
+
+ Graphics object.
+ String to draw.
+ that defines the text format of the string.
+ that determines the color and texture of the drawn text.
+ structure that specifies the upper-left corner of the drawn text.
+
+
+
+
+
+ Graphics object.
+ String to measure.
+ that defines the text format of the string.
+
+
Specifies which render quality is used to display the bitmap images.
@@ -115,6 +145,28 @@
A value indicating whether the is in the checked state.
+
+
+ Represents a selection control with a drop-down list.
+
+
+
+
+ Gets the collection used to generate the content of the .
+
+
+
+
+ Gets the currently selected item associated with this .
+
+ If you assign a value to this property, the displayed text in the user interface will not be changed.
+
+
+
+ Initializes a new instance of the class with the provided .
+
+
+
The element base class.
@@ -283,12 +335,17 @@
- Gets the font of the main application.
+ Gets the current font of the current theme.
- Gets the color of the main application.
+ Gets the current color of the current theme.
+
+
+
+
+ Gets the current theme setting of the main application.
@@ -316,6 +373,41 @@
Updates the plugin window.
+
+
+ The theme settings of the main application.
+
+
+
+
+ Gets the primary color of the current theme.
+
+
+
+
+ Gets the secondary color of the current theme.
+
+
+
+
+ Gets the background color of the current theme.
+
+
+
+
+ Gets the font of the current theme.
+
+
+
+
+ Gets the corner radius of the current theme.
+
+
+
+
+ Gets the corner radius of the current theme.
+
+
The plugin class.
@@ -338,7 +430,12 @@
- Occurs once when the pugin gets activated.
+ Occurs once when the plugin gets activated.
+
+
+
+
+ Occurs once when the plugin gets deactivated.
@@ -365,7 +462,7 @@
Occurs when the user rotates the mouse wheel while the mouse pointer is over this element.
The x- and y-coordinates of the mouse pointer position relative to the plugin window.
- A value that indicates the amount that the mouse wheel has changed.
+ A value that indicates the amount that the mouse wheel has changed.
diff --git a/src/DesktopMagicPluginAPI/Drawing/GraphicsExtentions.cs b/src/DesktopMagicPluginAPI/Drawing/GraphicsExtentions.cs
index af38757..a984bb4 100644
--- a/src/DesktopMagicPluginAPI/Drawing/GraphicsExtentions.cs
+++ b/src/DesktopMagicPluginAPI/Drawing/GraphicsExtentions.cs
@@ -5,14 +5,14 @@ using System.Drawing;
namespace DesktopMagicPluginAPI.Drawing
{
///
- /// Extentions for the class.
+ /// Extensions for the class.
///
public static class GraphicsExtentions
{
private static readonly Dictionary fonts = new Dictionary(new FontComparer());
///
- /// Draws the specified text string at the specified location with the specified and objects.
+ ///
///
/// Graphics object.
/// String to draw.
@@ -22,7 +22,7 @@ namespace DesktopMagicPluginAPI.Drawing
/// The y-coordinate of the upper-left corner of the drawn text.
public static void DrawStringMonospace(this Graphics graphics, string s, Font font, Brush brush, float x, float y)
{
- int widest = GetWidestChar(font);
+ int widest = graphics.GetWidestChar(font);
for (int i = 0; i < s.Length; i++)
{
@@ -33,7 +33,7 @@ namespace DesktopMagicPluginAPI.Drawing
}
///
- /// Draws the specified text string at the specified location with the specified and objects.
+ ///
///
/// Graphics object.
/// String to draw.
@@ -42,7 +42,7 @@ namespace DesktopMagicPluginAPI.Drawing
/// structure that specifies the upper-left corner of the drawn text.
public static void DrawStringMonospace(this Graphics graphics, string s, Font font, Brush brush, PointF point)
{
- int widest = GetWidestChar(font);
+ int widest = graphics.GetWidestChar(font);
for (int i = 0; i < s.Length; i++)
{
@@ -53,7 +53,7 @@ namespace DesktopMagicPluginAPI.Drawing
}
///
- /// Draws the specified text string at the specified location with the specified and objects.
+ ///
///
/// Graphics object.
/// String to draw.
@@ -73,7 +73,7 @@ namespace DesktopMagicPluginAPI.Drawing
}
///
- /// Draws the specified text string at the specified location with the specified and objects.
+ ///
///
/// Graphics object.
/// String to draw.
@@ -91,12 +91,76 @@ namespace DesktopMagicPluginAPI.Drawing
}
}
- private static int GetWidestChar(Font font)
+ ///
+ ///
+ ///
+ /// Graphics object.
+ /// String to draw.
+ /// that defines the text format of the string.
+ /// that determines the color and texture of the drawn text.
+ /// The x-coordinate of the upper-left corner of the drawn text.
+ /// The y-coordinate of the upper-left corner of the drawn text.
+ public static void DrawStringNoLeftPadding(this Graphics graphics, string s, Font font, Brush brush, float x, float y)
+ {
+ // measure left padding
+ StringFormat sf = new StringFormat(StringFormatFlags.NoClip);
+ sf.SetMeasurableCharacterRanges(new CharacterRange[] { new CharacterRange(0, 1) });
+ Region[] r = graphics.MeasureCharacterRanges(s, font, new RectangleF(0, 0, 1000, 100), sf);
+ float leftPadding = r[0].GetBounds(graphics).Left;
+
+ // draw string
+ sf = new StringFormat(StringFormatFlags.NoClip);
+ graphics.DrawString(s, font, brush, x - leftPadding, y, sf);
+ }
+
+ ///
+ ///
+ ///
+ /// Graphics object.
+ /// String to draw.
+ /// that defines the text format of the string.
+ /// that determines the color and texture of the drawn text.
+ /// structure that specifies the upper-left corner of the drawn text.
+ public static void DrawStringNoLeftPadding(this Graphics graphics, string s, Font font, Brush brush, PointF point)
+ {
+ // measure left padding
+ StringFormat sf = new StringFormat(StringFormatFlags.NoClip);
+ sf.SetMeasurableCharacterRanges(new CharacterRange[] { new CharacterRange(0, 1) });
+ Region[] r = graphics.MeasureCharacterRanges(s, font, new RectangleF(0, 0, 1000, 100), sf);
+ float leftPadding = r[0].GetBounds(graphics).Left;
+
+ // draw string
+ sf = new StringFormat(StringFormatFlags.NoClip);
+ graphics.DrawString(s, font, brush, point.X - leftPadding, point.Y, sf);
+ }
+
+ ///
+ ///
+ ///
+ /// Graphics object.
+ /// String to measure.
+ /// that defines the text format of the string.
+ ///
+ public static SizeF MeasureStringNoLeftPadding(this Graphics graphics, string text, Font font)
+ {
+ SizeF size = graphics.MeasureString(text, font, int.MaxValue);
+
+ StringFormat sf = new StringFormat(StringFormatFlags.NoClip);
+ sf.SetMeasurableCharacterRanges(new CharacterRange[] { new CharacterRange(0, 1) });
+ Region[] r = graphics.MeasureCharacterRanges(text, font, new RectangleF(0, 0, 1000, 100), sf);
+ float leftPadding = r[0].GetBounds(graphics).Left;
+
+ size.Width -= leftPadding / 1.5f;
+ return size;
+ }
+
+ private static int GetWidestChar(this Graphics graphics, Font font)
{
if (fonts.ContainsKey(font))
+ {
return fonts[font];
+ }
- Graphics graphics = Graphics.FromImage(new Bitmap(1, 1));
float max = 0;
char maxx = ' ';
for (int i = 0; i <= 255; i++)
diff --git a/src/DesktopMagicPluginAPI/IPluginData.cs b/src/DesktopMagicPluginAPI/IPluginData.cs
index a7c0c1e..aaabd7a 100644
--- a/src/DesktopMagicPluginAPI/IPluginData.cs
+++ b/src/DesktopMagicPluginAPI/IPluginData.cs
@@ -1,4 +1,5 @@
-using System.Drawing;
+using System;
+using System.Drawing;
namespace DesktopMagicPluginAPI
{
@@ -8,19 +9,26 @@ namespace DesktopMagicPluginAPI
public interface IPluginData
{
///
- /// Gets the font of the main application.
+ /// Gets the current font of the current theme.
///
+ [Obsolete("Use the \"Theme\" property instead")]
string Font { get; }
///
- /// Gets the color of the main application.
+ /// Gets the current color of the current theme.
///
+ [Obsolete("Use the \"Theme\" property instead")]
Color Color { get; }
+ ///
+ /// Gets the current theme setting of the main application.
+ ///
+ ITheme Theme { get; }
+
///
/// Gets the window size of the plugin window.
///
- Point WindowSize { get; }
+ Size WindowSize { get; }
///
/// Gets the window position of the plugin window.
diff --git a/src/DesktopMagicPluginAPI/ITheme.cs b/src/DesktopMagicPluginAPI/ITheme.cs
new file mode 100644
index 0000000..7d5f8f9
--- /dev/null
+++ b/src/DesktopMagicPluginAPI/ITheme.cs
@@ -0,0 +1,40 @@
+using System.Drawing;
+
+namespace DesktopMagicPluginAPI
+{
+ ///
+ /// The theme settings of the main application.
+ ///
+ public interface ITheme
+ {
+ ///
+ /// Gets the primary color of the current theme.
+ ///
+ Color PrimaryColor { get; }
+
+ ///
+ /// Gets the secondary color of the current theme.
+ ///
+ Color SecondaryColor { get; }
+
+ ///
+ /// Gets the background color of the current theme.
+ ///
+ Color BackgroundColor { get; }
+
+ ///
+ /// Gets the font of the current theme.
+ ///
+ string Font { get; }
+
+ ///
+ /// Gets the corner radius of the current theme.
+ ///
+ int CornerRadius { get; }
+
+ ///
+ /// Gets the corner radius of the current theme.
+ ///
+ int Margin { get; }
+ }
+}
\ No newline at end of file
diff --git a/src/DesktopMagicPluginAPI/Inputs/ComboBox.cs b/src/DesktopMagicPluginAPI/Inputs/ComboBox.cs
new file mode 100644
index 0000000..3bfa2d5
--- /dev/null
+++ b/src/DesktopMagicPluginAPI/Inputs/ComboBox.cs
@@ -0,0 +1,46 @@
+using System.Collections.ObjectModel;
+
+namespace DesktopMagicPluginAPI.Inputs
+{
+ ///
+ /// Represents a selection control with a drop-down list.
+ ///
+ public class ComboBox : Element
+ {
+ private string _value;
+
+ ///
+ /// Gets the collection used to generate the content of the .
+ ///
+ public ObservableCollection Items { get; } = new ObservableCollection();
+
+ ///
+ /// Gets the currently selected item associated with this .
+ ///
+ /// If you assign a value to this property, the displayed text in the user interface will not be changed.
+ public string Value
+ {
+ get => _value;
+ set
+ {
+ if (_value != value)
+ {
+ _value = value;
+ ValueChanged();
+ }
+ }
+ }
+
+ ///
+ /// Initializes a new instance of the class with the provided .
+ ///
+ ///
+ public ComboBox(params string[] items)
+ {
+ foreach (string item in items)
+ {
+ Items.Add(item);
+ }
+ }
+ }
+}
\ No newline at end of file
diff --git a/src/DesktopMagicPluginAPI/Plugin.cs b/src/DesktopMagicPluginAPI/Plugin.cs
index 46351a2..fb0cb81 100644
--- a/src/DesktopMagicPluginAPI/Plugin.cs
+++ b/src/DesktopMagicPluginAPI/Plugin.cs
@@ -19,17 +19,7 @@ namespace DesktopMagicPluginAPI
public IPluginData Application
{
get => application;
- set
- {
- if (application is null)
- {
- application = value;
- }
- else
- {
- throw new InvalidOperationException($"You cannot set the value of the {nameof(Application)} property");
- }
- }
+ set => application = application is null ? value : throw new InvalidOperationException($"You cannot set the value of the {nameof(Application)} property");
}
///
@@ -43,12 +33,19 @@ namespace DesktopMagicPluginAPI
public virtual RenderQuality RenderQuality { get; set; } = RenderQuality.High;
///
- /// Occurs once when the pugin gets activated.
+ /// Occurs once when the plugin gets activated.
///
public virtual void Start()
{
}
+ ///
+ /// Occurs once when the plugin gets deactivated.
+ ///
+ public virtual void Stop()
+ {
+ }
+
///
/// Occurs when the elapses.
///
@@ -76,8 +73,8 @@ namespace DesktopMagicPluginAPI
/// Occurs when the user rotates the mouse wheel while the mouse pointer is over this element.
///
/// The x- and y-coordinates of the mouse pointer position relative to the plugin window.
- /// A value that indicates the amount that the mouse wheel has changed.
- public virtual void OnMouseWheel(Point position, int Delta)
+ /// A value that indicates the amount that the mouse wheel has changed.
+ public virtual void OnMouseWheel(Point position, int delta)
{
}
}
diff --git a/update/DesktopMagic.zip b/update/DesktopMagic.zip
index c4b05a1..61870de 100644
Binary files a/update/DesktopMagic.zip and b/update/DesktopMagic.zip differ
diff --git a/update/updateInfo.json b/update/updateInfo.json
index 9f82c86..31d47e2 100644
--- a/update/updateInfo.json
+++ b/update/updateInfo.json
@@ -1,4 +1,4 @@
{
- "Version":"0.0.3.0",
+ "Version":"0.0.3.1",
"FileUrl":"http://github.com/Stone-Red-Code/DesktopMagic/blob/main/update/DesktopMagic.zip?raw=true"
}