expand the test used to decide if we need to make copies when uncombining a compound...
[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 ArdourButton::reset_fixed_colors ()
831 {
832         if (_fixed_colors_set == 0) {
833                 return;
834         }
835         _fixed_colors_set = 0;
836         _update_colors = true;
837         CairoWidget::set_dirty ();
838 }
839
840 void
841 ArdourButton::build_patterns ()
842 {
843         if (convex_pattern) {
844                 cairo_pattern_destroy (convex_pattern);
845                 convex_pattern = 0;
846         }
847
848         if (concave_pattern) {
849                 cairo_pattern_destroy (concave_pattern);
850                 concave_pattern = 0;
851         }
852
853         if (led_inset_pattern) {
854                 cairo_pattern_destroy (led_inset_pattern);
855                 led_inset_pattern = 0;
856         }
857
858         //convex gradient
859         convex_pattern = cairo_pattern_create_linear (0.0, 0, 0.0,  get_height());
860         cairo_pattern_add_color_stop_rgba (convex_pattern, 0.0, 0,0,0, 0.0);
861         cairo_pattern_add_color_stop_rgba (convex_pattern, 1.0, 0,0,0, 0.35);
862
863         //concave gradient
864         concave_pattern = cairo_pattern_create_linear (0.0, 0, 0.0,  get_height());
865         cairo_pattern_add_color_stop_rgba (concave_pattern, 0.0, 0,0,0, 0.5);
866         cairo_pattern_add_color_stop_rgba (concave_pattern, 0.7, 0,0,0, 0.0);
867
868         led_inset_pattern = cairo_pattern_create_linear (0.0, 0.0, 0.0, _diameter);
869         cairo_pattern_add_color_stop_rgba (led_inset_pattern, 0, 0,0,0, 0.4);
870         cairo_pattern_add_color_stop_rgba (led_inset_pattern, 1, 1,1,1, 0.7);
871
872         _pattern_height = get_height() ;
873 }
874
875 void
876 ArdourButton::set_led_left (bool yn)
877 {
878         _led_left = yn;
879 }
880
881 bool
882 ArdourButton::on_button_press_event (GdkEventButton *ev)
883 {
884         focus_handler (this);
885
886         if (ev->type == GDK_2BUTTON_PRESS || ev->type == GDK_3BUTTON_PRESS) {
887                 return _fallthrough_to_parent ? false : true;
888         }
889
890         if (ev->button == 1 && (_elements & Indicator) && _led_rect && _distinct_led_click) {
891                 if (ev->x >= _led_rect->x && ev->x < _led_rect->x + _led_rect->width &&
892                     ev->y >= _led_rect->y && ev->y < _led_rect->y + _led_rect->height) {
893                         return true;
894                 }
895         }
896
897         if (binding_proxy.button_press_handler (ev)) {
898                 return true;
899         }
900
901         _grabbed = true;
902         CairoWidget::set_dirty ();
903
904         if (ev->button == 1 && !_act_on_release) {
905                 if (_action) {
906                         _action->activate ();
907                         return true;
908                 } else if (_auto_toggle) {
909                         set_active (!get_active ());
910                         signal_clicked ();
911                         return true;
912                 }
913         }
914
915         return _fallthrough_to_parent ? false : true;
916 }
917
918 bool
919 ArdourButton::on_button_release_event (GdkEventButton *ev)
920 {
921         if (ev->type == GDK_2BUTTON_PRESS || ev->type == GDK_3BUTTON_PRESS) {
922                 return _fallthrough_to_parent ? false : true;
923         }
924         if (ev->button == 1 && _hovering && (_elements & Indicator) && _led_rect && _distinct_led_click) {
925                 if (ev->x >= _led_rect->x && ev->x < _led_rect->x + _led_rect->width &&
926                     ev->y >= _led_rect->y && ev->y < _led_rect->y + _led_rect->height) {
927                         signal_led_clicked(ev); /* EMIT SIGNAL */
928                         return true;
929                 }
930         }
931
932         _grabbed = false;
933         CairoWidget::set_dirty ();
934
935         if (ev->button == 1 && _hovering) {
936                 if (_act_on_release && _auto_toggle && !_action) {
937                         set_active (!get_active ());
938                 }
939                 signal_clicked ();
940                 if (_act_on_release) {
941                         if (_action) {
942                                 _action->activate ();
943                                 return true;
944                         }
945                 }
946         }
947
948         return _fallthrough_to_parent ? false : true;
949 }
950
951 void
952 ArdourButton::set_distinct_led_click (bool yn)
953 {
954         _distinct_led_click = yn;
955         setup_led_rect ();
956 }
957
958 void
959 ArdourButton::color_handler ()
960 {
961         _update_colors = true;
962         CairoWidget::set_dirty ();
963 }
964
965 void
966 ArdourButton::on_size_allocate (Allocation& alloc)
967 {
968         CairoWidget::on_size_allocate (alloc);
969         setup_led_rect ();
970 }
971
972 void
973 ArdourButton::set_controllable (boost::shared_ptr<Controllable> c)
974 {
975         watch_connection.disconnect ();
976         binding_proxy.set_controllable (c);
977 }
978
979 void
980 ArdourButton::watch ()
981 {
982         boost::shared_ptr<Controllable> c (binding_proxy.get_controllable ());
983
984         if (!c) {
985                 warning << _("button cannot watch state of non-existing Controllable\n") << endmsg;
986                 return;
987         }
988         c->Changed.connect (watch_connection, invalidator(*this), boost::bind (&ArdourButton::controllable_changed, this), gui_context());
989 }
990
991 void
992 ArdourButton::controllable_changed ()
993 {
994         float val = binding_proxy.get_controllable()->get_value();
995
996         if (fabs (val) >= 0.5f) {
997                 set_active_state (Gtkmm2ext::ExplicitActive);
998         } else {
999                 unset_active_state ();
1000         }
1001         CairoWidget::set_dirty ();
1002 }
1003
1004 void
1005 ArdourButton::set_related_action (RefPtr<Action> act)
1006 {
1007         Gtkmm2ext::Activatable::set_related_action (act);
1008
1009         if (_action) {
1010
1011                 action_tooltip_changed ();
1012                 action_sensitivity_changed ();
1013
1014                 Glib::RefPtr<ToggleAction> tact = Glib::RefPtr<ToggleAction>::cast_dynamic (_action);
1015                 if (tact) {
1016                         action_toggled ();
1017                         tact->signal_toggled().connect (sigc::mem_fun (*this, &ArdourButton::action_toggled));
1018                 }
1019
1020                 _action->connect_property_changed ("sensitive", sigc::mem_fun (*this, &ArdourButton::action_sensitivity_changed));
1021                 _action->connect_property_changed ("visible", sigc::mem_fun (*this, &ArdourButton::action_visibility_changed));
1022                 _action->connect_property_changed ("tooltip", sigc::mem_fun (*this, &ArdourButton::action_tooltip_changed));
1023         }
1024 }
1025
1026 void
1027 ArdourButton::action_toggled ()
1028 {
1029         Glib::RefPtr<ToggleAction> tact = Glib::RefPtr<ToggleAction>::cast_dynamic (_action);
1030
1031         if (tact) {
1032                 if (tact->get_active()) {
1033                         set_active_state (Gtkmm2ext::ExplicitActive);
1034                 } else {
1035                         unset_active_state ();
1036                 }
1037         }
1038 }
1039
1040 void
1041 ArdourButton::on_style_changed (const RefPtr<Gtk::Style>&)
1042 {
1043         _update_colors = true;
1044         CairoWidget::set_dirty ();
1045         _char_pixel_width = 0;
1046         _char_pixel_height = 0;
1047         if (is_realized()) {
1048                 queue_resize ();
1049         }
1050 }
1051
1052 void
1053 ArdourButton::on_name_changed ()
1054 {
1055         _char_pixel_width = 0;
1056         _char_pixel_height = 0;
1057         _diameter = 0;
1058         _update_colors = true;
1059         if (is_realized()) {
1060                 queue_resize ();
1061         }
1062 }
1063
1064 void
1065 ArdourButton::setup_led_rect ()
1066 {
1067         if (!(_elements & Indicator)) {
1068                 delete _led_rect;
1069                 _led_rect = 0;
1070                 return;
1071         }
1072
1073         if (!_led_rect) {
1074                 _led_rect = new cairo_rectangle_t;
1075         }
1076
1077         if (_elements & Text) {
1078                 if (_led_left) {
1079                         _led_rect->x = char_pixel_width();
1080                 } else {
1081                         _led_rect->x = get_width() - char_pixel_width() + _diameter;
1082                 }
1083         } else {
1084                 /* centered */
1085                 _led_rect->x = .5 * get_width() - _diameter;
1086         }
1087
1088         _led_rect->y = .5 * (get_height() - _diameter);
1089         _led_rect->width = _diameter;
1090         _led_rect->height = _diameter;
1091 }
1092
1093 void
1094 ArdourButton::set_image (const RefPtr<Gdk::Pixbuf>& img)
1095 {
1096          _elements = (ArdourButton::Element) (_elements & ~ArdourButton::Text);
1097         _pixbuf = img;
1098         if (is_realized()) {
1099                 queue_resize ();
1100         }
1101 }
1102
1103 void
1104 ArdourButton::set_active_state (Gtkmm2ext::ActiveState s)
1105 {
1106         bool changed = (_active_state != s);
1107         CairoWidget::set_active_state (s);
1108         if (changed) {
1109                 _update_colors = true;
1110                 CairoWidget::set_dirty ();
1111         }
1112 }
1113
1114 void
1115 ArdourButton::set_visual_state (Gtkmm2ext::VisualState s)
1116 {
1117         bool changed = (_visual_state != s);
1118         CairoWidget::set_visual_state (s);
1119         if (changed) {
1120                 _update_colors = true;
1121                 CairoWidget::set_dirty ();
1122         }
1123 }
1124
1125 bool
1126 ArdourButton::on_focus_in_event (GdkEventFocus* ev)
1127 {
1128         _focused = true;
1129         CairoWidget::set_dirty ();
1130         return CairoWidget::on_focus_in_event (ev);
1131 }
1132
1133 bool
1134 ArdourButton::on_focus_out_event (GdkEventFocus* ev)
1135 {
1136         _focused = false;
1137         CairoWidget::set_dirty ();
1138         return CairoWidget::on_focus_out_event (ev);
1139 }
1140
1141 bool
1142 ArdourButton::on_key_release_event (GdkEventKey *ev) {
1143         if (_act_on_release && _focused &&
1144                         (ev->keyval == GDK_space || ev->keyval == GDK_Return))
1145         {
1146                 if (_auto_toggle && !_action) {
1147                                 set_active (!get_active ());
1148                 }
1149                 signal_clicked();
1150                 if (_action) {
1151                         _action->activate ();
1152                 }
1153                 return true;
1154         }
1155         return CairoWidget::on_key_release_event (ev);
1156 }
1157
1158 bool
1159 ArdourButton::on_key_press_event (GdkEventKey *ev) {
1160         if (!_act_on_release && _focused &&
1161                         (ev->keyval == GDK_space || ev->keyval == GDK_Return))
1162         {
1163                 if (_auto_toggle && !_action) {
1164                                 set_active (!get_active ());
1165                 }
1166                 signal_clicked();
1167                 if (_action) {
1168                         _action->activate ();
1169                 }
1170                 return true;
1171         }
1172         return CairoWidget::on_key_release_event (ev);
1173 }
1174
1175 bool
1176 ArdourButton::on_enter_notify_event (GdkEventCrossing* ev)
1177 {
1178         _hovering = (_elements & Inactive) ? false : true;
1179
1180         if (UIConfigurationBase::instance().get_widget_prelight()) {
1181                 CairoWidget::set_dirty ();
1182         }
1183
1184         boost::shared_ptr<PBD::Controllable> c (binding_proxy.get_controllable ());
1185         if (c) {
1186                 PBD::Controllable::GUIFocusChanged (boost::weak_ptr<PBD::Controllable> (c));
1187         }
1188
1189         return CairoWidget::on_enter_notify_event (ev);
1190 }
1191
1192 bool
1193 ArdourButton::on_leave_notify_event (GdkEventCrossing* ev)
1194 {
1195         _hovering = false;
1196
1197         if (UIConfigurationBase::instance().get_widget_prelight()) {
1198                 CairoWidget::set_dirty ();
1199         }
1200
1201         if (binding_proxy.get_controllable()) {
1202                 PBD::Controllable::GUIFocusChanged (boost::weak_ptr<PBD::Controllable> ());
1203         }
1204
1205         return CairoWidget::on_leave_notify_event (ev);
1206 }
1207
1208 bool
1209 ArdourButton::on_grab_broken_event(GdkEventGrabBroken* grab_broken_event) {
1210         /* Our implicit grab due to a button_press was broken by another grab:
1211          * the button will not get any button_release event if the mouse leaves
1212          * while the grab is taken, so unpress ourselves */
1213         _grabbed = false;
1214         CairoWidget::set_dirty ();
1215         return true;
1216 }
1217
1218 void
1219 ArdourButton::set_tweaks (Tweaks t)
1220 {
1221         if (_tweaks != t) {
1222                 _tweaks = t;
1223                 if (is_realized()) {
1224                         queue_resize ();
1225                 }
1226         }
1227 }
1228
1229 void
1230 ArdourButton::action_sensitivity_changed ()
1231 {
1232         if (_action->property_sensitive ()) {
1233                 set_visual_state (Gtkmm2ext::VisualState (visual_state() & ~Gtkmm2ext::Insensitive));
1234         } else {
1235                 set_visual_state (Gtkmm2ext::VisualState (visual_state() | Gtkmm2ext::Insensitive));
1236         }
1237 }
1238
1239 void
1240 ArdourButton::set_layout_ellipsize_width (int w)
1241 {
1242         if (_layout_ellipsize_width == w) {
1243                 return;
1244         }
1245         _layout_ellipsize_width = w;
1246         if (!_layout) {
1247                 return;
1248         }
1249         if (_layout_ellipsize_width > 3 * PANGO_SCALE) {
1250                 _layout->set_width (_layout_ellipsize_width - 3 * PANGO_SCALE);
1251         }
1252         if (is_realized ()) {
1253                 queue_resize ();
1254         }
1255 }
1256
1257 void
1258 ArdourButton::set_text_ellipsize (Pango::EllipsizeMode e)
1259 {
1260         if (_ellipsis == e) {
1261                 return;
1262         }
1263         _ellipsis = e;
1264         if (!_layout) {
1265                 return;
1266         }
1267         _layout->set_ellipsize(_ellipsis);
1268         if (_layout_ellipsize_width > 3 * PANGO_SCALE) {
1269                 _layout->set_width (_layout_ellipsize_width - 3 * PANGO_SCALE);
1270         }
1271         if (is_realized ()) {
1272                 queue_resize ();
1273         }
1274 }
1275
1276 void
1277 ArdourButton::ensure_layout ()
1278 {
1279         if (!_layout) {
1280                 ensure_style ();
1281                 _layout = Pango::Layout::create (get_pango_context());
1282                 _layout->set_ellipsize(_ellipsis);
1283                 if (_layout_ellipsize_width > 3 * PANGO_SCALE) {
1284                         _layout->set_width (_layout_ellipsize_width - 3* PANGO_SCALE);
1285                 }
1286         }
1287 }
1288
1289 void
1290 ArdourButton::recalc_char_pixel_geometry ()
1291 {
1292         if (_char_pixel_height > 0 && _char_pixel_width > 0) {
1293                 return;
1294         }
1295         ensure_layout();
1296         // NB. this is not static, since the geometry is different
1297         // depending on the font used.
1298         int w, h;
1299         std::string x = _("@ABCDEFGHIJLKMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789");
1300         _layout->set_text (x);
1301         _layout->get_pixel_size (w, h);
1302         _char_pixel_height = std::max(4, h);
1303         // number of actual chars in the string (not bytes)
1304         // Glib to the rescue.
1305         Glib::ustring gx(x);
1306         _char_avg_pixel_width = w / (float)gx.size();
1307         _char_pixel_width = std::max(4, (int) ceil (_char_avg_pixel_width));
1308         set_text_internal (); /* restore display text */
1309 }
1310
1311 void
1312 ArdourButton::action_visibility_changed ()
1313 {
1314         if (_action->property_visible ()) {
1315                 show ();
1316         } else {
1317                 hide ();
1318         }
1319 }
1320
1321 void
1322 ArdourButton::action_tooltip_changed ()
1323 {
1324         string str = _action->property_tooltip().get_value();
1325         set_tooltip (*this, str);
1326 }
1327
1328 void
1329 ArdourButton::set_elements (Element e)
1330 {
1331         _elements = e;
1332         CairoWidget::set_dirty ();
1333 }
1334
1335 void
1336 ArdourButton::add_elements (Element e)
1337 {
1338         _elements = (ArdourButton::Element) (_elements | e);
1339         CairoWidget::set_dirty ();
1340 }
1341
1342 void
1343 ArdourButton::set_icon (ArdourIcon::Icon i)
1344 {
1345         _icon = i;
1346         _icon_render_cb = 0;
1347         _icon_render_cb_data = 0;
1348         _elements = (ArdourButton::Element) ((_elements | VectorIcon) & ~(ArdourButton::Text | IconRenderCallback));
1349         CairoWidget::set_dirty ();
1350 }
1351
1352 void
1353 ArdourButton::set_icon (rendercallback_t cb, void* d)
1354 {
1355         if (!cb) {
1356                 _elements = (ArdourButton::Element) ((_elements | ArdourButton::Text) & ~(IconRenderCallback | VectorIcon));
1357                 _icon_render_cb = 0;
1358                 _icon_render_cb_data = 0;
1359         } else {
1360                 _elements = (ArdourButton::Element) ((_elements | IconRenderCallback) & ~(ArdourButton::Text | VectorIcon));
1361                 _icon_render_cb = cb;
1362                 _icon_render_cb_data = d;
1363         }
1364         CairoWidget::set_dirty ();
1365 }
1366
1367 void
1368 ArdourButton::set_custom_led_color (uint32_t c, bool useit)
1369 {
1370         if (led_custom_color == c && use_custom_led_color == useit) {
1371                 return;
1372         }
1373
1374         led_custom_color = c;
1375         use_custom_led_color = useit;
1376         CairoWidget::set_dirty ();
1377 }