Esempio n. 1
0
        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);
            }
        }
Esempio n. 2
0
 void ITextViewConnect.RemoveFromTextView(ICSharpCode.AvalonEdit.Rendering.TextView textView)
 {
     if (textView != null)
     {
         Debug.Assert(textView.Document == document);
         textViews.Remove(textView);
     }
 }
Esempio n. 3
0
 void ITextViewConnect.AddToTextView(ICSharpCode.AvalonEdit.Rendering.TextView textView)
 {
     if (textView != null && !textViews.Contains(textView))
     {
         Debug.Assert(textView.Document == document);
         textViews.Add(textView);
     }
 }
Esempio n. 4
0
        protected override void OnRender(DrawingContext drawingContext)
        {
            Size renderSize = this.RenderSize;
            var  theme      = Themes.Theme;
            var  bgColor    = theme.GetColor(ColorType.IconBar).InheritedColor.Background.GetColor(null).Value;

            drawingContext.DrawRectangle(theme.GetColor(ColorType.IconBar).InheritedColor.Background.GetBrush(null), null,
                                         new Rect(0, 0, renderSize.Width, renderSize.Height));
            drawingContext.DrawLine(new Pen(theme.GetColor(ColorType.IconBarBorder).InheritedColor.Background.GetBrush(null), 1),
                                    new Point(renderSize.Width - 0.5, 0),
                                    new Point(renderSize.Width - 0.5, renderSize.Height));

            ICSharpCode.AvalonEdit.Rendering.TextView textView = this.TextView;
            if (textView != null && textView.VisualLinesValid)
            {
                // create a dictionary line number => first bookmark
                Dictionary <int, List <IIconBarObject> > bookmarkDict = new Dictionary <int, List <IIconBarObject> >();
                foreach (var obj in TextLineObjectManager.Instance.GetObjectsOfType <IIconBarObject>())
                {
                    if (!obj.IsVisible(decompilerTextView))
                    {
                        continue;
                    }
                    int line = obj.GetLineNumber(decompilerTextView);
                    List <IIconBarObject> list;
                    if (!bookmarkDict.TryGetValue(line, out list))
                    {
                        bookmarkDict[line] = list = new List <IIconBarObject>();
                    }
                    list.Add(obj);
                }

                const double imagePadding = 1.0;
                Size         pixelSize    = PixelSnapHelpers.GetPixelSize(this);
                foreach (VisualLine line in textView.VisualLines)
                {
                    int lineNumber = line.FirstDocumentLine.LineNumber;
                    List <IIconBarObject> list;
                    if (!bookmarkDict.TryGetValue(lineNumber, out list))
                    {
                        continue;
                    }
                    list.Sort((a, b) => a.ZOrder.CompareTo(b.ZOrder));
                    foreach (var bm in list)
                    {
                        Rect rect = new Rect(imagePadding, PixelSnapHelpers.Round(line.VisualTop - textView.VerticalOffset, pixelSize.Height), 16, 16);
                        drawingContext.DrawImage(bm.GetImage(bgColor), rect);
                    }
                }
            }
        }
Esempio n. 5
0
        public BracketHighlightRenderer(ICSharpCode.AvalonEdit.Rendering.TextView textView)
        {
            if (textView == null)
            {
                throw new ArgumentNullException("textView");
            }

            this.borderPen       = (Pen)textView.FindResource(Themes.ResourceKeys.BracketHighlightBorderPen);
            this.backgroundBrush = (SolidColorBrush)textView.FindResource(Themes.ResourceKeys.BracketHighlightBackgroundBrush);

            this.textView = textView;

            this.textView.BackgroundRenderers.Add(this);
        }
Esempio n. 6
0
        //public KnownLayer Layer => throw new NotImplementedException();

        public void Draw(ICSharpCode.AvalonEdit.Rendering.TextView textview, DrawingContext drawingcontext)
        {
            if (_editor.Document == null || textview.ActualWidth <= 32)
            {
                return;
            }
            textview.EnsureVisualLines();
            ICSharpCode.AvalonEdit.Document.DocumentLine currentline = _editor.Document.GetLineByOffset(_editor.CaretOffset);
            foreach (var rect in BackgroundGeometryBuilder.GetRectsForSegment(textview, currentline))
            {
                drawingcontext.DrawRectangle(new SolidColorBrush(System.Windows.Media.Color.FromArgb(25, 255, 255, 255)), null, new System.Windows.Rect(rect.Location,
                                                                                                                                                        new System.Windows.Size(textview.ActualWidth - 32, rect.Height)));
            }
        }
Esempio n. 7
0
        public int GetLineFromMousePosition(MouseEventArgs e)
        {
            ICSharpCode.AvalonEdit.Rendering.TextView textView = this.TextView;
            if (textView == null)
            {
                return(0);
            }
            VisualLine vl = textView.GetVisualLineFromVisualTop(e.GetPosition(textView).Y + textView.ScrollOffset.Y);

            if (vl == null)
            {
                return(0);
            }
            return(vl.FirstDocumentLine.LineNumber);
        }
Esempio n. 8
0
        public BracketHighlightRenderer(ICSharpCode.AvalonEdit.Rendering.TextView textView)
        {
            if (textView == null)
            {
                throw new ArgumentNullException("textView");
            }

            this.borderPen = new Pen(new SolidColorBrush(Color.FromArgb(52, 0, 0, 255)), 1);
            this.borderPen.Freeze();

            this.backgroundBrush = new SolidColorBrush(Color.FromArgb(22, 0, 0, 255));
            this.backgroundBrush.Freeze();

            this.textView = textView;

            this.textView.BackgroundRenderers.Add(this);
        }
Esempio n. 9
0
        public void Draw(ICSharpCode.AvalonEdit.Rendering.TextView textView, DrawingContext drawingContext)
        {
            if (textView == null)
            {
                throw new ArgumentNullException("textView");
            }
            if (drawingContext == null)
            {
                throw new ArgumentNullException("drawingContext");
            }
            if (markers == null || !textView.VisualLinesValid)
            {
                return;
            }
            var visualLines = textView.VisualLines;

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

            foreach (TextMarker marker in markers.FindOverlappingSegments(viewStart, viewEnd - viewStart).Reverse())
            {
                if (!marker.IsVisible(marker.Bookmark))
                {
                    continue;
                }

                if (marker.BackgroundColor != null)
                {
                    BackgroundGeometryBuilder 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;
                        SolidColorBrush brush = new SolidColorBrush(color);
                        brush.Freeze();
                        drawingContext.DrawGeometry(brush, null, geometry);
                    }
                }
                if (marker.MarkerType != TextMarkerType.None)
                {
                    foreach (Rect r in BackgroundGeometryBuilder.GetRectsForSegment(textView, marker))
                    {
                        Point startPoint = r.BottomLeft;
                        Point endPoint   = r.BottomRight;

                        Pen usedPen = new Pen(new SolidColorBrush(marker.MarkerColor), 1);
                        usedPen.Freeze();
                        switch (marker.MarkerType)
                        {
                        case TextMarkerType.SquigglyUnderline:
                            double offset = 2.5;

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

                            StreamGeometry geometry = new StreamGeometry();

                            using (StreamGeometryContext 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;
                        }
                    }
                }
            }
        }
Esempio n. 10
0
 protected override IHighlighter CreateHighlighter(AR.TextView textView, TextDocument document)
 {
     return(new NewHighlighter(textEditor, document));
 }
Esempio n. 11
0
        protected override void OnRender(DrawingContext drawingContext)
        {
            Size renderSize = this.RenderSize;
            var  theme      = Themes.Theme;
            var  bgColor    = theme.GetColor(ColorType.IconBar).InheritedColor.Background.GetColor(null).Value;

            drawingContext.DrawRectangle(theme.GetColor(ColorType.IconBar).InheritedColor.Background.GetBrush(null), null,
                                         new Rect(0, 0, renderSize.Width, renderSize.Height));
            drawingContext.DrawLine(new Pen(theme.GetColor(ColorType.IconBarBorder).InheritedColor.Background.GetBrush(null), 1),
                                    new Point(renderSize.Width - 0.5, 0),
                                    new Point(renderSize.Width - 0.5, renderSize.Height));

            ICSharpCode.AvalonEdit.Rendering.TextView textView = this.TextView;
            if (textView != null && textView.VisualLinesValid)
            {
                // create a dictionary line number => first bookmark
                Dictionary <int, List <IBookmark> > bookmarkDict = new Dictionary <int, List <IBookmark> >();
                var cm = decompilerTextView.CodeMappings;
                foreach (var bm in BookmarkManager.Bookmarks)
                {
                    if (bm is BreakpointBookmark)
                    {
                        if (cm == null || cm.Count == 0 || !cm.ContainsKey(((BreakpointBookmark)bm).MethodKey))
                        {
                            continue;
                        }
                    }
                    int line = bm.GetLineNumber(decompilerTextView);
                    List <IBookmark> list;
                    if (!bookmarkDict.TryGetValue(line, out list))
                    {
                        bookmarkDict[line] = list = new List <IBookmark>();
                    }
                    list.Add(bm);
                }

                foreach (var bm in manager.Bookmarks)
                {
                    int line = BookmarkBase.GetLineNumber(bm, decompilerTextView);
                    List <IBookmark> list;
                    if (!bookmarkDict.TryGetValue(line, out list))
                    {
                        bookmarkDict[line] = list = new List <IBookmark>();
                    }
                    list.Add(bm);
                }

                const double imagePadding = 1.0;
                Size         pixelSize    = PixelSnapHelpers.GetPixelSize(this);
                foreach (VisualLine line in textView.VisualLines)
                {
                    int lineNumber = line.FirstDocumentLine.LineNumber;
                    List <IBookmark> list;
                    if (!bookmarkDict.TryGetValue(lineNumber, out list))
                    {
                        continue;
                    }
                    list.Sort((a, b) => a.ZOrder.CompareTo(b.ZOrder));
                    foreach (var bm in list)
                    {
                        Rect rect = new Rect(imagePadding, PixelSnapHelpers.Round(line.VisualTop - textView.VerticalOffset, pixelSize.Height), 16, 16);
                        drawingContext.DrawImage(bm.GetImage(bgColor), rect);
                    }
                }
            }
        }
Esempio n. 12
0
        protected override void OnRender(DrawingContext drawingContext)
        {
            Size renderSize = this.RenderSize;

            drawingContext.DrawRectangle(SystemColors.ControlBrush, null,
                                         new Rect(0, 0, renderSize.Width, renderSize.Height));
            drawingContext.DrawLine(new Pen(SystemColors.ControlDarkBrush, 1),
                                    new Point(renderSize.Width - 0.5, 0),
                                    new Point(renderSize.Width - 0.5, renderSize.Height));

            ICSharpCode.AvalonEdit.Rendering.TextView textView = this.TextView;
            if (textView != null && textView.VisualLinesValid)
            {
                // create a dictionary line number => first bookmark
                Dictionary <int, IBookmark> bookmarkDict = new Dictionary <int, IBookmark>();
                foreach (var bm in BookmarkManager.Bookmarks)
                {
                    if (bm is BreakpointBookmark)
                    {
                        if (DebugInformation.CodeMappings == null || DebugInformation.CodeMappings.Count == 0 ||
                            !DebugInformation.CodeMappings.ContainsKey(((BreakpointBookmark)bm).FunctionToken))
                        {
                            continue;
                        }
                    }
                    int       line = bm.LineNumber;
                    IBookmark existingBookmark;
                    if (!bookmarkDict.TryGetValue(line, out existingBookmark) || bm.ZOrder > existingBookmark.ZOrder)
                    {
                        bookmarkDict[line] = bm;
                    }
                }

                foreach (var bm in manager.Bookmarks)
                {
                    int       line = bm.LineNumber;
                    IBookmark existingBookmark;
                    if (!bookmarkDict.TryGetValue(line, out existingBookmark) || bm.ZOrder > existingBookmark.ZOrder)
                    {
                        bookmarkDict[line] = bm;
                    }
                }

                const double imagePadding = 1.0;
                Size         pixelSize    = PixelSnapHelpers.GetPixelSize(this);
                foreach (VisualLine line in textView.VisualLines)
                {
                    int       lineNumber = line.FirstDocumentLine.LineNumber;
                    IBookmark bm;
                    if (bookmarkDict.TryGetValue(lineNumber, out bm))
                    {
                        Rect rect = new Rect(imagePadding, PixelSnapHelpers.Round(line.VisualTop - textView.VerticalOffset, pixelSize.Height), 16, 16);
                        if (dragDropBookmark == bm && dragStarted)
                        {
                            drawingContext.PushOpacity(0.5);
                        }
                        drawingContext.DrawImage(bm.Image, rect);
                        if (dragDropBookmark == bm && dragStarted)
                        {
                            drawingContext.Pop();
                        }
                    }
                }
                if (dragDropBookmark != null && dragStarted)
                {
                    Rect rect = new Rect(imagePadding, PixelSnapHelpers.Round(dragDropCurrentPoint - 8, pixelSize.Height), 16, 16);
                    drawingContext.DrawImage(dragDropBookmark.Image, rect);
                }
            }
        }
Esempio n. 13
0
        public void Draw(ICSharpCode.AvalonEdit.Rendering.TextView textView, DrawingContext drawingContext)
        {
            if (textView == null)
            {
                throw new ArgumentNullException("textView");
            }
            if (drawingContext == null)
            {
                throw new ArgumentNullException("drawingContext");
            }
            if (markers == null || markers.Count == 0 || !textView.VisualLinesValid)
            {
                return;
            }
            var visualLines = textView.VisualLines;

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

            foreach (TextMarker marker in GetSortedTextMarkers(viewStart, viewEnd - viewStart))
            {
                if (marker.TextMarkerObject != null && !marker.IsVisible(marker.TextMarkerObject))
                {
                    continue;
                }

                if (marker.BackgroundColor != null)
                {
                    BackgroundGeometryBuilder geoBuilder = new BackgroundGeometryBuilder();
                    geoBuilder.AlignToWholePixels = true;
                    geoBuilder.CornerRadius       = 0;
                    geoBuilder.AddSegment(textView, marker);
                    Geometry geometry = geoBuilder.CreateGeometry();
                    if (geometry != null)
                    {
                        Color           color = marker.BackgroundColor.Value;
                        SolidColorBrush brush = new SolidColorBrush(color);
                        brush.Freeze();
                        drawingContext.DrawGeometry(brush, null, geometry);
                    }
                }
                var underlineMarkerTypes = TextMarkerTypes.SquigglyUnderline | TextMarkerTypes.NormalUnderline | TextMarkerTypes.DottedUnderline;
                if ((marker.MarkerTypes & underlineMarkerTypes) != 0)
                {
                    foreach (Rect r in BackgroundGeometryBuilder.GetRectsForSegment(textView, marker))
                    {
                        Point startPoint = r.BottomLeft;
                        Point endPoint   = r.BottomRight;

                        Brush usedBrush = new SolidColorBrush(marker.MarkerColor);
                        usedBrush.Freeze();
                        if ((marker.MarkerTypes & TextMarkerTypes.SquigglyUnderline) != 0)
                        {
                            double offset = 2.5;

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

                            StreamGeometry geometry = new StreamGeometry();

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

                            geometry.Freeze();

                            Pen usedPen = new Pen(usedBrush, 1);
                            usedPen.Freeze();
                            drawingContext.DrawGeometry(Brushes.Transparent, usedPen, geometry);
                        }
                        if ((marker.MarkerTypes & TextMarkerTypes.NormalUnderline) != 0)
                        {
                            Pen usedPen = new Pen(usedBrush, 1);
                            usedPen.Freeze();
                            drawingContext.DrawLine(usedPen, startPoint, endPoint);
                        }
                        if ((marker.MarkerTypes & TextMarkerTypes.DottedUnderline) != 0)
                        {
                            Pen usedPen = new Pen(usedBrush, 1);
                            usedPen.DashStyle = DashStyles.Dot;
                            usedPen.Freeze();
                            drawingContext.DrawLine(usedPen, startPoint, endPoint);
                        }
                    }
                }
            }
        }