예제 #1
0
        public void Should_Track_Bounds()
        {
            using (UnitTestApplication.Start(TestServices.StyledWindow))
            {
                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));
                ImmediateRenderer.Render(tree, context);

                var track   = control.GetObservable(Visual.TransformedBoundsProperty);
                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);
            }
        }
예제 #2
0
        private void Render(IControl control)
        {
            var ctx = CreateDrawingContext();

            control.Measure(Size.Infinity);
            control.Arrange(new Rect(control.DesiredSize));
            ImmediateRenderer.Render(control, ctx);
        }
예제 #3
0
 public static void ToFile(string fileName, IEnumerable <IVisual> visuals)
 {
     using var doc = SKDocument.CreatePdf(fileName);
     foreach (var visual in visuals)
     {
         var bounds       = visual.Bounds;
         var page         = doc.BeginPage((float)bounds.Width, (float)bounds.Height);
         var renderTarget = SkiaRenderTarget.Create(page);
         ImmediateRenderer.Render(visual, renderTarget);
         doc.EndPage();
     }
     doc.Close();
 }
예제 #4
0
 public static void ToFile(string fileName, IEnumerable <IVisual> visuals)
 {
     using var doc = SKDocument.CreatePdf(fileName);
     foreach (var visual in visuals)
     {
         var bounds = visual.Bounds;
         var page   = doc.BeginPage((float)bounds.Width, (float)bounds.Height);
         using var context = new DrawingContext(DrawingContextHelper.WrapSkiaCanvas(page, SkiaPlatform.DefaultDpi));
         ImmediateRenderer.Render(visual, context);
         doc.EndPage();
     }
     doc.Close();
 }
        public void Static_Render_Method_Does_Not_Update_TransformedBounds()
        {
            using (UnitTestApplication.Start(TestServices.MockPlatformRenderInterface))
            {
                var target   = new Border();
                var expected = new TransformedBounds(new Rect(1, 2, 3, 4), new Rect(4, 5, 6, 7), Matrix.CreateRotation(0.8));

                ((IVisual)target).TransformedBounds = expected;

                var renderTarget = Mock.Of <IRenderTarget>(x =>
                                                           x.CreateDrawingContext(It.IsAny <IVisualBrushRenderer>()) == Mock.Of <IDrawingContextImpl>());
                ImmediateRenderer.Render(target, renderTarget);

                Assert.Equal(expected, target.TransformedBounds);
            }
        }
예제 #6
0
        public static void Render(Control target, SKCanvas canvas, double dpi = 96, bool useDeferredRenderer = false)
        {
            var renderTarget = new CanvasRenderTarget(canvas, dpi);

            if (useDeferredRenderer)
            {
                using var renderer = new DeferredRenderer(target, renderTarget);
                renderer.Start();
                var renderLoopTask = renderer as IRenderLoopTask;
                renderLoopTask.Update(TimeSpan.Zero);
                renderLoopTask.Render();
            }
            else
            {
                ImmediateRenderer.Render(target, renderTarget);
            }
        }
예제 #7
0
 /// <summary>
 /// Renders a visual to the <see cref="RenderTargetBitmap"/>.
 /// </summary>
 /// <param name="visual">The visual to render.</param>
 public void Render(IVisual visual) => ImmediateRenderer.Render(visual, this);