From 1d5c6104f50b97dd3c796852c93d9b09fef41360 Mon Sep 17 00:00:00 2001 From: Robin Gareus Date: Sun, 24 May 2015 21:45:39 +0200 Subject: [PATCH] replace old ArdourButton::Icon API with Gtkmm2ext. --- gtk2_ardour/ardour_button.cc | 395 +--------------------------- gtk2_ardour/ardour_button.h | 26 +- gtk2_ardour/ardour_ui2.cc | 18 +- gtk2_ardour/automation_time_axis.cc | 2 +- gtk2_ardour/editor.cc | 4 +- gtk2_ardour/mixer_strip.cc | 6 +- gtk2_ardour/route_ui.cc | 6 +- 7 files changed, 25 insertions(+), 432 deletions(-) diff --git a/gtk2_ardour/ardour_button.cc b/gtk2_ardour/ardour_button.cc index 07163f97a7..16770f4a99 100644 --- a/gtk2_ardour/ardour_button.cc +++ b/gtk2_ardour/ardour_button.cc @@ -59,7 +59,7 @@ ArdourButton::Element ArdourButton::just_led_default_elements = ArdourButton::El ArdourButton::ArdourButton (Element e) : _elements (e) - , _icon (ArdourButton::NoIcon) + , _icon (Gtkmm2ext::ArdourIcon::NoIcon) , _tweaks (Tweaks (0)) , _char_pixel_width (0) , _char_pixel_height (0) @@ -203,395 +203,6 @@ ArdourButton::set_alignment (const float xa, const float ya) * Option 2: * ARDOUR_UI_UTILS::render_vector_icon() */ -static void -render_vector_icon (cairo_t *cr, - const enum ArdourButton::Icon icon, - const int width, const int height, - const Gtkmm2ext::ActiveState state, - const ArdourCanvas::Color fg_color) -{ - -#define VECTORICONSTROKEFILL(fillalpha) \ - cairo_set_line_width(cr, 1.5); \ - cairo_set_source_rgba (cr, 0, 0, 0, 1.0); \ - cairo_stroke_preserve(cr); \ - cairo_set_source_rgba (cr, 1, 1, 1, (fillalpha)); \ - cairo_fill(cr); - -#define VECTORICONSTROKEOUTLINE() \ - cairo_set_line_cap (cr, CAIRO_LINE_CAP_ROUND); \ - cairo_set_line_width(cr, 3.0); \ - cairo_set_source_rgba (cr, 0, 0, 0, 1.0); \ - cairo_stroke_preserve(cr); \ - ArdourCanvas::set_source_rgba (cr, fg_color); \ - cairo_set_line_width(cr, 1.5); \ - cairo_stroke(cr); - - - /* TODO separate these into dedicated class - * it may also be efficient to render them only once for every size (image-surface) */ - switch (icon) { - - case ArdourButton::RecTapeMode: - { - const double x = width * .5; - const double y = height * .5; - const double r = std::min(x, y) * .6; - const double slit = .11 * M_PI; - cairo_save(cr); - cairo_translate(cr, x, y); - - cairo_arc (cr, 0, 0, r, 0, 2 * M_PI); - if (state == Gtkmm2ext::ExplicitActive) { - cairo_set_source_rgba (cr, .95, .1, .1, 1.); - } else { - cairo_set_source_rgba (cr, .95, .44, .44, 1.); // #f46f6f - } - cairo_fill_preserve(cr); - cairo_set_source_rgba (cr, .0, .0, .0, .5); - cairo_set_line_width(cr, 1); - cairo_stroke(cr); - - cairo_save(cr); - cairo_set_source_rgba (cr, .15, .07, .07, 1.0); - - cairo_rotate (cr, -.5 * M_PI); - cairo_move_to(cr, 0, 0); - cairo_arc (cr, 0, 0, r *.85, -slit, slit); - cairo_line_to(cr, 0, 0); - cairo_close_path(cr); - - cairo_fill(cr); - cairo_rotate (cr, 2. * M_PI / 3.); - - cairo_move_to(cr, 0, 0); - cairo_arc (cr, 0, 0, r *.85, -slit, slit); - cairo_line_to(cr, 0, 0); - cairo_close_path(cr); - cairo_fill(cr); - - cairo_rotate (cr, 2. * M_PI / 3.); - cairo_move_to(cr, 0, 0); - cairo_arc (cr, 0, 0, r *.85, -slit, slit); - cairo_line_to(cr, 0, 0); - cairo_close_path(cr); - cairo_fill(cr); - - cairo_restore(cr); - - cairo_arc (cr, 0, 0, r * .3, 0, 2 * M_PI); - if (state == Gtkmm2ext::ExplicitActive) - cairo_set_source_rgba (cr, .95, .1, .1, 1.); - else - cairo_set_source_rgba (cr, .95, .44, .44, 1.); // #f46f6f - cairo_fill(cr); - cairo_set_source_rgba (cr, .0, .0, .0, 1.0); - cairo_arc (cr, 0, 0, r *.15, 0, 2 * M_PI); // hole in the middle - cairo_fill(cr); - - cairo_restore(cr); - } - break; - case ArdourButton::RecButton: - { - const double x = width * .5; - const double y = height * .5; - const double r = std::min(x, y) * .55; - cairo_arc (cr, x, y, r, 0, 2 * M_PI); - if (state == Gtkmm2ext::ExplicitActive) - cairo_set_source_rgba (cr, .95, .1, .1, 1.); - else - cairo_set_source_rgba (cr, .95, .44, .44, 1.); // #f46f6f - cairo_fill_preserve(cr); - cairo_set_source_rgba (cr, .0, .0, .0, .8); - cairo_set_line_width(cr, 1); - cairo_stroke(cr); - } - break; - case ArdourButton::CloseCross: - { - const double x = width * .5; - const double y = height * .5; - const double o = .5 + std::min(x, y) * .4; - ArdourCanvas::set_source_rgba (cr, fg_color); - cairo_set_line_width(cr, 1); - cairo_move_to(cr, x-o, y-o); - cairo_line_to(cr, x+o, y+o); - cairo_move_to(cr, x+o, y-o); - cairo_line_to(cr, x-o, y+o); - cairo_stroke(cr); - } - break; - case ArdourButton::StripWidth: - { - const double x0 = width * .2; - const double x1 = width * .8; - - const double y0 = height * .25; - const double y1= height * .75; - - const double ym= height * .5; - - // arrow - const double xa0= height * .39; - const double xa1= height * .61; - const double ya0= height * .35; - const double ya1= height * .65; - - ArdourCanvas::set_source_rgba (cr, fg_color); - cairo_set_line_width(cr, 1); - - // left + right - cairo_move_to(cr, x0, y0); - cairo_line_to(cr, x0, y1); - cairo_move_to(cr, x1, y0); - cairo_line_to(cr, x1, y1); - - // horiz center line - cairo_move_to(cr, x0, ym); - cairo_line_to(cr, x1, ym); - - // arrow left - cairo_move_to(cr, x0, ym); - cairo_line_to(cr, xa0, ya0); - cairo_move_to(cr, x0, ym); - cairo_line_to(cr, xa0, ya1); - - // arrow right - cairo_move_to(cr, x1, ym); - cairo_line_to(cr, xa1, ya0); - cairo_move_to(cr, x1, ym); - cairo_line_to(cr, xa1, ya1); - cairo_stroke(cr); - } - break; - case ArdourButton::DinMidi: - { - const double x = width * .5; - const double y = height * .5; - const double r = std::min(x, y) * .75; - ArdourCanvas::set_source_rgba (cr, fg_color); - cairo_set_line_width(cr, 1); - cairo_arc (cr, x, y, r, .57 * M_PI, 2.43 * M_PI); - cairo_stroke(cr); - - // pins equally spaced 45deg - cairo_arc (cr, x, y * 0.5, r * .15, 0, 2 * M_PI); - cairo_fill(cr); - cairo_arc (cr, x * 0.5, y, r * .15, 0, 2 * M_PI); - cairo_fill(cr); - cairo_arc (cr, x * 1.5, y, r * .15, 0, 2 * M_PI); - cairo_fill(cr); - // .5 + .5 * .5 * sin(45deg), 1.5 - .5 * .5 * cos(45deg) - cairo_arc (cr, x * 0.677, y * .677, r * .15, 0, 2 * M_PI); - cairo_fill(cr); - cairo_arc (cr, x * 1.323, y * .677, r * .15, 0, 2 * M_PI); - cairo_fill(cr); - - // bottom notch - cairo_arc (cr, x, y+r, r * .26, 1.05 * M_PI, 1.95 * M_PI); - cairo_stroke(cr); - } - break; - case ArdourButton::TransportStop: - { - const int wh = std::min (width, height); - cairo_rectangle (cr, - (width - wh) * .5 + wh * .25, - (height - wh) * .5 + wh * .25, - wh * .5, wh * .5); - - VECTORICONSTROKEFILL(0.8); - } - break; - case ArdourButton::TransportPlay: - { - const int wh = std::min (width, height) * .5; - const double y = height * .5; - const double x = width - wh; - - const float tri = ceil(.577 * wh); // 1/sqrt(3) - - cairo_move_to (cr, x + wh * .5, y); - cairo_line_to (cr, x - wh * .5, y - tri); - cairo_line_to (cr, x - wh * .5, y + tri); - cairo_close_path (cr); - - VECTORICONSTROKEFILL(0.8); - } - break; - case ArdourButton::TransportPanic: - { - const int wh = std::min (width, height) * .1; - const double xc = width * .5; - const double yh = height; - cairo_rectangle (cr, - xc - wh, yh *.19, - wh * 2, yh *.41); - VECTORICONSTROKEFILL(0.8); - - cairo_arc (cr, xc, yh *.75, wh, 0, 2 * M_PI); - VECTORICONSTROKEFILL(0.8); - } - break; - case ArdourButton::TransportStart: - case ArdourButton::TransportEnd: - case ArdourButton::TransportRange: - { - // small play triangle - int wh = std::min (width, height); - const double y = height * .5; - const double x = width - wh * .5; - wh *= .18; - const float tri = ceil(.577 * wh * 2); // 1/sqrt(3) - - const float ln = std::min (width, height) * .07; - - if (icon == ArdourButton::TransportStart || icon == ArdourButton::TransportRange) { - cairo_rectangle (cr, - x - wh - ln, y - tri * 1.7, - ln * 2, tri * 3.4); - - VECTORICONSTROKEFILL(1.0); - } - - if (icon == ArdourButton::TransportEnd || icon == ArdourButton::TransportRange) { - cairo_rectangle (cr, - x + wh - ln, y - tri * 1.7, - ln * 2, tri * 3.4); - - VECTORICONSTROKEFILL(1.0); - } - - if (icon == ArdourButton::TransportStart) { - cairo_move_to (cr, x - wh, y); - cairo_line_to (cr, x + wh, y - tri); - cairo_line_to (cr, x + wh, y + tri); - } else { - cairo_move_to (cr, x + wh, y); - cairo_line_to (cr, x - wh, y - tri); - cairo_line_to (cr, x - wh, y + tri); - } - - cairo_close_path (cr); - VECTORICONSTROKEFILL(1.0); - } - break; - case ArdourButton::TransportLoop: - { - const double x = width * .5; - const double y = height * .5; - const double r = std::min(x, y); - - cairo_arc (cr, x, y, r * .62, 0, 2 * M_PI); - cairo_arc_negative (cr, x, y, r * .35, 2 * M_PI, 0); - - VECTORICONSTROKEFILL(1.0); -#define ARCARROW(rad, ang) \ - x + (rad) * sin((ang) * 2.0 * M_PI), y + (rad) * cos((ang) * 2.0 * M_PI) - - cairo_move_to (cr, ARCARROW(r * .35, .72)); - cairo_line_to (cr, ARCARROW(r * .15, .72)); - cairo_line_to (cr, ARCARROW(r * .56, .60)); - cairo_line_to (cr, ARCARROW(r * .75, .72)); - cairo_line_to (cr, ARCARROW(r * .62, .72)); - - cairo_set_source_rgba (cr, 0, 0, 0, 1.0); - cairo_stroke_preserve(cr); - cairo_close_path (cr); - cairo_set_source_rgba (cr, 1, 1, 1, 1.0); - cairo_fill(cr); -#undef ARCARROW - } - break; - case ArdourButton::TransportMetronom: - { - const double x = width * .5; - const double y = height * .5; - const double wh = std::min(x, y); - const double h = wh * .85; - const double w = wh * .55; - const double lw = w * .34; - - cairo_rectangle (cr, - x - w * .7, y + h * .25, - w * 1.4, lw); - - VECTORICONSTROKEFILL(1.0); - - cairo_move_to (cr, x - w, y + h); - cairo_line_to (cr, x + w, y + h); - cairo_line_to (cr, x + w * .35, y - h); - cairo_line_to (cr, x - w * .35, y - h); - cairo_line_to (cr, x - w, y + h); - - cairo_move_to (cr, x - w + lw, y + h -lw); - cairo_line_to (cr, x - w * .35 + lw, y - h + lw); - cairo_line_to (cr, x + w * .35 - lw, y - h + lw); - cairo_line_to (cr, x + w - lw, y + h -lw); - cairo_line_to (cr, x - w + lw, y + h -lw); - - VECTORICONSTROKEFILL(1.0); - - // ddx = .70 w = .75 * .5 wh = .375 wh - // ddy = .75 h - lw = .75 * .8 wh - wh .5 * .2 = .5 wh - // ang = (ddx/ddy): - // -> angle = atan (ang) = atan (375 / .5) ~= 36deg - const double dx = lw * .2; // 1 - cos(tan^-1(ang)) - const double dy = lw * .4; // 1 - sin(tan^-1(ang)) - cairo_move_to (cr, x - w * .3 , y + h * .25 + lw * .5); - cairo_line_to (cr, x - w + dx , y - h + lw + dy); - cairo_line_to (cr, x - w + lw , y - h + lw); - cairo_line_to (cr, x - w * .3 + lw, y + h * .25 + lw * .5); - cairo_close_path (cr); - - VECTORICONSTROKEFILL(1.0); - - cairo_rectangle (cr, - x - w * .7, y + h * .25, - w * 1.4, lw); - cairo_fill(cr); - } - break; - case ArdourButton::NudgeLeft: - { - const double x = width * .5; - const double y = height * .5; - const double wh = std::min (x, y); - - const double tri_x = .3 * wh; - const double tri_y = .6 * wh; - - cairo_move_to (cr, x + tri_x, y - tri_y); - cairo_line_to (cr, x - tri_x, y); - cairo_line_to (cr, x + tri_x, y + tri_y); - VECTORICONSTROKEOUTLINE(); - } - break; - case ArdourButton::NudgeRight: - { - - const double x = width * .5; - const double y = height * .5; - const double wh = std::min (x, y); - - const double tri_x = .3 * wh; - const double tri_y = .6 * wh; - - cairo_move_to (cr, x - tri_x, y - tri_y); - cairo_line_to (cr, x + tri_x, y); - cairo_line_to (cr, x - tri_x, y + tri_y); - VECTORICONSTROKEOUTLINE(); - - } - break; - default: - // missing icon - assert(0); - } // end case(icon) -#undef VECTORICONSTROKEFILL -} - void ArdourButton::render (cairo_t* cr, cairo_rectangle_t *) { @@ -709,7 +320,7 @@ ArdourButton::render (cairo_t* cr, cairo_rectangle_t *) } else /* VectorIcons are exclusive to Pixbuf Icons */ if (_elements & VectorIcon) { - render_vector_icon (cr, _icon, get_width(), get_height(), active_state(), text_color); + Gtkmm2ext::ArdourIcon::render (cr, _icon, get_width(), get_height(), active_state(), text_color); } const int text_margin = char_pixel_width(); @@ -1518,7 +1129,7 @@ ArdourButton::add_elements (Element e) } void -ArdourButton::set_icon (Icon i) +ArdourButton::set_icon (Gtkmm2ext::ArdourIcon::Icon i) { _icon = i; _elements = (ArdourButton::Element) ((_elements | ArdourButton::VectorIcon) & ~ArdourButton::Text); diff --git a/gtk2_ardour/ardour_button.h b/gtk2_ardour/ardour_button.h index 8d6cb49d73..9df1089246 100644 --- a/gtk2_ardour/ardour_button.h +++ b/gtk2_ardour/ardour_button.h @@ -25,6 +25,7 @@ #include #include "pbd/signals.h" +#include "gtkmm2ext/ardour_icon.h" #include "gtkmm2ext/binding_proxy.h" #include "gtkmm2ext/activatable.h" #include "gtkmm2ext/cairo_widget.h" @@ -43,25 +44,6 @@ class ArdourButton : public CairoWidget , public Gtkmm2ext::Activatable VectorIcon = 0x80, // tentative, see commit message }; - enum Icon { - NoIcon, - RecButton, - RecTapeMode, - CloseCross, - StripWidth, - DinMidi, - TransportStop, - TransportPlay, - TransportLoop, - TransportRange, - TransportStart, - TransportEnd, - TransportPanic, - TransportMetronom, - NudgeLeft, - NudgeRight, - }; - static Element default_elements; static Element led_default_elements; static Element just_led_default_elements; @@ -90,8 +72,8 @@ class ArdourButton : public CairoWidget , public Gtkmm2ext::Activatable void set_elements (Element); void add_elements (Element); - Icon icon() const { return _icon; } - void set_icon (Icon); + Gtkmm2ext::ArdourIcon::Icon icon() const { return _icon; } + void set_icon (Gtkmm2ext::ArdourIcon::Icon); void set_corner_radius (float); @@ -151,7 +133,7 @@ class ArdourButton : public CairoWidget , public Gtkmm2ext::Activatable Glib::RefPtr _pixbuf; std::string _text; Element _elements; - Icon _icon; + Gtkmm2ext::ArdourIcon::Icon _icon; Tweaks _tweaks; BindingProxy binding_proxy; diff --git a/gtk2_ardour/ardour_ui2.cc b/gtk2_ardour/ardour_ui2.cc index 775f5ae3d2..e813691829 100644 --- a/gtk2_ardour/ardour_ui2.cc +++ b/gtk2_ardour/ardour_ui2.cc @@ -258,7 +258,7 @@ ARDOUR_UI::setup_transport () // auto_input_button.set_text (_("Auto Input")); - click_button.set_icon (ArdourButton::TransportMetronom); + click_button.set_icon (ArdourIcon::TransportMetronom); act = ActionManager::get_action ("Transport", "ToggleClick"); click_button.set_related_action (act); @@ -275,14 +275,14 @@ ARDOUR_UI::setup_transport () stop_button.set_active (true); - goto_start_button.set_icon (ArdourButton::TransportStart); - goto_end_button.set_icon (ArdourButton::TransportEnd); - roll_button.set_icon (ArdourButton::TransportPlay); - stop_button.set_icon (ArdourButton::TransportStop); - play_selection_button.set_icon (ArdourButton::TransportRange); - auto_loop_button.set_icon (ArdourButton::TransportLoop); - rec_button.set_icon (ArdourButton::RecButton); - midi_panic_button.set_icon (ArdourButton::TransportPanic); + goto_start_button.set_icon (ArdourIcon::TransportStart); + goto_end_button.set_icon (ArdourIcon::TransportEnd); + roll_button.set_icon (ArdourIcon::TransportPlay); + stop_button.set_icon (ArdourIcon::TransportStop); + play_selection_button.set_icon (ArdourIcon::TransportRange); + auto_loop_button.set_icon (ArdourIcon::TransportLoop); + rec_button.set_icon (ArdourIcon::RecButton); + midi_panic_button.set_icon (ArdourIcon::TransportPanic); act = ActionManager::get_action (X_("Transport"), X_("Stop")); stop_button.set_related_action (act); diff --git a/gtk2_ardour/automation_time_axis.cc b/gtk2_ardour/automation_time_axis.cc index 8f9f895575..01f2ebb514 100644 --- a/gtk2_ardour/automation_time_axis.cc +++ b/gtk2_ardour/automation_time_axis.cc @@ -149,7 +149,7 @@ AutomationTimeAxisView::AutomationTimeAxisView ( _base_rect->lower_to_bottom(); } - hide_button.set_icon (ArdourButton::CloseCross); + hide_button.set_icon (ArdourIcon::CloseCross); hide_button.set_tweaks(ArdourButton::TrackHeader); auto_button.set_name ("route button"); diff --git a/gtk2_ardour/editor.cc b/gtk2_ardour/editor.cc index 1d29fe866f..a47c1c2491 100644 --- a/gtk2_ardour/editor.cc +++ b/gtk2_ardour/editor.cc @@ -695,10 +695,10 @@ Editor::Editor () /* nudge stuff */ nudge_forward_button.set_name ("nudge button"); - nudge_forward_button.set_icon(ArdourButton::NudgeRight); + nudge_forward_button.set_icon(ArdourIcon::NudgeRight); nudge_backward_button.set_name ("nudge button"); - nudge_backward_button.set_icon(ArdourButton::NudgeLeft); + nudge_backward_button.set_icon(ArdourIcon::NudgeLeft); fade_context_menu.set_name ("ArdourContextMenu"); diff --git a/gtk2_ardour/mixer_strip.cc b/gtk2_ardour/mixer_strip.cc index e8c3c6cc16..a011d2e9b3 100644 --- a/gtk2_ardour/mixer_strip.cc +++ b/gtk2_ardour/mixer_strip.cc @@ -154,10 +154,10 @@ MixerStrip::init () t += string_compose (_("\n%1-%2-click to toggle the width of all strips."), Keyboard::primary_modifier_name(), Keyboard::tertiary_modifier_name ()); } - width_button.set_icon (ArdourButton::StripWidth); + width_button.set_icon (ArdourIcon::StripWidth); ARDOUR_UI::instance()->set_tip (width_button, t); - hide_button.set_icon (ArdourButton::CloseCross); + hide_button.set_icon (ArdourIcon::CloseCross); ARDOUR_UI::instance()->set_tip (&hide_button, _("Hide this mixer strip")); input_button_box.set_spacing(2); @@ -540,7 +540,7 @@ MixerStrip::set_route (boost::shared_ptr rt) midi_input_enable_button = manage (new ArdourButton); midi_input_enable_button->set_name ("midi input button"); midi_input_enable_button->set_elements ((ArdourButton::Element)(ArdourButton::Edge|ArdourButton::Body|ArdourButton::VectorIcon)); - midi_input_enable_button->set_icon (ArdourButton::DinMidi); + midi_input_enable_button->set_icon (ArdourIcon::DinMidi); midi_input_enable_button->signal_button_press_event().connect (sigc::mem_fun (*this, &MixerStrip::input_active_button_press), false); midi_input_enable_button->signal_button_release_event().connect (sigc::mem_fun (*this, &MixerStrip::input_active_button_release), false); ARDOUR_UI::instance()->set_tip (midi_input_enable_button, _("Enable/Disable MIDI input")); diff --git a/gtk2_ardour/route_ui.cc b/gtk2_ardour/route_ui.cc index 3dfba200e9..300379363f 100644 --- a/gtk2_ardour/route_ui.cc +++ b/gtk2_ardour/route_ui.cc @@ -148,7 +148,7 @@ RouteUI::init () rec_enable_button = manage (new ArdourButton); rec_enable_button->set_name ("record enable button"); - rec_enable_button->set_icon (ArdourButton::RecButton); + rec_enable_button->set_icon (ArdourIcon::RecButton); UI::instance()->set_tip (rec_enable_button, _("Enable recording on this track"), ""); if (ARDOUR_UI::config()->get_blink_rec_arm()) { @@ -2121,10 +2121,10 @@ RouteUI::track_mode_changed (void) switch (track()->mode()) { case ARDOUR::NonLayered: case ARDOUR::Normal: - rec_enable_button->set_icon (ArdourButton::RecButton); + rec_enable_button->set_icon (ArdourIcon::RecButton); break; case ARDOUR::Destructive: - rec_enable_button->set_icon (ArdourButton::RecTapeMode); + rec_enable_button->set_icon (ArdourIcon::RecTapeMode); break; } rec_enable_button->queue_draw();