Example #1
4
        public override void UpdateGeometry()
        {
            ScaleThickness = Image.State.Flags.HasFlag(ShapeStateFlags.Thickness);
            ScaleSize      = Image.State.Flags.HasFlag(ShapeStateFlags.Size);

            if (!string.IsNullOrEmpty(Image.Key))
            {
                ImageCached = BitmapCache.Get(Image.Key) as AMI.Bitmap;
                if (ImageCached == null && ImageCache != null)
                {
                    try
                    {
                        var bytes = ImageCache.GetImage(Image.Key);
                        if (bytes != null)
                        {
                            using var ms = new System.IO.MemoryStream(bytes);
                            ImageCached  = new AMI.Bitmap(ms);
                            BitmapCache.Set(Image.Key, ImageCached);
                        }
                    }
                    catch (Exception ex)
                    {
                        Debug.WriteLine($"{ex.Message}");
                        Debug.WriteLine($"{ex.StackTrace}");
                    }
                }

                if (ImageCached != null)
                {
                    SourceRect = new A.Rect(0, 0, ImageCached.PixelSize.Width, ImageCached.PixelSize.Height);
                }
            }
            else
            {
                ImageCached = null;
            }

            var rect2 = Rect2.FromPoints(Image.TopLeft.X, Image.TopLeft.Y, Image.BottomRight.X, Image.BottomRight.Y, 0, 0);

            DestRect = new A.Rect(rect2.X, rect2.Y, rect2.Width, rect2.Height);
            Center   = DestRect.Center;

            base.UpdateTextGeometry();
        }
 public ImageDrawCommand(AM.IImage?source, A.Rect sourceRect, A.Rect destRect, AVMI.BitmapInterpolationMode bitmapInterpolationMode)
 {
     Source     = source;
     SourceRect = sourceRect;
     DestRect   = destRect;
     BitmapInterpolationMode = bitmapInterpolationMode;
 }
Example #3
0
 public override void UpdateGeometry()
 {
     ScaleThickness = false;
     ScaleSize      = false;
     Rect           = new A.Rect(X, Y, Width, Height);
     Center         = Rect.Center;
 }
Example #4
0
 public RectangleDrawCommand(AM.IBrush?brush, AM.IPen?pen, A.Rect rect, double radiusX, double radiusY)
 {
     Brush   = brush;
     Pen     = pen;
     Rect    = rect;
     RadiusX = radiusX;
     RadiusY = radiusY;
 }
Example #5
0
        public static AM.Geometry ToGeometry(EllipseShapeViewModel ellipse)
        {
            var rect2 = Rect2.FromPoints(ellipse.TopLeft.X, ellipse.TopLeft.Y, ellipse.BottomRight.X, ellipse.BottomRight.Y);
            var rect  = new A.Rect(rect2.X, rect2.Y, rect2.Width, rect2.Height);
            var g     = new AM.EllipseGeometry(rect);

            return(g);
        }
Example #6
0
        /// <inheritdoc/>
        public override void Fill(object dc, double x, double y, double width, double height, ArgbColor color)
        {
            var _dc   = dc as AM.DrawingContext;
            var brush = ToBrush(color);
            var rect  = new A.Rect(x, y, width, height);

            _dc.FillRectangle(brush, rect);
        }
Example #7
0
        public override void UpdateGeometry()
        {
            ScaleThickness = true; // Point.State.HasFlag(ShapeStateFlags.Thickness);
            ScaleSize      = true; // Point.State.HasFlag(ShapeStateFlags.Size);
            var rect2 = Rect2.FromPoints(Point.X - PointSize, Point.Y - PointSize, Point.X + PointSize, Point.Y + PointSize, 0, 0);

            Rect   = new A.Rect(rect2.X, rect2.Y, rect2.Width, rect2.Height);
            Center = Rect.Center;
        }
Example #8
0
        public override void UpdateGeometry()
        {
            ScaleThickness = Rectangle.State.HasFlag(ShapeStateFlags.Thickness);
            ScaleSize      = Rectangle.State.HasFlag(ShapeStateFlags.Size);
            var rect2 = Rect2.FromPoints(Rectangle.TopLeft.X, Rectangle.TopLeft.Y, Rectangle.BottomRight.X, Rectangle.BottomRight.Y, 0, 0);

            Rect   = new A.Rect(rect2.X, rect2.Y, rect2.Width, rect2.Height);
            Center = Rect.Center;
        }
Example #9
0
    public sealed override void UpdateGeometry()
    {
        ScaleThickness = Text.State.HasFlag(ShapeStateFlags.Thickness);
        ScaleSize      = Text.State.HasFlag(ShapeStateFlags.Size);
        var rect2 = Rect2.FromPoints(Text.TopLeft.X, Text.TopLeft.Y, Text.BottomRight.X, Text.BottomRight.Y, 0, 0);

        Rect   = new A.Rect(rect2.X, rect2.Y, rect2.Width, rect2.Height);
        Center = Rect.Center;

        UpdateTextGeometry();
    }
Example #10
0
 public override void UpdateGeometry()
 {
     ScaleThickness = true;
     ScaleSize      = false;
     Rect           = new A.Rect(
         X + Grid.GridOffsetLeft,
         Y + Grid.GridOffsetTop,
         Width - Grid.GridOffsetLeft + Grid.GridOffsetRight,
         Height - Grid.GridOffsetTop + Grid.GridOffsetBottom);
     Center = Rect.Center;
 }
		public void Draw(TextView textView, DrawingContext drawingContext)
		{
			if (line > 0 && line < textView.TextDocument.LineCount)
			{
				var currentLine = textView.TextDocument.GetLineByNumber(line);

				var rects = VisualLineGeometryBuilder.GetRectsForSegment(textView, currentLine);

				foreach (var rect in rects)
				{
					var drawRect = new Rect(rect.TopLeft.X, rect.TopLeft.Y, textView.Bounds.Width, rect.Height);
					drawingContext.FillRectangle(selectedLineBg, drawRect);
				}
			}
		}
Example #12
0
        private static void DrawEllipseInternal(AM.DrawingContext dc, AM.IBrush brush, AM.Pen pen, bool isStroked, bool isFilled, ref Rect2 rect)
        {
            if (!isFilled && !isStroked)
            {
                return;
            }

            var r = new A.Rect(rect.X, rect.Y, rect.Width, rect.Height);
            var g = new AM.EllipseGeometry(r);

            dc.DrawGeometry(
                isFilled ? brush : null,
                isStroked ? pen : null,
                g);
        }
        public void Draw(TextView textView, DrawingContext drawingContext)
		{
			if (textView.SelectionStart == textView.SelectionEnd && textView.CaretIndex != -1 &&
				textView.CaretIndex <= textView.TextDocument.TextLength)
			{
				var currentLine = textView.TextDocument.GetLineByOffset(textView.CaretIndex);

				var rects = VisualLineGeometryBuilder.GetRectsForSegment(textView, currentLine);

				foreach (var rect in rects)
				{
					var drawRect = new Rect(rect.TopLeft.X, rect.TopLeft.Y, textView.Bounds.Width, rect.Height);
					drawingContext.FillRectangle(selectedLineBg, drawRect);
				}
			}
		}
Example #14
0
        public void DrawPoint(Point point, PointStyle style, bool fast)
        {
            Point viewPoint = (Point)Viewport.GetViewGeometry(point);

            A.Rect rect  = GetPointRect(viewPoint.Coordinate, style.Size);
            Brush  brush = GetBrush(style.FillStyle);
            Pen    pen   = GetPen(style.LineStyle);

            AM.Geometry geometry;
            if (style.Shape == PointShape.Circle)
            {
                geometry = new EllipseGeometry(rect);
            }
            else
            {
                geometry = new RectangleGeometry(rect);
            }
            m_Context.DrawGeometry(brush, pen, geometry);
        }
Example #15
0
        private static void DrawRectangleInternal(AM.DrawingContext dc, AM.IBrush brush, AM.Pen pen, bool isStroked, bool isFilled, ref Rect2 rect)
        {
            if (!isStroked && !isFilled)
            {
                return;
            }

            var r = new A.Rect(rect.X, rect.Y, rect.Width, rect.Height);

            if (isFilled)
            {
                dc.FillRectangle(brush, r);
            }

            if (isStroked)
            {
                dc.DrawRectangle(pen, r);
            }
        }
Example #16
0
        private void DrawCoordinates(Coordinate[] coords, PointStyle style, bool fast, bool skipLast = false)
        {
            Brush brush = GetBrush(style.FillStyle);
            Pen   pen   = GetPen(style.LineStyle);
            int   max   = (skipLast ? coords.Length - 1 : coords.Length);

            for (int i = 0; i < max; i++)
            {
                A.Rect      rect = GetPointRect(coords[i], style.Size);
                AM.Geometry geometry;
                if (style.Shape == PointShape.Circle)
                {
                    geometry = new EllipseGeometry(rect);
                }
                else
                {
                    geometry = new RectangleGeometry(rect);
                }
                m_Context.DrawGeometry(brush, pen, geometry);
            }
        }
Example #17
0
            protected override void OnRender(DrawingContext ctx)
            {
                ctx.FillRectangle(Brushes.Green, new Rect(0, 0, Width, Height));

                var rc = new Rect(0, 0, Width/3, Height/3);
                using (ctx.PushPostTransform(
                    Avalonia.Matrix.CreateTranslation(-Width/6, -Width/6)*
                    Avalonia.Matrix.CreateRotation(_radians)*
                                             Avalonia.Matrix.CreateTranslation(Width/2, Height/2)))
                {
                    ctx.FillRectangle(new LinearGradientBrush()
                    {
                        GradientStops =
                        {
                            new GradientStop() {Color = Colors.Blue},
                            new GradientStop(Colors.Red, 1)
                        }
                    }, rc, 5);
                }


            }
Example #18
0
        public static Rect Inflate(Rect rect, double width, double height)
        {
            if (width < rect.Width * -2)
            {
                return Rect.Empty;
            }

            if (height < rect.Height * -2)
            {
                return Rect.Empty;
            }

            Rect result = rect;
            result.Inflate(width, height);
            return result;
        }
Example #19
0
        private static void Record(CanvasCommand canvasCommand, AvaloniaPicture avaloniaPicture)
        {
            if (avaloniaPicture == null || avaloniaPicture._commands == null)
            {
                return;
            }

            switch (canvasCommand)
            {
            case ClipPathCanvasCommand clipPathCanvasCommand:
            {
                var path = clipPathCanvasCommand.ClipPath.ToGeometry(false);
                if (path != null)
                {
                    // TODO: clipPathCanvasCommand.Operation;
                    // TODO: clipPathCanvasCommand.Antialias;
                    avaloniaPicture._commands.Add(new GeometryClipDrawCommand(path));
                }
            }
            break;

            case ClipRectCanvasCommand clipRectCanvasCommand:
            {
                var rect = clipRectCanvasCommand.Rect.ToSKRect();
                // TODO: clipRectCanvasCommand.Operation;
                // TODO: clipRectCanvasCommand.Antialias;
                avaloniaPicture._commands.Add(new ClipDrawCommand(rect));
            }
            break;

            case SaveCanvasCommand _:
            {
                // TODO:
                avaloniaPicture._commands.Add(new SaveDrawCommand());
            }
            break;

            case RestoreCanvasCommand _:
            {
                // TODO:
                avaloniaPicture._commands.Add(new RestoreDrawCommand());
            }
            break;

            case SetMatrixCanvasCommand setMatrixCanvasCommand:
            {
                var matrix = setMatrixCanvasCommand.Matrix.ToMatrix();
                avaloniaPicture._commands.Add(new SetTransformDrawCommand(matrix));
            }
            break;

            case SaveLayerCanvasCommand saveLayerCanvasCommand:
            {
                // TODO:
                avaloniaPicture._commands.Add(new SaveLayerDrawCommand());
            }
            break;

            case DrawImageCanvasCommand drawImageCanvasCommand:
            {
                if (drawImageCanvasCommand.Image != null)
                {
                    var image = drawImageCanvasCommand.Image.ToBitmap();
                    if (image != null)
                    {
                        var source = drawImageCanvasCommand.Source.ToSKRect();
                        var dest   = drawImageCanvasCommand.Dest.ToSKRect();
                        var bitmapInterpolationMode = drawImageCanvasCommand.Paint?.FilterQuality.ToBitmapInterpolationMode() ?? AVMI.BitmapInterpolationMode.Default;
                        avaloniaPicture._commands.Add(new ImageDrawCommand(image, source, dest, bitmapInterpolationMode));
                    }
                }
            }
            break;

            case DrawPathCanvasCommand drawPathCanvasCommand:
            {
                if (drawPathCanvasCommand.Path != null && drawPathCanvasCommand.Paint != null)
                {
                    (var brush, var pen) = drawPathCanvasCommand.Paint.ToBrushAndPen();

                    if (drawPathCanvasCommand.Path.Commands?.Count == 1)
                    {
                        var pathCommand = drawPathCanvasCommand.Path.Commands[0];
                        var success     = false;

                        switch (pathCommand)
                        {
                        case AddRectPathCommand addRectPathCommand:
                        {
                            var rect = addRectPathCommand.Rect.ToSKRect();
                            avaloniaPicture._commands.Add(new RectangleDrawCommand(brush, pen, rect, 0, 0));
                            success = true;
                        }
                        break;

                        case AddRoundRectPathCommand addRoundRectPathCommand:
                        {
                            var rect = addRoundRectPathCommand.Rect.ToSKRect();
                            var rx   = addRoundRectPathCommand.Rx;
                            var ry   = addRoundRectPathCommand.Ry;
                            avaloniaPicture._commands.Add(new RectangleDrawCommand(brush, pen, rect, rx, ry));
                            success = true;
                        }
                        break;

                        case AddOvalPathCommand addOvalPathCommand:
                        {
                            var rect            = addOvalPathCommand.Rect.ToSKRect();
                            var ellipseGeometry = new AM.EllipseGeometry(rect);
                            avaloniaPicture._commands.Add(new GeometryDrawCommand(brush, pen, ellipseGeometry));
                            success = true;
                        }
                        break;

                        case AddCirclePathCommand addCirclePathCommand:
                        {
                            var x               = addCirclePathCommand.X;
                            var y               = addCirclePathCommand.Y;
                            var radius          = addCirclePathCommand.Radius;
                            var rect            = new A.Rect(x - radius, y - radius, radius + radius, radius + radius);
                            var ellipseGeometry = new AM.EllipseGeometry(rect);
                            avaloniaPicture._commands.Add(new GeometryDrawCommand(brush, pen, ellipseGeometry));
                            success = true;
                        }
                        break;

                        case AddPolyPathCommand addPolyPathCommand:
                        {
                            if (addPolyPathCommand.Points != null)
                            {
                                var points           = addPolyPathCommand.Points.ToPoints();
                                var close            = addPolyPathCommand.Close;
                                var polylineGeometry = new AM.PolylineGeometry(points, close);
                                avaloniaPicture._commands.Add(new GeometryDrawCommand(brush, pen, polylineGeometry));
                                success = true;
                            }
                        }
                        break;
                        }

                        if (success)
                        {
                            break;
                        }
                    }

                    if (drawPathCanvasCommand.Path.Commands?.Count == 2)
                    {
                        var pathCommand1 = drawPathCanvasCommand.Path.Commands[0];
                        var pathCommand2 = drawPathCanvasCommand.Path.Commands[1];

                        if (pathCommand1 is MoveToPathCommand moveTo && pathCommand2 is LineToPathCommand lineTo)
                        {
                            var p1 = new A.Point(moveTo.X, moveTo.Y);
                            var p2 = new A.Point(lineTo.X, lineTo.Y);
                            avaloniaPicture._commands.Add(new LineDrawCommand(pen, p1, p2));
                            break;
                        }
                    }

                    var geometry = drawPathCanvasCommand.Path.ToGeometry(brush != null);
                    if (geometry != null)
                    {
                        avaloniaPicture._commands.Add(new GeometryDrawCommand(brush, pen, geometry));
                    }
                }
            }
            break;

            case DrawTextBlobCanvasCommand drawPositionedTextCanvasCommand:
            {
                // TODO:
            }
            break;

            case DrawTextCanvasCommand drawTextCanvasCommand:
            {
                if (drawTextCanvasCommand.Paint != null)
                {
                    (var brush, _) = drawTextCanvasCommand.Paint.ToBrushAndPen();
                    var text   = drawTextCanvasCommand.Paint.ToFormattedText(drawTextCanvasCommand.Text);
                    var x      = drawTextCanvasCommand.X;
                    var y      = drawTextCanvasCommand.Y;
                    var origin = new A.Point(x, y - drawTextCanvasCommand.Paint.TextSize);
                    avaloniaPicture._commands.Add(new TextDrawCommand(brush, origin, text));
                }
            }
            break;

            case DrawTextOnPathCanvasCommand drawTextOnPathCanvasCommand:
            {
                // TODO:
            }
            break;

            default:
                break;
            }
        }
Example #20
0
 public static bool Equals(Rect rect1, Rect rect2)
 {
     return rect1.Equals(rect2);
 }
Example #21
0
 /// <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);
 }
Example #22
0
 /// <summary>
 /// Determines whether the rectangle fully contains another rectangle.
 /// </summary>
 /// <param name="r">The rectangle.</param>
 /// <returns>true if the rectangle is fully contained; otherwise false.</returns>
 public bool Contains(Rect r)
 {
     return Contains(r.TopLeft) && Contains(r.BottomRight);
 }
Example #23
0
 public static Rect Offset(Rect rect, double offsetX, double offsetY)
 {
     Rect result = rect;
     result.Offset(offsetX, offsetY);
     return result;
 }
Example #24
0
 public static Rect Transform(Rect rect, Matrix matrix)
 {
     Rect result = rect;
     result.Transform(matrix);
     return result;
 }
Example #25
0
 /// <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);
 }
Example #26
0
        private static void DrawRectangleInternal(AM.DrawingContext dc, AM.IBrush brush, AM.Pen pen, bool isStroked, bool isFilled, ref Rect2 rect)
        {
            if (!isStroked && !isFilled)
                return;

            var r = new A.Rect(rect.X, rect.Y, rect.Width, rect.Height);

            if (isFilled)
            {
                dc.FillRectangle(brush, r);
            }

            if (isStroked)
            {
                dc.DrawRectangle(pen, r);
            }
        }
Example #27
0
        protected sealed override void ArrangeCore(Rect finalRect)
        {
            Point origin = new Point(
                finalRect.Left + this.Margin.Left,
                finalRect.Top + this.Margin.Top);
            
            Size size = new Size(
                Math.Max(0, finalRect.Width - this.Margin.Left - this.Margin.Right),
                Math.Max(0, finalRect.Height - this.Margin.Top - this.Margin.Bottom));

            if (this.HorizontalAlignment != HorizontalAlignment.Stretch)
            {
                size = new Size(Math.Min(size.Width, this.DesiredSize.Width), size.Height);
            }

            if (this.VerticalAlignment != VerticalAlignment.Stretch)
            {
                size = new Size(size.Width, Math.Min(size.Height, this.DesiredSize.Height));
            }

            Size taken = this.ArrangeOverride(size);

            size = new Size(
                Math.Min(taken.Width, size.Width),
                Math.Min(taken.Height, size.Height));

            switch (this.HorizontalAlignment)
            {
                case HorizontalAlignment.Center:
                    origin.X += (finalRect.Width - size.Width) / 2;
                    break;
                case HorizontalAlignment.Right:
                    origin.X += finalRect.Width - size.Width;
                    break;
            }

            switch (this.VerticalAlignment)
            {
                case VerticalAlignment.Center:
                    origin.Y += (finalRect.Height - size.Height) / 2;
                    break;
                case VerticalAlignment.Bottom:
                    origin.Y += finalRect.Height - size.Height;
                    break;
            }

            base.ArrangeCore(new Rect(origin, size));
        }
Example #28
0
 protected virtual void ArrangeCore(Rect finalRect)
 {
     this.VisualOffset = (Vector)finalRect.TopLeft;
     this.RenderSize = finalRect.Size;
 }
Example #29
0
        private static void DrawEllipseInternal(AM.DrawingContext dc, AM.IBrush brush, AM.Pen pen, bool isStroked, bool isFilled, ref Rect2 rect)
        {
            if (!isFilled && !isStroked)
                return;

            var r = new A.Rect(rect.X, rect.Y, rect.Width, rect.Height);
            var g = new AM.EllipseGeometry(r);

            dc.DrawGeometry(
                isFilled ? brush : null,
                isStroked ? pen : null,
                g);
        }
Example #30
0
 public ClipDrawCommand(A.Rect clip)
 {
     Clip = clip;
 }
Example #31
0
    private MarkerBase CreateArrowMarker(double x, double y, double angle, ShapeStyleViewModel shapeStyleViewModel, ArrowStyleViewModel style)
    {
        switch (style.ArrowType)
        {
        default:
        {
            var marker = new NoneMarker();

            marker.ShapeViewModel      = Line;
            marker.ShapeStyleViewModel = shapeStyleViewModel;
            marker.Style = style;
            marker.Point = new A.Point(x, y);

            return(marker);
        }

        case ArrowType.Rectangle:
        {
            double rx = style.RadiusX;
            double ry = style.RadiusY;
            double sx = 2.0 * rx;
            double sy = 2.0 * ry;

            var marker = new RectangleMarker();

            marker.ShapeViewModel      = Line;
            marker.ShapeStyleViewModel = shapeStyleViewModel;
            marker.Style    = style;
            marker.Rotation = ACP.MatrixHelper.Rotation(angle, new A.Vector(x, y));
            marker.Point    = ACP.MatrixHelper.TransformPoint(marker.Rotation, new A.Point(x - sx, y));

            var rect2 = new Rect2(x - sx, y - ry, sx, sy);
            marker.Rect = new A.Rect(rect2.X, rect2.Y, rect2.Width, rect2.Height);

            return(marker);
        }

        case ArrowType.Ellipse:
        {
            double rx = style.RadiusX;
            double ry = style.RadiusY;
            double sx = 2.0 * rx;
            double sy = 2.0 * ry;

            var marker = new EllipseMarker();

            marker.ShapeViewModel      = Line;
            marker.ShapeStyleViewModel = shapeStyleViewModel;
            marker.Style    = style;
            marker.Rotation = ACP.MatrixHelper.Rotation(angle, new A.Vector(x, y));
            marker.Point    = ACP.MatrixHelper.TransformPoint(marker.Rotation, new A.Point(x - sx, y));

            var rect2 = new Rect2(x - sx, y - ry, sx, sy);
            var rect  = new A.Rect(rect2.X, rect2.Y, rect2.Width, rect2.Height);
            marker.EllipseGeometry = new AM.EllipseGeometry(rect);

            return(marker);
        }

        case ArrowType.Arrow:
        {
            double rx = style.RadiusX;
            double ry = style.RadiusY;
            double sx = 2.0 * rx;
            double sy = 2.0 * ry;

            var marker = new ArrowMarker();

            marker.ShapeViewModel      = Line;
            marker.ShapeStyleViewModel = shapeStyleViewModel;
            marker.Style    = style;
            marker.Rotation = ACP.MatrixHelper.Rotation(angle, new A.Vector(x, y));
            marker.Point    = ACP.MatrixHelper.TransformPoint(marker.Rotation, new A.Point(x, y));

            marker.P11 = ACP.MatrixHelper.TransformPoint(marker.Rotation, new A.Point(x - sx, y + sy));
            marker.P21 = ACP.MatrixHelper.TransformPoint(marker.Rotation, new A.Point(x, y));
            marker.P12 = ACP.MatrixHelper.TransformPoint(marker.Rotation, new A.Point(x - sx, y - sy));
            marker.P22 = ACP.MatrixHelper.TransformPoint(marker.Rotation, new A.Point(x, y));

            return(marker);
        }
        }
    }
Example #32
0
 public static Rect Inflate(Rect rect, Size size)
 {
     return Rect.Inflate(rect, size.Width, size.Height);
 }
Example #33
0
 public static Rect Union(Rect rect, Point point)
 {
     Rect result = rect;
     result.Union(point);
     return result;
 }
Example #34
0
 public static Rect Intersect(Rect rect1, Rect rect2)
 {
     Rect result = rect1;
     result.Intersect(rect2);
     return result;
 }
Example #35
0
        public bool Contains(Rect rect)
        {
            if (rect.Left < this.Left ||
                rect.Right > this.Right)
            {
                return false;
            }

            if (rect.Top < this.Top ||
                rect.Bottom > this.Bottom)
            {
                return false;
            }

            return true;
        }
Example #36
0
 public static Rect Offset(Rect rect, Vector offsetVector)
 {
     Rect result = rect;
     result.Offset(offsetVector);
     return result;
 }
Example #37
0
 public bool IntersectsWith(Rect rect)
 {
     return !((this.Left >= rect.Right) || (this.Right <= rect.Left) ||
         (this.Top >= rect.Bottom) || (this.Bottom <= rect.Top));
 }
Example #38
0
 public static Rect Union(Rect rect1, Rect rect2)
 {
     Rect result = rect1;
     result.Union(rect2);
     return result;
 }
Example #39
0
        /// <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;
            }
        }
Example #40
0
 public bool Equals(Rect value)
 {
     return this.x == value.X &&
            this.y == value.Y &&
            this.width == value.Width &&
            this.height == value.Height;
 }
Example #41
0
 public bool BringIntoView(IControl target, Rect targetRect)
 {
     throw new NotImplementedException();
 }
Example #42
0
        public void 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)
            {
                this.x = this.y = double.PositiveInfinity;
                this.width = this.height = double.NegativeInfinity;
            }
            else
            {
                this.x = x;
                this.y = y;
                this.width = width;
                this.height = height;
            }
        }
Example #43
0
        /// <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);
            }
        }
Example #44
0
        public void Union(Rect rect)
        {
            var left = Math.Min(this.Left, rect.Left);
            var top = Math.Min(this.Top, rect.Top);
            var right = Math.Max(this.Right, rect.Right);
            var bottom = Math.Max(this.Bottom, rect.Bottom);

            this.x = left;
            this.y = top;
            this.width = right - left;
            this.height = bottom - top;
        }
Example #45
0
 /// <inheritdoc/>
 public override void Fill(object dc, double x, double y, double width, double height, ArgbColor color)
 {
     var _dc = dc as AM.DrawingContext;
     var brush = ToBrush(color);
     var rect = new A.Rect(x, y, width, height);
     _dc.FillRectangle(brush, rect);
 }
Example #46
0
        public IInputElement InputHitTest(Point point)
        {
            Rect bounds = new Rect(this.RenderSize);

            if (bounds.Contains(point))
            {
                foreach (UIElement child in VisualTreeHelper.GetChildren(this).OfType<UIElement>())
                {
                    Point offsetPoint = point - child.VisualOffset;
                    IInputElement hit = child.InputHitTest(offsetPoint);

                    if (hit != null)
                    {
                        return hit;
                    }
                }

                return this;
            }
            else
            {
                return null;
            }
        }
Example #47
0
 /// <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);
 }