mirror of
https://github.com/Stone-Red-Code/DesktopMagic.git
synced 2026-09-04 00:46:12 +02:00
Updated Guide (markdown)
+92
-1
@@ -1 +1,92 @@
|
||||
### Coming soon™️
|
||||
## 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.
|
||||
}
|
||||
}
|
||||
}
|
||||
```
|
||||
|
||||
Reference in New Issue
Block a user