Jump to content

Updating control values


John8

Recommended Posts

Hello,

 

I was wondering how to update controls in a plugin.

The use case is to estimate some parameters and then let the user choose to adjust the values himself.

 

I my case, I have properties like that :

        protected override PropertyCollection OnCreatePropertyCollection()
        {
            var propertyList = new List<Property>
            {
                StaticListChoiceProperty.CreateForEnum(PropertyNames.WhiteBalanceMethod, WhiteBalanceMethod.None, false),
                new DoubleProperty(PropertyNames.RedGain, 1.0, 0.0, 2.0),
                new DoubleProperty(PropertyNames.GreenGain, 1.0, 0.0, 2.0),
                new DoubleProperty(PropertyNames.BlueGain, 1.0, 0.0, 2.0)
            };

            return new PropertyCollection(propertyList);
        }

For those properties I set up the controles like that :

        protected override ControlInfo OnCreateConfigUI(PropertyCollection props)
        {
            var defaultConfigUi = CreateDefaultConfigUI(props);
            defaultConfigUi.SetPropertyControlValue(PropertyNames.RedGain, ControlInfoPropertyNames.DisplayName, "Red Gain");
            defaultConfigUi.SetPropertyControlValue(PropertyNames.GreenGain, ControlInfoPropertyNames.DisplayName, "Green Gain");
            defaultConfigUi.SetPropertyControlValue(PropertyNames.BlueGain, ControlInfoPropertyNames.DisplayName, "Blue Gain");

            defaultConfigUi.SetPropertyControlValue(PropertyNames.WhiteBalanceMethod, ControlInfoPropertyNames.DisplayName, "White Balance Method");

            var controlForPropertyName = defaultConfigUi.FindControlForPropertyName(PropertyNames.WhiteBalanceMethod);
            controlForPropertyName.SetValueDisplayName(WhiteBalanceMethod.None, "None");
            controlForPropertyName.SetValueDisplayName(WhiteBalanceMethod.GrayWorld, "GrayWorld");
            controlForPropertyName.SetValueDisplayName(WhiteBalanceMethod.Retinex, "Retinex");
            controlForPropertyName.SetValueDisplayName(WhiteBalanceMethod.YCbCr, "YCbCr");

            return defaultConfigUi;
        }

Then, at some point, I update the properties' values with SetPropertyValue like that :

        private void UpdateProperties(PropertyBasedEffectConfigToken newToken, WhiteBalanceMethod whiteBalanceMethod)
        {
            var whiteBalanceFunction = GetWhiteBalanceFunction(whiteBalanceMethod);

            if (whiteBalanceFunction == null) 
                return;

            var (redGain, greenGain, blueGain) = whiteBalanceFunction(SrcArgs.Surface);
            (redGain, greenGain, blueGain) = Normalize(redGain, greenGain, blueGain);

            newToken.SetPropertyValue(PropertyNames.RedGain, redGain);
            newToken.SetPropertyValue(PropertyNames.GreenGain, greenGain);
            newToken.SetPropertyValue(PropertyNames.BlueGain, blueGain);

            // XXX : How to update controls with new values ?
        }

Updating the property values works, and I can read back the values with GetProperty.

However it does not update the controls in the UI and the sliders remain to the value that was already set.

 

How can I update the controls' value to display their properties' value ?

 

Thanks in advance.

 

Link to comment
Share on other sites

13 hours ago, John8 said:

Is there a way without IndirectUI ?

 

Without IndirectUI you can do pretty much what you want with the controls, including changing their values. The user interface is just a Windows Form. The challenge is sufficiently maintaining the look-and-feel of PDN user interfaces. For instance, most non-IndirecUI Effects I've encountered don't have control resets, which many users (e.g., me) expect.

Link to comment
Share on other sites

14 hours ago, MJW said:

 For instance, most non-IndirecUI Effects I've encountered don't have control resets, which many users (e.g., me) expect.

 

Sometimes the reset button is actually a label just like the TechnoRobbo's plugin.
Clicking on the label resets the control to its initial value.

lZvqAiH.png

Link to comment
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...