new button look
[ardour.git] / gtk2_ardour / ardour_button.cc
1 /*
2     Copyright (C) 2010 Paul Davis
3
4     This program is free software; you can redistribute it and/or modify
5     it under the terms of the GNU General Public License as published by
6     the Free Software Foundation; either version 2 of the License, or
7     (at your option) any later version.
8
9     This program is distributed in the hope that it will be useful,
10     but WITHOUT ANY WARRANTY; without even the implied warranty of
11     MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
12     GNU General Public License for more details.
13
14     You should have received a copy of the GNU General Public License
15     along with this program; if not, write to the Free Software
16     Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
17
18 */
19
20 #include <iostream>
21 #include <cmath>
22 #include <algorithm>
23
24 #include <pangomm/layout.h>
25
26 #include "pbd/compose.h"
27 #include "pbd/error.h"
28
29 #include "gtkmm2ext/utils.h"
30 #include "gtkmm2ext/rgb_macros.h"
31 #include "gtkmm2ext/gui_thread.h"
32
33 #include "ardour/rc_configuration.h" // for widget prelight preference
34
35 #include "ardour_button.h"
36 #include "ardour_ui.h"
37 #include "global_signals.h"
38
39 #include "i18n.h"
40
41 using namespace Gdk;
42 using namespace Gtk;
43 using namespace Glib;
44 using namespace PBD;
45 using std::max;
46 using std::min;
47 using namespace std;
48
49 ArdourButton::Element ArdourButton::default_elements = ArdourButton::Element (ArdourButton::Edge|ArdourButton::Body|ArdourButton::Text);
50 ArdourButton::Element ArdourButton::led_default_elements = ArdourButton::Element (ArdourButton::default_elements|ArdourButton::Indicator);
51 ArdourButton::Element ArdourButton::just_led_default_elements = ArdourButton::Element (ArdourButton::Edge|ArdourButton::Body|ArdourButton::Indicator);
52 bool ArdourButton::_flat_buttons = false;
53
54 ArdourButton::ArdourButton (Element e)
55         : _elements (e)
56         , _tweaks (Tweaks (0))
57         , _text_width (0)
58         , _text_height (0)
59         , _diameter (11.0)
60         , _corner_radius (5.0)
61         , _corner_mask (0xf)
62         , border_color (0)
63         , fill_color_active (0)
64         , fill_color_inactive (0)
65         , fill_pattern (0)
66         , fill_pattern_active (0)
67         , shine_pattern (0)
68         , led_inset_pattern (0)
69         , reflection_pattern (0)
70         , _led_rect (0)
71         , _act_on_release (true)
72         , _led_left (false)
73         , _fixed_diameter (true)
74         , _distinct_led_click (false)
75         , _hovering (false)
76 {
77         ColorsChanged.connect (sigc::mem_fun (*this, &ArdourButton::color_handler));
78 }
79
80 ArdourButton::ArdourButton (const std::string& str, Element e)
81         : _elements (e)
82         , _tweaks (Tweaks (0))
83         , _text_width (0)
84         , _text_height (0)
85         , _diameter (11.0)
86         , _corner_radius (5.0)
87         , _corner_mask (0xf)
88         , border_color (0)
89         , fill_color_active (0)
90         , fill_color_inactive (0)
91         , fill_pattern (0)
92         , fill_pattern_active (0)
93         , shine_pattern (0)
94         , led_inset_pattern (0)
95         , reflection_pattern (0)
96         , _led_rect (0)
97         , _act_on_release (true)
98         , _led_left (false)
99         , _fixed_diameter (true)
100         , _distinct_led_click (false)
101         , _hovering (false)
102 {
103         set_text (str);
104 }
105
106 ArdourButton::~ArdourButton()
107 {
108         delete _led_rect;
109
110         if (shine_pattern) {
111                 cairo_pattern_destroy (shine_pattern);
112         }
113
114         if (fill_pattern) {
115                 cairo_pattern_destroy (fill_pattern);
116         }
117         
118         if (fill_pattern_active) {
119                 cairo_pattern_destroy (fill_pattern_active);
120         }
121         
122         if (led_inset_pattern) {
123                 cairo_pattern_destroy (led_inset_pattern);
124         }
125         
126         if (reflection_pattern) {
127                 cairo_pattern_destroy (reflection_pattern);
128         }
129
130 }
131
132 void
133 ArdourButton::set_text (const std::string& str)
134 {
135         _text = str;
136
137         if (!_layout && !_text.empty()) {
138                 _layout = Pango::Layout::create (get_pango_context());
139         } 
140
141         if (_layout) {
142                 _layout->set_text (str);
143         }
144
145         queue_resize ();
146 }
147
148 void
149 ArdourButton::set_markup (const std::string& str)
150 {
151         _text = str;
152
153         if (!_layout) {
154                 _layout = Pango::Layout::create (get_pango_context());
155         } 
156
157         _layout->set_text (str);
158         queue_resize ();
159 }
160
161 void
162 ArdourButton::render (cairo_t* cr)
163 {
164         void (*rounded_function)(cairo_t*, double, double, double, double, double);
165
166         switch (_corner_mask) {
167         case 0x1: /* upper left only */
168                 rounded_function = Gtkmm2ext::rounded_top_left_rectangle;
169                 break;
170         case 0x2: /* upper right only */
171                 rounded_function = Gtkmm2ext::rounded_top_right_rectangle;
172                 break;
173         case 0x3: /* upper only */
174                 rounded_function = Gtkmm2ext::rounded_top_rectangle;
175                 break;
176                 /* should really have functions for lower right, lower left,
177                    lower only, but for now, we don't
178                 */
179         default:
180                 rounded_function = Gtkmm2ext::rounded_rectangle;
181         }
182
183         if (!_fixed_diameter) {
184                 _diameter = std::min (get_width(), get_height());
185         }
186
187         float r,g,b,a;
188
189         if (_elements & Edge) {
190                 rounded_function (cr, 0, 0, get_width(), get_height(), _corner_radius);
191                 UINT_TO_RGBA (border_color, &r, &g, &b, &a);
192                 //cairo_set_source_rgba (cr, r/255.0,g/255.0,b/255.0,a/255.0);  //TODO:  why doesn't this work?
193                 cairo_set_source_rgba (cr, 0,0,0,0.9);
194                 cairo_fill (cr);
195         }
196
197         if (_elements & Body) {
198                 if (_elements & Edge) {
199                         rounded_function (cr, 1, 1, get_width()-2, get_height()-2, _corner_radius - 1.0);
200                 } else {
201                         rounded_function (cr, 0, 0, get_width(), get_height(), _corner_radius);
202                 }
203
204                 if (active_state() == Gtkmm2ext::ImplicitActive) {
205                         //background color
206                         cairo_set_source (cr, fill_pattern);
207                         cairo_fill_preserve (cr);
208
209                         //border
210                         UINT_TO_RGBA (fill_color_active, &r, &g, &b, &a);
211                         cairo_set_line_width (cr, 2.0);
212 //                      rounded_function (cr, 3, 3, get_width()-6, get_height()-6, _corner_radius - 1.0);
213                         cairo_set_source_rgba (cr, r/255.0, g/255.0, b/255.0, a/255.0);
214                         cairo_stroke (cr);
215
216                         //reflection
217                         if (!_flat_buttons) {
218                                 rounded_function (cr, 2, 2, get_width()-4, get_height()/2-2, _corner_radius - 1.0);
219                                 cairo_set_source (cr, shine_pattern);
220                                 cairo_fill (cr);
221                         }
222                 } else if (active_state() == Gtkmm2ext::ExplicitActive) {
223
224                         //background color
225                         cairo_set_source (cr, fill_pattern_active);
226                         cairo_fill (cr);
227
228                         //reflection
229                         if (!_flat_buttons) {
230                                 rounded_function (cr, 2, 2, get_width()-4, get_height()/2-2, _corner_radius - 1.0);
231                                 cairo_set_source (cr, shine_pattern);
232                                 cairo_fill (cr);
233                         }
234                 } else {
235
236                         //background color
237                         cairo_set_source (cr, fill_pattern);
238                         cairo_fill (cr);
239
240                         //reflection
241                         if (!_flat_buttons) {
242                                 rounded_function (cr, 2, 2, get_width()-4, get_height()/2-2, _corner_radius - 1.0);
243                                 cairo_set_source (cr, shine_pattern);
244                                 cairo_fill (cr);
245                         }               
246                 }
247         }
248
249         if (_pixbuf) {
250
251                 double x,y;
252                 x = (get_width() - _pixbuf->get_width())/2.0;
253                 y = (get_height() - _pixbuf->get_height())/2.0;
254
255                 cairo_rectangle (cr, x, y, _pixbuf->get_width(), _pixbuf->get_height());
256                 gdk_cairo_set_source_pixbuf (cr, _pixbuf->gobj(), x, y);
257                 cairo_fill (cr);
258         }
259
260         /* text, if any */
261
262         int text_margin;
263
264         if (get_width() < 75) {
265                 text_margin = 3;
266         } else {
267                 text_margin = 10;
268         }
269
270         if ((_elements & Text) && !_text.empty()) {
271
272                 cairo_new_path (cr);    
273
274                 if (_elements & Indicator) {
275                         if (_led_left) {
276                                 cairo_move_to (cr, text_margin + _diameter + 4, get_height()/2.0 - _text_height/2.0);
277                         } else {
278                                 cairo_move_to (cr, text_margin, get_height()/2.0 - _text_height/2.0);
279                         }
280                 } else {
281                         /* center text */
282                         cairo_move_to (cr, (get_width() - _text_width)/2.0, get_height()/2.0 - _text_height/2.0);
283                 }
284
285                 cairo_set_source_rgba (cr, text_r, text_g, text_b, text_a);
286                 pango_cairo_show_layout (cr, _layout->gobj());
287         } 
288
289         if (_elements & Indicator) {
290
291                 /* move to the center of the indicator/led */
292
293                 cairo_save (cr);
294
295                 if (_elements & Text) {
296                         if (_led_left) {
297                                 cairo_translate (cr, text_margin + (_diameter/2.0), get_height()/2.0);
298                         } else {
299                                 cairo_translate (cr, get_width() - ((_diameter/2.0) + 4.0), get_height()/2.0);
300                         }
301                 } else {
302                         cairo_translate (cr, get_width()/2.0, get_height()/2.0);
303                 }
304                 
305                 //inset
306                 cairo_arc (cr, 0, 0, _diameter/2, 0, 2 * M_PI);
307                 cairo_set_source (cr, led_inset_pattern);
308                 cairo_fill (cr);
309                 
310                 //black ring
311                 cairo_set_source_rgb (cr, 0, 0, 0);
312                 cairo_arc (cr, 0, 0, _diameter/2-2, 0, 2 * M_PI);
313                 cairo_fill(cr);
314                 
315                 //led color
316                 cairo_set_source_rgba (cr, led_r, led_g, led_b, led_a);
317                 cairo_arc (cr, 0, 0, _diameter/2-3, 0, 2 * M_PI);
318                 cairo_fill(cr);
319                 
320                 //reflection
321                 cairo_scale(cr, 0.7, 0.7);
322                 cairo_arc (cr, 0, 0, _diameter/2-3, 0, 2 * M_PI);
323                 cairo_set_source (cr, reflection_pattern);
324                 cairo_fill (cr);
325
326                 cairo_restore (cr);
327
328         }
329
330
331         /* a partially transparent gray layer to indicate insensitivity */
332
333         if ((visual_state() & Gtkmm2ext::Insensitive)) {
334                 rounded_function (cr, 0, 0, get_width(), get_height(), _corner_radius);
335                 cairo_set_source_rgba (cr, 0.905, 0.917, 0.925, 0.5);
336                 cairo_fill (cr);
337         }
338
339         /* if requested, show hovering */
340         
341         if (ARDOUR::Config->get_widget_prelight()) {
342                 if (_hovering) {
343                         rounded_function (cr, 0, 0, get_width(), get_height(), _corner_radius);
344                         cairo_set_source_rgba (cr, 0.905, 0.917, 0.925, 0.2);
345                         cairo_fill (cr);
346                 }
347         }
348 }
349
350 void
351 ArdourButton::set_diameter (float d)
352 {
353         _diameter = (d*2) + 5.0;
354
355         if (_diameter != 0.0) {
356                 _fixed_diameter = true;
357         }
358
359         set_colors ();
360 }
361
362 void
363 ArdourButton::set_corner_radius (float r)
364 {
365         _corner_radius = r;
366         set_dirty ();
367 }
368
369 void
370 ArdourButton::on_size_request (Gtk::Requisition* req)
371 {
372         int xpad = 0;
373         int ypad = 6;
374
375         CairoWidget::on_size_request (req);
376
377         if ((_elements & Text) && !_text.empty()) {
378                 _layout->get_pixel_size (_text_width, _text_height);
379                 if (_text_width + _diameter < 75) {
380                         xpad = 7;
381                 } else {
382                         xpad = 20;
383                 }
384         } else {
385                 _text_width = 0;
386                 _text_height = 0;
387         }
388
389         if (_pixbuf) {
390                 xpad = 6;
391         }
392
393         if ((_elements & Indicator) && _fixed_diameter) {
394                 if (_pixbuf) {
395                         req->width = _pixbuf->get_width() + lrint (_diameter) + xpad;
396                         req->height = max (_pixbuf->get_height(), (int) lrint (_diameter)) + ypad;
397                 } else {
398                         req->width = _text_width + lrint (_diameter) + xpad;
399                         req->height = max (_text_height, (int) lrint (_diameter)) + ypad;
400                 }
401         } else {
402                 if (_pixbuf) {
403                         req->width = _pixbuf->get_width() + xpad;
404                         req->height = _pixbuf->get_height() + ypad;
405                 }  else {
406                         req->width = _text_width + xpad;
407                         req->height = _text_height + ypad;
408                 }
409         }
410 }
411
412 void
413 ArdourButton::set_colors ()
414 {
415         uint32_t start_color;
416         uint32_t end_color;
417         uint32_t r, g, b, a;
418         uint32_t text_color;
419         uint32_t led_color;
420
421         /* we use the edge of the button to show Selected state, so the
422          * color/pattern used there will vary depending on that
423          */
424         
425         fill_color_active = ARDOUR_UI::config()->color_by_name (string_compose ("%1: fill end active", get_name()));
426         fill_color_inactive = ARDOUR_UI::config()->color_by_name (string_compose ("%1: fill end", get_name()));
427         border_color = ARDOUR_UI::config()->color_by_name ( "button border" );
428
429         if (shine_pattern) {
430                 cairo_pattern_destroy (shine_pattern);
431                 shine_pattern = 0;
432         }
433
434         if (fill_pattern) {
435                 cairo_pattern_destroy (fill_pattern);
436                 fill_pattern = 0;
437         }
438
439         if (fill_pattern_active) {
440                 cairo_pattern_destroy (fill_pattern_active);
441                 fill_pattern_active = 0;
442         }
443
444         if (_elements & Body) {
445
446                 shine_pattern = cairo_pattern_create_linear (0.0, 0.0, 0.0, get_height()/2-2);
447                 start_color = ARDOUR_UI::config()->color_by_name (string_compose ("%1: fill start active", get_name()));
448
449                 if (_flat_buttons) {
450                         end_color = start_color;
451                 } else {
452                         end_color = fill_color_active;
453                 }
454                 UINT_TO_RGBA (start_color, &r, &g, &b, &a);
455
456                 active_r = r/255.0;
457                 active_g = g/255.0;
458                 active_b = b/255.0;
459                 active_a = a/255.0;
460
461                 cairo_pattern_add_color_stop_rgba (shine_pattern, 0, 1,1,1,0.1);
462                 cairo_pattern_add_color_stop_rgba (shine_pattern, 0.2, 1,1,1,0.4);
463                 cairo_pattern_add_color_stop_rgba (shine_pattern, 1, 1,1,1,0.1);
464
465                 fill_pattern = cairo_pattern_create_linear (0.0, 0.0, 0.0, get_height()-3);
466                 start_color = ARDOUR_UI::config()->color_by_name (string_compose ("%1: fill start", get_name()));
467                 if (_flat_buttons) {
468                         end_color = start_color;
469                 } else {
470                         end_color = fill_color_inactive;
471                 }
472                 UINT_TO_RGBA (start_color, &r, &g, &b, &a);
473                 cairo_pattern_add_color_stop_rgba (fill_pattern, 0, r/255.0,g/255.0,b/255.0, a/255.0);
474                 UINT_TO_RGBA (end_color, &r, &g, &b, &a);
475                 cairo_pattern_add_color_stop_rgba (fill_pattern, 1, r/255.0,g/255.0,b/255.0, a/255.0);
476
477                 fill_pattern_active = cairo_pattern_create_linear (0.0, 0.0, 0.0, get_height()-3);
478                 start_color = ARDOUR_UI::config()->color_by_name (string_compose ("%1: fill start active", get_name()));
479                 if (_flat_buttons) {
480                         end_color = start_color;
481                 } else {
482                         end_color = ARDOUR_UI::config()->color_by_name (string_compose ("%1: fill end active", get_name()));
483                 }
484                 UINT_TO_RGBA (start_color, &r, &g, &b, &a);
485                 cairo_pattern_add_color_stop_rgba (fill_pattern_active, 0, r/255.0,g/255.0,b/255.0, a/255.0);
486                 UINT_TO_RGBA (end_color, &r, &g, &b, &a);
487                 cairo_pattern_add_color_stop_rgba (fill_pattern_active, 1, r/255.0,g/255.0,b/255.0, a/255.0);
488         }
489
490         if (led_inset_pattern) {
491                 cairo_pattern_destroy (led_inset_pattern);
492         }
493         
494         if (reflection_pattern) {
495                 cairo_pattern_destroy (reflection_pattern);
496         }
497
498         if (_elements & Indicator) {
499                 led_inset_pattern = cairo_pattern_create_linear (0.0, 0.0, 0.0, _diameter);
500                 cairo_pattern_add_color_stop_rgba (led_inset_pattern, 0, 0,0,0, 0.4);
501                 cairo_pattern_add_color_stop_rgba (led_inset_pattern, 1, 1,1,1, 0.7);
502
503                 reflection_pattern = cairo_pattern_create_linear (0.0, 0.0, 0.0, _diameter/2-3);
504                 cairo_pattern_add_color_stop_rgba (reflection_pattern, 0, 1,1,1, active_state() ? 0.4 : 0.2);
505                 cairo_pattern_add_color_stop_rgba (reflection_pattern, 1, 1,1,1, 0.0);
506         }
507         
508         /* text and LED colors */
509
510         if (active_state() == Gtkmm2ext::ExplicitActive) {
511                 text_color = ARDOUR_UI::config()->color_by_name (string_compose ("%1: text active", get_name()));
512                 led_color = ARDOUR_UI::config()->color_by_name (string_compose ("%1: led active", get_name()));
513         } else {
514                 text_color = ARDOUR_UI::config()->color_by_name (string_compose ("%1: text", get_name()));
515                 led_color = ARDOUR_UI::config()->color_by_name (string_compose ("%1: led", get_name()));
516         }
517
518         UINT_TO_RGBA (text_color, &r, &g, &b, &a);
519         text_r = r/255.0;
520         text_g = g/255.0;
521         text_b = b/255.0;
522         text_a = a/255.0;
523         UINT_TO_RGBA (led_color, &r, &g, &b, &a);
524         led_r = r/255.0;
525         led_g = g/255.0;
526         led_b = b/255.0;
527         led_a = a/255.0;
528
529         set_dirty ();
530 }
531
532 void
533 ArdourButton::set_led_left (bool yn)
534 {
535         _led_left = yn;
536 }
537
538 bool
539 ArdourButton::on_button_press_event (GdkEventButton *ev)
540 {
541         if ((_elements & Indicator) && _led_rect && _distinct_led_click) {
542                 if (ev->x >= _led_rect->x && ev->x < _led_rect->x + _led_rect->width && 
543                     ev->y >= _led_rect->y && ev->y < _led_rect->y + _led_rect->height) {
544                         return true;
545                 }
546         }
547
548         if (_tweaks & ShowClick) {
549                 set_active_state (Gtkmm2ext::ExplicitActive);
550         }
551
552         if (binding_proxy.button_press_handler (ev)) {
553                 return true;
554         }
555
556         if (!_act_on_release) {
557                 if (_action) {
558                         _action->activate ();
559                         return true;
560                 }
561         }
562
563         return false;
564 }
565
566 bool
567 ArdourButton::on_button_release_event (GdkEventButton *ev)
568 {
569         if ((_elements & Indicator) && _led_rect && _distinct_led_click) {
570                 if (ev->x >= _led_rect->x && ev->x < _led_rect->x + _led_rect->width && 
571                     ev->y >= _led_rect->y && ev->y < _led_rect->y + _led_rect->height) {
572                         signal_led_clicked(); /* EMIT SIGNAL */
573                         return true;
574                 }
575         }
576
577         if (_tweaks & ShowClick) {
578                 unset_active_state ();
579         }
580
581         signal_clicked ();
582
583         if (_act_on_release) {
584                 if (_action) {
585                         _action->activate ();
586                         return true;
587                 }
588         }
589
590
591         return false;
592 }
593
594 void
595 ArdourButton::set_distinct_led_click (bool yn)
596 {
597         _distinct_led_click = yn;
598         setup_led_rect ();
599 }
600
601 void
602 ArdourButton::color_handler ()
603 {
604         set_colors ();
605         set_dirty ();
606 }
607
608 void
609 ArdourButton::on_size_allocate (Allocation& alloc)
610 {
611         CairoWidget::on_size_allocate (alloc);
612         setup_led_rect ();
613         set_colors ();
614 }
615
616 void
617 ArdourButton::set_controllable (boost::shared_ptr<Controllable> c)
618 {
619         watch_connection.disconnect ();
620         binding_proxy.set_controllable (c);
621 }
622
623 void
624 ArdourButton::watch ()
625 {
626         boost::shared_ptr<Controllable> c (binding_proxy.get_controllable ());
627
628         if (!c) {
629                 warning << _("button cannot watch state of non-existing Controllable\n") << endmsg;
630                 return;
631         }
632
633         c->Changed.connect (watch_connection, invalidator(*this), boost::bind (&ArdourButton::controllable_changed, this), gui_context());
634 }
635
636 void
637 ArdourButton::controllable_changed ()
638 {
639         float val = binding_proxy.get_controllable()->get_value();
640
641         if (fabs (val) >= 0.5f) {
642                 set_active_state (Gtkmm2ext::ExplicitActive);
643         } else {
644                 unset_active_state ();
645         }
646 }
647
648 void
649 ArdourButton::set_related_action (RefPtr<Action> act)
650 {
651         Gtkmm2ext::Activatable::set_related_action (act);
652
653         if (_action) {
654
655                 action_tooltip_changed ();
656
657                 Glib::RefPtr<ToggleAction> tact = Glib::RefPtr<ToggleAction>::cast_dynamic (_action);
658                 if (tact) {
659                         action_toggled ();
660                         tact->signal_toggled().connect (sigc::mem_fun (*this, &ArdourButton::action_toggled));
661                 } 
662
663                 _action->connect_property_changed ("sensitive", sigc::mem_fun (*this, &ArdourButton::action_sensitivity_changed));
664                 _action->connect_property_changed ("visible", sigc::mem_fun (*this, &ArdourButton::action_visibility_changed));
665                 _action->connect_property_changed ("tooltip", sigc::mem_fun (*this, &ArdourButton::action_tooltip_changed));
666         }
667 }
668
669 void
670 ArdourButton::action_toggled ()
671 {
672         Glib::RefPtr<ToggleAction> tact = Glib::RefPtr<ToggleAction>::cast_dynamic (_action);
673
674         if (tact) {
675                 if (tact->get_active()) {
676                         set_active_state (Gtkmm2ext::ExplicitActive);
677                 } else {
678                         unset_active_state ();
679                 }
680         }
681 }       
682
683 void
684 ArdourButton::on_style_changed (const RefPtr<Gtk::Style>&)
685 {
686         set_colors ();
687 }
688
689 void
690 ArdourButton::setup_led_rect ()
691 {
692         int text_margin;
693
694         if (get_width() < 75) {
695                 text_margin = 3;
696         } else {
697                 text_margin = 10;
698         }
699
700         if (_elements & Indicator) {
701                 _led_rect = new cairo_rectangle_t;
702                 
703                 if (_elements & Text) {
704                         if (_led_left) {
705                                 _led_rect->x = text_margin;
706                         } else {
707                                 _led_rect->x = get_width() - text_margin - _diameter/2.0;
708                         }
709                 } else {
710                         /* centered */
711                         _led_rect->x = get_width()/2.0 - _diameter/2.0;
712                 }
713
714                 _led_rect->y = get_height()/2.0 - _diameter/2.0;
715                 _led_rect->width = _diameter;
716                 _led_rect->height = _diameter;
717
718         } else {
719                 delete _led_rect;
720                 _led_rect = 0;
721         }
722 }
723
724 void
725 ArdourButton::set_image (const RefPtr<Gdk::Pixbuf>& img)
726 {
727         _pixbuf = img;
728         queue_draw ();
729 }
730
731 void
732 ArdourButton::set_active_state (Gtkmm2ext::ActiveState s)
733 {
734         bool changed = (_active_state != s);
735         CairoWidget::set_active_state (s);
736         if (changed) {
737                 set_colors ();
738         }
739 }
740         
741 void
742 ArdourButton::set_visual_state (Gtkmm2ext::VisualState s)
743 {
744         bool changed = (_visual_state != s);
745         CairoWidget::set_visual_state (s);
746         if (changed) {
747                 set_colors ();
748         }
749 }
750         
751 bool
752 ArdourButton::on_enter_notify_event (GdkEventCrossing* ev)
753 {
754         _hovering = true;
755
756         if (ARDOUR::Config->get_widget_prelight()) {
757                 queue_draw ();
758         }
759
760         return CairoWidget::on_enter_notify_event (ev);
761 }
762
763 bool
764 ArdourButton::on_leave_notify_event (GdkEventCrossing* ev)
765 {
766         _hovering = false;
767
768         if (ARDOUR::Config->get_widget_prelight()) {
769                 queue_draw ();
770         }
771
772         return CairoWidget::on_leave_notify_event (ev);
773 }
774
775 void
776 ArdourButton::set_tweaks (Tweaks t)
777 {
778         if (_tweaks != t) {
779                 _tweaks = t;
780                 queue_draw ();
781         }
782 }
783
784 void
785 ArdourButton::action_sensitivity_changed ()
786 {
787         if (_action->property_sensitive ()) {
788                 set_visual_state (Gtkmm2ext::VisualState (visual_state() & ~Gtkmm2ext::Insensitive));
789         } else {
790                 set_visual_state (Gtkmm2ext::VisualState (visual_state() | Gtkmm2ext::Insensitive));
791         }
792         
793 }
794
795
796 void
797 ArdourButton::action_visibility_changed ()
798 {
799         if (_action->property_visible ()) {
800                 show ();
801         } else {
802                 hide ();
803         }
804 }
805
806 void
807 ArdourButton::action_tooltip_changed ()
808 {
809         string str = _action->property_tooltip().get_value();
810         ARDOUR_UI::instance()->set_tip (*this, str);
811 }
812
813 void
814 ArdourButton::set_rounded_corner_mask (int mask)
815 {
816         _corner_mask = mask;
817         queue_draw ();
818 }
819
820 void
821 ArdourButton::set_elements (Element e)
822 {
823         _elements = e;
824         set_colors ();
825 }
826
827 void
828 ArdourButton::set_flat_buttons (bool yn)
829 {
830         _flat_buttons = yn;
831 }