From b2b50090ba86ff298e650e86295b40a58e849a8b Mon Sep 17 00:00:00 2001 From: Steven Kirk Date: Fri, 4 Sep 2015 11:22:27 +0200 Subject: [PATCH] Added clipping to VisualBrush.DestinationRect. --- .../Rendering/RendererBase.cs | 4 +- .../Media/VisualBrushImpl.cs | 2 +- .../Media/VisualBrushTests.cs | 38 ++++++++++++++++++ ...Rect_DestinationRect_Absolute.expected.png | Bin 0 -> 2031 bytes 4 files changed, 42 insertions(+), 2 deletions(-) create mode 100644 tests/TestFiles/Direct2D1/Media/VisualBrush/VisualBrush_SourceRect_DestinationRect_Absolute.expected.png diff --git a/src/Perspex.SceneGraph/Rendering/RendererBase.cs b/src/Perspex.SceneGraph/Rendering/RendererBase.cs index 2dce69e3d0..d5b593d5e0 100644 --- a/src/Perspex.SceneGraph/Rendering/RendererBase.cs +++ b/src/Perspex.SceneGraph/Rendering/RendererBase.cs @@ -43,9 +43,11 @@ namespace Perspex.Rendering /// The visual to render. /// An optional platform-specific handle. /// The transform. - public virtual void Render(IVisual visual, IPlatformHandle handle, Matrix transform) + /// An optional clip rectangle. + public virtual void Render(IVisual visual, IPlatformHandle handle, Matrix transform, Rect? clip = null) { using (var context = this.CreateDrawingContext(handle)) + using (clip.HasValue ? context.PushClip(clip.Value) : null) { this.Render(visual, context, Matrix.Identity, transform); } diff --git a/src/Windows/Perspex.Direct2D1/Media/VisualBrushImpl.cs b/src/Windows/Perspex.Direct2D1/Media/VisualBrushImpl.cs index a1a7520fb2..d2467bbb86 100644 --- a/src/Windows/Perspex.Direct2D1/Media/VisualBrushImpl.cs +++ b/src/Windows/Perspex.Direct2D1/Media/VisualBrushImpl.cs @@ -40,7 +40,7 @@ namespace Perspex.Direct2D1.Media var transform = Matrix.CreateTranslation(-sourceRect.Position) * Matrix.CreateScale(scale) * Matrix.CreateTranslation(translate); - renderer.Render(visual, null, transform); + renderer.Render(visual, null, transform, destinationRect); var result = new BitmapBrush(brt, brt.Bitmap); this.PlatformBrush = result; diff --git a/tests/Perspex.RenderTests/Media/VisualBrushTests.cs b/tests/Perspex.RenderTests/Media/VisualBrushTests.cs index 962ecf01a6..7d32014cc3 100644 --- a/tests/Perspex.RenderTests/Media/VisualBrushTests.cs +++ b/tests/Perspex.RenderTests/Media/VisualBrushTests.cs @@ -320,5 +320,43 @@ namespace Perspex.Direct2D1.RenderTests.Media this.RenderToFile(target); this.CompareImages(); } + + [Fact] + public void VisualBrush_SourceRect_DestinationRect_Absolute() + { + Decorator target = new Decorator + { + Padding = new Thickness(8), + Width = 200, + Height = 200, + Child = new Rectangle + { + Fill = new VisualBrush + { + SourceRect = new RelativeRect(40, 40, 100, 100, OriginUnit.Pixels), + 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_SourceRect_DestinationRect_Absolute.expected.png b/tests/TestFiles/Direct2D1/Media/VisualBrush/VisualBrush_SourceRect_DestinationRect_Absolute.expected.png new file mode 100644 index 0000000000000000000000000000000000000000..b2abed4041535e8c15d543fc4bca4951a4fccd9c GIT binary patch literal 2031 zcmcgtiCYrb7I$MP+$h(~94sk!eOfLF28!X9Yif#Hnp!TXnB#5(Hkg?}CWeJ8nU!0` zBwEgp=1PuD)=P6u6ro&Ehcwam$ob~|3GaU2z2|rD?=I)ubI!d5ULI&gkQPWvN=nhi z8Ra99ec$VzA0%z#xuyz#5Zje|L)sj0P?in2gy zi4Ono67FKr;yspMSYlpC^*Sky3T*rORZ6s-0# zGVW)Yz0scmT*645wvUoOe`gAplq{|a_HFX#yP0Z&?wPw8QC@M9c@K)~Az#Gx!Ty6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