Using IndirectUI rules

IndirectUI is the API Paint.NET effects can use to create dialogs that look and feel like Paint.NET. The rules feature makes it possible to add controls that change how other controls behave.

Adding a “link sliders” option

Often an effect UI will have the same property for, say, different parts of the image. We want to make it easy for the user to change both sliders at once, as they normally don't need to move them independently.

Our OnCreatePropertyCollection() method looks something like this.

protected override PropertyCollection OnCreatePropertyCollection() 
{ 
	List<Property> propsBuilder = new List<Property>(); 
 
	propsBuilder.Add(new Int32Property("Left-hand brightness", 0, 0, 10)); 
	propsBuilder.Add(new Int32Property("Right-hand brightness", 0, 0, 10)); 
 
	return new PropertyCollection(propsBuilder); 
} 

The first step from here is to create a rules list.

protected override PropertyCollection OnCreatePropertyCollection() 
{ 
	List<Property> propsBuilder = new List<Property>(); 
 
	propsBuilder.Add(new Int32Property("lhbright", 0, 0, 10)); 
	propsBuilder.Add(new Int32Property("rhbright", 0, 0, 10)); 
 
	List<PropertyCollectionRule> propRules = new List<PropertyCollectionRule>(); 
	
	return new PropertyCollection(propsBuilder, propRules); 
} 

Next, add a checkbox that will be used to link the sliders.

protected override PropertyCollection OnCreatePropertyCollection() 
{ 
	List<Property> propsBuilder = new List<Property>(); 
 
	propsBuilder.Add(new Int32Property("lhbright", 0, 0, 10)); 
	propsBuilder.Add(new Int32Property("rhbright", 0, 0, 10)); 
	propsBuilder.Add(new BooleanProperty("linkvals", false)); 
 
	List<PropertyCollectionRule> propRules = new List<PropertyCollectionRule>(); 
	
	return new PropertyCollection(propsBuilder, propRules); 
} 

Except right-now it's useless. To get it to work we just need to add a new rule.

protected override PropertyCollection OnCreatePropertyCollection() 
{ 
	List<Property> propsBuilder = new List<Property>(); 
 
	propsBuilder.Add(new Int32Property("lhbright", 0, 0, 10)); 
	propsBuilder.Add(new Int32Property("rhbright", 0, 0, 10)); 
	propsBuilder.Add(new BooleanProperty("linkvals", false)); 
 
	List<PropertyCollectionRule> propRules = new List<PropertyCollectionRule>(); 
	
	propRules.Add(new LinkValuesBasedOnBooleanRule<int, Int32Property>(new string[] { "lhbright", "rhbright" }, "linkvals", false)); 
	
	return new PropertyCollection(propsBuilder, propRules); 
} 

Disabling one property according to the value of another

Sometimes one control is only useful when a certain option is checked. In this case we have an effect that draws a ruler.

protected override PropertyCollection OnCreatePropertyCollection() 
{ 
	List<Property> propsBuilder = new List<Property>(); 
 
	propsBuilder.Add(new BooleanProperty("drawruler", true)); 
	propsBuilder.Add(new Int32Property("rulerlength", 5, 1, 10)); 
 
	List<PropertyCollectionRule> propRules = new List<PropertyCollectionRule>(); 
	
	return new PropertyCollection(propsBuilder, propRules); 
} 

When drawing the ruler is turned off, the ruler length property should be disabled. We can accomplish this using rules.

protected override PropertyCollection OnCreatePropertyCollection() 
{ 
	List<Property> propsBuilder = new List<Property>(); 
 
	propsBuilder.Add(new BooleanProperty("drawruler", true)); 
	propsBuilder.Add(new Int32Property("rulerlength", 5, 1, 10)); 
 
	List<PropertyCollectionRule> propRules = new List<PropertyCollectionRule>(); 
 
	propRules.Add(new ReadOnlyBoundToBooleanRule("rulerlength", "drawruler", true)); 
	
	return new PropertyCollection(propsBuilder, propRules); 
} 


Copyright (C) Simon Brown 2009 - 2024. All rights reserved. Icons by Yusuke Kamiyamane.