diff options
author | Carl Hetherington <carl@carlh.net> | 2011-08-30 09:48:53 +0000 |
---|---|---|
committer | Carl Hetherington <carl@carlh.net> | 2011-08-30 09:48:53 +0000 |
commit | 7d32cf3813b7145b98c86b59867092e04aa2621a (patch) | |
tree | dbb2d319f55e2c287b51a7071a236dadd6d83ca3 /gtk2_ardour/utils.cc | |
parent | 9b7ae4cccc8507bc3e74e909b738a5b87a2b717b (diff) |
Give route groups their own colour, settable from the route
group dialogue. Americanise spelling of color in a few
places to avoid confusion. Fixes #4224. Addresses parts
of #2650 and #4064.
git-svn-id: svn://localhost/ardour2/branches/3.0@10030 d708f5d6-7413-0410-9779-e7cbd77b26cf
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 */ + } +} |