private void DrawChange(DrawingContext drawingContext, ChangeTypes type, NormalizedSnapshotSpanCollection[] allChanges)
        {
            NormalizedSnapshotSpanCollection changes = allChanges[(int)type];

            if (changes.Count > 0)
            {
                double yTop    = Math.Floor(_scrollBar.GetYCoordinateOfBufferPosition(changes[0].Start)) - ChangePadding;
                double yBottom = Math.Ceiling(_scrollBar.GetYCoordinateOfBufferPosition(changes[0].End)) + ChangePadding;

                for (int i = 1; (i < changes.Count); ++i)
                {
                    double y = _scrollBar.GetYCoordinateOfBufferPosition(changes[i].Start) - ChangePadding;
                    if (yBottom < y)
                    {
                        drawingContext.DrawRectangle(_brushes[(int)type], null,
                                                     new Rect(ChangeOffset * 0.5, yTop, this.Width - ChangeOffset, yBottom - yTop));

                        yTop = y;
                    }

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

                drawingContext.DrawRectangle(_brushes[(int)type], null,
                                             new Rect(ChangeOffset * 0.5, yTop, this.Width - ChangeOffset, yBottom - yTop));
            }
        }
예제 #2
0
        void DrawSelections(DrawingContext drawingContext)
        {
            var ss        = _TextView.Selection.SelectedSpans;
            var threshold = ss.Count < 2 ? 3 : 0.5;

            foreach (var item in ss)
            {
                var top    = _ScrollBar.GetYCoordinateOfBufferPosition(item.Start);
                var height = _ScrollBar.GetYCoordinateOfBufferPosition(item.End) - top;
                if (height > threshold)
                {
                    drawingContext.DrawRectangle(_SelectionBrush, null, new Rect(-100, top, 200, height));
                }
            }
        }
예제 #3
0
        void DrawMarkers(DrawingContext drawingContext)
        {
            var   lastY     = 0.0;
            Brush lastBrush = null;
            var   tags      = new List <SpanTag>(_Tags.Tags);

            tags.Sort((x, y) => x.Start - y.Start);
            var snapshot       = _TextView.TextSnapshot;
            var snapshotLength = snapshot.Length;

            foreach (var tag in tags)
            {
                if (tag.End >= snapshotLength)
                {
                    continue;
                }
                //todo: customizable marker style
                var   c = tag.Tag.ClassificationType.Classification;
                Brush b;
                if (ClassificationBrushMapper.TryGetValue(c, out b) == false)
                {
                    continue;
                }
                var y = _ScrollBar.GetYCoordinateOfBufferPosition(new SnapshotPoint(snapshot, tag.Start));
                if (lastY + HalfMarkSize > y && lastBrush == b)
                {
                    // avoid drawing too many closed markers
                    continue;
                }
                else if (b == PreProcessorBrush)
                {
                    if (!Config.Instance.MarkerOptions.MatchFlags(MarkerOptions.CompilerDirective))
                    {
                        continue;
                    }
                    DrawMark(drawingContext, b, y, 0);
                }
                else if (b == TaskBrush)
                {
                    if (!Config.Instance.MarkerOptions.MatchFlags(MarkerOptions.SpecialComment))
                    {
                        continue;
                    }
                    //note the text relies on the last character of Constants.Task1Comment, etc.
                    DrawTaskMark(drawingContext, b, y, c[c.Length - 1].ToString());
                }
                else
                {
                    if (!Config.Instance.MarkerOptions.MatchFlags(MarkerOptions.SpecialComment))
                    {
                        continue;
                    }
                    DrawCommentMark(drawingContext, b, y);
                }
                lastY     = y;
                lastBrush = b;
            }
        }
예제 #4
0
        private void DrawBlock(DrawingContext drawingContext, IMappingTagSpan <IBlockTag> tag, bool methodHighlights)
        {
            if (methodHighlights
                ? (tag.Tag.Type == BlockType.Method)
                : ((tag.Tag.Type != BlockType.Namespace) && (tag.Tag.Type != BlockType.Root)))
            {
                int level = 0;
                for (var p = tag.Tag.Parent; (p != null); p = p.Parent)
                {
                    if ((p.Type != BlockType.Namespace) && (p.Type != BlockType.Root))
                    {
                        ++level;
                    }
                }

                NormalizedSnapshotSpanCollection spans = tag.Span.GetSpans(_textView.TextSnapshot);
                foreach (var span in spans)
                {
                    double x = (double)(level) * (lineWidth + gapWidth) + 3.0;

                    if (x < this.ActualWidth)
                    {
                        double yTop    = _scrollBar.GetYCoordinateOfBufferPosition(span.Start);
                        double yBottom = _scrollBar.GetYCoordinateOfBufferPosition(span.End);

                        if (yBottom > yTop + 2.0)
                        {
                            if (methodHighlights)
                            {
                                drawingContext.PushClip(new RectangleGeometry(new Rect(x - 1.0, 0.0, (this.ActualWidth - x), this.ActualHeight)));
                                drawingContext.DrawEllipse(_coloring.MethodSeparatorAndHighlightColoring.ToolTipBrush, null, new Point(x - 1.0, (yTop + yBottom) * 0.5),
                                                           (this.ActualWidth + 1.0 - x), (yBottom - yTop) * 0.5);
                                drawingContext.Pop();
                            }
                            else
                            {
                                drawingContext.DrawLine(_coloring.GetLinePen(tag.Tag),
                                                        new Point(x, yTop),
                                                        new Point(x, yBottom));
                            }
                        }
                    }
                }
            }
        }
        Geometry GetMarkerGeometry(SnapshotPoint snapshotPoint)
        {
            double markerHeight = 2.0;

            var y = _scrollBar.GetYCoordinateOfBufferPosition(snapshotPoint);

            var rectangleGeometry = new RectangleGeometry(new Rect(0, y - markerHeight / 2, Width, markerHeight));

            return(rectangleGeometry);
        }
예제 #6
0
        void DrawMarkers(DrawingContext drawingContext)
        {
            var   lastY          = 0.0;
            Brush lastBrush      = null;
            var   snapshot       = _TextView.TextSnapshot;
            var   snapshotLength = snapshot.Length;

            foreach (var tag in _Tags.GetTags())
            {
                if (tag.End >= snapshotLength)
                {
                    continue;
                }
                //todo: customizable marker style
                var   c = tag.Tag.ClassificationType;
                Brush b;
                if (ClassificationBrushMapper.TryGetValue(c, out b) == false)
                {
                    continue;
                }
                var y = _ScrollBar.GetYCoordinateOfBufferPosition(new SnapshotPoint(snapshot, tag.Start));
                if (lastY + HalfMarkSize > y && lastBrush == b)
                {
                    // avoid drawing too many closed markers
                    continue;
                }
                else if (b == PreProcessorBrush)
                {
                    if (!Config.Instance.MarkerOptions.MatchFlags(MarkerOptions.CompilerDirective))
                    {
                        continue;
                    }
                    DrawMark(drawingContext, b, y, 0);
                }
                else if (b == TaskBrush)
                {
                    if (!Config.Instance.MarkerOptions.MatchFlags(MarkerOptions.SpecialComment))
                    {
                        continue;
                    }
                    DrawTaskMark(drawingContext, b, y, String.Empty, tag.ContentText);
                }
                else
                {
                    if (!Config.Instance.MarkerOptions.MatchFlags(MarkerOptions.SpecialComment))
                    {
                        continue;
                    }
                    DrawCommentMark(drawingContext, b, y);
                }
                lastY     = y;
                lastBrush = b;
            }
        }
예제 #7
0
        void DrawLineNumbers(DrawingContext drawingContext)
        {
            var snapshot = _TextView.TextSnapshot;
            var lc       = snapshot.LineCount;
            var step     = lc < 500 ? 50 : lc < 2000 ? 100 : lc < 3000 ? 200 : lc < 5000 ? 500 : lc < 20000 ? 1000 : lc < 100000 ? 5000 : 10000;

            for (int i = step; i < lc; i += step)
            {
                var y = _ScrollBar.GetYCoordinateOfBufferPosition(new SnapshotPoint(snapshot, snapshot.GetLineFromLineNumber(i - 1).Start));
                drawingContext.DrawLine(LineNumberPen, new Point(-100, y), new Point(100, y));
                var t = WpfHelper.ToFormattedText(i.ToString(), 9, LineNumberBrush);
                drawingContext.DrawText(t, new Point(_ScrollbarWidth - t.Width, y));
            }
        }
예제 #8
0
            internal void Render(DrawingContext drawingContext)
            {
                const int showMemberDeclarationThredshold = 30, longDeclarationLines = 50, labelSize = 8;

                if (Config.Instance.MarkerOptions.HasAnyFlag(MarkerOptions.MemberDeclaration | MarkerOptions.RegionDirective) == false ||
                    _TextView.IsClosed)
                {
                    return;
                }
                var           snapshot = _TextView.TextSnapshot;
                var           regions = _Regions;
                FormattedText text;

                if (regions != null && Config.Instance.MarkerOptions.MatchFlags(MarkerOptions.RegionDirective))
                {
                    foreach (RegionDirectiveTriviaSyntax region in regions)
                    {
                        var s = region.GetDeclarationSignature();
                        if (s != null)
                        {
                            text = WpfHelper.ToFormattedText(s, labelSize, _Element._RegionForeground);
                            SnapshotPoint rp;
                            try {
                                rp = new SnapshotPoint(snapshot, region.SpanStart);
                            }
                            catch (ArgumentOutOfRangeException) {
                                break;
                            }
                            var p = new Point(5, _ScrollBar.GetYCoordinateOfBufferPosition(rp) - text.Height / 2);
                            if (_Element._RegionBackground != null)
                            {
                                drawingContext.DrawRectangle(_Element._RegionBackground, null, new Rect(p, new Size(text.Width, text.Height)));
                            }
                            drawingContext.DrawText(text, p);
                        }
                    }
                }
                var tags = _Tags;

                if (tags == null || _CodeMemberTagger == null || Config.Instance.MarkerOptions.MatchFlags(MarkerOptions.MemberDeclaration) == false)
                {
                    return;
                }
                var           snapshotLength = snapshot.Length;
                var           memberLevel = 0;
                var           memberType = CodeMemberType.Root;
                var           lastLabel = Double.MinValue;
                SnapshotPoint rangeFrom = default, rangeTo = default;
예제 #9
0
        protected override void OnRender(DrawingContext drawingContext)
        {
            base.OnRender(drawingContext);


            foreach (var comment in getPReviewComments())
            {
                try
                {
                    double y = scrollBar.GetYCoordinateOfBufferPosition(comment.SnapShotSpan.Start);
                    this.DrawMark(drawingContext, markBrush, y);
                } catch (ArgumentException)
                {
                    Debug.WriteLine("SnapShotSpan mismatch");
                }
            }
        }
예제 #10
0
        /// <summary>
        /// Draw all the marks in the buffer.
        /// </summary>
        /// <remarks>
        /// Marks may be represented by glyphs or color swatches,
        /// depending on available space and on the information provided by the mark.
        /// This does not erase any previously rendered marks.
        /// </remarks>
        /// <param name="marks">
        /// A list of overview marks and their associated start positions, sorted by
        /// ascending start position.
        /// </param>
        private void DrawMarks(DrawingContext drawingContext, IList <Tuple <IOverviewMark, SnapshotPoint> > marks)
        {
            double lastY = double.MinValue;

            foreach (var entry in marks)
            {
                double y = Math.Round(_scrollBar.GetYCoordinateOfBufferPosition(entry.Item2));
                if (y - MarkSpacing > lastY)
                {
                    Brush brush = new SolidColorBrush(entry.Item1.Color);
                    brush.Freeze();

                    Rect rectangle = new Rect(MarkOffset * 0.5, y - MarkHeight * 0.5, this.Width - MarkOffset, MarkHeight);
                    drawingContext.DrawRectangle(brush, _markPen, rectangle);

                    lastY = y;
                }

                _visibleMarks.Add(new Tuple <IOverviewMark, double>(entry.Item1, y));
            }
        }