mirror of
https://github.com/Stone-Red-Code/DesktopMagic.git
synced 2026-09-04 00:46:12 +02:00
- Remove unnecessary code
- Execute `OnValueChanged` event in task
This commit is contained in:
@@ -473,7 +473,6 @@ namespace DesktopMagic
|
||||
Dispatcher.Invoke(() =>
|
||||
{
|
||||
label.Text = eLabel.Value;
|
||||
Option_ValueChanged();
|
||||
});
|
||||
};
|
||||
}
|
||||
@@ -498,7 +497,6 @@ namespace DesktopMagic
|
||||
Dispatcher.Invoke(() =>
|
||||
{
|
||||
button.Content = eButton.Value;
|
||||
Option_ValueChanged();
|
||||
});
|
||||
};
|
||||
|
||||
@@ -522,7 +520,6 @@ namespace DesktopMagic
|
||||
Dispatcher.Invoke(() =>
|
||||
{
|
||||
checkBox.IsChecked = eCheckBox.Value;
|
||||
Option_ValueChanged();
|
||||
});
|
||||
};
|
||||
|
||||
@@ -546,7 +543,6 @@ namespace DesktopMagic
|
||||
Dispatcher.Invoke(() =>
|
||||
{
|
||||
textBox.Text = eTextBox.Value;
|
||||
Option_ValueChanged();
|
||||
});
|
||||
};
|
||||
_ = stackPanel.Children.Add(textBox);
|
||||
@@ -570,7 +566,6 @@ namespace DesktopMagic
|
||||
Dispatcher.Invoke(() =>
|
||||
{
|
||||
integerUpDown.Value = eIntegerUpDown.Value;
|
||||
Option_ValueChanged();
|
||||
});
|
||||
};
|
||||
_ = stackPanel.Children.Add(integerUpDown);
|
||||
@@ -596,7 +591,6 @@ namespace DesktopMagic
|
||||
Dispatcher.Invoke(() =>
|
||||
{
|
||||
slider.Value = eSlider.Value;
|
||||
Option_ValueChanged();
|
||||
});
|
||||
};
|
||||
|
||||
@@ -606,20 +600,6 @@ namespace DesktopMagic
|
||||
}
|
||||
}
|
||||
|
||||
private void Option_ValueChanged()
|
||||
{
|
||||
//Plugin settings save currenty disabled. Not sure if I want to add it back in the future.
|
||||
/*
|
||||
string pluginName = ((Tuple<string, int>)optionsComboBox.SelectedItem).Item1.ToString();
|
||||
|
||||
if (PluginsSettings.ContainsKey(pluginName))
|
||||
{
|
||||
string jsonSettings = JsonSerializer.Serialize(PluginsSettings[pluginName]);
|
||||
File.WriteAllText($"{applicationDataPath}\\Plugins\\{pluginName}\\{pluginName}.save", jsonSettings);
|
||||
}
|
||||
*/
|
||||
}
|
||||
|
||||
#endregion options
|
||||
|
||||
private void TextBlock_Loaded(object sender, RoutedEventArgs e)
|
||||
|
||||
@@ -117,15 +117,9 @@ namespace DesktopMagic
|
||||
|
||||
private void LoadPlugin()
|
||||
{
|
||||
string PluginPath;
|
||||
|
||||
pluginFolderPath = $"{Environment.GetFolderPath(Environment.SpecialFolder.ApplicationData)}\\{MainWindow.AppName}\\Plugins\\{pluginName}";
|
||||
|
||||
if (File.Exists($"{pluginFolderPath}\\{pluginName}.dll"))
|
||||
{
|
||||
PluginPath = $"{pluginFolderPath}\\{pluginName}.dll";
|
||||
}
|
||||
else
|
||||
if (!File.Exists($"{pluginFolderPath}\\{pluginName}.dll"))
|
||||
{
|
||||
_ = MessageBox.Show("File does not exist!", "Error", MessageBoxButton.OK, MessageBoxImage.Error);
|
||||
Exit();
|
||||
|
||||
@@ -1,28 +1,60 @@
|
||||
using DesktopMagicPluginAPI;
|
||||
using DesktopMagicPluginAPI.Inputs;
|
||||
using System.Drawing;
|
||||
using System.Diagnostics;
|
||||
using System.Drawing.Imaging;
|
||||
using System.Drawing.Drawing2D;
|
||||
using System.IO;
|
||||
using System.Collections.Generic;
|
||||
|
||||
namespace DesktopMagicPlugin.Test
|
||||
{
|
||||
public class GifPlugin : Plugin
|
||||
{
|
||||
[Element("Gif path:")]
|
||||
public TextBox input = new TextBox("");
|
||||
private TextBox input = new TextBox("");
|
||||
|
||||
public override int UpdateInterval { get; set; } = 100;
|
||||
private List<Bitmap> bitmaps = new List<Bitmap>();
|
||||
|
||||
public override void OnMouseWheel(Point position, int delta)
|
||||
private int frameCount = -1;
|
||||
|
||||
public override void Start()
|
||||
{
|
||||
Debug.WriteLine(position + " | " + delta);
|
||||
input.OnValueChanged += Input_OnValueChanged;
|
||||
}
|
||||
|
||||
private void Input_OnValueChanged()
|
||||
{
|
||||
try
|
||||
{
|
||||
if (File.Exists(input.Value))
|
||||
{
|
||||
Image gif = Image.FromFile(input.Value);
|
||||
PropertyItem item = gif.GetPropertyItem(0x5100); // FrameDelay in libgdiplus
|
||||
|
||||
UpdateInterval = (item.Value[0] + item.Value[1] * 256) * 10; //FrameDelay in ms
|
||||
bitmaps.Clear();
|
||||
for (int i = 0; i < gif.GetFrameCount(FrameDimension.Time); i++)
|
||||
{
|
||||
gif.SelectActiveFrame(FrameDimension.Time, i);
|
||||
|
||||
bitmaps.Add(new Bitmap(gif));
|
||||
}
|
||||
}
|
||||
}
|
||||
catch { }
|
||||
}
|
||||
|
||||
public override Bitmap Main()
|
||||
{
|
||||
Bitmap bmp = new Bitmap(100, 100);
|
||||
using Graphics graphics = Graphics.FromImage(bmp);
|
||||
graphics.Clear(Application.Color);
|
||||
return bmp;
|
||||
if (bitmaps.Count == 0)
|
||||
return new Bitmap(1, 1);
|
||||
|
||||
frameCount++;
|
||||
|
||||
if (frameCount >= bitmaps.Count)
|
||||
frameCount = 0;
|
||||
|
||||
return bitmaps[frameCount];
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -1,7 +1,4 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace DesktopMagicPluginAPI.Inputs
|
||||
@@ -48,7 +45,7 @@ namespace DesktopMagicPluginAPI.Inputs
|
||||
/// </summary>
|
||||
public void Click()
|
||||
{
|
||||
OnClick?.Invoke();
|
||||
_ = Task.Run(() => OnClick?.Invoke());
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -1,4 +1,5 @@
|
||||
using System;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace DesktopMagicPluginAPI.Inputs
|
||||
{
|
||||
@@ -17,7 +18,7 @@ namespace DesktopMagicPluginAPI.Inputs
|
||||
/// </summary>
|
||||
protected void ValueChanged()
|
||||
{
|
||||
OnValueChanged?.Invoke();
|
||||
_ = Task.Run(() => OnValueChanged?.Invoke());
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user