OpacityMaskTests.cs 3.0 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192
  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. namespace Avalonia.Skia.RenderTests
  10. {
  11. public class OpacityMaskTests : TestBase
  12. {
  13. public OpacityMaskTests()
  14. : base("OpacityMask")
  15. {
  16. }
  17. [Fact]
  18. public async Task Opacity_Mask_Masks_Element()
  19. {
  20. var target = new Canvas
  21. {
  22. OpacityMask = new LinearGradientBrush
  23. {
  24. StartPoint = new RelativePoint(0, 0, RelativeUnit.Relative),
  25. EndPoint = new RelativePoint(1, 1, RelativeUnit.Relative),
  26. GradientStops =
  27. {
  28. new GradientStop(Color.FromUInt32(0xffffffff), 0),
  29. new GradientStop(Color.FromUInt32(0x00ffffff), 1)
  30. }
  31. },
  32. Width = 76,
  33. Height = 76,
  34. Children =
  35. {
  36. new Path
  37. {
  38. Width = 32,
  39. Height = 40,
  40. [Canvas.LeftProperty] = 23,
  41. [Canvas.TopProperty] = 18,
  42. Stretch = Stretch.Fill,
  43. Fill = Brushes.Red,
  44. 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")
  45. }
  46. }
  47. };
  48. await RenderToFile(target);
  49. CompareImages();
  50. }
  51. [Fact]
  52. public async Task RenderTransform_Applies_To_Opacity_Mask()
  53. {
  54. var target = new Canvas
  55. {
  56. OpacityMask = new LinearGradientBrush
  57. {
  58. StartPoint = new RelativePoint(0, 0, RelativeUnit.Relative),
  59. EndPoint = new RelativePoint(1, 1, RelativeUnit.Relative),
  60. GradientStops =
  61. {
  62. new GradientStop(Color.FromUInt32(0xffffffff), 0),
  63. new GradientStop(Color.FromUInt32(0x00ffffff), 1)
  64. }
  65. },
  66. RenderTransform = new RotateTransform(90),
  67. Width = 76,
  68. Height = 76,
  69. Children =
  70. {
  71. new Path
  72. {
  73. Width = 32,
  74. Height = 40,
  75. [Canvas.LeftProperty] = 23,
  76. [Canvas.TopProperty] = 18,
  77. Stretch = Stretch.Fill,
  78. Fill = Brushes.Red,
  79. 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")
  80. }
  81. }
  82. };
  83. await RenderToFile(target);
  84. CompareImages();
  85. }
  86. }
  87. }