diff --git a/src/Windows/Perspex.Direct2D1/Media/DrawingContext.cs b/src/Windows/Perspex.Direct2D1/Media/DrawingContext.cs index 1720591c57..22c79d0f72 100644 --- a/src/Windows/Perspex.Direct2D1/Media/DrawingContext.cs +++ b/src/Windows/Perspex.Direct2D1/Media/DrawingContext.cs @@ -8,7 +8,6 @@ namespace Perspex.Direct2D1.Media { using System; using System.Reactive.Disposables; - using Layout; using Perspex.Media; using SharpDX; using SharpDX.Direct2D1; diff --git a/src/Windows/Perspex.Direct2D1/Media/VisualBrushImpl.cs b/src/Windows/Perspex.Direct2D1/Media/VisualBrushImpl.cs index a17106b6b5..a1a7520fb2 100644 --- a/src/Windows/Perspex.Direct2D1/Media/VisualBrushImpl.cs +++ b/src/Windows/Perspex.Direct2D1/Media/VisualBrushImpl.cs @@ -16,8 +16,7 @@ namespace Perspex.Direct2D1.Media public VisualBrushImpl( Perspex.Media.VisualBrush brush, SharpDX.Direct2D1.RenderTarget target, - Size destinationSize) - : base(brush, target, destinationSize) + Size targetSize) { var visual = brush.Visual; var layoutable = visual as ILayoutable; @@ -29,21 +28,33 @@ namespace Perspex.Direct2D1.Media } var sourceRect = brush.SourceRect.ToPixels(layoutable.Bounds.Size); - var destinationRect = brush.DestinationRect.ToPixels(destinationSize); + var destinationRect = brush.DestinationRect.ToPixels(targetSize); + var bitmapSize = CalculateBitmapSize(brush.TileMode, destinationRect.Size, targetSize); var scale = brush.Stretch.CalculateScaling(destinationRect.Size, sourceRect.Size); var translate = CalculateTranslate(brush, sourceRect, destinationRect, scale); + var options = CompatibleRenderTargetOptions.None; - using (var brt = new BitmapRenderTarget( - target, - CompatibleRenderTargetOptions.None, - destinationRect.Size.ToSharpDX())) + using (var brt = new BitmapRenderTarget(target, options, bitmapSize.ToSharpDX())) { var renderer = new Renderer(brt); var transform = Matrix.CreateTranslation(-sourceRect.Position) * Matrix.CreateScale(scale) * Matrix.CreateTranslation(translate); renderer.Render(visual, null, transform); - this.PlatformBrush = new BitmapBrush(brt, brt.Bitmap); + + var result = new BitmapBrush(brt, brt.Bitmap); + this.PlatformBrush = result; + } + } + + private static Size CalculateBitmapSize(TileMode tileMode, Size size, Size targetSize) + { + switch (tileMode) + { + case TileMode.None: + return targetSize; + default: + throw new NotImplementedException(); } } @@ -53,8 +64,8 @@ namespace Perspex.Direct2D1.Media Rect destinationRect, Vector scale) { - var x = 0.0; - var y = 0.0; + var x = destinationRect.X; + var y = destinationRect.Y; var size = sourceRect.Size * scale; switch (brush.AlignmentX) diff --git a/tests/Perspex.RenderTests/Media/VisualBrushTests.cs b/tests/Perspex.RenderTests/Media/VisualBrushTests.cs index fc74160e74..962ecf01a6 100644 --- a/tests/Perspex.RenderTests/Media/VisualBrushTests.cs +++ b/tests/Perspex.RenderTests/Media/VisualBrushTests.cs @@ -283,5 +283,42 @@ namespace Perspex.Direct2D1.RenderTests.Media this.RenderToFile(target); this.CompareImages(); } + + [Fact] + public void VisualBrush_DestinationRect_Absolute() + { + Decorator target = new Decorator + { + Padding = new Thickness(8), + Width = 200, + Height = 200, + Child = new Rectangle + { + Fill = new VisualBrush + { + DestinationRect = new RelativeRect(92, 92, 92, 92, OriginUnit.Pixels), + Visual = new Border + { + Width = 180, + Height = 180, + Background = Brushes.Red, + BorderBrush = Brushes.Black, + BorderThickness = 2, + Child = new Ellipse + { + Width = 100, + Height = 100, + Fill = Brushes.Yellow, + VerticalAlignment = VerticalAlignment.Center, + HorizontalAlignment = HorizontalAlignment.Center, + } + } + } + } + }; + + this.RenderToFile(target); + this.CompareImages(); + } } } diff --git a/tests/TestFiles/Direct2D1/Media/VisualBrush/VisualBrush_DestinationRect_Absolute.expected.png b/tests/TestFiles/Direct2D1/Media/VisualBrush/VisualBrush_DestinationRect_Absolute.expected.png new file mode 100644 index 0000000000..9253eee164 Binary files /dev/null and b/tests/TestFiles/Direct2D1/Media/VisualBrush/VisualBrush_DestinationRect_Absolute.expected.png differ