ICSharpCode.AvalonEdit.Rendering.BackgroundGeometryBuilder.AddRectangle C# (CSharp) Method

AddRectangle() public method

Adds a rectangle to the geometry.
public AddRectangle ( double left, double top, double right, double bottom ) : void
left double
top double
right double
bottom double
return void
        public void AddRectangle(double left, double top, double right, double bottom)
        {
            if (!top.IsClose(lastBottom)) {
                CloseFigure();
            }
            if (figure == null) {
                figure = new PathFigure();
                figure.StartPoint = new Point(left, top + cornerRadius);
                if (Math.Abs(left - right) > cornerRadius) {
                    figure.Segments.Add(MakeArc(left + cornerRadius, top, SweepDirection.Clockwise));
                    figure.Segments.Add(MakeLineSegment(right - cornerRadius, top));
                    figure.Segments.Add(MakeArc(right, top + cornerRadius, SweepDirection.Clockwise));
                }
                figure.Segments.Add(MakeLineSegment(right, bottom - cornerRadius));
                insertionIndex = figure.Segments.Count;
                //figure.Segments.Add(MakeArc(left, bottom - cornerRadius, SweepDirection.Clockwise));
            } else {
                if (!lastRight.IsClose(right)) {
                    double cr = right < lastRight ? -cornerRadius : cornerRadius;
                    SweepDirection dir1 = right < lastRight ? SweepDirection.Clockwise : SweepDirection.Counterclockwise;
                    SweepDirection dir2 = right < lastRight ? SweepDirection.Counterclockwise : SweepDirection.Clockwise;
                    figure.Segments.Insert(insertionIndex++, MakeArc(lastRight + cr, lastBottom, dir1));
                    figure.Segments.Insert(insertionIndex++, MakeLineSegment(right - cr, top));
                    figure.Segments.Insert(insertionIndex++, MakeArc(right, top + cornerRadius, dir2));
                }
                figure.Segments.Insert(insertionIndex++, MakeLineSegment(right, bottom - cornerRadius));
                figure.Segments.Insert(insertionIndex, MakeLineSegment(lastLeft, lastTop + cornerRadius));
                if (!lastLeft.IsClose(left)) {
                    double cr = left < lastLeft ? cornerRadius : -cornerRadius;
                    SweepDirection dir1 = left < lastLeft ? SweepDirection.Counterclockwise : SweepDirection.Clockwise;
                    SweepDirection dir2 = left < lastLeft ? SweepDirection.Clockwise : SweepDirection.Counterclockwise;
                    figure.Segments.Insert(insertionIndex, MakeArc(lastLeft, lastBottom - cornerRadius, dir1));
                    figure.Segments.Insert(insertionIndex, MakeLineSegment(lastLeft - cr, lastBottom));
                    figure.Segments.Insert(insertionIndex, MakeArc(left + cr, lastBottom, dir2));
                }
            }
            this.lastTop = top;
            this.lastBottom = bottom;
            this.lastLeft = left;
            this.lastRight = right;
        }

Usage Example

        public void Draw(TextView textView, DrawingContext drawingContext)
        {
            if (!this.textView.Options.HighlightCurrentLine)
            {
                return;
            }

            BackgroundGeometryBuilder builder = new BackgroundGeometryBuilder();

            var visualLine = this.textView.GetVisualLine(line);

            if (visualLine == null)
            {
                return;
            }

            var linePosY = visualLine.VisualTop - this.textView.ScrollOffset.Y;

            builder.AddRectangle(textView, new Rect(0, linePosY, textView.ActualWidth, visualLine.Height));

            Geometry geometry = builder.CreateGeometry();

            if (geometry != null)
            {
                drawingContext.DrawGeometry(this.BackgroundBrush, this.BorderPen, geometry);
            }
        }
All Usage Examples Of ICSharpCode.AvalonEdit.Rendering.BackgroundGeometryBuilder::AddRectangle