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