OpacityMaskTests.cs 3.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596
  1. using Avalonia.Controls;
  2. using Avalonia.Controls.Shapes;
  3. using Avalonia.Media;
  4. using System;
  5. using System.Collections.Generic;
  6. using System.Text;
  7. using Xunit;
  8. using System.Threading.Tasks;
  9. #if AVALONIA_SKIA
  10. namespace Avalonia.Skia.RenderTests
  11. #else
  12. namespace Avalonia.Direct2D1.RenderTests
  13. #endif
  14. {
  15. public class OpacityMaskTests : TestBase
  16. {
  17. public OpacityMaskTests()
  18. : base("OpacityMask")
  19. {
  20. }
  21. [Fact]
  22. public async Task Opacity_Mask_Masks_Element()
  23. {
  24. var target = new Canvas
  25. {
  26. OpacityMask = new LinearGradientBrush
  27. {
  28. StartPoint = new RelativePoint(0, 0, RelativeUnit.Relative),
  29. EndPoint = new RelativePoint(1, 1, RelativeUnit.Relative),
  30. GradientStops =
  31. {
  32. new GradientStop(Color.FromUInt32(0xffffffff), 0),
  33. new GradientStop(Color.FromUInt32(0x00ffffff), 1)
  34. }
  35. },
  36. Width = 76,
  37. Height = 76,
  38. Children =
  39. {
  40. new Path
  41. {
  42. Width = 32,
  43. Height = 40,
  44. [Canvas.LeftProperty] = 23,
  45. [Canvas.TopProperty] = 18,
  46. Stretch = Stretch.Fill,
  47. Fill = Brushes.Red,
  48. Data = StreamGeometry.Parse("F1 M 27,18L 23,26L 33,30L 24,38L 33,46L 23,50L 27,58L 45,58L 55,38L 45,18L 27,18 Z")
  49. }
  50. }
  51. };
  52. await RenderToFile(target);
  53. CompareImages();
  54. }
  55. [Fact]
  56. public async Task RenderTransform_Applies_To_Opacity_Mask()
  57. {
  58. var target = new Canvas
  59. {
  60. OpacityMask = new LinearGradientBrush
  61. {
  62. StartPoint = new RelativePoint(0, 0, RelativeUnit.Relative),
  63. EndPoint = new RelativePoint(1, 1, RelativeUnit.Relative),
  64. GradientStops =
  65. {
  66. new GradientStop(Color.FromUInt32(0xffffffff), 0),
  67. new GradientStop(Color.FromUInt32(0x00ffffff), 1)
  68. }
  69. },
  70. RenderTransform = new RotateTransform(90),
  71. Width = 76,
  72. Height = 76,
  73. Children =
  74. {
  75. new Path
  76. {
  77. Width = 32,
  78. Height = 40,
  79. [Canvas.LeftProperty] = 23,
  80. [Canvas.TopProperty] = 18,
  81. Stretch = Stretch.Fill,
  82. Fill = Brushes.Red,
  83. Data = StreamGeometry.Parse("F1 M 27,18L 23,26L 33,30L 24,38L 33,46L 23,50L 27,58L 45,58L 55,38L 45,18L 27,18 Z")
  84. }
  85. }
  86. };
  87. await RenderToFile(target);
  88. CompareImages();
  89. }
  90. }
  91. }