Free cookie consent management tool by TermsFeed Policy Generator

source: branches/2989_MovingPeaksBenchmark/HeuristicLab.ExtLibs/HeuristicLab.AvalonEdit/5.0.1/AvalonEdit-5.0.1/Rendering/CurrentLineHighlightRenderer.cs @ 18242

Last change on this file since 18242 was 11700, checked in by jkarder, 10 years ago

#2077: created branch and added first version

File size: 2.1 KB
Line 
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)
3
4using System;
5using System.Windows;
6using System.Windows.Media;
7
8using ICSharpCode.AvalonEdit.Rendering;
9
10namespace ICSharpCode.AvalonEdit.Rendering
11{
12  sealed class CurrentLineHighlightRenderer : IBackgroundRenderer
13  {
14    #region Fields
15   
16    int line;
17    TextView textView;
18   
19    public static readonly Color DefaultBackground = Color.FromArgb(22, 20, 220, 224);
20    public static readonly Color DefaultBorder = Color.FromArgb(52, 0, 255, 110);
21   
22    #endregion
23
24    #region Properties
25   
26    public int Line {
27      get { return this.Line; }
28      set {
29        if (this.line != value) {
30          this.line = value;
31          this.textView.InvalidateLayer(this.Layer);
32        }
33      }
34    }
35   
36    public KnownLayer Layer
37    {
38      get { return KnownLayer.Selection; }
39    }
40   
41    public Brush BackgroundBrush {
42      get; set;
43    }
44   
45    public Pen BorderPen {
46      get; set;
47    }
48   
49    #endregion   
50   
51    public CurrentLineHighlightRenderer(TextView textView)
52    {
53      if (textView == null)
54        throw new ArgumentNullException("textView");
55     
56      this.BorderPen = new Pen(new SolidColorBrush(DefaultBorder), 1);
57      this.BorderPen.Freeze();
58     
59      this.BackgroundBrush = new SolidColorBrush(DefaultBackground);
60      this.BackgroundBrush.Freeze();
61     
62      this.textView = textView;
63      this.textView.BackgroundRenderers.Add(this);
64     
65      this.line = 0;
66    }
67   
68    public void Draw(TextView textView, DrawingContext drawingContext)
69    {
70      if(!this.textView.Options.HighlightCurrentLine)
71        return;
72     
73      BackgroundGeometryBuilder builder = new BackgroundGeometryBuilder();
74     
75      var visualLine = this.textView.GetVisualLine(line);
76      if (visualLine == null) return;
77     
78      var linePosY = visualLine.VisualTop - this.textView.ScrollOffset.Y;
79     
80      builder.AddRectangle(textView, new Rect(0, linePosY, textView.ActualWidth, visualLine.Height));
81     
82      Geometry geometry = builder.CreateGeometry();
83      if (geometry != null) {
84        drawingContext.DrawGeometry(this.BackgroundBrush, this.BorderPen, geometry);
85      }
86    }
87  }
88}
Note: See TracBrowser for help on using the repository browser.