diff options
author | Paul Davis <paul@linuxaudiosystems.com> | 2005-12-21 21:37:18 +0000 |
---|---|---|
committer | Paul Davis <paul@linuxaudiosystems.com> | 2005-12-21 21:37:18 +0000 |
commit | 541ff632019c53a93611ad34f43930595386afe9 (patch) | |
tree | b72ecc5298aae17b3585f27003ee8fd31657bc65 /libs/gtkmm2ext/stateful_button.cc | |
parent | bf5180d17a56deb1f1a9b242ab382cd85b87ebf5 (diff) |
button hacks and more
git-svn-id: svn://localhost/trunk/ardour2@200 d708f5d6-7413-0410-9779-e7cbd77b26cf
Diffstat (limited to 'libs/gtkmm2ext/stateful_button.cc')
-rw-r--r-- | libs/gtkmm2ext/stateful_button.cc | 80 |
1 files changed, 80 insertions, 0 deletions
diff --git a/libs/gtkmm2ext/stateful_button.cc b/libs/gtkmm2ext/stateful_button.cc new file mode 100644 index 0000000000..074d086651 --- /dev/null +++ b/libs/gtkmm2ext/stateful_button.cc @@ -0,0 +1,80 @@ +#include <string> +#include <iostream> +#include "gtkmm2ext/stateful_button.h" + +using namespace Gtk; +using namespace Glib; +using namespace Gtkmm2ext; +using namespace std; + +StatefulButton::StatefulButton () +{ + current_state = 0; + have_saved_bg = false; +} + +StatefulButton::StatefulButton (const string& label) + : Button (label) +{ + current_state = 0; + have_saved_bg = false; +} + +void +StatefulButton::set_colors (const vector<Gdk::Color>& c) +{ + colors = c; + current_state++; // to force transition + set_state (current_state - 1); +} + +void +StatefulButton::on_realize () +{ + Button::on_realize (); + + if (!have_saved_bg) { + saved_bg = get_style()->get_bg (STATE_NORMAL); + have_saved_bg = true; + } + + current_state++; // to force transition + set_state (current_state - 1); +} + +void +StatefulButton::set_state (int n) +{ + if (is_realized()) { + + if (n == current_state) { + return; + } + + if (n == 0) { + + /* back to the default color */ + + if (have_saved_bg) { + modify_bg (STATE_NORMAL, saved_bg); + modify_bg (STATE_ACTIVE, saved_bg); + modify_bg (STATE_SELECTED, saved_bg); + modify_bg (STATE_PRELIGHT, saved_bg); + } + + + } else { + + int index = (n-1) % colors.size (); + + modify_bg (STATE_NORMAL, colors[index]); + modify_bg (STATE_ACTIVE, colors[index]); + modify_bg (STATE_SELECTED, colors[index]); + modify_bg (STATE_PRELIGHT, colors[index]); + } + + /* leave insensitive alone */ + } + + current_state = n; +} |