48
44
get { return editor.Document; }
47
readonly DateTime startTime;
49
const uint animationLength = 250;
50
public bool AnimationFinished {
52
var age = (DateTime.Now - startTime).TotalMilliseconds;
53
return age >= animationLength;
51
57
public FoldingScreenbackgroundRenderer (TextEditor editor, IEnumerable<FoldSegment> foldSegments)
53
59
this.editor = editor;
54
60
this.foldSegments = new List<FoldSegment> (foldSegments);
55
this.roles = new Roles[this.foldSegments.Count];
61
startTime = DateTime.Now;
62
timeout = GLib.Timeout.Add (30, delegate {
64
var cont = (DateTime.Now - startTime).TotalMilliseconds < animationLength;
58
public void Draw (Cairo.Context cr, Cairo.Rectangle area, DocumentLine lineSegment, double x, double y, double lineHeight)
71
HslColor GetColor (int i, double brightness, int colorCount)
60
int foundSegment = -1;
61
if (lineSegment != null) {
62
for (int i = 0; i < foldSegments.Count; i++) {
63
FoldSegment segment = foldSegments [i];
64
if (segment.StartLine.Offset <= lineSegment.Offset && lineSegment.EndOffsetIncludingDelimiter <= segment.EndLine.EndOffsetIncludingDelimiter) {
66
roles [i] = Roles.Between;
67
if (segment.StartLine.Offset == lineSegment.Offset) {
68
roles [i] |= Roles.Start;
70
roles [i] |= Roles.End;
72
if (segment.EndLine.Offset == lineSegment.Offset)
73
roles [i] |= Roles.End;
73
HslColor hslColor = new HslColor (editor.ColorStyle.PlainText.Background);
74
int colorPosition = i + 1;
75
if (i == foldSegments.Count - 1)
77
if (brightness < 0.5) {
78
hslColor.L = hslColor.L * 0.81 + hslColor.L * 0.25 * (colorCount - colorPosition) / colorCount;
80
hslColor.L = hslColor.L * 0.86 + hslColor.L * 0.1 * colorPosition / colorCount;
85
public void Draw (Cairo.Context cr, Cairo.Rectangle area)
77
87
TextViewMargin textViewMargin = editor.TextViewMargin;
78
88
ISyntaxMode mode = Document.SyntaxMode != null && editor.Options.EnableSyntaxHighlighting ? Document.SyntaxMode : new SyntaxMode (Document);
80
// Gdk.Rectangle lineArea = new Gdk.Rectangle (textViewMargin.XOffset, y, editor.Allocation.Width - textViewMargin.XOffset, editor.LineHeight);
81
// Gdk.GC gc = new Gdk.GC (drawable);
82
90
TextViewMargin.LayoutWrapper lineLayout = null;
83
double brightness = HslColor.Brightness (editor.ColorStyle.Default.BackgroundColor);
91
double brightness = HslColor.Brightness (editor.ColorStyle.PlainText.Background);
85
93
int colorCount = foldSegments.Count + 2;
86
for (int segment = -1; segment <= foundSegment; segment++) {
87
HslColor hslColor = new HslColor (editor.ColorStyle.Default.BackgroundColor);
88
int colorPosition = segment + 1;
89
if (segment == foldSegments.Count - 1)
91
if (brightness < 0.5) {
92
hslColor.L = hslColor.L * 0.81 + hslColor.L * 0.25 * (colorCount - colorPosition) / colorCount;
94
hslColor.L = hslColor.L * 0.86 + hslColor.L * 0.1 * colorPosition / colorCount;
97
Roles role = Roles.Between;
94
cr.Color = GetColor (-1, brightness, colorCount);
97
var rectangles = new Cairo.Rectangle[foldSegments.Count];
98
const int xPadding = 4;
99
const int yPadding = 2;
100
const int rightMarginPadding = 16;
101
for (int i = foldSegments.Count - 1; i >= 0 ; i--) {
102
var segment = foldSegments [i];
103
var segmentStartLine = segment.StartLine;
104
var segmentEndLine = segment.EndLine;
107
var endLine = segmentEndLine.NextLine;
108
var y = editor.LineToY (segmentStartLine.LineNumber);
109
if (y < editor.VAdjustment.Value) {
110
segmentStartLine = editor.GetLine (editor.YToLine (editor.VAdjustment.Value));
111
y = editor.LineToY (segmentStartLine.LineNumber);
114
for (var curLine = segmentStartLine; curLine != endLine && y < editor.VAdjustment.Value + editor.Allocation.Height; curLine = curLine.NextLine) {
115
var curLayout = textViewMargin.CreateLinePartLayout (mode, curLine, curLine.Offset, curLine.Length, -1, -1);
116
var width = (int)(curLayout.PangoWidth / Pango.Scale.PangoScale);
117
curWidth = System.Math.Max (curWidth, width);
118
y += editor.GetLineHeight (curLine);
98
121
double xPos = textViewMargin.XOffset;
99
double rectangleWidth = editor.Allocation.Width - xPos;
101
DocumentLine segmentStartLine = foldSegments [segment].StartLine;
102
lineLayout = textViewMargin.CreateLinePartLayout (mode, segmentStartLine, segmentStartLine.Offset, segmentStartLine.Length, -1, -1);
103
Pango.Rectangle rectangle = lineLayout.Layout.IndexToPos (GetFirstNonWsIdx (lineLayout.Layout.Text));
104
xPos = System.Math.Max (textViewMargin.XOffset, (textViewMargin.XOffset + rectangle.X / Pango.Scale.PangoScale - editor.HAdjustment.Value));
106
DocumentLine segmentEndLine = foldSegments [segment].EndLine;
107
lineLayout = textViewMargin.CreateLinePartLayout (mode, segmentEndLine, segmentEndLine.Offset, segmentEndLine.Length, -1, -1);
108
rectangle = lineLayout.Layout.IndexToPos (GetFirstNonWsIdx (lineLayout.Layout.Text));
109
xPos = System.Math.Min (xPos, System.Math.Max (textViewMargin.XOffset, (textViewMargin.XOffset + rectangle.X / Pango.Scale.PangoScale - editor.HAdjustment.Value)));
111
int width = editor.Allocation.Width;
112
if (editor.HAdjustment.Upper > width) {
113
width = (int)(textViewMargin.XOffset + editor.HAdjustment.Upper - editor.HAdjustment.Value);
115
rectangleWidth = (int)(width - xPos - 6 * (segment + 1));
116
role = roles [segment];
118
DrawRoundRectangle (cr, (role & Roles.Start) == Roles.Start, (role & Roles.End) == Roles.End, xPos, y, editor.LineHeight / 2, rectangleWidth, lineHeight);
119
cr.Color = ColorScheme.ToCairoColor (hslColor);
122
double rectangleWidth = 0, rectangleHeight = 0;
124
lineLayout = textViewMargin.CreateLinePartLayout (mode, segmentStartLine, segmentStartLine.Offset, segmentStartLine.Length, -1, -1);
125
var rectangleStart = lineLayout.Layout.IndexToPos (GetFirstNonWsIdx (lineLayout.Layout.Text));
126
xPos = System.Math.Max (textViewMargin.XOffset, (textViewMargin.XOffset + textViewMargin.TextStartPosition + rectangleStart.X / Pango.Scale.PangoScale) - xPadding);
128
lineLayout = textViewMargin.CreateLinePartLayout (mode, segmentEndLine, segmentEndLine.Offset, segmentEndLine.Length, -1, -1);
130
var rectangleEnd = lineLayout.Layout.IndexToPos (GetFirstNonWsIdx (lineLayout.Layout.Text));
131
xPos = System.Math.Min (xPos, System.Math.Max (textViewMargin.XOffset, (textViewMargin.XOffset + textViewMargin.TextStartPosition + rectangleEnd.X / Pango.Scale.PangoScale) - xPadding));
133
rectangleWidth = textViewMargin.XOffset + textViewMargin.TextStartPosition + curWidth - xPos + xPadding * 2;
135
if (i < foldSegments.Count - 1) {
136
rectangleWidth = System.Math.Max ((rectangles [i + 1].X + rectangles[i + 1].Width + rightMarginPadding) - xPos, rectangleWidth);
139
y = editor.LineToY (segment.StartLine.LineNumber);
140
var yEnd = editor.LineToY (segment.EndLine.LineNumber + 1);
142
yEnd = editor.VAdjustment.Upper;
143
rectangleHeight = yEnd - y;
145
rectangles[i] = new Cairo.Rectangle (xPos, y - yPadding, rectangleWidth, rectangleHeight + yPadding * 2);
148
for (int i = 0; i < foldSegments.Count; i++) {
149
var rect = rectangles[i];
151
if (i == foldSegments.Count - 1) {
152
/* var radius = (int)(editor.Options.Zoom * 2);
154
using (var shadow = new Blur (
155
System.Math.Min ((int)rect.Width + w * 2, editor.Allocation.Width),
156
System.Math.Min ((int)rect.Height + w * 2, editor.Allocation.Height),
158
using (var gctx = shadow.GetContext ()) {
159
gctx.Color = new Cairo.Color (0, 0, 0, 0);
164
DrawRoundRectangle (gctx, true, true, w - a, w - b, editor.LineHeight / 4, rect.Width + a * 2, rect.Height + a * 2);
165
var bg = editor.ColorStyle.Default.CairoColor;
166
gctx.Color = new Cairo.Color (bg.R, bg.G, bg.B, 0.6);
171
cr.Translate (rect.X - w - editor.HAdjustment.Value, rect.Y - editor.VAdjustment.Value - w);
178
var age = (DateTime.Now - startTime).TotalMilliseconds;
180
if (age < animationLength) {
181
var animationState = age / (double)animationLength;
182
curPadSize = (int)(3 + System.Math.Sin (System.Math.PI * animationState) * 3);
183
alpha = 0.1 + (1.0 - animationState) / 5;
186
var bg = editor.ColorStyle.PlainText.Foreground;
187
cr.Color = new Cairo.Color (bg.R, bg.G, bg.B, alpha);
188
DrawRoundRectangle (cr, true, true, rect.X - editor.HAdjustment.Value - curPadSize , rect.Y - editor.VAdjustment.Value - curPadSize, editor.LineHeight / 2, rect.Width + curPadSize * 2, rect.Height + curPadSize * 2);
191
if (age < animationLength) {
192
var animationState = age / (double)animationLength;
193
curPadSize = (int)(2 + System.Math.Sin (System.Math.PI * animationState) * 2);
194
DrawRoundRectangle (cr, true, true, rect.X - editor.HAdjustment.Value - curPadSize, rect.Y - editor.VAdjustment.Value - curPadSize, editor.LineHeight / 2, rect.Width + curPadSize * 2, rect.Height + curPadSize * 2);
195
cr.Color = GetColor (i, brightness, colorCount);
202
DrawRoundRectangle (cr, true, true, rect.X - editor.HAdjustment.Value, rect.Y - editor.VAdjustment.Value, editor.LineHeight / 2, rect.Width, rect.Height);
204
cr.Color = GetColor (i, brightness, colorCount);
121
/* if (segment == foldSegments.Count - 1) {
122
cr.Color = new Cairo.Color (0.5, 0.5, 0.5, 1);
125
if (lineLayout != null && lineLayout.IsUncached) {
126
lineLayout.Dispose ();
133
209
public static void DrawRoundRectangle (Cairo.Context cr, bool upperRound, bool lowerRound, double x, double y, double r, double w, double h)