2 Copyright (C) 2010 Paul Davis
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.
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.
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.
24 #include <pangomm/layout.h>
26 #include "pbd/compose.h"
27 #include "pbd/error.h"
28 #include "pbd/stacktrace.h"
30 #include "gtkmm2ext/utils.h"
31 #include "gtkmm2ext/rgb_macros.h"
32 #include "gtkmm2ext/gui_thread.h"
34 #include "ardour/rc_configuration.h" // for widget prelight preference
36 #include "canvas/utils.h"
38 #include "ardour_button.h"
39 #include "ardour_ui.h"
40 #include "global_signals.h"
44 #define REFLECTION_HEIGHT 2
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);
58 ArdourButton::ArdourButton (Element e)
60 , _tweaks (Tweaks (0))
61 , _char_pixel_width (0)
62 , _char_pixel_height (0)
66 , _corner_radius (2.5)
71 , fill_inactive_color (0)
72 , fill_active_color (0)
73 , text_active_color(0)
74 , text_inactive_color(0)
76 , led_inactive_color(0)
79 , led_inset_pattern (0)
81 , _act_on_release (true)
83 , _fixed_diameter (true)
84 , _distinct_led_click (false)
87 , _fixed_colors_set (false)
88 , _fallthrough_to_parent (false)
90 ARDOUR_UI_UTILS::ColorsChanged.connect (sigc::mem_fun (*this, &ArdourButton::color_handler));
93 ArdourButton::ArdourButton (const std::string& str, Element e)
95 , _tweaks (Tweaks (0))
99 , _corner_radius (4.0)
104 , fill_inactive_color (0)
105 , fill_active_color (0)
106 , text_active_color(0)
107 , text_inactive_color(0)
108 , led_active_color(0)
109 , led_inactive_color(0)
111 , concave_pattern (0)
112 , led_inset_pattern (0)
114 , _act_on_release (true)
116 , _fixed_diameter (true)
117 , _distinct_led_click (false)
120 , _fixed_colors_set (false)
125 ArdourButton::~ArdourButton()
129 if (convex_pattern) {
130 cairo_pattern_destroy (convex_pattern);
133 if (concave_pattern) {
134 cairo_pattern_destroy (concave_pattern);
137 if (led_inset_pattern) {
138 cairo_pattern_destroy (led_inset_pattern);
144 ArdourButton::set_text (const std::string& str)
148 if (!_layout && !_text.empty()) {
149 _layout = Pango::Layout::create (get_pango_context());
153 _layout->set_text (str);
160 ArdourButton::set_markup (const std::string& str)
165 _layout = Pango::Layout::create (get_pango_context());
168 _layout->set_markup (str);
173 ArdourButton::set_angle (const double angle)
179 ArdourButton::set_alignment (const float xa, const float ya)
186 ArdourButton::render (cairo_t* cr, cairo_rectangle_t *)
190 if ( active_state() == Gtkmm2ext::ExplicitActive ) {
191 text_color = text_active_color;
192 led_color = led_active_color;
194 text_color = text_inactive_color;
195 led_color = led_inactive_color;
198 void (*rounded_function)(cairo_t*, double, double, double, double, double);
200 switch (_corner_mask) {
201 case 0x1: /* upper left only */
202 rounded_function = Gtkmm2ext::rounded_top_left_rectangle;
204 case 0x2: /* upper right only */
205 rounded_function = Gtkmm2ext::rounded_top_right_rectangle;
207 case 0x3: /* upper only */
208 rounded_function = Gtkmm2ext::rounded_top_rectangle;
210 /* should really have functions for lower right, lower left,
211 lower only, but for now, we don't
214 rounded_function = Gtkmm2ext::rounded_rectangle;
217 if (!_fixed_diameter) {
218 _diameter = std::min (get_width(), get_height());
221 // draw edge (filling a rect underneath, rather than stroking a border on top, allows the corners to be lighter-weight.
222 if ((_elements & (Body|Edge)) == (Body|Edge)) {
223 rounded_function (cr, 0, 0, get_width(), get_height(), _corner_radius);
224 cairo_set_source_rgba (cr, 0, 0, 0, 1);
229 if ((_elements & Body)==Body) {
230 rounded_function (cr, 1, 1, get_width() - 2, get_height() - 2, _corner_radius);
231 if (active_state() == Gtkmm2ext::ImplicitActive && !((_elements & Indicator)==Indicator)) {
232 ArdourCanvas::set_source_rgba (cr, fill_inactive_color);
234 } else if ( (active_state() == Gtkmm2ext::ExplicitActive) && !((_elements & Indicator)==Indicator) ) {
236 ArdourCanvas::set_source_rgba (cr, fill_active_color);
238 } else { //inactive, or it has an indicator
240 ArdourCanvas::set_source_rgba (cr, fill_inactive_color);
245 // IMPLICIT ACTIVE: draw a border of the active color
246 if ((_elements & Body)==Body) {
247 if (active_state() == Gtkmm2ext::ImplicitActive && !((_elements & Indicator)==Indicator)) {
248 cairo_set_line_width (cr, 2.0);
249 rounded_function (cr, 2, 2, get_width() - 4, get_height() - 4, _corner_radius);
250 ArdourCanvas::set_source_rgba (cr, fill_active_color);
255 //show the "convex" or "concave" gradient
256 if (!_flat_buttons) {
257 if ( active_state() == Gtkmm2ext::ExplicitActive && !((_elements & Indicator)==Indicator) ) {
259 cairo_set_source (cr, concave_pattern);
260 Gtkmm2ext::rounded_rectangle (cr, 1, 1, get_width() - 2, get_height() - 2, _corner_radius);
263 cairo_set_source (cr, convex_pattern);
264 Gtkmm2ext::rounded_rectangle (cr, 1, 1, get_width() - 2, get_height() - 2, _corner_radius);
273 x = (get_width() - _pixbuf->get_width())/2.0;
274 y = (get_height() - _pixbuf->get_height())/2.0;
276 //if this is a DropDown with an icon, then we need to
277 //move the icon left slightly to accomomodate the arrow
278 if (((_elements & Menu)==Menu)) {
280 cairo_translate (cr, -8,0 );
283 cairo_rectangle (cr, x, y, _pixbuf->get_width(), _pixbuf->get_height());
284 gdk_cairo_set_source_pixbuf (cr, _pixbuf->gobj(), x, y);
287 //..and then return to our previous drawing position
288 if (((_elements & Menu)==Menu)) {
292 else // rec-en is exclusive to pixbuf (tape machine mode, rec-en)
293 if ((_elements & (RecButton|RecTapeMode)) == (RecButton|RecTapeMode)) {
294 const double h = get_height();
295 const double x = get_width() * .5;
296 const double y = get_height() * .5;
297 const double slit = .11 * M_PI;
299 cairo_translate(cr, x, y);
301 cairo_arc (cr, 0, 0, y *.6, 0, 2 * M_PI);
302 cairo_set_source_rgba (cr, .95, .44, .44, 1.); // #f46f6f
303 cairo_fill_preserve(cr);
304 cairo_set_source_rgba (cr, .0, .0, .0, .5);
305 cairo_set_line_width(cr, 1);
309 cairo_set_source_rgba (cr, .15, .07, .07, 1.0);
311 cairo_rotate (cr, -.5 * M_PI);
312 cairo_move_to(cr, 0, 0);
313 cairo_arc (cr, 0, 0, h *.25, -slit, slit);
314 cairo_line_to(cr, 0, 0);
315 cairo_close_path(cr);
318 cairo_rotate (cr, 2. * M_PI / 3.);
320 cairo_move_to(cr, 0, 0);
321 cairo_arc (cr, 0, 0, h *.25, -slit, slit);
322 cairo_line_to(cr, 0, 0);
323 cairo_close_path(cr);
326 cairo_rotate (cr, 2. * M_PI / 3.);
327 cairo_move_to(cr, 0, 0);
328 cairo_arc (cr, 0, 0, h *.25, -slit, slit);
329 cairo_line_to(cr, 0, 0);
330 cairo_close_path(cr);
335 cairo_arc (cr, 0, 0, h * .09, 0, 2 * M_PI);
336 cairo_set_source_rgba (cr, .95, .44, .44, 1.); // #f46f6f
338 cairo_set_source_rgba (cr, .0, .0, .0, 1.0);
339 cairo_arc (cr, 0, 0, h *.05, 0, 2 * M_PI); // hole in the middle
344 else if (_elements & RecButton) {
345 const double x = get_width() * .5;
346 const double y = get_height() * .5;
347 cairo_arc (cr, x, y, y *.55, 0, 2 * M_PI);
348 cairo_set_source_rgba (cr, .95, .44, .44, 1.); // #f46f6f
349 cairo_fill_preserve(cr);
350 cairo_set_source_rgba (cr, .0, .0, .0, .5);
351 cairo_set_line_width(cr, 1);
356 if (get_width() < 75 || (_elements & Menu) ) {
363 if ( !_pixbuf && ((_elements & Text)==Text) && !_text.empty()) {
366 cairo_rectangle (cr, 2, 1, get_width()-4, get_height()-2);
370 ArdourCanvas::set_source_rgba (cr, text_color);
372 if ( (_elements & Menu) == Menu) {
373 cairo_move_to (cr, rint(text_margin), rint((get_height() - _text_height)/2.0));
374 pango_cairo_show_layout (cr, _layout->gobj());
375 } else if ( (_elements & Indicator) == Indicator) {
377 cairo_move_to (cr, rint(text_margin + _diameter + 4), rint((get_height() - _text_height)/2.0));
379 cairo_move_to (cr, rint(text_margin), rint((get_height() - _text_height)/2.0));
381 pango_cairo_show_layout (cr, _layout->gobj());
389 cairo_save (cr); // TODO retain rotataion.. adj. LED,...
390 cairo_rotate(cr, _angle * M_PI / 180.0);
391 cairo_device_to_user(cr, &ww, &wh);
392 xa = (ww - _text_width) * _xalign;
393 ya = (wh - _text_height) * _yalign;
395 /* quick hack for left/bottom alignment at -90deg
396 * TODO this should be generalized incl rotation.
397 * currently only 'user' of this API is meter_strip.cc
399 if (_xalign < 0) xa = (ww * fabs(_xalign) + text_margin);
401 // TODO honor left/right text_margin with min/max()
403 cairo_move_to (cr, rint(.5 + xa), rint(ya));
404 pango_cairo_update_layout(cr, _layout->gobj());
405 pango_cairo_show_layout (cr, _layout->gobj());
412 if (((_elements & Menu)==Menu)) {
413 const float trih = ceil(_diameter/2.0);
414 const float triw2 = ceil(.577 * _diameter/2.0); // 1/sqrt(3) Equilateral triangle
416 cairo_set_source_rgba (cr, 1, 1, 1, 0.4);
417 cairo_move_to(cr, get_width() - triw2 - 3. , rint((get_height() + trih) / 2.0));
418 cairo_rel_line_to(cr, -triw2, -trih);
419 cairo_rel_line_to(cr, 2. * triw2, 0);
420 cairo_close_path(cr);
422 cairo_set_source_rgba (cr, 1, 1, 1, 0.4);
425 cairo_move_to(cr, get_width() - triw2 - 3 , rint((get_height() + trih) / 2.0));
426 cairo_rel_line_to(cr, .5 - triw2, .5 - trih);
427 cairo_rel_line_to(cr, 2. * triw2 - 1, 0);
428 cairo_close_path(cr);
429 cairo_set_source_rgba (cr, 0, 0, 0, 0.8);
430 cairo_set_line_width(cr, 1);
435 if (((_elements & Indicator)==Indicator)) {
437 /* move to the center of the indicator/led */
441 if (_elements & Text) {
443 cairo_translate (cr, text_margin + (_diameter/2.0), get_height()/2.0);
445 cairo_translate (cr, get_width() - ((_diameter/2.0) + 4.0), get_height()/2.0);
448 cairo_translate (cr, get_width()/2.0, get_height()/2.0);
452 if (!_flat_buttons) {
453 cairo_arc (cr, 0, 0, _diameter/2, 0, 2 * M_PI);
454 cairo_set_source (cr, led_inset_pattern);
459 cairo_set_source_rgb (cr, 0, 0, 0);
460 cairo_arc (cr, 0, 0, _diameter/2-1, 0, 2 * M_PI);
464 ArdourCanvas::set_source_rgba (cr, led_color);
465 cairo_arc (cr, 0, 0, _diameter/2-3, 0, 2 * M_PI);
472 // a transparent gray layer to indicate insensitivity
473 if ((visual_state() & Gtkmm2ext::Insensitive)) {
474 rounded_function (cr, 1, 1, get_width() - 2, get_height() - 2, _corner_radius);
475 cairo_set_source_rgba (cr, 0.505, 0.517, 0.525, 0.6);
479 // if requested, show hovering
480 if (ARDOUR::Config->get_widget_prelight()
481 && !((visual_state() & Gtkmm2ext::Insensitive))) {
483 rounded_function (cr, 1, 1, get_width() - 2, get_height() - 2, _corner_radius);
484 cairo_set_source_rgba (cr, 0.905, 0.917, 0.925, 0.2);
489 //user is currently pressing the button. black outline helps to indicate this
490 if ( _grabbed && !(_elements & (Inactive|Menu))) {
491 rounded_function (cr, 1, 1, get_width() - 2, get_height() - 2, _corner_radius);
492 cairo_set_line_width(cr, 2);
493 cairo_set_source_rgba (cr, 0.1, 0.1, 0.1, .5); // XXX no longer 'black'
497 //some buttons (like processor boxes) can be selected (so they can be deleted). Draw a selection indicator
498 if (visual_state() & Gtkmm2ext::Selected) {
499 #if 0 // outline, edge + 1px outside
500 cairo_set_line_width(cr, 2);
501 cairo_set_source_rgba (cr, 1, 0, 0, 0.8);
502 #else // replace edge (if any)
503 cairo_set_line_width(cr, 1);
504 cairo_set_source_rgba (cr, 1, 0, 0, 0.8);
506 rounded_function (cr, 0.5, 0.5, get_width() - 1, get_height() - 1, _corner_radius);
510 //I guess this means we have keyboard focus. I don't think this works currently
512 //A: yes, it's keyboard focus and it does work when there's no editor window
513 // (the editor is always the first receiver for KeyDown).
514 // It's needed for eg. the engine-dialog at startup or after closing a sesion.
516 rounded_function (cr, 1.5, 1.5, get_width() - 3, get_height() - 3, _corner_radius);
517 cairo_set_source_rgba (cr, 0.905, 0.917, 0.925, 0.8);
519 cairo_set_dash (cr, &dashes, 1, 0);
520 cairo_set_line_cap (cr, CAIRO_LINE_CAP_BUTT);
521 cairo_set_line_width (cr, 1.0);
523 cairo_set_dash (cr, 0, 0, 0);
528 ArdourButton::set_diameter (float d)
530 _diameter = (d*2) + 5.0;
532 if (_diameter != 0.0) {
533 _fixed_diameter = true;
541 ArdourButton::set_corner_radius (float r)
548 ArdourButton::on_size_request (Gtk::Requisition* req)
553 CairoWidget::on_size_request (req);
555 if ((_elements & Text) && !_text.empty()) {
557 //calc our real width for our string (but ignore the height, because that results in inconsistent button heights)
559 _layout->get_pixel_size (_text_width, ignored);
560 _text_height = char_pixel_height ();
562 if (_text_width + _diameter < 75) {
576 if ((_elements & Indicator) && _fixed_diameter) {
578 req->width = _pixbuf->get_width() + lrint (_diameter) + xpad;
579 req->height = max (_pixbuf->get_height(), (int) lrint (_diameter)) + ypad;
581 req->width = _text_width + lrint (_diameter) + xpad * 2; // margin left+right * 2
582 req->height = max (_text_height, (int) lrint (_diameter)) + ypad;
586 req->width = _pixbuf->get_width() + xpad;
587 req->height = _pixbuf->get_height() + ypad;
589 req->width = _text_width + xpad;
590 req->height = _text_height + ypad;
594 if ((_elements & Menu)) {
595 req->width += _diameter + 4;
598 if ((_elements & RecButton) && !_pixbuf) {
599 assert(!(_elements & Text));
600 req->width += char_pixel_height();
601 req->height += char_pixel_height();
604 req->width += _corner_radius;
608 * This sets the colors used for rendering based on the name of the button, and
609 * thus uses information from the GUI config data.
612 ArdourButton::set_colors ()
614 if (_fixed_colors_set) {
617 std::string name = get_name();
619 fill_active_color = ARDOUR_UI::config()->color_by_name (string_compose ("%1: fill active", name));
620 fill_inactive_color = ARDOUR_UI::config()->color_by_name (string_compose ("%1: fill", name));
622 text_active_color = ARDOUR_UI::config()->color_by_name (string_compose ("%1: text active", name));
623 text_inactive_color = ARDOUR_UI::config()->color_by_name (string_compose ("%1: text", name));
625 led_active_color = ARDOUR_UI::config()->color_by_name (string_compose ("%1: led active", name));
626 led_inactive_color = ARDOUR_UI::config()->color_by_name (string_compose ("%1: led", name));
629 * This sets the colors used for rendering based on two fixed values, rather
630 * than basing them on the button name, and thus information in the GUI config
633 void ArdourButton::set_fixed_colors (const uint32_t color_active, const uint32_t color_inactive)
635 _fixed_colors_set = true;
637 fill_active_color = color_active;
638 fill_inactive_color = color_inactive;
640 unsigned char r, g, b, a;
641 UINT_TO_RGBA(color_active, &r, &g, &b, &a);
643 double white_contrast = (max (double(r), 255.) - min (double(r), 255.)) +
644 (max (double(g), 255.) - min (double(g), 255.)) +
645 (max (double(b), 255.) - min (double(b), 255.));
647 double black_contrast = (max (double(r), 0.) - min (double(r), 0.)) +
648 (max (double(g), 0.) - min (double(g), 0.)) +
649 (max (double(b), 0.) - min (double(b), 0.));
651 text_active_color = (white_contrast > black_contrast) ?
652 RGBA_TO_UINT(255, 255, 255, 255) : /* use white */
653 RGBA_TO_UINT( 0, 0, 0, 255); /* use black */
656 UINT_TO_RGBA(color_inactive, &r, &g, &b, &a);
658 white_contrast = (max (double(r), 255.) - min (double(r), 255.)) +
659 (max (double(g), 255.) - min (double(g), 255.)) +
660 (max (double(b), 255.) - min (double(b), 255.));
662 black_contrast = (max (double(r), 0.) - min (double(r), 0.)) +
663 (max (double(g), 0.) - min (double(g), 0.)) +
664 (max (double(b), 0.) - min (double(b), 0.));
666 text_inactive_color = (white_contrast > black_contrast) ?
667 RGBA_TO_UINT(255, 255, 255, 255) : /* use white */
668 RGBA_TO_UINT( 0, 0, 0, 255); /* use black */
670 /* XXX what about led colors ? */
673 set_name (""); /* this will trigger a "style-changed" message and then set_colors() */
677 ArdourButton::build_patterns ()
679 if (convex_pattern) {
680 cairo_pattern_destroy (convex_pattern);
684 if (concave_pattern) {
685 cairo_pattern_destroy (concave_pattern);
689 if (led_inset_pattern) {
690 cairo_pattern_destroy (led_inset_pattern);
694 convex_pattern = cairo_pattern_create_linear (0.0, 0, 0.0, get_height());
695 cairo_pattern_add_color_stop_rgba (convex_pattern, 0.0, 0,0,0, 0.0);
696 cairo_pattern_add_color_stop_rgba (convex_pattern, 1.0, 0,0,0, 0.35);
699 concave_pattern = cairo_pattern_create_linear (0.0, 0, 0.0, get_height());
700 cairo_pattern_add_color_stop_rgba (concave_pattern, 0.0, 0,0,0, 0.5);
701 cairo_pattern_add_color_stop_rgba (concave_pattern, 0.7, 0,0,0, 0.0);
703 if (_elements & Indicator) {
704 led_inset_pattern = cairo_pattern_create_linear (0.0, 0.0, 0.0, _diameter);
705 cairo_pattern_add_color_stop_rgba (led_inset_pattern, 0, 0,0,0, 0.4);
706 cairo_pattern_add_color_stop_rgba (led_inset_pattern, 1, 1,1,1, 0.7);
713 ArdourButton::set_led_left (bool yn)
719 ArdourButton::on_button_press_event (GdkEventButton *ev)
721 if ((_elements & Indicator) && _led_rect && _distinct_led_click) {
722 if (ev->x >= _led_rect->x && ev->x < _led_rect->x + _led_rect->width &&
723 ev->y >= _led_rect->y && ev->y < _led_rect->y + _led_rect->height) {
728 if (binding_proxy.button_press_handler (ev)) {
735 if (!_act_on_release) {
737 _action->activate ();
742 if (_fallthrough_to_parent)
749 ArdourButton::on_button_release_event (GdkEventButton *ev)
751 if (_hovering && (_elements & Indicator) && _led_rect && _distinct_led_click) {
752 if (ev->x >= _led_rect->x && ev->x < _led_rect->x + _led_rect->width &&
753 ev->y >= _led_rect->y && ev->y < _led_rect->y + _led_rect->height) {
754 signal_led_clicked(); /* EMIT SIGNAL */
764 if (_act_on_release) {
766 _action->activate ();
772 if (_fallthrough_to_parent)
779 ArdourButton::set_distinct_led_click (bool yn)
781 _distinct_led_click = yn;
786 ArdourButton::color_handler ()
794 ArdourButton::on_size_allocate (Allocation& alloc)
796 CairoWidget::on_size_allocate (alloc);
802 ArdourButton::set_controllable (boost::shared_ptr<Controllable> c)
804 watch_connection.disconnect ();
805 binding_proxy.set_controllable (c);
809 ArdourButton::watch ()
811 boost::shared_ptr<Controllable> c (binding_proxy.get_controllable ());
814 warning << _("button cannot watch state of non-existing Controllable\n") << endmsg;
818 c->Changed.connect (watch_connection, invalidator(*this), boost::bind (&ArdourButton::controllable_changed, this), gui_context());
822 ArdourButton::controllable_changed ()
824 float val = binding_proxy.get_controllable()->get_value();
826 if (fabs (val) >= 0.5f) {
827 set_active_state (Gtkmm2ext::ExplicitActive);
829 unset_active_state ();
834 ArdourButton::set_related_action (RefPtr<Action> act)
836 Gtkmm2ext::Activatable::set_related_action (act);
840 action_tooltip_changed ();
842 Glib::RefPtr<ToggleAction> tact = Glib::RefPtr<ToggleAction>::cast_dynamic (_action);
845 tact->signal_toggled().connect (sigc::mem_fun (*this, &ArdourButton::action_toggled));
848 _action->connect_property_changed ("sensitive", sigc::mem_fun (*this, &ArdourButton::action_sensitivity_changed));
849 _action->connect_property_changed ("visible", sigc::mem_fun (*this, &ArdourButton::action_visibility_changed));
850 _action->connect_property_changed ("tooltip", sigc::mem_fun (*this, &ArdourButton::action_tooltip_changed));
855 ArdourButton::action_toggled ()
857 Glib::RefPtr<ToggleAction> tact = Glib::RefPtr<ToggleAction>::cast_dynamic (_action);
860 if (tact->get_active()) {
861 set_active_state (Gtkmm2ext::ExplicitActive);
863 unset_active_state ();
869 ArdourButton::on_style_changed (const RefPtr<Gtk::Style>&)
875 ArdourButton::on_name_changed ()
877 _char_pixel_width = 0;
878 _char_pixel_height = 0;
884 ArdourButton::setup_led_rect ()
888 if (get_width() < 75) {
894 if (_elements & Indicator) {
895 _led_rect = new cairo_rectangle_t;
897 if (_elements & Text) {
899 _led_rect->x = text_margin;
901 _led_rect->x = get_width() - text_margin - _diameter/2.0;
905 _led_rect->x = get_width()/2.0 - _diameter/2.0;
908 _led_rect->y = get_height()/2.0 - _diameter/2.0;
909 _led_rect->width = _diameter;
910 _led_rect->height = _diameter;
919 ArdourButton::set_image (const RefPtr<Gdk::Pixbuf>& img)
926 ArdourButton::set_active_state (Gtkmm2ext::ActiveState s)
928 bool changed = (_active_state != s);
929 CairoWidget::set_active_state (s);
937 ArdourButton::set_visual_state (Gtkmm2ext::VisualState s)
939 bool changed = (_visual_state != s);
940 CairoWidget::set_visual_state (s);
949 ArdourButton::on_focus_in_event (GdkEventFocus* ev)
953 return CairoWidget::on_focus_in_event (ev);
957 ArdourButton::on_focus_out_event (GdkEventFocus* ev)
961 return CairoWidget::on_focus_out_event (ev);
965 ArdourButton::on_key_release_event (GdkEventKey *ev) {
967 (ev->keyval == GDK_KEY_space || ev->keyval == GDK_Return))
971 _action->activate ();
975 return CairoWidget::on_key_release_event (ev);
979 ArdourButton::on_enter_notify_event (GdkEventCrossing* ev)
981 _hovering = (_elements & Inactive) ? false : true;
983 if (ARDOUR::Config->get_widget_prelight()) {
987 return CairoWidget::on_enter_notify_event (ev);
991 ArdourButton::on_leave_notify_event (GdkEventCrossing* ev)
995 if (ARDOUR::Config->get_widget_prelight()) {
999 return CairoWidget::on_leave_notify_event (ev);
1003 ArdourButton::set_tweaks (Tweaks t)
1012 ArdourButton::action_sensitivity_changed ()
1014 if (_action->property_sensitive ()) {
1015 set_visual_state (Gtkmm2ext::VisualState (visual_state() & ~Gtkmm2ext::Insensitive));
1017 set_visual_state (Gtkmm2ext::VisualState (visual_state() | Gtkmm2ext::Insensitive));
1023 ArdourButton::recalc_char_pixel_geometry ()
1025 if (_char_pixel_height > 0 && _char_pixel_width > 0) {
1029 _layout = Pango::Layout::create (get_pango_context());
1031 // NB. this is not static, since the geometry is different
1032 // depending on the font used.
1034 std::string t = _layout->get_text();
1035 std::string x = _("ABCDEFGHIJLKMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789");
1036 _layout->set_text (x);
1037 _layout->get_pixel_size (w, h);
1038 _layout->set_text (t);
1039 _char_pixel_height = std::max(4, h);
1040 // number of actual chars in the string (not bytes)
1041 // Glib to the rescue.
1042 Glib::ustring gx(x);
1043 _char_pixel_width = std::max(4, w / (int)gx.size());
1047 ArdourButton::action_visibility_changed ()
1049 if (_action->property_visible ()) {
1057 ArdourButton::action_tooltip_changed ()
1059 string str = _action->property_tooltip().get_value();
1060 ARDOUR_UI::instance()->set_tip (*this, str);
1064 ArdourButton::set_elements (Element e)
1070 ArdourButton::add_elements (Element e)
1072 _elements = (ArdourButton::Element) (_elements | e);