From 8d1adbb49fedeb34c5ebbea64458e8b6ebc5c90e Mon Sep 17 00:00:00 2001 From: Sergio Pedri Date: Fri, 24 May 2024 12:00:03 +0200 Subject: [PATCH] Add 'GeneratedCanvasEffectProperty' type --- .../GeneratedCanvasEffectPropertyAttribute.cs | 65 +++++++++++++++++++ 1 file changed, 65 insertions(+) create mode 100644 src/ComputeSharp.D2D1.WinUI/Attributes/GeneratedCanvasEffectPropertyAttribute.cs diff --git a/src/ComputeSharp.D2D1.WinUI/Attributes/GeneratedCanvasEffectPropertyAttribute.cs b/src/ComputeSharp.D2D1.WinUI/Attributes/GeneratedCanvasEffectPropertyAttribute.cs new file mode 100644 index 00000000..48ead4d1 --- /dev/null +++ b/src/ComputeSharp.D2D1.WinUI/Attributes/GeneratedCanvasEffectPropertyAttribute.cs @@ -0,0 +1,65 @@ +using System; + +namespace ComputeSharp.D2D1.WinUI; + +/// +/// An attribute that indicates that a given property represents an effect property, which should invalidate the effect. +/// In order to use this attribute, the containing type has to inherit from . +/// +/// This attribute can be used as follows: +/// +/// partial class MyEffect : CanvasEffect +/// { +/// [GeneratedCanvasEffectProperty] +/// public int BlurAmount { get; set; } +/// } +/// +/// +/// And with this, code analogous to this will be generated: +/// +/// partial class MyEffect +/// { +/// public partial int BlurAmount +/// { +/// get => field; +/// set +/// { +/// if (EqualityComparer<int>.Default.Equals(field, value)) +/// { +/// return; +/// } +/// +/// int oldValue = field; +/// +/// OnBlurAmountChanging(value); +/// OnBlurAmountChanging(oldValue, value); +/// +/// field = value; +/// +/// OnBlurAmountChanged(value); +/// OnBlurAmountChanged(oldValue, value); +/// +/// InvalidateEffectGraph(<INVALIDATION_TYPE>); +/// } +/// } +/// +/// partial void OnBlurAmountChanging(int newValue); +/// partial void OnBlurAmountChanging(int oldValue, int newValue); +/// partial void OnBlurAmountChanged(int newValue); +/// partial void OnBlurAmountChanged(int oldValue, int newValue); +/// } +/// +/// +/// The invalidation type to request. +/// +/// The generated OnChanging and OnChanged methods will be completely removed by +/// the compiler if an implementation for the is not provided, making them fully pay-for-play. +/// +[AttributeUsage(AttributeTargets.Property, AllowMultiple = false)] +public sealed class GeneratedCanvasEffectPropertyAttribute(CanvasEffectInvalidationType invalidationType = CanvasEffectInvalidationType.Update) : Attribute +{ + /// + /// Gets the requested invalidation type for the effect graph when changing the proprty value. + /// + public CanvasEffectInvalidationType InvalidationType { get; } = invalidationType; +} \ No newline at end of file