Sign in to follow this  
stuff_gnome

Changing UI control values using IndirectUI

Recommended Posts

I have been working on a plug-in that draws the Koch snowflake fractal(s), and I have run into a bit of a problem. I plan to give the user the option to generate several snowflakes of random size and position, to do this I need a maximum and minimum size to be specified by the user. However, I can’t figure out how to automatically make these max and min slider control values equal to one another if the user tries to make the min become greater than the max, or the max becomes less than the min.

As you can see in my code I have tried to use the PropertyBasedEffectConfigToken.SetPropertyValue(object propertyName) method to accomplish this but either I am not using it correctly or it was not ment to be used in this manner.

Any help on this matter would be most appreciated.

UI and plug-in results example:

screen_shot.png

protected override void OnSetRenderInfo(PropertyBasedEffectConfigToken newToken, RenderArgs dstArgs, RenderArgs srcArgs)
       {
           Random random = new Random((int)DateTime.Now.Ticks);



           this.ComplexityValue = newToken.GetProperty(PropertyNames.Complexity).Value;

           this.MaxSizeValue = newToken.GetProperty(PropertyNames.MaxSize).Value;

           this.MinSizeValue = newToken.GetProperty(PropertyNames.MinSize).Value;

           if (this.MinSizeValue > this.MaxSizeValue)
           {

              newToken.SetPropertyValue(PropertyNames.MaxSize, this.MinSizeValue);//)
              this.MaxSizeValue = newToken.GetProperty(PropertyNames.MaxSize).Value;

           }    

           this.AngleValue = newToken.GetProperty(PropertyNames.Angle).Value;

           this.BrushsizeValue = newToken.GetProperty(PropertyNames.Brushsize).Value;

           this.offsetValue = newToken.GetProperty(PropertyNames.Offset).Value;

           this.AntialiasValue = newToken.GetProperty(PropertyNames.Antialias).Value;

           this.Random = newToken.GetProperty(PropertyNames.Random).Value;

           this.RanNum = newToken.GetProperty(PropertyNames.RanNum).Value;

           if (this.Random)
           {
            MultSizes = new ArrayList(this.RanNum);
               for(int i=0; i                    this.MultSizes.Add(MinSizeValue + (random.NextDouble() * (MaxSizeValue - MinSizeValue)));

           }

           base.OnSetRenderInfo(newToken, dstArgs, srcArgs);
       }

Share this post


Link to post
Share on other sites

I have been working on a plug-in that draws the Koch snowflake fractal(s), and I have run into a bit of a problem. I plan to give the user the option to generate several snowflakes of random size and position, to do this I need a maximum and minimum size to be specified by the user. However, I can’t figure out how to automatically make these max and min slider control values equal to one another if the user tries to make the min become greater than the max, or the max becomes less than the min.

As you can see in my code I have tried to use the PropertyBasedEffectConfigToken.SetPropertyValue(object propertyName) method to accomplish this but either I am not using it correctly or it was not ment to be used in this manner.

Any help on this matter would be most appreciated.

UI and plug-in results example:

screen_shot.png

protected override void OnSetRenderInfo(PropertyBasedEffectConfigToken newToken, RenderArgs dstArgs, RenderArgs srcArgs)
       {
           Random random = new Random((int)DateTime.Now.Ticks);



           this.ComplexityValue = newToken.GetProperty(PropertyNames.Complexity).Value;

           this.MaxSizeValue = newToken.GetProperty(PropertyNames.MaxSize).Value;

           this.MinSizeValue = newToken.GetProperty(PropertyNames.MinSize).Value;

           if (this.MinSizeValue > this.MaxSizeValue)
           {

              newToken.SetPropertyValue(PropertyNames.MaxSize, this.MinSizeValue);//)
              this.MaxSizeValue = newToken.GetProperty(PropertyNames.MaxSize).Value;

           }    

           this.AngleValue = newToken.GetProperty(PropertyNames.Angle).Value;

           this.BrushsizeValue = newToken.GetProperty(PropertyNames.Brushsize).Value;

           this.offsetValue = newToken.GetProperty(PropertyNames.Offset).Value;

           this.AntialiasValue = newToken.GetProperty(PropertyNames.Antialias).Value;

           this.Random = newToken.GetProperty(PropertyNames.Random).Value;

           this.RanNum = newToken.GetProperty(PropertyNames.RanNum).Value;

           if (this.Random)
           {
            MultSizes = new ArrayList(this.RanNum);
               for(int i=0; i                    this.MultSizes.Add(MinSizeValue + (random.NextDouble() * (MaxSizeValue - MinSizeValue)));

           }

           base.OnSetRenderInfo(newToken, dstArgs, srcArgs);
       }

Share this post


Link to post
Share on other sites

SoftMutuallyBoundMinMaxRule is what you're looking for:

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

           props.Add(new Int32Property(PropertyNames.MaxSomething, 50, 1, 200));
           props.Add(new Int32Property(PropertyNames.MinSomething, 25, 1, 200));

           List rules = new List();
           rules.Add(new SoftMutuallyBoundMinMaxRule(PropertyNames.MinSomething, PropertyNames.MaxSomething));

           return new PropertyCollection(props, rules);
       }

Share this post


Link to post
Share on other sites

SoftMutuallyBoundMinMaxRule is what you're looking for:

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

           props.Add(new Int32Property(PropertyNames.MaxSomething, 50, 1, 200));
           props.Add(new Int32Property(PropertyNames.MinSomething, 25, 1, 200));

           List rules = new List();
           rules.Add(new SoftMutuallyBoundMinMaxRule(PropertyNames.MinSomething, PropertyNames.MaxSomething));

           return new PropertyCollection(props, rules);
       }

Share this post


Link to post
Share on other sites
SoftMutuallyBoundMinMaxRule is what you're looking for:

Yes, that was indeed what I was looking for and it worked rather well. Strange how there is something just for the very specific purpose of making sure two max and min values don't over lap each other, seems like something a bit more general that allows the programmer to update the UI control values as needed would be more appropriate. Not that I'm trying to be critical or complaining, I certainly found it useful :D.

Apart from moving away from IndirectUI

I am quickly beginning to second guess my decision to use IndirectUI, as I expand on my original idea I am finding it(IndirectUI) exceedingly restrictive, but I suppose thats the trade-off for being so easy to use.

I thank you both for your replies.

Share this post


Link to post
Share on other sites
SoftMutuallyBoundMinMaxRule is what you're looking for:

Yes, that was indeed what I was looking for and it worked rather well. Strange how there is something just for the very specific purpose of making sure two max and min values don't over lap each other, seems like something a bit more general that allows the programmer to update the UI control values as needed would be more appropriate. Not that I'm trying to be critical or complaining, I certainly found it useful :D.

Apart from moving away from IndirectUI

I am quickly beginning to second guess my decision to use IndirectUI, as I expand on my original idea I am finding it(IndirectUI) exceedingly restrictive, but I suppose thats the trade-off for being so easy to use.

I thank you both for your replies.

Share this post


Link to post
Share on other sites
Strange how there is something just for the very specific purpose of making sure two max and min values don't over lap each other
Frosted Glass uses it.
, seems like something a bit more general that allows the programmer to update the UI control values as needed would be more appropriate.
That would defeat the purpose of IndirectUI. Indirect. UI. Meaning you don't directly touch the UI. Not every design pattern works for everything. Use the right tool for the job. Can you imaging trying to hack Smudge into IndirectUI? The old "DirectUI" was kept around for a reason.

If you're finding IndirectUI too restrictive for what you need, by all means use Effect and EffectConfigDialog. I've switched a couple of my plugins between the two, and you'd be surprised how little work it tends to be.

Share this post


Link to post
Share on other sites
Strange how there is something just for the very specific purpose of making sure two max and min values don't over lap each other
Frosted Glass uses it.
, seems like something a bit more general that allows the programmer to update the UI control values as needed would be more appropriate.
That would defeat the purpose of IndirectUI. Indirect. UI. Meaning you don't directly touch the UI. Not every design pattern works for everything. Use the right tool for the job. Can you imaging trying to hack Smudge into IndirectUI? The old "DirectUI" was kept around for a reason.

If you're finding IndirectUI too restrictive for what you need, by all means use Effect and EffectConfigDialog. I've switched a couple of my plugins between the two, and you'd be surprised how little work it tends to be.

Share this post


Link to post
Share on other sites

Also, it is called a "Soft" min/max rule because it doesn't prevent the user from pushing the sliders past each other. Both sliders have "authority", in other words. A 'hard' min/max rule would require more sliders, probably 3 total. (2 to establish min/max, and 1 that would be strictly confined to be between them)

Share this post


Link to post
Share on other sites

Also, it is called a "Soft" min/max rule because it doesn't prevent the user from pushing the sliders past each other. Both sliders have "authority", in other words. A 'hard' min/max rule would require more sliders, probably 3 total. (2 to establish min/max, and 1 that would be strictly confined to be between them)

Share this post


Link to post
Share on other sites

After playing around a bit more, using relector/intellisense to uncover some things, I have been able to reach a level of usability that I am comfortable with. The combination of both the property rules (if thats the correct term, for something like SoftMutuallyBoundMinMaxRule) and the ReadOnlyChanged/ValueChanged events has allowed for a greater range of UI control manipulation.

I don't think it will be too much longer until I produce something worthy of public use. There are still a few features I would like to add though, mainly an open file dialog to be able to utilize color pallete files to further customize the rendering of random snowflake and a "re-randomize" button but that can wait for a rewrite. For now I just plan on using the unique colors present in the active layer as a palette to draw random colors from, any data structure suggestions for keeping track of these colors? A hashset came to mind but recently I have been trying to wrap my mind around the concept of an octree and its use in storing color information efficiently

Share this post


Link to post
Share on other sites

After playing around a bit more, using relector/intellisense to uncover some things, I have been able to reach a level of usability that I am comfortable with. The combination of both the property rules (if thats the correct term, for something like SoftMutuallyBoundMinMaxRule) and the ReadOnlyChanged/ValueChanged events has allowed for a greater range of UI control manipulation.

I don't think it will be too much longer until I produce something worthy of public use. There are still a few features I would like to add though, mainly an open file dialog to be able to utilize color pallete files to further customize the rendering of random snowflake and a "re-randomize" button but that can wait for a rewrite. For now I just plan on using the unique colors present in the active layer as a palette to draw random colors from, any data structure suggestions for keeping track of these colors? A hashset came to mind but recently I have been trying to wrap my mind around the concept of an octree and its use in storing color information efficiently

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