public void Draw(TextView textView, DrawingContext drawingContext)
            {
                var s = Element.Segment;

                if (s != null)
                {
                    var geoBuilder = new BackgroundGeometryBuilder
                    {
                        AlignToWholePixels = true,
                        BorderThickness    = ActiveBorderPen?.Thickness ?? 0
                    };
                    if (Layer == KnownLayer.Background)
                    {
                        geoBuilder.AddSegment(textView, s);
                        drawingContext.DrawGeometry(BackgroundBrush, null, geoBuilder.CreateGeometry());
                    }
                    else
                    {
                        // draw foreground only if active
                        if (Element._isCaretInside)
                        {
                            geoBuilder.AddSegment(textView, s);
                            foreach (var boundElement in Element._context.ActiveElements.OfType <BoundActiveElement>())
                            {
                                if (boundElement.TargetElement == Element)
                                {
                                    geoBuilder.AddSegment(textView, boundElement.Segment);
                                    geoBuilder.CloseFigure();
                                }
                            }
                            drawingContext.DrawGeometry(null, ActiveBorderPen, geoBuilder.CreateGeometry());
                        }
                    }
                }
            }
Exemple #2
0
            public void Draw(TextView textView, System.Windows.Media.DrawingContext drawingContext)
            {
                ISegment s = element.Segment;

                if (s != null)
                {
                    BackgroundGeometryBuilder geoBuilder = new BackgroundGeometryBuilder();
                    geoBuilder.AlignToMiddleOfPixels = true;
                    if (Layer == KnownLayer.Background)
                    {
                        geoBuilder.AddSegment(textView, s);
                        drawingContext.DrawGeometry(backgroundBrush, null, geoBuilder.CreateGeometry());
                    }
                    else
                    {
                        // draw foreground only if active
                        if (element.isCaretInside)
                        {
                            geoBuilder.AddSegment(textView, s);
                            foreach (BoundActiveElement boundElement in element.context.ActiveElements.OfType <BoundActiveElement>())
                            {
                                if (boundElement.targetElement == element)
                                {
                                    geoBuilder.AddSegment(textView, boundElement.Segment);
                                    geoBuilder.CloseFigure();
                                }
                            }
                            drawingContext.DrawGeometry(null, activeBorderPen, geoBuilder.CreateGeometry());
                        }
                    }
                }
            }
        public void Draw(TextView textView, DrawingContext drawingContext)
        {
            if (this.result == null)
            {
                return;
            }

            BackgroundGeometryBuilder builder = new BackgroundGeometryBuilder();

            builder.CornerRadius          = 1;
            builder.AlignToMiddleOfPixels = true;

            builder.AddSegment(textView, new TextSegment()
            {
                StartOffset = result.OpeningBracketOffset, Length = result.OpeningBracketLength
            });
            builder.CloseFigure(); // prevent connecting the two segments
            builder.AddSegment(textView, new TextSegment()
            {
                StartOffset = result.ClosingBracketOffset, Length = result.ClosingBracketLength
            });

            Geometry geometry = builder.CreateGeometry();

            if (borderPen == null)
            {
                this.UpdateColors(DefaultBackground, DefaultBackground);
            }

            if (geometry != null)
            {
                drawingContext.DrawGeometry(backgroundBrush, borderPen, geometry);
            }
        }
Exemple #4
0
        public void Draw(TextView textView, DrawingContext drawingContext)
        {
            if (BraceMatchingResult == null)
            {
                return;
            }

            BackgroundGeometryBuilder builder = new BackgroundGeometryBuilder();

            builder.CornerRadius       = 1;
            builder.AlignToWholePixels = true;

            builder.AddSegment(textView, new TextSegment()
            {
                StartOffset = BraceMatchingResult.Value.LeftSpan.Start, Length = BraceMatchingResult.Value.LeftSpan.Length
            });
            builder.CloseFigure(); // prevent connecting the two segments
            builder.AddSegment(textView, new TextSegment()
            {
                StartOffset = BraceMatchingResult.Value.RightSpan.Start, Length = BraceMatchingResult.Value.RightSpan.Length
            });

            Geometry geometry = builder.CreateGeometry();

            drawingContext.DrawGeometry(_backgroundBrush, _borderPen, geometry);
        }
        public void Draw(TextView textView, DrawingContext drawingContext)
        {
            if (!Enabled)
            {
                return;
            }
            BackgroundGeometryBuilder builder = new BackgroundGeometryBuilder();

            builder.CornerRadius       = 1;
            builder.AlignToWholePixels = true;

            builder.AddSegment(textView, new TextSegment()
            {
                StartOffset = Begin, Length = 1
            });
            builder.CloseFigure();
            builder.AddSegment(textView, new TextSegment()
            {
                StartOffset = End, Length = 1
            });

            Geometry geometry = builder.CreateGeometry();

            if (geometry != null)
            {
                drawingContext.DrawGeometry(backgroundBrush, borderPen, geometry);
            }
        }
        public void Draw(TextView textView, DrawingContext drawingContext)
        {
            if (result == null)
            {
                return;
            }

            var builder = new BackgroundGeometryBuilder
            {
                CornerRadius       = 1,
                AlignToWholePixels = true,
                BorderThickness    = 0.0
            };

            builder.AddSegment(textView, new TextSegment()
            {
                StartOffset = result.OpeningBracketOffset, Length = result.OpeningBracketLength
            });
            builder.CloseFigure();
            builder.AddSegment(textView, new TextSegment()
            {
                StartOffset = result.ClosingBracketOffset, Length = result.ClosingBracketLength
            });

            var geometry = builder.CreateGeometry();

            if (geometry != null)
            {
                drawingContext.DrawGeometry(backgroundBrush, null, geometry);
            }
        }
Exemple #7
0
        public void Draw(TextView textView, DrawingContext drawingContext)
        {
            if (result == null)
            {
                return;
            }

            var builder = new BackgroundGeometryBuilder();

            builder.AlignToWholePixels = true;
            builder.AddSegment(textView, new TextSegment {
                StartOffset = result.OpeningOffset, Length = 1
            });
            builder.CloseFigure(); // prevent connecting the two segments
            builder.AddSegment(textView, new TextSegment {
                StartOffset = result.ClosingOffset, Length = 1
            });

            var geometry = builder.CreateGeometry();

            if (geometry != null)
            {
                drawingContext.DrawGeometry(backgroundBrush, borderPen, geometry);
            }
        }
Exemple #8
0
        public void Draw(TextView textView, DrawingContext drawingContext)
        {
            if (currentReferences == null)
            {
                var start = textView.VisualLines.First().FirstDocumentLine.LineNumber;
                var end   = textView.VisualLines.Last().LastDocumentLine.LineNumber;
                currentReferences = new List <ISegment>();
                FindCurrentReferences(start, end);
            }
            if (currentReferences.Count == 0)
            {
                return;
            }
            BackgroundGeometryBuilder builder = new BackgroundGeometryBuilder();

            builder.CornerRadius          = cornerRadius;
            builder.AlignToMiddleOfPixels = true;
            foreach (var reference in this.currentReferences)
            {
                builder.AddSegment(textView, new TextSegment()
                {
                    StartOffset = reference.Offset,
                    Length      = reference.Length
                });
                builder.CloseFigure();
            }
            Geometry geometry = builder.CreateGeometry();

            if (geometry != null)
            {
                drawingContext.DrawGeometry(backgroundBrush, borderPen, geometry);
            }
        }
Exemple #9
0
            private void DrawSegment(DiffSegment segment, TextView textView, DrawingContext drawingContext)
            {
                BackgroundGeometryBuilder geoBuilder = new BackgroundGeometryBuilder
                {
                    AlignToWholePixels = true,
                    BorderThickness    = 0,
                    CornerRadius       = 3,
                };

                Brush markerBrush;

                switch (segment.type)
                {
                case DiffItem.DiffType.Deleted:
                    markerBrush = deletedBrush;
                    geoBuilder.AddSegment(textView, segment);
                    break;

                case DiffItem.DiffType.Inserted:
                    markerBrush = addedBrush;
                    geoBuilder.AddSegment(textView, segment);
                    break;

                default:
                    markerBrush = null;
                    break;
                }

                Geometry geometry = geoBuilder.CreateGeometry();

                if (geometry != null)
                {
                    drawingContext.DrawGeometry(markerBrush, null, geometry);
                }
            }
Exemple #10
0
    void IBackgroundRenderer.Draw(TextView textView, DrawingContext drawingContext)
    {
        if (markers == null || !textView.VisualLinesValid)
        {
            return;
        }
        var visualLines = textView.VisualLines;

        if (visualLines.Count == 0)
        {
            return;
        }

        var viewStart = visualLines.First().FirstDocumentLine.Offset;
        var viewEnd   = visualLines.Last().LastDocumentLine.EndOffset;

        foreach (var marker in markers.FindOverlappingSegments(viewStart, viewEnd - viewStart))
        {
            if (marker.BackgroundColor != null)
            {
                var geoBuilder = new BackgroundGeometryBuilder {
                    AlignToWholePixels = true, CornerRadius = 3
                };
                geoBuilder.AddSegment(textView, marker);

                var geometry = geoBuilder.CreateGeometry();
                if (geometry != null)
                {
                    var color = marker.BackgroundColor.Value;
                    var brush = new SolidColorBrush(color);
                    brush.Freeze();
                    drawingContext.DrawGeometry(brush, null, geometry);
                }
            }

            foreach (var r in BackgroundGeometryBuilder.GetRectsForSegment(textView, marker))
            {
                var startPoint = r.BottomLeft;
                var endPoint   = r.BottomRight;

                var usedPen = new Pen(new SolidColorBrush(marker.MarkerColor), 1);
                usedPen.Freeze();
                const double offset = 2.5;

                var count = Math.Max((int)((endPoint.X - startPoint.X) / offset) + 1, 4);

                var geometry = new StreamGeometry();

                using (var ctx = geometry.Open()) {
                    ctx.BeginFigure(startPoint, false, false);
                    ctx.PolyLineTo(CreatePoints(startPoint, endPoint, offset, count).ToArray(), true, false);
                }

                geometry.Freeze();

                drawingContext.DrawGeometry(Brushes.Transparent, usedPen, geometry);
                break;
            }
        }
    }
        public override void Render(DrawingContext drawingContext)
        {
            base.Render(drawingContext);

            var selectionBorder = _textArea.SelectionBorder;

            var geoBuilder = new BackgroundGeometryBuilder
            {
                AlignToWholePixels         = true,
                BorderThickness            = selectionBorder?.Thickness ?? 0,
                ExtendToFullWidthAtLineEnd = _textArea.Selection.EnableVirtualSpace,
                CornerRadius = _textArea.SelectionCornerRadius
            };

            foreach (var segment in _textArea.Selection.Segments)
            {
                geoBuilder.AddSegment(TextView, segment);
            }

            var geometry = geoBuilder.CreateGeometry();

            if (geometry != null)
            {
                drawingContext.DrawGeometry(_textArea.SelectionBrush, selectionBorder, geometry);
            }
        }
Exemple #12
0
        public void Draw(TextView textView, DrawingContext drawingContext)
        {
            if (renderedReferences == null)
            {
                return;
            }
            var builder = new BackgroundGeometryBuilder
            {
                CornerRadius          = cornerRadius,
                AlignToMiddleOfPixels = true
            };

            foreach (var reference in renderedReferences)
            {
                foreach (var span in reference.HighlightSpans)
                {
                    builder.AddSegment(textView, new TextSegment()
                    {
                        StartOffset = span.TextSpan.Start,
                        Length      = span.TextSpan.Length
                    });
                    builder.CloseFigure();
                }
            }
            Geometry geometry = builder.CreateGeometry();

            if (geometry != null)
            {
                drawingContext.DrawGeometry(backgroundBrush, borderPen, geometry);
            }
        }
        public void Draw(TextView textView, DrawingContext drawingContext)
        {
            if (this.renderedReferences == null)
            {
                return;
            }
            BackgroundGeometryBuilder builder = new BackgroundGeometryBuilder();

            builder.CornerRadius          = cornerRadius;
            builder.AlignToMiddleOfPixels = true;
            foreach (var reference in this.renderedReferences)
            {
                builder.AddSegment(textView, new TextSegment()
                {
                    StartOffset = reference.Offset,
                    Length      = reference.Length
                });
                builder.CloseFigure();
            }
            Geometry geometry = builder.CreateGeometry();

            if (geometry != null)
            {
                drawingContext.DrawGeometry(backgroundBrush, borderPen, geometry);
            }
        }
        public void Draw(ICSharpCode.AvalonEdit.Rendering.TextView textView, DrawingContext drawingContext)
        {
            if (this.result == null)
            {
                return;
            }

            BackgroundGeometryBuilder builder = new BackgroundGeometryBuilder();

            builder.CornerRadius = 1;

            builder.AddSegment(textView, new TextSegment()
            {
                StartOffset = result.OpeningBracketOffset, Length = result.OpeningBracketLength
            });
            builder.CloseFigure();             // prevent connecting the two segments
            builder.AddSegment(textView, new TextSegment()
            {
                StartOffset = result.ClosingBracketOffset, Length = result.ClosingBracketLength
            });

            Geometry geometry = builder.CreateGeometry();

            if (geometry != null)
            {
                drawingContext.DrawGeometry(backgroundBrush, borderPen, geometry);
            }
        }
        public void Draw(TextView textView, DrawingContext drawingContext)
        {
            if (_result == null)
            {
                return;
            }

            var builder = new BackgroundGeometryBuilder();

            builder.CornerRadius          = 1;
            builder.AlignToMiddleOfPixels = true;

            builder.AddSegment(textView, new TextSegment()
            {
                StartOffset = _result.OpeningBracketOffset, Length = _result.OpeningBracketLength
            });
            builder.CloseFigure();
            builder.AddSegment(textView, new TextSegment()
            {
                StartOffset = _result.ClosingBracketOffset, Length = _result.ClosingBracketLength
            });

            var geometry = builder.CreateGeometry();

            if (geometry != null)
            {
                drawingContext.DrawGeometry(_backgroundBrush, _borderPen, geometry);
            }
        }
        public void Draw(TextView textView, DrawingContext drawingContext)
        {
            if (this.openBracketOffset == null || this.closeBracketOffset == null)
            {
                return;
            }

            BackgroundGeometryBuilder builder = new BackgroundGeometryBuilder();

            builder.CornerRadius          = 1;
            builder.AlignToMiddleOfPixels = true;

            builder.AddSegment(textView, new TextSegment()
            {
                StartOffset = openBracketOffset, Length = 1
            });
            builder.CloseFigure();             // prevent connecting the two segments
            builder.AddSegment(textView, new TextSegment()
            {
                StartOffset = closeBracketOffset, Length = 1
            });

            Geometry geometry = builder.CreateGeometry();

            if (geometry != null)
            {
                drawingContext.DrawGeometry(backgroundBrush, borderPen, geometry);
            }
        }
        public void Draw(TextView textView, DrawingContext drawingContext)
        {
            if (_textEditor.SelectionLength == 0 && _textEditor.CaretOffset != -1 &&
                _textEditor.CaretOffset <= textView.Document.TextLength)
            {
                var currentLine = textView.Document.GetLocation(_textEditor.CaretOffset).Line;

                var visualLine = textView.GetVisualLine(currentLine);
                if (visualLine == null)
                {
                    return;
                }

                BackgroundGeometryBuilder builder = new BackgroundGeometryBuilder();

                var linePosY   = visualLine.VisualTop - textView.ScrollOffset.Y;
                var lineBottom = linePosY + visualLine.Height;

                Size pixelSize = PixelSnapHelpers.GetPixelSize(textView);


                double x  = PixelSnapHelpers.PixelAlign(0, pixelSize.Width);
                double y  = PixelSnapHelpers.PixelAlign(linePosY, pixelSize.Height);
                var    x2 = PixelSnapHelpers.PixelAlign(textView.Bounds.Width, pixelSize.Width);
                var    y2 = PixelSnapHelpers.PixelAlign(lineBottom, pixelSize.Height);

                builder.AddRectangle(textView, new Rect(new Point(x, y), new Point(x2, y2)));

                Geometry geometry = builder.CreateGeometry();
                if (geometry != null)
                {
                    drawingContext.DrawGeometry(BackgroundBrush, BorderPen, geometry);
                }
            }
        }
Exemple #18
0
        public void Draw(TextView textView, DrawingContext drawingContext)
        {
            if (result.HasValue)
            {
                var match = result.Value;

                var builder = new BackgroundGeometryBuilder
                {
                    CornerRadius          = 1,
                    AlignToMiddleOfPixels = true
                };

                builder.AddSegment(textView, new TextSegment()
                {
                    StartOffset = match.LeftSpan.Start, Length = match.LeftSpan.Length
                });
                builder.CloseFigure(); // prevent connecting the two segments
                builder.AddSegment(textView, new TextSegment()
                {
                    StartOffset = match.RightSpan.Start, Length = match.RightSpan.Length
                });

                Geometry geometry = builder.CreateGeometry();
                if (geometry != null)
                {
                    drawingContext.DrawGeometry(backgroundBrush, borderPen, geometry);
                }
            }
        }
 public void Draw(TextView textview, DrawingContext drawingContext)
 {
     if (_result != null)
     {
         var backgroundGeometryBuilder = new BackgroundGeometryBuilder
         {
             CornerRadius       = 1.0,
             AlignToWholePixels = true
                                  //                    AlignToMiddleOfPixels = true
         };
         backgroundGeometryBuilder.AddSegment(textview, new TextSegment
         {
             StartOffset = _result.OpeningBracketOffset,
             Length      = _result.OpeningBracketLength
         });
         backgroundGeometryBuilder.CloseFigure();
         backgroundGeometryBuilder.AddSegment(textview, new TextSegment
         {
             StartOffset = _result.ClosingBracketOffset,
             Length      = _result.ClosingBracketLength
         });
         var geometry = backgroundGeometryBuilder.CreateGeometry();
         if (_borderPen == null)
         {
             UpdateColors(DefaultBackground, DefaultBackground);
         }
         if (geometry != null)
         {
             drawingContext.DrawGeometry(_backgroundBrush, _borderPen, geometry);
         }
     }
 }
Exemple #20
0
        protected override void OnRender(DrawingContext drawingContext)
        {
            base.OnRender(drawingContext);

            BackgroundGeometryBuilder geoBuilder = new BackgroundGeometryBuilder();

            geoBuilder.CornerRadius = textArea.SelectionCornerRadius;
            foreach (var segment in textArea.Selection.Segments)
            {
                geoBuilder.AddSegment(textView, segment);
            }
            Geometry geometry = geoBuilder.CreateGeometry();

            if (geometry != null)
            {
                if (textArea.Selection.IsFindOnPageSelection())
                {
                    drawingContext.DrawGeometry(textArea.FindOnPageBrush, textArea.FindOnPageBorder, geometry);
                    textView.findOnPageSelectionGeometry = geometry;
                }
                else
                {
                    drawingContext.DrawGeometry(textArea.SelectionBrush, textArea.SelectionBorder, geometry);
                    textView.findOnPageSelectionGeometry = null;
                }
            }
            else
            {
                textView.findOnPageSelectionGeometry = null;
            }
        }
        public void Draw(TextView textView, DrawingContext drawingContext)
        {
            var text        = _editor.Text;
            var caretOffset = _editor.CaretOffset;

            if (caretOffset >= 0 && caretOffset <= text.Length)
            {
                var openingBracketOffset = -1;
                var closingBracketOffset = -1;

                if (caretOffset < text.Length)
                {
                    var  openingBracket = text[caretOffset];
                    char closingBracket;

                    if (OpeningBrackets.TryGetValue(openingBracket, out closingBracket))
                    {
                        openingBracketOffset = caretOffset;
                        closingBracketOffset = FindClosingBracketOffset(text, openingBracketOffset, openingBracket,
                                                                        closingBracket);
                    }
                }

                if (!(openingBracketOffset >= 0 && closingBracketOffset >= 0) && caretOffset > 0)
                {
                    var  closingBracket = text[caretOffset - 1];
                    char openingBracket;

                    if (ClosingBrackets.TryGetValue(closingBracket, out openingBracket))
                    {
                        closingBracketOffset = caretOffset - 1;
                        openingBracketOffset = FindOpeningBracketOffset(text, closingBracketOffset, openingBracket,
                                                                        closingBracket);
                    }
                }

                if (openingBracketOffset >= 0 && closingBracketOffset >= 0)
                {
                    var builder = new BackgroundGeometryBuilder {
                        CornerRadius = 1, AlignToMiddleOfPixels = true
                    };
                    builder.AddSegment(textView, new TextSegment {
                        StartOffset = openingBracketOffset, Length = 1
                    });
                    builder.CloseFigure(); // сегменты не связаны друг с другом
                    builder.AddSegment(textView, new TextSegment {
                        StartOffset = closingBracketOffset, Length = 1
                    });

                    var geometry = builder.CreateGeometry();

                    if (geometry != null)
                    {
                        drawingContext.DrawGeometry(CurrentBracketBrush, null, geometry);
                    }
                }
            }
        }
        public void Draw(TextView textView, DrawingContext drawingContext)
        {
            //check arguments are valid
            if (textView == null)
            {
                throw new ArgumentNullException(nameof(textView));
            }
            if (drawingContext == null)
            {
                throw new ArgumentNullException(nameof(drawingContext));
            }

            if (this.result == null)
            {
                return;
            }

            BackgroundGeometryBuilder builder = new BackgroundGeometryBuilder
            {
                CornerRadius       = 1,
                AlignToWholePixels = true,
                BorderThickness    = 1
            };

            builder.AddSegment(textView, new TextSegment()
            {
                StartOffset = result.OpeningBracketOffset, Length = result.OpeningBracketLength
            });
            builder.CloseFigure(); // prevent connecting the two segments
            builder.AddSegment(textView, new TextSegment()
            {
                StartOffset = result.ClosingBracketOffset, Length = result.ClosingBracketLength
            });

            Geometry geometry = builder.CreateGeometry();

            //Transform highlightFixTransform = new TranslateTransform(0, 2);
            //geometry.Transform.Value.OffsetY = 2;

            if (borderPen == null)
            {
                this.UpdateColors(DefaultBackground, DefaultBackground);
            }
            if (result.ClosingBracketLength == 0)
            {
                this.UpdateColors(InvalidBackground, InvalidBackground);
            }
            else
            {
                this.UpdateColors(DefaultBackground, DefaultBackground);
            }

            if (geometry != null)
            {
                drawingContext.DrawGeometry(backgroundBrush, borderPen, geometry);
            }
        }
        /// <summary>
        /// Defines style of highlighting.
        /// </summary>
        /// <param name="segment"></param>
        /// <param name="textView"></param>
        /// <param name="drawingContext"></param>
        protected virtual void highlight(ISegment segment, TextView textView, DrawingContext drawingContext)
        {
            BackgroundGeometryBuilder geoBuilder = new BackgroundGeometryBuilder()
            {
                CornerRadius = 0
            };

            geoBuilder.AddSegment(textView, segment);

            Geometry geometry = geoBuilder.CreateGeometry();

            drawingContext.DrawGeometry(BrushStyle, PenStyle, geometry);
        }
Exemple #24
0
            public void Draw(TextView textView, DrawingContext drawingContext)
            {
                if (textView == null)
                {
                    throw new ArgumentNullException("textView");
                }
                if (drawingContext == null)
                {
                    throw new ArgumentNullException("drawingContext");
                }

                if (_selectedSegments == null || !textView.VisualLinesValid)
                {
                    return;
                }

                var visualLines = textView.VisualLines;

                if (visualLines.Count == 0 || _selectedSegments.Count == 0)
                {
                    return;
                }

                foreach (SelectedSegment result in _selectedSegments)
                {
                    var selectedType = result.SelectedType;
                    if (selectedType == SelectedType.None || selectedType == SelectedType.Information)
                    {
                        continue;
                    }

                    var geoBuilder = new BackgroundGeometryBuilder();
                    geoBuilder.AlignToWholePixels = true;
                    geoBuilder.BorderThickness    = _errorPen != null ? _errorPen.Thickness : 0;
                    geoBuilder.CornerRadius       = 3;
                    geoBuilder.AddSegment(textView, result.Segment);

                    var geometry = geoBuilder.CreateGeometry();
                    if (geometry != null && !geometry.IsEmpty())
                    {
                        if (selectedType == SelectedType.Error)
                        {
                            drawingContext.DrawGeometry(_errorBrush, _errorPen, geometry);
                        }
                        else if (selectedType == SelectedType.Warning)
                        {
                            drawingContext.DrawGeometry(_warnBrush, _warnPen, geometry);
                        }
                    }
                }
            }
Exemple #25
0
        public void Draw(TextView textView, DrawingContext drawingContext)
        {
            if (textView == null)
            {
                throw new ArgumentNullException("textView");
            }
            if (drawingContext == null)
            {
                throw new ArgumentNullException("drawingContext");
            }

            if (currentResults == null || !textView.VisualLinesValid)
            {
                return;
            }

            var visualLines = textView.VisualLines;

            if (visualLines.Count == 0)
            {
                return;
            }

            int viewStart = visualLines.First().FirstDocumentLine.Offset;
            int viewEnd   = visualLines.Last().LastDocumentLine.EndOffset;

            int highlightCounter = 0;

            foreach (SearchResult result in currentResults.FindOverlappingSegments(viewStart, viewEnd - viewStart))
            {
                BackgroundGeometryBuilder geoBuilder = new BackgroundGeometryBuilder();
                geoBuilder.AlignToWholePixels = true;
                geoBuilder.BorderThickness    = markerPen != null ? markerPen.Thickness : 0;
                geoBuilder.CornerRadius       = 3;
                geoBuilder.AddSegment(textView, result);
                Geometry geometry = geoBuilder.CreateGeometry();
                if (geometry != null)
                {
                    drawingContext.DrawGeometry(markerBrush, markerPen, geometry);
                }
                highlightCounter++;
                if (highlightCounter >= MAX_HIGHLIGHT)
                {
                    break;
                }
            }
        }
        public void Draw(TextView textView, DrawingContext drawingContext)
        {
            if (LeftOfPosition == null && RightOfPosition == null)
            {
                return;
            }

            var builder = new BackgroundGeometryBuilder
            {
                CornerRadius = 1,
#if !AVALONIA
                AlignToMiddleOfPixels = true
#endif
            };

            if (RightOfPosition != null)
            {
                builder.AddSegment(textView, new TextSegment {
                    StartOffset = RightOfPosition.Value.LeftSpan.Start, Length = RightOfPosition.Value.LeftSpan.Length
                });
                builder.CloseFigure();
                builder.AddSegment(textView, new TextSegment {
                    StartOffset = RightOfPosition.Value.RightSpan.Start, Length = RightOfPosition.Value.RightSpan.Length
                });
                builder.CloseFigure();
            }

            if (LeftOfPosition != null)
            {
                builder.AddSegment(textView, new TextSegment {
                    StartOffset = LeftOfPosition.Value.LeftSpan.Start, Length = LeftOfPosition.Value.LeftSpan.Length
                });
                builder.CloseFigure();
                builder.AddSegment(textView, new TextSegment {
                    StartOffset = LeftOfPosition.Value.RightSpan.Start, Length = LeftOfPosition.Value.RightSpan.Length
                });
                builder.CloseFigure();
            }

            var geometry = builder.CreateGeometry();

            if (geometry != null)
            {
                drawingContext.DrawGeometry(_backgroundBrush, null, geometry);
            }
        }
Exemple #27
0
        public void DrawMarker(ISegment range, Color color)
        {
            var geoBuilder = new BackgroundGeometryBuilder {
                AlignToWholePixels = true, CornerRadius = 3
            };

            geoBuilder.AddSegment(_textView, range);
            var geometry = geoBuilder.CreateGeometry();

            if (geometry == null)
            {
                return;
            }
            var brush = new SolidColorBrush(color);

            brush.Freeze();
            _drawingContext.DrawGeometry(brush, null, geometry);
        }
Exemple #28
0
        protected override void OnRender(DrawingContext drawingContext)
        {
            base.OnRender(drawingContext);

            BackgroundGeometryBuilder geoBuilder = new BackgroundGeometryBuilder();

            geoBuilder.AlignToMiddleOfPixels = true;
            geoBuilder.CornerRadius          = textArea.SelectionCornerRadius;
            foreach (var segment in textArea.Selection.Segments)
            {
                geoBuilder.AddSegment(textView, segment);
            }
            Geometry geometry = geoBuilder.CreateGeometry();

            if (geometry != null)
            {
                drawingContext.DrawGeometry(textArea.SelectionBrush, textArea.SelectionBorder, geometry);
            }
        }
Exemple #29
0
        /// <summary>
        /// Causes the background renderer to draw.
        /// </summary>
        /// <param name="textView"></param>
        /// <param name="drawingContext"></param>
        public void Draw(TextView textView, DrawingContext drawingContext)
        {
            if (String.IsNullOrWhiteSpace(editor.SelectedText) ||
                !editor.SelectedText.All(Char.IsLetterOrDigit))
            {
                return;
            }
            ISearchStrategy strategy = SearchStrategyFactory.Create(editor.SelectedText, false, true, SearchMode.Normal);

            foreach (ISearchResult result in strategy.FindAll(textView.Document, 0, textView.Document.TextLength))
            {
                BackgroundGeometryBuilder builder = new BackgroundGeometryBuilder()
                {
                    CornerRadius = 1
                };
                builder.AddSegment(textView, result);
                drawingContext.DrawGeometry(BrushStyle, PenStyle, builder.CreateGeometry());
            }
        }
Exemple #30
0
        public void Draw(TextView textView, DrawingContext drawingContext)
        {
            if (textView == null)
            {
                throw new ArgumentNullException("textView");
            }
            if (drawingContext == null)
            {
                throw new ArgumentNullException("drawingContext");
            }
            if (markers == null || !textView.VisualLinesValid)
            {
                return;
            }
            ReadOnlyCollection <VisualLine> visualLines = textView.VisualLines;

            if (visualLines.Count == 0)
            {
                return;
            }
            int viewStart = visualLines.First().FirstDocumentLine.Offset;
            int viewEnd   = visualLines.Last().LastDocumentLine.EndOffset;

            foreach (TextMarker marker in markers.FindOverlappingSegments(viewStart, viewEnd - viewStart))
            {
                if (marker.BackgroundColor != null)
                {
                    var geoBuilder = new BackgroundGeometryBuilder();
                    geoBuilder.AlignToWholePixels = true;
                    geoBuilder.CornerRadius       = 3;
                    geoBuilder.AddSegment(textView, marker);
                    Geometry geometry = geoBuilder.CreateGeometry();
                    if (geometry != null)
                    {
                        Color color = marker.BackgroundColor.Value;
                        var   brush = new SolidColorBrush(color);
                        brush.Freeze();
                        drawingContext.DrawGeometry(brush, null, geometry);
                    }
                }
            }
        }