Re #6980. Fix calculation of color index.

The problem was that the ColorBox had been added, which extended the
number of colours to 24, but the method contained this hard-coded so
the calculation wrapped around too soon. Also if you hit white you then
got 'stuck' at black - now it skips on to the next colour.
I've changed to calling methods on ColorBox instead of magic numbers,
and also streamlined the code in other places.
Merge remote-tracking branch 'origin/bugfix/6980_curve_colour_choosing'