Browse Source

ScreenToFrame -> Point

Tig 1 year ago
parent
commit
37a1464c7c

+ 1 - 1
Terminal.Gui/Application.cs

@@ -1637,7 +1637,7 @@ public static partial class Application
 
 
         if (view is Adornment adornment)
         if (view is Adornment adornment)
         {
         {
-            Point frameLoc = adornment.ScreenToFrame (mouseEvent.X, mouseEvent.Y);
+            Point frameLoc = adornment.ScreenToFrame (new (mouseEvent.X, mouseEvent.Y));
 
 
             me = new ()
             me = new ()
             {
             {

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

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

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

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

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

@@ -211,7 +211,7 @@ public partial class View
     public Point ScreenToContent (in Point location)
     public Point ScreenToContent (in Point location)
     {
     {
         Point viewportOffset = GetViewportOffsetFromFrame ();
         Point viewportOffset = GetViewportOffsetFromFrame ();
-        Point screen = ScreenToFrame (location.X, location.Y);
+        Point screen = ScreenToFrame (location);
         screen.Offset (Viewport.X - viewportOffset.X, Viewport.Y - viewportOffset.Y);
         screen.Offset (Viewport.X - viewportOffset.X, Viewport.Y - viewportOffset.Y);
 
 
         return screen;
         return screen;
@@ -451,7 +451,7 @@ public partial class View
     public Point ScreenToViewport (int x, int y)
     public Point ScreenToViewport (int x, int y)
     {
     {
         Point viewportOffset = GetViewportOffsetFromFrame ();
         Point viewportOffset = GetViewportOffsetFromFrame ();
-        Point screen = ScreenToFrame (x, y);
+        Point screen = ScreenToFrame (new (x, y));
         screen.Offset (-viewportOffset.X, -viewportOffset.Y);
         screen.Offset (-viewportOffset.X, -viewportOffset.Y);
 
 
         return screen;
         return screen;

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

@@ -1805,7 +1805,7 @@ public class MenuBar : View
 
 
                     if (me.Y > -1)
                     if (me.Y > -1)
                     {
                     {
-                        Point frameLoc = v.ScreenToFrame (me.X, me.Y);
+                        Point frameLoc = v.ScreenToFrame (new (me.X, me.Y));
 
 
                         nme = new ()
                         nme = new ()
                         {
                         {

+ 2 - 2
Terminal.Gui/Views/TileView.cs

@@ -219,7 +219,7 @@ public class TileView : View
                 bool isRoot = _splitterLines.Contains (line);
                 bool isRoot = _splitterLines.Contains (line);
 
 
                 Rectangle screen = line.ViewportToScreen (Rectangle.Empty);
                 Rectangle screen = line.ViewportToScreen (Rectangle.Empty);
-                Point origin = ScreenToFrame (screen.X, screen.Y);
+                Point origin = ScreenToFrame (screen.Location);
                 int length = line.Orientation == Orientation.Horizontal ? line.Frame.Width : line.Frame.Height;
                 int length = line.Orientation == Orientation.Horizontal ? line.Frame.Width : line.Frame.Height;
 
 
                 if (!isRoot)
                 if (!isRoot)
@@ -841,7 +841,7 @@ public class TileView : View
         public Point GetLocalCoordinateForTitle (TileView intoCoordinateSpace)
         public Point GetLocalCoordinateForTitle (TileView intoCoordinateSpace)
         {
         {
             Rectangle screen = Tile.ContentView.ViewportToScreen (Rectangle.Empty);
             Rectangle screen = Tile.ContentView.ViewportToScreen (Rectangle.Empty);
-            return intoCoordinateSpace.ScreenToFrame (screen.X, screen.Y - 1);
+            return intoCoordinateSpace.ScreenToFrame (new (screen.X, screen.Y - 1));
         }
         }
 
 
         internal string GetTrimmedTitle ()
         internal string GetTrimmedTitle ()

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

@@ -198,7 +198,7 @@ public class ScreenToTests
             BorderStyle = LineStyle.Single
             BorderStyle = LineStyle.Single
         };
         };
 
 
-        Point actual = view.ScreenToFrame (x, y);
+        Point actual = view.ScreenToFrame (new (x, y));
         Assert.Equal (expectedX, actual.X);
         Assert.Equal (expectedX, actual.X);
         Assert.Equal (expectedY, actual.Y);
         Assert.Equal (expectedY, actual.Y);
     }
     }
@@ -220,7 +220,7 @@ public class ScreenToTests
     {
     {
         var view = new View { X = viewX, Y = viewY, Width = 10, Height = 10 };
         var view = new View { X = viewX, Y = viewY, Width = 10, Height = 10 };
 
 
-        Point actual = view.ScreenToFrame (x, y);
+        Point actual = view.ScreenToFrame (new (x, y));
         Assert.Equal (expectedX, actual.X);
         Assert.Equal (expectedX, actual.X);
         Assert.Equal (expectedY, actual.Y);
         Assert.Equal (expectedY, actual.Y);
     }
     }
@@ -248,7 +248,7 @@ public class ScreenToTests
         var view = new View { X = viewX, Y = viewY, Width = 5, Height = 5 };
         var view = new View { X = viewX, Y = viewY, Width = 5, Height = 5 };
         super.Add (view);
         super.Add (view);
 
 
-        Point actual = view.ScreenToFrame (x, y);
+        Point actual = view.ScreenToFrame (new (x, y));
         Assert.Equal (expectedX, actual.X);
         Assert.Equal (expectedX, actual.X);
         Assert.Equal (expectedY, actual.Y);
         Assert.Equal (expectedY, actual.Y);
     }
     }
@@ -269,7 +269,7 @@ public class ScreenToTests
         var view = new View { X = viewX, Y = viewY, Width = 5, Height = 5 };
         var view = new View { X = viewX, Y = viewY, Width = 5, Height = 5 };
         super.Add (view);
         super.Add (view);
 
 
-        Point actual = view.ScreenToFrame (x, y);
+        Point actual = view.ScreenToFrame (new (x, y));
         Assert.Equal (expectedX, actual.X);
         Assert.Equal (expectedX, actual.X);
         Assert.Equal (expectedY, actual.Y);
         Assert.Equal (expectedY, actual.Y);
     }
     }

+ 18 - 18
UnitTests/View/NavigationTests.cs

@@ -851,7 +851,7 @@ public class NavigationTests
                                                          );
                                                          );
 
 
         // top
         // top
-        Assert.Equal (Point.Empty, top.ScreenToFrame (0, 0));
+        Assert.Equal (Point.Empty, top.ScreenToFrame (new (0, 0)));
         Rectangle screen = top.Margin.ViewportToScreen (new (0, 0, 0, 0));
         Rectangle screen = top.Margin.ViewportToScreen (new (0, 0, 0, 0));
         Assert.Equal (0, screen.X);
         Assert.Equal (0, screen.X);
         Assert.Equal (0, screen.Y);
         Assert.Equal (0, screen.Y);
@@ -872,7 +872,7 @@ public class NavigationTests
 
 
         Assert.Equal (0, found.Frame.X);
         Assert.Equal (0, found.Frame.X);
         Assert.Equal (0, found.Frame.Y);
         Assert.Equal (0, found.Frame.Y);
-        Assert.Equal (new Point (3, 2), top.ScreenToFrame (3, 2));
+        Assert.Equal (new Point (3, 2), top.ScreenToFrame (new (3, 2)));
         screen = top.ViewportToScreen (new (3, 2, 0, 0));
         screen = top.ViewportToScreen (new (3, 2, 0, 0));
         Assert.Equal (4, screen.X);
         Assert.Equal (4, screen.X);
         Assert.Equal (3, screen.Y);
         Assert.Equal (3, screen.Y);
@@ -884,7 +884,7 @@ public class NavigationTests
         Assert.Equal (top, found);
         Assert.Equal (top, found);
         //Assert.Equal (3, found.FrameToScreen ().X);
         //Assert.Equal (3, found.FrameToScreen ().X);
         //Assert.Equal (2, found.FrameToScreen ().Y);
         //Assert.Equal (2, found.FrameToScreen ().Y);
-        Assert.Equal (new Point (13, 2), top.ScreenToFrame (13, 2));
+        Assert.Equal (new Point (13, 2), top.ScreenToFrame (new (13, 2)));
         screen = top.ViewportToScreen (new (12, 2, 0, 0));
         screen = top.ViewportToScreen (new (12, 2, 0, 0));
         Assert.Equal (13, screen.X);
         Assert.Equal (13, screen.X);
         Assert.Equal (3, screen.Y);
         Assert.Equal (3, screen.Y);
@@ -899,7 +899,7 @@ public class NavigationTests
         Assert.Equal (top, found);
         Assert.Equal (top, found);
         //Assert.Equal (13, found.FrameToScreen ().X);
         //Assert.Equal (13, found.FrameToScreen ().X);
         //Assert.Equal (2, found.FrameToScreen ().Y);
         //Assert.Equal (2, found.FrameToScreen ().Y);
-        Assert.Equal (new Point (14, 3), top.ScreenToFrame (14, 3));
+        Assert.Equal (new Point (14, 3), top.ScreenToFrame (new (14, 3)));
         screen = top.ViewportToScreen (new (14, 3, 0, 0));
         screen = top.ViewportToScreen (new (14, 3, 0, 0));
         Assert.Equal (15, screen.X);
         Assert.Equal (15, screen.X);
         Assert.Equal (4, screen.Y);
         Assert.Equal (4, screen.Y);
@@ -909,7 +909,7 @@ public class NavigationTests
         //Assert.Equal (3, found.FrameToScreen ().Y);
         //Assert.Equal (3, found.FrameToScreen ().Y);
 
 
         // view
         // view
-        Assert.Equal (new Point (-4, -3), view.ScreenToFrame (0, 0));
+        Assert.Equal (new Point (-4, -3), view.ScreenToFrame (new (0, 0)));
         screen = view.Margin.ViewportToScreen (new (-3, -2, 0, 0));
         screen = view.Margin.ViewportToScreen (new (-3, -2, 0, 0));
         Assert.Equal (1, screen.X);
         Assert.Equal (1, screen.X);
         Assert.Equal (1, screen.Y);
         Assert.Equal (1, screen.Y);
@@ -928,21 +928,21 @@ public class NavigationTests
         found = View.FindDeepestView (top, 0, 0);
         found = View.FindDeepestView (top, 0, 0);
         Assert.Equal (top.Border, found);
         Assert.Equal (top.Border, found);
 
 
-        Assert.Equal (new Point (-1, -1), view.ScreenToFrame (3, 2));
+        Assert.Equal (new Point (-1, -1), view.ScreenToFrame (new (3, 2)));
         screen = view.ViewportToScreen (new (0, 0, 0, 0));
         screen = view.ViewportToScreen (new (0, 0, 0, 0));
         Assert.Equal (4, screen.X);
         Assert.Equal (4, screen.X);
         Assert.Equal (3, screen.Y);
         Assert.Equal (3, screen.Y);
         found = View.FindDeepestView (top, 4, 3);
         found = View.FindDeepestView (top, 4, 3);
         Assert.Equal (view, found);
         Assert.Equal (view, found);
 
 
-        Assert.Equal (new Point (9, -1), view.ScreenToFrame (13, 2));
+        Assert.Equal (new Point (9, -1), view.ScreenToFrame (new (13, 2)));
         screen = view.ViewportToScreen (new (10, 0, 0, 0));
         screen = view.ViewportToScreen (new (10, 0, 0, 0));
         Assert.Equal (14, screen.X);
         Assert.Equal (14, screen.X);
         Assert.Equal (3, screen.Y);
         Assert.Equal (3, screen.Y);
         found = View.FindDeepestView (top, 14, 3);
         found = View.FindDeepestView (top, 14, 3);
         Assert.Equal (top, found);
         Assert.Equal (top, found);
 
 
-        Assert.Equal (new Point (10, 0), view.ScreenToFrame (14, 3));
+        Assert.Equal (new Point (10, 0), view.ScreenToFrame (new (14, 3)));
         screen = view.ViewportToScreen (new (11, 1, 0, 0));
         screen = view.ViewportToScreen (new (11, 1, 0, 0));
         Assert.Equal (15, screen.X);
         Assert.Equal (15, screen.X);
         Assert.Equal (4, screen.Y);
         Assert.Equal (4, screen.Y);
@@ -1005,7 +1005,7 @@ public class NavigationTests
         Assert.Equal (new Rectangle (3, 2, 23, 10), frame);
         Assert.Equal (new Rectangle (3, 2, 23, 10), frame);
 
 
         // top
         // top
-        Assert.Equal (new Point (-3, -2), top.ScreenToFrame (0, 0));
+        Assert.Equal (new Point (-3, -2), top.ScreenToFrame (new (0, 0)));
         Rectangle screen = top.Margin.ViewportToScreen (new (-3, -2, 0, 0));
         Rectangle screen = top.Margin.ViewportToScreen (new (-3, -2, 0, 0));
         Assert.Equal (0, screen.X);
         Assert.Equal (0, screen.X);
         Assert.Equal (0, screen.Y);
         Assert.Equal (0, screen.Y);
@@ -1023,28 +1023,28 @@ public class NavigationTests
         Assert.Equal (0, screen.Y);
         Assert.Equal (0, screen.Y);
         var found = View.FindDeepestView (top, -4, -3);
         var found = View.FindDeepestView (top, -4, -3);
         Assert.Null (found);
         Assert.Null (found);
-        Assert.Equal (Point.Empty, top.ScreenToFrame (3, 2));
+        Assert.Equal (Point.Empty, top.ScreenToFrame (new (3, 2)));
         screen = top.ViewportToScreen (new (0, 0, 0, 0));
         screen = top.ViewportToScreen (new (0, 0, 0, 0));
         Assert.Equal (4, screen.X);
         Assert.Equal (4, screen.X);
         Assert.Equal (3, screen.Y);
         Assert.Equal (3, screen.Y);
         Assert.Equal (top.Border, View.FindDeepestView (top, 3, 2));
         Assert.Equal (top.Border, View.FindDeepestView (top, 3, 2));
         //Assert.Equal (0, found.FrameToScreen ().X);
         //Assert.Equal (0, found.FrameToScreen ().X);
         //Assert.Equal (0, found.FrameToScreen ().Y);
         //Assert.Equal (0, found.FrameToScreen ().Y);
-        Assert.Equal (new Point (10, 0), top.ScreenToFrame (13, 2));
+        Assert.Equal (new Point (10, 0), top.ScreenToFrame (new (13, 2)));
         screen = top.ViewportToScreen (new (10, 0, 0, 0));
         screen = top.ViewportToScreen (new (10, 0, 0, 0));
         Assert.Equal (14, screen.X);
         Assert.Equal (14, screen.X);
         Assert.Equal (3, screen.Y);
         Assert.Equal (3, screen.Y);
         Assert.Equal (top.Border, View.FindDeepestView (top, 13, 2));
         Assert.Equal (top.Border, View.FindDeepestView (top, 13, 2));
         //Assert.Equal (10, found.FrameToScreen ().X);
         //Assert.Equal (10, found.FrameToScreen ().X);
         //Assert.Equal (0, found.FrameToScreen ().Y);
         //Assert.Equal (0, found.FrameToScreen ().Y);
-        Assert.Equal (new Point (11, 1), top.ScreenToFrame (14, 3));
+        Assert.Equal (new Point (11, 1), top.ScreenToFrame (new (14, 3)));
         screen = top.ViewportToScreen (new (11, 1, 0, 0));
         screen = top.ViewportToScreen (new (11, 1, 0, 0));
         Assert.Equal (15, screen.X);
         Assert.Equal (15, screen.X);
         Assert.Equal (4, screen.Y);
         Assert.Equal (4, screen.Y);
         Assert.Equal (top, View.FindDeepestView (top, 14, 3));
         Assert.Equal (top, View.FindDeepestView (top, 14, 3));
 
 
         // view
         // view
-        Assert.Equal (new Point (-7, -5), view.ScreenToFrame (0, 0));
+        Assert.Equal (new Point (-7, -5), view.ScreenToFrame (new (0, 0)));
         screen = view.Margin.ViewportToScreen (new (-6, -4, 0, 0));
         screen = view.Margin.ViewportToScreen (new (-6, -4, 0, 0));
         Assert.Equal (1, screen.X);
         Assert.Equal (1, screen.X);
         Assert.Equal (1, screen.Y);
         Assert.Equal (1, screen.Y);
@@ -1058,27 +1058,27 @@ public class NavigationTests
         Assert.Equal (1, screen.X);
         Assert.Equal (1, screen.X);
         Assert.Equal (1, screen.Y);
         Assert.Equal (1, screen.Y);
         Assert.Null (View.FindDeepestView (top, 1, 1));
         Assert.Null (View.FindDeepestView (top, 1, 1));
-        Assert.Equal (new Point (-4, -3), view.ScreenToFrame (3, 2));
+        Assert.Equal (new Point (-4, -3), view.ScreenToFrame (new (3, 2)));
         screen = view.ViewportToScreen (new (-3, -2, 0, 0));
         screen = view.ViewportToScreen (new (-3, -2, 0, 0));
         Assert.Equal (4, screen.X);
         Assert.Equal (4, screen.X);
         Assert.Equal (3, screen.Y);
         Assert.Equal (3, screen.Y);
         Assert.Equal (top, View.FindDeepestView (top, 4, 3));
         Assert.Equal (top, View.FindDeepestView (top, 4, 3));
-        Assert.Equal (new Point (-1, -1), view.ScreenToFrame (6, 4));
+        Assert.Equal (new Point (-1, -1), view.ScreenToFrame (new (6, 4)));
         screen = view.ViewportToScreen (new (0, 0, 0, 0));
         screen = view.ViewportToScreen (new (0, 0, 0, 0));
         Assert.Equal (7, screen.X);
         Assert.Equal (7, screen.X);
         Assert.Equal (5, screen.Y);
         Assert.Equal (5, screen.Y);
         Assert.Equal (view, View.FindDeepestView (top, 7, 5));
         Assert.Equal (view, View.FindDeepestView (top, 7, 5));
-        Assert.Equal (new Point (6, -1), view.ScreenToFrame (13, 4));
+        Assert.Equal (new Point (6, -1), view.ScreenToFrame (new (13, 4)));
         screen = view.ViewportToScreen (new (7, 0, 0, 0));
         screen = view.ViewportToScreen (new (7, 0, 0, 0));
         Assert.Equal (14, screen.X);
         Assert.Equal (14, screen.X);
         Assert.Equal (5, screen.Y);
         Assert.Equal (5, screen.Y);
         Assert.Equal (view, View.FindDeepestView (top, 14, 5));
         Assert.Equal (view, View.FindDeepestView (top, 14, 5));
-        Assert.Equal (new Point (7, -2), view.ScreenToFrame (14, 3));
+        Assert.Equal (new Point (7, -2), view.ScreenToFrame (new (14, 3)));
         screen = view.ViewportToScreen (new (8, -1, 0, 0));
         screen = view.ViewportToScreen (new (8, -1, 0, 0));
         Assert.Equal (15, screen.X);
         Assert.Equal (15, screen.X);
         Assert.Equal (4, screen.Y);
         Assert.Equal (4, screen.Y);
         Assert.Equal (top, View.FindDeepestView (top, 15, 4));
         Assert.Equal (top, View.FindDeepestView (top, 15, 4));
-        Assert.Equal (new Point (16, -2), view.ScreenToFrame (23, 3));
+        Assert.Equal (new Point (16, -2), view.ScreenToFrame (new (23, 3)));
         screen = view.ViewportToScreen (new (17, -1, 0, 0));
         screen = view.ViewportToScreen (new (17, -1, 0, 0));
         Assert.Equal (24, screen.X);
         Assert.Equal (24, screen.X);
         Assert.Equal (4, screen.Y);
         Assert.Equal (4, screen.Y);