/// <summary> /// Adds the specified segment to the geometry. /// </summary> public void AddSegment(TextView textView, ISegment segment) { if (textView == null) { throw new ArgumentNullException("textView"); } Size pixelSize = PixelSnapHelpers.GetPixelSize(textView); foreach (Rect r in GetRectsForSegment(textView, segment)) { if (AlignToWholePixels) { AddRectangle(PixelSnapHelpers.Round(r.Left, pixelSize.Width), PixelSnapHelpers.Round(r.Top, pixelSize.Height), PixelSnapHelpers.Round(r.Right, pixelSize.Width), PixelSnapHelpers.Round(r.Bottom, pixelSize.Height)); } else if (AlignToMiddleOfPixels) { AddRectangle(PixelSnapHelpers.PixelAlign(r.Left, pixelSize.Width), PixelSnapHelpers.PixelAlign(r.Top, pixelSize.Height), PixelSnapHelpers.PixelAlign(r.Right, pixelSize.Width), PixelSnapHelpers.PixelAlign(r.Bottom, pixelSize.Height)); } else { AddRectangle(r.Left, r.Top, r.Right, r.Bottom); } } }
public override void Render(DrawingContext drawingContext) { base.Render(drawingContext); if (_isVisible && _blink) { var caretBrush = CaretBrush ?? TextView.GetValue(TextBlock.ForegroundProperty); if (_textArea.OverstrikeMode) { if (caretBrush is ISolidColorBrush scBrush) { var brushColor = scBrush.Color; var newColor = Color.FromArgb(100, brushColor.R, brushColor.G, brushColor.B); caretBrush = new SolidColorBrush(newColor); } } var r = new Rect(_caretRectangle.X - TextView.HorizontalOffset, _caretRectangle.Y - TextView.VerticalOffset, _caretRectangle.Width, _caretRectangle.Height); drawingContext.FillRectangle(caretBrush, PixelSnapHelpers.Round(r, PixelSnapHelpers.GetPixelSize(this))); } }
protected override void OnRender(DrawingContext drawingContext) { var renderSize = RenderSize; drawingContext.DrawRectangle(SystemColors.ControlBrush, null, new Rect(0, 0, renderSize.Width, renderSize.Height)); drawingContext.DrawLine(new Pen(SystemColors.ControlDarkBrush, 1), new Point(renderSize.Width - 0.5, 0), new Point(renderSize.Width - 0.5, renderSize.Height)); var textView = TextView; if (textView == null || !textView.VisualLinesValid) { return; } // create a dictionary line number => first bookmark var bookmarkDict = new Dictionary <int, IBookmark>(); foreach (var bm in _manager.Bookmarks) { var line = bm.LineNumber; IBookmark existingBookmark; if (!bookmarkDict.TryGetValue(line, out existingBookmark) || bm.ZOrder > existingBookmark.ZOrder) { bookmarkDict[line] = bm; } } var pixelSize = PixelSnapHelpers.GetPixelSize(this); Rect rect; foreach (var line in textView.VisualLines) { var lineNumber = line.FirstDocumentLine.LineNumber; IBookmark bm; if (!bookmarkDict.TryGetValue(lineNumber, out bm)) { continue; } var lineMiddle = line.GetTextLineVisualYPosition(line.TextLines[0], VisualYPosition.TextMiddle) - textView.VerticalOffset; rect = new Rect(0, PixelSnapHelpers.Round(lineMiddle - 8, pixelSize.Height), 16, 16); if (_dragDropBookmark == bm && _dragStarted) { drawingContext.PushOpacity(0.5); } drawingContext.DrawImage((bm.Image ?? BookmarkBase.defaultBookmarkImage).Bitmap, rect); if (_dragDropBookmark == bm && _dragStarted) { drawingContext.Pop(); } } if (_dragDropBookmark == null || !_dragStarted) { return; } rect = new Rect(0, PixelSnapHelpers.Round(_dragDropCurrentPoint - 8, pixelSize.Height), 16, 16); drawingContext.DrawImage((_dragDropBookmark.Image ?? BookmarkBase.defaultBookmarkImage).ImageSource, rect); }
protected override void OnRender(DrawingContext drawingContext) { var renderSize = RenderSize; drawingContext.DrawRectangle(SystemColors.ControlBrush, null, new Rect(0, 0, renderSize.Width, renderSize.Height)); drawingContext.DrawLine(new Pen(SystemColors.ControlDarkBrush, 1), new Point(renderSize.Width - 0.5, 0), new Point(renderSize.Width - 0.5, renderSize.Height)); var textView = TextView; if (textView == null || !textView.VisualLinesValid) { return; } var pixelSize = PixelSnapHelpers.GetPixelSize(this); foreach (var line in textView.VisualLines) { var lineNumber = line.FirstDocumentLine.LineNumber; var bookmarks = _manager.Bookmarks.Where(item => item.LineNumber == lineNumber).ToList(); var renderer = default(IMarkerRenderer); var bookmark = bookmarks.FirstOrDefault(); // Make sure that a breakpoint or current debug point is always the one rendered if there is multiple bookmarks on the line foreach (var b in bookmarks) { if (b.BookmarkType == BookmarkType.Breakpoint || b.BookmarkType == BookmarkType.CurrentDebugPoint) { bookmark = b; break; } } if (bookmark == null) { continue; } switch (bookmark.BookmarkType) { case BookmarkType.CurrentDebugPoint: case BookmarkType.Breakpoint: renderer = new DebugMarkerRenderer(textView, this); break; case BookmarkType.ParseError: renderer = new ParseErrorRenderer(textView, this); break; case BookmarkType.AnalyzerWarning: renderer = new AnalyzerWarningRenderer(textView, this); break; } renderer?.Render(drawingContext, line, pixelSize); } }
protected override Size MeasureCore(Size availableSize) { double size = MarginSizeFactor * FoldingMargin.SizeFactor * (double)GetValue(TextBlock.FontSizeProperty); size = PixelSnapHelpers.RoundToOdd(size, PixelSnapHelpers.GetPixelSize(this).Width); return(new Size(size, size)); }
public void Draw(TextView textView, DrawingContext drawingContext) { if (_textEditor.SelectionLength == 0 && _textEditor.CaretOffset != -1 && _textEditor.CaretOffset <= textView.Document.TextLength) { var currentLine = textView.Document.GetLocation(_textEditor.CaretOffset).Line; var visualLine = textView.GetVisualLine(currentLine); if (visualLine == null) { return; } BackgroundGeometryBuilder builder = new BackgroundGeometryBuilder(); var linePosY = visualLine.VisualTop - textView.ScrollOffset.Y; var lineBottom = linePosY + visualLine.Height; Size pixelSize = PixelSnapHelpers.GetPixelSize(textView); double x = PixelSnapHelpers.PixelAlign(0, pixelSize.Width); double y = PixelSnapHelpers.PixelAlign(linePosY, pixelSize.Height); var x2 = PixelSnapHelpers.PixelAlign(textView.Bounds.Width, pixelSize.Width); var y2 = PixelSnapHelpers.PixelAlign(lineBottom, pixelSize.Height); builder.AddRectangle(textView, new Rect(new Point(x, y), new Point(x2, y2))); Geometry geometry = builder.CreateGeometry(); if (geometry != null) { drawingContext.DrawGeometry(BackgroundBrush, BorderPen, geometry); } } }
protected override void OnRender(DrawingContext drawingContext) { FoldingMargin margin = VisualParent as FoldingMargin; Pen activePen = new Pen(margin.SelectedFoldingMarkerBrush, 1); Pen inactivePen = new Pen(margin.FoldingMarkerBrush, 1); activePen.StartLineCap = inactivePen.StartLineCap = PenLineCap.Square; activePen.EndLineCap = inactivePen.EndLineCap = PenLineCap.Square; Size pixelSize = PixelSnapHelpers.GetPixelSize(this); Rect rect = new Rect(pixelSize.Width / 2, pixelSize.Height / 2, this.RenderSize.Width - pixelSize.Width, this.RenderSize.Height - pixelSize.Height); drawingContext.DrawRectangle( IsMouseDirectlyOver ? margin.SelectedFoldingMarkerBackgroundBrush : margin.FoldingMarkerBackgroundBrush, IsMouseDirectlyOver ? activePen : inactivePen, rect); double middleX = rect.Left + rect.Width / 2; double middleY = rect.Top + rect.Height / 2; double space = PixelSnapHelpers.Round(rect.Width / 8, pixelSize.Width) + pixelSize.Width; drawingContext.DrawLine(activePen, new Point(rect.Left + space, middleY), new Point(rect.Right - space, middleY)); if (!isExpanded) { drawingContext.DrawLine(activePen, new Point(middleX, rect.Top + space), new Point(middleX, rect.Bottom - space)); } }
protected override void OnRender(DrawingContext drawingContext) { base.OnRender(drawingContext); if (isVisible && blink) { Brush caretBrush = this.CaretBrush; if (caretBrush == null) { caretBrush = (Brush)textView.GetValue(TextBlock.ForegroundProperty); } if (this.textArea.OverstrikeMode) { SolidColorBrush scBrush = caretBrush as SolidColorBrush; if (scBrush != null) { Color brushColor = scBrush.Color; Color newColor = Color.FromArgb(100, brushColor.R, brushColor.G, brushColor.B); caretBrush = new SolidColorBrush(newColor); caretBrush.Freeze(); } } Rect r = new Rect(caretRectangle.X - textView.HorizontalOffset, caretRectangle.Y - textView.VerticalOffset, caretRectangle.Width, caretRectangle.Height); drawingContext.DrawRectangle(caretBrush, null, PixelSnapHelpers.Round(r, PixelSnapHelpers.GetPixelSize(this))); } }
protected override void OnRender(DrawingContext drawingContext) { Pen blackPen = new Pen(Brushes.Black, 1); blackPen.StartLineCap = PenLineCap.Square; blackPen.EndLineCap = PenLineCap.Square; Size pixelSize = PixelSnapHelpers.GetPixelSize(this); Rect rect = new Rect(pixelSize.Width / 2, pixelSize.Height / 2, this.RenderSize.Width - pixelSize.Width, this.RenderSize.Height - pixelSize.Height); drawingContext.DrawRectangle(Brushes.White, IsMouseDirectlyOver ? blackPen : new Pen(Brushes.Gray, 1), rect); double middleX = rect.Left + rect.Width / 2; double middleY = rect.Top + rect.Height / 2; double space = PixelSnapHelpers.Round(rect.Width / 8, pixelSize.Width) + pixelSize.Width; drawingContext.DrawLine(blackPen, new Point(rect.Left + space, middleY), new Point(rect.Right - space, middleY)); if (!isExpanded) { drawingContext.DrawLine(blackPen, new Point(middleX, rect.Top + space), new Point(middleX, rect.Bottom - space)); } }
protected override Size ArrangeOverride(Size finalSize) { var pixelSize = PixelSnapHelpers.GetPixelSize(this); var textView = TextView; _visibleMarkers.Clear(); foreach (var marker in _markers) { RemoveVisualChild(marker); var visualLine = textView.GetVisualLine(marker.Breakpoint.Anchor.Line); if (visualLine == null) { continue; } _visibleMarkers.Add(marker); AddVisualChild(marker); var topLeft = new Point(0, visualLine.VisualTop - textView.VerticalOffset); marker.Arrange(new Rect(PixelSnapHelpers.Round(topLeft, pixelSize), marker.DesiredSize)); } return(base.ArrangeOverride(finalSize)); }
void DrawLineForInsertionPoint(int index, Pen pen, DrawingContext drawingContext) { var pos = GetLinePosition(index); var endPos = new Point(pos.X + editor.TextView.ActualWidth * 0.6, pos.Y); var pixelSize = PixelSnapHelpers.GetPixelSize(this); drawingContext.DrawLine(pen, PixelSnapHelpers.Round(pos, pixelSize), PixelSnapHelpers.Round(endPos, pixelSize)); }
public void Render(DrawingContext drawingContext, VisualLine line, Size pixelSize) { var lineMiddle = line.GetTextLineVisualYPosition(line.TextLines[0], VisualYPosition.TextMiddle) - _textView.VerticalOffset; var rect = new Rect(3, PixelSnapHelpers.Round(lineMiddle - 8, pixelSize.Height) + 1, 14, 14); drawingContext.DrawRoundedRectangle(Brushes.DarkRed, null, rect, 8, 8); }
protected override void OnRender(DrawingContext drawingContext) { Size renderSize = this.RenderSize; drawingContext.DrawRectangle(SystemColors.ControlBrush, null, new Rect(0, 0, renderSize.Width, renderSize.Height)); drawingContext.DrawLine(new Pen(SystemColors.ControlDarkBrush, 1), new Point(renderSize.Width - 0.5, 0), new Point(renderSize.Width - 0.5, renderSize.Height)); TextView textView = this.TextView; if (textView != null && textView.VisualLinesValid) { // create a dictionary line number => first bookmark Dictionary <int, BookmarkBase> bookmarkDict = new Dictionary <int, BookmarkBase>(); foreach (var bm in BookmarkManager.Bookmarks) { if (DebugData.DecompiledMemberReferences == null || DebugData.DecompiledMemberReferences.Count == 0 || !DebugData.DecompiledMemberReferences.ContainsKey(bm.MemberReference.MetadataToken.ToInt32())) { continue; } int line = bm.LineNumber; BookmarkBase existingBookmark; if (!bookmarkDict.TryGetValue(line, out existingBookmark) || bm.ZOrder > existingBookmark.ZOrder) { bookmarkDict[line] = bm; } } Size pixelSize = PixelSnapHelpers.GetPixelSize(this); foreach (VisualLine line in textView.VisualLines) { int lineNumber = line.FirstDocumentLine.LineNumber; BookmarkBase bm; if (bookmarkDict.TryGetValue(lineNumber, out bm)) { Rect rect = new Rect(0, PixelSnapHelpers.Round(line.VisualTop - textView.VerticalOffset, pixelSize.Height), 16, 16); if (dragDropBookmark == bm && dragStarted) { drawingContext.PushOpacity(0.5); } drawingContext.DrawImage(bm.Image, rect); if (dragDropBookmark == bm && dragStarted) { drawingContext.Pop(); } } } if (dragDropBookmark != null && dragStarted) { Rect rect = new Rect(0, PixelSnapHelpers.Round(dragDropCurrentPoint - 8, pixelSize.Height), 16, 16); drawingContext.DrawImage(dragDropBookmark.Image, rect); } } }
public void Draw(TextView textView, DrawingContext drawingContext) { var typeface = textView.GetValue(TextBlock.FontFamilyProperty); var emSize = textView.GetValue(TextBlock.FontSizeProperty); var formattedText = TextFormatterFactory.CreateFormattedText( textView, "9", typeface, emSize, Brushes.Black ); var charSize = formattedText.Measure(); var pixelSize = PixelSnapHelpers.GetPixelSize(textView); foreach (var entry in markers) { var startLine = textView.Document.GetLineByOffset(entry.StartOffset); var start = entry.StartOffset; var startChar = textView.Document.GetCharAt(startLine.Offset); if (char.IsWhiteSpace(startChar)) { start = TextUtilities.GetNextCaretPosition(textView.Document, startLine.Offset, LogicalDirection.Forward, CaretPositioningMode.WordBorder); } var endLine = textView.Document.GetLineByOffset(entry.EndOffset <= textView.Document.TextLength ? entry.EndOffset : textView.Document.TextLength); if (endLine.EndOffset > start && startLine != endLine) { var newEntry = new TextSegment() { StartOffset = start, EndOffset = endLine.EndOffset }; var rects = BackgroundGeometryBuilder.GetRectsForSegment(textView, newEntry); var rect = GetRectForRange(rects); if (!rect.IsEmpty) { var xPos = charSize.Width * (textView.Document.GetLocation(newEntry.StartOffset).Column - 1); rect = rect.WithX(xPos + (charSize.Width / 2)); rect = rect.WithX(PixelSnapHelpers.PixelAlign(rect.X, pixelSize.Width)); rect = rect.WithY(PixelSnapHelpers.PixelAlign(rect.Y, pixelSize.Height)); drawingContext.DrawLine(_pen, rect.TopLeft, rect.BottomLeft); } } } }
/// <summary> /// Adds the specified segment to the geometry. /// </summary> public void AddSegment(TextView textView, ISegment segment) { if (textView == null) throw new ArgumentNullException("textView"); Size pixelSize = PixelSnapHelpers.GetPixelSize(textView); foreach (Rect r in GetRectsForSegment(textView, segment, ExtendToFullWidthAtLineEnd)) { AddRectangle(pixelSize, r); } }
protected override void OnRender(DrawingContext drawingContext) { Size renderSize = this.RenderSize; var theme = themeManager.Theme; var bgColor = (theme.GetColor(ColorType.IconBar).Background as SolidColorBrush).Color; drawingContext.DrawRectangle(theme.GetColor(ColorType.IconBar).Background, null, new Rect(0, 0, renderSize.Width, renderSize.Height)); drawingContext.DrawLine(new Pen(theme.GetColor(ColorType.IconBarBorder).Background, 1), new Point(renderSize.Width - 0.5, 0), new Point(renderSize.Width - 0.5, renderSize.Height)); TextView textView = this.TextView; if (textView != null && textView.VisualLinesValid) { // create a dictionary line number => first bookmark Dictionary <int, List <IIconBarObject> > bookmarkDict = new Dictionary <int, List <IIconBarObject> >(); foreach (var obj in textLineObjectManager.GetObjectsOfType <IIconBarObject>()) { if (!obj.IsVisible(uiContext)) { continue; } int line = obj.GetLineNumber(uiContext); List <IIconBarObject> list; if (!bookmarkDict.TryGetValue(line, out list)) { bookmarkDict[line] = list = new List <IIconBarObject>(); } list.Add(obj); } const double imagePadding = 1.0; Size pixelSize = PixelSnapHelpers.GetPixelSize(this); foreach (VisualLine line in textView.VisualLines) { int lineNumber = line.FirstDocumentLine.LineNumber; List <IIconBarObject> list; if (!bookmarkDict.TryGetValue(lineNumber, out list)) { continue; } list.Sort((a, b) => a.ZOrder.CompareTo(b.ZOrder)); foreach (var bm in list) { Rect rect = new Rect(imagePadding, PixelSnapHelpers.Round(line.VisualTop - textView.VerticalOffset, pixelSize.Height), 16, 16); var imgRef = bm.ImageReference; if (imgRef != null) { drawingContext.DrawImage(imageManager.GetImage(imgRef.Value.Assembly, imgRef.Value.Name, bgColor), rect); } } } } }
/// <inheritdoc/> protected override Size MeasureOverride(Size availableSize) { foreach (FoldingMarginMarker m in markers) { m.Measure(availableSize); } double width = SizeFactor * (double)GetValue(TextBlock.FontSizeProperty); return(new Size(PixelSnapHelpers.RoundToOdd(width, PixelSnapHelpers.GetPixelSize(this).Width), 0)); }
public void Draw(TextView textView, DrawingContext drawingContext) { double offset = textView.WideSpaceWidth * _column; Size pixelSize = PixelSnapHelpers.GetPixelSize(textView); double markerXPos = PixelSnapHelpers.PixelAlign(offset, pixelSize.Width); markerXPos -= textView.ScrollOffset.X; Point start = new Point(markerXPos, 0); Point end = new Point(markerXPos, Math.Max(textView.DocumentHeight, textView.Bounds.Height)); drawingContext.DrawLine(_pen, start, end); }
protected override void OnRender(DrawingContext drawingContext) { Size renderSize = this.RenderSize; drawingContext.DrawRectangle(SystemColors.ControlBrush, null, new Rect(0, 0, renderSize.Width, renderSize.Height)); drawingContext.DrawLine(new Pen(SystemColors.ControlDarkBrush, 1), new Point(renderSize.Width - 0.5, 0), new Point(renderSize.Width - 0.5, renderSize.Height)); TextView textView = this.TextView; if (textView != null && textView.VisualLinesValid) { // create a dictionary line number => first bookmark Dictionary <int, IBookmark> bookmarkDict = new Dictionary <int, IBookmark>(); foreach (IBookmark bm in manager.Bookmarks) { int line = bm.LineNumber; IBookmark existingBookmark; if (!bookmarkDict.TryGetValue(line, out existingBookmark) || bm.ZOrder > existingBookmark.ZOrder) { bookmarkDict[line] = bm; } } Size pixelSize = PixelSnapHelpers.GetPixelSize(this); foreach (VisualLine line in textView.VisualLines) { int lineNumber = line.FirstDocumentLine.LineNumber; IBookmark bm; if (bookmarkDict.TryGetValue(lineNumber, out bm)) { double lineMiddle = line.GetTextLineVisualYPosition(line.TextLines[0], VisualYPosition.TextMiddle) - textView.VerticalOffset; Rect rect = new Rect(0, PixelSnapHelpers.Round(lineMiddle - 8, pixelSize.Height), 16, 16); if (dragDropBookmark == bm && dragStarted) { drawingContext.PushOpacity(0.5); } drawingContext.DrawImage((bm.Image ?? DefaultBookmarkImage), rect); if (dragDropBookmark == bm && dragStarted) { drawingContext.Pop(); } } } if (dragDropBookmark != null && dragStarted) { Rect rect = new Rect(0, PixelSnapHelpers.Round(dragDropCurrentPoint - 8, pixelSize.Height), 16, 16); drawingContext.DrawImage((dragDropBookmark.Image ?? DefaultBookmarkImage), rect); } } }
protected override void OnRender(DrawingContext drawingContext) { Size renderSize = this.RenderSize; var theme = Themes.Theme; var bgColor = theme.GetColor(ColorType.IconBar).InheritedColor.Background.GetColor(null).Value; drawingContext.DrawRectangle(theme.GetColor(ColorType.IconBar).InheritedColor.Background.GetBrush(null), null, new Rect(0, 0, renderSize.Width, renderSize.Height)); drawingContext.DrawLine(new Pen(theme.GetColor(ColorType.IconBarBorder).InheritedColor.Background.GetBrush(null), 1), new Point(renderSize.Width - 0.5, 0), new Point(renderSize.Width - 0.5, renderSize.Height)); ICSharpCode.AvalonEdit.Rendering.TextView textView = this.TextView; if (textView != null && textView.VisualLinesValid) { // create a dictionary line number => first bookmark Dictionary <int, List <IIconBarObject> > bookmarkDict = new Dictionary <int, List <IIconBarObject> >(); foreach (var obj in TextLineObjectManager.Instance.GetObjectsOfType <IIconBarObject>()) { if (!obj.IsVisible(decompilerTextView)) { continue; } int line = obj.GetLineNumber(decompilerTextView); List <IIconBarObject> list; if (!bookmarkDict.TryGetValue(line, out list)) { bookmarkDict[line] = list = new List <IIconBarObject>(); } list.Add(obj); } const double imagePadding = 1.0; Size pixelSize = PixelSnapHelpers.GetPixelSize(this); foreach (VisualLine line in textView.VisualLines) { int lineNumber = line.FirstDocumentLine.LineNumber; List <IIconBarObject> list; if (!bookmarkDict.TryGetValue(lineNumber, out list)) { continue; } list.Sort((a, b) => a.ZOrder.CompareTo(b.ZOrder)); foreach (var bm in list) { Rect rect = new Rect(imagePadding, PixelSnapHelpers.Round(line.VisualTop - textView.VerticalOffset, pixelSize.Height), 16, 16); drawingContext.DrawImage(bm.GetImage(bgColor), rect); } } } }
public void Draw(TextView textView, System.Windows.Media.DrawingContext drawingContext) { if (column < 1) { return; } double offset = textView.WideSpaceWidth * column; Size pixelSize = PixelSnapHelpers.GetPixelSize(textView); double markerXPos = PixelSnapHelpers.PixelAlign(offset, pixelSize.Width); Point start = new Point(markerXPos, 0); Point end = new Point(markerXPos, Math.Max(textView.DocumentHeight, textView.ActualHeight)); drawingContext.DrawLine(pen, start, end); }
/// <inheritdoc/> protected override Size ArrangeOverride(Size finalSize) { Size pixelSize = PixelSnapHelpers.GetPixelSize(this); foreach (FoldingMarginMarker m in markers) { int visualColumn = m.VisualLine.GetVisualColumn(m.FoldingSection.StartOffset - m.VisualLine.FirstDocumentLine.Offset); TextLine textLine = m.VisualLine.GetTextLine(visualColumn); double yPos = m.VisualLine.GetTextLineVisualYPosition(textLine, VisualYPosition.LineTop) - TextView.VerticalOffset; yPos += (textLine.Height - m.DesiredSize.Height) / 2; double xPos = (finalSize.Width - m.DesiredSize.Width) / 2; m.Arrange(new Rect(PixelSnapHelpers.Round(new Point(xPos, yPos), pixelSize), m.DesiredSize)); } return(base.ArrangeOverride(finalSize)); }
private void AddRectangle(Size pixelSize, Rect r) { if (AlignToWholePixels) { var halfBorder = 0.5 * BorderThickness; AddRectangle(PixelSnapHelpers.Round(r.X - halfBorder, pixelSize.Width) + halfBorder, PixelSnapHelpers.Round(r.Y - halfBorder, pixelSize.Height) + halfBorder, PixelSnapHelpers.Round(r.Right + halfBorder, pixelSize.Width) - halfBorder, PixelSnapHelpers.Round(r.Bottom + halfBorder, pixelSize.Height) - halfBorder); } else { AddRectangle(r.X, r.Y, r.Right, r.Bottom); } }
private void AddRectangle(Size pixelSize, Rect r) { if (AlignToWholePixels) { var halfBorder = 0.5 * BorderThickness; AddRectangle(PixelSnapHelpers.Round(r.X - halfBorder, pixelSize.Width) + halfBorder, PixelSnapHelpers.Round(r.Y - halfBorder, pixelSize.Height) + halfBorder, PixelSnapHelpers.Round(r.Right + halfBorder, pixelSize.Width) - halfBorder, PixelSnapHelpers.Round(r.Bottom + halfBorder, pixelSize.Height) - halfBorder); Debug.WriteLine($"{r} -> {new Rect(_lastLeft, _lastTop, _lastRight - _lastLeft, _lastBottom - _lastTop)}"); } else { AddRectangle(r.X, r.Y, r.Right, r.Bottom); } }
void AddRectangle(Size pixelSize, Rect r) { if (AlignToWholePixels) { double halfBorder = 0.5 * BorderThickness; AddRectangle(PixelSnapHelpers.Round(r.Left - halfBorder, pixelSize.Width) + halfBorder, PixelSnapHelpers.Round(r.Top - halfBorder, pixelSize.Height) + halfBorder, PixelSnapHelpers.Round(r.Right + halfBorder, pixelSize.Width) - halfBorder, PixelSnapHelpers.Round(r.Bottom + halfBorder, pixelSize.Height) - halfBorder); //Debug.WriteLine(r.ToString() + " -> " + new Rect(lastLeft, lastTop, lastRight-lastLeft, lastBottom-lastTop).ToString()); } else { AddRectangle(r.Left, r.Top, r.Right, r.Bottom); } }
void AddRectangle(Size pixelSize, Rect r) { if (AlignToWholePixels) { AddRectangle(PixelSnapHelpers.Round(r.Left, pixelSize.Width), PixelSnapHelpers.Round(r.Top + 1, pixelSize.Height), PixelSnapHelpers.Round(r.Right, pixelSize.Width), PixelSnapHelpers.Round(r.Bottom + 1, pixelSize.Height)); } else if (AlignToMiddleOfPixels) { AddRectangle(PixelSnapHelpers.PixelAlign(r.Left, pixelSize.Width), PixelSnapHelpers.PixelAlign(r.Top + 1, pixelSize.Height), PixelSnapHelpers.PixelAlign(r.Right, pixelSize.Width), PixelSnapHelpers.PixelAlign(r.Bottom + 1, pixelSize.Height)); } else { AddRectangle(r.Left, r.Top + 1, r.Right, r.Bottom + 1); } }
protected override void OnRender(DrawingContext drawingContext) { base.OnRender(drawingContext); if (isVisible && blink) { Brush caretBrush = this.CaretBrush; if (caretBrush == null) { caretBrush = (Brush)textView.GetValue(TextBlock.ForegroundProperty); } Rect r = new Rect(caretRectangle.X - textView.HorizontalOffset, caretRectangle.Y - textView.VerticalOffset, caretRectangle.Width, caretRectangle.Height); drawingContext.DrawRectangle(caretBrush, null, PixelSnapHelpers.Round(r, PixelSnapHelpers.GetPixelSize(this))); } }
protected override void OnRender(DrawingContext drawingContext) { Size renderSize = this.RenderSize; drawingContext.DrawRectangle(new SolidColorBrush(Colors.White), null, new Rect(0, 0, renderSize.Width, renderSize.Height)); if (manager != null) { TextView textView = this.TextView; if (textView != null && textView.VisualLinesValid) { // create a dictionary line number => first bookmark Dictionary <int, IBookmark> bookmarkDict = new Dictionary <int, IBookmark>(); foreach (IBookmark bm in manager.Bookmarks) { int line = bm.LineNumber; IBookmark existingBookmark; if (!bookmarkDict.TryGetValue(line, out existingBookmark)) { bookmarkDict.Add(line, bm); } } Size pixelSize = PixelSnapHelpers.GetPixelSize(this); foreach (VisualLine line in textView.VisualLines) { int lineNumber = line.FirstDocumentLine.LineNumber; IBookmark bm; if (bookmarkDict.TryGetValue(lineNumber, out bm)) { double lineMiddle = line.GetTextLineVisualYPosition(line.TextLines[0], VisualYPosition.TextMiddle) - textView.VerticalOffset; Rect rect = new Rect(0, PixelSnapHelpers.Round(lineMiddle - 8, pixelSize.Height), 16, 16); ImageSourceConverter isc = new ImageSourceConverter(); var img = isc.ConvertFrom("pack://siteoforigin:,,,/" + (bm.Image ?? BookmarkBase.DefaultBookmarkImage)) as ImageSource; drawingContext.DrawImage(img, rect); } } } } }
protected override void OnRender(DrawingContext drawingContext) { Size renderSize = this.RenderSize; drawingContext.DrawRectangle(SystemColors.ControlBrush, null, new Rect(0, 0, renderSize.Width, renderSize.Height)); drawingContext.DrawLine(new Pen(SystemColors.ControlDarkBrush, 1), new Point(renderSize.Width - 0.5, 0), new Point(renderSize.Width - 0.5, renderSize.Height)); TextView textView = this.TextView; if (textView != null && textView.VisualLinesValid) { Size pixelSize = PixelSnapHelpers.GetPixelSize(this); foreach (VisualLine line in textView.VisualLines) { int lineNumber = line.FirstDocumentLine.LineNumber; bool arr = lineNumber == currPC; bool bp = breakpoints.ContainsKey(lineNumber) ? breakpoints[lineNumber] : false; double lineMiddle = line.GetTextLineVisualYPosition(line.TextLines[0], VisualYPosition.TextMiddle) - textView.VerticalOffset; Rect rect = new Rect(0, PixelSnapHelpers.Round(lineMiddle - 8, pixelSize.Height), 16, 16); if (bp && arr) { drawingContext.DrawImage(img_Combined, rect); } else if (bp) { drawingContext.DrawImage(img_Breakpoint, rect); } else if (arr) { drawingContext.DrawImage(img_Arrow, rect); } } } }
/// <summary> /// Draws the lines for the folding sections (vertical line with 'color', horizontal lines with 'endMarker') /// Each entry in the input arrays corresponds to one TextLine. /// </summary> void DrawFoldLines(DrawingContext drawingContext, Pen[] colors, Pen[] endMarker) { // Because we are using PenLineCap.Flat (the default), for vertical lines, // Y coordinates must be on pixel boundaries, whereas the X coordinate must be in the // middle of a pixel. (and the other way round for horizontal lines) Size pixelSize = PixelSnapHelpers.GetPixelSize(this); double markerXPos = PixelSnapHelpers.PixelAlign(RenderSize.Width / 2, pixelSize.Width); double startY = 0; Pen currentPen = colors[0]; int tlNumber = 0; foreach (VisualLine vl in TextView.VisualLines) { foreach (TextLine tl in vl.TextLines) { if (endMarker[tlNumber] != null) { double visualPos = GetVisualPos(vl, tl, pixelSize.Height); drawingContext.DrawLine(endMarker[tlNumber], new Point(markerXPos - pixelSize.Width / 2, visualPos), new Point(RenderSize.Width, visualPos)); } if (colors[tlNumber + 1] != currentPen) { double visualPos = GetVisualPos(vl, tl, pixelSize.Height); if (currentPen != null) { drawingContext.DrawLine(currentPen, new Point(markerXPos, startY + pixelSize.Height / 2), new Point(markerXPos, visualPos - pixelSize.Height / 2)); } currentPen = colors[tlNumber + 1]; startY = visualPos; } tlNumber++; } } if (currentPen != null) { drawingContext.DrawLine(currentPen, new Point(markerXPos, startY + pixelSize.Height / 2), new Point(markerXPos, RenderSize.Height)); } }