Extending class parameters

Class parameters make it easy to create different formulas with common features, but you can even take this a step further. If you load the MandelbrotTest example in Ultra Fractal, a Browse button is visible next to the name of the class in the list of parameters. This button enables the user to select a different class than the default Bailout class, as long as it descends from Bailout. (See Example 1 - Formula classes for an example.)

Let's write a descendant class that implements more bailout options:

class ExtendedBailout(Test.ufm:Bailout) {
public:
  bool func hasBailedOut(const complex z)
    return (@test == "mod" && |z| > @bailout) ||      \
      (@test == "real" && sqr(real(z)) > @bailout) || \
      (@test == "imag" && sqr(imag(z)) > @bailout)
  endfunc
default:
  title = "Extended Bailout"
  int param test
    caption = "Bailout Test"
    default = 0
    enum = "mod" "real" "imag"
  endparam
}

If you put this code in a class library file such as Test.ulb, you can select the new class by clicking on the Browse button next to the Bailout class parameter. The MandelbrotTest formula will now use the bailout code from the ExtendedBailout class. As you can see, this system enables you to add new features to a formula even after it has been published, without having to modify the formula itself!

Next: Parameter forwards

See Also
Classes
Class parameters
Inheritance
Overriding