diff options
Diffstat (limited to 'gtk2_ardour/utils.cc')
-rw-r--r-- | gtk2_ardour/utils.cc | 39 |
1 files changed, 39 insertions, 0 deletions
diff --git a/gtk2_ardour/utils.cc b/gtk2_ardour/utils.cc index add148d0b0..7c71170307 100644 --- a/gtk2_ardour/utils.cc +++ b/gtk2_ardour/utils.cc @@ -27,6 +27,7 @@ #include <cstdlib> #include <cctype> #include <fstream> +#include <list> #include <sys/stat.h> #include <libart_lgpl/art_misc.h> #include <gtkmm/rc.h> @@ -938,4 +939,42 @@ escape_underscores (string const & s) return o; } +Gdk::Color +unique_random_color (list<Gdk::Color>& used_colors) +{ + Gdk::Color newcolor; + while (1) { + + /* avoid neon/glowing tones by limiting them to the + "inner section" (paler) of a color wheel/circle. + */ + + const int32_t max_saturation = 48000; // 65535 would open up the whole color wheel + + newcolor.set_red (random() % max_saturation); + newcolor.set_blue (random() % max_saturation); + newcolor.set_green (random() % max_saturation); + + if (used_colors.size() == 0) { + used_colors.push_back (newcolor); + return newcolor; + } + + for (list<Gdk::Color>::iterator i = used_colors.begin(); i != used_colors.end(); ++i) { + Gdk::Color c = *i; + float rdelta, bdelta, gdelta; + + rdelta = newcolor.get_red() - c.get_red(); + bdelta = newcolor.get_blue() - c.get_blue(); + gdelta = newcolor.get_green() - c.get_green(); + + if (sqrt (rdelta*rdelta + bdelta*bdelta + gdelta*gdelta) > 25.0) { + used_colors.push_back (newcolor); + return newcolor; + } + } + + /* XXX need throttle here to make sure we don't spin for ever */ + } +} |