From 31be96a39882cda9eddb74265d108b69e9962b93 Mon Sep 17 00:00:00 2001 From: Stone_Red <56473591+Stone-Red-Code@users.noreply.github.com> Date: Thu, 16 Sep 2021 08:35:22 +0200 Subject: [PATCH 1/2] Create source.cs --- Plugins/Gif Plugin/source.cs | 84 ++++++++++++++++++++++++++++++++++++ 1 file changed, 84 insertions(+) create mode 100644 Plugins/Gif Plugin/source.cs diff --git a/Plugins/Gif Plugin/source.cs b/Plugins/Gif Plugin/source.cs new file mode 100644 index 0000000..c27b43e --- /dev/null +++ b/Plugins/Gif Plugin/source.cs @@ -0,0 +1,84 @@ +using DesktopMagicPluginAPI; +using DesktopMagicPluginAPI.Inputs; +using System.Drawing; +using System.Drawing.Imaging; +using System.IO; +using System.Collections.Generic; +using System.Threading.Tasks; +using System; + +namespace DesktopMagicPlugin.Test +{ + public class GifPlugin : Plugin + { + [Element("Gif path:")] + private TextBox input = new TextBox(""); + + [Element] + private Label info = new Label(""); + + private List bitmaps = new List(); + + private int frameCount = -1; + + private const string SaveFilePath = "gifPath.txt"; + + public override void Start() + { + input.OnValueChanged += Input_OnValueChanged; + if (File.Exists(SaveFilePath)) + { + input.Value = File.ReadAllText(SaveFilePath); + } + } + + private void Input_OnValueChanged() + { + _ = Task.Run(() => + { + try + { + if (File.Exists(input.Value)) + { + info.Value = "Loading..."; + 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)); + } + File.WriteAllText(SaveFilePath, input.Value); + info.Value = string.Empty; + } + else + { + info.Value = "File not found!"; + } + } + catch (Exception ex) + { + info.Value = $"Error: {ex.Message}"; + } + }); + } + + public override Bitmap Main() + { + if (bitmaps.Count == 0) + return new Bitmap(1, 1); + + frameCount++; + + if (frameCount >= bitmaps.Count) + frameCount = 0; + + return bitmaps[frameCount]; + } + } +} From af6705df4bea1ad527d4124db345fbc07e020acb Mon Sep 17 00:00:00 2001 From: Stone_Red <56473591+Stone-Red-Code@users.noreply.github.com> Date: Thu, 16 Sep 2021 08:37:03 +0200 Subject: [PATCH 2/2] Create source.cs --- Plugins/Quotes Plugin/source.cs | 70 +++++++++++++++++++++++++++++++++ 1 file changed, 70 insertions(+) create mode 100644 Plugins/Quotes Plugin/source.cs diff --git a/Plugins/Quotes Plugin/source.cs b/Plugins/Quotes Plugin/source.cs new file mode 100644 index 0000000..169dbec --- /dev/null +++ b/Plugins/Quotes Plugin/source.cs @@ -0,0 +1,70 @@ +using DesktopMagicPluginAPI; +using DesktopMagicPluginAPI.Inputs; +using System; +using System.Diagnostics; +using System.Drawing; +using System.IO; +using System.Net.Http; +using System.Text.Json; + +namespace Quotes_Plugin +{ + public class Quotes : Plugin + { + private const string SaveFilePath = "save.txt"; + + [Element("Update Interval (sec.):")] + private IntegerUpDown integerUpDown = new IntegerUpDown(1, 9999, 600); + + public override int UpdateInterval { get; set; } = 10000; + + private HttpClient httpClient = new HttpClient(); + + private Bitmap bmp; + + public override void Start() + { + integerUpDown.OnValueChanged += IntegerUpDown_OnValueChanged; + + if (File.Exists(SaveFilePath)) + { + string num = File.ReadAllText(SaveFilePath); + int updateInterval; + _ = int.TryParse(num, out updateInterval); + + if (updateInterval >= integerUpDown.Minimum && updateInterval <= integerUpDown.Maximum) + { + integerUpDown.Value = updateInterval; + } + } + } + + private void IntegerUpDown_OnValueChanged() + { + UpdateInterval = integerUpDown.Value * 1000; + File.WriteAllText(SaveFilePath, integerUpDown.Value.ToString()); + } + + public override Bitmap Main() + { + try + { + string quoteDataRaw = httpClient.GetStringAsync("https://api.quotable.io/random").GetAwaiter().GetResult(); + + JsonDocument quoteData = JsonDocument.Parse(quoteDataRaw); + + string content = $"{quoteData.RootElement.GetProperty("content").GetString()}"; + content += "\n\n- " + quoteData.RootElement.GetProperty("author").GetString(); + + bmp = new Bitmap(2000, 1000); + bmp.SetResolution(200, 200); + using Graphics g = Graphics.FromImage(bmp); + g.DrawString(content, new Font(Application.Font, 50), new SolidBrush(Application.Color), new RectangleF(0, 0, bmp.Width, bmp.Height)); + } + catch + { + } + return bmp; + } + } +}