void DrawFoldSegment(Xwt.Drawing.Context ctx, double x, double y, bool isOpen, bool isSelected) { var drawArea = new Rectangle(System.Math.Floor(x + (Width - foldSegmentSize) / 2) + 0.5, System.Math.Floor(y + (editor.LineHeight - foldSegmentSize) / 2) + 0.5, foldSegmentSize, foldSegmentSize); ctx.Rectangle(drawArea); ctx.SetSourceColor(isOpen ? foldBgGC : foldToggleMarkerBackground); ctx.FillPreserve(); ctx.SetSourceColor(isSelected ? foldLineHighlightedGC : foldLineGC); ctx.Stroke(); ctx.DrawLine(isSelected ? foldLineHighlightedGC : foldToggleMarkerGC, drawArea.X + drawArea.Width * 2 / 10, drawArea.Y + drawArea.Height / 2, drawArea.X + drawArea.Width - drawArea.Width * 2 / 10, drawArea.Y + drawArea.Height / 2); if (!isOpen) { ctx.DrawLine(isSelected ? foldLineHighlightedGC : foldToggleMarkerGC, drawArea.X + drawArea.Width / 2, drawArea.Y + drawArea.Height * 2 / 10, drawArea.X + drawArea.Width / 2, drawArea.Y + drawArea.Height - drawArea.Height * 2 / 10); } }
void InternalDraw(int markerStart, int markerEnd, TextEditor editor, Xwt.Drawing.Context cr, TextLayout layout, bool selected, int startOffset, int endOffset, double y, double startXPos, double endXPos) { if (markerStart >= markerEnd) { return; } double @from; double to; if (markerStart < startOffset && endOffset < markerEnd) { @from = startXPos; to = endXPos; } else { int start = startOffset < markerStart ? markerStart : startOffset; int end = endOffset < markerEnd ? endOffset : markerEnd; double /*lineNr,*/ x_pos; x_pos = layout.GetCoordinateFromIndex(start - startOffset).X; @from = startXPos + (int)(x_pos); x_pos = layout.GetCoordinateFromIndex(end - startOffset).X; to = startXPos + (int)(x_pos); } @from = System.Math.Max(@from, editor.TextViewMargin.XOffset); to = System.Math.Max(to, editor.TextViewMargin.XOffset); if (@from >= to) { return; } double height = editor.LineHeight / 5; if (selected) { cr.SetSourceColor(editor.ColorStyle.SelectedText.Foreground); } else { cr.SetSourceColor(ColorName == null ? Color : editor.ColorStyle.GetChunkStyle(ColorName).Foreground); } if (Wave) { //Pango.CairoHelper.ShowErrorUnderline(cr, @from, y + editor.LineHeight - height, to - @from, height); } else { cr.SetLineWidth(1); cr.MoveTo(@from, y + editor.LineHeight - 1.5); cr.LineTo(to, y + editor.LineHeight - 1.5); cr.Stroke(); } }
protected override void OnDraw(Xwt.Drawing.Context cr, Rectangle bound) { { cr.Rectangle(bound.X, bound.Y, bound.Width, bound.Height); cr.SetSourceColor(editor.ColorStyle.PlainText.Background); cr.Fill(); using (var layout = PangoUtil.CreateLayout(editor)) { layout.Font = editor.Options.Font; layout.Text = "000,00-00"; var mins = layout.GetSize(); var line = editor.GetLine(editor.Caret.Line); var visColumn = line.GetVisualColumn(editor.GetTextEditorData(), editor.Caret.Column); if (visColumn != editor.Caret.Column) { layout.Text = editor.Caret.Line + "," + editor.Caret.Column + "-" + visColumn; } else { layout.Text = editor.Caret.Line + "," + editor.Caret.Column; } var statuss = layout.GetSize(); statuss.Width = System.Math.Max(statuss.Width, mins.Width); statuss.Width += 8; cr.MoveTo(Size.Width - statuss.Width, 0); statuss.Width += 8; cr.SetSourceColor(editor.ColorStyle.PlainText.Foreground); cr.ShowLayout(layout); layout.Text = statusText ?? ""; var size = layout.GetSize(); var x = System.Math.Min(0, -size.Width + Size.Width - editor.TextViewMargin.CharWidth - statuss.Width); cr.MoveTo(x, 0); cr.SetSourceColor(editor.ColorStyle.PlainText.Foreground); cr.ShowLayout(layout); if (ShowCaret) { if (editor.TextViewMargin.caretBlink) { cr.Rectangle(size.Width + x, 0, (int)editor.TextViewMargin.CharWidth, (int)editor.LineHeight); cr.Fill(); } } } } }
public override bool DrawBackground(TextEditor editor, Xwt.Drawing.Context cr, double y, LineMetrics metrics) { var caretOffset = editor.Caret.Offset - BaseOffset; foreach (var link in mode.Links) { if (!link.IsEditable) { continue; } bool isPrimaryHighlighted = link.PrimaryLink.Offset <= caretOffset && caretOffset <= link.PrimaryLink.EndOffset; foreach (TextSegment segment in link.Links) { if ((BaseOffset + segment.Offset <= metrics.TextStartOffset && metrics.TextStartOffset < BaseOffset + segment.EndOffset) || (metrics.TextStartOffset <= BaseOffset + segment.Offset && BaseOffset + segment.Offset < metrics.TextEndOffset)) { int strOffset = BaseOffset + segment.Offset - metrics.TextStartOffset; int strEndOffset = BaseOffset + segment.EndOffset - metrics.TextStartOffset; var x_pos = metrics.Layout.Layout.IndexToPos(strOffset).X; var x_pos2 = metrics.Layout.Layout.IndexToPos(strEndOffset).X; x_pos = (int)(x_pos); x_pos2 = (int)(x_pos2); Color fillGc, rectangleGc; if (segment == link.PrimaryLink) { fillGc = isPrimaryHighlighted ? editor.ColorStyle.PrimaryTemplateHighlighted.SecondColor : editor.ColorStyle.PrimaryTemplate.SecondColor; rectangleGc = isPrimaryHighlighted ? editor.ColorStyle.PrimaryTemplateHighlighted.SecondColor : editor.ColorStyle.PrimaryTemplate.SecondColor; } else { fillGc = isPrimaryHighlighted ? editor.ColorStyle.SecondaryTemplateHighlighted.SecondColor : editor.ColorStyle.SecondaryTemplate.SecondColor; rectangleGc = isPrimaryHighlighted ? editor.ColorStyle.SecondaryTemplateHighlighted.Color : editor.ColorStyle.SecondaryTemplate.Color; } // Draw segment double x1 = metrics.TextRenderStartPosition + x_pos - 1; double x2 = metrics.TextRenderStartPosition + x_pos2 - 1 + 0.5; cr.Rectangle(x1 + 0.5, y + 0.5, x2 - x1, editor.LineHeight - 1); cr.SetSourceColor(fillGc); cr.FillPreserve(); cr.SetSourceColor(rectangleGc); cr.Stroke(); } } } return(true); }
internal protected override void Draw(Xwt.Drawing.Context cr, Rectangle area, DocumentLine lineSegment, int line, double x, double y, double lineHeight) { cr.MoveTo(x + 0.5, y); cr.LineTo(x + 0.5, y + lineHeight); cr.SetSourceColor(color); cr.Stroke(); }
public static void DrawLine(this Xwt.Drawing.Context cr, Color color, double x1, double y1, double x2, double y2) { cr.SetSourceColor(color); cr.MoveTo(x1, y1); cr.LineTo(x2, y2); cr.Stroke(); }
internal protected override void Draw(Xwt.Drawing.Context ctx, Rectangle area, DocumentLine lineSegment, int line, double x, double y, double lineHeight) { bool backgroundIsDrawn = false; if (lineSegment != null) { foreach (var marker in lineSegment.Markers) { var marginMarker = marker as MarginMarker; if (marginMarker != null && marginMarker.CanDrawBackground(this)) { backgroundIsDrawn = marginMarker.DrawBackground(editor, ctx, new MarginDrawMetrics(this, area, lineSegment, line, x, y, lineHeight)); } } } if (!backgroundIsDrawn) { ctx.Rectangle(x, y, Width, lineHeight); ctx.SetSourceColor(backgroundColor); ctx.Fill(); ctx.MoveTo(x + Width - 0.5, y); ctx.LineTo(x + Width - 0.5, y + lineHeight); ctx.SetSourceColor(separatorColor); ctx.Stroke(); } if (lineSegment != null && line <= editor.Document.LineCount) { foreach (var marker in lineSegment.Markers) { var marginMarker = marker as MarginMarker; if (marginMarker != null && marginMarker.CanDrawForeground(this)) { marginMarker.DrawForeground(editor, ctx, new MarginDrawMetrics(this, area, lineSegment, line, x, y, lineHeight)); } } if (DrawEvent != null) { DrawEvent(this, new BookmarkMarginDrawEventArgs(editor, ctx, lineSegment, line, x, y)); } } }
void DrawGutterBackground(Xwt.Drawing.Context cr, int line, double x, double y, double lineHeight) { if (editor.Caret.Line == line) { editor.TextViewMargin.DrawCaretLineMarker(cr, x, y, Width, lineHeight); return; } cr.Rectangle(x, y, Width, lineHeight); cr.SetSourceColor(lineNumberBgGC); cr.Fill(); }
public override bool DrawBackground(TextEditor editor, Xwt.Drawing.Context cr, double y, LineMetrics metrics) { if (metrics.SelectionStart > 0) { return(true); } cr.SetSourceColor(color); cr.Rectangle(metrics.TextRenderStartPosition, y, metrics.TextRenderEndPosition - metrics.TextRenderStartPosition, editor.LineHeight); cr.Fill(); return(true); }
public override bool DrawBackground(TextEditor editor, Xwt.Drawing.Context cr, MarginDrawMetrics metrics) { var width = metrics.Width; cr.Rectangle(metrics.X, metrics.Y, metrics.Width, metrics.Height); var lineNumberGC = editor.ColorStyle.LineNumbers.Foreground; cr.SetSourceColor(editor.Caret.Line == metrics.LineNumber ? editor.ColorStyle.LineMarker.Color : lineNumberGC); cr.Fill(); return(true); }
internal protected override void Draw(Xwt.Drawing.Context cr, Rectangle area, DocumentLine lineSegment, int line, double x, double y, double lineHeight) { var gutterMarker = lineSegment != null ? (MarginMarker)lineSegment.Markers.FirstOrDefault(marker => marker is MarginMarker && ((MarginMarker)marker).CanDraw(this)) : null; if (gutterMarker != null && gutterMarker.CanDrawBackground(this)) { bool hasDrawn = gutterMarker.DrawBackground(editor, cr, new MarginDrawMetrics(this, area, lineSegment, line, x, y, lineHeight)); if (!hasDrawn) { DrawGutterBackground(cr, line, x, y, lineHeight); } } else { DrawGutterBackground(cr, line, x, y, lineHeight); } if (gutterMarker != null && gutterMarker.CanDrawForeground(this)) { gutterMarker.DrawForeground(editor, cr, new MarginDrawMetrics(this, area, lineSegment, line, x, y, lineHeight)); return; } if (line <= editor.Document.LineCount) { // Due to a mac? gtk bug I need to re-create the layout here // otherwise I get pango exceptions. using (var layout = editor.LayoutCache.RequestLayout()) { layout.Font = gutterFont; layout.Width = (int)Width; layout.Alignment = Alignment.End; layout.SetText(line.ToString()); cr.Save(); cr.Translate(x + (int)Width + (editor.Options.ShowFoldMargin ? 0 : -2), y); cr.SetSourceColor(lineNumberGC); cr.ShowLayout(layout); cr.Restore(); } } }
public override void DrawForeground(TextEditor editor, Xwt.Drawing.Context cr, MarginDrawMetrics metrics) { var width = metrics.Width; var lineNumberBgGC = editor.ColorStyle.LineNumbers.Background; if (metrics.LineNumber <= editor.Document.LineCount) { // Due to a mac? gtk bug I need to re-create the layout here // otherwise I get pango exceptions. using (var layout = PangoUtil.CreateLayout(editor)) { layout.Font = editor.Options.Font; layout.Width = (int)width; layout.TextAlignment = Alignment.End; layout.Text = metrics.LineNumber.ToString(); cr.Save(); cr.Translate(metrics.X + (int)width + (editor.Options.ShowFoldMargin ? 0 : -2), metrics.Y); cr.SetSourceColor(lineNumberBgGC); cr.ShowLayout(layout); cr.Restore(); } } }
public void Draw(Xwt.Drawing.Context cr, Rectangle area) { TextViewMargin textViewMargin = editor.TextViewMargin; ISyntaxMode mode = Document.SyntaxMode != null && editor.Options.EnableSyntaxHighlighting ? Document.SyntaxMode : new SyntaxMode(Document); TextViewMargin.LayoutWrapper lineLayout = null; double brightness = HslColor.Brightness(editor.ColorStyle.PlainText.Background); int colorCount = foldSegments.Count + 2; cr.SetColor(GetColor(-1, brightness, colorCount)); cr.Rectangle(area); cr.Fill(); var rectangles = new Rectangle[foldSegments.Count]; const int xPadding = 4; const int yPadding = 2; const int rightMarginPadding = 16; for (int i = foldSegments.Count - 1; i >= 0; i--) { var segment = foldSegments[i]; if (segment.IsInvalid) { continue; } var segmentStartLine = segment.StartLine; var segmentEndLine = segment.EndLine; int curWidth = 0; var endLine = segmentEndLine.NextLine; var y = editor.LineToY(segmentStartLine.LineNumber); if (y < editor.VAdjustment.Value) { segmentStartLine = editor.GetLine(editor.YToLine(editor.VAdjustment.Value)); y = editor.LineToY(segmentStartLine.LineNumber); } for (var curLine = segmentStartLine; curLine != endLine && y < editor.VAdjustment.Value + editor.Size.Height; curLine = curLine.NextLine) { var curLayout = textViewMargin.CreateLinePartLayout(mode, curLine, curLine.Offset, curLine.Length, -1, -1); var width = (int)(curLayout.Width); curWidth = System.Math.Max(curWidth, width); y += editor.GetLineHeight(curLine); } double xPos = textViewMargin.XOffset; double rectangleWidth = 0, rectangleHeight = 0; lineLayout = textViewMargin.CreateLinePartLayout(mode, segmentStartLine, segmentStartLine.Offset, segmentStartLine.Length, -1, -1); var rectangleStart = lineLayout.Layout.IndexToPos(GetFirstNonWsIdx(lineLayout.Layout.Text)); xPos = System.Math.Max(textViewMargin.XOffset, (textViewMargin.XOffset + textViewMargin.TextStartPosition + rectangleStart.X) - xPadding); lineLayout = textViewMargin.CreateLinePartLayout(mode, segmentEndLine, segmentEndLine.Offset, segmentEndLine.Length, -1, -1); var rectangleEnd = lineLayout.Layout.IndexToPos(GetFirstNonWsIdx(lineLayout.Layout.Text)); xPos = System.Math.Min(xPos, System.Math.Max(textViewMargin.XOffset, (textViewMargin.XOffset + textViewMargin.TextStartPosition + rectangleEnd.X) - xPadding)); rectangleWidth = textViewMargin.XOffset + textViewMargin.TextStartPosition + curWidth - xPos + xPadding * 2; if (i < foldSegments.Count - 1) { rectangleWidth = System.Math.Max((rectangles[i + 1].X + rectangles[i + 1].Width + rightMarginPadding) - xPos, rectangleWidth); } y = editor.LineToY(segment.StartLine.LineNumber); var yEnd = editor.LineToY(segment.EndLine.LineNumber + 1) + (segment.EndLine.LineNumber == editor.LineCount ? editor.LineHeight : 0); if (yEnd == 0) { yEnd = editor.VAdjustment.UpperValue; } rectangleHeight = yEnd - y; rectangles[i] = new Rectangle(xPos, y - yPadding, rectangleWidth, rectangleHeight + yPadding * 2); } for (int i = 0; i < foldSegments.Count; i++) { Rectangle clampedRect; var rect = rectangles[i]; if (i == foldSegments.Count - 1) { /* var radius = (int)(editor.Options.Zoom * 2); * int w = 2 * radius; * using (var shadow = new Blur ( * System.Math.Min ((int)rect.Width + w * 2, editor.Allocation.Width), * System.Math.Min ((int)rect.Height + w * 2, editor.Allocation.Height), * radius)) { * using (var gctx = shadow.GetContext ()) { * gctx.Color = new Color (0, 0, 0, 0); * gctx.Fill (); * * var a = 0; * var b = 0; * DrawRoundRectangle (gctx, true, true, w - a, w - b, editor.LineHeight / 4, rect.Width + a * 2, rect.Height + a * 2); * var bg = editor.ColorStyle.Default.CairoColor; * gctx.Color = new Color (bg.R, bg.G, bg.B, 0.6); * gctx.Fill (); * } * * cr.Save (); * cr.Translate (rect.X - w - editor.HAdjustment.Value, rect.Y - editor.VAdjustment.Value - w); * shadow.Draw (cr); * cr.Restore (); * }*/ var curPadSize = 1; var age = (DateTime.Now - startTime).TotalMilliseconds; var alpha = 0.1; if (age < animationLength) { var animationState = age / (double)animationLength; curPadSize = (int)(3 + System.Math.Sin(System.Math.PI * animationState) * 3); alpha = 0.1 + (1.0 - animationState) / 5; } var bg = editor.ColorStyle.PlainText.Foreground; cr.SetColor(bg.WithAlpha(alpha)); clampedRect = ClampRect(rect.X - editor.HAdjustment.Value - curPadSize, rect.Y - editor.VAdjustment.Value - curPadSize, editor.LineHeight / 2, rect.Width + curPadSize * 2, rect.Height + curPadSize * 2, area); DrawRoundRectangle(cr, true, true, clampedRect.X, clampedRect.Y, editor.LineHeight / 2, clampedRect.Width, clampedRect.Height); cr.Fill(); if (age < animationLength) { var animationState = age / (double)animationLength; curPadSize = (int)(2 + System.Math.Sin(System.Math.PI * animationState) * 2); clampedRect = ClampRect(rect.X - editor.HAdjustment.Value - curPadSize, rect.Y - editor.VAdjustment.Value - curPadSize, editor.LineHeight / 2, rect.Width + curPadSize * 2, rect.Height + curPadSize * 2, area); DrawRoundRectangle(cr, true, true, clampedRect.X, clampedRect.Y, editor.LineHeight / 2, clampedRect.Width, clampedRect.Height); cr.SetSourceColor(GetColor(i, brightness, colorCount)); cr.Fill(); continue; } } clampedRect = ClampRect(rect.X - editor.HAdjustment.Value, rect.Y - editor.VAdjustment.Value, editor.LineHeight / 2, rect.Width, rect.Height, area); DrawRoundRectangle(cr, true, true, clampedRect.X, clampedRect.Y, editor.LineHeight / 2, clampedRect.Width, clampedRect.Height); cr.SetSourceColor(GetColor(i, brightness, colorCount)); cr.Fill(); } }
internal protected override void Draw(Xwt.Drawing.Context cr, Rectangle area, DocumentLine lineSegment, int line, double x, double y, double lineHeight) { var marker = lineSegment != null ? (MarginMarker)lineSegment.Markers.FirstOrDefault(m => m is MarginMarker && ((MarginMarker)m).CanDraw(this)) : null; if (marker != null) { bool hasDrawn = marker.DrawBackground(editor, cr, new MarginDrawMetrics(this, area, lineSegment, line, x, y, lineHeight)); if (!hasDrawn) { marker = null; } } foldSegmentSize = marginWidth * 4 / 6; foldSegmentSize -= (foldSegmentSize) % 2; Rectangle drawArea = new Rectangle(x, y, marginWidth, lineHeight); var state = editor.Document.GetLineState(lineSegment); bool isFoldStart = false; bool isContaining = false; bool isFoldEnd = false; bool isStartSelected = false; bool isContainingSelected = false; bool isEndSelected = false; if (editor.Options.ShowFoldMargin && line <= editor.Document.LineCount) { startFoldings.Clear(); containingFoldings.Clear(); endFoldings.Clear(); foreach (FoldSegment segment in editor.Document.GetFoldingContaining(lineSegment)) { if (segment.StartLine.Offset == lineSegment.Offset) { startFoldings.Add(segment); } else if (segment.EndLine.Offset == lineSegment.Offset) { endFoldings.Add(segment); } else { containingFoldings.Add(segment); } } isFoldStart = startFoldings.Count > 0; isContaining = containingFoldings.Count > 0; isFoldEnd = endFoldings.Count > 0; isStartSelected = this.lineHover != null && IsMouseHover(startFoldings); isContainingSelected = this.lineHover != null && IsMouseHover(containingFoldings); isEndSelected = this.lineHover != null && IsMouseHover(endFoldings); } if (marker == null) { if (editor.GetTextEditorData().HighlightCaretLine&& editor.Caret.Line == line) { editor.TextViewMargin.DrawCaretLineMarker(cr, x, y, Width, lineHeight); } else { var bgGC = foldBgGC; if (editor.TextViewMargin.BackgroundRenderer != null) { if (isContainingSelected || isStartSelected || isEndSelected) { bgGC = foldBgGC; } else { bgGC = foldLineHighlightedGCBg; } } cr.Rectangle(drawArea); cr.SetSourceColor(bgGC); cr.Fill(); } } if (editor.Options.EnableQuickDiff) { if (state == TextDocument.LineState.Changed) { cr.SetSourceColor(lineStateChangedGC); cr.Rectangle(x + 1, y, marginWidth / 3, lineHeight); cr.Fill(); } else if (state == TextDocument.LineState.Dirty) { cr.SetSourceColor(lineStateDirtyGC); cr.Rectangle(x + 1, y, marginWidth / 3, lineHeight); cr.Fill(); } } if (editor.Options.ShowFoldMargin && line <= editor.Document.LineCount) { double foldSegmentYPos = y + System.Math.Floor(editor.LineHeight - foldSegmentSize) / 2; double xPos = x + System.Math.Floor(marginWidth / 2) + 0.5; if (isFoldStart) { bool isVisible = true; bool moreLinedOpenFold = false; foreach (FoldSegment foldSegment in startFoldings) { if (foldSegment.IsFolded) { isVisible = false; } else { moreLinedOpenFold = foldSegment.EndLine.Offset > foldSegment.StartLine.Offset; } } bool isFoldEndFromUpperFold = false; foreach (FoldSegment foldSegment in endFoldings) { if (foldSegment.EndLine.Offset > foldSegment.StartLine.Offset && !foldSegment.IsFolded) { isFoldEndFromUpperFold = true; } } DrawFoldSegment(cr, x, y, isVisible, isStartSelected); if (isContaining || isFoldEndFromUpperFold) { cr.DrawLine(isContainingSelected ? foldLineHighlightedGC : foldLineGC, xPos, drawArea.Y, xPos, foldSegmentYPos - 2); } if (isContaining || moreLinedOpenFold) { cr.DrawLine(isEndSelected || (isStartSelected && isVisible) || isContainingSelected ? foldLineHighlightedGC : foldLineGC, xPos, foldSegmentYPos + foldSegmentSize + 2, xPos, drawArea.Y + drawArea.Height); } } else { if (isFoldEnd) { double yMid = System.Math.Floor(drawArea.Y + drawArea.Height / 2) + 0.5; cr.DrawLine(isEndSelected ? foldLineHighlightedGC : foldLineGC, xPos, yMid, x + marginWidth - 2, yMid); cr.DrawLine(isContainingSelected || isEndSelected ? foldLineHighlightedGC : foldLineGC, xPos, drawArea.Y, xPos, yMid); if (isContaining) { cr.DrawLine(isContainingSelected ? foldLineHighlightedGC : foldLineGC, xPos, yMid, xPos, drawArea.Y + drawArea.Height); } } else if (isContaining) { cr.DrawLine(isContainingSelected ? foldLineHighlightedGC : foldLineGC, xPos, drawArea.Y, xPos, drawArea.Y + drawArea.Height); } } } }