Add check so that only one instance can be open at a time

This commit is contained in:
Stone-Red-Code
2021-08-25 19:08:26 +02:00
parent ae490367ee
commit 8df53ef190
2 changed files with 60 additions and 39 deletions
+32 -38
View File
@@ -1,60 +1,54 @@
using DesktopMagicPluginAPI;
using DesktopMagicPluginAPI.Inputs;
using DesktopMagicPluginAPI.Drawing;
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 InputExamplePlugin : Plugin
public class GifPlugin : Plugin
{
public override int UpdateInterval { get; set; } = 0;
[Element("Gif path:")]
private TextBox input = new TextBox("");
[Element("Text:")] //Mark the property as element with the specified description
private TextBox textBox = new TextBox("abc"); //Create a text box with the specified default value.
private List<Bitmap> bitmaps = new List<Bitmap>();
private Color color = Color.Black;
public override int UpdateInterval { get; set; } = 100;
private int frameCount = -1;
public override void Start()
public GifPlugin()
{
textBox.OnValueChanged += TextBox_OnValueChanged; //Add an event handler to the "OnValueChanged" event.
input.OnValueChanged += Input_OnValueChanged;
}
private void Input_OnValueChanged()
{
if (File.Exists(input.Value))
{
Image gif = Image.FromFile(input.Value);
bitmaps.Clear();
for (int i = 0; i < gif.GetFrameCount(FrameDimension.Time); i++)
{
gif.SelectActiveFrame(FrameDimension.Time, i);
bitmaps.Add(new Bitmap(gif));
}
}
}
public override Bitmap Main()
{
Bitmap bmp = new Bitmap(1000, 1000);
if (bitmaps.Count == 0)
return new Bitmap(1, 1);
using (Graphics g = Graphics.FromImage(bmp))
{
g.InterpolationMode = InterpolationMode.HighQualityBilinear;
g.PixelOffsetMode = PixelOffsetMode.HighQuality;
g.Clear(color);
g.DrawStringFixedWidth(textBox.Value, new Font(Application.Font, 100), Brushes.Black, new PointF(0, 0), 120); //Draw the value of the text box to the image.
}
frameCount++;
return bmp; //Return the image.
}
if (frameCount >= bitmaps.Count)
frameCount = 0;
private void TextBox_OnValueChanged()
{
Application.UpdateWindow(); //Update the plugin window. (Calls the "Main" method.)
}
public override void OnMouseMove(Point position)
{
Debug.WriteLine(position.X);
Debug.WriteLine(500);
if (500 < position.X && color == Color.Black)
{
color = Color.White;
Application.UpdateWindow();
}
else if (500 > position.X && color == Color.White)
{
color = Color.Black;
Application.UpdateWindow();
}
return bitmaps[frameCount];
}
}
}