internal protected override void Draw(Context ctx, Rectangle area, long line, double x, double y) { ctx.Rectangle(x, y, Width, Editor.LineHeight); ctx.SetColor(Style.HexDigitBg); ctx.Fill(); LayoutWrapper layout = GetLayout(line); if (!Data.IsSomethingSelected && !Caret.InTextEditor && line == Data.Caret.Line) { var column = (int)(Caret.Offset % BytesInRow); if (Editor.Options.StringRepresentationType == StringRepresentationTypes.UTF16) { column /= 2; } var xOffset = charWidth * column; ctx.Rectangle(x + xOffset, y, charWidth, Editor.LineHeight); ctx.SetColor(Style.HighlightOffset); ctx.Fill(); } ctx.SetColor(Style.HexDigit); ctx.DrawTextLayout(layout.Layout, x, y); if (layout.IsUncached) { layout.Dispose(); } }
internal protected override void Draw(Gdk.Drawable drawable, Gdk.Rectangle area, long line, int x, int y) { drawable.DrawRectangle(GetGC(Style.HexOffsetBg), true, x, y, Width, Editor.LineHeight); LayoutWrapper layout = GetLayout(line); int w, h; layout.Layout.GetPixelSize(out w, out h); drawable.DrawLayout(GetGC(line != Caret.Line ? Style.HexOffset : Style.HexOffsetHighlighted), x + Width - w - 4, y, layout.Layout); if (layout.IsUncached) { layout.Dispose(); } }
internal protected override void Draw(Gdk.Drawable drawable, Gdk.Rectangle area, long line, int x, int y) { drawable.DrawRectangle(bgGC, true, x, y, Width, Editor.LineHeight); LayoutWrapper layout = GetLayout(line); if (!Data.IsSomethingSelected && Caret.InTextEditor && line == Data.Caret.Line) { drawable.DrawRectangle(GetGC(Style.HighlightOffset), true, CalculateCaretXPos(false), y, byteWidth, Editor.LineHeight); } drawable.DrawLayout(fgGC, x, y, layout.Layout); if (layout.IsUncached) { layout.Dispose(); } }
internal protected override void Draw(Gdk.Drawable drawable, Gdk.Rectangle area, long line, int x, int y) { drawable.DrawRectangle(bgGC, true, x, y, Width, Editor.LineHeight); LayoutWrapper layout = GetLayout(line); if (!Data.IsSomethingSelected && !Caret.InTextEditor && line == Data.Caret.Line) { int column = (int)(Caret.Offset % BytesInRow); int xOffset = charWidth * column; drawable.DrawRectangle(GetGC(Style.HighlightOffset), true, x + xOffset, y, charWidth, Editor.LineHeight); } drawable.DrawLayout(fgGC, x, y, layout.Layout); if (layout.IsUncached) { layout.Dispose(); } }
internal protected override void Draw(Context ctx, Rectangle area, long line, double x, double y) { ctx.Rectangle(x, y, Width, Editor.LineHeight); ctx.SetColor(Style.HexOffsetBg); ctx.Fill(); if (line >= 0 && line * Editor.BytesInRow < Data.Length) { LayoutWrapper layout = GetLayout(line); var sz = layout.Layout.GetSize(); ctx.SetColor(line != Caret.Line ? Style.HexOffset : Style.HexOffsetHighlighted); ctx.DrawTextLayout(layout.Layout, x + Width - sz.Width - 4, y); if (layout.IsUncached) { layout.Dispose(); } } }
int CalculateCaretXPos(bool useSubPositon) { int byteInRow = (int)Caret.Offset % BytesInRow; int groupNumber = byteInRow / Editor.Options.GroupBytes; int groupByte = byteInRow % Editor.Options.GroupBytes; int caretIndex = groupNumber * (Editor.Options.GroupBytes * 2 + 1) + groupByte * 2; if (useSubPositon) { caretIndex += Caret.SubPosition; } LayoutWrapper layout = GetLayout((int)Caret.Line); Pango.Rectangle rectangle = layout.Layout.IndexToPos(caretIndex); if (layout.IsUncached) { layout.Dispose(); } return(XOffset + (int)(rectangle.X / Pango.Scale.PangoScale)); }
double CalculateCaretXPos(bool useSubPositon, out char ch) { int byteInRow = (int)Caret.Offset % BytesInRow; int groupNumber = byteInRow / Editor.Options.GroupBytes; int groupByte = byteInRow % Editor.Options.GroupBytes; int caretIndex = groupNumber * (Editor.Options.GroupBytes * 2 + 1) + groupByte * 2; if (useSubPositon) { caretIndex += Caret.SubPosition; } LayoutWrapper layout = GetLayout((int)Caret.Line); var rectangle = layout.Layout.GetCoordinateFromIndex(caretIndex); var text = layout.Layout.Text; ch = caretIndex < text.Length ? text [caretIndex] : ' '; if (layout.IsUncached) { layout.Dispose(); } return(XOffset + rectangle.X); }
internal protected override void Draw(Context ctx, Rectangle area, long line, double x, double y) { ctx.Rectangle(x, y, Width, Editor.LineHeight); ctx.SetColor(Style.HexDigitBg); ctx.Fill(); LayoutWrapper layout = GetLayout(line); char ch; if (!Data.IsSomethingSelected && Caret.InTextEditor && line == Data.Caret.Line) { ctx.Rectangle(CalculateCaretXPos(false, out ch), y, byteWidth, Editor.LineHeight); ctx.SetColor(Style.HighlightOffset); ctx.Fill(); } ctx.SetColor(Style.HexDigit); ctx.DrawTextLayout(layout.Layout, x, y); if (layout.IsUncached) { layout.Dispose(); } }
void DrawLinePart (Cairo.Context cr, DocumentLine line, int lineNumber, int logicalRulerColumn, int offset, int length, ref double pangoPosition, ref bool isSelectionDrawn, double y, double maxX, double _lineHeight) { ISyntaxMode mode = Document.SyntaxMode != null && textEditor.Options.EnableSyntaxHighlighting ? Document.SyntaxMode : new SyntaxMode (Document); int selectionStart; int selectionEnd; if (this.HideSelection) { selectionStart = selectionEnd = -1; } else { GetSelectionOffsets (line, out selectionStart, out selectionEnd); } // ---- new renderer LayoutWrapper layout = CreateLinePartLayout (mode, line, logicalRulerColumn, offset, length, selectionStart, selectionEnd); int lineOffset = line.Offset; double width = layout.PangoWidth / Pango.Scale.PangoScale; double xPos = pangoPosition / Pango.Scale.PangoScale; // The caret line marker must be drawn below the text markers otherwise the're invisible if ((HighlightCaretLine || textEditor.Options.HighlightCaretLine) && Caret.Line == lineNumber) DrawCaretLineMarker (cr, xPos, y, layout.PangoWidth / Pango.Scale.PangoScale, _lineHeight); // if (!(HighlightCaretLine || textEditor.Options.HighlightCaretLine) || Document.GetLine(Caret.Line) != line) { if (BackgroundRenderer == null) { foreach (var bg in layout.BackgroundColors) { int x1, x2; x1 = layout.Layout.IndexToPos (bg.FromIdx).X; x2 = layout.Layout.IndexToPos (bg.ToIdx).X; DrawRectangleWithRuler ( cr, xPos + textEditor.HAdjustment.Value - TextStartPosition, new Cairo.Rectangle ((x1 + pangoPosition) / Pango.Scale.PangoScale, y, (x2 - x1) / Pango.Scale.PangoScale + 1, _lineHeight), bg.Color, true); } } bool drawBg = true; bool drawText = true; LineMetrics metrics = new LineMetrics { LineSegment = line, Layout = layout, SelectionStart = selectionStart, SelectionEnd = selectionEnd, TextStartOffset = offset, TextEndOffset = offset + length, TextRenderStartPosition = xPos, TextRenderEndPosition = xPos + width, LineHeight = _lineHeight, WholeLineWidth = textEditor.Allocation.Width - xPos }; foreach (TextLineMarker marker in line.Markers) { if (!marker.IsVisible) continue; if (marker.DrawBackground (textEditor, cr, y, metrics)) { isSelectionDrawn |= (marker.Flags & TextLineMarkerFlags.DrawsSelection) == TextLineMarkerFlags.DrawsSelection; } var bgMarker = marker as IBackgroundMarker; if (bgMarker != null) { isSelectionDrawn |= (marker.Flags & TextLineMarkerFlags.DrawsSelection) == TextLineMarkerFlags.DrawsSelection; drawText &= bgMarker.DrawBackground (textEditor, cr, metrics.Layout, metrics.SelectionStart, metrics.SelectionEnd, metrics.TextStartOffset, metrics.TextEndOffset, y, metrics.TextRenderStartPosition, metrics.TextRenderEndPosition, ref drawBg); continue; } } if (DecorateLineBg != null) DecorateLineBg (cr, layout, offset, length, xPos, y, selectionStart, selectionEnd); if (!isSelectionDrawn && (layout.StartSet || selectionStart == offset + length) && BackgroundRenderer == null) { double startX; double endX; if (selectionStart != offset + length) { var start = layout.Layout.IndexToPos ((int)layout.SelectionStartIndex); startX = System.Math.Floor (start.X / Pango.Scale.PangoScale); var end = layout.Layout.IndexToPos ((int)layout.SelectionEndIndex); endX = System.Math.Ceiling (end.X / Pango.Scale.PangoScale); } else { startX = width; endX = startX; } if (textEditor.MainSelection.SelectionMode == SelectionMode.Block && startX == endX) { endX = startX + 2; } DrawRectangleWithRuler (cr, xPos + textEditor.HAdjustment.Value - TextStartPosition, new Cairo.Rectangle (xPos + startX, y, endX - startX, _lineHeight), this.SelectionColor.Background, true); } // highlight search results TextSegment firstSearch; int o = offset; uint curIndex = 0, byteIndex = 0; if (textEditor.HighlightSearchPattern) { while (!(firstSearch = GetFirstSearchResult (o, offset + length)).IsInvalid) { double x = pangoPosition; HandleSelection (lineOffset, logicalRulerColumn, selectionStart, selectionEnd, System.Math.Max (lineOffset, firstSearch.Offset), System.Math.Min (lineOffset + line.Length, firstSearch.EndOffset), delegate(int start, int end) { uint startIndex = (uint)(start - offset); uint endIndex = (uint)(end - offset); if (startIndex < endIndex && endIndex <= layout.LineChars.Length) { uint startTranslated = TranslateToUTF8Index (layout.LineChars, startIndex, ref curIndex, ref byteIndex); uint endTranslated = TranslateToUTF8Index (layout.LineChars, endIndex, ref curIndex, ref byteIndex); int l, x1, x2; layout.Layout.IndexToLineX ((int)startTranslated, false, out l, out x1); layout.Layout.IndexToLineX ((int)endTranslated, false, out l, out x2); int w = (int) System.Math.Ceiling ((x2 - x1) / Pango.Scale.PangoScale); int s = (int) System.Math.Floor ((x1 + x) / Pango.Scale.PangoScale); double corner = System.Math.Min (4, width) * textEditor.Options.Zoom; cr.Color = MainSearchResult.IsInvalid || MainSearchResult.Offset != firstSearch.Offset ? ColorStyle.SearchResult.Color : ColorStyle.SearchResultMain.Color; FoldingScreenbackgroundRenderer.DrawRoundRectangle (cr, true, true, s, y, corner, w + 1, LineHeight); cr.Fill (); } }, null); o = System.Math.Max (firstSearch.EndOffset, o + 1); } } cr.Save (); cr.Translate (xPos, y); cr.ShowLayout (layout.Layout); cr.Restore (); if (offset == line.Offset) { DrawIndent (cr, layout, line, xPos, y); } if (textEditor.Options.ShowWhitespaces != ShowWhitespaces.Never && !(BackgroundRenderer != null && textEditor.Options.ShowWhitespaces == ShowWhitespaces.Selection)) DecorateTabsAndSpaces (cr, layout, offset, length, xPos, y, selectionStart, selectionEnd); if (lineNumber == Caret.Line) { int caretOffset = Caret.Offset; if (offset <= caretOffset && caretOffset <= offset + length) { int index = caretOffset - offset; if (Caret.Column > line.Length + 1) { string virtualSpace = ""; var data = textEditor.GetTextEditorData (); if (data.HasIndentationTracker && line.Length == 0) { virtualSpace = this.textEditor.GetTextEditorData ().GetIndentationString (Caret.Location); } if (Caret.Column > line.Length + 1 + virtualSpace.Length) virtualSpace += new string (' ', Caret.Column - line.Length - 1 - virtualSpace.Length); // predit layout already contains virtual space. if (!string.IsNullOrEmpty (textEditor.preeditString)) virtualSpace = ""; LayoutWrapper wrapper = new LayoutWrapper (PangoUtil.CreateLayout (textEditor)); wrapper.LineChars = virtualSpace.ToCharArray (); wrapper.Layout.SetText (virtualSpace); wrapper.Layout.Tabs = tabArray; wrapper.Layout.FontDescription = textEditor.Options.Font; int vy, vx; wrapper.Layout.GetSize (out vx, out vy); var x = ((pangoPosition + vx + layout.PangoWidth) / Pango.Scale.PangoScale); SetVisibleCaretPosition (x, y, x, y); xPos = (pangoPosition + layout.PangoWidth) / Pango.Scale.PangoScale; if (!isSelectionDrawn && (selectionEnd == lineOffset + line.Length) && BackgroundRenderer == null) { double startX; double endX; startX = xPos; endX = (pangoPosition + vx + layout.PangoWidth) / Pango.Scale.PangoScale; DrawRectangleWithRuler (cr, xPos + textEditor.HAdjustment.Value - TextStartPosition, new Cairo.Rectangle (startX, y, endX - startX, _lineHeight), this.SelectionColor.Background, true); } // When drawing virtual space before the selection start paint it as unselected. var virtualSpaceMod = selectionStart < caretOffset ? 0 : virtualSpace.Length; if ((!textEditor.IsSomethingSelected || (selectionStart >= offset && selectionStart != selectionEnd)) && (HighlightCaretLine || textEditor.Options.HighlightCaretLine) && Caret.Line == lineNumber) DrawCaretLineMarker (cr, pangoPosition / Pango.Scale.PangoScale, y, vx / Pango.Scale.PangoScale, _lineHeight); if (DecorateLineBg != null) DecorateLineBg (cr, wrapper, offset, length, xPos, y, selectionStart + virtualSpaceMod, selectionEnd + virtualSpace.Length); switch (textEditor.Options.ShowWhitespaces) { case ShowWhitespaces.Selection: if (textEditor.IsSomethingSelected && (selectionStart < offset || selectionStart == selectionEnd) && BackgroundRenderer == null) DecorateTabsAndSpaces (cr, wrapper, offset, length, xPos, y, selectionStart, selectionEnd + virtualSpace.Length); break; case ShowWhitespaces.Always: DecorateTabsAndSpaces (cr, wrapper, offset, length, xPos, y, selectionStart, selectionEnd + virtualSpace.Length); break; } wrapper.Dispose (); pangoPosition += vx; } else if (index == length && string.IsNullOrEmpty (textEditor.preeditString)) { var x = (pangoPosition + layout.PangoWidth) / Pango.Scale.PangoScale; SetVisibleCaretPosition (x, y, x, y); } else if (index >= 0 && index <= length) { Pango.Rectangle strong_pos, weak_pos; curIndex = byteIndex = 0; int utf8ByteIndex = (int)TranslateToUTF8Index (layout.LineChars, (uint)index, ref curIndex, ref byteIndex); layout.Layout.GetCursorPos (utf8ByteIndex, out strong_pos, out weak_pos); var cx = xPos + (strong_pos.X / Pango.Scale.PangoScale); var cy = y + (strong_pos.Y / Pango.Scale.PangoScale); if (textEditor.preeditCursorCharIndex == 0) { SetVisibleCaretPosition (cx, cy, cx, cy); } else { var preeditIndex = (uint)(index + textEditor.preeditCursorCharIndex); utf8ByteIndex = (int)TranslateToUTF8Index (layout.LineChars, preeditIndex, ref curIndex, ref byteIndex); layout.Layout.GetCursorPos (utf8ByteIndex, out strong_pos, out weak_pos); var pcx = xPos + (strong_pos.X / Pango.Scale.PangoScale); var pcy = y + (strong_pos.Y / Pango.Scale.PangoScale); SetVisibleCaretPosition (pcx, pcy, cx, cy); } } } } foreach (TextLineMarker marker in line.Markers.Where (m => m.IsVisible)) { if (layout.Layout != null) marker.Draw (textEditor, cr, y, metrics); } foreach (var marker in Document.GetTextSegmentMarkersAt (line).Where (m => m.IsVisible)) { if (layout.Layout != null) marker.Draw (textEditor, cr, layout.Layout, false, /*selected*/offset, offset + length, y, xPos, xPos + width); } pangoPosition += layout.PangoWidth; int scaledDown = (int)(pangoPosition / Pango.Scale.PangoScale); pangoPosition = scaledDown * Pango.Scale.PangoScale; if (layout.IsUncached) layout.Dispose (); }
void DrawLinePart (Cairo.Context cr, LineSegment line, int lineNumber, int logicalRulerColumn, int offset, int length, ref double pangoPosition, ref bool isSelectionDrawn, double y, double maxX) { ISyntaxMode mode = Document.SyntaxMode != null && textEditor.Options.EnableSyntaxHighlighting ? Document.SyntaxMode : new SyntaxMode (Document); int selectionStart; int selectionEnd; if (this.HideSelection) { selectionStart = selectionEnd = -1; } else { GetSelectionOffsets (line, out selectionStart, out selectionEnd); } // ---- new renderer LayoutWrapper layout = CreateLinePartLayout (mode, line, logicalRulerColumn, offset, length, selectionStart, selectionEnd); int lineOffset = line.Offset; double width = layout.PangoWidth / Pango.Scale.PangoScale; double xPos = pangoPosition / Pango.Scale.PangoScale; // if (!(HighlightCaretLine || textEditor.Options.HighlightCaretLine) || Document.GetLine(Caret.Line) != line) { foreach (var bg in layout.BackgroundColors) { int x1, x2; x1 = layout.Layout.IndexToPos (bg.FromIdx).X; x2 = layout.Layout.IndexToPos (bg.ToIdx).X; DrawRectangleWithRuler (cr, xPos + textEditor.HAdjustment.Value - TextStartPosition, new Cairo.Rectangle ((x1 + pangoPosition) / Pango.Scale.PangoScale, y, (x2 - x1) / Pango.Scale.PangoScale + 1, LineHeight), bg.Color, true); } // } bool drawBg = true; bool drawText = true; foreach (TextMarker marker in line.Markers) { IBackgroundMarker bgMarker = marker as IBackgroundMarker; if (bgMarker == null || !marker.IsVisible) continue; isSelectionDrawn |= (marker.Flags & TextMarkerFlags.DrawsSelection) == TextMarkerFlags.DrawsSelection; drawText &= bgMarker.DrawBackground (textEditor, cr, layout, selectionStart, selectionEnd, offset, offset + length, y, xPos, xPos + width, ref drawBg); } if (DecorateLineBg != null) DecorateLineBg (cr, layout, offset, length, xPos, y, selectionStart, selectionEnd); if ((HighlightCaretLine || textEditor.Options.HighlightCaretLine) && Caret.Line == lineNumber) DrawCaretLineMarker (cr, xPos, y, layout.PangoWidth / Pango.Scale.PangoScale); if (!isSelectionDrawn && (layout.StartSet || selectionStart == offset + length)) { double startX; double endX; if (selectionStart != offset + length) { var start = layout.Layout.IndexToPos ((int)layout.SelectionStartIndex); startX = start.X / Pango.Scale.PangoScale; var end = layout.Layout.IndexToPos ((int)layout.SelectionEndIndex); endX = end.X / Pango.Scale.PangoScale; } else { startX = width; endX = startX; } if (textEditor.MainSelection.SelectionMode == SelectionMode.Block && startX == endX) { endX = startX + 2; } DrawRectangleWithRuler (cr, xPos + textEditor.HAdjustment.Value - TextStartPosition, new Cairo.Rectangle (xPos + startX, y, endX - startX, LineHeight), this.SelectionColor.CairoBackgroundColor, true); } // highlight search results TextSegment firstSearch; int o = offset; uint curIndex = 0, byteIndex = 0; if (textEditor.HighlightSearchPattern) { while (!(firstSearch = GetFirstSearchResult (o, offset + length)).IsInvalid) { double x = pangoPosition; HandleSelection (lineOffset, logicalRulerColumn, selectionStart, selectionEnd, System.Math.Max (lineOffset, firstSearch.Offset), System.Math.Min (lineOffset + line.Length, firstSearch.EndOffset), delegate(int start, int end) { uint startIndex = (uint)(start - offset); uint endIndex = (uint)(end - offset); if (startIndex < endIndex && endIndex <= layout.LineChars.Length) { uint startTranslated = TranslateToUTF8Index (layout.LineChars, startIndex, ref curIndex, ref byteIndex); uint endTranslated = TranslateToUTF8Index (layout.LineChars, endIndex, ref curIndex, ref byteIndex); int l, x1, x2; layout.Layout.IndexToLineX ((int)startTranslated, false, out l, out x1); layout.Layout.IndexToLineX ((int)endTranslated, false, out l, out x2); x1 += (int)x; x2 += (int)x; x1 /= (int)Pango.Scale.PangoScale; x2 /= (int)Pango.Scale.PangoScale; cr.Color = MainSearchResult.IsInvalid || MainSearchResult.Offset != firstSearch.Offset ? ColorStyle.SearchTextBg : ColorStyle.SearchTextMainBg; FoldingScreenbackgroundRenderer.DrawRoundRectangle (cr, true, true, x1, y, System.Math.Min (10, width) * textEditor.Options.Zoom, x2 - x1, LineHeight); cr.Fill (); } }, null); o = System.Math.Max (firstSearch.EndOffset, o + 1); } } cr.Save (); cr.Translate (xPos, y); cr.ShowLayout (layout.Layout); cr.Restore (); if (DecorateLineFg != null) DecorateLineFg (cr, layout, offset, length, xPos, y, selectionStart, selectionEnd); if (lineNumber == Caret.Line) { int caretOffset = Caret.Offset; if (offset <= caretOffset && caretOffset <= offset + length) { int index = caretOffset - offset; if (Caret.Column > line.Length + 1) { string virtualSpace = ""; var data = textEditor.GetTextEditorData (); if (data.HasIndentationTracker && line.Length == 0) { virtualSpace = this.textEditor.GetTextEditorData ().GetIndentationString (Caret.Location); } if (Caret.Column > line.Length + 1 + virtualSpace.Length) virtualSpace += new string (' ', Caret.Column - line.Length - 1 - virtualSpace.Length); LayoutWrapper wrapper = new LayoutWrapper (PangoUtil.CreateLayout (textEditor)); wrapper.LineChars = virtualSpace.ToCharArray (); wrapper.Layout.SetText (virtualSpace); wrapper.Layout.Tabs = tabArray; wrapper.Layout.FontDescription = textEditor.Options.Font; int vy, vx; wrapper.Layout.GetSize (out vx, out vy); SetVisibleCaretPosition (((pangoPosition + vx + layout.PangoWidth) / Pango.Scale.PangoScale), y); xPos = (pangoPosition + layout.PangoWidth) / Pango.Scale.PangoScale; if (!isSelectionDrawn && (selectionEnd == lineOffset + line.Length)) { double startX; double endX; startX = xPos; endX = (pangoPosition + vx + layout.PangoWidth) / Pango.Scale.PangoScale; DrawRectangleWithRuler (cr, xPos + textEditor.HAdjustment.Value - TextStartPosition, new Cairo.Rectangle (startX, y, endX - startX, LineHeight), this.SelectionColor.CairoBackgroundColor, true); } if ((HighlightCaretLine || textEditor.Options.HighlightCaretLine) && Caret.Line == lineNumber) DrawCaretLineMarker (cr, pangoPosition / Pango.Scale.PangoScale, y, vx / Pango.Scale.PangoScale); // When drawing virtual space before the selection start paint it as unselected. var virtualSpaceMod = selectionStart < caretOffset ? 0 : virtualSpace.Length; if (DecorateLineBg != null) DecorateLineBg (cr, wrapper, offset, length, xPos, y, selectionStart + virtualSpaceMod, selectionEnd + virtualSpace.Length); if (DecorateLineFg != null) DecorateLineFg (cr, wrapper, offset, length, xPos, y, selectionStart + virtualSpaceMod, selectionEnd + virtualSpace.Length); wrapper.Dispose (); pangoPosition += vx; } else if (index == length && textEditor.preeditString == null) { SetVisibleCaretPosition ((pangoPosition + layout.PangoWidth) / Pango.Scale.PangoScale, y); } else if (index >= 0 && index <= length) { Pango.Rectangle strong_pos, weak_pos; curIndex = byteIndex = 0; int utf8ByteIndex = (int)TranslateToUTF8Index (layout.LineChars, (uint)index, ref curIndex, ref byteIndex); if (textEditor.preeditString != null && textEditor.preeditCursorCharIndex > 0) { curIndex = byteIndex = 0; int preeditUtf8ByteIndex = (int)TranslateToUTF8Index (textEditor.preeditString.ToCharArray (), (uint)textEditor.preeditCursorCharIndex, ref curIndex, ref byteIndex); utf8ByteIndex += preeditUtf8ByteIndex; } layout.Layout.GetCursorPos (utf8ByteIndex, out strong_pos, out weak_pos); SetVisibleCaretPosition (xPos + (strong_pos.X / Pango.Scale.PangoScale), y); } } } foreach (TextMarker marker in line.Markers.Where (m => m.IsVisible)) { if (layout.Layout != null) marker.Draw (textEditor, cr, layout.Layout, false, /*selected*/offset, offset + length, y, xPos, xPos + width); } pangoPosition += layout.PangoWidth; if (layout.IsUncached) layout.Dispose (); }
void DrawLinePart (Gdk.Drawable win, LineSegment line, int offset, int length, ref int pangoPosition, ref bool isSelectionDrawn, int y, int maxX) { SyntaxMode mode = Document.SyntaxMode != null && textEditor.Options.EnableSyntaxHighlighting ? Document.SyntaxMode : SyntaxMode.Default; int selectionStart; int selectionEnd; if (BackgroundRenderer != null || this.HideSelection) { selectionStart = selectionEnd = -1; } else { GetSelectionOffsets (line, out selectionStart, out selectionEnd); } // ---- new renderer LayoutWrapper layout = CreateLinePartLayout (mode, line, offset, length, selectionStart, selectionEnd); int width = (int)(layout.PangoWidth / Pango.Scale.PangoScale); int xPos = (int)(pangoPosition / Pango.Scale.PangoScale); bool drawBg = true; bool drawText = true; foreach (TextMarker marker in line.Markers) { IBackgroundMarker bgMarker = marker as IBackgroundMarker; if (bgMarker == null || !marker.IsVisible) continue; isSelectionDrawn |= (marker.Flags & TextMarkerFlags.DrawsSelection) == TextMarkerFlags.DrawsSelection; drawText &= bgMarker.DrawBackground (textEditor, win, layout, selectionStart, selectionEnd, offset, offset + length, y, xPos, xPos + width, ref drawBg); } if (DecorateLineBg != null) DecorateLineBg (win, layout, offset, length, xPos, y, selectionStart, selectionEnd); if (!isSelectionDrawn && (layout.StartSet || selectionStart == offset + length)) { int startX; int endX; if (selectionStart != offset + length) { var start = layout.Layout.IndexToPos ((int)layout.SelectionStartIndex); startX = (int)(start.X / Pango.Scale.PangoScale); var end = layout.Layout.IndexToPos ((int)layout.SelectionEndIndex); endX = (int)(end.X / Pango.Scale.PangoScale); } else { startX = width; endX = startX; } if (textEditor.MainSelection.SelectionMode == SelectionMode.Block && startX == endX) { endX = startX + 2; } DrawRectangleWithRuler (win, xPos + (int)textEditor.HAdjustment.Value - TextStartPosition, new Rectangle (xPos + startX, y, endX - startX, textEditor.LineHeight), this.SelectionColor.BackgroundColor, true); } // highlight search results ISegment firstSearch; int o = offset; uint curIndex = 0, byteIndex = 0; while ((firstSearch = GetFirstSearchResult (o, offset + length)) != null) { int x = pangoPosition; HandleSelection (line, selectionStart, selectionEnd, firstSearch.Offset, firstSearch.EndOffset, delegate(int start, int end) { uint startIndex = (uint)(start - offset); uint endIndex = (uint)(end - offset); if (startIndex < endIndex && endIndex <= layout.LineChars.Length) { uint startTranslated = TranslateToUTF8Index (layout.LineChars, startIndex, ref curIndex, ref byteIndex); uint endTranslated = TranslateToUTF8Index (layout.LineChars, endIndex, ref curIndex, ref byteIndex); using (Cairo.Context cr = Gdk.CairoHelper.Create (win)) { cr.Rectangle (XOffset, 0, textEditor.Allocation.Width - XOffset, textEditor.Allocation.Height); cr.Clip (); int l, x1, x2; layout.Layout.IndexToLineX ((int)startTranslated, false, out l, out x1); layout.Layout.IndexToLineX ((int)endTranslated, false, out l, out x2); x1 += x; x2 += x; x1 /= (int)Pango.Scale.PangoScale; x2 /= (int)Pango.Scale.PangoScale; cr.Color = Mono.TextEditor.Highlighting.Style.ToCairoColor (MainSearchResult == null || MainSearchResult.Offset != firstSearch.Offset ? ColorStyle.SearchTextBg : ColorStyle.SearchTextMainBg, AlphaBlendSearchResults ? 0.6 : 1.0); FoldingScreenbackgroundRenderer.DrawRoundRectangle (cr, true, true, x1, y, (int)(System.Math.Min (10, width) * textEditor.Options.Zoom), x2 - x1, textEditor.LineHeight); cr.Fill (); } } }, null); o = System.Math.Max (firstSearch.EndOffset, o + 1); } win.DrawLayout (GetGC (ColorStyle.Default.Color), xPos, y, layout.Layout); if (DecorateLineFg != null) DecorateLineFg (win, layout, offset, length, xPos, y, selectionStart, selectionEnd); if (Document.GetLine (Caret.Line) == line) { int caretOffset = Caret.Offset; if (offset <= caretOffset && caretOffset <= offset + length) { Pango.Rectangle strong_pos, weak_pos; int index = caretOffset- offset; if (offset <= textEditor.preeditOffset && textEditor.preeditOffset < offset + length) { index += textEditor.preeditString.Length; } if (Caret.Column > line.EditableLength) { string virtualSpace = this.textEditor.GetTextEditorData ().GetVirtualSpaces (Caret.Line, Caret.Column); LayoutWrapper wrapper = new LayoutWrapper (PangoUtil.CreateLayout (textEditor)); wrapper.LineChars = virtualSpace.ToCharArray (); wrapper.Layout.SetText (virtualSpace); wrapper.Layout.Tabs = tabArray; int vy, vx; wrapper.Layout.GetSize (out vx, out vy); SetVisibleCaretPosition (win, ' ', (int)((pangoPosition + vx + layout.PangoWidth) / Pango.Scale.PangoScale), y); xPos = (int)((pangoPosition + layout.PangoWidth) / Pango.Scale.PangoScale); if (!isSelectionDrawn && (selectionEnd == line.Offset + line.EditableLength)) { int startX; int endX; startX = xPos; endX = (int)((pangoPosition + vx + layout.PangoWidth) / Pango.Scale.PangoScale); DrawRectangleWithRuler (win, xPos + (int)textEditor.HAdjustment.Value - TextStartPosition, new Rectangle (startX, y, endX - startX, textEditor.LineHeight), this.SelectionColor.BackgroundColor, true); } if (DecorateLineBg != null) DecorateLineBg (win, wrapper, offset, length, xPos, y, selectionStart, selectionEnd + virtualSpace.Length); if (DecorateLineFg != null) DecorateLineFg (win, wrapper, offset, length, xPos, y, selectionStart, selectionEnd + virtualSpace.Length); wrapper.Dispose (); pangoPosition += vx; } else if (index >= 0 && index < length) { curIndex = byteIndex = 0; layout.Layout.GetCursorPos ((int)TranslateToUTF8Index (layout.LineChars, (uint)index, ref curIndex, ref byteIndex), out strong_pos, out weak_pos); char caretChar = Document.GetCharAt (caretOffset); if (textEditor.Options.ShowSpaces && caretChar == ' ') caretChar = spaceMarkerChar; if (textEditor.Options.ShowTabs && caretChar == '\t') caretChar = tabMarkerChar; SetVisibleCaretPosition (win, caretChar, xPos + (int)(strong_pos.X / Pango.Scale.PangoScale), y); } else if (index == length) { SetVisibleCaretPosition (win, textEditor.Options.ShowEolMarkers ? eolMarkerChar : ' ', (int)((pangoPosition + layout.PangoWidth) / Pango.Scale.PangoScale), y); } } } foreach (TextMarker marker in line.Markers) { marker.Draw (textEditor, win, layout.Layout, false, /*selected*/offset, offset + length, y, xPos, xPos + width); } pangoPosition += layout.PangoWidth; if (layout.IsUncached) layout.Dispose (); }
void DrawIndent (Cairo.Context cr, LayoutWrapper layout, DocumentLine line, double xPos, double y) { if (!textEditor.Options.DrawIndentationMarkers) return; bool dispose = false; if (line.Length == 0) { var nextLine = line.NextLine; while (nextLine != null && nextLine.Length == 0) nextLine = nextLine.NextLine; if (nextLine != null) { layout = GetLayout (nextLine); dispose = true; } } if (layout.IndentSize == 0) { if (dispose && layout.IsUncached) layout.Dispose (); return; } cr.Save (); var dotted = new [] { textEditor.Options.Zoom }; cr.SetDash (dotted, (int)y + textEditor.VAdjustment.Value); var top = y; var bottom = y + LineHeight; if (Caret.Line == line.LineNumber && textEditor.GetTextEditorData ().HighlightCaretLine) { top += textEditor.Options.Zoom; bottom -= textEditor.Options.Zoom; } for (int i = 0; i < layout.IndentSize; i += textEditor.Options.IndentationSize) { var x = System.Math.Floor (xPos + i * charWidth); cr.MoveTo (x + 0.5, top); cr.LineTo (x + 0.5, bottom); cr.SetSourceColor (ColorStyle.IndentationGuide.Color); cr.Stroke (); } cr.Restore (); if (dispose && layout.IsUncached) layout.Dispose (); }