Sign in to follow this  
Simon Brown

Tutorial: How to use IndirectUI rules

Recommended Posts

This is good information. I considered supporting this in CodeLab, but I couldn't come up with an easy way to specify the rules.

Share this post


Link to post
Share on other sites

Is it possible to link two sliders by their values using the IndirectU.I. prop rules?

I would like to link Maximum and Minimum sliders so that Maximum can never be lower than Minimum and vice versa.
Exactly the same behaviour as Pyrochild has used in his 'Random Shape Fill' effect.

I cannot work out how to use the 'LinkValuesBasedOnBooleanRule' without including a named checkbox on the U.I.
Is it possible to create two simple bool values based on the current values of the sliders and use these in the rules?
eg.(psuedo-code)

//bool linkMax2Min = false;
//bool linkMin2Max = false;
// if(Minimum > Maximum){linkMax2Min = true;}
//if (Maximum < Minimum) {linkMin2Max = true;}
// create two new LinkValuesBasedOnBooleanRules to use these instead of visible checkboxes identified by strings?

Ideally I would like to use this for my 'AlphaThreshold' effect, but
if this requires converting to the CustomU.I. template then it is probably not worth the effort.
(In the current version I simply swap the values in the code to prevent crashes - just means the sliders are lying!   :lol: )

Any help/example code would be very useful and much appreciated.
 

Share this post


Link to post
Share on other sites

What if you override OnCreateConfigUI(), clone the property collection you're giving but omit the boolean property that controls the linking, then pass the property collection to CreateDefaultConfigUI(), and use that?

Share this post


Link to post
Share on other sites

Thanks Rick - that sort of answers my question, in that there is no simple way.

I think I will leave this for the imminent pack update, but I will refer back to your advice when I have a better understanding of how all these methods and tokens interact. ( I can be very 'slow'  :roll: )

Many Thanks - and have an enjoyable vacation, after Pdn 4 you've earned it! ;)

Share this post


Link to post
Share on other sites

Is it possible to link two sliders by their values using the IndirectU.I. prop rules?

I would like to link Maximum and Minimum sliders so that Maximum can never be lower than Minimum and vice versa.

 

I guess you are looking to the wrong type of rule. Try the following:

 

new SoftMutuallyBoundMinMaxRule<int, Int32Property>(PropertyNames.MinInt32Slider,PropertyNames.MaxInt32Slider),

new SoftMutuallyBoundMinMaxRule<double, DoubleProperty>(PropertyNames.MinDoubleSlider,PropertyNames.MaxDoubleSlider),

  • Upvote 2

Share this post


Link to post
Share on other sites

Wow! - Thank you so much Midora - perfect.

I am an amatuer. A 'simple' problem like this has had me perplexed for years!

I did look at the definition of LinkValuesBasedOnBooleanRule and searched MSDN for clues. May I ask how you found that rule as intellisense does not suggest anything?

For other inexperienced plugin writers here is the relevant code:

 //Example of Linked Maximum and Minimum integer sliders
//Using the code example supplied by Midora 

 protected override PropertyCollection OnCreatePropertyCollection()
        {
            List<Property> props = new List<Property>();

            props.Add(new Int32Property(PropertyNames.Amount1, 63, 0, 255));//Minimum slider
            props.Add(new Int32Property(PropertyNames.Amount2, 191, 0, 255));//Maximum slider
			
	List<PropertyCollectionRule> propRules = new List<PropertyCollectionRule>();
            propRules.Add(new SoftMutuallyBoundMinMaxRule<int, Int32Property>(PropertyNames.Amount1, PropertyNames.Amount2));
            return new PropertyCollection(props, propRules); 
        }
//for double sliders use "new SoftMutuallyBoundMinMaxRule<double, DoubleProperty>(PropertyNames.Amount1,PropertyNames.Amount2)"
Thanks again!

Share this post


Link to post
Share on other sites

I am an amatuer. A 'simple' problem like this has had me perplexed for years!

 

Come on. You have written some quite expressive plugins for the community.

 

May I ask how you found that rule as intellisense does not suggest anything?

 

OK, but don't tell it someone else ;-)

 

if you know a rule then you also know the namespace where the rule is defined.

It's PaintDotNet.PropertySystem.

You should expect that other rules are implemented in the same namespace.

So open the class view and search for PaintDotNet.PropertySystem.

And Voila you get all the classes defining properties and rules.

 

Luckily Paint.NET is using meaningful names. This helps a lot together with IntelliSense.

 

As always. It's easy if you know it.

  • Upvote 2

Share this post


Link to post
Share on other sites

It looks like all the rules in PropertySystem are boolean based. Is that correct? I had wanted a property to become enabled when an option in a dropdown was selected. I just want verify that I can't do that. Let me know. Thank You.

Share this post


Link to post
Share on other sites

Rules may use static list properties. I.e.

// Disable UnitDPI if ModeChoiceList.Print OR ModeChoiceList.Model3D OR UnitChoiceList.Pixel
propRules.Add(new ReadOnlyBoundToNameValuesRule(PropertyNames.UnitDPI, false, new Pair<object, object>[] { 
    new Pair<object, object>(PropertyNames.ModeChoice, ModeChoiceList.Output),
    new Pair<object, object>(PropertyNames.ModeChoice, ModeChoiceList.Visualization),
    new Pair<object, object>(PropertyNames.UnitChoice, UnitChoiceList.Pixel)}));
  • Upvote 1

Share this post


Link to post
Share on other sites

Thank you for the example code.

 

When I compile, I get an error telling me that it's obsolete.

 

'PaintDotNet.PropertySystem.ReadOnlyBoundToNameValuesRule.ReadOnlyBoundToNameValuesRule(object, bool, params PaintDotNet.Pair<object,object>[])' is obsolete: 'Use the overload'    c:\users\-----documents\visual studio 2013\Projects\-------\-------.cs

 

Excuse my ignorance, but what is this overload that it speaks of? Is there a work around besides compiling against an older version of paint.net?
 

Edited by toe_head2001

Share this post


Link to post
Share on other sites

Thanks, I got it setup correctly now.
 

The control should only enable when option 4 is selected, however the control is enabled when the dialog loads (the rule is not recognizing that option 1 is selected until it clicked).  I think I know why Rick disabled this rule in v4...

 

Is there a way I can manually disable the control on dialog load?

Edited by toe_head2001

Share this post


Link to post
Share on other sites

As long as you are creating PropertyBasedEffects you are not able to access the controls.

For this you have to create your own effects or OptionBasedEffects.

Share this post


Link to post
Share on other sites

toe_head2001:

 

It looks like all the rules in PropertySystem are boolean based. Is that correct? I had wanted a property to become enabled when an option in a dropdown was selected. I just want verify that I can't do that..

 

It can be done by using ReadOnlyBoundToValueRule.

 

The following code is based on what was originally a CodeLab plugin (hence the Amount variables). I want to disable the second control if the first option of the first control isn't selected. (It could be simplified by using the inverse option, and the version of the call that takes a single value instead of an array, but I wanted to show the more general case.)

 
        // Standard stuff.       
        public enum Amount1Options
        {
            Amount1Option1,
            Amount1Option2,
            Amount1Option3
        }

        protected override PropertyCollection OnCreatePropertyCollection()
        {
            // Standard stuff.
            List<Property> props = new List<Property>();
            props.Add(StaticListChoiceProperty.CreateForEnum<Amount1Options>(PropertyNames.Amount1, 0, false));
            props.Add(new Int32Property(PropertyNames.Amount2, ColorBgra.ToOpaqueInt32(ColorBgra.FromBgra(EnvironmentParameters.PrimaryColor.B,EnvironmentParameters.PrimaryColor.G,EnvironmentParameters.PrimaryColor.R,255)), 0, 0xffffff));
            
            // Enable or disable the second control based on the first control, which is a drop-down list.
            // If either the second or third list item is selected, the second control is disabled.
            List<PropertyCollectionRule> propRules = new List<PropertyCollectionRule>();
            propRules.Add(new ReadOnlyBoundToValueRule<object, StaticListChoiceProperty>(PropertyNames.Amount2, PropertyNames.Amount1,
                new object[] { Amount1Options.Amount1Option2, Amount1Options.Amount1Option3 }, false));

            // Standard, except a second argument is added to the PropertyCollection call for the rules.
            return new PropertyCollection(props, propRules);
        }
The call has the basic form:

ReadOnlyBoundToValueRule<TValue, TProperty> 
The various versions of the call are:

ReadOnlyBoundToValueRule(Property targetProperty, TProperty sourceProperty, TValue valueForReadOnly, bool inverse);
ReadOnlyBoundToValueRule(Property targetProperty, TProperty sourceProperty, TValue[] valuesForReadOnly, bool inverse);
ReadOnlyBoundToValueRule(object targetPropertyName, object sourcePropertyName, TValue valueForReadOnly, bool inverse);
ReadOnlyBoundToValueRule(object targetPropertyName, object sourcePropertyName, TValue[] valuesForReadOnly, bool inverse);
Edited by MJW
  • Upvote 2

Share this post


Link to post
Share on other sites

It can be done by using ReadOnlyBoundToValueRule.

Thanks, I finally got around to using this.

 

It also works well for disabling a control when a Slider is set at zero.

propRules.Add(new ReadOnlyBoundToValueRule<int, Int32Property>(PropertyNames.Amount2, PropertyNames.Amount1, 0, false));
Edited by toe_head2001

Share this post


Link to post
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.

Sign in to follow this