69
69
layout = PangoUtil.CreateLayout (editor);
70
70
editor.Caret.PositionChanged += HandleEditorCaretPositionChanged;
71
71
editor.Document.FoldTreeUpdated += HandleEditorDocumentFoldTreeUpdated;
72
this.editor.Caret.PositionChanged += EditorCarethandlePositionChanged;
75
void EditorCarethandlePositionChanged (object sender, DocumentLocationEventArgs e)
77
if (!editor.Options.HighlightCaretLine || e.Location.Line == editor.Caret.Line)
79
editor.RedrawMarginLine (this, e.Location.Line);
80
editor.RedrawMarginLine (this, editor.Caret.Line);
74
83
void HandleEditorDocumentFoldTreeUpdated (object sender, EventArgs e)
76
85
editor.RedrawMargin (this);
79
88
void HandleEditorCaretPositionChanged (object sender, DocumentLocationEventArgs e)
81
90
if (!IsInCodeFocusMode)
159
168
RemoveBackgroundRenderer ();
171
List<FoldSegment> oldFolds;
163
172
bool SetBackgroundRenderer ()
174
List<FoldSegment> curFolds = new List<FoldSegment> (foldings);
175
if (oldFolds != null && oldFolds.Count == curFolds.Count) {
177
for (int i = 0; i < curFolds.Count; i++) {
178
if (oldFolds[i] != curFolds [i]) {
165
189
editor.TextViewMargin.DisposeLayoutDict ();
166
190
editor.TextViewMargin.BackgroundRenderer = new FoldingScreenbackgroundRenderer (editor, foldings);
167
191
editor.QueueDraw ();
202
227
internal protected override void OptionsChanged ()
204
foldBgGC = editor.ColorStyle.FoldLine.CairoBackgroundColor;
205
foldLineGC = editor.ColorStyle.FoldLine.CairoColor;
206
foldLineHighlightedGC = editor.ColorStyle.FoldLineHighlighted;
229
foldBgGC = editor.ColorStyle.PlainText.Background;
230
foldLineGC = editor.ColorStyle.FoldLineColor.Color;
231
foldLineHighlightedGC = editor.ColorStyle.PlainText.Foreground;
208
HslColor hslColor = new HslColor (editor.ColorStyle.Default.CairoBackgroundColor);
233
HslColor hslColor = new HslColor (editor.ColorStyle.PlainText.Background);
209
234
double brightness = HslColor.Brightness (hslColor);
210
235
if (brightness < 0.5) {
211
236
hslColor.L = hslColor.L * 0.85 + hslColor.L * 0.25;
216
241
foldLineHighlightedGCBg = hslColor;
217
foldToggleMarkerGC = editor.ColorStyle.FoldToggleMarker;
218
lineStateChangedGC = editor.ColorStyle.LineChangedBg;
219
lineStateDirtyGC = editor.ColorStyle.LineDirtyBg;
242
foldToggleMarkerGC = editor.ColorStyle.FoldCross.Color;
243
foldToggleMarkerBackground = editor.ColorStyle.FoldCross.SecondColor;
244
lineStateChangedGC = editor.ColorStyle.QuickDiffChanged.Color;
245
lineStateDirtyGC = editor.ColorStyle.QuickDiffDirty.Color;
221
247
marginWidth = editor.LineHeight;
224
Cairo.Color foldBgGC, foldLineGC, foldLineHighlightedGC, foldLineHighlightedGCBg, foldToggleMarkerGC;
250
Cairo.Color foldBgGC, foldLineGC, foldLineHighlightedGC, foldLineHighlightedGCBg, foldToggleMarkerGC, foldToggleMarkerBackground;
225
251
Cairo.Color lineStateChangedGC, lineStateDirtyGC;
227
253
public override void Dispose ()
231
257
editor.Document.FoldTreeUpdated -= HandleEditorDocumentFoldTreeUpdated;
232
258
layout = layout.Kill ();
235
261
void DrawFoldSegment (Cairo.Context ctx, double x, double y, bool isOpen, bool isSelected)
237
263
var drawArea = new Cairo.Rectangle (System.Math.Floor (x + (Width - foldSegmentSize) / 2) + 0.5,
238
System.Math.Floor (y + (editor.LineHeight - foldSegmentSize) / 2) + 0.5, foldSegmentSize, foldSegmentSize);
264
System.Math.Floor (y + (editor.LineHeight - foldSegmentSize) / 2) + 0.5, foldSegmentSize, foldSegmentSize);
239
265
ctx.Rectangle (drawArea);
240
ctx.Color = foldBgGC;
266
ctx.Color = isOpen ? foldBgGC : foldToggleMarkerBackground;
241
267
ctx.FillPreserve ();
242
268
ctx.Color = isSelected ? foldLineHighlightedGC : foldLineGC;
245
ctx.DrawLine (foldToggleMarkerGC,
271
ctx.DrawLine (isSelected ? foldLineHighlightedGC : foldToggleMarkerGC,
246
272
drawArea.X + drawArea.Width * 2 / 10,
247
273
drawArea.Y + drawArea.Height / 2,
248
274
drawArea.X + drawArea.Width - drawArea.Width * 2 / 10,
249
275
drawArea.Y + drawArea.Height / 2);
252
ctx.DrawLine (foldToggleMarkerGC,
278
ctx.DrawLine (isSelected ? foldLineHighlightedGC : foldToggleMarkerGC,
253
279
drawArea.X + drawArea.Width / 2,
254
280
drawArea.Y + drawArea.Height * 2 / 10,
255
281
drawArea.X + drawArea.Width / 2,
298
isFoldStart = startFoldings.Count > 0;
324
isFoldStart = startFoldings.Count > 0;
299
325
isContaining = containingFoldings.Count > 0;
300
isFoldEnd = endFoldings.Count > 0;
326
isFoldEnd = endFoldings.Count > 0;
302
isStartSelected = this.lineHover != null && IsMouseHover (startFoldings);
328
isStartSelected = this.lineHover != null && IsMouseHover (startFoldings);
303
329
isContainingSelected = this.lineHover != null && IsMouseHover (containingFoldings);
304
isEndSelected = this.lineHover != null && IsMouseHover (endFoldings);
308
if (editor.TextViewMargin.BackgroundRenderer != null) {
309
if (isContainingSelected || isStartSelected || isEndSelected) {
312
bgGC = foldLineHighlightedGCBg;
316
cr.Rectangle (drawArea);
320
if (state == TextDocument.LineState.Changed) {
321
cr.Color = lineStateChangedGC;
322
cr.Rectangle (x + 1, y, marginWidth / 3, lineHeight);
324
} else if (state == TextDocument.LineState.Dirty) {
325
cr.Color = lineStateDirtyGC;
326
cr.Rectangle (x + 1, y, marginWidth / 3, lineHeight);
330
if (line < editor.Document.LineCount) {
330
isEndSelected = this.lineHover != null && IsMouseHover (endFoldings);
333
if (editor.Options.HighlightCaretLine && editor.Caret.Line == line) {
334
editor.TextViewMargin.DrawCaretLineMarker (cr, x, y, Width, lineHeight);
337
if (editor.TextViewMargin.BackgroundRenderer != null) {
338
if (isContainingSelected || isStartSelected || isEndSelected) {
341
bgGC = foldLineHighlightedGCBg;
345
cr.Rectangle (drawArea);
350
if (editor.Options.EnableQuickDiff) {
351
if (state == TextDocument.LineState.Changed) {
352
cr.Color = lineStateChangedGC;
353
cr.Rectangle (x + 1, y, marginWidth / 3, lineHeight);
355
} else if (state == TextDocument.LineState.Dirty) {
356
cr.Color = lineStateDirtyGC;
357
cr.Rectangle (x + 1, y, marginWidth / 3, lineHeight);
362
if (editor.Options.ShowFoldMargin && line < editor.Document.LineCount) {
331
363
double foldSegmentYPos = y + System.Math.Floor (editor.LineHeight - foldSegmentSize) / 2;
332
364
double xPos = x + System.Math.Floor (marginWidth / 2) + 0.5;
347
379
isFoldEndFromUpperFold = true;
349
381
DrawFoldSegment (cr, x, y, isVisible, isStartSelected);
351
383
if (isContaining || isFoldEndFromUpperFold)
352
384
cr.DrawLine (isContainingSelected ? foldLineHighlightedGC : foldLineGC, xPos, drawArea.Y, xPos, foldSegmentYPos - 2);
353
385
if (isContaining || moreLinedOpenFold)
354
386
cr.DrawLine (isEndSelected || (isStartSelected && isVisible) || isContainingSelected ? foldLineHighlightedGC : foldLineGC, xPos, foldSegmentYPos + foldSegmentSize + 2, xPos, drawArea.Y + drawArea.Height);
359
double yMid = drawArea.Y + drawArea.Height / 2;
391
double yMid = System.Math.Floor (drawArea.Y + drawArea.Height / 2) + 0.5;
360
392
cr.DrawLine (isEndSelected ? foldLineHighlightedGC : foldLineGC, xPos, yMid, x + marginWidth - 2, yMid);
361
393
cr.DrawLine (isContainingSelected || isEndSelected ? foldLineHighlightedGC : foldLineGC, xPos, drawArea.Y, xPos, yMid);
363
395
if (isContaining)
364
cr.DrawLine (isContainingSelected ? foldLineHighlightedGC : foldLineGC, xPos, yMid + 1, xPos, drawArea.Y + drawArea.Height);
396
cr.DrawLine (isContainingSelected ? foldLineHighlightedGC : foldLineGC, xPos, yMid, xPos, drawArea.Y + drawArea.Height);
365
397
} else if (isContaining) {
366
398
cr.DrawLine (isContainingSelected ? foldLineHighlightedGC : foldLineGC, xPos, drawArea.Y, xPos, drawArea.Y + drawArea.Height);