5 #include <gtkmm/toggleaction.h>
7 #include "pbd/compose.h"
8 #include "gtkmm2ext/utils.h"
9 #include "gtkmm2ext/rgb_macros.h"
11 #include "ardour_ui.h"
12 #include "button_joiner.h"
16 ButtonJoiner::ButtonJoiner (const std::string& str, Gtk::Widget& lw, Gtk::Widget& rw)
20 , active_fill_pattern (0)
21 , inactive_fill_pattern (0)
23 packer.set_homogeneous (true);
24 packer.pack_start (left);
25 packer.pack_start (right);
30 align.set_padding (9, 0, 9, 9);
35 add_events (Gdk::BUTTON_PRESS_MASK|Gdk::BUTTON_RELEASE_MASK|
36 Gdk::ENTER_NOTIFY_MASK|Gdk::LEAVE_NOTIFY_MASK);
38 uint32_t border_color;
41 border_color = ARDOUR_UI::config()->color_by_name (string_compose ("%1: border end", name));
42 UINT_TO_RGBA (border_color, &r, &g, &b, &a);
48 /* child cairo widgets need the color of the inner edge as their
53 col.set_rgb_p (border_r, border_g, border_b);
54 provide_background_for_cairo_widget (*this, col);
57 ButtonJoiner::~ButtonJoiner ()
59 if (active_fill_pattern) {
60 cairo_pattern_destroy (active_fill_pattern);
61 cairo_pattern_destroy (inactive_fill_pattern);
66 ButtonJoiner::render (cairo_t* cr)
68 double h = get_height();
71 cairo_set_source (cr, inactive_fill_pattern);
73 cairo_set_source (cr, active_fill_pattern);
78 Gtkmm2ext::rounded_top_rectangle (cr, 0, 0, get_width(), h, 12);
79 cairo_fill_preserve (cr);
83 cairo_set_line_width (cr, 1);
84 cairo_set_source_rgb (cr, border_r, border_g, border_b);
89 Gtkmm2ext::rounded_top_rectangle (cr, 8, 8, get_width() - 16, h - 8, 10);
95 ButtonJoiner::on_size_allocate (Allocation& alloc)
97 CairoWidget::on_size_allocate (alloc);
102 ButtonJoiner::on_button_release_event (GdkEventButton* ev)
105 _action->activate ();
112 ButtonJoiner::on_size_request (Gtk::Requisition* r)
114 CairoWidget::on_size_request (r);
118 ButtonJoiner::set_related_action (Glib::RefPtr<Action> act)
120 Gtkmm2ext::Activatable::set_related_action (act);
124 action_tooltip_changed ();
126 Glib::RefPtr<ToggleAction> tact = Glib::RefPtr<ToggleAction>::cast_dynamic (_action);
129 tact->signal_toggled().connect (sigc::mem_fun (*this, &ButtonJoiner::action_toggled));
132 _action->connect_property_changed ("sensitive", sigc::mem_fun (*this, &ButtonJoiner::action_sensitivity_changed));
133 _action->connect_property_changed ("visible", sigc::mem_fun (*this, &ButtonJoiner::action_visibility_changed));
134 _action->connect_property_changed ("tooltip", sigc::mem_fun (*this, &ButtonJoiner::action_tooltip_changed));
139 ButtonJoiner::action_sensitivity_changed ()
141 if (_action->property_sensitive ()) {
142 set_visual_state (Gtkmm2ext::VisualState (visual_state() & ~Gtkmm2ext::Insensitive));
144 set_visual_state (Gtkmm2ext::VisualState (visual_state() | Gtkmm2ext::Insensitive));
150 ButtonJoiner::action_visibility_changed ()
152 if (_action->property_visible ()) {
160 ButtonJoiner::action_tooltip_changed ()
162 std::string str = _action->property_tooltip().get_value();
163 ARDOUR_UI::instance()->set_tip (*this, str);
167 ButtonJoiner::action_toggled ()
169 Glib::RefPtr<ToggleAction> tact = Glib::RefPtr<ToggleAction>::cast_dynamic (_action);
172 set_active (tact->get_active());
177 ButtonJoiner::set_active_state (Gtkmm2ext::ActiveState s)
179 bool changed = (_active_state != s);
180 CairoWidget::set_active_state (s);
187 ButtonJoiner::set_colors ()
189 uint32_t start_color;
193 if (active_fill_pattern) {
194 cairo_pattern_destroy (active_fill_pattern);
195 cairo_pattern_destroy (inactive_fill_pattern);
198 active_fill_pattern = cairo_pattern_create_linear (0.0, 0.0, 0.0, get_height());
199 inactive_fill_pattern = cairo_pattern_create_linear (0.0, 0.0, 0.0, get_height());
201 start_color = ARDOUR_UI::config()->color_by_name (string_compose ("%1: fill start", name));
202 end_color = ARDOUR_UI::config()->color_by_name (string_compose ("%1: fill end", name));
203 UINT_TO_RGBA (start_color, &r, &g, &b, &a);
204 cairo_pattern_add_color_stop_rgba (inactive_fill_pattern, 0, r/255.0,g/255.0,b/255.0, a/255.0);
205 UINT_TO_RGBA (end_color, &r, &g, &b, &a);
206 cairo_pattern_add_color_stop_rgba (inactive_fill_pattern, 1, r/255.0,g/255.0,b/255.0, a/255.0);
208 start_color = ARDOUR_UI::config()->color_by_name (string_compose ("%1: fill start active", name));
209 end_color = ARDOUR_UI::config()->color_by_name (string_compose ("%1: fill end active", name));
210 UINT_TO_RGBA (start_color, &r, &g, &b, &a);
211 cairo_pattern_add_color_stop_rgba (active_fill_pattern, 0, r/255.0,g/255.0,b/255.0, a/255.0);
212 UINT_TO_RGBA (end_color, &r, &g, &b, &a);
213 cairo_pattern_add_color_stop_rgba (active_fill_pattern, 1, r/255.0,g/255.0,b/255.0, a/255.0);