diff --git a/Guide.md b/Guide.md index 718ffb8..b7a67bb 100644 --- a/Guide.md +++ b/Guide.md @@ -1 +1,92 @@ -### Coming soon™️ \ No newline at end of file +## How to create a basic plugin + +1. Create a [.NET(Core) class library](https://docs.microsoft.com/en-us/dotnet/core/tutorials/library-with-visual-studio) project + +2. Add the [DesktopMagicPluginAPI](https://www.nuget.org/packages/DesktopMagicPluginAPI/) nuget package + +3. Create a class that inherits from `DesktopMagicPluginAPI.Plugin` + +4. Implement the reqired members from `DesktopMagicPluginAPI.Plugin` + +## Examples + +### Minimum example + +This is a very basic plugin that will display a constant string. + +```cs +using DesktopMagicPluginAPI; +using DesktopMagicPluginAPI.Drawing; +using System.Diagnostics; +using System.Drawing; + +namespace DesktopMagicPlugin +{ + public class MyFirstPlugin : Plugin + { + public override Bitmap Main() + { + Bitmap bmp = new Bitmap(1000, 1000); + + using(Graphics g = Graphics.FromImage(bmp)) + { + g.Clear(Application.Color); //Set the background color to the color specified in the Desktop Magic application. + + g.DrawStringFixedWidth("Hello", new Font(Application.Font, 100), Brushes.Black, new PointF(0, 0), 120); //Draw the "Hello" to the image. + } + + return bmp; //Return the image. + } + } +} +``` + +### Input example + +```cs +using DesktopMagicPluginAPI; +using DesktopMagicPluginAPI.Inputs; +using DesktopMagicPluginAPI.Drawing; +using System.Diagnostics; +using System.Drawing; + +using DesktopMagicPluginAPI; +using DesktopMagicPluginAPI.Inputs; +using DesktopMagicPluginAPI.Drawing; +using System.Drawing; + +namespace DesktopMagicPlugin +{ + public class InputExamplePlugin : Plugin + { + public override int UpdateInterval { get; set; } = 0; + + [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. + + public InputExamplePlugin() + { + textBox.OnValueChanged += TextBox_OnValueChanged; //Add an event handler to the "OnValueChanged" event. + } + + private void TextBox_OnValueChanged() + { + Application.UpdateWindow(); //Update the pugin window. (Calls the "Main" method.) + } + + public override Bitmap Main() + { + Bitmap bmp = new Bitmap(1000, 1000); + + using (Graphics g = Graphics.FromImage(bmp)) + { + g.Clear(Application.Color); //Set the background color to the color specified in the Desktop Magic application. + + 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. + } + + return bmp; //Return the image. + } + } +} +```