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:
- Add dependencies in your device constructor after creating your parameters
- (OPTIONAL) Create callback function if you have complex dependency needs, or want to do more than just enable or disable the target parameter.
- (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);