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)); } } }
public void GetVisualsAt_Should_Not_Find_Invisible_Controls_At_Point() { using (var application = UnitTestApplication.Start(new TestServices(renderInterface: new MockRenderInterface()))) { var container = new Decorator { Width = 200, Height = 200, Child = new Border { Width = 100, Height = 100, HorizontalAlignment = HorizontalAlignment.Center, VerticalAlignment = VerticalAlignment.Center, IsVisible = false, Child = new Border { HorizontalAlignment = HorizontalAlignment.Stretch, VerticalAlignment = VerticalAlignment.Stretch, } } }; container.Measure(Size.Infinity); container.Arrange(new Rect(container.DesiredSize)); var context = new DrawingContext(Mock.Of<IDrawingContextImpl>()); context.Render(container); var result = container.GetVisualsAt(new Point(100, 100)); Assert.Equal(new[] { container }, result); } }
protected internal override void OnRender(DrawingContext drawingContext) { Pen pen = (this.Stroke != null) ? new Pen(this.Stroke, this.StrokeThickness) : null; Rect shapeBounds = this.RenderedGeometry.GetRenderBounds(pen); Matrix matrix = Matrix.Identity; if (this.Stretch != Stretch.None) { double scaleX = this.ActualWidth / shapeBounds.Width; double scaleY = this.ActualHeight / shapeBounds.Height; switch (this.Stretch) { case Stretch.Uniform: scaleX = scaleY = Math.Min(scaleX, scaleY); break; case Stretch.UniformToFill: // Hmm, in WPF appears to be the same as Uniform. This can't be right... scaleX = scaleY = Math.Min(scaleX, scaleY); break; } matrix.Translate(-shapeBounds.X, -shapeBounds.Y); matrix.Scale(scaleX, scaleY); matrix.Translate( (this.ActualWidth - (shapeBounds.Width * scaleX)) / 2, (this.ActualHeight - (shapeBounds.Height * scaleY)) / 2); } drawingContext.DrawGeometry(this.Fill, pen, this.RenderedGeometry, matrix); }
private void DrawGridInternal(AM.DrawingContext dc, AM.Pen stroke, ref Rect2 rect, double offsetX, double offsetY, double cellWidth, double cellHeight, bool isStroked) { double ox = rect.X; double oy = rect.Y; double sx = ox + offsetX; double sy = oy + offsetY; double ex = ox + rect.Width; double ey = oy + rect.Height; for (double x = sx; x < ex; x += cellWidth) { var p0 = new A.Point( _scaleToPage(x), _scaleToPage(oy)); var p1 = new A.Point( _scaleToPage(x), _scaleToPage(ey)); DrawLineInternal(dc, stroke, isStroked, ref p0, ref p1); } for (double y = sy; y < ey; y += cellHeight) { var p0 = new A.Point( _scaleToPage(ox), _scaleToPage(y)); var p1 = new A.Point( _scaleToPage(ex), _scaleToPage(y)); DrawLineInternal(dc, stroke, isStroked, ref p0, ref p1); } }
private void Highlight(DrawingContext drawingContext, IEnumerable<Rect> rects) { foreach (var rect in rects) { drawingContext.FillRectangle(bracketHighlightBrush, rect); } }
public void TransformLine(TextView textView, DrawingContext drawingContext, VisualLine line) { if (!string.IsNullOrEmpty(SelectedWord) && line.RenderedText.Text.Contains(SelectedWord)) { var startIndex = 0; while (startIndex != -1) { startIndex = line.RenderedText.Text.IndexOf(SelectedWord, startIndex); if (startIndex != -1) { var rect = VisualLineGeometryBuilder.GetRectsForSegment(textView, new TextSegment { StartOffset = startIndex + line.Offset, EndOffset = startIndex + line.Offset + SelectedWord.Length }).First(); drawingContext.FillRectangle(highlightBrush, rect); startIndex += SelectedWord.Length; } } } }
public void InputHitTest_Should_Not_Find_Control_Outside_Point() { using (UnitTestApplication.Start(new TestServices(renderInterface: new MockRenderInterface()))) { var container = new Decorator { Width = 200, Height = 200, Child = new Border { Width = 100, Height = 100, HorizontalAlignment = HorizontalAlignment.Center, VerticalAlignment = VerticalAlignment.Center } }; container.Measure(Size.Infinity); container.Arrange(new Rect(container.DesiredSize)); var context = new DrawingContext(Mock.Of<IDrawingContextImpl>()); context.Render(container); var result = container.InputHitTest(new Point(10, 10)); Assert.Equal(container, result); } }
public RenderContext(IScene scene, AM.DrawingContext drawingContext) { Guard.Against.Null(scene, nameof(scene)); Guard.Against.Null(drawingContext, nameof(drawingContext)); m_Scene = scene; m_Context = drawingContext; }
public void Render(DrawingContext drawingContext, DependencyObject o) { Visual visual = o as Visual; UIElement uiElement = o as UIElement; int popCount = 0; if (uiElement != null) { TranslateTransform translate = new TranslateTransform(uiElement.VisualOffset); drawingContext.PushTransform(translate); ++popCount; if (uiElement.Opacity != 1) { drawingContext.PushOpacity(uiElement.Opacity); ++popCount; } uiElement.OnRender(drawingContext); } if (visual != null) { for (int i = 0; i < visual.VisualChildrenCount; ++i) { this.Render(drawingContext, visual.GetVisualChild(i)); } } for (int i = 0; i < popCount; ++i) { drawingContext.Pop(); } }
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); } }
private void DrawLineArrowsInternal(AM.DrawingContext dc, LineShape line, double dx, double dy, out A.Point pt1, out A.Point pt2) { AM.IBrush fillStartArrow = ToBrush(line.Style.StartArrowStyle.Fill); AM.Pen strokeStartArrow = ToPen(line.Style.StartArrowStyle, _scaleToPage); AM.IBrush fillEndArrow = ToBrush(line.Style.EndArrowStyle.Fill); AM.Pen strokeEndArrow = ToPen(line.Style.EndArrowStyle, _scaleToPage); double _x1 = line.Start.X + dx; double _y1 = line.Start.Y + dy; double _x2 = line.End.X + dx; double _y2 = line.End.Y + dy; line.GetMaxLength(ref _x1, ref _y1, ref _x2, ref _y2); float x1 = _scaleToPage(_x1); float y1 = _scaleToPage(_y1); float x2 = _scaleToPage(_x2); float y2 = _scaleToPage(_y2); var sas = line.Style.StartArrowStyle; var eas = line.Style.EndArrowStyle; double a1 = Math.Atan2(y1 - y2, x1 - x2); double a2 = Math.Atan2(y2 - y1, x2 - x1); // Draw start arrow. pt1 = DrawLineArrowInternal(dc, strokeStartArrow, fillStartArrow, x1, y1, a1, sas); // Draw end arrow. pt2 = DrawLineArrowInternal(dc, strokeEndArrow, fillEndArrow, x2, y2, a2, eas); }
public void Should_Track_Bounds() { using (UnitTestApplication.Start(TestServices.StyledWindow)) { var target = new BoundsTracker(); var control = default(Rectangle); var tree = new Decorator { Padding = new Thickness(10), Child = new Decorator { Padding = new Thickness(5), Child = control = new Rectangle { Width = 15, Height = 15, }, } }; var context = new DrawingContext(Mock.Of<IDrawingContextImpl>()); tree.Measure(Size.Infinity); tree.Arrange(new Rect(0, 0, 100, 100)); context.Render(tree); var track = target.Track(control); var results = new List<TransformedBounds?>(); track.Subscribe(results.Add); Assert.Equal(new Rect(0, 0, 15, 15), results[0].Value.Bounds); Assert.Equal(Matrix.CreateTranslation(42, 42), results[0].Value.Transform); } }
/// <summary> /// Init. /// </summary> /// <param name="g">the Avalonia graphics object to use</param> /// <param name="initialClip">the initial clip of the graphics</param> /// <param name="releaseGraphics">optional: if to release the graphics object on dispose (default - false)</param> public GraphicsAdapter(DrawingContext g, RRect initialClip, bool releaseGraphics = false) : base(AvaloniaAdapter.Instance, initialClip) { ArgChecker.AssertArgNotNull(g, "g"); _g = g; _releaseGraphics = releaseGraphics; }
public override void Render(DrawingContext context) { base.Render(context); if (SpiroEditor != null && SpiroEditor.Drawing != null) { if (SpiroEditor.Drawing.Guides != null && SpiroEditor.State.DisplayGuides) { DrawGuides(context); } var state = SpiroEditor.State; if (SpiroEditor.State.DisplayGuides && (state.Tool == EditorTool.Guide || state.Tool == EditorTool.Spiro)) { if ((state.Tool == EditorTool.Spiro && state.EnableSnap) || (state.Tool == EditorTool.Guide && state.IsCaptured) || (state.Tool == EditorTool.Guide && state.HaveSnapPoint)) { DrawHorizontalGuide(context, FromCache(state.HaveSnapPoint ? _snapGuideStyle : _guideStyle), state.GuidePosition, SpiroEditor.Drawing.Width); DrawVerticalGuide(context, FromCache(state.HaveSnapPoint ? _snapGuideStyle : _guideStyle), state.GuidePosition, SpiroEditor.Drawing.Height); } if (state.Tool == EditorTool.Guide && state.HaveSnapPoint) { DrawGuidePoint( context, FromCache(_snapPointStyle), SpiroEditor.State.SnapPoint, SpiroEditor.State.SnapPointRadius); } if (state.Tool == EditorTool.Guide && state.IsCaptured) { DrawGuideLine( context, FromCache(_newLineStyle), SpiroEditor.Measure.Point0, SpiroEditor.Measure.Point1); } } if (SpiroEditor.Drawing.Shapes != null) { DrawSpiroShapes(context); } } }
/// <summary> /// Renders the visual to a <see cref="DrawingContext"/>. /// </summary> /// <param name="context">The drawing context.</param> public override void Render(DrawingContext context) { var background = Background; if (background != null) { var renderSize = Bounds.Size; context.FillRectangle(background, new Rect(renderSize)); } base.Render(context); }
protected internal override void OnRender(DrawingContext drawingContext) { BitmapSource source = this.Source as BitmapSource; if (source != null) { Rect sourceRect = new Rect(0, 0, source.PixelWidth, source.PixelHeight); Rect destRect = new Rect(this.RenderSize); switch (this.Stretch) { case Stretch.None: sourceRect = new Rect( 0, 0, Math.Min(this.ActualWidth, source.PixelWidth), Math.Min(this.ActualHeight, source.PixelHeight)); break; case Stretch.Uniform: { double scale = Math.Min( this.DesiredSize.Width / source.PixelWidth, this.DesiredSize.Height / source.PixelHeight); double scaledWidth = source.PixelWidth * scale; double scaledHeight = source.PixelHeight * scale; destRect = new Rect( (this.ActualWidth - scaledWidth) / 2, (this.ActualHeight - scaledHeight) / 2, scaledWidth, scaledHeight); break; } case Stretch.UniformToFill: { double scale = Math.Max( this.DesiredSize.Width / source.PixelWidth, this.DesiredSize.Height / source.PixelHeight); sourceRect = new Rect( 0, 0, this.ActualWidth / scale, this.ActualHeight / scale); break; } } drawingContext.DrawImage(source, 1, sourceRect, destRect); } }
private static void DrawEllipseInternal(AM.DrawingContext dc, AM.IBrush brush, AM.Pen pen, bool isStroked, bool isFilled, ref Rect2 rect) { if (!isFilled && !isStroked) { return; } var r = new A.Rect(rect.X, rect.Y, rect.Width, rect.Height); var g = new AM.EllipseGeometry(r); dc.DrawGeometry( isFilled ? brush : null, isStroked ? pen : null, g); }
public void Draw(TextView textView, DrawingContext drawingContext) { if (line > 0 && line < textView.TextDocument.LineCount) { var currentLine = textView.TextDocument.GetLineByNumber(line); var rects = VisualLineGeometryBuilder.GetRectsForSegment(textView, currentLine); foreach (var rect in rects) { var drawRect = new Rect(rect.TopLeft.X, rect.TopLeft.Y, textView.Bounds.Width, rect.Height); drawingContext.FillRectangle(selectedLineBg, drawRect); } } }
/// <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); } }
public void Draw(TextView textView, DrawingContext drawingContext) { if (textView.SelectionStart == textView.SelectionEnd && textView.CaretIndex != -1 && textView.CaretIndex <= textView.TextDocument.TextLength) { var currentLine = textView.TextDocument.GetLineByOffset(textView.CaretIndex); var rects = VisualLineGeometryBuilder.GetRectsForSegment(textView, currentLine); foreach (var rect in rects) { var drawRect = new Rect(rect.TopLeft.X, rect.TopLeft.Y, textView.Bounds.Width, rect.Height); drawingContext.FillRectangle(selectedLineBg, drawRect); } } }
public void Draw(AM.DrawingContext context) { if (_commands == null) { return; } using var transformContainerState = context.PushTransformContainer(); var pushedStates = new Stack <Stack <IDisposable> >(); foreach (var command in _commands) { Draw(context, command, pushedStates); } }
/// <summary> /// Renders the control. /// </summary> /// <param name="context">The drawing context.</param> public override void Render(DrawingContext context) { var background = Background; var borderBrush = BorderBrush; var borderThickness = BorderThickness; var cornerRadius = CornerRadius; var rect = new Rect(Bounds.Size).Deflate(BorderThickness); if (background != null) { context.FillRectangle(background, rect, cornerRadius); } if (borderBrush != null && borderThickness > 0) { context.DrawRectangle(new Pen(borderBrush, borderThickness), rect, cornerRadius); } }
public void Draw(TextView textView, DrawingContext drawingContext) { if (textView.CaretIndex != -1) { var caretChar = '\0'; var behindCaretChar = '\0'; if (textView.CaretIndex < textView.TextDocument.TextLength) { caretChar = textView.TextDocument.GetCharAt(textView.CaretIndex); } if (textView.CaretIndex - 1 > 0 && textView.CaretIndex < textView.TextDocument.TextLength) { behindCaretChar = textView.TextDocument.GetCharAt(textView.CaretIndex - 1); } if (caretChar.IsOpenBracketChar() && !caretChar.IsPunctuationChar()) { var closeOffset = textView.FindMatchingBracketForward(textView.CaretIndex, caretChar, caretChar.GetCloseBracketChar()); Highlight(drawingContext, VisualLineGeometryBuilder.GetRectsForSegment(textView, new TextSegment {StartOffset = textView.CaretIndex, EndOffset = textView.CaretIndex + 1})); Highlight(drawingContext, VisualLineGeometryBuilder.GetRectsForSegment(textView, new TextSegment {StartOffset = closeOffset, EndOffset = closeOffset + 1})); } if (behindCaretChar.IsCloseBracketChar() && !behindCaretChar.IsPunctuationChar()) { var openOffset = textView.FindMatchingBracketBackward(textView.CaretIndex - 1, behindCaretChar, behindCaretChar.GetOpenBracketChar()); Highlight(drawingContext, VisualLineGeometryBuilder.GetRectsForSegment(textView, new TextSegment {StartOffset = textView.CaretIndex - 1, EndOffset = textView.CaretIndex})); Highlight(drawingContext, VisualLineGeometryBuilder.GetRectsForSegment(textView, new TextSegment {StartOffset = openOffset, EndOffset = openOffset + 1})); } } }
public void TransformLine(TextView textView, DrawingContext drawingContext, VisualLine line) { if (markers == null) { return; } var markersInLine = markers.FindOverlappingSegments(line); foreach (var marker in markersInLine) { if (marker.EndOffset < textView.TextDocument.TextLength) { foreach (var r in VisualLineGeometryBuilder.GetRectsForSegment(textView, marker)) { var startPoint = r.BottomLeft; var endPoint = r.BottomRight; var usedPen = new Pen(new SolidColorBrush(marker.MarkerColor), 1); const double offset = 2.5; var count = Math.Max((int) ((endPoint.X - startPoint.X)/offset) + 1, 4); var geometry = new StreamGeometry(); using (var ctx = geometry.Open()) { ctx.BeginFigure(startPoint, false); foreach (var point in CreatePoints(startPoint, endPoint, offset, count)) { ctx.LineTo(point); } ctx.EndFigure(false); } drawingContext.DrawGeometry(Brushes.Transparent, usedPen, geometry); break; } } } }
private static void DrawRectangleInternal(AM.DrawingContext dc, AM.IBrush brush, AM.Pen pen, bool isStroked, bool isFilled, ref Rect2 rect) { if (!isStroked && !isFilled) { return; } var r = new A.Rect(rect.X, rect.Y, rect.Width, rect.Height); if (isFilled) { dc.FillRectangle(brush, r); } if (isStroked) { dc.DrawRectangle(pen, r); } }
/// <summary> /// Renders the control. /// </summary> /// <param name="context">The drawing context.</param> public override void Render(DrawingContext context) { var source = Source; if (source != null) { Rect viewPort = new Rect(Bounds.Size); Size sourceSize = new Size(source.PixelWidth, source.PixelHeight); Vector scale = Stretch.CalculateScaling(Bounds.Size, sourceSize); Size scaledSize = sourceSize * scale; Rect destRect = viewPort .CenterIn(new Rect(scaledSize)) .Intersect(viewPort); Rect sourceRect = new Rect(sourceSize) .CenterIn(new Rect(destRect.Size / scale)); context.DrawImage(source, 1, sourceRect, destRect); } }
public override void Render(DrawingContext context) { var y = 0.0; for (var i = (int)_offset.Y; i < itemCount; ++i) { using (var line = new FormattedText( "Item " + (i + 1), TextBlock.GetFontFamily(this), TextBlock.GetFontSize(this), TextBlock.GetFontStyle(this), TextAlignment.Left, TextBlock.GetFontWeight(this))) { context.DrawText(Brushes.Black, new Point(-_offset.X, y), line); y += _lineSize.Height; } } }
/// <summary> /// Renders container control contents. /// </summary> /// <param name="context">The drawing context.</param> public override void Render(DrawingContext context) { base.Render(context); if (Container != null) { if (Renderer != null) { _presenter.Render(context, Renderer, Container, 0.0, 0.0); } else { var renderer = GetValue(RendererOptions.RendererProperty); if (renderer != null) { _presenter.Render(context, renderer, Container, 0.0, 0.0); } } } }
public override void Render(DrawingContext context, TextInfo textInfo) { if (textView.TextDocument != null) { Width = textInfo.CharWidth * textInfo.NumLines.ToString().Length + 12; if (textView != null && textView.VisualLines.Count > 0) { var firstLine = textView.VisualLines.First().DocumentLine.LineNumber; var lastLine = textView.VisualLines.Last().DocumentLine.LineNumber; DocumentLine currentLine = null; if (textView.SelectionStart == textView.SelectionEnd && textView.CaretIndex >= 0 && textView.CaretIndex <= textView.TextDocument.TextLength) { currentLine = textView.TextDocument.GetLineByOffset(textView.CaretIndex); } for (var i = 0; i < textInfo.NumLines && i + firstLine <= textView.TextDocument.LineCount && i + firstLine <= lastLine; i++) { using ( var formattedText = new FormattedText((i + firstLine).ToString(), "Consolas", textView.FontSize, FontStyle.Normal, TextAlignment.Right, FontWeight.Normal) { Constraint = new Size(Width, Bounds.Height) }) { IBrush textColor = foreground; if (currentLine != null) { if ((i + firstLine) == currentLine.LineNumber) { textColor = currentLineForeground; } } context.DrawText(textColor, new Point(-8, textInfo.LineHeight * i), formattedText); } } } } }
protected override void OnRender(DrawingContext ctx) { ctx.FillRectangle(Brushes.Green, new Rect(0, 0, Width, Height)); var rc = new Rect(0, 0, Width/3, Height/3); using (ctx.PushPostTransform( Avalonia.Matrix.CreateTranslation(-Width/6, -Width/6)* Avalonia.Matrix.CreateRotation(_radians)* Avalonia.Matrix.CreateTranslation(Width/2, Height/2))) { ctx.FillRectangle(new LinearGradientBrush() { GradientStops = { new GradientStop() {Color = Colors.Blue}, new GradientStop(Colors.Red, 1) } }, rc, 5); } }
private static void DrawLineCurveInternal(AM.DrawingContext _dc, AM.Pen pen, bool isStroked, ref A.Point pt1, ref A.Point pt2, double curvature, CurveOrientation orientation, PointAlignment pt1a, PointAlignment pt2a) { if (isStroked) { var sg = new AM.StreamGeometry(); using (var sgc = sg.Open()) { sgc.BeginFigure(new A.Point(pt1.X, pt1.Y), false); double p1x = pt1.X; double p1y = pt1.Y; double p2x = pt2.X; double p2y = pt2.Y; LineShapeExtensions.GetCurvedLineBezierControlPoints(orientation, curvature, pt1a, pt2a, ref p1x, ref p1y, ref p2x, ref p2y); sgc.CubicBezierTo( new A.Point(p1x, p1y), new A.Point(p2x, p2y), new A.Point(pt2.X, pt2.Y)); sgc.EndFigure(false); } _dc.DrawGeometry(null, pen, sg); } }
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; } }
/// <summary> /// Render the html using the given device. /// </summary> /// <param name="g">the device to use to render</param> /// <param name="clip">the clip rectangle of the html container</param> public void PerformPaint(DrawingContext g, Rect clip) { ArgChecker.AssertArgNotNull(g, "g"); using (var ig = new GraphicsAdapter(g, Util.Convert(clip))) { _htmlContainerInt.PerformPaint(ig); } }
/// <summary> /// Renders the visual to a <see cref="DrawingContext"/>. /// </summary> /// <param name="context">The drawing context.</param> public virtual void Render(DrawingContext context) { Contract.Requires<ArgumentNullException>(context != null); }
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 TransformLine(TextView textView, DrawingContext drawingContext, VisualLine line) { }
public override void Render(DrawingContext context) { Rendered = true; }
public AvaloniaDrawingContext(Avalonia.Media.DrawingContext avaloniaContext) { this.avaloniaContext = avaloniaContext; }
protected internal override void OnRender(DrawingContext drawingContext) { Rect rect = new Rect(new Size(this.ActualWidth, this.ActualHeight)); if (this.formattedText == null) { this.formattedText = this.CreateFormattedText(); } drawingContext.DrawRectangle( this.Background, null, rect); drawingContext.DrawText(this.formattedText, new Point()); }
/// <summary> /// Renders the <see cref="TextBlock"/> to a drawing context. /// </summary> /// <param name="context">The drawing context.</param> public override void Render(DrawingContext context) { var background = Background; if (background != null) { context.FillRectangle(background, new Rect(Bounds.Size)); } FormattedText.Constraint = Bounds.Size; context.DrawText(Foreground, new Point(), FormattedText); }
private static A.Point DrawLineArrowInternal(AM.DrawingContext dc, AM.Pen pen, AM.IBrush brush, float x, float y, double angle, ArrowStyle style) { A.Point pt = default(A.Point); var rt = APAZ.MatrixHelper.Rotation(angle, new A.Vector(x, y)); double rx = style.RadiusX; double ry = style.RadiusY; double sx = 2.0 * rx; double sy = 2.0 * ry; switch (style.ArrowType) { default: case ArrowType.None: { pt = new A.Point(x, y); } break; case ArrowType.Rectangle: { pt = APAZ.MatrixHelper.TransformPoint(rt, new A.Point(x - (float)sx, y)); var rect = new Rect2(x - sx, y - ry, sx, sy); using (var d = dc.PushPreTransform(rt)) { DrawRectangleInternal(dc, brush, pen, style.IsStroked, style.IsFilled, ref rect); } } break; case ArrowType.Ellipse: { pt = APAZ.MatrixHelper.TransformPoint(rt, new A.Point(x - (float)sx, y)); using (var d = dc.PushPreTransform(rt)) { var rect = new Rect2(x - sx, y - ry, sx, sy); DrawEllipseInternal(dc, brush, pen, style.IsStroked, style.IsFilled, ref rect); } } break; case ArrowType.Arrow: { var pts = new A.Point[] { new A.Point(x, y), new A.Point(x - (float)sx, y + (float)sy), new A.Point(x, y), new A.Point(x - (float)sx, y - (float)sy), new A.Point(x, y) }; pt = APAZ.MatrixHelper.TransformPoint(rt, pts[0]); var p11 = APAZ.MatrixHelper.TransformPoint(rt, pts[1]); var p21 = APAZ.MatrixHelper.TransformPoint(rt, pts[2]); var p12 = APAZ.MatrixHelper.TransformPoint(rt, pts[3]); var p22 = APAZ.MatrixHelper.TransformPoint(rt, pts[4]); DrawLineInternal(dc, pen, style.IsStroked, ref p11, ref p21); DrawLineInternal(dc, pen, style.IsStroked, ref p12, ref p22); } break; } return(pt); }