Browse Source

added usefull TransalePoint extension method to IVisual

pull/793/head
donandren 10 years ago
parent
commit
80ce8412c0
  1. 16
      src/Avalonia.Visuals/VisualExtensions.cs

16
src/Avalonia.Visuals/VisualExtensions.cs

@ -45,6 +45,22 @@ namespace Avalonia
return p.Item1.PointToScreen(point + p.Item2); 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> /// <summary>
/// Gets the root of the control's visual tree and the position of the control /// Gets the root of the control's visual tree and the position of the control
/// in the root's coordinate space. /// in the root's coordinate space.

Loading…
Cancel
Save