protected override DrawingVisual RenderCore(RenderParameters renderParams) { caretRect.Height = Configurations.FontDisplayHeight; if (null == drawingVisual) { drawingVisual = new DrawingVisual(); PauseCaretTimer(false); // Get timer going! } // There's no script yet. if (null == this.currentScript) return drawingVisual; DrawingContext context = drawingVisual.RenderOpen(); CodeFragment[] crossHighlight = textEditorCanvas.TextEditorCore.GetCrossHighlightArray(); if (crossHighlight != null) { if (crossHighlight.Length != 0) { List<Rect> rectList = new List<Rect>(); foreach (CodeFragment codeFragment in crossHighlight) { CharPosition start = currentScript.CreateCharPosition(); start.SetCharacterPosition(codeFragment.ColStart, codeFragment.Line); CharPosition end = currentScript.CreateCharPosition(); end.SetCharacterPosition(codeFragment.ColEnd + 1, codeFragment.Line); List<Rect> tempList = CalculateRectangles(start, end, renderParams.firstVisibleLine); if (tempList != null) rectList.AddRange(tempList); } //SolidColorBrush crossHighlightBrush = new SolidColorBrush(Color.FromRgb(226, 230, 214)); RenderRectangles(context, rectList, UIColors.CrossHighlightColor); } } // We don't care about keyboard focus when in playback mode. if (false == TextEditorControl.Instance.IsInPlaybackMode) { // If the focus is not within the canvas, or on any extension popup, // then there's no need to show the caret (focus is probably other app). if (false == TextEditorControl.Instance.ShouldDisplayCaret()) caretVisibility = System.Windows.Visibility.Hidden; } // Cursor rendering pass... if (caretVisibility == System.Windows.Visibility.Visible) { System.Windows.Rect displayRect = caretRect; double firstVisibleColumn = textEditorCanvas.FirstVisibleColumn * Configurations.FormatFontWidth; displayRect.Offset(-firstVisibleColumn, -renderParams.firstVisibleLine * Configurations.FontDisplayHeight); context.DrawRectangle(Brushes.Black, null, displayRect); } context.Close(); return drawingVisual; }
protected abstract DrawingVisual RenderCore(RenderParameters renderParams);
protected override DrawingVisual RenderCore(RenderParameters renderParams) { if (drawingVisual == null) { drawingVisual = new DrawingVisual(); } if (null == currentScript) { return(drawingVisual); // No active script yet! } System.Windows.Point linePosition = new System.Windows.Point( Configurations.CanvasMarginLeft, 0); ITextEditorCore textCore = textEditorCanvas.TextEditorCore; ITextBuffer textBuffer = currentScript.GetTextBuffer(); numberOfLines = textBuffer.GetLineCount(); int lastVisibleLine = renderParams.firstVisibleLine + renderParams.maxVisibleLines; if (lastVisibleLine >= numberOfLines) { lastVisibleLine = numberOfLines - 1; } // Retrieve the DrawingContext from the DrawingVisual. DrawingContext context = drawingVisual.RenderOpen(); int maxColumns = textEditorCanvas.MaxVisibelColumns + 1; double hiddenWidth = textEditorCanvas.FirstVisibleColumn * Configurations.FormatFontWidth; CharPosition converter = this.currentScript.CreateCharPosition(); Typeface font = new Typeface(Configurations.FontFace); for (int lineIndex = renderParams.firstVisibleLine; lineIndex <= lastVisibleLine; lineIndex++) { // A constant starting point on left edge. linePosition.X = Configurations.CanvasMarginLeft; int startColumn = converter.VisualToCharOffset(lineIndex, textEditorCanvas.FirstVisibleColumn); string lineContent = textBuffer.GetLineContent(lineIndex); int lineLength = (lineContent != null ? lineContent.Length : 0); if (lineLength <= startColumn) { linePosition.Y += Configurations.FontDisplayHeight; continue; } if (startColumn > 0) { string hiddenText = lineContent.Substring(0, startColumn); hiddenText = hiddenText.Replace("\t", Configurations.TabSpaces); // Accounting for the part that is hidden beyond the left of canvas. double hiddenTextWidth = hiddenText.Length * Configurations.FormatFontWidth; linePosition.X = linePosition.X + hiddenTextWidth - hiddenWidth; } int endColumn = startColumn + maxColumns; endColumn = ((endColumn >= lineLength) ? lineLength - 1 : endColumn); for (int charIndex = startColumn; charIndex <= endColumn; charIndex++) { CodeFragment fragment = null; int fragmentWidth = textCore.GetFragment( charIndex, lineIndex, out fragment); // We may be showing partial fragment now. if (null != fragment) { fragmentWidth -= (charIndex - fragment.ColStart); } int offsetToNextChar = fragmentWidth - 1; if ((charIndex + fragmentWidth) > (lineLength - 1)) { fragmentWidth = (lineLength - 1) - charIndex; offsetToNextChar = fragmentWidth - 1; } // Initialize the text store. string textContent = string.Empty; textContent = lineContent.Substring(charIndex, ((fragmentWidth == 0) ? 1 : fragmentWidth)); // Replace all TAB characters with actual spaces. textContent = textContent.Replace("\t", Configurations.TabSpaces); CodeFragment.Type fragmentType = CodeFragment.Type.None; if (null != fragment) { fragmentType = fragment.CodeType; } Color textColor = CodeFragment.GetFragmentColor(fragmentType); if ((textBuffer.ParsePending == true) && (fragmentType == CodeFragment.Type.None)) { textColor = Colors.Black; } FormattedText formattedText = new FormattedText( textContent, CultureInfo.GetCultureInfo("en-us"), FlowDirection.LeftToRight, font, Configurations.FontHeight, new SolidColorBrush(textColor)); // Draw the formatted text into the drawing context. context.DrawText(formattedText, linePosition); if (lineContent[charIndex] == '\n') { break; } else { linePosition.X += formattedText.WidthIncludingTrailingWhitespace; } if (fragmentWidth > 0) { charIndex += offsetToNextChar; } } // Update the line position coordinate for the displayed line. linePosition.Y += Configurations.FontDisplayHeight; } // Persist the drawn text content. context.Close(); return(drawingVisual); }
protected override DrawingVisual RenderCore(RenderParameters renderParams) { caretRect.Height = Configurations.FontDisplayHeight; if (null == drawingVisual) { drawingVisual = new DrawingVisual(); PauseCaretTimer(false); // Get timer going! } // There's no script yet. if (null == this.currentScript) { return(drawingVisual); } DrawingContext context = drawingVisual.RenderOpen(); CodeFragment[] crossHighlight = textEditorCanvas.TextEditorCore.GetCrossHighlightArray(); if (crossHighlight != null) { if (crossHighlight.Length != 0) { List <Rect> rectList = new List <Rect>(); foreach (CodeFragment codeFragment in crossHighlight) { CharPosition start = currentScript.CreateCharPosition(); start.SetCharacterPosition(codeFragment.ColStart, codeFragment.Line); CharPosition end = currentScript.CreateCharPosition(); end.SetCharacterPosition(codeFragment.ColEnd + 1, codeFragment.Line); List <Rect> tempList = CalculateRectangles(start, end, renderParams.firstVisibleLine); if (tempList != null) { rectList.AddRange(tempList); } } //SolidColorBrush crossHighlightBrush = new SolidColorBrush(Color.FromRgb(226, 230, 214)); RenderRectangles(context, rectList, UIColors.CrossHighlightColor); } } // We don't care about keyboard focus when in playback mode. if (false == TextEditorControl.Instance.IsInPlaybackMode) { // If the focus is not within the canvas, or on any extension popup, // then there's no need to show the caret (focus is probably other app). if (false == TextEditorControl.Instance.ShouldDisplayCaret()) { caretVisibility = System.Windows.Visibility.Hidden; } } // Cursor rendering pass... if (caretVisibility == System.Windows.Visibility.Visible) { System.Windows.Rect displayRect = caretRect; double firstVisibleColumn = textEditorCanvas.FirstVisibleColumn * Configurations.FormatFontWidth; displayRect.Offset(-firstVisibleColumn, -renderParams.firstVisibleLine * Configurations.FontDisplayHeight); context.DrawRectangle(Brushes.Black, null, displayRect); } context.Close(); return(drawingVisual); }
protected override DrawingVisual RenderCore(RenderParameters renderParams) { if (drawingVisual == null) drawingVisual = new DrawingVisual(); if (null == currentScript) return drawingVisual; // No active script yet! System.Windows.Point linePosition = new System.Windows.Point( Configurations.CanvasMarginLeft, 0); ITextEditorCore textCore = textEditorCanvas.TextEditorCore; ITextBuffer textBuffer = currentScript.GetTextBuffer(); numberOfLines = textBuffer.GetLineCount(); int lastVisibleLine = renderParams.firstVisibleLine + renderParams.maxVisibleLines; if (lastVisibleLine >= numberOfLines) lastVisibleLine = numberOfLines - 1; // Retrieve the DrawingContext from the DrawingVisual. DrawingContext context = drawingVisual.RenderOpen(); int maxColumns = textEditorCanvas.MaxVisibelColumns + 1; double hiddenWidth = textEditorCanvas.FirstVisibleColumn * Configurations.FormatFontWidth; CharPosition converter = this.currentScript.CreateCharPosition(); Typeface font = new Typeface(Configurations.FontFace); for (int lineIndex = renderParams.firstVisibleLine; lineIndex <= lastVisibleLine; lineIndex++) { // A constant starting point on left edge. linePosition.X = Configurations.CanvasMarginLeft; int startColumn = converter.VisualToCharOffset(lineIndex, textEditorCanvas.FirstVisibleColumn); string lineContent = textBuffer.GetLineContent(lineIndex); int lineLength = (lineContent != null ? lineContent.Length : 0); if (lineLength <= startColumn) { linePosition.Y += Configurations.FontDisplayHeight; continue; } if (startColumn > 0) { string hiddenText = lineContent.Substring(0, startColumn); hiddenText = hiddenText.Replace("\t", Configurations.TabSpaces); // Accounting for the part that is hidden beyond the left of canvas. double hiddenTextWidth = hiddenText.Length * Configurations.FormatFontWidth; linePosition.X = linePosition.X + hiddenTextWidth - hiddenWidth; } int endColumn = startColumn + maxColumns; endColumn = ((endColumn >= lineLength) ? lineLength - 1 : endColumn); for (int charIndex = startColumn; charIndex <= endColumn; charIndex++) { CodeFragment fragment = null; int fragmentWidth = textCore.GetFragment( charIndex, lineIndex, out fragment); // We may be showing partial fragment now. if (null != fragment) fragmentWidth -= (charIndex - fragment.ColStart); int offsetToNextChar = fragmentWidth - 1; if ((charIndex + fragmentWidth) > (lineLength - 1)) { fragmentWidth = (lineLength - 1) - charIndex; offsetToNextChar = fragmentWidth - 1; } // Initialize the text store. string textContent = string.Empty; textContent = lineContent.Substring(charIndex, ((fragmentWidth == 0) ? 1 : fragmentWidth)); // Replace all TAB characters with actual spaces. textContent = textContent.Replace("\t", Configurations.TabSpaces); CodeFragment.Type fragmentType = CodeFragment.Type.None; if (null != fragment) fragmentType = fragment.CodeType; Color textColor = CodeFragment.GetFragmentColor(fragmentType); if ((textBuffer.ParsePending == true) && (fragmentType == CodeFragment.Type.None)) textColor = Colors.Black; FormattedText formattedText = new FormattedText( textContent, CultureInfo.GetCultureInfo("en-us"), FlowDirection.LeftToRight, font, Configurations.FontHeight, new SolidColorBrush(textColor)); // Draw the formatted text into the drawing context. context.DrawText(formattedText, linePosition); if (lineContent[charIndex] == '\n') break; else { linePosition.X += formattedText.WidthIncludingTrailingWhitespace; } if (fragmentWidth > 0) charIndex += offsetToNextChar; } // Update the line position coordinate for the displayed line. linePosition.Y += Configurations.FontDisplayHeight; } // Persist the drawn text content. context.Close(); return drawingVisual; }
protected override DrawingVisual RenderCore(RenderParameters renderParams) { if (null == drawingVisual) drawingVisual = new DrawingVisual(); // There's no script yet. if (null == currentScript) return drawingVisual; if (null == textEditorCanvas.TextEditorCore.CurrentTextBuffer) return drawingVisual; DrawingContext context = drawingVisual.RenderOpen(); lineSelection.SetCharacterPosition(textEditorCanvas.TextEditorCore.CursorPosition); Rect cursorSelections = CalculateRectangleFullLine(lineSelection, renderParams.firstVisibleLine); RenderRectangle(context, cursorSelections, UIColors.CursorSelectionColor); List<InlineMessageItem> messageList = Solution.Current.GetInlineMessage(); if (messageList != null) { foreach (InlineMessageItem message in messageList) { int line = message.Line; int column = message.Column; if (Solution.Current.ActiveScript == null || message.FilePath != Solution.Current.ActiveScript.GetParsedScript().GetScriptPath()) continue; if (line >= 0) { System.Drawing.Point inlineSelectionStart = new System.Drawing.Point(column, line); inLineSelection.SetCharacterPosition(inlineSelectionStart); Rect outputSelections = CalculateRectangleFullLine(inLineSelection, renderParams.firstVisibleLine); Color inLineColor = new Color(); switch (message.Type) { case InlineMessageItem.OutputMessageType.Error: inLineColor = UIColors.InlinErrorColor; break; case InlineMessageItem.OutputMessageType.Warning: inLineColor = UIColors.InlineWarningColor; break; case InlineMessageItem.OutputMessageType.PossibleError: inLineColor = UIColors.InlinPossibleErrorColor; break; case InlineMessageItem.OutputMessageType.PossibleWarning: inLineColor = UIColors.InlinPossibleWarningColor; break; } RenderRectangle(context, outputSelections, inLineColor); } } } if (null != breakpointsRef) { CharPosition startPoint = currentScript.CreateCharPosition(); CharPosition endPoint = currentScript.CreateCharPosition(); foreach (CodeRange breakpoint in breakpointsRef) { if (FallsWithinActiveScript(breakpoint.StartInclusive) == false) continue; // This breakpoint does not belong to the script. int startX = breakpoint.StartInclusive.CharNo - 1; int startY = breakpoint.StartInclusive.LineNo - 1; int endX = breakpoint.EndExclusive.CharNo - 1; int endY = breakpoint.EndExclusive.LineNo - 1; startPoint.SetCharacterPosition(startX, startY); endPoint.SetCharacterPosition(endX, endY); Rect region = CalculateRectangleFullLine(startPoint, renderParams.firstVisibleLine); RenderRectangle(context, region, UIColors.BreakpointLineColor); } } if (FallsWithinActiveScript(executionCursor.StartInclusive)) { CharPosition start = currentScript.CreateCharPosition(); CharPosition end = currentScript.CreateCharPosition(); start.SetCharacterPosition( executionCursor.StartInclusive.CharNo - 1, executionCursor.StartInclusive.LineNo - 1); end.SetCharacterPosition( executionCursor.EndExclusive.CharNo - 1, executionCursor.EndExclusive.LineNo - 1); List<Rect> execCursors = CalculateRectangles(start, end, renderParams.firstVisibleLine); RenderRectangles(context, execCursors, UIColors.ExecutionCursorColor); } List<Rect> selections = CalculateRectangles(selectionStart, selectionEnd, renderParams.firstVisibleLine); RenderRectangles(context, selections, UIColors.SelectionsColor); List<FindPosition> searchResults = textEditorCanvas.TextEditorCore.CurrentTextBuffer.SearchResult; if (searchResults != null) { System.Drawing.Point start; System.Drawing.Point end; foreach (FindPosition item in searchResults) { start = item.startPoint; end = item.endPoint; end.X += 1; allOccurencesSelectionStart.SetCharacterPosition(start); allOccurencesSelectionEnd.SetCharacterPosition(end); List<Rect> findSelections = CalculateRectangles(allOccurencesSelectionStart, allOccurencesSelectionEnd, renderParams.firstVisibleLine); RenderRectangles(context, findSelections, Colors.Yellow); } int searchIndex = textEditorCanvas.TextEditorCore.CurrentTextBuffer.CurrentSearchIndex; if (searchResults.Count != 0 && searchIndex != -1) { FindPosition currentPosition = searchResults[searchIndex]; System.Drawing.Point startPoint = currentPosition.startPoint; System.Drawing.Point endPoint = currentPosition.endPoint; endPoint.X += 1; if (startPoint.X == 0 && endPoint.X == 0 && startPoint.Y == 0 && endPoint.Y == 0) { } else { currentOccurenceSelectionStart.SetCharacterPosition(startPoint); currentOccurenceSelectionEnd.SetCharacterPosition(endPoint); List<Rect> currentOccurenceSelections = CalculateRectangles(currentOccurenceSelectionStart, currentOccurenceSelectionEnd, renderParams.firstVisibleLine); RenderRectangles(context, currentOccurenceSelections, Colors.Orange); } } } context.Close(); return drawingVisual; }
protected override DrawingVisual RenderCore(RenderParameters renderParams) { if (null == drawingVisual) drawingVisual = new DrawingVisual(); if (null == currentScript) return drawingVisual; // There's nothing here yet. // Even when a line is half shown, we draw it in full. renderParams.maxVisibleLines = renderParams.maxVisibleLines + 1; ITextBuffer textBuffer = currentScript.GetTextBuffer(); int lineCount = textBuffer.GetLineCount(); lineCount = ((0 == lineCount) ? 1 : lineCount); if (lineCount > renderParams.maxVisibleLines) lineCount = renderParams.maxVisibleLines; int lastVisibleLine = renderParams.firstVisibleLine + lineCount; DrawingContext context = drawingVisual.RenderOpen(); double columnHeight = renderParams.maxVisibleLines * Configurations.FontDisplayHeight; // BreakpointIcon Rectangle Rect breakpointRectangle = new Rect(0, 0, Configurations.BreakpointColumnWidth, columnHeight); SolidColorBrush breakpointRectangleBrush = new SolidColorBrush(UIColors.BreakpointColor); context.DrawRectangle(breakpointRectangleBrush, null, breakpointRectangle); // Line Number Rectangle double lineColumnStart = Configurations.LineNumberColumnStart; double lineColumnWidth = Configurations.LineNumberColumnWidth; Rect numberRectangle = new Rect(lineColumnStart, 0, lineColumnWidth, columnHeight); SolidColorBrush lineColumnBrush = new SolidColorBrush(UIColors.LineColumnBrushColor); context.DrawRectangle(lineColumnBrush, null, numberRectangle); //Shadow Lines double halfShadowWidth = Configurations.ShadowWidth / 2; double start = Configurations.LineNumberColumnEnd; Point startPointDark = new Point(start, 0); Point startPointLight = new Point(start + halfShadowWidth, 0); Point endPointDark = new Point(start, columnHeight); Point endPointLight = new Point(start + halfShadowWidth, columnHeight); SolidColorBrush shadowDarkBrush = new SolidColorBrush(UIColors.ShadowDarkColor); SolidColorBrush shadowLightBrush = new SolidColorBrush(UIColors.ShadowLightColor); Pen darkPen = new Pen(shadowDarkBrush, halfShadowWidth); Pen lightPen = new Pen(shadowLightBrush, halfShadowWidth); context.DrawLine(darkPen, startPointDark, endPointDark); context.DrawLine(lightPen, startPointLight, endPointLight); double textColumnRightEdge = Configurations.LineNumberColumnStart + lineColumnWidth - Configurations.LineNumberColumnPadding; Point point = new Point(textColumnRightEdge, 0); Typeface typeface = new Typeface(Configurations.FontFace); for (int index = renderParams.firstVisibleLine + 1; index <= lastVisibleLine; index++) { FormattedText formattedtext = new FormattedText(index.ToString(), CultureInfo.GetCultureInfo("en-US"), FlowDirection.LeftToRight, typeface, Configurations.FontHeight, Brushes.Gray); formattedtext.TextAlignment = TextAlignment.Right; context.DrawText(formattedtext, point); point.Y = point.Y + Configurations.FontDisplayHeight; } RenderBreakpoints(context, renderParams.firstVisibleLine, lastVisibleLine); HighlightCurrentLine(context, renderParams.firstVisibleLine, lastVisibleLine); RenderInlineIcons(context, renderParams.firstVisibleLine, lastVisibleLine); context.Close(); return drawingVisual; }
protected override DrawingVisual RenderCore(RenderParameters renderParams) { if (null == drawingVisual) { drawingVisual = new DrawingVisual(); } // There's no script yet. if (null == currentScript) { return(drawingVisual); } if (null == textEditorCanvas.TextEditorCore.CurrentTextBuffer) { return(drawingVisual); } DrawingContext context = drawingVisual.RenderOpen(); lineSelection.SetCharacterPosition(textEditorCanvas.TextEditorCore.CursorPosition); Rect cursorSelections = CalculateRectangleFullLine(lineSelection, renderParams.firstVisibleLine); RenderRectangle(context, cursorSelections, UIColors.CursorSelectionColor); List <InlineMessageItem> messageList = Solution.Current.GetInlineMessage(); if (messageList != null) { foreach (InlineMessageItem message in messageList) { int line = message.Line; int column = message.Column; if (Solution.Current.ActiveScript == null || message.FilePath != Solution.Current.ActiveScript.GetParsedScript().GetScriptPath()) { continue; } if (line >= 0) { System.Drawing.Point inlineSelectionStart = new System.Drawing.Point(column, line); inLineSelection.SetCharacterPosition(inlineSelectionStart); Rect outputSelections = CalculateRectangleFullLine(inLineSelection, renderParams.firstVisibleLine); Color inLineColor = new Color(); switch (message.Type) { case InlineMessageItem.OutputMessageType.Error: inLineColor = UIColors.InlinErrorColor; break; case InlineMessageItem.OutputMessageType.Warning: inLineColor = UIColors.InlineWarningColor; break; case InlineMessageItem.OutputMessageType.PossibleError: inLineColor = UIColors.InlinPossibleErrorColor; break; case InlineMessageItem.OutputMessageType.PossibleWarning: inLineColor = UIColors.InlinPossibleWarningColor; break; } RenderRectangle(context, outputSelections, inLineColor); } } } if (null != breakpointsRef) { CharPosition startPoint = currentScript.CreateCharPosition(); CharPosition endPoint = currentScript.CreateCharPosition(); foreach (CodeRange breakpoint in breakpointsRef) { if (FallsWithinActiveScript(breakpoint.StartInclusive) == false) { continue; // This breakpoint does not belong to the script. } int startX = breakpoint.StartInclusive.CharNo - 1; int startY = breakpoint.StartInclusive.LineNo - 1; int endX = breakpoint.EndExclusive.CharNo - 1; int endY = breakpoint.EndExclusive.LineNo - 1; startPoint.SetCharacterPosition(startX, startY); endPoint.SetCharacterPosition(endX, endY); Rect region = CalculateRectangleFullLine(startPoint, renderParams.firstVisibleLine); RenderRectangle(context, region, UIColors.BreakpointLineColor); } } if (FallsWithinActiveScript(executionCursor.StartInclusive)) { CharPosition start = currentScript.CreateCharPosition(); CharPosition end = currentScript.CreateCharPosition(); start.SetCharacterPosition( executionCursor.StartInclusive.CharNo - 1, executionCursor.StartInclusive.LineNo - 1); end.SetCharacterPosition( executionCursor.EndExclusive.CharNo - 1, executionCursor.EndExclusive.LineNo - 1); List <Rect> execCursors = CalculateRectangles(start, end, renderParams.firstVisibleLine); RenderRectangles(context, execCursors, UIColors.ExecutionCursorColor); } List <Rect> selections = CalculateRectangles(selectionStart, selectionEnd, renderParams.firstVisibleLine); RenderRectangles(context, selections, UIColors.SelectionsColor); List <FindPosition> searchResults = textEditorCanvas.TextEditorCore.CurrentTextBuffer.SearchResult; if (searchResults != null) { System.Drawing.Point start; System.Drawing.Point end; foreach (FindPosition item in searchResults) { start = item.startPoint; end = item.endPoint; end.X += 1; allOccurencesSelectionStart.SetCharacterPosition(start); allOccurencesSelectionEnd.SetCharacterPosition(end); List <Rect> findSelections = CalculateRectangles(allOccurencesSelectionStart, allOccurencesSelectionEnd, renderParams.firstVisibleLine); RenderRectangles(context, findSelections, Colors.Yellow); } int searchIndex = textEditorCanvas.TextEditorCore.CurrentTextBuffer.CurrentSearchIndex; if (searchResults.Count != 0 && searchIndex != -1) { FindPosition currentPosition = searchResults[searchIndex]; System.Drawing.Point startPoint = currentPosition.startPoint; System.Drawing.Point endPoint = currentPosition.endPoint; endPoint.X += 1; if (startPoint.X == 0 && endPoint.X == 0 && startPoint.Y == 0 && endPoint.Y == 0) { } else { currentOccurenceSelectionStart.SetCharacterPosition(startPoint); currentOccurenceSelectionEnd.SetCharacterPosition(endPoint); List <Rect> currentOccurenceSelections = CalculateRectangles(currentOccurenceSelectionStart, currentOccurenceSelectionEnd, renderParams.firstVisibleLine); RenderRectangles(context, currentOccurenceSelections, Colors.Orange); } } } context.Close(); return(drawingVisual); }
protected override DrawingVisual RenderCore(RenderParameters renderParams) { if (null == drawingVisual) { drawingVisual = new DrawingVisual(); } if (null == currentScript) { return(drawingVisual); // There's nothing here yet. } // Even when a line is half shown, we draw it in full. renderParams.maxVisibleLines = renderParams.maxVisibleLines + 1; ITextBuffer textBuffer = currentScript.GetTextBuffer(); int lineCount = textBuffer.GetLineCount(); lineCount = ((0 == lineCount) ? 1 : lineCount); if (lineCount > renderParams.maxVisibleLines) { lineCount = renderParams.maxVisibleLines; } int lastVisibleLine = renderParams.firstVisibleLine + lineCount; DrawingContext context = drawingVisual.RenderOpen(); double columnHeight = renderParams.maxVisibleLines * Configurations.FontDisplayHeight; // BreakpointIcon Rectangle Rect breakpointRectangle = new Rect(0, 0, Configurations.BreakpointColumnWidth, columnHeight); SolidColorBrush breakpointRectangleBrush = new SolidColorBrush(UIColors.BreakpointColor); context.DrawRectangle(breakpointRectangleBrush, null, breakpointRectangle); // Line Number Rectangle double lineColumnStart = Configurations.LineNumberColumnStart; double lineColumnWidth = Configurations.LineNumberColumnWidth; Rect numberRectangle = new Rect(lineColumnStart, 0, lineColumnWidth, columnHeight); SolidColorBrush lineColumnBrush = new SolidColorBrush(UIColors.LineColumnBrushColor); context.DrawRectangle(lineColumnBrush, null, numberRectangle); //Shadow Lines double halfShadowWidth = Configurations.ShadowWidth / 2; double start = Configurations.LineNumberColumnEnd; Point startPointDark = new Point(start, 0); Point startPointLight = new Point(start + halfShadowWidth, 0); Point endPointDark = new Point(start, columnHeight); Point endPointLight = new Point(start + halfShadowWidth, columnHeight); SolidColorBrush shadowDarkBrush = new SolidColorBrush(UIColors.ShadowDarkColor); SolidColorBrush shadowLightBrush = new SolidColorBrush(UIColors.ShadowLightColor); Pen darkPen = new Pen(shadowDarkBrush, halfShadowWidth); Pen lightPen = new Pen(shadowLightBrush, halfShadowWidth); context.DrawLine(darkPen, startPointDark, endPointDark); context.DrawLine(lightPen, startPointLight, endPointLight); double textColumnRightEdge = Configurations.LineNumberColumnStart + lineColumnWidth - Configurations.LineNumberColumnPadding; Point point = new Point(textColumnRightEdge, 0); Typeface typeface = new Typeface(Configurations.FontFace); for (int index = renderParams.firstVisibleLine + 1; index <= lastVisibleLine; index++) { FormattedText formattedtext = new FormattedText(index.ToString(), CultureInfo.GetCultureInfo("en-US"), FlowDirection.LeftToRight, typeface, Configurations.FontHeight, Brushes.Gray); formattedtext.TextAlignment = TextAlignment.Right; context.DrawText(formattedtext, point); point.Y = point.Y + Configurations.FontDisplayHeight; } RenderBreakpoints(context, renderParams.firstVisibleLine, lastVisibleLine); HighlightCurrentLine(context, renderParams.firstVisibleLine, lastVisibleLine); RenderInlineIcons(context, renderParams.firstVisibleLine, lastVisibleLine); context.Close(); return(drawingVisual); }