/// <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 dots per inch (DPI). /// </summary> /// <param name="rect">The rect.</param> /// <param name="dpi">The dots per inch of the device.</param> /// <returns>The device-independent point.</returns> public static PixelRect FromRectWithDpi(Rect rect, Vector dpi) => new PixelRect( PixelPoint.FromPointWithDpi(rect.Position, dpi), PixelSize.FromSizeWithDpi(rect.Size, dpi));
/// <summary> /// Determines whether a point in in the bounds of the rectangle. /// </summary> /// <param name="p">The point.</param> /// <returns>true if the point is in the bounds of the rectangle; otherwise false.</returns> public bool Contains(PixelPoint p) { return(p.X >= X && p.X <= Right && p.Y >= Y && p.Y <= Bottom); }
/// <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 rootPoint = visual.VisualRoot.PointToClient(point); return(visual.VisualRoot.TranslatePoint(rootPoint, visual).Value); }
/// <summary> /// Converts a <see cref="Rect"/> to device pixels using the specified dots per inch (DPI). /// </summary> /// <param name="rect">The rect.</param> /// <param name="dpi">The dots per inch of the device.</param> /// <returns>The device-independent point.</returns> public static PixelRect FromRectWithDpi(Rect rect, Vector dpi) => new PixelRect( PixelPoint.FromPointWithDpi(rect.Position, dpi), FromPointCeiling(rect.BottomRight, dpi / 96));
/// <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));
/// <summary> /// Determines whether a point is in the bounds of the rectangle, exclusive of the /// rectangle's bottom/right edge. /// </summary> /// <param name="p">The point.</param> /// <returns>true if the point is in the bounds of the rectangle; otherwise false.</returns> public bool ContainsExclusive(PixelPoint p) { return(p.X >= X && p.X < X + Width && p.Y >= Y && p.Y < Y + Height); }