diff --git a/src/DesktopMagic/Plugin/PluginWindow.xaml.cs b/src/DesktopMagic/Plugin/PluginWindow.xaml.cs index fee07c4..cc63216 100644 --- a/src/DesktopMagic/Plugin/PluginWindow.xaml.cs +++ b/src/DesktopMagic/Plugin/PluginWindow.xaml.cs @@ -210,7 +210,7 @@ namespace DesktopMagic private void LoadOptions(object instance) { Debug.WriteLine(instance.GetType().FullName); - FieldInfo[] props = instance.GetType().GetFields(BindingFlags.Instance | BindingFlags.NonPublic | BindingFlags.GetField); + FieldInfo[] props = instance.GetType().GetFields(BindingFlags.Instance | BindingFlags.NonPublic | BindingFlags.Public | BindingFlags.GetField); List settingElements = new List(); foreach (FieldInfo prop in props) @@ -330,7 +330,26 @@ namespace DesktopMagic BitmapSource bitmapImage = (BitmapSource)imageSource; double pixelMousePositionX = e.GetPosition(image).X * bitmapImage.PixelWidth / image.ActualHeight; double pixelMousePositionY = e.GetPosition(image).Y * bitmapImage.PixelHeight / image.ActualHeight; - Clicked(new System.Drawing.Point((int)pixelMousePositionX, (int)pixelMousePositionY)); + + MouseButton mouseButton; + + switch (e.ChangedButton) + { + case System.Windows.Input.MouseButton.Left: + mouseButton = MouseButton.Left; + break; + + case System.Windows.Input.MouseButton.Middle: + mouseButton = MouseButton.Middle; + break; + + case System.Windows.Input.MouseButton.Right: + mouseButton = MouseButton.Right; + break; + + default: return; + }; + Clicked(new System.Drawing.Point((int)pixelMousePositionX, (int)pixelMousePositionY), mouseButton); } private void Window_MouseMove(object sender, System.Windows.Input.MouseEventArgs e) @@ -346,9 +365,9 @@ namespace DesktopMagic #region Plugin Methods - private void Clicked(System.Drawing.Point positon) + private void Clicked(System.Drawing.Point positon, MouseButton mouseButton) { - pluginClassInstance.OnMouseClick(positon); + pluginClassInstance.OnMouseClick(positon, mouseButton); } private void Moved(System.Drawing.Point positon) diff --git a/src/DesktopMagicPlugin.Test/PluginScript.cs b/src/DesktopMagicPlugin.Test/PluginScript.cs index 090bdcc..b63bc08 100644 --- a/src/DesktopMagicPlugin.Test/PluginScript.cs +++ b/src/DesktopMagicPlugin.Test/PluginScript.cs @@ -1,54 +1,28 @@ using DesktopMagicPluginAPI; using DesktopMagicPluginAPI.Inputs; using System.Drawing; -using System.Drawing.Imaging; -using System.Drawing.Drawing2D; -using System.IO; -using System.Collections.Generic; +using System.Diagnostics; namespace DesktopMagicPlugin.Test { public class GifPlugin : Plugin { [Element("Gif path:")] - private TextBox input = new TextBox(""); - - private List bitmaps = new List(); + public TextBox input = new TextBox(""); public override int UpdateInterval { get; set; } = 100; - private int frameCount = -1; - public GifPlugin() + public override void OnMouseClick(Point position, MouseButton mouseButton) { - 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)); - } - } + Debug.WriteLine(position + " | " + mouseButton); } public override Bitmap Main() { - if (bitmaps.Count == 0) - return new Bitmap(1, 1); - - frameCount++; - - if (frameCount >= bitmaps.Count) - frameCount = 0; - - return bitmaps[frameCount]; + Bitmap bmp = new Bitmap(100, 100); + using Graphics graphics = Graphics.FromImage(bmp); + graphics.Clear(Color.Red); + return bmp; } } } \ No newline at end of file diff --git a/src/DesktopMagicPluginAPI/DesktopMagicPluginAPI.csproj b/src/DesktopMagicPluginAPI/DesktopMagicPluginAPI.csproj index b6dbfaf..b428bd2 100644 --- a/src/DesktopMagicPluginAPI/DesktopMagicPluginAPI.csproj +++ b/src/DesktopMagicPluginAPI/DesktopMagicPluginAPI.csproj @@ -4,19 +4,23 @@ net5.0 Stone_Red Stone_Red - 0.0.0.2 + 0.0.0.4 https://github.com/Stone-Red-Code/DesktopMagic LICENSE true - 0.0.0.2 + 0.0.0.4 - 0.0.0.2 + 0.0.0.4 C:\Users\David\Programmieren\DesktopMagic\src\DesktopMagicPluginAPI\DesktopMagicPluginAPI.xml + + C:\Users\David\Programmieren\DesktopMagic\src\DesktopMagicPluginAPI\DesktopMagicPluginAPI.xml + + diff --git a/src/DesktopMagicPluginAPI/DesktopMagicPluginAPI.md b/src/DesktopMagicPluginAPI/DesktopMagicPluginAPI.md index 876a43e..a085413 100644 --- a/src/DesktopMagicPluginAPI/DesktopMagicPluginAPI.md +++ b/src/DesktopMagicPluginAPI/DesktopMagicPluginAPI.md @@ -38,11 +38,15 @@ - [#ctor(value,bold)](#M-DesktopMagicPluginAPI-Inputs-Label-#ctor-System-String,System-Boolean- 'DesktopMagicPluginAPI.Inputs.Label.#ctor(System.String,System.Boolean)') - [Bold](#P-DesktopMagicPluginAPI-Inputs-Label-Bold 'DesktopMagicPluginAPI.Inputs.Label.Bold') - [Value](#P-DesktopMagicPluginAPI-Inputs-Label-Value 'DesktopMagicPluginAPI.Inputs.Label.Value') +- [MouseButton](#T-DesktopMagicPluginAPI-Inputs-MouseButton 'DesktopMagicPluginAPI.Inputs.MouseButton') + - [Left](#F-DesktopMagicPluginAPI-Inputs-MouseButton-Left 'DesktopMagicPluginAPI.Inputs.MouseButton.Left') + - [Middle](#F-DesktopMagicPluginAPI-Inputs-MouseButton-Middle 'DesktopMagicPluginAPI.Inputs.MouseButton.Middle') + - [Right](#F-DesktopMagicPluginAPI-Inputs-MouseButton-Right 'DesktopMagicPluginAPI.Inputs.MouseButton.Right') - [Plugin](#T-DesktopMagicPluginAPI-Plugin 'DesktopMagicPluginAPI.Plugin') - [Application](#P-DesktopMagicPluginAPI-Plugin-Application 'DesktopMagicPluginAPI.Plugin.Application') - [UpdateInterval](#P-DesktopMagicPluginAPI-Plugin-UpdateInterval 'DesktopMagicPluginAPI.Plugin.UpdateInterval') - [Main()](#M-DesktopMagicPluginAPI-Plugin-Main 'DesktopMagicPluginAPI.Plugin.Main') - - [OnMouseClick(position)](#M-DesktopMagicPluginAPI-Plugin-OnMouseClick-System-Drawing-Point- 'DesktopMagicPluginAPI.Plugin.OnMouseClick(System.Drawing.Point)') + - [OnMouseClick(position,mouseButton)](#M-DesktopMagicPluginAPI-Plugin-OnMouseClick-System-Drawing-Point,DesktopMagicPluginAPI-Inputs-MouseButton- 'DesktopMagicPluginAPI.Plugin.OnMouseClick(System.Drawing.Point,DesktopMagicPluginAPI.Inputs.MouseButton)') - [OnMouseMove(position)](#M-DesktopMagicPluginAPI-Plugin-OnMouseMove-System-Drawing-Point- 'DesktopMagicPluginAPI.Plugin.OnMouseMove(System.Drawing.Point)') - [Start()](#M-DesktopMagicPluginAPI-Plugin-Start 'DesktopMagicPluginAPI.Plugin.Start') - [Slider](#T-DesktopMagicPluginAPI-Inputs-Slider 'DesktopMagicPluginAPI.Inputs.Slider') @@ -325,14 +329,14 @@ Gets the font of the main application. ##### Summary -Gets the window position of the main application. +Gets the window position of the plugin window. ### WindowSize `property` ##### Summary -Gets the window size of the main application. +Gets the window size of the plugin window. ### UpdateWindow() `method` @@ -437,6 +441,38 @@ Gets or set a value indicating whether the content of the [Label](#T-DesktopMagi Gets or sets the text associated with this [Label](#T-DesktopMagicPluginAPI-Inputs-Label 'DesktopMagicPluginAPI.Inputs.Label'). + +## MouseButton `type` + +##### Namespace + +DesktopMagicPluginAPI.Inputs + +##### Summary + +Mouse Buttons + + +### Left `constants` + +##### Summary + +The left mouse button. + + +### Middle `constants` + +##### Summary + +The middle mouse button. + + +### Right `constants` + +##### Summary + +The right mouse button. + ## Plugin `type` @@ -477,8 +513,8 @@ Occurs when the [UpdateInterval](#P-DesktopMagicPluginAPI-Plugin-UpdateInterval This method has no parameters. - -### OnMouseClick(position) `method` + +### OnMouseClick(position,mouseButton) `method` ##### Summary @@ -488,7 +524,8 @@ Occurs when the window is clicked by the mouse. | Name | Type | Description | | ---- | ---- | ----------- | -| position | [System.Drawing.Point](http://msdn.microsoft.com/query/dev14.query?appId=Dev14IDEF1&l=EN-US&k=k:System.Drawing.Point 'System.Drawing.Point') | | +| position | [System.Drawing.Point](http://msdn.microsoft.com/query/dev14.query?appId=Dev14IDEF1&l=EN-US&k=k:System.Drawing.Point 'System.Drawing.Point') | The x- and y-coordinates of the mouse pointer position relative to the plugin window. | +| mouseButton | [DesktopMagicPluginAPI.Inputs.MouseButton](#T-DesktopMagicPluginAPI-Inputs-MouseButton 'DesktopMagicPluginAPI.Inputs.MouseButton') | Gets the button associated with the event. | ### OnMouseMove(position) `method` @@ -501,7 +538,7 @@ Occurs when the mouse pointer is moved over the control. | Name | Type | Description | | ---- | ---- | ----------- | -| position | [System.Drawing.Point](http://msdn.microsoft.com/query/dev14.query?appId=Dev14IDEF1&l=EN-US&k=k:System.Drawing.Point 'System.Drawing.Point') | | +| position | [System.Drawing.Point](http://msdn.microsoft.com/query/dev14.query?appId=Dev14IDEF1&l=EN-US&k=k:System.Drawing.Point 'System.Drawing.Point') | The x- and y-coordinates of the mouse pointer position relative to the plugin window. | ### Start() `method` diff --git a/src/DesktopMagicPluginAPI/DesktopMagicPluginAPI.xml b/src/DesktopMagicPluginAPI/DesktopMagicPluginAPI.xml index 147c378..2b97ae5 100644 --- a/src/DesktopMagicPluginAPI/DesktopMagicPluginAPI.xml +++ b/src/DesktopMagicPluginAPI/DesktopMagicPluginAPI.xml @@ -192,6 +192,26 @@ The text associated with this A value indicating whether the content of the is bold or not. + + + Mouse Buttons + + + + + The left mouse button. + + + + + The middle mouse button. + + + + + The right mouse button. + + Represents a slider control. @@ -253,12 +273,12 @@ - Gets the window size of the main application. + Gets the window size of the plugin window. - Gets the window position of the main application. + Gets the window position of the plugin window. @@ -292,17 +312,18 @@ - + Occurs when the window is clicked by the mouse. - + The x- and y-coordinates of the mouse pointer position relative to the plugin window. + Gets the button associated with the event. Occurs when the mouse pointer is moved over the control. - + The x- and y-coordinates of the mouse pointer position relative to the plugin window. diff --git a/src/DesktopMagicPluginAPI/IPluginData.cs b/src/DesktopMagicPluginAPI/IPluginData.cs index 3b05e01..9eeef60 100644 --- a/src/DesktopMagicPluginAPI/IPluginData.cs +++ b/src/DesktopMagicPluginAPI/IPluginData.cs @@ -18,12 +18,12 @@ namespace DesktopMagicPluginAPI Color Color { get; } /// - /// Gets the window size of the main application. + /// Gets the window size of the plugin window. /// Point WindowSize { get; } /// - /// Gets the window position of the main application. + /// Gets the window position of the plugin window. /// Point WindowPosition { get; } diff --git a/src/DesktopMagicPluginAPI/Inputs/MouseButton.cs b/src/DesktopMagicPluginAPI/Inputs/MouseButton.cs new file mode 100644 index 0000000..498b38b --- /dev/null +++ b/src/DesktopMagicPluginAPI/Inputs/MouseButton.cs @@ -0,0 +1,29 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace DesktopMagicPluginAPI.Inputs +{ + /// + /// Mouse Buttons + /// + public enum MouseButton + { + /// + /// The left mouse button. + /// + Left, + + /// + /// The middle mouse button. + /// + Middle, + + /// + /// The right mouse button. + /// + Right, + } +} \ No newline at end of file diff --git a/src/DesktopMagicPluginAPI/Plugin.cs b/src/DesktopMagicPluginAPI/Plugin.cs index 0a2c345..6f141a8 100644 --- a/src/DesktopMagicPluginAPI/Plugin.cs +++ b/src/DesktopMagicPluginAPI/Plugin.cs @@ -1,4 +1,5 @@ -using System; +using DesktopMagicPluginAPI.Inputs; +using System; using System.Drawing; namespace DesktopMagicPluginAPI @@ -50,15 +51,16 @@ namespace DesktopMagicPluginAPI /// /// Occurs when the window is clicked by the mouse. /// - /// - public virtual void OnMouseClick(Point position) + /// The x- and y-coordinates of the mouse pointer position relative to the plugin window. + /// Gets the button associated with the event. + public virtual void OnMouseClick(Point position, MouseButton mouseButton) { } /// /// Occurs when the mouse pointer is moved over the control. /// - /// + /// The x- and y-coordinates of the mouse pointer position relative to the plugin window. public virtual void OnMouseMove(Point position) { }