Browse Source

Made MouseEvent.ScreenX/Y a Point

Tig Kindel 1 year ago
parent
commit
916c0c6fdd

+ 3 - 6
Terminal.Gui/Application.cs

@@ -1411,8 +1411,7 @@ public static partial class Application
                 X = frameLoc.X,
                 Y = frameLoc.Y,
                 Flags = a.MouseEvent.Flags,
-                ScreenX = a.MouseEvent.X,
-                ScreenY = a.MouseEvent.Y,
+                ScreenPosition = new (a.MouseEvent.X, a.MouseEvent.Y),
                 View = view
             };
 
@@ -1468,8 +1467,7 @@ public static partial class Application
                 X = frameLoc.X,
                 Y = frameLoc.Y,
                 Flags = a.MouseEvent.Flags,
-                ScreenX = a.MouseEvent.X,
-                ScreenY = a.MouseEvent.Y,
+                ScreenPosition = new (a.MouseEvent.X, a.MouseEvent.Y),
                 View = view
             };
         }
@@ -1482,8 +1480,7 @@ public static partial class Application
                 X = boundsPoint.X,
                 Y = boundsPoint.Y,
                 Flags = a.MouseEvent.Flags,
-                ScreenX = a.MouseEvent.X,
-                ScreenY = a.MouseEvent.X,
+                ScreenPosition = new (a.MouseEvent.X, a.MouseEvent.Y),
                 View = view
             };
         }

+ 6 - 23
Terminal.Gui/Input/Mouse.cs

@@ -111,10 +111,10 @@ public class MouseEvent
     /// <summary>The View at the location for the mouse event.</summary>
     public View View { get; set; }
 
-    /// <summary>The X (column) location of the mouse in <see cref="View.Bounds"/>-relative coordinates.</summary>
+    /// <summary>The X position of the mouse in <see cref="View.Bounds"/>-relative coordinates.</summary>
     public int X { get; set; }
 
-    /// <summary>The Y (column) location of the mouse in <see cref="View.Bounds"/>-relative coordinates.</summary>
+    /// <summary>The Y position of the mouse in <see cref="View.Bounds"/>-relative coordinates.</summary>
     public int Y { get; set; }
 
     /// <summary>
@@ -124,36 +124,19 @@ public class MouseEvent
     public bool Handled { get; set; }
 
     /// <summary>
-    ///     The screen-relative mouse coordinate.
+    ///     The screen-relative mouse position.
     /// </summary>
     /// <remarks>
     ///     <para>
-    ///         Calculated and processed in <see cref="Application.OnMouseEvent(MouseEventEventArgs)"/>.
-    ///     </para>
-    ///     <para>
-    ///         The View that has called <see cref="Application.GrabMouse"/> will receive all mouse events
-    ///         with <see cref="View.Bounds"/>-relative coordinates. <see cref="ScreenX"/> and <see cref="ScreenY"/> provide
-    ///         the screen-relative offset of these coordinates, enabling the grabbed view to know how much the
+    ///         The <see cref="X"/> and <see cref="Y"/> properties are always <see cref="View.Bounds"/>-relative. When the mouse is grabbed by a view,
+    ///         <see cref="ScreenPosition"/> provides the mouse position screen-relative coordinates, enabling the grabbed view to know how much the
     ///         mouse has moved.
     ///     </para>
-    /// </remarks>
-    public int ScreenX { get; set; }
-
-    /// <summary>
-    ///     The screen-relative mouse coordinate.
-    /// </summary>
-    /// <remarks>
     ///     <para>
     ///         Calculated and processed in <see cref="Application.OnMouseEvent(MouseEventEventArgs)"/>.
     ///     </para>
-    ///     <para>
-    ///         The View that has called <see cref="Application.GrabMouse"/> will receive all mouse events
-    ///         with <see cref="View.Bounds"/>-relative coordinates. <see cref="ScreenX"/> and <see cref="ScreenY"/> provide
-    ///         the screen-relative offset of these coordinates, enabling the grabbed view to know how much the
-    ///         mouse has moved.
-    ///     </para>
     /// </remarks>
-    public int ScreenY { get; set; }
+    public Point ScreenPosition { get; set; }
 
     /// <summary>Returns a <see cref="T:System.String"/> that represents the current <see cref="MouseEvent"/>.</summary>
     /// <returns>A <see cref="T:System.String"/> that represents the current <see cref="MouseEvent"/>.</returns>

+ 2 - 4
Terminal.Gui/View/Adornment/Adornment.cs

@@ -221,9 +221,7 @@ public class Adornment : View
             if (Thickness.Contains (Frame, mouseEvent.X, mouseEvent.Y) && mouseEvent.Flags.HasFlag (MouseFlags.Button1Pressed))
             {
                 _startGrabPoint = new (mouseEvent.X, mouseEvent.Y);
-                nx = mouseEvent.ScreenX;
-                ny = mouseEvent.ScreenY;
-                _dragPosition = new Point (nx, ny);
+                _dragPosition = new (mouseEvent.X, mouseEvent.Y);
                 Application.GrabMouse (this);
             }
 
@@ -246,7 +244,7 @@ public class Adornment : View
 
                 _dragPosition = new Point (mouseEvent.X, mouseEvent.Y);
 
-                var parentLoc = Parent.SuperView?.ScreenToBounds (mouseEvent.ScreenX, mouseEvent.ScreenY) ?? new (mouseEvent.ScreenX, mouseEvent.ScreenY);
+                var parentLoc = Parent.SuperView?.ScreenToBounds (mouseEvent.ScreenPosition.X, mouseEvent.ScreenPosition.Y) ?? mouseEvent.ScreenPosition;
                 GetLocationThatFits (
                                      Parent,
                                      parentLoc.X - _startGrabPoint.X,