fix spelling error
[ardour.git] / gtk2_ardour / ardour_button.cc
index f3f7789f4670d2fac6ea383f240da8d9d1575ceb..03c9f562366697fa3fe59669344ae867ad613677 100644 (file)
@@ -34,6 +34,7 @@
 #include "ardour/rc_configuration.h" // for widget prelight preference
 
 #include "canvas/utils.h"
+#include "canvas/colors.h"
 
 #include "ardour_button.h"
 #include "ardour_ui.h"
@@ -76,6 +77,8 @@ ArdourButton::ArdourButton (Element e)
        , text_inactive_color(0)
        , led_active_color(0)
        , led_inactive_color(0)
+       , led_custom_color (0)
+       , use_custom_led_color (false)
        , convex_pattern (0)
        , concave_pattern (0)
        , led_inset_pattern (0)
@@ -112,6 +115,8 @@ ArdourButton::ArdourButton (const std::string& str, Element e)
        , text_inactive_color(0)
        , led_active_color(0)
        , led_inactive_color(0)
+       , led_custom_color (0)
+       , use_custom_led_color (false)
        , convex_pattern (0)
        , concave_pattern (0)
        , led_inset_pattern (0)
@@ -150,6 +155,16 @@ ArdourButton::~ArdourButton()
        }
 }
 
+void
+ArdourButton::set_layout_font (const Pango::FontDescription& fd)
+{
+       ensure_layout ();
+       if (_layout) {
+               _layout->set_font_description (fd);
+               queue_resize ();
+       }
+}
+
 void
 ArdourButton::set_text (const std::string& str)
 {
@@ -198,6 +213,10 @@ ArdourButton::render (cairo_t* cr, cairo_rectangle_t *)
                led_color = led_inactive_color;
        }
 
+       if (use_custom_led_color) {
+               led_color = led_custom_color;
+       }
+
        void (*rounded_function)(cairo_t*, double, double, double, double, double);
 
        switch (_corner_mask) {
@@ -253,7 +272,7 @@ ArdourButton::render (cairo_t* cr, cairo_rectangle_t *)
 
        //show the "convex" or "concave" gradient
        if (!_flat_buttons) {
-               if ( active_state() == Gtkmm2ext::ExplicitActive && !((_elements & Indicator)==Indicator) ) {
+               if ( active_state() == Gtkmm2ext::ExplicitActive && ( !((_elements & Indicator)==Indicator) || use_custom_led_color) ) {
                        //concave
                        cairo_set_source (cr, concave_pattern);
                        Gtkmm2ext::rounded_rectangle (cr, 1, 1, get_width() - 2, get_height() - 2, _corner_radius);
@@ -500,15 +519,16 @@ ArdourButton::render (cairo_t* cr, cairo_rectangle_t *)
                cairo_restore (cr);
        }
 
-       // a transparent gray layer to indicate insensitivity
+       // a transparent overlay to indicate insensitivity
        if ((visual_state() & Gtkmm2ext::Insensitive)) {
-               rounded_function (cr, 1, 1, get_width() - 2, get_height() - 2, _corner_radius);
-               cairo_set_source_rgba (cr, 0.505, 0.517, 0.525, 0.6);
+               rounded_function (cr, 0, 0, get_width(), get_height(), _corner_radius);
+               uint32_t ins_color = ARDOUR_UI::config()->color ("gtk_background");
+               ArdourCanvas::set_source_rgb_a (cr, ins_color, 0.6);
                cairo_fill (cr);
        }
 
        // if requested, show hovering
-       if (ARDOUR::Config->get_widget_prelight()
+       if (ARDOUR_UI::config()->get_widget_prelight()
                        && !((visual_state() & Gtkmm2ext::Insensitive))) {
                if (_hovering) {
                        rounded_function (cr, 1, 1, get_width() - 2, get_height() - 2, _corner_radius);
@@ -575,7 +595,7 @@ ArdourButton::on_size_request (Gtk::Requisition* req)
        CairoWidget::on_size_request (req);
 
        if (_diameter == 0) {
-               const float newdia = rint (ARDOUR::Config->get_font_scale () / 1024. / 7.5); // 11px with 80% font-scaling
+               const float newdia = rint (ARDOUR_UI::config()->get_font_scale () / 9600.0); // 11px with 100% font-scaling
                if (_diameter != newdia) {
                        _pattern_height = 0;
                        _diameter = newdia;
@@ -652,15 +672,33 @@ ArdourButton::set_colors ()
                return;
        }
        std::string name = get_name();
+       bool failed = false;
+
+       fill_active_color = ARDOUR_UI::config()->color (string_compose ("%1: fill active", name), &failed);
+       if (failed) {
+               fill_active_color = ARDOUR_UI::config()->color ("generic button: fill active");
+       }
+       fill_inactive_color = ARDOUR_UI::config()->color (string_compose ("%1: fill", name), &failed);
+       if (failed) {
+               fill_inactive_color = ARDOUR_UI::config()->color ("generic button: fill");
+       }
 
-       fill_active_color = ARDOUR_UI::config()->color_by_name (string_compose ("%1: fill active", name));
-       fill_inactive_color = ARDOUR_UI::config()->color_by_name (string_compose ("%1: fill", name));
+       text_active_color = ArdourCanvas::contrasting_text_color (fill_active_color);
+       text_inactive_color = ArdourCanvas::contrasting_text_color (fill_inactive_color);
 
-       text_active_color = ARDOUR_UI::config()->color_by_name (string_compose ("%1: text active", name));
-       text_inactive_color = ARDOUR_UI::config()->color_by_name (string_compose ("%1: text", name));
+       led_active_color = ARDOUR_UI::config()->color (string_compose ("%1: led active", name), &failed);
+       if (failed) {
+               led_active_color = ARDOUR_UI::config()->color ("generic button: led active");
+       }
+
+       /* The inactive color for the LED is just a fairly dark version of the
+        * active color.
+        */
+       
+       ArdourCanvas::HSV inactive (led_active_color);
+       inactive.v = 0.35;
 
-       led_active_color = ARDOUR_UI::config()->color_by_name (string_compose ("%1: led active", name));
-       led_inactive_color = ARDOUR_UI::config()->color_by_name (string_compose ("%1: led", name));
+       led_inactive_color = inactive.color ();
 }
 
 /**
@@ -755,7 +793,7 @@ ArdourButton::on_button_press_event (GdkEventButton *ev)
 {
        focus_handler ();
 
-       if ((_elements & Indicator) && _led_rect && _distinct_led_click) {
+       if (ev->button == 1 && (_elements & Indicator) && _led_rect && _distinct_led_click) {
                if (ev->x >= _led_rect->x && ev->x < _led_rect->x + _led_rect->width &&
                    ev->y >= _led_rect->y && ev->y < _led_rect->y + _led_rect->height) {
                        return true;
@@ -769,7 +807,7 @@ ArdourButton::on_button_press_event (GdkEventButton *ev)
        _grabbed = true;
        CairoWidget::set_dirty ();
 
-       if (!_act_on_release) {
+       if (ev->button == 1 && !_act_on_release) {
                if (_action) {
                        _action->activate ();
                        return true;
@@ -785,7 +823,7 @@ ArdourButton::on_button_press_event (GdkEventButton *ev)
 bool
 ArdourButton::on_button_release_event (GdkEventButton *ev)
 {
-       if (_hovering && (_elements & Indicator) && _led_rect && _distinct_led_click) {
+       if (ev->button == 1 && _hovering && (_elements & Indicator) && _led_rect && _distinct_led_click) {
                if (ev->x >= _led_rect->x && ev->x < _led_rect->x + _led_rect->width &&
                    ev->y >= _led_rect->y && ev->y < _led_rect->y + _led_rect->height) {
                        signal_led_clicked(); /* EMIT SIGNAL */
@@ -796,7 +834,7 @@ ArdourButton::on_button_release_event (GdkEventButton *ev)
        _grabbed = false;
        CairoWidget::set_dirty ();
 
-       if (_hovering) {
+       if (ev->button == 1 && _hovering) {
                signal_clicked ();
                if (_act_on_release) {
                        if (_action) {
@@ -1014,7 +1052,7 @@ ArdourButton::on_enter_notify_event (GdkEventCrossing* ev)
 {
        _hovering = (_elements & Inactive) ? false : true;
 
-       if (ARDOUR::Config->get_widget_prelight()) {
+       if (ARDOUR_UI::config()->get_widget_prelight()) {
                CairoWidget::set_dirty ();
        }
 
@@ -1026,7 +1064,7 @@ ArdourButton::on_leave_notify_event (GdkEventCrossing* ev)
 {
        _hovering = false;
 
-       if (ARDOUR::Config->get_widget_prelight()) {
+       if (ARDOUR_UI::config()->get_widget_prelight()) {
                CairoWidget::set_dirty ();
        }
 
@@ -1055,7 +1093,7 @@ ArdourButton::action_sensitivity_changed ()
 }
 
 void
-ArdourButton::set_layout_ellisize_width (int w)
+ArdourButton::set_layout_ellipsize_width (int w)
 {
        if (_layout_ellipsize_width == w) {
                return;
@@ -1064,8 +1102,11 @@ ArdourButton::set_layout_ellisize_width (int w)
        if (!_layout) {
                return;
        }
-       if (_layout_ellipsize_width > 0) {
-       _layout->set_width (_layout_ellipsize_width);
+       if (_layout_ellipsize_width > 3 * PANGO_SCALE) {
+               _layout->set_width (_layout_ellipsize_width - 3 * PANGO_SCALE);
+       }
+       if (is_realized ()) {
+               queue_resize ();
        }
 }
 
@@ -1080,8 +1121,8 @@ ArdourButton::set_text_ellipsize (Pango::EllipsizeMode e)
                return;
        }
        _layout->set_ellipsize(_ellipsis);
-       if (_layout_ellipsize_width > 0) {
-               _layout->set_width (_layout_ellipsize_width);
+       if (_layout_ellipsize_width > 3 * PANGO_SCALE) {
+               _layout->set_width (_layout_ellipsize_width - 3 * PANGO_SCALE);
        }
        if (is_realized ()) {
                queue_resize ();
@@ -1095,8 +1136,8 @@ ArdourButton::ensure_layout ()
                ensure_style ();
                _layout = Pango::Layout::create (get_pango_context());
                _layout->set_ellipsize(_ellipsis);
-               if (_layout_ellipsize_width > 0) {
-                       _layout->set_width (_layout_ellipsize_width);
+               if (_layout_ellipsize_width > 3 * PANGO_SCALE) {
+                       _layout->set_width (_layout_ellipsize_width - 3* PANGO_SCALE);
                }
        }
 }
@@ -1153,3 +1194,15 @@ ArdourButton::add_elements (Element e)
        _elements = (ArdourButton::Element) (_elements | e);
        CairoWidget::set_dirty ();
 }
+
+void
+ArdourButton::set_custom_led_color (uint32_t c, bool useit)
+{
+       if (led_custom_color == c && use_custom_led_color == useit) {
+               return;
+       }
+
+       led_custom_color = c;
+       use_custom_led_color = useit;
+       CairoWidget::set_dirty ();
+}