浏览代码

ScreenToViewport -> Point

Tig 1 年之前
父节点
当前提交
c03f349db4

+ 3 - 3
Terminal.Gui/Application.cs

@@ -1574,7 +1574,7 @@ public static partial class Application
         {
             // If the mouse is grabbed, send the event to the view that grabbed it.
             // The coordinates are relative to the Bounds of the view that grabbed the mouse.
-            Point frameLoc = MouseGrabView.ScreenToViewport (mouseEvent.X, mouseEvent.Y);
+            Point frameLoc = MouseGrabView.ScreenToViewport (new (mouseEvent.X, mouseEvent.Y));
 
             var viewRelativeMouseEvent = new MouseEvent
             {
@@ -1650,7 +1650,7 @@ public static partial class Application
         }
         else if (view.ViewportToScreen (Rectangle.Empty with { Size = view.Viewport.Size }).Contains (mouseEvent.X, mouseEvent.Y))
         {
-            Point viewportLocation = view.ScreenToViewport (mouseEvent.X, mouseEvent.Y);
+            Point viewportLocation = view.ScreenToViewport (new (mouseEvent.X, mouseEvent.Y));
 
             me = new ()
             {
@@ -1709,7 +1709,7 @@ public static partial class Application
                 break;
             }
 
-            Point boundsPoint = view.ScreenToViewport (mouseEvent.X, mouseEvent.Y);
+            Point boundsPoint = view.ScreenToViewport (new (mouseEvent.X, mouseEvent.Y));
 
             me = new ()
             {

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

@@ -135,9 +135,9 @@ public class Adornment : View
     }
 
     /// <inheritdoc/>
-    public override Point ScreenToFrame (Point screen)
+    public override Point ScreenToFrame (Point location)
     {
-        return Parent.ScreenToFrame (new (screen.X - Frame.X, screen.Y - Frame.Y));
+        return Parent.ScreenToFrame (new (location.X - Frame.X, location.Y - Frame.Y));
     }
 
     /// <summary>Does nothing for Adornment</summary>

+ 1 - 1
Terminal.Gui/View/Adornment/Border.cs

@@ -301,7 +301,7 @@ public class Border : Adornment
 
                 _dragPosition = new Point (mouseEvent.X, mouseEvent.Y);
 
-                Point parentLoc = Parent.SuperView?.ScreenToViewport (mouseEvent.ScreenPosition.X, mouseEvent.ScreenPosition.Y) ?? mouseEvent.ScreenPosition;
+                Point parentLoc = Parent.SuperView?.ScreenToViewport (new (mouseEvent.ScreenPosition.X, mouseEvent.ScreenPosition.Y)) ?? mouseEvent.ScreenPosition;
 
                 GetLocationEnsuringFullVisibility (
                                      Parent,

+ 6 - 6
Terminal.Gui/View/Layout/ViewLayout.cs

@@ -147,22 +147,22 @@ public partial class View
     ///     View's <see cref="SuperView"/>'s <see cref="Viewport"/>.
     /// </summary>
     /// <returns>The coordinate relative to the <see cref="SuperView"/>'s <see cref="Viewport"/>.</returns>
-    /// <param name="screen">Screen-relative coordinate.</param>
-    public virtual Point ScreenToFrame (Point screen)
+    /// <param name="location">Screen-relative coordinate.</param>
+    public virtual Point ScreenToFrame (Point location)
     {
         if (SuperView is null)
         {
-            return new (screen.X - Frame.X, screen.Y - Frame.Y);
+            return new (location.X - Frame.X, location.Y - Frame.Y);
         }
 
         Point superViewViewportOffset = SuperView.GetViewportOffsetFromFrame ();
         superViewViewportOffset.X -= SuperView.Viewport.X;
         superViewViewportOffset.Y -= SuperView.Viewport.Y;
 
-        screen.X -= superViewViewportOffset.X;
-        screen.Y -= superViewViewportOffset.Y;
+        location.X -= superViewViewportOffset.X;
+        location.Y -= superViewViewportOffset.Y;
 
-        Point frame = SuperView.ScreenToFrame (screen);
+        Point frame = SuperView.ScreenToFrame (location);
         frame.X -= Frame.X;
         frame.Y -= Frame.Y;
 

+ 5 - 6
Terminal.Gui/View/ViewContent.cs

@@ -446,15 +446,14 @@ public partial class View
     /// <remarks>
     ///     Viewport-relative means relative to the top-left corner of the inner rectangle of the <see cref="Padding"/>.
     /// </remarks>
-    /// <param name="x">Column relative to the left side of the Viewport.</param>
-    /// <param name="y">Row relative to the top of the Viewport</param>
-    public Point ScreenToViewport (int x, int y)
+    /// <param name="location">Screen-Relative Coordinate.</param>
+    public Point ScreenToViewport (in Point location)
     {
         Point viewportOffset = GetViewportOffsetFromFrame ();
-        Point screen = ScreenToFrame (new (x, y));
-        screen.Offset (-viewportOffset.X, -viewportOffset.Y);
+        Point frame = ScreenToFrame (location);
+        frame.Offset (-viewportOffset.X, -viewportOffset.Y);
 
-        return screen;
+        return frame;
     }
 
     /// <summary>

+ 1 - 1
Terminal.Gui/Views/Menu/Menu.cs

@@ -726,7 +726,7 @@ internal sealed class Menu : View
 
         View view = a.View ?? this;
 
-        Point boundsPoint = view.ScreenToViewport (a.X, a.Y);
+        Point boundsPoint = view.ScreenToViewport (new (a.X, a.Y));
         var me = new MouseEvent
         {
             X = boundsPoint.X,

+ 6 - 6
UnitTests/View/Layout/ScreenToTests.cs

@@ -32,7 +32,7 @@ public class ScreenToTests
             BorderStyle = LineStyle.Single
         };
 
-        Point actual = view.ScreenToViewport (x, y);
+        Point actual = view.ScreenToViewport (new (x, y));
         Assert.Equal (expectedX, actual.X);
         Assert.Equal (expectedY, actual.Y);
     }
@@ -54,7 +54,7 @@ public class ScreenToTests
     {
         var view = new View { X = viewX, Y = viewY, Width = 10, Height = 10 };
 
-        Point actual = view.ScreenToViewport (x, y);
+        Point actual = view.ScreenToViewport (new (x, y));
         Assert.Equal (expectedX, actual.X);
         Assert.Equal (expectedY, actual.Y);
     }
@@ -82,7 +82,7 @@ public class ScreenToTests
         var view = new View { X = viewX, Y = viewY, Width = 5, Height = 5 };
         super.Add (view);
 
-        Point actual = view.ScreenToViewport (x, y);
+        Point actual = view.ScreenToViewport (new (x, y));
         Assert.Equal (expectedX, actual.X);
         Assert.Equal (expectedY, actual.Y);
     }
@@ -113,7 +113,7 @@ public class ScreenToTests
 
         view.Viewport = new (1, 1, 5, 5);
 
-        Point actual = view.ScreenToViewport (x, y);
+        Point actual = view.ScreenToViewport (new (x, y));
         Assert.Equal (expectedX, actual.X);
         Assert.Equal (expectedY, actual.Y);
     }
@@ -134,7 +134,7 @@ public class ScreenToTests
         var view = new View { X = viewX, Y = viewY, Width = 5, Height = 5 };
         super.Add (view);
 
-        Point actual = view.ScreenToViewport (x, y);
+        Point actual = view.ScreenToViewport (new (x, y));
         Assert.Equal (expectedX, actual.X);
         Assert.Equal (expectedY, actual.Y);
     }
@@ -169,7 +169,7 @@ public class ScreenToTests
 
         view.Viewport = view.Viewport with { Location = new (1, 1) };
 
-        Point actual = view.ScreenToViewport (x, y);
+        Point actual = view.ScreenToViewport (new (x, y));
         Assert.Equal (expectedX, actual.X);
         Assert.Equal (expectedY, actual.Y);
     }