SetParameter() public method

public SetParameter ( EffectParameter parameter, object value ) : void
parameter EffectParameter
value object
return void
        static UIElement CreateBoolWidget(Effect effect, EffectParameter parameter)
        {
            var checkbox = new CheckBox()
            {
                IsChecked = (bool)effect.GetParameter(parameter)
            };

            checkbox.Checked   += (sender, e) => { effect.SetParameter(parameter, true); };
            checkbox.Unchecked += (sender, e) => { effect.SetParameter(parameter, false); };

            return(checkbox);
        }
        static UIElement CreateFloatWidget(Effect effect, EffectParameter parameter)
        {
            float valueScale = (parameter.Max - parameter.Min) / 100;

            var slider = new Slider()
            {
                Value = ((float)effect.GetParameter(parameter) - parameter.Min) / valueScale
            };

            slider.ValueChanged += (sender, e) =>
            {
                effect.SetParameter(parameter, parameter.Min + (float)e.NewValue * valueScale);
            };

            return(slider);
        }
        static UIElement CreateIntWidget(Effect effect, EffectParameter parameter)
        {
            var slider = new Slider()
            {
                Minimum = parameter.Min,
                Maximum = parameter.Max,

                Value = (int)effect.GetParameter(parameter)
            };

            slider.ValueChanged += (sender, e) =>
            {
                effect.SetParameter(parameter, (int)e.NewValue);
            };

            return(slider);
        }
        static UIElement CreateColorWidget(Effect effect, EffectParameter parameter)
        {
            var colorProperties = typeof(Colors).GetRuntimeProperties();
            var colorNames      = colorProperties.Select(p => p.Name).ToList();
            var colorValues     = colorProperties.Select(p => p.GetValue(null)).ToList();

            var combo = new ComboBox()
            {
                ItemsSource   = colorNames,
                SelectedIndex = colorValues.IndexOf(effect.GetParameter(parameter))
            };

            combo.SelectionChanged += (sender, e) =>
            {
                effect.SetParameter(parameter, colorValues[combo.SelectedIndex]);
            };

            return(combo);
        }
        static void CreateRectWidgets(Effect effect, EffectParameter parameter, List <UIElement> widgets, List <string> widgetNames)
        {
            Photo photo = effect.Parent.Parent;

            // Read the current rectangle (infinity means not initialized).
            var initialValue = (Rect)effect.GetParameter(parameter);

            if (double.IsInfinity(initialValue.Width))
            {
                initialValue = photo.SourceBitmap.Bounds;
            }

            var topLeft     = new Vector2((float)initialValue.Left, (float)initialValue.Top);
            var bottomRight = new Vector2((float)initialValue.Right, (float)initialValue.Bottom);

            // Create four sliders.
            for (int i = 0; i < 4; i++)
            {
                int whichSlider = i;

                var slider = new Slider();

                // Initialize the slider position.
                switch (whichSlider)
                {
                case 0:
                    slider.Value = topLeft.X * 100 / photo.Size.X;
                    break;

                case 1:
                    slider.Value = bottomRight.X * 100 / photo.Size.X;
                    break;

                case 2:
                    slider.Value = topLeft.Y * 100 / photo.Size.Y;
                    break;

                case 3:
                    slider.Value = bottomRight.Y * 100 / photo.Size.Y;
                    break;
                }

                // Respond to slider changes.
                slider.ValueChanged += (sender, e) =>
                {
                    switch (whichSlider)
                    {
                    case 0:
                        topLeft.X = (float)e.NewValue * photo.Size.X / 100;
                        break;

                    case 1:
                        bottomRight.X = (float)e.NewValue * photo.Size.X / 100;
                        break;

                    case 2:
                        topLeft.Y = (float)e.NewValue * photo.Size.Y / 100;
                        break;

                    case 3:
                        bottomRight.Y = (float)e.NewValue * photo.Size.Y / 100;
                        break;
                    }

                    // Make sure the rectangle never goes zero or negative.
                    var tl = Vector2.Min(topLeft, photo.Size - Vector2.One);
                    var br = Vector2.Max(bottomRight, tl + Vector2.One);

                    effect.SetParameter(parameter, new Rect(tl.ToPoint(), br.ToPoint()));
                };

                widgets.Add(slider);
            }

            widgetNames.AddRange(new string[] { "Left", "Right", "Top", "Bottom" });
        }