mirror of
https://github.com/Stone-Red-Code/DesktopMagic.git
synced 2026-09-04 23:39:29 +02:00
- Remove unnecessary code
- Execute `OnValueChanged` event in task
This commit is contained in:
@@ -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];
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user