1
// Copyright (c) AlphaSierraPapa for the SharpDevelop Team (for details please see \doc\copyright.txt)
2
// This code is distributed under the GNU LGPL (for details please see \doc\license.txt)
5
using System.Diagnostics;
6
using System.Windows.Media;
7
using System.Collections.Generic;
9
using ICSharpCode.AvalonEdit.Document;
10
using ICSharpCode.AvalonEdit.Rendering;
11
using ICSharpCode.SharpDevelop.Editor;
12
using ICSharpCode.SharpDevelop.Refactoring;
14
namespace ICSharpCode.AvalonEdit.AddIn
17
/// Highlights expressions (references to expression under current caret).
19
public class ExpressionHighlightRenderer : IBackgroundRenderer
21
List<Reference> renderedReferences;
23
Brush backgroundBrush;
25
readonly Color borderColor = Color.FromArgb(52, 30, 130, 255); //Color.FromArgb(180, 70, 230, 70))
26
readonly Color fillColor = Color.FromArgb(22, 30, 130, 255); //Color.FromArgb(40, 60, 255, 60)
27
readonly int borderThickness = 1;
28
readonly int cornerRadius = 1;
30
public void SetHighlight(List<Reference> renderedReferences)
32
if (this.renderedReferences != renderedReferences) {
33
this.renderedReferences = renderedReferences;
34
textView.InvalidateLayer(this.Layer);
38
public void ClearHighlight()
40
this.SetHighlight(null);
43
public ExpressionHighlightRenderer(TextView textView)
46
throw new ArgumentNullException("textView");
47
this.textView = textView;
48
this.borderPen = new Pen(new SolidColorBrush(borderColor), borderThickness);
49
this.backgroundBrush = new SolidColorBrush(fillColor);
50
this.borderPen.Freeze();
51
this.backgroundBrush.Freeze();
52
this.textView.BackgroundRenderers.Add(this);
55
public KnownLayer Layer {
57
return KnownLayer.Selection;
61
public void Draw(TextView textView, DrawingContext drawingContext)
63
if (this.renderedReferences == null)
65
BackgroundGeometryBuilder builder = new BackgroundGeometryBuilder();
66
builder.CornerRadius = cornerRadius;
67
builder.AlignToMiddleOfPixels = true;
68
foreach (var reference in this.renderedReferences) {
69
builder.AddSegment(textView, new TextSegment() {
70
StartOffset = reference.Offset,
71
Length = reference.Length });
72
builder.CloseFigure();
74
Geometry geometry = builder.CreateGeometry();
75
if (geometry != null) {
76
drawingContext.DrawGeometry(backgroundBrush, borderPen, geometry);