From 4cb1e66a56321a4fb5cc885de870e725ef5cde7a Mon Sep 17 00:00:00 2001 From: Steven Kirk Date: Fri, 4 Sep 2015 15:39:34 +0200 Subject: [PATCH] Added support for VisualBrush TileMode.Tile. --- .../Media/VisualBrushImpl.cs | 41 ++++++++++-------- .../Media/VisualBrushTests.cs | 38 ++++++++++++++++ .../VisualBrush/VisualBrush_Tile.expected.png | Bin 0 -> 1628 bytes 3 files changed, 62 insertions(+), 17 deletions(-) create mode 100644 tests/TestFiles/Direct2D1/Media/VisualBrush/VisualBrush_Tile.expected.png diff --git a/src/Windows/Perspex.Direct2D1/Media/VisualBrushImpl.cs b/src/Windows/Perspex.Direct2D1/Media/VisualBrushImpl.cs index d2467bbb86..41d63c2beb 100644 --- a/src/Windows/Perspex.Direct2D1/Media/VisualBrushImpl.cs +++ b/src/Windows/Perspex.Direct2D1/Media/VisualBrushImpl.cs @@ -29,7 +29,7 @@ namespace Perspex.Direct2D1.Media var sourceRect = brush.SourceRect.ToPixels(layoutable.Bounds.Size); var destinationRect = brush.DestinationRect.ToPixels(targetSize); - var bitmapSize = CalculateBitmapSize(brush.TileMode, destinationRect.Size, targetSize); + var bitmapSize = CalculateBitmapSize(brush.TileMode, sourceRect.Size, targetSize); var scale = brush.Stretch.CalculateScaling(destinationRect.Size, sourceRect.Size); var translate = CalculateTranslate(brush, sourceRect, destinationRect, scale); var options = CompatibleRenderTargetOptions.None; @@ -43,6 +43,8 @@ namespace Perspex.Direct2D1.Media renderer.Render(visual, null, transform, destinationRect); var result = new BitmapBrush(brt, brt.Bitmap); + result.ExtendModeX = ExtendMode.Wrap; + result.ExtendModeY = ExtendMode.Wrap; this.PlatformBrush = result; } } @@ -53,6 +55,8 @@ namespace Perspex.Direct2D1.Media { case TileMode.None: return targetSize; + case TileMode.Tile: + return size; default: throw new NotImplementedException(); } @@ -68,24 +72,27 @@ namespace Perspex.Direct2D1.Media var y = destinationRect.Y; var size = sourceRect.Size * scale; - switch (brush.AlignmentX) + if (brush.TileMode == TileMode.None) { - case AlignmentX.Center: - x += (destinationRect.Width - size.Width) / 2; - break; - case AlignmentX.Right: - x += destinationRect.Width - size.Width; - break; - } + switch (brush.AlignmentX) + { + case AlignmentX.Center: + x += (destinationRect.Width - size.Width) / 2; + break; + case AlignmentX.Right: + x += destinationRect.Width - size.Width; + break; + } - switch (brush.AlignmentY) - { - case AlignmentY.Center: - y += (destinationRect.Height - size.Height) / 2; - break; - case AlignmentY.Bottom: - y += destinationRect.Height - size.Height; - break; + switch (brush.AlignmentY) + { + case AlignmentY.Center: + y += (destinationRect.Height - size.Height) / 2; + break; + case AlignmentY.Bottom: + y += destinationRect.Height - size.Height; + break; + } } return new Vector(x, y); diff --git a/tests/Perspex.RenderTests/Media/VisualBrushTests.cs b/tests/Perspex.RenderTests/Media/VisualBrushTests.cs index 4d404cfefd..ac8c39f113 100644 --- a/tests/Perspex.RenderTests/Media/VisualBrushTests.cs +++ b/tests/Perspex.RenderTests/Media/VisualBrushTests.cs @@ -396,5 +396,43 @@ namespace Perspex.Direct2D1.RenderTests.Media this.RenderToFile(target); this.CompareImages(); } + + [Fact] + public void VisualBrush_Tile() + { + Decorator target = new Decorator + { + Padding = new Thickness(8), + Width = 200, + Height = 200, + Child = new Rectangle + { + Fill = new VisualBrush + { + Stretch = Stretch.None, + TileMode = TileMode.Tile, + Visual = new Border + { + Width = 92, + Height = 92, + Background = Brushes.Red, + BorderBrush = Brushes.Black, + BorderThickness = 2, + Child = new TextBlock + { + Text = "Perspex", + FontSize = 12, + FontFamily = "Arial", + HorizontalAlignment = HorizontalAlignment.Center, + VerticalAlignment = VerticalAlignment.Center, + } + } + } + } + }; + + this.RenderToFile(target); + this.CompareImages(); + } } } diff --git a/tests/TestFiles/Direct2D1/Media/VisualBrush/VisualBrush_Tile.expected.png b/tests/TestFiles/Direct2D1/Media/VisualBrush/VisualBrush_Tile.expected.png new file mode 100644 index 0000000000000000000000000000000000000000..ab0cf7e1d05de7a6f83c0007b3bf4098af64031d GIT binary patch literal 1628 zcmchX`BTyf7{uG?L_G9sibvolb28x;rm_P8bJwuPyI4IFMCITLrN5%_2$e{;S-P5N zL+h*Ygu}zE=2NnI0n;8vu_OT>M&j2_)E~CUQha-~pOS)iSvub4=ljpj5@o>%7`I7+ zC8Q6Cm}L((x8|}LBw*ZbBT)2KINd|85J!cPi+^5CLfLjR8vZ)ca9TekT9Y{Y<|iff zz&dPDdvPv~rIyi^O5r)!q=*`dv5)?|~QZkZy=}hRruQ!n1?wgrb(B^AQxBsU`vOLYY+yxMd z0qDXj1|Pa`1>$O7`UM~=uvevaC9sv>P^$jr^{ol=l03j34!CTWOBy(#&#PK=4pVg zJ<*vdB9L%pC2FoMaJ96$i0CiVQ<}xmxQQ)Nqxh@=+S+Pz7bpPLt`UBDx<4McoFm0q9wou^qu3Dw|(8n~bjA3zHd}9uQKc%$O&5 z8xg)hr$`??`mrab+1SYlJ}>*5e*U--)2;oGG$yey^Dd^{N^TVzdn)Mob$erusf$lK zC=8or0j@R`CV2I68gCT4n{xc^_sw`5>UHbE2~{mUpkb`-`EphM&uc%OagF@oInP9+coaesjl}-sE}6Coz3v!+fE| z$rie2x}@)iyN58L&$4PN)!PcU_u+kb`x(KZ_3{v|_{EDE3|CBk&KfotMYKdJns{f0 zSBd?iAj)G)pvx1zpe9*mK(Q$)!h$LVdZ%7$+$F|jzyxa<=a7D~#2UHc{@^R>wO8bu zl-gVm>zX3xl{Umwj_S8Z83|Dii>QCIR5KD>y7kI literal 0 HcmV?d00001