• Welcome to World Machine Community. Please login or sign up.
 
May 20, 2019, 07:30:12 pm

News:

Read the Development Diary for an inside look at World Machine's progress!


Updating Parameter Flags

Started by CKlosters, November 15, 2011, 03:31:52 am

Previous topic - Next topic

0 Members and 1 Guest are viewing this topic.

CKlosters

Hi!

I'm trying to change parameter flags based on a user action.
For example: if the user toggles "Visualize" on or off, I want a parameter to be read only or editable based on the state of Visualize (true or false).

I can set flags, but can't find methods to remove them (in the Parameter object). Is there a simple way to accomplish this?
Currenlty in the activate function i do?:



bool blend_edges = BlendEdges;

// Try to blank out
if (!blend_edges)
params.GetParam(BlendStart)->setFlag(PARM_FLAG_READONLY);
else
????


CKlosters

mm, this seems to work when closing the parameter dialog and opening it again.
How can I refresh (or force a rebuild) of the parameter dialog?

Stephen

November 16, 2011, 03:31:57 pm #2 Last Edit: November 16, 2011, 03:34:31 pm by Remnant
Hi there,

what you want is a Parameter Dependency, where certain parameters enabled state can depend upon the value of another. There's alot more I'd like to do with making complex sets of parameters accessible, but here's how to do it currently:



1) Add dependencies in your device constructor after creating your parameters
2) (OPTIONAL) Create callback function if you have complex dependency needs, or want to do more than just enable or disable the target parameter.
3) (OPTIONAL) If running your own UI dialog box, you must call ProcessDependencies() on your device's parameter set to recheck dependencies after a changed value. HOWEVER, the default generic dialog interface does this step for you so if you are using the built in system you are good to go.


More detail on step 1:

(defined in Parameter.h):

Call:

bool AddDependence(const char *target, const char *trigger, DEPENDS_TYPE type, VAL dependsval, DEPENDS_FUNC func = NULL);


Where the parameters are:

target: parameter name of the parameter that should be MODIFIED based on dependency
trigger: parameter name of the parameter that, when changed, TRIGGERS the dependency
type: VALUE_CHANGE if the dependency function should be called for any change of the trigger
         VALUE_EQUAL if the target should be turned on when the trigger value = dependsval, and off otherwise
dependsval: value of trigger parameter that triggers dependency
func: the callback assigned to this dependency (optional!)


So, wrapping it up:


A simple "turn this on when this one is turned on" dependency would be expressed like:


// example from the Lightmap Generator deice code!
// enable the sun color parameter only when Produce RGB is true
params.AddDependence("Sun Color", "Produce RGB Lightmap", VALUE_EQUAL, VAL(true));


Or, here's a more complex dependence, making sure a filename always has the correct extension when you change the format:


void dependsChangeExtension(Device *dev, DependsPair &dep) {
// do string stuff
};

// call the function provided whenever the file format changes
params.AddDependence("File Name", "File Format", VALUE_CHANGE, 0, dependsChangeExtension);

-- Stephen Schmitt
- Creator of World Machine

CKlosters

November 17, 2011, 04:07:20 pm #3 Last Edit: November 17, 2011, 04:09:28 pm by CKlosters
That's exactly what I needed to know!
In the long run, having access to more comlex parameter sets would be beneficial as well.

Thanks  :D

CKlosters

I implemented the AddDepence Method in the constructor after adding the parameters.
It seems to work, but only for the depending parameter slider and value.

The actual parameter name doesn't change color (grey to black, black to grey)

Is this expected behaviour?


// Add parameter dependencies
params.AddDependence("Edge Blend", "Blend Edges", VALUE_EQUAL, VAL(true));
params.AddDependence("Edge Power", "Blend Edges", VALUE_EQUAL, VAL(true));
params.AddDependence("Min Height","Map Incoming Values",VALUE_EQUAL,VAL(true));
params.AddDependence("Max Height","Map Incoming Values",VALUE_EQUAL,VAL(true));

Stephen

good catch, this is 'normal' but errant behavior -- it should be disabling everything including the label. This will be fixed in the next beta!
-- Stephen Schmitt
- Creator of World Machine


Quick Reply

With Quick-Reply you can write a post when viewing a topic without loading a new page. You can still use bulletin board code and smileys as you would in a normal post.

Warning: this topic has not been posted in for at least 120 days.
Unless you're sure you want to reply, please consider starting a new topic.

Note: this post will not display until it's been approved by a moderator.

Name:
Email:
Verification:
Please leave this box empty:
Type the letters shown in the picture
Listen to the letters / Request another image

Type the letters shown in the picture:

Shortcuts: ALT+S save/post or ALT+P preview