private void DrawChanges(DrawingContext drawingContext, NormalizedSnapshotSpanCollection changes, Brush brush)
        {
            if (changes.Count > 0)
            {
                double yTop    = Math.Floor(_scrollBar.GetYCoordinateOfBufferPosition(changes[0].Start)) + markerStartOffset;
                double yBottom = Math.Ceiling(_scrollBar.GetYCoordinateOfBufferPosition(changes[0].End)) + markerEndOffset;

                for (int i = 1; i < changes.Count; ++i)
                {
                    double y = _scrollBar.GetYCoordinateOfBufferPosition(changes[i].Start) + markerStartOffset;
                    if (yBottom < y)
                    {
                        drawingContext.DrawRectangle(
                            brush,
                            null,
                            new Rect(0, yTop, markerWidth, yBottom - yTop));

                        yTop = y;
                    }

                    yBottom = Math.Ceiling(_scrollBar.GetYCoordinateOfBufferPosition(changes[i].End)) + markerEndOffset;
                }

                drawingContext.DrawRectangle(
                    brush,
                    null,
                    new Rect(0, yTop, markerWidth, yBottom - yTop));
            }
        }
        private void DrawMarkers(DrawingContext drawingContext, NormalizedSnapshotSpanCollection markers, Brush brush, bool right, short xOfs, short markerWidth)
        {
            if (markers.Count > 0)
            {
                double yTop    = Math.Floor(_scrollBar.GetYCoordinateOfBufferPosition(markers[0].Start)) + markerStartOffset;
                double yBottom = Math.Ceiling(_scrollBar.GetYCoordinateOfBufferPosition(markers[0].End)) + markerEndOffset;
                double x       = right ? _scrollBar.Width - markerWidth + xOfs : xOfs;

                for (int i = 1; i < markers.Count; ++i)
                {
                    double y = _scrollBar.GetYCoordinateOfBufferPosition(markers[i].Start) + markerStartOffset;
                    if (yBottom < y)
                    {
                        drawingContext.DrawRectangle(
                            brush, null,
                            new Rect(x, yTop, markerWidth, yBottom - yTop));

                        yTop = y;
                    }

                    yBottom = Math.Ceiling(_scrollBar.GetYCoordinateOfBufferPosition(markers[i].End)) + markerEndOffset;
                }

                drawingContext.DrawRectangle(
                    brush, null,
                    new Rect(x, yTop, markerWidth, yBottom - yTop));
            }
        }
        public void Render(DrawingContext drawingContext)
        {
            if (!HighlightWordTaggerProvider.Taggers.ContainsKey(_textView))
            {
                return;
            }

            NormalizedSnapshotSpanCollection           spans = new NormalizedSnapshotSpanCollection(new SnapshotSpan(_textView.TextSnapshot, 0, _textView.TextSnapshot.Length));
            IEnumerable <ITagSpan <HighlightWordTag> > tags  = HighlightWordTaggerProvider.Taggers[_textView].GetTags(spans);
            List <SnapshotSpan> highlightList = new List <SnapshotSpan>();

            foreach (ITagSpan <HighlightWordTag> highlight in tags)
            {
                highlightList.Add(highlight.Span);
            }

            NormalizedSnapshotSpanCollection highlights = new NormalizedSnapshotSpanCollection(highlightList);

            if (highlights.Count > 0)
            {
                double yMark   = Options.FindMarkSize * 0.5;
                double yTop    = Math.Floor(_scrollBar.GetYCoordinateOfBufferPosition(highlights[0].Start)) + markerStartOffset - yMark;
                double yBottom = Math.Ceiling(_scrollBar.GetYCoordinateOfBufferPosition(highlights[0].End)) + markerEndOffset + yMark;
                double x       = _scrollBar.Width - markerRight;

                for (int i = 1; i < highlights.Count; ++i)
                {
                    double y = _scrollBar.GetYCoordinateOfBufferPosition(highlights[i].Start) + markerStartOffset;
                    if (yBottom < y)
                    {
                        drawingContext.DrawRectangle(
                            Colors.HighlightsBrush, null,
                            new Rect(x, yTop, markerWidth, yBottom - yTop));

                        yTop = y;
                    }

                    yBottom = Math.Ceiling(_scrollBar.GetYCoordinateOfBufferPosition(highlights[i].End)) + markerEndOffset + yMark;
                }

                drawingContext.DrawRectangle(
                    Colors.HighlightsBrush, null,
                    new Rect(x, yTop, markerWidth, yBottom - yTop));
            }
        }
Example #4
0
        private void RenderMarks()
        {
            if (_textView.IsClosed)
            {
                return;
            }

            try
            {
                using (DrawingContext drawingContext = MarksVisual.RenderOpen())
                {
                    // Render viewport
                    double textHeight      = Math.Min(_textRenderer.Height, DrawHeight);
                    double numVisibleLines = _textView.ViewportHeight / _textView.LineHeight;
                    int    viewportHeight  = Math.Max((int)(numVisibleLines * (textHeight / _textRenderer.NumLines)), 5);
                    int    firstLine       = (int)_scrollBar.GetYCoordinateOfBufferPosition(new SnapshotPoint(_textView.TextViewLines.FirstVisibleLine.Snapshot, _textView.TextViewLines.FirstVisibleLine.Start));

                    drawingContext.DrawRectangle(Colors.VisibleRegionBrush, null, new Rect(0.0, firstLine, ActualWidth, viewportHeight));

                    // Render various marks
                    _changeRenderer.Colors = Colors;
                    _changeRenderer.Render(drawingContext);

                    _highlightRenderer.Colors = Colors;
                    _highlightRenderer.Render(drawingContext);

                    _markerRenderer.Colors = Colors;
                    _markerRenderer.Render(drawingContext);

                    if (Options.CursorBorderEnabled)
                    {
                        drawingContext.DrawRectangle(null, Colors.VisibleRegionBorderPen, new Rect(0.5, firstLine + 0.5, ActualWidth - 1.0, viewportHeight - 1.0));
                    }
                }
            }
            catch (Exception)
            {
                // Just in case.
            }
        }