| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452 |
- // Copyright (c) The Avalonia Project. All rights reserved.
- // Licensed under the MIT license. See licence.md file in the project root for full license information.
- using System.Threading.Tasks;
- using Avalonia.Controls;
- using Avalonia.Controls.Shapes;
- using Avalonia.Layout;
- using Avalonia.Media;
- using Avalonia.Media.Imaging;
- using Xunit;
- #if AVALONIA_SKIA
- namespace Avalonia.Skia.RenderTests
- #else
- namespace Avalonia.Direct2D1.RenderTests.Media
- #endif
- {
- public class VisualBrushTests : TestBase
- {
- public VisualBrushTests()
- : base(@"Media\VisualBrush")
- {
- }
- private string BitmapPath
- {
- get { return System.IO.Path.Combine(OutputPath, "github_icon.png"); }
- }
- private Control Visual
- {
- get
- {
- return new Panel
- {
- Children =
- {
- new Image
- {
- Source = new Bitmap(BitmapPath),
- },
- new Border
- {
- BorderBrush = Brushes.Blue,
- BorderThickness = new Thickness(2),
- HorizontalAlignment = HorizontalAlignment.Center,
- VerticalAlignment = VerticalAlignment.Center,
- Child = new TextBlock
- {
- FontSize = 24,
- FontFamily = new FontFamily("Arial"),
- Background = Brushes.Green,
- Foreground = Brushes.Yellow,
- Text = "VisualBrush",
- }
- }
- }
- };
- }
- }
- [Fact]
- public async Task VisualBrush_NoStretch_NoTile_Alignment_TopLeft()
- {
- Decorator target = new Decorator
- {
- Padding = new Thickness(8),
- Width = 200,
- Height = 200,
- Child = new Rectangle
- {
- Fill = new VisualBrush
- {
- Stretch = Stretch.None,
- TileMode = TileMode.None,
- AlignmentX = AlignmentX.Left,
- AlignmentY = AlignmentY.Top,
- Visual = Visual,
- }
- }
- };
- await RenderToFile(target);
- CompareImages();
- }
-
- #if AVALONIA_SKIA_SKIP_FAIL
- [Fact(Skip = "FIXME")]
- #else
- [Fact]
- #endif
- public async Task VisualBrush_NoStretch_NoTile_Alignment_Center()
- {
- Decorator target = new Decorator
- {
- Padding = new Thickness(8),
- Width = 200,
- Height = 200,
- Child = new Rectangle
- {
- Fill = new VisualBrush
- {
- Stretch = Stretch.None,
- TileMode = TileMode.None,
- AlignmentX = AlignmentX.Center,
- AlignmentY = AlignmentY.Center,
- Visual = Visual,
- }
- }
- };
- await RenderToFile(target);
- CompareImages();
- }
- [Fact]
- public async Task VisualBrush_NoStretch_NoTile_Alignment_BottomRight()
- {
- Decorator target = new Decorator
- {
- Padding = new Thickness(8),
- Width = 200,
- Height = 200,
- Child = new Rectangle
- {
- Fill = new VisualBrush
- {
- Stretch = Stretch.None,
- TileMode = TileMode.None,
- AlignmentX = AlignmentX.Right,
- AlignmentY = AlignmentY.Bottom,
- Visual = Visual,
- }
- }
- };
- await RenderToFile(target);
- CompareImages();
- }
- #if AVALONIA_SKIA_SKIP_FAIL
- [Fact(Skip = "FIXME")]
- #else
- [Fact]
- #endif
- public async Task VisualBrush_Fill_NoTile()
- {
- Decorator target = new Decorator
- {
- Padding = new Thickness(8),
- Width = 920,
- Height = 920,
- Child = new Rectangle
- {
- Fill = new VisualBrush
- {
- Stretch = Stretch.Fill,
- TileMode = TileMode.None,
- Visual = Visual,
- }
- }
- };
- await RenderToFile(target);
- CompareImages();
- }
- #if AVALONIA_SKIA_SKIP_FAIL
- [Fact(Skip = "FIXME")]
- #else
- [Fact]
- #endif
- public async Task VisualBrush_Uniform_NoTile()
- {
- Decorator target = new Decorator
- {
- Padding = new Thickness(8),
- Width = 300,
- Height = 200,
- Child = new Rectangle
- {
- Fill = new VisualBrush
- {
- Stretch = Stretch.Uniform,
- TileMode = TileMode.None,
- Visual = Visual,
- }
- }
- };
- await RenderToFile(target);
- CompareImages();
- }
- #if AVALONIA_SKIA_SKIP_FAIL
- [Fact(Skip = "FIXME")]
- #else
- [Fact]
- #endif
- public async Task VisualBrush_UniformToFill_NoTile()
- {
- Decorator target = new Decorator
- {
- Padding = new Thickness(8),
- Width = 300,
- Height = 200,
- Child = new Rectangle
- {
- Fill = new VisualBrush
- {
- Stretch = Stretch.UniformToFill,
- TileMode = TileMode.None,
- Visual = Visual,
- }
- }
- };
- await RenderToFile(target);
- CompareImages();
- }
- [Fact]
- public async Task VisualBrush_NoStretch_NoTile_BottomRightQuarterSource()
- {
- Decorator target = new Decorator
- {
- Padding = new Thickness(8),
- Width = 200,
- Height = 200,
- Child = new Rectangle
- {
- Fill = new VisualBrush
- {
- Stretch = Stretch.None,
- TileMode = TileMode.None,
- SourceRect = new RelativeRect(250, 250, 250, 250, RelativeUnit.Absolute),
- Visual = Visual,
- }
- }
- };
- await RenderToFile(target);
- CompareImages();
- }
- #if AVALONIA_SKIA_SKIP_FAIL
- [Fact(Skip = "FIXME")]
- #else
- [Fact]
- #endif
- public async Task VisualBrush_NoStretch_NoTile_BottomRightQuarterDest()
- {
- Decorator target = new Decorator
- {
- Padding = new Thickness(8),
- Width = 200,
- Height = 200,
- Child = new Rectangle
- {
- Fill = new VisualBrush
- {
- Stretch = Stretch.None,
- TileMode = TileMode.None,
- DestinationRect = new RelativeRect(92, 92, 92, 92, RelativeUnit.Absolute),
- Visual = Visual,
- }
- }
- };
- await RenderToFile(target);
- CompareImages();
- }
-
- [Fact]
- public async Task VisualBrush_NoStretch_NoTile_BottomRightQuarterSource_BottomRightQuarterDest()
- {
- Decorator target = new Decorator
- {
- Padding = new Thickness(8),
- Width = 200,
- Height = 200,
- Child = new Rectangle
- {
- Fill = new VisualBrush
- {
- Stretch = Stretch.None,
- TileMode = TileMode.None,
- SourceRect = new RelativeRect(0.5, 0.5, 0.5, 0.5, RelativeUnit.Relative),
- DestinationRect = new RelativeRect(0.5, 0.5, 0.5, 0.5, RelativeUnit.Relative),
- Visual = Visual,
- }
- }
- };
- await RenderToFile(target);
- CompareImages();
- }
- [Fact]
- public async Task VisualBrush_NoStretch_Tile_BottomRightQuarterSource_CenterQuarterDest()
- {
- Decorator target = new Decorator
- {
- Padding = new Thickness(8),
- Width = 200,
- Height = 200,
- Child = new Rectangle
- {
- Fill = new VisualBrush
- {
- Stretch = Stretch.None,
- TileMode = TileMode.Tile,
- SourceRect = new RelativeRect(0.5, 0.5, 0.5, 0.5, RelativeUnit.Relative),
- DestinationRect = new RelativeRect(0.25, 0.25, 0.5, 0.5, RelativeUnit.Relative),
- Visual = Visual,
- }
- }
- };
- await RenderToFile(target);
- CompareImages();
- }
- #if AVALONIA_SKIA_SKIP_FAIL
- [Fact(Skip = "FIXME")]
- #else
- [Fact]
- #endif
- public async Task VisualBrush_NoStretch_FlipX_TopLeftDest()
- {
- Decorator target = new Decorator
- {
- Padding = new Thickness(8),
- Width = 200,
- Height = 200,
- Child = new Rectangle
- {
- Fill = new VisualBrush
- {
- Stretch = Stretch.None,
- TileMode = TileMode.FlipX,
- DestinationRect = new RelativeRect(0, 0, 0.5, 0.5, RelativeUnit.Relative),
- Visual = Visual,
- }
- }
- };
- await RenderToFile(target);
- CompareImages();
- }
- #if AVALONIA_SKIA_SKIP_FAIL
- [Fact(Skip = "FIXME")]
- #else
- [Fact]
- #endif
- public async Task VisualBrush_NoStretch_FlipY_TopLeftDest()
- {
- Decorator target = new Decorator
- {
- Padding = new Thickness(8),
- Width = 200,
- Height = 200,
- Child = new Rectangle
- {
- Fill = new VisualBrush
- {
- Stretch = Stretch.None,
- TileMode = TileMode.FlipY,
- DestinationRect = new RelativeRect(0, 0, 0.5, 0.5, RelativeUnit.Relative),
- Visual = Visual,
- }
- }
- };
- await RenderToFile(target);
- CompareImages();
- }
- #if AVALONIA_SKIA_SKIP_FAIL
- [Fact(Skip = "FIXME")]
- #else
- [Fact]
- #endif
- public async Task VisualBrush_NoStretch_FlipXY_TopLeftDest()
- {
- Decorator target = new Decorator
- {
- Padding = new Thickness(8),
- Width = 200,
- Height = 200,
- Child = new Rectangle
- {
- Fill = new VisualBrush
- {
- Stretch = Stretch.None,
- TileMode = TileMode.FlipXY,
- DestinationRect = new RelativeRect(0, 0, 0.5, 0.5, RelativeUnit.Relative),
- Visual = Visual,
- }
- }
- };
- await RenderToFile(target);
- CompareImages();
- }
- #if AVALONIA_SKIA_SKIP_FAIL
- [Fact(Skip = "FIXME")]
- #else
- [Fact]
- #endif
- public async Task VisualBrush_InTree_Visual()
- {
- Border source;
- Decorator target = new Decorator
- {
- Padding = new Thickness(8),
- Width = 200,
- Height = 200,
- Child = new Grid
- {
- RowDefinitions = new RowDefinitions("Auto,*"),
- Children =
- {
- (source = new Border
- {
- Background = Brushes.Yellow,
- HorizontalAlignment = HorizontalAlignment.Left,
- Child = new TextBlock
- {
- Text = "Visual"
- }
- }),
- new Border
- {
- Background = new VisualBrush
- {
- Stretch = Stretch.Uniform,
- Visual = source,
- },
- [Grid.RowProperty] = 1,
- }
- }
- }
- };
- await RenderToFile(target);
- CompareImages();
- }
- }
- }
|