mirror of
https://github.com/gui-cs/Terminal.Gui.git
synced 2025-12-26 15:57:56 +01:00
ScreenToFrame -> Point
This commit is contained in:
@@ -1637,7 +1637,7 @@ public static partial class Application
|
||||
|
||||
if (view is Adornment adornment)
|
||||
{
|
||||
Point frameLoc = adornment.ScreenToFrame (mouseEvent.X, mouseEvent.Y);
|
||||
Point frameLoc = adornment.ScreenToFrame (new (mouseEvent.X, mouseEvent.Y));
|
||||
|
||||
me = new ()
|
||||
{
|
||||
|
||||
@@ -135,7 +135,10 @@ public class Adornment : View
|
||||
}
|
||||
|
||||
/// <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>
|
||||
/// <returns></returns>
|
||||
|
||||
@@ -147,23 +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="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)
|
||||
{
|
||||
return new (x - Frame.X, y - Frame.Y);
|
||||
return new (screen.X - Frame.X, screen.Y - Frame.Y);
|
||||
}
|
||||
|
||||
Point superViewViewportOffset = SuperView.GetViewportOffsetFromFrame ();
|
||||
superViewViewportOffset.X -= SuperView.Viewport.X;
|
||||
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.Y -= Frame.Y;
|
||||
|
||||
|
||||
@@ -211,7 +211,7 @@ public partial class View
|
||||
public Point ScreenToContent (in Point location)
|
||||
{
|
||||
Point viewportOffset = GetViewportOffsetFromFrame ();
|
||||
Point screen = ScreenToFrame (location.X, location.Y);
|
||||
Point screen = ScreenToFrame (location);
|
||||
screen.Offset (Viewport.X - viewportOffset.X, Viewport.Y - viewportOffset.Y);
|
||||
|
||||
return screen;
|
||||
@@ -451,7 +451,7 @@ public partial class View
|
||||
public Point ScreenToViewport (int x, int y)
|
||||
{
|
||||
Point viewportOffset = GetViewportOffsetFromFrame ();
|
||||
Point screen = ScreenToFrame (x, y);
|
||||
Point screen = ScreenToFrame (new (x, y));
|
||||
screen.Offset (-viewportOffset.X, -viewportOffset.Y);
|
||||
|
||||
return screen;
|
||||
|
||||
@@ -1805,7 +1805,7 @@ public class MenuBar : View
|
||||
|
||||
if (me.Y > -1)
|
||||
{
|
||||
Point frameLoc = v.ScreenToFrame (me.X, me.Y);
|
||||
Point frameLoc = v.ScreenToFrame (new (me.X, me.Y));
|
||||
|
||||
nme = new ()
|
||||
{
|
||||
|
||||
@@ -219,7 +219,7 @@ public class TileView : View
|
||||
bool isRoot = _splitterLines.Contains (line);
|
||||
|
||||
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;
|
||||
|
||||
if (!isRoot)
|
||||
@@ -841,7 +841,7 @@ public class TileView : View
|
||||
public Point GetLocalCoordinateForTitle (TileView intoCoordinateSpace)
|
||||
{
|
||||
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 ()
|
||||
|
||||
@@ -198,7 +198,7 @@ public class ScreenToTests
|
||||
BorderStyle = LineStyle.Single
|
||||
};
|
||||
|
||||
Point actual = view.ScreenToFrame (x, y);
|
||||
Point actual = view.ScreenToFrame (new (x, y));
|
||||
Assert.Equal (expectedX, actual.X);
|
||||
Assert.Equal (expectedY, actual.Y);
|
||||
}
|
||||
@@ -220,7 +220,7 @@ public class ScreenToTests
|
||||
{
|
||||
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 (expectedY, actual.Y);
|
||||
}
|
||||
@@ -248,7 +248,7 @@ public class ScreenToTests
|
||||
var view = new View { X = viewX, Y = viewY, Width = 5, Height = 5 };
|
||||
super.Add (view);
|
||||
|
||||
Point actual = view.ScreenToFrame (x, y);
|
||||
Point actual = view.ScreenToFrame (new (x, y));
|
||||
Assert.Equal (expectedX, actual.X);
|
||||
Assert.Equal (expectedY, actual.Y);
|
||||
}
|
||||
@@ -269,7 +269,7 @@ public class ScreenToTests
|
||||
var view = new View { X = viewX, Y = viewY, Width = 5, Height = 5 };
|
||||
super.Add (view);
|
||||
|
||||
Point actual = view.ScreenToFrame (x, y);
|
||||
Point actual = view.ScreenToFrame (new (x, y));
|
||||
Assert.Equal (expectedX, actual.X);
|
||||
Assert.Equal (expectedY, actual.Y);
|
||||
}
|
||||
|
||||
@@ -851,7 +851,7 @@ public class NavigationTests
|
||||
);
|
||||
|
||||
// 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));
|
||||
Assert.Equal (0, screen.X);
|
||||
Assert.Equal (0, screen.Y);
|
||||
@@ -872,7 +872,7 @@ public class NavigationTests
|
||||
|
||||
Assert.Equal (0, found.Frame.X);
|
||||
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));
|
||||
Assert.Equal (4, screen.X);
|
||||
Assert.Equal (3, screen.Y);
|
||||
@@ -884,7 +884,7 @@ public class NavigationTests
|
||||
Assert.Equal (top, found);
|
||||
//Assert.Equal (3, found.FrameToScreen ().X);
|
||||
//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));
|
||||
Assert.Equal (13, screen.X);
|
||||
Assert.Equal (3, screen.Y);
|
||||
@@ -899,7 +899,7 @@ public class NavigationTests
|
||||
Assert.Equal (top, found);
|
||||
//Assert.Equal (13, found.FrameToScreen ().X);
|
||||
//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));
|
||||
Assert.Equal (15, screen.X);
|
||||
Assert.Equal (4, screen.Y);
|
||||
@@ -909,7 +909,7 @@ public class NavigationTests
|
||||
//Assert.Equal (3, found.FrameToScreen ().Y);
|
||||
|
||||
// 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));
|
||||
Assert.Equal (1, screen.X);
|
||||
Assert.Equal (1, screen.Y);
|
||||
@@ -928,21 +928,21 @@ public class NavigationTests
|
||||
found = View.FindDeepestView (top, 0, 0);
|
||||
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));
|
||||
Assert.Equal (4, screen.X);
|
||||
Assert.Equal (3, screen.Y);
|
||||
found = View.FindDeepestView (top, 4, 3);
|
||||
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));
|
||||
Assert.Equal (14, screen.X);
|
||||
Assert.Equal (3, screen.Y);
|
||||
found = View.FindDeepestView (top, 14, 3);
|
||||
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));
|
||||
Assert.Equal (15, screen.X);
|
||||
Assert.Equal (4, screen.Y);
|
||||
@@ -1005,7 +1005,7 @@ public class NavigationTests
|
||||
Assert.Equal (new Rectangle (3, 2, 23, 10), frame);
|
||||
|
||||
// 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));
|
||||
Assert.Equal (0, screen.X);
|
||||
Assert.Equal (0, screen.Y);
|
||||
@@ -1023,28 +1023,28 @@ public class NavigationTests
|
||||
Assert.Equal (0, screen.Y);
|
||||
var found = View.FindDeepestView (top, -4, -3);
|
||||
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));
|
||||
Assert.Equal (4, screen.X);
|
||||
Assert.Equal (3, screen.Y);
|
||||
Assert.Equal (top.Border, View.FindDeepestView (top, 3, 2));
|
||||
//Assert.Equal (0, found.FrameToScreen ().X);
|
||||
//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));
|
||||
Assert.Equal (14, screen.X);
|
||||
Assert.Equal (3, screen.Y);
|
||||
Assert.Equal (top.Border, View.FindDeepestView (top, 13, 2));
|
||||
//Assert.Equal (10, found.FrameToScreen ().X);
|
||||
//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));
|
||||
Assert.Equal (15, screen.X);
|
||||
Assert.Equal (4, screen.Y);
|
||||
Assert.Equal (top, View.FindDeepestView (top, 14, 3));
|
||||
|
||||
// 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));
|
||||
Assert.Equal (1, screen.X);
|
||||
Assert.Equal (1, screen.Y);
|
||||
@@ -1058,27 +1058,27 @@ public class NavigationTests
|
||||
Assert.Equal (1, screen.X);
|
||||
Assert.Equal (1, screen.Y);
|
||||
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));
|
||||
Assert.Equal (4, screen.X);
|
||||
Assert.Equal (3, screen.Y);
|
||||
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));
|
||||
Assert.Equal (7, screen.X);
|
||||
Assert.Equal (5, screen.Y);
|
||||
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));
|
||||
Assert.Equal (14, screen.X);
|
||||
Assert.Equal (5, screen.Y);
|
||||
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));
|
||||
Assert.Equal (15, screen.X);
|
||||
Assert.Equal (4, screen.Y);
|
||||
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));
|
||||
Assert.Equal (24, screen.X);
|
||||
Assert.Equal (4, screen.Y);
|
||||
|
||||
Reference in New Issue
Block a user