private static void DrawLineInternal(AM.DrawingContext dc, AM.Pen pen, bool isStroked, ref A.Point p0, ref A.Point p1) { if (isStroked) { dc.DrawLine(pen, p0, p1); } }
/// <summary> /// Renders the <see cref="AccessText"/> to a drawing context. /// </summary> /// <param name="context">The drawing context.</param> public override void Render(DrawingContext context) { base.Render(context); int underscore = Text?.IndexOf('_') ?? -1; if (underscore != -1 && ShowAccessKey) { var rect = FormattedText.HitTestTextPosition(underscore); var offset = new Vector(0, -0.5); context.DrawLine( new Pen(Foreground, 1), rect.BottomLeft + offset, rect.BottomRight + offset); } }
private void Draw(AM.DrawingContext context, DrawCommand command, Stack <Stack <IDisposable> > pushedStates) { switch (command) { case GeometryClipDrawCommand geometryClipDrawCommand: { var geometryPushedState = context.PushGeometryClip(geometryClipDrawCommand.Clip); var currentPushedStates = pushedStates.Peek(); currentPushedStates.Push(geometryPushedState); } break; case ClipDrawCommand clipDrawCommand: { var clipPushedState = context.PushClip(clipDrawCommand.Clip); var currentPushedStates = pushedStates.Peek(); currentPushedStates.Push(clipPushedState); } break; case SaveDrawCommand _: { pushedStates.Push(new Stack <IDisposable>()); } break; case RestoreDrawCommand _: { var currentPushedStates = pushedStates.Pop(); while (currentPushedStates.Count > 0) { var pushedState = currentPushedStates.Pop(); pushedState.Dispose(); } } break; case SetTransformDrawCommand setTransformDrawCommand: { var transformPreTransform = context.PushSetTransform(setTransformDrawCommand.Matrix); var currentPushedStates = pushedStates.Peek(); currentPushedStates.Push(transformPreTransform); } break; case SaveLayerDrawCommand saveLayerDrawCommand: { pushedStates.Push(new Stack <IDisposable>()); } break; case ImageDrawCommand imageDrawCommand: { context.DrawImage( imageDrawCommand.Source, imageDrawCommand.SourceRect, imageDrawCommand.DestRect, imageDrawCommand.BitmapInterpolationMode); } break; case GeometryDrawCommand geometryDrawCommand: { context.DrawGeometry( geometryDrawCommand.Brush, geometryDrawCommand.Pen, geometryDrawCommand.Geometry); } break; case LineDrawCommand lineDrawCommand: { context.DrawLine( lineDrawCommand.Pen, lineDrawCommand.P1, lineDrawCommand.P2); } break; case RectangleDrawCommand rectangleDrawCommand: { context.DrawRectangle( rectangleDrawCommand.Brush, rectangleDrawCommand.Pen, rectangleDrawCommand.Rect, rectangleDrawCommand.RadiusX, rectangleDrawCommand.RadiusY); } break; case TextDrawCommand textDrawCommand: { context.DrawText( textDrawCommand.Brush, textDrawCommand.Origin, textDrawCommand.FormattedText); } break; } }
public override void Render(DrawingContext context) { var selectionStart = SelectionStart; var selectionEnd = SelectionEnd; if (selectionStart != selectionEnd) { var start = Math.Min(selectionStart, selectionEnd); var length = Math.Max(selectionStart, selectionEnd) - start; // issue #600: set constaint before any FormattedText manipulation // see base.Render(...) implementation FormattedText.Constraint = Bounds.Size; var rects = FormattedText.HitTestTextRange(start, length); if (_highlightBrush == null) { _highlightBrush = (IBrush)this.FindStyleResource("HighlightBrush"); } foreach (var rect in rects) { context.FillRectangle(_highlightBrush, rect); } } base.Render(context); if (selectionStart == selectionEnd) { var backgroundColor = (((Control)TemplatedParent).GetValue(BackgroundProperty) as SolidColorBrush)?.Color; var caretBrush = Brushes.Black; if(backgroundColor.HasValue) { byte red = (byte)~(backgroundColor.Value.R); byte green = (byte)~(backgroundColor.Value.G); byte blue = (byte)~(backgroundColor.Value.B); caretBrush = new SolidColorBrush(Color.FromRgb(red, green, blue)); } if (_caretBlink) { var charPos = FormattedText.HitTestTextPosition(CaretIndex); var x = Math.Floor(charPos.X) + 0.5; var y = Math.Floor(charPos.Y) + 0.5; var b = Math.Ceiling(charPos.Bottom) - 0.5; context.DrawLine( new Pen(caretBrush, 1), new Point(x, y), new Point(x, b)); } } }
public void Draw(TextView textView, DrawingContext drawingContext) { var xPos = textView.TextSurfaceBounds.X + textView.CharSize.Width*120.0; drawingContext.DrawLine(new Pen(brush, 1), new Point(xPos, 0), new Point(xPos, textView.Bounds.Bottom)); }
private void DrawGuideLine(DrawingContext dc, BasicStyleCache cache, GuidePoint point0, GuidePoint point1) { dc.DrawLine(cache.StrokePen, new Point(point0.X, point0.Y), new Point(point1.X, point1.Y)); }
protected internal override void OnRender(DrawingContext drawingContext) { Rect rect = new Rect(new Size(this.ActualWidth, this.ActualHeight)); drawingContext.DrawText(this.FormattedText, new Point()); if (this.parent.IsKeyboardFocused) { Point caretPos = this.FormattedText.GetCaretPosition(this.parent.CaretIndex); Brush caretBrush = this.parent.CaretBrush; if (caretBrush == null) { Color color = Colors.Black; SolidColorBrush background = this.parent.Background as SolidColorBrush; if (background != null) { color = Color.FromUInt32(0x00ffffffu ^ background.Color.ToUint32()); } caretBrush = new SolidColorBrush(color); } if (this.caretBlink) { drawingContext.DrawLine( new Pen(caretBrush, 1), caretPos, caretPos + new Vector(0, this.FormattedText.Height)); } } }