/// <summary> /// Converts a point from screen to client coordinates. /// </summary> /// <param name="visual">The visual.</param> /// <param name="point">The point in screen coordinates.</param> /// <returns>The point in client coordinates.</returns> public static Point PointToClient(this IVisual visual, PixelPoint point) { var(root, offset) = GetRootAndPosition(visual); var screenOffset = PixelPoint.FromPoint((Point)offset, root.RenderScaling); var screenPoint = new PixelPoint(point.X - screenOffset.X, point.Y - screenOffset.Y); return(root.PointToClient(screenPoint)); }
/// <summary> /// Converts a <see cref="Rect"/> to device pixels using the specified scaling factor. /// </summary> /// <param name="rect">The rect.</param> /// <param name="scale">The scaling factor.</param> /// <returns>The device-independent point.</returns> public static PixelRect FromRect(Rect rect, Vector scale) => new PixelRect( PixelPoint.FromPoint(rect.Position, scale), PixelSize.FromSize(rect.Size, scale));
/// <summary> /// Converts a <see cref="Rect"/> to device pixels using the specified scaling factor. /// </summary> /// <param name="rect">The rect.</param> /// <param name="scale">The scaling factor.</param> /// <returns>The device-independent point.</returns> public static PixelRect FromRect(Rect rect, Vector scale) => new PixelRect( PixelPoint.FromPoint(rect.Position, scale), FromPointCeiling(rect.BottomRight, scale));