From f94f24297e5d00e3c24974d6f53c3a70dd9664db Mon Sep 17 00:00:00 2001 From: Stone-Red-Code <56473591+Stone-Red-Code@users.noreply.github.com> Date: Sat, 11 Sep 2021 17:13:02 +0200 Subject: [PATCH] - Add `OnMouseWheel` event --- src/DesktopMagic/Plugin/PluginWindow.xaml | 2 +- src/DesktopMagic/Plugin/PluginWindow.xaml.cs | 33 ++++++++++--------- .../DesktopMagicPlugin.Test.csproj | 1 + src/DesktopMagicPlugin.Test/PluginScript.cs | 4 +-- .../DesktopMagicPluginAPI.md | 17 +++++++++- .../DesktopMagicPluginAPI.xml | 9 ++++- src/DesktopMagicPluginAPI/Plugin.cs | 11 ++++++- 7 files changed, 55 insertions(+), 22 deletions(-) diff --git a/src/DesktopMagic/Plugin/PluginWindow.xaml b/src/DesktopMagic/Plugin/PluginWindow.xaml index 83e7267..d845850 100644 --- a/src/DesktopMagic/Plugin/PluginWindow.xaml +++ b/src/DesktopMagic/Plugin/PluginWindow.xaml @@ -18,7 +18,7 @@ - + diff --git a/src/DesktopMagic/Plugin/PluginWindow.xaml.cs b/src/DesktopMagic/Plugin/PluginWindow.xaml.cs index cc63216..26eb572 100644 --- a/src/DesktopMagic/Plugin/PluginWindow.xaml.cs +++ b/src/DesktopMagic/Plugin/PluginWindow.xaml.cs @@ -349,7 +349,9 @@ namespace DesktopMagic default: return; }; - Clicked(new System.Drawing.Point((int)pixelMousePositionX, (int)pixelMousePositionY), mouseButton); + + System.Drawing.Point point = new System.Drawing.Point((int)pixelMousePositionX, (int)pixelMousePositionY); + pluginClassInstance.OnMouseClick(point, mouseButton); } private void Window_MouseMove(object sender, System.Windows.Input.MouseEventArgs e) @@ -358,23 +360,22 @@ 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; - Moved(new System.Drawing.Point((int)pixelMousePositionX, (int)pixelMousePositionY)); + + System.Drawing.Point point = new System.Drawing.Point((int)pixelMousePositionX, (int)pixelMousePositionY); + pluginClassInstance.OnMouseMove(point); + } + + private void Window_MouseWheel(object sender, System.Windows.Input.MouseWheelEventArgs e) + { + ImageSource imageSource = image.Source; + BitmapSource bitmapImage = (BitmapSource)imageSource; + double pixelMousePositionX = e.GetPosition(image).X * bitmapImage.PixelWidth / image.ActualHeight; + double pixelMousePositionY = e.GetPosition(image).Y * bitmapImage.PixelHeight / image.ActualHeight; + + System.Drawing.Point point = new System.Drawing.Point((int)pixelMousePositionX, (int)pixelMousePositionY); + pluginClassInstance.OnMouseWheel(point, e.Delta); } #endregion Window Events - - #region Plugin Methods - - private void Clicked(System.Drawing.Point positon, MouseButton mouseButton) - { - pluginClassInstance.OnMouseClick(positon, mouseButton); - } - - private void Moved(System.Drawing.Point positon) - { - pluginClassInstance.OnMouseMove(positon); - } - - #endregion Plugin Methods } } \ No newline at end of file diff --git a/src/DesktopMagicPlugin.Test/DesktopMagicPlugin.Test.csproj b/src/DesktopMagicPlugin.Test/DesktopMagicPlugin.Test.csproj index d2240e9..19fb9b6 100644 --- a/src/DesktopMagicPlugin.Test/DesktopMagicPlugin.Test.csproj +++ b/src/DesktopMagicPlugin.Test/DesktopMagicPlugin.Test.csproj @@ -5,6 +5,7 @@ + diff --git a/src/DesktopMagicPlugin.Test/PluginScript.cs b/src/DesktopMagicPlugin.Test/PluginScript.cs index b63bc08..67a7c0d 100644 --- a/src/DesktopMagicPlugin.Test/PluginScript.cs +++ b/src/DesktopMagicPlugin.Test/PluginScript.cs @@ -12,9 +12,9 @@ namespace DesktopMagicPlugin.Test public override int UpdateInterval { get; set; } = 100; - public override void OnMouseClick(Point position, MouseButton mouseButton) + public override void OnMouseWheel(Point position, int delta) { - Debug.WriteLine(position + " | " + mouseButton); + Debug.WriteLine(position + " | " + delta); } public override Bitmap Main() diff --git a/src/DesktopMagicPluginAPI/DesktopMagicPluginAPI.md b/src/DesktopMagicPluginAPI/DesktopMagicPluginAPI.md index a085413..90b9321 100644 --- a/src/DesktopMagicPluginAPI/DesktopMagicPluginAPI.md +++ b/src/DesktopMagicPluginAPI/DesktopMagicPluginAPI.md @@ -48,6 +48,7 @@ - [Main()](#M-DesktopMagicPluginAPI-Plugin-Main 'DesktopMagicPluginAPI.Plugin.Main') - [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)') + - [OnMouseWheel(position,Delta)](#M-DesktopMagicPluginAPI-Plugin-OnMouseWheel-System-Drawing-Point,System-Int32- 'DesktopMagicPluginAPI.Plugin.OnMouseWheel(System.Drawing.Point,System.Int32)') - [Start()](#M-DesktopMagicPluginAPI-Plugin-Start 'DesktopMagicPluginAPI.Plugin.Start') - [Slider](#T-DesktopMagicPluginAPI-Inputs-Slider 'DesktopMagicPluginAPI.Inputs.Slider') - [#ctor(min,max,value)](#M-DesktopMagicPluginAPI-Inputs-Slider-#ctor-System-Double,System-Double,System-Double- 'DesktopMagicPluginAPI.Inputs.Slider.#ctor(System.Double,System.Double,System.Double)') @@ -525,7 +526,7 @@ 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') | 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. | +| mouseButton | [DesktopMagicPluginAPI.Inputs.MouseButton](#T-DesktopMagicPluginAPI-Inputs-MouseButton 'DesktopMagicPluginAPI.Inputs.MouseButton') | The button associated with the event. | ### OnMouseMove(position) `method` @@ -540,6 +541,20 @@ Occurs when the mouse pointer is moved over the control. | ---- | ---- | ----------- | | 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. | + +### OnMouseWheel(position,Delta) `method` + +##### Summary + +Occurs when the user rotates the mouse wheel while the mouse pointer is over this element. + +##### Parameters + +| 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') | The x- and y-coordinates of the mouse pointer position relative to the plugin window. | +| Delta | [System.Int32](http://msdn.microsoft.com/query/dev14.query?appId=Dev14IDEF1&l=EN-US&k=k:System.Int32 'System.Int32') | A value that indicates the amount that the mouse wheel has changed. | + ### Start() `method` diff --git a/src/DesktopMagicPluginAPI/DesktopMagicPluginAPI.xml b/src/DesktopMagicPluginAPI/DesktopMagicPluginAPI.xml index 2b97ae5..a02771b 100644 --- a/src/DesktopMagicPluginAPI/DesktopMagicPluginAPI.xml +++ b/src/DesktopMagicPluginAPI/DesktopMagicPluginAPI.xml @@ -317,7 +317,7 @@ 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. + The button associated with the event. @@ -325,5 +325,12 @@ The x- and y-coordinates of the mouse pointer position relative to the plugin window. + + + Occurs when the user rotates the mouse wheel while the mouse pointer is over this element. + + The x- and y-coordinates of the mouse pointer position relative to the plugin window. + A value that indicates the amount that the mouse wheel has changed. + diff --git a/src/DesktopMagicPluginAPI/Plugin.cs b/src/DesktopMagicPluginAPI/Plugin.cs index 6f141a8..abac60e 100644 --- a/src/DesktopMagicPluginAPI/Plugin.cs +++ b/src/DesktopMagicPluginAPI/Plugin.cs @@ -52,7 +52,7 @@ namespace DesktopMagicPluginAPI /// 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. + /// The button associated with the event. public virtual void OnMouseClick(Point position, MouseButton mouseButton) { } @@ -64,5 +64,14 @@ namespace DesktopMagicPluginAPI public virtual void OnMouseMove(Point position) { } + + /// + /// Occurs when the user rotates the mouse wheel while the mouse pointer is over this element. + /// + /// The x- and y-coordinates of the mouse pointer position relative to the plugin window. + /// A value that indicates the amount that the mouse wheel has changed. + public virtual void OnMouseWheel(Point position, int Delta) + { + } } } \ No newline at end of file