VisualBrushTests.cs 13 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456
  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 = "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. #if AVALONIA_SKIA_SKIP_FAIL
  254. [Fact(Skip = "FIXME")]
  255. #else
  256. [Fact]
  257. #endif
  258. public async Task VisualBrush_NoStretch_NoTile_BottomRightQuarterSource_BottomRightQuarterDest()
  259. {
  260. Decorator target = new Decorator
  261. {
  262. Padding = new Thickness(8),
  263. Width = 200,
  264. Height = 200,
  265. Child = new Rectangle
  266. {
  267. Fill = new VisualBrush
  268. {
  269. Stretch = Stretch.None,
  270. TileMode = TileMode.None,
  271. SourceRect = new RelativeRect(0.5, 0.5, 0.5, 0.5, RelativeUnit.Relative),
  272. DestinationRect = new RelativeRect(0.5, 0.5, 0.5, 0.5, RelativeUnit.Relative),
  273. Visual = Visual,
  274. }
  275. }
  276. };
  277. await RenderToFile(target);
  278. CompareImages();
  279. }
  280. [Fact]
  281. public async Task VisualBrush_NoStretch_Tile_BottomRightQuarterSource_CenterQuarterDest()
  282. {
  283. Decorator target = new Decorator
  284. {
  285. Padding = new Thickness(8),
  286. Width = 200,
  287. Height = 200,
  288. Child = new Rectangle
  289. {
  290. Fill = new VisualBrush
  291. {
  292. Stretch = Stretch.None,
  293. TileMode = TileMode.Tile,
  294. SourceRect = new RelativeRect(0.5, 0.5, 0.5, 0.5, RelativeUnit.Relative),
  295. DestinationRect = new RelativeRect(0.25, 0.25, 0.5, 0.5, RelativeUnit.Relative),
  296. Visual = Visual,
  297. }
  298. }
  299. };
  300. await RenderToFile(target);
  301. CompareImages();
  302. }
  303. #if AVALONIA_SKIA_SKIP_FAIL
  304. [Fact(Skip = "FIXME")]
  305. #else
  306. [Fact]
  307. #endif
  308. public async Task VisualBrush_NoStretch_FlipX_TopLeftDest()
  309. {
  310. Decorator target = new Decorator
  311. {
  312. Padding = new Thickness(8),
  313. Width = 200,
  314. Height = 200,
  315. Child = new Rectangle
  316. {
  317. Fill = new VisualBrush
  318. {
  319. Stretch = Stretch.None,
  320. TileMode = TileMode.FlipX,
  321. DestinationRect = new RelativeRect(0, 0, 0.5, 0.5, RelativeUnit.Relative),
  322. Visual = Visual,
  323. }
  324. }
  325. };
  326. await RenderToFile(target);
  327. CompareImages();
  328. }
  329. #if AVALONIA_SKIA_SKIP_FAIL
  330. [Fact(Skip = "FIXME")]
  331. #else
  332. [Fact]
  333. #endif
  334. public async Task VisualBrush_NoStretch_FlipY_TopLeftDest()
  335. {
  336. Decorator target = new Decorator
  337. {
  338. Padding = new Thickness(8),
  339. Width = 200,
  340. Height = 200,
  341. Child = new Rectangle
  342. {
  343. Fill = new VisualBrush
  344. {
  345. Stretch = Stretch.None,
  346. TileMode = TileMode.FlipY,
  347. DestinationRect = new RelativeRect(0, 0, 0.5, 0.5, RelativeUnit.Relative),
  348. Visual = Visual,
  349. }
  350. }
  351. };
  352. await RenderToFile(target);
  353. CompareImages();
  354. }
  355. #if AVALONIA_SKIA_SKIP_FAIL
  356. [Fact(Skip = "FIXME")]
  357. #else
  358. [Fact]
  359. #endif
  360. public async Task VisualBrush_NoStretch_FlipXY_TopLeftDest()
  361. {
  362. Decorator target = new Decorator
  363. {
  364. Padding = new Thickness(8),
  365. Width = 200,
  366. Height = 200,
  367. Child = new Rectangle
  368. {
  369. Fill = new VisualBrush
  370. {
  371. Stretch = Stretch.None,
  372. TileMode = TileMode.FlipXY,
  373. DestinationRect = new RelativeRect(0, 0, 0.5, 0.5, RelativeUnit.Relative),
  374. Visual = Visual,
  375. }
  376. }
  377. };
  378. await RenderToFile(target);
  379. CompareImages();
  380. }
  381. #if AVALONIA_SKIA_SKIP_FAIL
  382. [Fact(Skip = "FIXME")]
  383. #else
  384. [Fact]
  385. #endif
  386. public async Task VisualBrush_InTree_Visual()
  387. {
  388. Border source;
  389. Decorator target = new Decorator
  390. {
  391. Padding = new Thickness(8),
  392. Width = 200,
  393. Height = 200,
  394. Child = new Grid
  395. {
  396. RowDefinitions = new RowDefinitions("Auto,*"),
  397. Children =
  398. {
  399. (source = new Border
  400. {
  401. Background = Brushes.Yellow,
  402. HorizontalAlignment = HorizontalAlignment.Left,
  403. Child = new TextBlock
  404. {
  405. Text = "Visual"
  406. }
  407. }),
  408. new Border
  409. {
  410. Background = new VisualBrush
  411. {
  412. Stretch = Stretch.Uniform,
  413. Visual = source,
  414. },
  415. [Grid.RowProperty] = 1,
  416. }
  417. }
  418. }
  419. };
  420. await RenderToFile(target);
  421. CompareImages();
  422. }
  423. }
  424. }