VisualBrushTests.cs 13 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452
  1. // Copyright (c) The Avalonia Project. All rights reserved.
  2. // Licensed under the MIT license. See licence.md file in the project root for full license information.
  3. using System.Threading.Tasks;
  4. using Avalonia.Controls;
  5. using Avalonia.Controls.Shapes;
  6. using Avalonia.Layout;
  7. using Avalonia.Media;
  8. using Avalonia.Media.Imaging;
  9. using Xunit;
  10. #if AVALONIA_SKIA
  11. namespace Avalonia.Skia.RenderTests
  12. #else
  13. namespace Avalonia.Direct2D1.RenderTests.Media
  14. #endif
  15. {
  16. public class VisualBrushTests : TestBase
  17. {
  18. public VisualBrushTests()
  19. : base(@"Media\VisualBrush")
  20. {
  21. }
  22. private string BitmapPath
  23. {
  24. get { return System.IO.Path.Combine(OutputPath, "github_icon.png"); }
  25. }
  26. private Control Visual
  27. {
  28. get
  29. {
  30. return new Panel
  31. {
  32. Children =
  33. {
  34. new Image
  35. {
  36. Source = new Bitmap(BitmapPath),
  37. },
  38. new Border
  39. {
  40. BorderBrush = Brushes.Blue,
  41. BorderThickness = new Thickness(2),
  42. HorizontalAlignment = HorizontalAlignment.Center,
  43. VerticalAlignment = VerticalAlignment.Center,
  44. Child = new TextBlock
  45. {
  46. FontSize = 24,
  47. FontFamily = new FontFamily("Arial"),
  48. Background = Brushes.Green,
  49. Foreground = Brushes.Yellow,
  50. Text = "VisualBrush",
  51. }
  52. }
  53. }
  54. };
  55. }
  56. }
  57. [Fact]
  58. public async Task VisualBrush_NoStretch_NoTile_Alignment_TopLeft()
  59. {
  60. Decorator target = new Decorator
  61. {
  62. Padding = new Thickness(8),
  63. Width = 200,
  64. Height = 200,
  65. Child = new Rectangle
  66. {
  67. Fill = new VisualBrush
  68. {
  69. Stretch = Stretch.None,
  70. TileMode = TileMode.None,
  71. AlignmentX = AlignmentX.Left,
  72. AlignmentY = AlignmentY.Top,
  73. Visual = Visual,
  74. }
  75. }
  76. };
  77. await RenderToFile(target);
  78. CompareImages();
  79. }
  80. #if AVALONIA_SKIA_SKIP_FAIL
  81. [Fact(Skip = "FIXME")]
  82. #else
  83. [Fact]
  84. #endif
  85. public async Task VisualBrush_NoStretch_NoTile_Alignment_Center()
  86. {
  87. Decorator target = new Decorator
  88. {
  89. Padding = new Thickness(8),
  90. Width = 200,
  91. Height = 200,
  92. Child = new Rectangle
  93. {
  94. Fill = new VisualBrush
  95. {
  96. Stretch = Stretch.None,
  97. TileMode = TileMode.None,
  98. AlignmentX = AlignmentX.Center,
  99. AlignmentY = AlignmentY.Center,
  100. Visual = Visual,
  101. }
  102. }
  103. };
  104. await RenderToFile(target);
  105. CompareImages();
  106. }
  107. [Fact]
  108. public async Task VisualBrush_NoStretch_NoTile_Alignment_BottomRight()
  109. {
  110. Decorator target = new Decorator
  111. {
  112. Padding = new Thickness(8),
  113. Width = 200,
  114. Height = 200,
  115. Child = new Rectangle
  116. {
  117. Fill = new VisualBrush
  118. {
  119. Stretch = Stretch.None,
  120. TileMode = TileMode.None,
  121. AlignmentX = AlignmentX.Right,
  122. AlignmentY = AlignmentY.Bottom,
  123. Visual = Visual,
  124. }
  125. }
  126. };
  127. await RenderToFile(target);
  128. CompareImages();
  129. }
  130. #if AVALONIA_SKIA_SKIP_FAIL
  131. [Fact(Skip = "FIXME")]
  132. #else
  133. [Fact]
  134. #endif
  135. public async Task VisualBrush_Fill_NoTile()
  136. {
  137. Decorator target = new Decorator
  138. {
  139. Padding = new Thickness(8),
  140. Width = 920,
  141. Height = 920,
  142. Child = new Rectangle
  143. {
  144. Fill = new VisualBrush
  145. {
  146. Stretch = Stretch.Fill,
  147. TileMode = TileMode.None,
  148. Visual = Visual,
  149. }
  150. }
  151. };
  152. await RenderToFile(target);
  153. CompareImages();
  154. }
  155. #if AVALONIA_SKIA_SKIP_FAIL
  156. [Fact(Skip = "FIXME")]
  157. #else
  158. [Fact]
  159. #endif
  160. public async Task VisualBrush_Uniform_NoTile()
  161. {
  162. Decorator target = new Decorator
  163. {
  164. Padding = new Thickness(8),
  165. Width = 300,
  166. Height = 200,
  167. Child = new Rectangle
  168. {
  169. Fill = new VisualBrush
  170. {
  171. Stretch = Stretch.Uniform,
  172. TileMode = TileMode.None,
  173. Visual = Visual,
  174. }
  175. }
  176. };
  177. await RenderToFile(target);
  178. CompareImages();
  179. }
  180. #if AVALONIA_SKIA_SKIP_FAIL
  181. [Fact(Skip = "FIXME")]
  182. #else
  183. [Fact]
  184. #endif
  185. public async Task VisualBrush_UniformToFill_NoTile()
  186. {
  187. Decorator target = new Decorator
  188. {
  189. Padding = new Thickness(8),
  190. Width = 300,
  191. Height = 200,
  192. Child = new Rectangle
  193. {
  194. Fill = new VisualBrush
  195. {
  196. Stretch = Stretch.UniformToFill,
  197. TileMode = TileMode.None,
  198. Visual = Visual,
  199. }
  200. }
  201. };
  202. await RenderToFile(target);
  203. CompareImages();
  204. }
  205. [Fact]
  206. public async Task VisualBrush_NoStretch_NoTile_BottomRightQuarterSource()
  207. {
  208. Decorator target = new Decorator
  209. {
  210. Padding = new Thickness(8),
  211. Width = 200,
  212. Height = 200,
  213. Child = new Rectangle
  214. {
  215. Fill = new VisualBrush
  216. {
  217. Stretch = Stretch.None,
  218. TileMode = TileMode.None,
  219. SourceRect = new RelativeRect(250, 250, 250, 250, RelativeUnit.Absolute),
  220. Visual = Visual,
  221. }
  222. }
  223. };
  224. await RenderToFile(target);
  225. CompareImages();
  226. }
  227. #if AVALONIA_SKIA_SKIP_FAIL
  228. [Fact(Skip = "FIXME")]
  229. #else
  230. [Fact]
  231. #endif
  232. public async Task VisualBrush_NoStretch_NoTile_BottomRightQuarterDest()
  233. {
  234. Decorator target = new Decorator
  235. {
  236. Padding = new Thickness(8),
  237. Width = 200,
  238. Height = 200,
  239. Child = new Rectangle
  240. {
  241. Fill = new VisualBrush
  242. {
  243. Stretch = Stretch.None,
  244. TileMode = TileMode.None,
  245. DestinationRect = new RelativeRect(92, 92, 92, 92, RelativeUnit.Absolute),
  246. Visual = Visual,
  247. }
  248. }
  249. };
  250. await RenderToFile(target);
  251. CompareImages();
  252. }
  253. [Fact]
  254. public async Task VisualBrush_NoStretch_NoTile_BottomRightQuarterSource_BottomRightQuarterDest()
  255. {
  256. Decorator target = new Decorator
  257. {
  258. Padding = new Thickness(8),
  259. Width = 200,
  260. Height = 200,
  261. Child = new Rectangle
  262. {
  263. Fill = new VisualBrush
  264. {
  265. Stretch = Stretch.None,
  266. TileMode = TileMode.None,
  267. SourceRect = new RelativeRect(0.5, 0.5, 0.5, 0.5, RelativeUnit.Relative),
  268. DestinationRect = new RelativeRect(0.5, 0.5, 0.5, 0.5, RelativeUnit.Relative),
  269. Visual = Visual,
  270. }
  271. }
  272. };
  273. await RenderToFile(target);
  274. CompareImages();
  275. }
  276. [Fact]
  277. public async Task VisualBrush_NoStretch_Tile_BottomRightQuarterSource_CenterQuarterDest()
  278. {
  279. Decorator target = new Decorator
  280. {
  281. Padding = new Thickness(8),
  282. Width = 200,
  283. Height = 200,
  284. Child = new Rectangle
  285. {
  286. Fill = new VisualBrush
  287. {
  288. Stretch = Stretch.None,
  289. TileMode = TileMode.Tile,
  290. SourceRect = new RelativeRect(0.5, 0.5, 0.5, 0.5, RelativeUnit.Relative),
  291. DestinationRect = new RelativeRect(0.25, 0.25, 0.5, 0.5, RelativeUnit.Relative),
  292. Visual = Visual,
  293. }
  294. }
  295. };
  296. await RenderToFile(target);
  297. CompareImages();
  298. }
  299. #if AVALONIA_SKIA_SKIP_FAIL
  300. [Fact(Skip = "FIXME")]
  301. #else
  302. [Fact]
  303. #endif
  304. public async Task VisualBrush_NoStretch_FlipX_TopLeftDest()
  305. {
  306. Decorator target = new Decorator
  307. {
  308. Padding = new Thickness(8),
  309. Width = 200,
  310. Height = 200,
  311. Child = new Rectangle
  312. {
  313. Fill = new VisualBrush
  314. {
  315. Stretch = Stretch.None,
  316. TileMode = TileMode.FlipX,
  317. DestinationRect = new RelativeRect(0, 0, 0.5, 0.5, RelativeUnit.Relative),
  318. Visual = Visual,
  319. }
  320. }
  321. };
  322. await RenderToFile(target);
  323. CompareImages();
  324. }
  325. #if AVALONIA_SKIA_SKIP_FAIL
  326. [Fact(Skip = "FIXME")]
  327. #else
  328. [Fact]
  329. #endif
  330. public async Task VisualBrush_NoStretch_FlipY_TopLeftDest()
  331. {
  332. Decorator target = new Decorator
  333. {
  334. Padding = new Thickness(8),
  335. Width = 200,
  336. Height = 200,
  337. Child = new Rectangle
  338. {
  339. Fill = new VisualBrush
  340. {
  341. Stretch = Stretch.None,
  342. TileMode = TileMode.FlipY,
  343. DestinationRect = new RelativeRect(0, 0, 0.5, 0.5, RelativeUnit.Relative),
  344. Visual = Visual,
  345. }
  346. }
  347. };
  348. await RenderToFile(target);
  349. CompareImages();
  350. }
  351. #if AVALONIA_SKIA_SKIP_FAIL
  352. [Fact(Skip = "FIXME")]
  353. #else
  354. [Fact]
  355. #endif
  356. public async Task VisualBrush_NoStretch_FlipXY_TopLeftDest()
  357. {
  358. Decorator target = new Decorator
  359. {
  360. Padding = new Thickness(8),
  361. Width = 200,
  362. Height = 200,
  363. Child = new Rectangle
  364. {
  365. Fill = new VisualBrush
  366. {
  367. Stretch = Stretch.None,
  368. TileMode = TileMode.FlipXY,
  369. DestinationRect = new RelativeRect(0, 0, 0.5, 0.5, RelativeUnit.Relative),
  370. Visual = Visual,
  371. }
  372. }
  373. };
  374. await RenderToFile(target);
  375. CompareImages();
  376. }
  377. #if AVALONIA_SKIA_SKIP_FAIL
  378. [Fact(Skip = "FIXME")]
  379. #else
  380. [Fact]
  381. #endif
  382. public async Task VisualBrush_InTree_Visual()
  383. {
  384. Border source;
  385. Decorator target = new Decorator
  386. {
  387. Padding = new Thickness(8),
  388. Width = 200,
  389. Height = 200,
  390. Child = new Grid
  391. {
  392. RowDefinitions = new RowDefinitions("Auto,*"),
  393. Children =
  394. {
  395. (source = new Border
  396. {
  397. Background = Brushes.Yellow,
  398. HorizontalAlignment = HorizontalAlignment.Left,
  399. Child = new TextBlock
  400. {
  401. Text = "Visual"
  402. }
  403. }),
  404. new Border
  405. {
  406. Background = new VisualBrush
  407. {
  408. Stretch = Stretch.Uniform,
  409. Visual = source,
  410. },
  411. [Grid.RowProperty] = 1,
  412. }
  413. }
  414. }
  415. };
  416. await RenderToFile(target);
  417. CompareImages();
  418. }
  419. }
  420. }