- Remove unnecessary code

- Execute `OnValueChanged` event in task
This commit is contained in:
Stone-Red-Code
2021-09-13 19:49:05 +02:00
parent d70e6229cc
commit e00c873bd5
5 changed files with 45 additions and 41 deletions
+41 -9
View File
@@ -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];
}
}
}