internal CodeWriter Constructor(ShaderModel model, bool defaultCtor) { if (defaultCtor) { this.Line("/// <summary>") .Line($"/// The uri should be something like pack://application:,,,/Gu.Wpf.Geometry;component/Effects/{model.GeneratedClassName}.ps") .Line($"/// The file {model.GeneratedClassName}.ps should have BuildAction: Resource") .Line("/// </summary>") .Line("private static readonly PixelShader Shader = new PixelShader") .Line("{") .Line($" UriSource = new Uri(\"pack://application:,,,/[assemblyname];component/[folder]/{model.GeneratedClassName}.ps\", UriKind.Absolute),") .Line("};") .Line() .Line($"public {model.GeneratedClassName}()") .OpenCurly() .Line("this.PixelShader = Shader;"); } else { this.Line($"public {model.GeneratedClassName}(PixelShader shader)") .OpenCurly() .Line("this.PixelShader = shader;"); } this.Line("this.UpdateShaderValue(InputProperty);"); foreach (var register in model.Registers) { this.Line($"this.UpdateShaderValue({register.Name}Property);"); } return(this.EndCurly() .Line()); }
internal CodeWriter Properties(ShaderModel model) { this.Summary("There has to be a property of type Brush called Input. This property contains the input image and it is usually not set directly - it is set automatically when our effect is applied to a control.") .Line("public Brush Input") .Line("{") .Line($" get => (Brush)this.GetValue(InputProperty);") .Line($" set => this.SetValue(InputProperty, value);") .Line("}"); foreach (var register in model.Registers) { this.Line() .Summary(register.Description) .Line($"public {TypeName(register.Type)} {register.Name}") .Line("{") .Line($" get => ({TypeName(register.Type)})this.GetValue({register.Name}Property);") .Line($" set => this.SetValue({register.Name}Property, value);") .Line("}"); } return(this); }
internal CodeWriter BackingFields(ShaderModel model) { this.Summary("Identifies the Input dependency property.") .Line("public static readonly DependencyProperty InputProperty = ShaderEffect.RegisterPixelShaderSamplerProperty(") .Line(" nameof(Input),") .Line($" typeof({model.GeneratedClassName}),") .Line($" 0);") .Line(); foreach (var register in model.Registers) { this.Summary($"Identifies the {register.Name} dependency property.") .Line($"public static readonly DependencyProperty {register.Name}Property = DependencyProperty.Register(") .Line($" nameof({register.Name}),") .Line($" typeof({TypeName(register.Type)}),") .Line($" typeof({model.GeneratedClassName}),") .Line(" new UIPropertyMetadata(") .Line($" {DefaultValue(register.DefaultValue, register.Type)},") .Line($" PixelShaderConstantCallback({register.Ordinal})));") .Line(); } return(this); }