Changing active-state needs no color lookup
[ardour.git] / libs / widgets / ardour_button.cc
1 /*
2  * Copyright (C) 2010 Paul Davis <paul@linuxaudiosystems.com>
3  * Copyright (C) 2017-2018 Robin Gareus <robin@gareus.org>
4  *
5  * This program is free software; you can redistribute it and/or modify
6  * it under the terms of the GNU General Public License as published by
7  * the Free Software Foundation; either version 2 of the License, or
8  * (at your option) any later version.
9  *
10  * This program is distributed in the hope that it will be useful,
11  * but WITHOUT ANY WARRANTY; without even the implied warranty of
12  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
13  * GNU General Public License for more details.
14  *
15  * You should have received a copy of the GNU General Public License along
16  * with this program; if not, write to the Free Software Foundation, Inc.,
17  * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
18  */
19
20 #include <iostream>
21 #include <cmath>
22 #include <algorithm>
23
24 #include <pangomm/layout.h>
25 #include <gtkmm/toggleaction.h>
26
27 #include "pbd/compose.h"
28 #include "pbd/controllable.h"
29 #include "pbd/error.h"
30 #include "pbd/stacktrace.h"
31
32 #include "gtkmm2ext/colors.h"
33 #include "gtkmm2ext/gui_thread.h"
34 #include "gtkmm2ext/rgb_macros.h"
35 #include "gtkmm2ext/utils.h"
36
37 #include "widgets/ardour_button.h"
38 #include "widgets/tooltips.h"
39 #include "widgets/ui_config.h"
40
41 #include "pbd/i18n.h"
42
43 #define BASELINESTRETCH (1.25)
44 #define TRACKHEADERBTNW (3.10)
45
46 using namespace Gtk;
47 using namespace Glib;
48 using namespace PBD;
49 using namespace ArdourWidgets;
50 using std::max;
51 using std::min;
52 using namespace std;
53
54 ArdourButton::Element ArdourButton::default_elements = ArdourButton::Element (ArdourButton::Edge|ArdourButton::Body|ArdourButton::Text);
55 ArdourButton::Element ArdourButton::led_default_elements = ArdourButton::Element (ArdourButton::default_elements|ArdourButton::Indicator);
56 ArdourButton::Element ArdourButton::just_led_default_elements = ArdourButton::Element (ArdourButton::Edge|ArdourButton::Body|ArdourButton::Indicator);
57
58 ArdourButton::ArdourButton (Element e, bool toggle)
59         : _sizing_text("")
60         , _markup (false)
61         , _elements (e)
62         , _icon (ArdourIcon::NoIcon)
63         , _icon_render_cb (0)
64         , _icon_render_cb_data (0)
65         , _tweaks (Tweaks (0))
66         , _char_pixel_width (0)
67         , _char_pixel_height (0)
68         , _char_avg_pixel_width (0)
69         , _text_width (0)
70         , _text_height (0)
71         , _diameter (0)
72         , _corner_radius (3.5)
73         , _corner_mask (0xf)
74         , _angle(0)
75         , _xalign(.5)
76         , _yalign(.5)
77         , fill_inactive_color (0)
78         , fill_active_color (0)
79         , text_active_color(0)
80         , text_inactive_color(0)
81         , led_active_color(0)
82         , led_inactive_color(0)
83         , led_custom_color (0)
84         , use_custom_led_color (false)
85         , convex_pattern (0)
86         , concave_pattern (0)
87         , led_inset_pattern (0)
88         , _led_rect (0)
89         , _act_on_release (true)
90         , _auto_toggle (toggle)
91         , _led_left (false)
92         , _distinct_led_click (false)
93         , _hovering (false)
94         , _focused (false)
95         , _fixed_colors_set (false)
96         , _fallthrough_to_parent (false)
97         , _layout_ellipsize_width (-1)
98         , _ellipsis (Pango::ELLIPSIZE_NONE)
99         , _update_colors (true)
100         , _pattern_height (0)
101 {
102         UIConfigurationBase::instance().ColorsChanged.connect (sigc::mem_fun (*this, &ArdourButton::color_handler));
103         /* This is not provided by gtkmm */
104         signal_grab_broken_event().connect (sigc::mem_fun (*this, &ArdourButton::on_grab_broken_event));
105 }
106
107 ArdourButton::ArdourButton (const std::string& str, Element e, bool toggle)
108         : _sizing_text("")
109         , _markup (false)
110         , _elements (e)
111         , _icon (ArdourIcon::NoIcon)
112         , _tweaks (Tweaks (0))
113         , _char_pixel_width (0)
114         , _char_pixel_height (0)
115         , _char_avg_pixel_width (0)
116         , _text_width (0)
117         , _text_height (0)
118         , _diameter (0)
119         , _corner_radius (3.5)
120         , _corner_mask (0xf)
121         , _angle(0)
122         , _xalign(.5)
123         , _yalign(.5)
124         , fill_inactive_color (0)
125         , fill_active_color (0)
126         , text_active_color(0)
127         , text_inactive_color(0)
128         , led_active_color(0)
129         , led_inactive_color(0)
130         , led_custom_color (0)
131         , use_custom_led_color (false)
132         , convex_pattern (0)
133         , concave_pattern (0)
134         , led_inset_pattern (0)
135         , _led_rect (0)
136         , _act_on_release (true)
137         , _auto_toggle (toggle)
138         , _led_left (false)
139         , _distinct_led_click (false)
140         , _hovering (false)
141         , _focused (false)
142         , _fixed_colors_set (false)
143         , _fallthrough_to_parent (false)
144         , _layout_ellipsize_width (-1)
145         , _ellipsis (Pango::ELLIPSIZE_NONE)
146         , _update_colors (true)
147         , _pattern_height (0)
148 {
149         set_text (str);
150         UIConfigurationBase::instance().ColorsChanged.connect (sigc::mem_fun (*this, &ArdourButton::color_handler));
151         UIConfigurationBase::instance().DPIReset.connect (sigc::mem_fun (*this, &ArdourButton::on_name_changed));
152         /* This is not provided by gtkmm */
153         signal_grab_broken_event().connect (sigc::mem_fun (*this, &ArdourButton::on_grab_broken_event));
154 }
155
156 ArdourButton::~ArdourButton()
157 {
158         delete _led_rect;
159
160         if (convex_pattern) {
161                 cairo_pattern_destroy (convex_pattern);
162         }
163
164         if (concave_pattern) {
165                 cairo_pattern_destroy (concave_pattern);
166         }
167
168         if (led_inset_pattern) {
169                 cairo_pattern_destroy (led_inset_pattern);
170         }
171 }
172
173 void
174 ArdourButton::set_layout_font (const Pango::FontDescription& fd)
175 {
176         ensure_layout ();
177         if (_layout) {
178                 _layout->set_font_description (fd);
179                 queue_resize ();
180                 _char_pixel_width = 0;
181                 _char_pixel_height = 0;
182         }
183 }
184
185 void
186 ArdourButton::set_text_internal () {
187         assert (_layout);
188         if (_markup) {
189                 _layout->set_markup (_text);
190         } else {
191                 _layout->set_text (_text);
192         }
193 }
194
195 void
196 ArdourButton::set_text (const std::string& str, bool markup)
197 {
198         if (!(_elements & Text)) {
199                 return;
200         }
201         if (_text == str && _markup == markup) {
202                 return;
203         }
204
205         _text = str;
206         _markup = markup;
207         if (!is_realized()) {
208                 return;
209         }
210         ensure_layout ();
211         if (_layout && _layout->get_text() != _text) {
212                 set_text_internal ();
213                 /* on_size_request() will fill in _text_width/height
214                  * so queue it even if _sizing_text != "" */
215                 queue_resize ();
216         }
217 }
218
219 void
220 ArdourButton::set_sizing_text (const std::string& str)
221 {
222         if (_sizing_text == str) {
223                 return;
224         }
225         _sizing_text = str;
226         queue_resize ();
227 }
228
229 void
230 ArdourButton::set_angle (const double angle)
231 {
232         _angle = angle;
233 }
234
235 void
236 ArdourButton::set_alignment (const float xa, const float ya)
237 {
238         _xalign = xa;
239         _yalign = ya;
240 }
241
242
243 /* TODO make this a dedicated function elsewhere.
244  *
245  * Option 1:
246  * virtual ArdourButton::render_vector_icon()
247  * ArdourIconButton::render_vector_icon
248  *
249  * Option 2:
250  * ARDOUR_UI_UTILS::render_vector_icon()
251  */
252 void
253 ArdourButton::render (Cairo::RefPtr<Cairo::Context> const& ctx, cairo_rectangle_t*)
254 {
255         cairo_t* cr = ctx->cobj();
256
257         uint32_t text_color;
258         uint32_t led_color;
259
260         const float corner_radius = _boxy_buttons ? 0 : std::max(2.f, _corner_radius * UIConfigurationBase::instance().get_ui_scale());
261
262         if (_update_colors) {
263                 set_colors ();
264         }
265         if (get_height() != _pattern_height) {
266                 build_patterns ();
267         }
268
269         if ( active_state() == Gtkmm2ext::ExplicitActive ) {
270                 text_color = text_active_color;
271                 led_color = led_active_color;
272         } else {
273                 text_color = text_inactive_color;
274                 led_color = led_inactive_color;
275         }
276
277         if (use_custom_led_color) {
278                 led_color = led_custom_color;
279         }
280
281         void (*rounded_function)(cairo_t*, double, double, double, double, double);
282
283         switch (_corner_mask) {
284         case 0x1: /* upper left only */
285                 rounded_function = Gtkmm2ext::rounded_top_left_rectangle;
286                 break;
287         case 0x2: /* upper right only */
288                 rounded_function = Gtkmm2ext::rounded_top_right_rectangle;
289                 break;
290         case 0x3: /* upper only */
291                 rounded_function = Gtkmm2ext::rounded_top_rectangle;
292                 break;
293                 /* should really have functions for lower right, lower left,
294                    lower only, but for now, we don't
295                 */
296         default:
297                 rounded_function = Gtkmm2ext::rounded_rectangle;
298         }
299
300         // draw edge (filling a rect underneath, rather than stroking a border on top, allows the corners to be lighter-weight.
301         if ((_elements & (Body|Edge)) == (Body|Edge)) {
302                 rounded_function (cr, 0, 0, get_width(), get_height(), corner_radius + 1.5);
303                 cairo_set_source_rgba (cr, 0, 0, 0, 1);
304                 cairo_fill(cr);
305         }
306
307         // background fill
308         if ((_elements & Body)==Body) {
309                 rounded_function (cr, 1, 1, get_width() - 2, get_height() - 2, corner_radius);
310                 if (active_state() == Gtkmm2ext::ImplicitActive && !((_elements & Indicator)==Indicator)) {
311                         Gtkmm2ext::set_source_rgba (cr, fill_inactive_color);
312                         cairo_fill (cr);
313                 } else if ( (active_state() == Gtkmm2ext::ExplicitActive) && !((_elements & Indicator)==Indicator) ) {
314                         //background color
315                         Gtkmm2ext::set_source_rgba (cr, fill_active_color);
316                         cairo_fill (cr);
317                 } else {  //inactive, or it has an indicator
318                         //background color
319                         Gtkmm2ext::set_source_rgba (cr, fill_inactive_color);
320                 }
321                 cairo_fill (cr);
322         }
323
324         // IMPLICIT ACTIVE: draw a border of the active color
325         if ((_elements & Body)==Body) {
326                 if (active_state() == Gtkmm2ext::ImplicitActive && !((_elements & Indicator)==Indicator)) {
327                         cairo_set_line_width (cr, 2.0);
328                         rounded_function (cr, 2, 2, get_width() - 4, get_height() - 4, corner_radius-0.5);
329                         Gtkmm2ext::set_source_rgba (cr, fill_active_color);
330                         cairo_stroke (cr);
331                 }
332         }
333
334         //show the "convex" or "concave" gradient
335         if (!_flat_buttons && (_elements & Body)==Body) {
336                 if ( active_state() == Gtkmm2ext::ExplicitActive && ( !((_elements & Indicator)==Indicator) || use_custom_led_color) ) {
337                         //concave
338                         cairo_set_source (cr, concave_pattern);
339                         Gtkmm2ext::rounded_rectangle (cr, 1, 1, get_width() - 2, get_height() - 2, corner_radius);
340                         cairo_fill (cr);
341                 } else {
342                         cairo_set_source (cr, convex_pattern);
343                         Gtkmm2ext::rounded_rectangle (cr, 1, 1, get_width() - 2, get_height() - 2, corner_radius);
344                         cairo_fill (cr);
345                 }
346         }
347
348         const int text_margin = char_pixel_width();
349
350         //Pixbuf, if any
351         if (_pixbuf) {
352                 double x = rint((get_width() - _pixbuf->get_width()) * .5);
353                 const double y = rint((get_height() - _pixbuf->get_height()) * .5);
354 #if 0 // DEBUG style (print on hover)
355                 if (_hovering || (_elements & Inactive)) {
356                         printf("%s: p:%dx%d (%dx%d)\n",
357                                         get_name().c_str(),
358                                         _pixbuf->get_width(), _pixbuf->get_height(),
359                                         get_width(), get_height());
360                 }
361 #endif
362                 if (_elements & Menu) {
363                         //if this is a DropDown with an icon, then we need to
364                         //move the icon left slightly to accomomodate the arrow
365                         x -= _diameter - 2;
366                 }
367                 cairo_rectangle (cr, x, y, _pixbuf->get_width(), _pixbuf->get_height());
368                 gdk_cairo_set_source_pixbuf (cr, _pixbuf->gobj(), x, y);
369                 cairo_fill (cr);
370         }
371         else /* VectorIcon, IconRenderCallback are exclusive to Pixbuf Icons */
372         if (_elements & (VectorIcon | IconRenderCallback)) {
373                 int vw = get_width();
374                 int vh = get_height();
375                 cairo_save (cr);
376
377                 if (_elements & Menu) {
378                         vw -= _diameter + 4;
379                 }
380                 if (_elements & Indicator) {
381                         vw -= _diameter + .5 * text_margin;
382                         if (_led_left) {
383                                 cairo_translate (cr, _diameter + text_margin, 0);
384                         }
385                 }
386                 if (_elements & Text) {
387                         vw -= _text_width + text_margin;
388                 }
389                 if (_elements & VectorIcon) {
390                         ArdourIcon::render (cr, _icon, vw, vh, active_state(), text_color);
391                 } else {
392                         rounded_function (cr, 0, 0, get_width(), get_height(), corner_radius + 1.5);
393                         cairo_clip (cr);
394                         _icon_render_cb (cr, vw, vh, text_color, _icon_render_cb_data);
395                 }
396                 cairo_restore (cr);
397         }
398
399         // Text, if any
400         if (!_pixbuf && ((_elements & Text)==Text) && !_text.empty()) {
401                 assert(_layout);
402 #if 0 // DEBUG style (print on hover)
403                 if (_hovering || (_elements & Inactive)) {
404                         bool layout_font = true;
405                         Pango::FontDescription fd = _layout->get_font_description();
406                         if (fd.gobj() == NULL) {
407                                 layout_font = false;
408                                 fd = get_pango_context()->get_font_description();
409                         }
410                         printf("%s: f:%dx%d aw:%.3f bh:%.0f t:%dx%d (%dx%d) %s\"%s\"\n",
411                                         get_name().c_str(),
412                                         char_pixel_width(), char_pixel_height(), char_avg_pixel_width(),
413                                         ceil(char_pixel_height() * BASELINESTRETCH),
414                                         _text_width, _text_height,
415                                         get_width(), get_height(),
416                                         layout_font ? "L:" : "W:",
417                                         fd.to_string().c_str());
418                 }
419 #endif
420
421                 cairo_save (cr);
422                 cairo_rectangle (cr, 2, 1, get_width() - 4, get_height() - 2);
423                 cairo_clip(cr);
424
425                 cairo_new_path (cr);
426                 Gtkmm2ext::set_source_rgba (cr, text_color);
427                 const double text_ypos = (get_height() - _text_height) * .5;
428
429                 if (_elements & Menu) {
430                         // always left align (dropdown)
431                         cairo_move_to (cr, text_margin, text_ypos);
432                         pango_cairo_show_layout (cr, _layout->gobj());
433                 } else if ( (_elements & Indicator)  == Indicator) {
434                         // left/right align depending on LED position
435                         if (_led_left) {
436                                 cairo_move_to (cr, text_margin + _diameter + .5 * char_pixel_width(), text_ypos);
437                         } else {
438                                 cairo_move_to (cr, text_margin, text_ypos);
439                         }
440                         pango_cairo_show_layout (cr, _layout->gobj());
441                 } else if (VectorIcon == (_elements & VectorIcon)) {
442                         cairo_move_to (cr, get_width () - text_margin - _text_width, text_ypos);
443                         pango_cairo_show_layout (cr, _layout->gobj());
444                 } else {
445                         /* centered text otherwise */
446                         double ww, wh;
447                         double xa, ya;
448                         ww = get_width();
449                         wh = get_height();
450
451                         cairo_matrix_t m1;
452                         cairo_get_matrix (cr, &m1);
453                         cairo_matrix_t m2 = m1;
454                         m2.x0 = 0;
455                         m2.y0 = 0;
456                         cairo_set_matrix (cr, &m2);
457
458                         if (_angle) {
459                                 cairo_rotate(cr, _angle * M_PI / 180.0);
460                         }
461
462                         cairo_device_to_user(cr, &ww, &wh);
463                         xa = text_margin + (ww - _text_width - 2 * text_margin) * _xalign;
464                         ya = (wh - _text_height) * _yalign;
465
466                         /* quick hack for left/bottom alignment at -90deg
467                          * TODO this should be generalized incl rotation.
468                          * currently only 'user' of this API is meter_strip.cc
469                          */
470                         if (_xalign < 0) xa = ceil(.5 + (ww * fabs(_xalign) + text_margin));
471
472                         cairo_move_to (cr, xa + m1.x0, ya + m1.y0);
473                         pango_cairo_update_layout(cr, _layout->gobj());
474                         pango_cairo_show_layout (cr, _layout->gobj());
475                 }
476                 cairo_restore (cr);
477         }
478
479         //Menu "triangle"
480         if (_elements & Menu) {
481                 const float trih = ceil(_diameter * .5);
482                 const float triw2 = ceil(.577 * _diameter * .5); // 1/sqrt(3) Equilateral triangle
483                 //menu arrow
484                 cairo_set_source_rgba (cr, 1, 1, 1, 0.4);
485                 cairo_move_to(cr, get_width() - triw2 - 3. , rint((get_height() + trih) * .5));
486                 cairo_rel_line_to(cr, -triw2, -trih);
487                 cairo_rel_line_to(cr, 2. * triw2, 0);
488                 cairo_close_path(cr);
489
490                 cairo_set_source_rgba (cr, 1, 1, 1, 0.4);
491                 cairo_fill(cr);
492
493                 cairo_move_to(cr, get_width() - triw2 - 3 , rint((get_height() + trih) * .5));
494                 cairo_rel_line_to(cr, .5 - triw2, .5 - trih);
495                 cairo_rel_line_to(cr, 2. * triw2 - 1, 0);
496                 cairo_close_path(cr);
497                 cairo_set_source_rgba (cr, 0, 0, 0, 0.8);
498                 cairo_set_line_width(cr, 1);
499                 cairo_stroke(cr);
500         }
501
502         //Indicator LED
503         if (_elements & Indicator) {
504                 cairo_save (cr);
505
506                 /* move to the center of the indicator/led */
507                 if (_elements & (Text | VectorIcon | IconRenderCallback)) {
508                         int led_xoff = ceil((char_pixel_width() + _diameter) * .5);
509                         if (_led_left) {
510                                 cairo_translate (cr, led_xoff, get_height() * .5);
511                         } else {
512                                 cairo_translate (cr, get_width() - led_xoff, get_height() * .5);
513                         }
514                 } else {
515                         cairo_translate (cr, get_width() * .5, get_height() * .5);
516                 }
517
518                 //inset
519                 if (!_flat_buttons) {
520                         cairo_arc (cr, 0, 0, _diameter * .5, 0, 2 * M_PI);
521                         cairo_set_source (cr, led_inset_pattern);
522                         cairo_fill (cr);
523                 }
524
525                 //black ring
526                 cairo_set_source_rgb (cr, 0, 0, 0);
527                 cairo_arc (cr, 0, 0, _diameter * .5 - 1 * UIConfigurationBase::instance().get_ui_scale(), 0, 2 * M_PI);
528                 cairo_fill(cr);
529
530                 //led color
531                 Gtkmm2ext::set_source_rgba (cr, led_color);
532                 cairo_arc (cr, 0, 0, _diameter * .5 - 3 * UIConfigurationBase::instance().get_ui_scale(), 0, 2 * M_PI);
533                 cairo_fill(cr);
534
535                 cairo_restore (cr);
536         }
537
538         // a transparent overlay to indicate insensitivity
539         if ((visual_state() & Gtkmm2ext::Insensitive)) {
540                 rounded_function (cr, 0, 0, get_width(), get_height(), corner_radius);
541                 uint32_t ins_color = UIConfigurationBase::instance().color ("gtk_background");
542                 Gtkmm2ext::set_source_rgb_a (cr, ins_color, 0.6);
543                 cairo_fill (cr);
544         }
545
546         // if requested, show hovering
547         if (UIConfigurationBase::instance().get_widget_prelight()
548                         && !((visual_state() & Gtkmm2ext::Insensitive))) {
549                 if (_hovering) {
550                         rounded_function (cr, 1, 1, get_width() - 2, get_height() - 2, corner_radius);
551                         cairo_set_source_rgba (cr, 0.905, 0.917, 0.925, 0.2);
552                         cairo_fill (cr);
553                 }
554         }
555
556         //user is currently pressing the button. dark outline helps to indicate this
557         if (_grabbed && !(_elements & (Inactive|Menu))) {
558                 rounded_function (cr, 1, 1, get_width() - 2, get_height() - 2, corner_radius);
559                 cairo_set_line_width(cr, 2);
560                 cairo_set_source_rgba (cr, 0.1, 0.1, 0.1, .5);
561                 cairo_stroke (cr);
562         }
563
564         //some buttons (like processor boxes) can be selected  (so they can be deleted).  Draw a selection indicator
565         if (visual_state() & Gtkmm2ext::Selected) {
566                 cairo_set_line_width(cr, 1);
567                 cairo_set_source_rgba (cr, 1, 0, 0, 0.8);
568                 rounded_function (cr, 0.5, 0.5, get_width() - 1, get_height() - 1, corner_radius);
569                 cairo_stroke (cr);
570         }
571
572         //I guess this means we have keyboard focus.  I don't think this works currently
573         //
574         //A: yes, it's keyboard focus and it does work when there's no editor window
575         //   (the editor is always the first receiver for KeyDown).
576         //   It's needed for eg. the engine-dialog at startup or after closing a sesion.
577         if (_focused) {
578                 rounded_function (cr, 1.5, 1.5, get_width() - 3, get_height() - 3, corner_radius);
579                 cairo_set_source_rgba (cr, 0.905, 0.917, 0.925, 0.8);
580                 double dashes = 1;
581                 cairo_set_dash (cr, &dashes, 1, 0);
582                 cairo_set_line_cap (cr, CAIRO_LINE_CAP_BUTT);
583                 cairo_set_line_width (cr, 1.0);
584                 cairo_stroke (cr);
585                 cairo_set_dash (cr, 0, 0, 0);
586         }
587 }
588
589 void
590 ArdourButton::set_corner_radius (float r)
591 {
592         _corner_radius = r;
593         CairoWidget::set_dirty ();
594 }
595
596 void
597 ArdourButton::on_realize()
598 {
599         CairoWidget::on_realize ();
600         ensure_layout ();
601         if (_layout) {
602                 if (_layout->get_text() != _text) {
603                         set_text_internal ();
604                         queue_resize ();
605                 }
606         }
607 }
608
609 void
610 ArdourButton::on_size_request (Gtk::Requisition* req)
611 {
612         req->width = req->height = 0;
613         CairoWidget::on_size_request (req);
614
615         if (_diameter == 0) {
616                 const float newdia = rintf (11.f * UIConfigurationBase::instance().get_ui_scale());
617                 if (_diameter != newdia) {
618                         _pattern_height = 0;
619                         _diameter = newdia;
620                 }
621         }
622
623         if (_elements & Text) {
624
625                 ensure_layout();
626                 set_text_internal ();
627
628                 /* render() needs the size of the displayed text */
629                 _layout->get_pixel_size (_text_width, _text_height);
630
631                 if (_tweaks & OccasionalText) {
632
633                         /* size should not change based on presence or absence
634                          * of text.
635                          */
636
637                 } else if (_layout_ellipsize_width > 0 && _sizing_text.empty()) {
638
639                         req->height = std::max(req->height, (int) ceil(char_pixel_height() * BASELINESTRETCH + 1.0));
640                         req->width += _layout_ellipsize_width / PANGO_SCALE;
641
642                 } else /*if (!_text.empty() || !_sizing_text.empty()) */ {
643
644                         req->height = std::max(req->height, (int) ceil(char_pixel_height() * BASELINESTRETCH + 1.0));
645                         req->width += rint(1.75 * char_pixel_width()); // padding
646
647                         if (!_sizing_text.empty()) {
648                                 _layout->set_text (_sizing_text); /* use sizing text */
649                         }
650
651                         int sizing_text_width = 0, sizing_text_height = 0;
652                         _layout->get_pixel_size (sizing_text_width, sizing_text_height);
653
654                         req->width += sizing_text_width;
655
656                         if (!_sizing_text.empty()) {
657                                 set_text_internal (); /* restore display text */
658                         }
659                 }
660
661                 /* XXX hack (surprise). Deal with two common rotation angles */
662
663                 if (_angle == 90 || _angle == 270) {
664                         /* do not swap text width or height because we rely on
665                            these being the un-rotated values in ::render()
666                         */
667                         swap (req->width, req->height);
668                 }
669
670         } else {
671                 _text_width = 0;
672                 _text_height = 0;
673         }
674
675         if (_pixbuf) {
676                 req->width += _pixbuf->get_width() + char_pixel_width();
677                 req->height = std::max(req->height, _pixbuf->get_height() + 4);
678         }
679
680         if (_elements & Indicator) {
681                 req->width += ceil (_diameter + char_pixel_width());
682                 req->height = std::max (req->height, (int) lrint (_diameter) + 4);
683         }
684
685         if ((_elements & Menu)) {
686                 req->width += _diameter + 4;
687         }
688
689         if (_elements & (VectorIcon | IconRenderCallback)) {
690                 const int wh = std::max (8., std::max (ceil (TRACKHEADERBTNW * char_avg_pixel_width()), ceil (char_pixel_height() * BASELINESTRETCH + 1.)));
691                 req->width += wh;
692                 req->height = std::max(req->height, wh);
693         }
694
695         /* Tweaks to mess the nice stuff above up again. */
696         if (_tweaks & TrackHeader) {
697                 // forget everything above and just use a fixed square [em] size
698                 // "TrackHeader Buttons" are single letter (usually uppercase)
699                 // a SizeGroup is much less efficient (lots of gtk work under the hood for each track)
700                 const int wh = std::max (rint (TRACKHEADERBTNW * char_avg_pixel_width()), ceil (char_pixel_height() * BASELINESTRETCH + 1.));
701                 req->width  = wh;
702                 req->height = wh;
703         }
704         else if (_tweaks & Square) {
705                 // currerntly unused (again)
706                 if (req->width < req->height)
707                         req->width = req->height;
708                 if (req->height < req->width)
709                         req->height = req->width;
710         } else if (_sizing_text.empty() && _text_width > 0 && !(_elements & Menu)) {
711                 // properly centered text for those elements that are centered
712                 // (no sub-pixel offset)
713                 if ((req->width - _text_width) & 1) { ++req->width; }
714                 if ((req->height - _text_height) & 1) { ++req->height; }
715         }
716 #if 0
717                 printf("REQ: %s: %dx%d\n", get_name().c_str(), req->width, req->height);
718 #endif
719 }
720
721 /**
722  * This sets the colors used for rendering based on the name of the button, and
723  * thus uses information from the GUI config data.
724  */
725 void
726 ArdourButton::set_colors ()
727 {
728         _update_colors = false;
729
730         if (_fixed_colors_set == 0x3) {
731                 return;
732         }
733
734         std::string name = get_name();
735         bool failed = false;
736
737         if (!(_fixed_colors_set & 0x1)) {
738                 fill_active_color = UIConfigurationBase::instance().color (string_compose ("%1: fill active", name), &failed);
739                 if (failed) {
740                         fill_active_color = UIConfigurationBase::instance().color ("generic button: fill active");
741                 }
742         }
743
744         if (!(_fixed_colors_set & 0x2)) {
745                 fill_inactive_color = UIConfigurationBase::instance().color (string_compose ("%1: fill", name), &failed);
746                 if (failed) {
747                         fill_inactive_color = UIConfigurationBase::instance().color ("generic button: fill");
748                 }
749         }
750
751         text_active_color = Gtkmm2ext::contrasting_text_color (fill_active_color);
752         text_inactive_color = Gtkmm2ext::contrasting_text_color (fill_inactive_color);
753
754         led_active_color = UIConfigurationBase::instance().color (string_compose ("%1: led active", name), &failed);
755         if (failed) {
756                 led_active_color = UIConfigurationBase::instance().color ("generic button: led active");
757         }
758
759         /* The inactive color for the LED is just a fairly dark version of the
760          * active color.
761          */
762
763         Gtkmm2ext::HSV inactive (led_active_color);
764         inactive.v = 0.35;
765
766         led_inactive_color = inactive.color ();
767 }
768
769 /**
770  * This sets the colors used for rendering based on two fixed values, rather
771  * than basing them on the button name, and thus information in the GUI config
772  * data.
773  */
774 void ArdourButton::set_fixed_colors (const uint32_t color_active, const uint32_t color_inactive)
775 {
776         set_active_color (color_active);
777         set_inactive_color (color_inactive);
778 }
779
780 void ArdourButton::set_active_color (const uint32_t color)
781 {
782         _fixed_colors_set |= 0x1;
783
784         fill_active_color = color;
785
786         unsigned char r, g, b, a;
787         UINT_TO_RGBA(color, &r, &g, &b, &a);
788
789         double white_contrast = (max (double(r), 255.) - min (double(r), 255.)) +
790                 (max (double(g), 255.) - min (double(g), 255.)) +
791                 (max (double(b), 255.) - min (double(b), 255.));
792
793         double black_contrast = (max (double(r), 0.) - min (double(r), 0.)) +
794                 (max (double(g), 0.) - min (double(g), 0.)) +
795                 (max (double(b), 0.) - min (double(b), 0.));
796
797         text_active_color = (white_contrast > black_contrast) ?
798                 RGBA_TO_UINT(255, 255, 255, 255) : /* use white */
799                 RGBA_TO_UINT(  0,   0,   0,   255);  /* use black */
800
801         /* XXX what about led colors ? */
802         CairoWidget::set_dirty ();
803 }
804
805 void ArdourButton::set_inactive_color (const uint32_t color)
806 {
807         _fixed_colors_set |= 0x2;
808
809         fill_inactive_color = color;
810
811         unsigned char r, g, b, a;
812         UINT_TO_RGBA(color, &r, &g, &b, &a);
813
814         double white_contrast = (max (double(r), 255.) - min (double(r), 255.)) +
815                 (max (double(g), 255.) - min (double(g), 255.)) +
816                 (max (double(b), 255.) - min (double(b), 255.));
817
818         double black_contrast = (max (double(r), 0.) - min (double(r), 0.)) +
819                 (max (double(g), 0.) - min (double(g), 0.)) +
820                 (max (double(b), 0.) - min (double(b), 0.));
821
822         text_inactive_color = (white_contrast > black_contrast) ?
823                 RGBA_TO_UINT(255, 255, 255, 255) : /* use white */
824                 RGBA_TO_UINT(  0,   0,   0,   255);  /* use black */
825
826         /* XXX what about led colors ? */
827         CairoWidget::set_dirty ();
828 }
829
830 void
831 ArdourButton::build_patterns ()
832 {
833         if (convex_pattern) {
834                 cairo_pattern_destroy (convex_pattern);
835                 convex_pattern = 0;
836         }
837
838         if (concave_pattern) {
839                 cairo_pattern_destroy (concave_pattern);
840                 concave_pattern = 0;
841         }
842
843         if (led_inset_pattern) {
844                 cairo_pattern_destroy (led_inset_pattern);
845                 led_inset_pattern = 0;
846         }
847
848         //convex gradient
849         convex_pattern = cairo_pattern_create_linear (0.0, 0, 0.0,  get_height());
850         cairo_pattern_add_color_stop_rgba (convex_pattern, 0.0, 0,0,0, 0.0);
851         cairo_pattern_add_color_stop_rgba (convex_pattern, 1.0, 0,0,0, 0.35);
852
853         //concave gradient
854         concave_pattern = cairo_pattern_create_linear (0.0, 0, 0.0,  get_height());
855         cairo_pattern_add_color_stop_rgba (concave_pattern, 0.0, 0,0,0, 0.5);
856         cairo_pattern_add_color_stop_rgba (concave_pattern, 0.7, 0,0,0, 0.0);
857
858         led_inset_pattern = cairo_pattern_create_linear (0.0, 0.0, 0.0, _diameter);
859         cairo_pattern_add_color_stop_rgba (led_inset_pattern, 0, 0,0,0, 0.4);
860         cairo_pattern_add_color_stop_rgba (led_inset_pattern, 1, 1,1,1, 0.7);
861
862         _pattern_height = get_height() ;
863 }
864
865 void
866 ArdourButton::set_led_left (bool yn)
867 {
868         _led_left = yn;
869 }
870
871 bool
872 ArdourButton::on_button_press_event (GdkEventButton *ev)
873 {
874         focus_handler (this);
875
876         if (ev->type == GDK_2BUTTON_PRESS || ev->type == GDK_3BUTTON_PRESS) {
877                 return _fallthrough_to_parent ? false : true;
878         }
879
880         if (ev->button == 1 && (_elements & Indicator) && _led_rect && _distinct_led_click) {
881                 if (ev->x >= _led_rect->x && ev->x < _led_rect->x + _led_rect->width &&
882                     ev->y >= _led_rect->y && ev->y < _led_rect->y + _led_rect->height) {
883                         return true;
884                 }
885         }
886
887         if (binding_proxy.button_press_handler (ev)) {
888                 return true;
889         }
890
891         _grabbed = true;
892         CairoWidget::set_dirty ();
893
894         if (ev->button == 1 && !_act_on_release) {
895                 if (_action) {
896                         _action->activate ();
897                         return true;
898                 } else if (_auto_toggle) {
899                         set_active (!get_active ());
900                         signal_clicked ();
901                         return true;
902                 }
903         }
904
905         return _fallthrough_to_parent ? false : true;
906 }
907
908 bool
909 ArdourButton::on_button_release_event (GdkEventButton *ev)
910 {
911         if (ev->type == GDK_2BUTTON_PRESS || ev->type == GDK_3BUTTON_PRESS) {
912                 return _fallthrough_to_parent ? false : true;
913         }
914         if (ev->button == 1 && _hovering && (_elements & Indicator) && _led_rect && _distinct_led_click) {
915                 if (ev->x >= _led_rect->x && ev->x < _led_rect->x + _led_rect->width &&
916                     ev->y >= _led_rect->y && ev->y < _led_rect->y + _led_rect->height) {
917                         signal_led_clicked(ev); /* EMIT SIGNAL */
918                         return true;
919                 }
920         }
921
922         _grabbed = false;
923         CairoWidget::set_dirty ();
924
925         if (ev->button == 1 && _hovering) {
926                 if (_act_on_release && _auto_toggle && !_action) {
927                         set_active (!get_active ());
928                 }
929                 signal_clicked ();
930                 if (_act_on_release) {
931                         if (_action) {
932                                 _action->activate ();
933                                 return true;
934                         }
935                 }
936         }
937
938         return _fallthrough_to_parent ? false : true;
939 }
940
941 void
942 ArdourButton::set_distinct_led_click (bool yn)
943 {
944         _distinct_led_click = yn;
945         setup_led_rect ();
946 }
947
948 void
949 ArdourButton::color_handler ()
950 {
951         _update_colors = true;
952         CairoWidget::set_dirty ();
953 }
954
955 void
956 ArdourButton::on_size_allocate (Allocation& alloc)
957 {
958         CairoWidget::on_size_allocate (alloc);
959         setup_led_rect ();
960 }
961
962 void
963 ArdourButton::set_controllable (boost::shared_ptr<Controllable> c)
964 {
965         watch_connection.disconnect ();
966         binding_proxy.set_controllable (c);
967 }
968
969 void
970 ArdourButton::watch ()
971 {
972         boost::shared_ptr<Controllable> c (binding_proxy.get_controllable ());
973
974         if (!c) {
975                 warning << _("button cannot watch state of non-existing Controllable\n") << endmsg;
976                 return;
977         }
978         c->Changed.connect (watch_connection, invalidator(*this), boost::bind (&ArdourButton::controllable_changed, this), gui_context());
979 }
980
981 void
982 ArdourButton::controllable_changed ()
983 {
984         float val = binding_proxy.get_controllable()->get_value();
985
986         if (fabs (val) >= 0.5f) {
987                 set_active_state (Gtkmm2ext::ExplicitActive);
988         } else {
989                 unset_active_state ();
990         }
991         CairoWidget::set_dirty ();
992 }
993
994 void
995 ArdourButton::set_related_action (RefPtr<Action> act)
996 {
997         Gtkmm2ext::Activatable::set_related_action (act);
998
999         if (_action) {
1000
1001                 action_tooltip_changed ();
1002                 action_sensitivity_changed ();
1003
1004                 Glib::RefPtr<ToggleAction> tact = Glib::RefPtr<ToggleAction>::cast_dynamic (_action);
1005                 if (tact) {
1006                         action_toggled ();
1007                         tact->signal_toggled().connect (sigc::mem_fun (*this, &ArdourButton::action_toggled));
1008                 }
1009
1010                 _action->connect_property_changed ("sensitive", sigc::mem_fun (*this, &ArdourButton::action_sensitivity_changed));
1011                 _action->connect_property_changed ("visible", sigc::mem_fun (*this, &ArdourButton::action_visibility_changed));
1012                 _action->connect_property_changed ("tooltip", sigc::mem_fun (*this, &ArdourButton::action_tooltip_changed));
1013         }
1014 }
1015
1016 void
1017 ArdourButton::action_toggled ()
1018 {
1019         Glib::RefPtr<ToggleAction> tact = Glib::RefPtr<ToggleAction>::cast_dynamic (_action);
1020
1021         if (tact) {
1022                 if (tact->get_active()) {
1023                         set_active_state (Gtkmm2ext::ExplicitActive);
1024                 } else {
1025                         unset_active_state ();
1026                 }
1027         }
1028 }
1029
1030 void
1031 ArdourButton::on_style_changed (const RefPtr<Gtk::Style>&)
1032 {
1033         _update_colors = true;
1034         CairoWidget::set_dirty ();
1035         _char_pixel_width = 0;
1036         _char_pixel_height = 0;
1037         if (is_realized()) {
1038                 queue_resize ();
1039         }
1040 }
1041
1042 void
1043 ArdourButton::on_name_changed ()
1044 {
1045         _char_pixel_width = 0;
1046         _char_pixel_height = 0;
1047         _diameter = 0;
1048         _update_colors = true;
1049         if (is_realized()) {
1050                 queue_resize ();
1051         }
1052 }
1053
1054 void
1055 ArdourButton::setup_led_rect ()
1056 {
1057         if (!(_elements & Indicator)) {
1058                 delete _led_rect;
1059                 _led_rect = 0;
1060                 return;
1061         }
1062
1063         if (!_led_rect) {
1064                 _led_rect = new cairo_rectangle_t;
1065         }
1066
1067         if (_elements & Text) {
1068                 if (_led_left) {
1069                         _led_rect->x = char_pixel_width();
1070                 } else {
1071                         _led_rect->x = get_width() - char_pixel_width() + _diameter;
1072                 }
1073         } else {
1074                 /* centered */
1075                 _led_rect->x = .5 * get_width() - _diameter;
1076         }
1077
1078         _led_rect->y = .5 * (get_height() - _diameter);
1079         _led_rect->width = _diameter;
1080         _led_rect->height = _diameter;
1081 }
1082
1083 void
1084 ArdourButton::set_image (const RefPtr<Gdk::Pixbuf>& img)
1085 {
1086          _elements = (ArdourButton::Element) (_elements & ~ArdourButton::Text);
1087         _pixbuf = img;
1088         if (is_realized()) {
1089                 queue_resize ();
1090         }
1091 }
1092
1093 void
1094 ArdourButton::set_active_state (Gtkmm2ext::ActiveState s)
1095 {
1096         bool changed = (_active_state != s);
1097         CairoWidget::set_active_state (s);
1098         if (changed) {
1099                 CairoWidget::set_dirty ();
1100         }
1101 }
1102
1103 void
1104 ArdourButton::set_visual_state (Gtkmm2ext::VisualState s)
1105 {
1106         bool changed = (_visual_state != s);
1107         CairoWidget::set_visual_state (s);
1108         if (changed) {
1109                 _update_colors = true;
1110                 CairoWidget::set_dirty ();
1111         }
1112 }
1113
1114 bool
1115 ArdourButton::on_focus_in_event (GdkEventFocus* ev)
1116 {
1117         _focused = true;
1118         CairoWidget::set_dirty ();
1119         return CairoWidget::on_focus_in_event (ev);
1120 }
1121
1122 bool
1123 ArdourButton::on_focus_out_event (GdkEventFocus* ev)
1124 {
1125         _focused = false;
1126         CairoWidget::set_dirty ();
1127         return CairoWidget::on_focus_out_event (ev);
1128 }
1129
1130 bool
1131 ArdourButton::on_key_release_event (GdkEventKey *ev) {
1132         if (_act_on_release && _focused &&
1133                         (ev->keyval == GDK_space || ev->keyval == GDK_Return))
1134         {
1135                 if (_auto_toggle && !_action) {
1136                                 set_active (!get_active ());
1137                 }
1138                 signal_clicked();
1139                 if (_action) {
1140                         _action->activate ();
1141                 }
1142                 return true;
1143         }
1144         return CairoWidget::on_key_release_event (ev);
1145 }
1146
1147 bool
1148 ArdourButton::on_key_press_event (GdkEventKey *ev) {
1149         if (!_act_on_release && _focused &&
1150                         (ev->keyval == GDK_space || ev->keyval == GDK_Return))
1151         {
1152                 if (_auto_toggle && !_action) {
1153                                 set_active (!get_active ());
1154                 }
1155                 signal_clicked();
1156                 if (_action) {
1157                         _action->activate ();
1158                 }
1159                 return true;
1160         }
1161         return CairoWidget::on_key_release_event (ev);
1162 }
1163
1164 bool
1165 ArdourButton::on_enter_notify_event (GdkEventCrossing* ev)
1166 {
1167         _hovering = (_elements & Inactive) ? false : true;
1168
1169         if (UIConfigurationBase::instance().get_widget_prelight()) {
1170                 CairoWidget::set_dirty ();
1171         }
1172
1173         boost::shared_ptr<PBD::Controllable> c (binding_proxy.get_controllable ());
1174         if (c) {
1175                 PBD::Controllable::GUIFocusChanged (boost::weak_ptr<PBD::Controllable> (c));
1176         }
1177
1178         return CairoWidget::on_enter_notify_event (ev);
1179 }
1180
1181 bool
1182 ArdourButton::on_leave_notify_event (GdkEventCrossing* ev)
1183 {
1184         _hovering = false;
1185
1186         if (UIConfigurationBase::instance().get_widget_prelight()) {
1187                 CairoWidget::set_dirty ();
1188         }
1189
1190         if (binding_proxy.get_controllable()) {
1191                 PBD::Controllable::GUIFocusChanged (boost::weak_ptr<PBD::Controllable> ());
1192         }
1193
1194         return CairoWidget::on_leave_notify_event (ev);
1195 }
1196
1197 bool
1198 ArdourButton::on_grab_broken_event(GdkEventGrabBroken* grab_broken_event) {
1199         /* Our implicit grab due to a button_press was broken by another grab:
1200          * the button will not get any button_release event if the mouse leaves
1201          * while the grab is taken, so unpress ourselves */
1202         _grabbed = false;
1203         CairoWidget::set_dirty ();
1204         return true;
1205 }
1206
1207 void
1208 ArdourButton::set_tweaks (Tweaks t)
1209 {
1210         if (_tweaks != t) {
1211                 _tweaks = t;
1212                 if (is_realized()) {
1213                         queue_resize ();
1214                 }
1215         }
1216 }
1217
1218 void
1219 ArdourButton::action_sensitivity_changed ()
1220 {
1221         if (_action->property_sensitive ()) {
1222                 set_visual_state (Gtkmm2ext::VisualState (visual_state() & ~Gtkmm2ext::Insensitive));
1223         } else {
1224                 set_visual_state (Gtkmm2ext::VisualState (visual_state() | Gtkmm2ext::Insensitive));
1225         }
1226 }
1227
1228 void
1229 ArdourButton::set_layout_ellipsize_width (int w)
1230 {
1231         if (_layout_ellipsize_width == w) {
1232                 return;
1233         }
1234         _layout_ellipsize_width = w;
1235         if (!_layout) {
1236                 return;
1237         }
1238         if (_layout_ellipsize_width > 3 * PANGO_SCALE) {
1239                 _layout->set_width (_layout_ellipsize_width - 3 * PANGO_SCALE);
1240         }
1241         if (is_realized ()) {
1242                 queue_resize ();
1243         }
1244 }
1245
1246 void
1247 ArdourButton::set_text_ellipsize (Pango::EllipsizeMode e)
1248 {
1249         if (_ellipsis == e) {
1250                 return;
1251         }
1252         _ellipsis = e;
1253         if (!_layout) {
1254                 return;
1255         }
1256         _layout->set_ellipsize(_ellipsis);
1257         if (_layout_ellipsize_width > 3 * PANGO_SCALE) {
1258                 _layout->set_width (_layout_ellipsize_width - 3 * PANGO_SCALE);
1259         }
1260         if (is_realized ()) {
1261                 queue_resize ();
1262         }
1263 }
1264
1265 void
1266 ArdourButton::ensure_layout ()
1267 {
1268         if (!_layout) {
1269                 ensure_style ();
1270                 _layout = Pango::Layout::create (get_pango_context());
1271                 _layout->set_ellipsize(_ellipsis);
1272                 if (_layout_ellipsize_width > 3 * PANGO_SCALE) {
1273                         _layout->set_width (_layout_ellipsize_width - 3* PANGO_SCALE);
1274                 }
1275         }
1276 }
1277
1278 void
1279 ArdourButton::recalc_char_pixel_geometry ()
1280 {
1281         if (_char_pixel_height > 0 && _char_pixel_width > 0) {
1282                 return;
1283         }
1284         ensure_layout();
1285         // NB. this is not static, since the geometry is different
1286         // depending on the font used.
1287         int w, h;
1288         std::string x = _("@ABCDEFGHIJLKMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789");
1289         _layout->set_text (x);
1290         _layout->get_pixel_size (w, h);
1291         _char_pixel_height = std::max(4, h);
1292         // number of actual chars in the string (not bytes)
1293         // Glib to the rescue.
1294         Glib::ustring gx(x);
1295         _char_avg_pixel_width = w / (float)gx.size();
1296         _char_pixel_width = std::max(4, (int) ceil (_char_avg_pixel_width));
1297         set_text_internal (); /* restore display text */
1298 }
1299
1300 void
1301 ArdourButton::action_visibility_changed ()
1302 {
1303         if (_action->property_visible ()) {
1304                 show ();
1305         } else {
1306                 hide ();
1307         }
1308 }
1309
1310 void
1311 ArdourButton::action_tooltip_changed ()
1312 {
1313         string str = _action->property_tooltip().get_value();
1314         set_tooltip (*this, str);
1315 }
1316
1317 void
1318 ArdourButton::set_elements (Element e)
1319 {
1320         _elements = e;
1321         CairoWidget::set_dirty ();
1322 }
1323
1324 void
1325 ArdourButton::add_elements (Element e)
1326 {
1327         _elements = (ArdourButton::Element) (_elements | e);
1328         CairoWidget::set_dirty ();
1329 }
1330
1331 void
1332 ArdourButton::set_icon (ArdourIcon::Icon i)
1333 {
1334         _icon = i;
1335         _icon_render_cb = 0;
1336         _icon_render_cb_data = 0;
1337         _elements = (ArdourButton::Element) ((_elements | VectorIcon) & ~(ArdourButton::Text | IconRenderCallback));
1338         CairoWidget::set_dirty ();
1339 }
1340
1341 void
1342 ArdourButton::set_icon (rendercallback_t cb, void* d)
1343 {
1344         if (!cb) {
1345                 _elements = (ArdourButton::Element) ((_elements | ArdourButton::Text) & ~(IconRenderCallback | VectorIcon));
1346                 _icon_render_cb = 0;
1347                 _icon_render_cb_data = 0;
1348         } else {
1349                 _elements = (ArdourButton::Element) ((_elements | IconRenderCallback) & ~(ArdourButton::Text | VectorIcon));
1350                 _icon_render_cb = cb;
1351                 _icon_render_cb_data = d;
1352         }
1353         CairoWidget::set_dirty ();
1354 }
1355
1356 void
1357 ArdourButton::set_custom_led_color (uint32_t c, bool useit)
1358 {
1359         if (led_custom_color == c && use_custom_led_color == useit) {
1360                 return;
1361         }
1362
1363         led_custom_color = c;
1364         use_custom_led_color = useit;
1365         CairoWidget::set_dirty ();
1366 }