Welcome to mirror list, hosted at ThFree Co, Russian Federation.

UsageSegmentMarker.cs « TextMarker « MonoDevelop.SourceEditor « MonoDevelop.SourceEditor2 « addins « src « main - github.com/mono/monodevelop.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
blob: bdd4c7c59dba580443dd57eaf950cdaf4b2c3a0a (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
using System;
using Mono.TextEditor;
using MonoDevelop.Ide.Editor;
using MonoDevelop.Ide.FindInFiles;
using Cairo;
using MonoDevelop.Components;
using MonoDevelop.Ide.Editor.Extension;

namespace MonoDevelop.SourceEditor
{
	class UsageSegmentMarker : TextSegmentMarker, ITextSegmentMarker
	{
		readonly Usage usage;

		public Usage Usage {
			get {
				return usage;
			}
		}

		public UsageSegmentMarker (Usage usage) : base (usage.Offset, usage.Length)
		{
			this.usage = usage;
		}

		event EventHandler<TextMarkerMouseEventArgs> ITextSegmentMarker.MousePressed {
			add {
			}
			remove {
			}
		}

		event EventHandler<TextMarkerMouseEventArgs> ITextSegmentMarker.MouseHover {
			add {
			}
			remove {
			}
		}

		object ITextSegmentMarker.Tag {
			get;
			set;
		}

		public override void DrawBackground (Mono.TextEditor.MonoTextEditor editor, Context cr, LineMetrics metrics, int startOffset, int endOffset)
		{
			int markerStart = usage.Offset;
			int markerEnd = usage.EndOffset;

			if (markerEnd < startOffset || markerStart > endOffset) 
				return; 

			double @from;
			double to;
			var startXPos = metrics.TextRenderStartPosition;
			var endXPos = metrics.TextRenderEndPosition;
			var y = metrics.LineYRenderStartPosition;
			if (markerStart < startOffset && endOffset < markerEnd) {
				@from = startXPos;
				to = endXPos;
			} else {
				int start = startOffset < markerStart ? markerStart : startOffset;
				int end = endOffset < markerEnd ? endOffset : markerEnd;

				uint curIndex = 0, byteIndex = 0;
				TextViewMargin.TranslateToUTF8Index (metrics.Layout.LineChars, (uint)(start - startOffset), ref curIndex, ref byteIndex);

				int x_pos = metrics.Layout.Layout.IndexToPos ((int)byteIndex).X;

				@from = startXPos + (int)(x_pos / Pango.Scale.PangoScale);

				TextViewMargin.TranslateToUTF8Index (metrics.Layout.LineChars, (uint)(end - startOffset), ref curIndex, ref byteIndex);
				x_pos = metrics.Layout.Layout.IndexToPos ((int)byteIndex).X;

				to = startXPos + (int)(x_pos / Pango.Scale.PangoScale);
			}

			@from = Math.Max (@from, editor.TextViewMargin.XOffset);
			to = Math.Max (to, editor.TextViewMargin.XOffset);
			if (@from < to) {
				Mono.TextEditor.Highlighting.AmbientColor colorStyle;
				if ((usage.UsageType & ReferenceUsageType.Write) == ReferenceUsageType.Write ||
					(usage.UsageType & ReferenceUsageType.Declariton) == ReferenceUsageType.Declariton) {
					colorStyle = editor.ColorStyle.ChangingUsagesRectangle;
				} else {
					colorStyle = editor.ColorStyle.UsagesRectangle;
				}

				using (var lg = new LinearGradient (@from + 1, y + 1, to , y + editor.LineHeight)) {
					lg.AddColorStop (0, colorStyle.Color);
					lg.AddColorStop (1, colorStyle.SecondColor);
					cr.SetSource (lg);
					cr.RoundedRectangle (@from + 0.5, y + 1.5, to - @from - 1, editor.LineHeight - 2, editor.LineHeight / 4);
					cr.FillPreserve ();
				}

				cr.SetSourceColor (colorStyle.BorderColor);
				cr.Stroke ();
			}
		}
	}
}