/// <summary> /// Centers another rectangle in this rectangle. /// </summary> /// <param name="rect">The rectangle to center.</param> /// <returns>The centered rectangle.</returns> public Rect CenterIn(Rect rect) { return new Rect( this.x + ((this.width - rect.width) / 2), this.y + ((this.height - rect.height) / 2), rect.width, rect.height); }
/// <summary> /// Gets the intersection of two rectangles. /// </summary> /// <param name="rect">The other rectangle.</param> /// <returns>The intersection.</returns> public Rect Intersect(Rect rect) { double x = Math.Max(this.x, rect.x); double y = Math.Max(this.y, rect.y); double width = Math.Min(this.Right, rect.Right) - x; double height = Math.Min(this.Bottom, rect.Bottom) - y; if (width < 0 || height < 0) { return new Rect( double.PositiveInfinity, double.PositiveInfinity, double.NegativeInfinity, double.NegativeInfinity); } else { return new Rect(x, y, width, height); } }
/// <summary> /// Determines whether a rectangle intersects with this rectangle. /// </summary> /// <param name="rect">The other rectangle.</param> /// <returns> /// True if the specified rectangle intersects with this one; otherwise false. /// </returns> public bool Intersects(Rect rect) { return (rect.X < Right) && (X < rect.Right) && (rect.Y < Bottom) && (Y < rect.Bottom); }
/// <summary> /// /// </summary> /// <param name="dc"></param> /// <param name="c"></param> /// <param name="width"></param> /// <param name="height"></param> private void DrawBackground(DrawingContext dc, ArgbColor c, double width, double height) { var color = Color.FromArgb(c.A, c.R, c.G, c.B); var brush = new SolidColorBrush(color); var rect = new Rect(0, 0, width, height); dc.FillRectangle(brush, rect); // TODO: brush.Dispose(); }
/// <summary> /// Centers another rectangle in this rectangle. /// </summary> /// <param name="rect">The rectangle to center.</param> /// <returns>The centered rectangle.</returns> public Rect CenterIn(Rect rect) { return new Rect( _x + ((_width - rect._width) / 2), _y + ((_height - rect._height) / 2), rect._width, rect._height); }
/// <summary> /// Gets the intersection of two rectangles. /// </summary> /// <param name="rect">The other rectangle.</param> /// <returns>The intersection.</returns> public Rect Intersect(Rect rect) { var newLeft = (rect.X > X) ? rect.X : X; var newTop = (rect.Y > Y) ? rect.Y : Y; var newRight = (rect.Right < Right) ? rect.Right : Right; var newBottom = (rect.Bottom < Bottom) ? rect.Bottom : Bottom; if ((newRight > newLeft) && (newBottom > newTop)) { return new Rect(newLeft, newTop, newRight - newLeft, newBottom - newTop); } else { return Empty; } }
/// <summary> /// /// </summary> /// <param name="dc"></param> /// <param name="brush"></param> /// <param name="pen"></param> /// <param name="isStroked"></param> /// <param name="isFilled"></param> /// <param name="rect"></param> private static void DrawRectangleInternal( IDrawingContext dc, Brush brush, Pen pen, bool isStroked, bool isFilled, ref Rect2 rect) { if (!isStroked && !isFilled) return; var r = new Rect(rect.X, rect.Y, rect.Width, rect.Height); if (isFilled) { dc.FillRectangle(brush, r); } if (isStroked) { dc.DrawRectangle(pen, r); } }
/// <summary> /// /// </summary> /// <param name="dc"></param> /// <param name="container"></param> private void DrawBackgroundInternal(IDrawingContext dc, Container container) { Brush brush = ToSolidBrush(container.Background); var rect = new Rect(0, 0, container.Width, container.Height); dc.FillRectangle(brush, rect); // TODO: brush.Dispose(); }
/// <summary> /// /// </summary> /// <param name="dc"></param> /// <param name="brush"></param> /// <param name="pen"></param> /// <param name="isStroked"></param> /// <param name="isFilled"></param> /// <param name="rect"></param> private static void DrawEllipseInternal( IDrawingContext dc, Brush brush, Pen pen, bool isStroked, bool isFilled, ref Rect2 rect) { if (!isFilled && !isStroked) return; var r = new Rect(rect.X, rect.Y, rect.Width, rect.Height); var g = new EllipseGeometry(r); dc.DrawGeometry( isFilled ? brush : null, isStroked ? pen : null, g); // TODO: g.Dispose(); }
/// <summary> /// Render the html using the given device. /// </summary> /// <param name="g">the device to use to render</param> /// <param name="clip">the clip rectangle of the html container</param> public void PerformPaint(DrawingContext g, Rect clip) { ArgChecker.AssertArgNotNull(g, "g"); using (var ig = new GraphicsAdapter(g, Util.Convert(clip))) { _htmlContainerInt.PerformPaint(ig); } }
/// <summary> /// Convert from WPF rectangle to core rectangle. /// </summary> public static RRect Convert(Rect r) { return new RRect(r.X, r.Y, r.Width, r.Height); }
protected override void OnMouseMove(MouseEventArgs e) { var res = _text.HitTestPoint(new Point(e.X, e.Y) - _textPos); if (res.IsInside) { _textRect = _text.HitTestTextPosition(res.TextPosition); _textRect = new Rect(_textRect.Position + _textPos, _textRect.Size); _textString = _text.Text.Substring(res.TextPosition, 1); } else _textRect = new Rect(); UpdateTitle(); base.OnMouseMove(e); }
private void DrawRoundRect(DrawingContext ctx) { ctx.FillRectangle(new SolidColorBrush(Colors.White), new Rect(new Size(ClientSize.Width, ClientSize.Height))); var rc = new Rect(0, 0, 60, 60); var transform = GetTransform(); using (ctx.PushPostTransform(transform)) { ctx.FillRectangle(new SolidColorBrush(Colors.Aqua), rc, 20); ctx.DrawRectangle(new Pen(new SolidColorBrush(Colors.Magenta), 10), rc, 20); } }