Browse Source

Merge pull request #793 from donandren/issues/screentoclient

Fixed PointToClient and added TranslatePoint
pull/794/head
Steven Kirk 10 years ago
committed by GitHub
parent
commit
db28cd621c
  1. 18
      src/Avalonia.Visuals/VisualExtensions.cs

18
src/Avalonia.Visuals/VisualExtensions.cs

@ -30,7 +30,7 @@ namespace Avalonia
public static Point PointToClient(this IVisual visual, Point point)
{
var p = GetRootAndPosition(visual);
return p.Item1.PointToClient(point + p.Item2);
return p.Item1.PointToClient(point - p.Item2);
}
/// <summary>
@ -45,6 +45,22 @@ namespace Avalonia
return p.Item1.PointToScreen(point + p.Item2);
}
/// <summary>
/// Translates a point relative to this visual to coordinates that are relative to the specified visual.
/// The visual and relativeTo should be descendants of the same root window
/// </summary>
/// <param name="visual">The visual.</param>
/// <param name="point">The point value, as relative to this visual.</param>
/// <param name="relativeTo">The visual to translate the given point into.</param>
/// <returns>A point value, now relative to the target visual rather than this source element.</returns>
public static Point TranslatePoint(this IVisual visual, Point point, IVisual relativeTo)
{
var pos = GetRootAndPosition(visual);
var relToPos = GetRootAndPosition(relativeTo);
return point - (relToPos.Item2 - pos.Item2);
}
/// <summary>
/// Gets the root of the control's visual tree and the position of the control
/// in the root's coordinate space.

Loading…
Cancel
Save