From a6317060599e7a17eddc6172eab28bfed4cb1b97 Mon Sep 17 00:00:00 2001 From: Robin Gareus Date: Sun, 11 Dec 2016 01:33:23 +0100 Subject: Rework shuttle control display --- gtk2_ardour/shuttle_control.cc | 119 +++++++++++++++++------------------------ 1 file changed, 50 insertions(+), 69 deletions(-) (limited to 'gtk2_ardour/shuttle_control.cc') diff --git a/gtk2_ardour/shuttle_control.cc b/gtk2_ardour/shuttle_control.cc index fec3547e1e..70293cd20e 100644 --- a/gtk2_ardour/shuttle_control.cc +++ b/gtk2_ardour/shuttle_control.cc @@ -16,6 +16,8 @@ Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. */ +#define BASELINESTRETCH (1.25) + #include #include @@ -55,11 +57,14 @@ ShuttleControl::ShuttleControl () , binding_proxy (_controllable) , text_color (0) { - left_text = Pango::Layout::create (get_pango_context()); - right_text = Pango::Layout::create (get_pango_context()); - right_text->set_attributes (text_attributes); - left_text->set_attributes (text_attributes); + Pango::AttrFontDesc* font_attr; + font_attr = new Pango::AttrFontDesc (Pango::Attribute::create_attr_font_desc (UIConfiguration::instance().get_NormalFont())); + text_attributes.change (*font_attr); + delete font_attr; + + _text = Pango::Layout::create (get_pango_context()); + _text->set_attributes (text_attributes); set_tooltip (*this, _("Shuttle speed control (Context-click for options)")); @@ -78,9 +83,16 @@ ShuttleControl::ShuttleControl () set_flags (CAN_FOCUS); add_events (Gdk::ENTER_NOTIFY_MASK|Gdk::LEAVE_NOTIFY_MASK|Gdk::BUTTON_RELEASE_MASK|Gdk::BUTTON_PRESS_MASK|Gdk::POINTER_MOTION_MASK|Gdk::SCROLL_MASK); - set_size_request (85, 20); set_name (X_("ShuttleControl")); + int tw, th, h; + ensure_style (); + _text->set_text ("@Sp"); + _text->get_pixel_size (tw, th); + h = (int) ceil(th * BASELINESTRETCH + 1.0); + if ((h - th) & 1) { ++h; } + set_size_request (85, h); + shuttle_max_speed = Config->get_shuttle_max_speed(); if (shuttle_max_speed >= 8.f) { shuttle_max_speed = 8.0f; } @@ -146,13 +158,6 @@ ShuttleControl::on_size_allocate (Gtk::Allocation& alloc) cairo_pattern_add_color_stop_rgba (shine_pattern, 0, 1,1,1,0.0); cairo_pattern_add_color_stop_rgba (shine_pattern, 0.2, 1,1,1,0.4); cairo_pattern_add_color_stop_rgba (shine_pattern, 1, 1,1,1,0.1); - - Pango::AttrFontDesc* font_attr; - - font_attr = new Pango::AttrFontDesc (Pango::Attribute::create_attr_font_desc (UIConfiguration::instance().get_NormalBoldFont())); - text_attributes.change (*font_attr); - - delete font_attr; } void @@ -594,13 +599,19 @@ ShuttleControl::set_colors () void ShuttleControl::render (cairo_t* cr, cairo_rectangle_t*) { - //black border + // center slider line + float yc = get_height() / 2; + float lw = 3; + cairo_set_line_cap (cr, CAIRO_LINE_CAP_ROUND); + cairo_set_line_width (cr, 3); + cairo_move_to (cr, lw, yc); + cairo_line_to (cr, get_width () - lw, yc); cairo_set_source_rgb (cr, bg_r, bg_g, bg_b); - rounded_rectangle (cr, 0, 0, get_width(), get_height(), 4); - cairo_fill (cr); + cairo_stroke (cr); float speed = 0.0; float acutal_speed = 0.0; + char buf[32]; if (_session) { speed = _session->transport_speed (); @@ -610,87 +621,55 @@ ShuttleControl::render (cairo_t* cr, cairo_rectangle_t*) } } - /* Marker */ - float visual_fraction = std::min (1.0f, speed / shuttle_max_speed); - float marker_size = get_height() - 5.0; - float avail_width = get_width() - marker_size - 4; - float x = get_width() * 0.5 + visual_fraction * avail_width * 0.5; -// cairo_set_source_rgb (cr, 0, 1, 0.0); - cairo_set_source (cr, pattern); - if (speed == 1.0) { - cairo_move_to( cr, x, 2.5); - cairo_line_to( cr, x + marker_size * .577, 2.5 + marker_size * 0.5); - cairo_line_to( cr, x, 2.5 + marker_size); - cairo_close_path(cr); - } else if ( speed ==0.0 ) - rounded_rectangle (cr, x, 2.5, marker_size, marker_size, 1); - else - cairo_arc (cr, x, 2.5 + marker_size * .5, marker_size * 0.47, 0, 2.0 * M_PI); - cairo_set_line_width (cr, 1.75); - cairo_stroke (cr); - - /* speed text */ + /* marker */ + float visual_fraction = std::max (-1.0f, std::min (1.0f, speed / shuttle_max_speed)); + float marker_size = round (get_height() * 0.66); + float avail_width = get_width() - marker_size; + float x = 0.5 * (get_width() + visual_fraction * avail_width - marker_size); - char buf[32]; + rounded_rectangle (cr, x, 0, marker_size, get_height(), 5); + cairo_set_source_rgba (cr, 0, 0, 0, 1); + cairo_fill(cr); + rounded_rectangle (cr, x + 1, 1, marker_size - 2, get_height() - 2, 3.5); + cairo_set_source (cr, pattern); + cairo_fill(cr); + /* text */ if (acutal_speed != 0) { - if (Config->get_shuttle_units() == Percentage) { - if (acutal_speed == 1.0) { snprintf (buf, sizeof (buf), "%s", _("Playing")); } else { if (acutal_speed < 0.0) { - snprintf (buf, sizeof (buf), "<<< %.1f%%", -acutal_speed * 100.f); + snprintf (buf, sizeof (buf), "< %.1f%%", -acutal_speed * 100.f); } else { - snprintf (buf, sizeof (buf), ">>> %.1f%%", acutal_speed * 100.f); + snprintf (buf, sizeof (buf), "> %.1f%%", acutal_speed * 100.f); } } - } else { - bool reversed; int semi = speed_as_semitones (acutal_speed, reversed); - if (reversed) { - snprintf (buf, sizeof (buf), _("<<< %+d semitones"), semi); + snprintf (buf, sizeof (buf), _("< %+2d semi"), semi); } else { - snprintf (buf, sizeof (buf), _(">>> %+d semitones"), semi); + snprintf (buf, sizeof (buf), _("> %+2d semi"), semi); } } - } else { snprintf (buf, sizeof (buf), "%s", _("Stopped")); } last_speed_displayed = acutal_speed; - const float top_text_margin = 3.0f; - const float side_text_margin = 5.0f; - - left_text->set_text (buf); - cairo_move_to (cr, side_text_margin, top_text_margin); - pango_cairo_show_layout (cr, left_text->gobj()); - - /* style text */ - - switch (Config->get_shuttle_behaviour()) { - case Sprung: - snprintf (buf, sizeof (buf), "%s", _("Sprung")); - break; - case Wheel: - snprintf (buf, sizeof (buf), "%s", _("Wheel")); - break; - } - - right_text->set_text (buf); - Pango::Rectangle r = right_text->get_ink_extents (); - cairo_move_to (cr, get_width() - ((r.get_width()/PANGO_SCALE) + side_text_margin), top_text_margin); - pango_cairo_show_layout (cr, right_text->gobj()); + int tw, th; + _text->set_text (buf); + _text->get_pixel_size (tw, th); + cairo_move_to (cr, 0.5 * (get_width() - tw), 0.5 * (get_height() - th)); + pango_cairo_show_layout (cr, _text->gobj()); if (UIConfiguration::instance().get_widget_prelight()) { if (_hovering) { - rounded_rectangle (cr, 1, 1, get_width()-2, get_height()-2, 4.0); + rounded_rectangle (cr, 0, 0, get_width(), get_height(), 3.5); cairo_set_source_rgba (cr, 1, 1, 1, 0.15); cairo_fill (cr); } @@ -766,6 +745,8 @@ ShuttleControl::parameter_changed (std::string p) break; } + } else if (p == "shuttle-max-speed") { + queue_draw (); } else if (p == "shuttle-units") { queue_draw (); } -- cgit v1.2.3