diff --git a/WaveOptics/Effects/WaveOpticsEffect.cs b/WaveOptics/Effects/WaveOpticsEffect.cs index fcd5ad0..d53ae70 100644 --- a/WaveOptics/Effects/WaveOpticsEffect.cs +++ b/WaveOptics/Effects/WaveOpticsEffect.cs @@ -33,10 +33,12 @@ public sealed class WaveOpticsEffect : VideoEffectBase private bool _linear; [Display(GroupName = nameof(Texts.OutputGroup), Name = nameof(Texts.HighlightThreshold), Description = nameof(Texts.HighlightThresholdDescription), Order = 3, ResourceType = typeof(Texts))] + [LinearLightVisible] [AnimationSlider("F1", "%", 0, 100)] public Animation HighlightThreshold { get; } = new(95, 0, 100); [Display(GroupName = nameof(Texts.OutputGroup), Name = nameof(Texts.HighlightBoost), Description = nameof(Texts.HighlightBoostDescription), Order = 4, ResourceType = typeof(Texts))] + [LinearLightVisible] [AnimationSlider("F1", "x", 1, 100)] public Animation HighlightBoost { get; } = new(1, 1, 1000); @@ -75,6 +77,7 @@ public sealed class WaveOpticsEffect : VideoEffectBase private WaveOpticsApertureShape _apertureShape; [Display(GroupName = nameof(Texts.ApertureGroup), Name = nameof(Texts.BladeCount), Description = nameof(Texts.BladeCountDescription), Order = 21, ResourceType = typeof(Texts))] + [PolygonApertureVisible] [TextBoxSlider("F0", "", 3, 16)] [Range(3, 32)] [DefaultValue(6)] @@ -82,6 +85,7 @@ public sealed class WaveOpticsEffect : VideoEffectBase private int _bladeCount = 6; [Display(GroupName = nameof(Texts.ApertureGroup), Name = nameof(Texts.BladeRotation), Description = nameof(Texts.BladeRotationDescription), Order = 22, ResourceType = typeof(Texts))] + [PolygonApertureVisible] [AnimationSlider("F1", "°", -180, 180)] public Animation BladeRotation { get; } = new(0, -360, 360); diff --git a/WaveOptics/Effects/WaveOpticsVisibility.cs b/WaveOptics/Effects/WaveOpticsVisibility.cs new file mode 100644 index 0000000..9351d58 --- /dev/null +++ b/WaveOptics/Effects/WaveOpticsVisibility.cs @@ -0,0 +1,35 @@ +using System.Globalization; +using System.Windows; +using System.Windows.Data; +using YukkuriMovieMaker.ItemEditor; + +namespace WaveOptics.Effects; + +[AttributeUsage(AttributeTargets.Property)] +internal sealed class PolygonApertureVisibleAttribute : Attribute, ICustomVisibilityAttribute2 +{ + public Binding GetBinding(object item, object propertyOwner) => new(nameof(WaveOpticsEffect.ApertureShape)) + { + Source = item, + Converter = new VisibilityConverter(value => value is WaveOpticsApertureShape.RegularPolygon) + }; +} + +[AttributeUsage(AttributeTargets.Property)] +internal sealed class LinearLightVisibleAttribute : Attribute, ICustomVisibilityAttribute2 +{ + public Binding GetBinding(object item, object propertyOwner) => new(nameof(WaveOpticsEffect.Linear)) + { + Source = item, + Converter = new VisibilityConverter(value => value is true) + }; +} + +internal sealed class VisibilityConverter(Func isVisible) : IValueConverter +{ + public object Convert(object? value, Type targetType, object? parameter, CultureInfo culture) + => isVisible(value) ? Visibility.Visible : Visibility.Collapsed; + + public object ConvertBack(object? value, Type targetType, object? parameter, CultureInfo culture) + => throw new NotSupportedException(); +}