public override void DrawBackground(MonoTextEditor editor, Cairo.Context cr, LineMetrics metrics, int startOffset, int endOffset) { this.editor = editor; int markerStart = base.Offset; int markerEnd = base.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) { cr.SetSourceColor(background(editor).Color); cr.RoundedRectangle(@from + 2.5, y + 0.5, to - @from, editor.LineHeight - 1, 2); // 2.5 to make space for the column guideline if (background(editor).HasBorderColor) { cr.FillPreserve(); cr.SetSourceColor(background(editor).BorderColor); cr.Stroke(); } else { cr.Fill(); } } }
public bool DrawBackground(TextEditor editor, Cairo.Context cr, TextViewMargin.LayoutWrapper layout, int selectionStart, int selectionEnd, int startOffset, int endOffset, double y, double startXPos, double endXPos, ref bool drawBg) { drawBg = false; if (selectionStart >= 0 || editor.CurrentMode is TextLinkEditMode) { return(true); } foreach (ISegment usage in Usages) { int markerStart = usage.Offset; int markerEnd = usage.EndOffset; if (markerEnd < startOffset || markerStart > endOffset) { return(true); } 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; uint curIndex = 0, byteIndex = 0; TextViewMargin.TranslateToUTF8Index(layout.LineChars, (uint)(start - startOffset), ref curIndex, ref byteIndex); int x_pos = layout.Layout.IndexToPos((int)byteIndex).X; @from = startXPos + (int)(x_pos / Pango.Scale.PangoScale); TextViewMargin.TranslateToUTF8Index(layout.LineChars, (uint)(end - startOffset), ref curIndex, ref byteIndex); x_pos = layout.Layout.IndexToPos((int)byteIndex).X; to = startXPos + (int)(x_pos / Pango.Scale.PangoScale); } @from = System.Math.Max(@from, editor.TextViewMargin.XOffset); to = System.Math.Max(to, editor.TextViewMargin.XOffset); if (@from < to) { cr.Color = (HslColor)editor.ColorStyle.BracketHighlightRectangle.BackgroundColor; cr.Rectangle(@from + 1, y + 1, to - @from - 1, editor.LineHeight - 2); cr.Fill(); cr.Color = (HslColor)editor.ColorStyle.BracketHighlightRectangle.Color; cr.Rectangle(@from, y, to - @from, editor.LineHeight - 1); cr.Fill(); } } return(true); }
public bool DrawBackground(TextEditor editor, Gdk.Drawable win, TextViewMargin.LayoutWrapper layout, int selectionStart, int selectionEnd, int startOffset, int endOffset, int y, int startXPos, int endXPos, ref bool drawBg) { drawBg = false; if (selectionStart >= 0 || editor.CurrentMode is TextLinkEditMode) { return(true); } foreach (ISegment usage in Usages) { int markerStart = usage.Offset; int markerEnd = usage.EndOffset; if (markerEnd < startOffset || markerStart > endOffset) { return(true); } int @from; int to; 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(layout.LineChars, (uint)(start - startOffset), ref curIndex, ref byteIndex); int x_pos = layout.Layout.IndexToPos((int)byteIndex).X; @from = startXPos + (int)(x_pos / Pango.Scale.PangoScale); TextViewMargin.TranslateToUTF8Index(layout.LineChars, (uint)(end - startOffset), ref curIndex, ref byteIndex); x_pos = layout.Layout.IndexToPos((int)byteIndex).X; to = startXPos + (int)(x_pos / Pango.Scale.PangoScale); } @from = System.Math.Max(@from, editor.TextViewMargin.XOffset); to = System.Math.Max(to, editor.TextViewMargin.XOffset); if (@from < to) { using (Gdk.GC gc = new Gdk.GC(win)) { gc.RgbFgColor = editor.ColorStyle.BracketHighlightRectangle.BackgroundColor; win.DrawRectangle(gc, true, @from + 1, y + 1, to - @from - 1, editor.LineHeight - 2); gc.RgbFgColor = editor.ColorStyle.BracketHighlightRectangle.Color; win.DrawRectangle(gc, false, @from, y, to - @from, editor.LineHeight - 1); } } } return(true); }
public override void DrawBackground(MonoTextEditor editor, Cairo.Context cr, LineMetrics metrics, int startOffset, int endOffset) { int markerStart = Offset; int markerEnd = EndOffset; 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.Text, (uint)(start - startOffset), ref curIndex, ref byteIndex); int x_pos = metrics.Layout.IndexToPos((int)byteIndex).X; @from = startXPos + (int)(x_pos / Pango.Scale.PangoScale); TextViewMargin.TranslateToUTF8Index(metrics.Layout.Text, (uint)(end - startOffset), ref curIndex, ref byteIndex); x_pos = metrics.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) { if (metrics.TextEndOffset < markerEnd) { to = metrics.WholeLineWidth + metrics.TextRenderStartPosition; } var c1 = (Cairo.Color)SyntaxHighlightingService.GetColor(editor.EditorTheme, EditorThemeColors.Background); var c2 = (Cairo.Color)SyntaxHighlightingService.GetColor(editor.EditorTheme, EditorThemeColors.Selection); cr.SetSourceRGB((c1.R + c2.R) / 2, (c1.G + c2.G) / 2, (c1.B + c2.B) / 2); cr.Rectangle(@from, y, to - @from, metrics.LineHeight); cr.Fill(); } }
public override bool DrawBackground(TextEditor editor, Context cr, double y, LineMetrics metrics) { if (metrics.SelectionStart >= 0 || editor.CurrentMode is TextLinkEditMode || editor.TextViewMargin.SearchResultMatchCount > 0) { return(false); } foreach (var usage in Usages) { int markerStart = usage.TextSegment.Offset; int markerEnd = usage.TextSegment.EndOffset; if (markerEnd < metrics.TextStartOffset || markerStart > metrics.TextEndOffset) { return(false); } double @from; double to; if (markerStart < metrics.TextStartOffset && metrics.TextEndOffset < markerEnd) { @from = metrics.TextRenderStartPosition; to = metrics.TextRenderEndPosition; } else { int start = metrics.TextStartOffset < markerStart ? markerStart : metrics.TextStartOffset; int end = metrics.TextEndOffset < markerEnd ? metrics.TextEndOffset : markerEnd; uint curIndex = 0, byteIndex = 0; TextViewMargin.TranslateToUTF8Index(metrics.Layout.LineChars, (uint)(start - metrics.TextStartOffset), ref curIndex, ref byteIndex); int x_pos = metrics.Layout.Layout.IndexToPos((int)byteIndex).X; @from = metrics.TextRenderStartPosition + (int)(x_pos / Pango.Scale.PangoScale); TextViewMargin.TranslateToUTF8Index(metrics.Layout.LineChars, (uint)(end - metrics.TextStartOffset), ref curIndex, ref byteIndex); x_pos = metrics.Layout.Layout.IndexToPos((int)byteIndex).X; to = metrics.TextRenderStartPosition + (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) { 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 + 0.5, to - @from + 1, editor.LineHeight - 1, 2); cr.FillPreserve(); } cr.SetSourceColor(colorStyle.BorderColor); cr.Stroke(); } } return(true); }
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.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.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) { HslColor colorStyle; if ((usage.UsageType & ReferenceUsageType.Write) == ReferenceUsageType.Write || (usage.UsageType & ReferenceUsageType.Declariton) == ReferenceUsageType.Declariton) { colorStyle = SyntaxHighlightingService.GetColor(editor.EditorTheme, EditorThemeColors.ChangingUsagesRectangle); if (colorStyle.Alpha == 0.0) { colorStyle = SyntaxHighlightingService.GetColor(editor.EditorTheme, EditorThemeColors.UsagesRectangle); } } else { colorStyle = SyntaxHighlightingService.GetColor(editor.EditorTheme, EditorThemeColors.UsagesRectangle); } using (var lg = new LinearGradient(@from + 1, y + 1.5, to, y + editor.LineHeight - 1)) { lg.AddColorStop(0, colorStyle); lg.AddColorStop(1, colorStyle); cr.SetSource(lg); cr.RoundedRectangle(@from - 0.5, y + 0.5, to - @from + 1, editor.LineHeight - 1, 2); cr.FillPreserve(); } // TODO: EditorTheme : do we need the border ?! cr.SetSourceColor(colorStyle); cr.Stroke(); } }
public uint TranslateToUTF8Index(uint textIndex, ref uint curIndex, ref uint byteIndex) { return(TextViewMargin.TranslateToUTF8Index(LineChars, textIndex, ref curIndex, ref byteIndex)); }