From 5c926136988757f1f11a14c11720ed3daac3195f Mon Sep 17 00:00:00 2001 From: Robin Gareus Date: Sat, 15 Jul 2017 17:38:28 +0200 Subject: Separate Ardour UI widgets into dedicated library --- gtk2_ardour/add_route_dialog.cc | 5 +- gtk2_ardour/ardev_common.sh.in | 2 +- gtk2_ardour/ardour_button.cc | 1340 -------------------------------- gtk2_ardour/ardour_button.h | 215 ----- gtk2_ardour/ardour_display.cc | 141 ---- gtk2_ardour/ardour_display.h | 51 -- gtk2_ardour/ardour_dropdown.cc | 165 ---- gtk2_ardour/ardour_dropdown.h | 56 -- gtk2_ardour/ardour_knob.cc | 599 -------------- gtk2_ardour/ardour_knob.h | 128 --- gtk2_ardour/ardour_spacer.h | 47 -- gtk2_ardour/ardour_spinner.cc | 207 ----- gtk2_ardour/ardour_spinner.h | 70 -- gtk2_ardour/ardour_ui.cc | 3 +- gtk2_ardour/ardour_ui.h | 72 +- gtk2_ardour/ardour_ui2.cc | 1 + gtk2_ardour/ardour_ui_dialogs.cc | 1 + gtk2_ardour/ardour_ui_options.cc | 1 + gtk2_ardour/audio_clock.cc | 4 +- gtk2_ardour/audio_clock.h | 10 +- gtk2_ardour/audio_time_axis.cc | 4 +- gtk2_ardour/automation_controller.cc | 5 +- gtk2_ardour/automation_time_axis.cc | 4 +- gtk2_ardour/automation_time_axis.h | 9 +- gtk2_ardour/button_joiner.cc | 4 +- gtk2_ardour/color_theme_manager.cc | 1 - gtk2_ardour/control_slave_ui.cc | 2 +- gtk2_ardour/control_slave_ui.h | 8 +- gtk2_ardour/editor.cc | 6 +- gtk2_ardour/editor.h | 107 +-- gtk2_ardour/editor_ops.cc | 1 + gtk2_ardour/editor_regions.cc | 4 +- gtk2_ardour/editor_route_groups.cc | 4 +- gtk2_ardour/editor_routes.cc | 4 +- gtk2_ardour/engine_dialog.cc | 1 + gtk2_ardour/engine_dialog.h | 45 +- gtk2_ardour/export_format_dialog.cc | 8 +- gtk2_ardour/gain_meter.cc | 19 +- gtk2_ardour/gain_meter.h | 6 +- gtk2_ardour/generic_pluginui.cc | 18 +- gtk2_ardour/location_ui.cc | 4 +- gtk2_ardour/location_ui.h | 14 +- gtk2_ardour/luadialog.cc | 5 +- gtk2_ardour/luawindow.cc | 8 +- gtk2_ardour/luawindow.h | 18 +- gtk2_ardour/meter_strip.cc | 12 +- gtk2_ardour/meter_strip.h | 10 +- gtk2_ardour/midi_time_axis.cc | 11 +- gtk2_ardour/midi_time_axis.h | 31 +- gtk2_ardour/mini_timeline.cc | 5 +- gtk2_ardour/mixer_strip.cc | 7 +- gtk2_ardour/mixer_strip.h | 36 +- gtk2_ardour/monitor_section.cc | 4 +- gtk2_ardour/monitor_section.h | 57 +- gtk2_ardour/panner_ui.cc | 6 +- gtk2_ardour/plugin_pin_dialog.cc | 8 +- gtk2_ardour/plugin_pin_dialog.h | 38 +- gtk2_ardour/plugin_selector.cc | 7 +- gtk2_ardour/plugin_selector.h | 13 +- gtk2_ardour/plugin_setup_dialog.cc | 1 + gtk2_ardour/plugin_setup_dialog.h | 10 +- gtk2_ardour/plugin_ui.cc | 22 +- gtk2_ardour/plugin_ui.h | 37 +- gtk2_ardour/processor_box.cc | 34 +- gtk2_ardour/processor_box.h | 7 +- gtk2_ardour/rc_option_editor.cc | 13 +- gtk2_ardour/region_editor.cc | 6 +- gtk2_ardour/route_time_axis.cc | 21 +- gtk2_ardour/route_time_axis.h | 11 +- gtk2_ardour/route_ui.cc | 19 +- gtk2_ardour/route_ui.h | 23 +- gtk2_ardour/session_dialog.cc | 4 +- gtk2_ardour/shuttle_control.cc | 5 +- gtk2_ardour/shuttle_control.h | 6 +- gtk2_ardour/step_entry.cc | 4 +- gtk2_ardour/time_axis_view.cc | 5 +- gtk2_ardour/time_info_box.h | 2 - gtk2_ardour/tooltips.cc | 41 - gtk2_ardour/tooltips.h | 41 - gtk2_ardour/ui_config.cc | 1 + gtk2_ardour/ui_config.h | 8 +- gtk2_ardour/vca_master_strip.cc | 8 +- gtk2_ardour/vca_master_strip.h | 41 +- gtk2_ardour/vca_time_axis.cc | 8 +- gtk2_ardour/vca_time_axis.h | 17 +- gtk2_ardour/wscript | 69 +- libs/widgets/ardour_button.cc | 1340 ++++++++++++++++++++++++++++++++ libs/widgets/ardour_display.cc | 142 ++++ libs/widgets/ardour_dropdown.cc | 166 ++++ libs/widgets/ardour_knob.cc | 598 ++++++++++++++ libs/widgets/ardour_spacer.cc | 27 + libs/widgets/ardour_spinner.cc | 206 +++++ libs/widgets/tooltips.cc | 40 + libs/widgets/ui_config.cc | 7 + libs/widgets/widgets/ardour_button.h | 221 ++++++ libs/widgets/widgets/ardour_display.h | 55 ++ libs/widgets/widgets/ardour_dropdown.h | 60 ++ libs/widgets/widgets/ardour_knob.h | 133 ++++ libs/widgets/widgets/ardour_spacer.h | 53 ++ libs/widgets/widgets/ardour_spinner.h | 73 ++ libs/widgets/widgets/tooltips.h | 41 + libs/widgets/widgets/ui_config.h | 31 + libs/widgets/widgets/visibility.h | 45 ++ libs/widgets/wscript | 70 ++ wscript | 1 + 105 files changed, 3859 insertions(+), 3586 deletions(-) delete mode 100644 gtk2_ardour/ardour_button.cc delete mode 100644 gtk2_ardour/ardour_button.h delete mode 100644 gtk2_ardour/ardour_display.cc delete mode 100644 gtk2_ardour/ardour_display.h delete mode 100644 gtk2_ardour/ardour_dropdown.cc delete mode 100644 gtk2_ardour/ardour_dropdown.h delete mode 100644 gtk2_ardour/ardour_knob.cc delete mode 100644 gtk2_ardour/ardour_knob.h delete mode 100644 gtk2_ardour/ardour_spacer.h delete mode 100644 gtk2_ardour/ardour_spinner.cc delete mode 100644 gtk2_ardour/ardour_spinner.h delete mode 100644 gtk2_ardour/tooltips.cc delete mode 100644 gtk2_ardour/tooltips.h create mode 100644 libs/widgets/ardour_button.cc create mode 100644 libs/widgets/ardour_display.cc create mode 100644 libs/widgets/ardour_dropdown.cc create mode 100644 libs/widgets/ardour_knob.cc create mode 100644 libs/widgets/ardour_spacer.cc create mode 100644 libs/widgets/ardour_spinner.cc create mode 100644 libs/widgets/tooltips.cc create mode 100644 libs/widgets/ui_config.cc create mode 100644 libs/widgets/widgets/ardour_button.h create mode 100644 libs/widgets/widgets/ardour_display.h create mode 100644 libs/widgets/widgets/ardour_dropdown.h create mode 100644 libs/widgets/widgets/ardour_knob.h create mode 100644 libs/widgets/widgets/ardour_spacer.h create mode 100644 libs/widgets/widgets/ardour_spinner.h create mode 100644 libs/widgets/widgets/tooltips.h create mode 100644 libs/widgets/widgets/ui_config.h create mode 100644 libs/widgets/widgets/visibility.h create mode 100644 libs/widgets/wscript diff --git a/gtk2_ardour/add_route_dialog.cc b/gtk2_ardour/add_route_dialog.cc index 066fa84310..4c090afc75 100644 --- a/gtk2_ardour/add_route_dialog.cc +++ b/gtk2_ardour/add_route_dialog.cc @@ -32,6 +32,8 @@ #include "gtkmm2ext/utils.h" #include "gtkmm2ext/doi.h" +#include "widgets/tooltips.h" + #include "ardour/plugin_manager.h" #include "ardour/profile.h" #include "ardour/template_utils.h" @@ -42,7 +44,6 @@ #include "utils.h" #include "add_route_dialog.h" #include "route_group_dialog.h" -#include "tooltips.h" #include "pbd/i18n.h" using namespace Gtk; @@ -173,7 +174,7 @@ AddRouteDialog::AddRouteDialog () table2->attach (*l, 1, 2, n, n + 1, Gtk::FILL, Gtk::EXPAND, 0, 0); table2->attach (strict_io_combo, 2, 3, n, n + 1, Gtk::FILL, Gtk::EXPAND | Gtk::FILL, 0, 0); - ARDOUR_UI_UTILS::set_tooltip (strict_io_combo, + ArdourWidgets::set_tooltip (strict_io_combo, _("With strict-i/o enabled, Effect Processors will not modify the number of channels on a track. The number of output channels will always match the number of input channels.")); ++n; } diff --git a/gtk2_ardour/ardev_common.sh.in b/gtk2_ardour/ardev_common.sh.in index 10469a6524..0904e143c0 100644 --- a/gtk2_ardour/ardev_common.sh.in +++ b/gtk2_ardour/ardev_common.sh.in @@ -36,7 +36,7 @@ export ARDOUR_DLL_PATH=$libs export GTK_PATH=~/.ardour3:$libs/clearlooks-newer export VAMP_PATH=$libs/vamp-plugins${VAMP_PATH:+:$VAMP_PATH} -export LD_LIBRARY_PATH=$libs/ptformat:$libs/qm-dsp:$libs/vamp-sdk:$libs/surfaces:$libs/surfaces/control_protocol:$libs/ardour:$libs/midi++2:$libs/pbd:$libs/rubberband:$libs/soundtouch:$libs/gtkmm2ext:$libs/gnomecanvas:$libs/libsndfile:$libs/appleutility:$libs/taglib:$libs/evoral:$libs/evoral/src/libsmf:$libs/audiographer:$libs/timecode:$libs/libltc:$libs/canvas:$libs/ardouralsautil${LD_LIBRARY_PATH:+:$LD_LIBRARY_PATH} +export LD_LIBRARY_PATH=$libs/ptformat:$libs/qm-dsp:$libs/vamp-sdk:$libs/surfaces:$libs/surfaces/control_protocol:$libs/ardour:$libs/midi++2:$libs/pbd:$libs/rubberband:$libs/soundtouch:$libs/gtkmm2ext:$libs/widgets:$libs/appleutility:$libs/taglib:$libs/evoral:$libs/evoral/src/libsmf:$libs/audiographer:$libs/timecode:$libs/libltc:$libs/canvas:$libs/ardouralsautil${LD_LIBRARY_PATH:+:$LD_LIBRARY_PATH} # DYLD_LIBRARY_PATH is for darwin. export DYLD_FALLBACK_LIBRARY_PATH=$LD_LIBRARY_PATH diff --git a/gtk2_ardour/ardour_button.cc b/gtk2_ardour/ardour_button.cc deleted file mode 100644 index 3ec9d770d9..0000000000 --- a/gtk2_ardour/ardour_button.cc +++ /dev/null @@ -1,1340 +0,0 @@ -/* - Copyright (C) 2010 Paul Davis - - This program is free software; you can redistribute it and/or modify - it under the terms of the GNU General Public License as published by - the Free Software Foundation; either version 2 of the License, or - (at your option) any later version. - - This program is distributed in the hope that it will be useful, - but WITHOUT ANY WARRANTY; without even the implied warranty of - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - GNU General Public License for more details. - - You should have received a copy of the GNU General Public License - along with this program; if not, write to the Free Software - Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. - -*/ - -#include -#include -#include - -#include - -#include "pbd/compose.h" -#include "pbd/controllable.h" -#include "pbd/error.h" -#include "pbd/stacktrace.h" - -#include "gtkmm2ext/utils.h" -#include "gtkmm2ext/rgb_macros.h" -#include "gtkmm2ext/gui_thread.h" - -#include "canvas/utils.h" -#include "canvas/colors.h" - -#include "ardour_button.h" -#include "tooltips.h" -#include "ui_config.h" - -#include "pbd/i18n.h" - -#define BASELINESTRETCH (1.25) -#define TRACKHEADERBTNW (3.10) - -using namespace Gtk; -using namespace Glib; -using namespace PBD; -using namespace ARDOUR_UI_UTILS; -using std::max; -using std::min; -using namespace std; - -ArdourButton::Element ArdourButton::default_elements = ArdourButton::Element (ArdourButton::Edge|ArdourButton::Body|ArdourButton::Text); -ArdourButton::Element ArdourButton::led_default_elements = ArdourButton::Element (ArdourButton::default_elements|ArdourButton::Indicator); -ArdourButton::Element ArdourButton::just_led_default_elements = ArdourButton::Element (ArdourButton::Edge|ArdourButton::Body|ArdourButton::Indicator); - -ArdourButton::ArdourButton (Element e) - : _sizing_text("") - , _markup (false) - , _elements (e) - , _icon (Gtkmm2ext::ArdourIcon::NoIcon) - , _icon_render_cb (0) - , _icon_render_cb_data (0) - , _tweaks (Tweaks (0)) - , _char_pixel_width (0) - , _char_pixel_height (0) - , _char_avg_pixel_width (0) - , _text_width (0) - , _text_height (0) - , _diameter (0) - , _corner_radius (3.5) - , _corner_mask (0xf) - , _angle(0) - , _xalign(.5) - , _yalign(.5) - , fill_inactive_color (0) - , fill_active_color (0) - , text_active_color(0) - , 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) - , _led_rect (0) - , _act_on_release (true) - , _led_left (false) - , _distinct_led_click (false) - , _hovering (false) - , _focused (false) - , _fixed_colors_set (false) - , _fallthrough_to_parent (false) - , _layout_ellipsize_width (-1) - , _ellipsis (Pango::ELLIPSIZE_NONE) - , _update_colors (true) - , _pattern_height (0) -{ - UIConfiguration::instance().ColorsChanged.connect (sigc::mem_fun (*this, &ArdourButton::color_handler)); - /* This is not provided by gtkmm */ - signal_grab_broken_event().connect (sigc::mem_fun (*this, &ArdourButton::on_grab_broken_event)); -} - -ArdourButton::ArdourButton (const std::string& str, Element e) - : _sizing_text("") - , _markup (false) - , _elements (e) - , _icon (Gtkmm2ext::ArdourIcon::NoIcon) - , _tweaks (Tweaks (0)) - , _char_pixel_width (0) - , _char_pixel_height (0) - , _char_avg_pixel_width (0) - , _text_width (0) - , _text_height (0) - , _diameter (0) - , _corner_radius (3.5) - , _corner_mask (0xf) - , _angle(0) - , _xalign(.5) - , _yalign(.5) - , fill_inactive_color (0) - , fill_active_color (0) - , text_active_color(0) - , 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) - , _led_rect (0) - , _act_on_release (true) - , _led_left (false) - , _distinct_led_click (false) - , _hovering (false) - , _focused (false) - , _fixed_colors_set (false) - , _fallthrough_to_parent (false) - , _layout_ellipsize_width (-1) - , _ellipsis (Pango::ELLIPSIZE_NONE) - , _update_colors (true) - , _pattern_height (0) -{ - set_text (str); - UIConfiguration::instance().ColorsChanged.connect (sigc::mem_fun (*this, &ArdourButton::color_handler)); - UIConfiguration::instance().DPIReset.connect (sigc::mem_fun (*this, &ArdourButton::on_name_changed)); - /* This is not provided by gtkmm */ - signal_grab_broken_event().connect (sigc::mem_fun (*this, &ArdourButton::on_grab_broken_event)); -} - -ArdourButton::~ArdourButton() -{ - delete _led_rect; - - if (convex_pattern) { - cairo_pattern_destroy (convex_pattern); - } - - if (concave_pattern) { - cairo_pattern_destroy (concave_pattern); - } - - if (led_inset_pattern) { - cairo_pattern_destroy (led_inset_pattern); - } -} - -void -ArdourButton::set_layout_font (const Pango::FontDescription& fd) -{ - ensure_layout (); - if (_layout) { - _layout->set_font_description (fd); - queue_resize (); - _char_pixel_width = 0; - _char_pixel_height = 0; - } -} - -void -ArdourButton::set_text_internal () { - assert (_layout); - if (_markup) { - _layout->set_markup (_text); - } else { - _layout->set_text (_text); - } -} - -void -ArdourButton::set_text (const std::string& str, bool markup) -{ - if (!(_elements & Text)) { - return; - } - if (_text == str && _markup == markup) { - return; - } - - _text = str; - _markup = markup; - if (!is_realized()) { - return; - } - ensure_layout (); - if (_layout && _layout->get_text() != _text) { - set_text_internal (); - /* on_size_request() will fill in _text_width/height - * so queue it even if _sizing_text != "" */ - queue_resize (); - } -} - -void -ArdourButton::set_sizing_text (const std::string& str) -{ - if (_sizing_text == str) { - return; - } - _sizing_text = str; - if (!is_realized()) { - return; - } - ensure_layout (); - if (_layout) { - queue_resize (); - } -} - -void -ArdourButton::set_angle (const double angle) -{ - _angle = angle; -} - -void -ArdourButton::set_alignment (const float xa, const float ya) -{ - _xalign = xa; - _yalign = ya; -} - - -/* TODO make this a dedicated function elsewhere. - * - * Option 1: - * virtual ArdourButton::render_vector_icon() - * ArdourIconButton::render_vector_icon - * - * Option 2: - * ARDOUR_UI_UTILS::render_vector_icon() - */ -void -ArdourButton::render (Cairo::RefPtr const& ctx, cairo_rectangle_t*) -{ - cairo_t* cr = ctx->cobj(); - - uint32_t text_color; - uint32_t led_color; - - const float corner_radius = std::max(2.f, _corner_radius * UIConfiguration::instance().get_ui_scale()); - - if (_update_colors) { - set_colors (); - } - if (get_height() != _pattern_height) { - build_patterns (); - } - - if ( active_state() == Gtkmm2ext::ExplicitActive ) { - text_color = text_active_color; - led_color = led_active_color; - } else { - text_color = text_inactive_color; - 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) { - case 0x1: /* upper left only */ - rounded_function = Gtkmm2ext::rounded_top_left_rectangle; - break; - case 0x2: /* upper right only */ - rounded_function = Gtkmm2ext::rounded_top_right_rectangle; - break; - case 0x3: /* upper only */ - rounded_function = Gtkmm2ext::rounded_top_rectangle; - break; - /* should really have functions for lower right, lower left, - lower only, but for now, we don't - */ - default: - rounded_function = Gtkmm2ext::rounded_rectangle; - } - - // draw edge (filling a rect underneath, rather than stroking a border on top, allows the corners to be lighter-weight. - if ((_elements & (Body|Edge)) == (Body|Edge)) { - rounded_function (cr, 0, 0, get_width(), get_height(), corner_radius + 1.5); - cairo_set_source_rgba (cr, 0, 0, 0, 1); - cairo_fill(cr); - } - - // background fill - if ((_elements & Body)==Body) { - rounded_function (cr, 1, 1, get_width() - 2, get_height() - 2, corner_radius); - if (active_state() == Gtkmm2ext::ImplicitActive && !((_elements & Indicator)==Indicator)) { - ArdourCanvas::set_source_rgba (cr, fill_inactive_color); - cairo_fill (cr); - } else if ( (active_state() == Gtkmm2ext::ExplicitActive) && !((_elements & Indicator)==Indicator) ) { - //background color - ArdourCanvas::set_source_rgba (cr, fill_active_color); - cairo_fill (cr); - } else { //inactive, or it has an indicator - //background color - ArdourCanvas::set_source_rgba (cr, fill_inactive_color); - } - cairo_fill (cr); - } - - // IMPLICIT ACTIVE: draw a border of the active color - if ((_elements & Body)==Body) { - if (active_state() == Gtkmm2ext::ImplicitActive && !((_elements & Indicator)==Indicator)) { - cairo_set_line_width (cr, 2.0); - rounded_function (cr, 2, 2, get_width() - 4, get_height() - 4, corner_radius-0.5); - ArdourCanvas::set_source_rgba (cr, fill_active_color); - cairo_stroke (cr); - } - } - - //show the "convex" or "concave" gradient - if (!_flat_buttons && (_elements & Body)==Body) { - 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); - cairo_fill (cr); - } else { - cairo_set_source (cr, convex_pattern); - Gtkmm2ext::rounded_rectangle (cr, 1, 1, get_width() - 2, get_height() - 2, corner_radius); - cairo_fill (cr); - } - } - - //Pixbuf, if any - if (_pixbuf) { - double x = rint((get_width() - _pixbuf->get_width()) * .5); - const double y = rint((get_height() - _pixbuf->get_height()) * .5); -#if 0 // DEBUG style (print on hover) - if (_hovering || (_elements & Inactive)) { - printf("%s: p:%dx%d (%dx%d)\n", - get_name().c_str(), - _pixbuf->get_width(), _pixbuf->get_height(), - get_width(), get_height()); - } -#endif - if (_elements & Menu) { - //if this is a DropDown with an icon, then we need to - //move the icon left slightly to accomomodate the arrow - x -= _diameter - 2; - } - cairo_rectangle (cr, x, y, _pixbuf->get_width(), _pixbuf->get_height()); - gdk_cairo_set_source_pixbuf (cr, _pixbuf->gobj(), x, y); - cairo_fill (cr); - } - else /* VectorIcon, IconRenderCallback are exclusive to Pixbuf Icons */ - if (_elements & (VectorIcon | IconRenderCallback)) { - int vw = get_width(); - int vh = get_height(); - if (_elements & Menu) { - vw -= _diameter + 4; - } - if (_elements & VectorIcon) { - Gtkmm2ext::ArdourIcon::render (cr, _icon, vw, vh, active_state(), text_color); - } else { - cairo_save (cr); - rounded_function (cr, 0, 0, get_width(), get_height(), corner_radius + 1.5); - cairo_clip (cr); - _icon_render_cb (cr, vw, vh, text_color, _icon_render_cb_data); - cairo_restore (cr); - } - } - - const int text_margin = char_pixel_width(); - // Text, if any - if (!_pixbuf && ((_elements & Text)==Text) && !_text.empty()) { - assert(_layout); -#if 0 // DEBUG style (print on hover) - if (_hovering || (_elements & Inactive)) { - bool layout_font = true; - Pango::FontDescription fd = _layout->get_font_description(); - if (fd.gobj() == NULL) { - layout_font = false; - fd = get_pango_context()->get_font_description(); - } - printf("%s: f:%dx%d aw:%.3f bh:%.0f t:%dx%d (%dx%d) %s\"%s\"\n", - get_name().c_str(), - char_pixel_width(), char_pixel_height(), char_avg_pixel_width(), - ceil(char_pixel_height() * BASELINESTRETCH), - _text_width, _text_height, - get_width(), get_height(), - layout_font ? "L:" : "W:", - fd.to_string().c_str()); - } -#endif - - cairo_save (cr); - cairo_rectangle (cr, 2, 1, get_width() - 4, get_height() - 2); - cairo_clip(cr); - - cairo_new_path (cr); - ArdourCanvas::set_source_rgba (cr, text_color); - const double text_ypos = (get_height() - _text_height) * .5; - - if (_elements & Menu) { - // always left align (dropdown) - cairo_move_to (cr, text_margin, text_ypos); - pango_cairo_show_layout (cr, _layout->gobj()); - } else if ( (_elements & Indicator) == Indicator) { - // left/right align depending on LED position - if (_led_left) { - cairo_move_to (cr, text_margin + _diameter + .5 * char_pixel_width(), text_ypos); - } else { - cairo_move_to (cr, text_margin, text_ypos); - } - pango_cairo_show_layout (cr, _layout->gobj()); - } else { - /* centered text otherwise */ - double ww, wh; - double xa, ya; - ww = get_width(); - wh = get_height(); - - cairo_matrix_t m1; - cairo_get_matrix (cr, &m1); - cairo_matrix_t m2 = m1; - m2.x0 = 0; - m2.y0 = 0; - cairo_set_matrix (cr, &m2); - - if (_angle) { - cairo_rotate(cr, _angle * M_PI / 180.0); - } - - cairo_device_to_user(cr, &ww, &wh); - xa = text_margin + (ww - _text_width - 2 * text_margin) * _xalign; - ya = (wh - _text_height) * _yalign; - - /* quick hack for left/bottom alignment at -90deg - * TODO this should be generalized incl rotation. - * currently only 'user' of this API is meter_strip.cc - */ - if (_xalign < 0) xa = ceil(.5 + (ww * fabs(_xalign) + text_margin)); - - cairo_move_to (cr, xa + m1.x0, ya + m1.y0); - pango_cairo_update_layout(cr, _layout->gobj()); - pango_cairo_show_layout (cr, _layout->gobj()); - } - cairo_restore (cr); - } - - //Menu "triangle" - if (_elements & Menu) { - const float trih = ceil(_diameter * .5); - const float triw2 = ceil(.577 * _diameter * .5); // 1/sqrt(3) Equilateral triangle - //menu arrow - cairo_set_source_rgba (cr, 1, 1, 1, 0.4); - cairo_move_to(cr, get_width() - triw2 - 3. , rint((get_height() + trih) * .5)); - cairo_rel_line_to(cr, -triw2, -trih); - cairo_rel_line_to(cr, 2. * triw2, 0); - cairo_close_path(cr); - - cairo_set_source_rgba (cr, 1, 1, 1, 0.4); - cairo_fill(cr); - - cairo_move_to(cr, get_width() - triw2 - 3 , rint((get_height() + trih) * .5)); - cairo_rel_line_to(cr, .5 - triw2, .5 - trih); - cairo_rel_line_to(cr, 2. * triw2 - 1, 0); - cairo_close_path(cr); - cairo_set_source_rgba (cr, 0, 0, 0, 0.8); - cairo_set_line_width(cr, 1); - cairo_stroke(cr); - } - - //Indicator LED - if (_elements & Indicator) { - cairo_save (cr); - - /* move to the center of the indicator/led */ - if (_elements & Text) { - int led_xoff = ceil(char_pixel_width() + _diameter * .5); - if (_led_left) { - cairo_translate (cr, led_xoff, get_height() * .5); - } else { - cairo_translate (cr, get_width() - led_xoff, get_height() * .5); - } - } else { - cairo_translate (cr, get_width() * .5, get_height() * .5); - } - - //inset - if (!_flat_buttons) { - cairo_arc (cr, 0, 0, _diameter * .5, 0, 2 * M_PI); - cairo_set_source (cr, led_inset_pattern); - cairo_fill (cr); - } - - //black ring - cairo_set_source_rgb (cr, 0, 0, 0); - cairo_arc (cr, 0, 0, _diameter * .5 - 1 * UIConfiguration::instance().get_ui_scale(), 0, 2 * M_PI); - cairo_fill(cr); - - //led color - ArdourCanvas::set_source_rgba (cr, led_color); - cairo_arc (cr, 0, 0, _diameter * .5 - 3 * UIConfiguration::instance().get_ui_scale(), 0, 2 * M_PI); - cairo_fill(cr); - - cairo_restore (cr); - } - - // a transparent overlay to indicate insensitivity - if ((visual_state() & Gtkmm2ext::Insensitive)) { - rounded_function (cr, 0, 0, get_width(), get_height(), corner_radius); - uint32_t ins_color = UIConfiguration::instance().color ("gtk_background"); - ArdourCanvas::set_source_rgb_a (cr, ins_color, 0.6); - cairo_fill (cr); - } - - // if requested, show hovering - if (UIConfiguration::instance().get_widget_prelight() - && !((visual_state() & Gtkmm2ext::Insensitive))) { - if (_hovering) { - rounded_function (cr, 1, 1, get_width() - 2, get_height() - 2, corner_radius); - cairo_set_source_rgba (cr, 0.905, 0.917, 0.925, 0.2); - cairo_fill (cr); - } - } - - //user is currently pressing the button. dark outline helps to indicate this - if (_grabbed && !(_elements & (Inactive|Menu))) { - rounded_function (cr, 1, 1, get_width() - 2, get_height() - 2, corner_radius); - cairo_set_line_width(cr, 2); - cairo_set_source_rgba (cr, 0.1, 0.1, 0.1, .5); - cairo_stroke (cr); - } - - //some buttons (like processor boxes) can be selected (so they can be deleted). Draw a selection indicator - if (visual_state() & Gtkmm2ext::Selected) { - cairo_set_line_width(cr, 1); - cairo_set_source_rgba (cr, 1, 0, 0, 0.8); - rounded_function (cr, 0.5, 0.5, get_width() - 1, get_height() - 1, corner_radius); - cairo_stroke (cr); - } - - //I guess this means we have keyboard focus. I don't think this works currently - // - //A: yes, it's keyboard focus and it does work when there's no editor window - // (the editor is always the first receiver for KeyDown). - // It's needed for eg. the engine-dialog at startup or after closing a sesion. - if (_focused) { - rounded_function (cr, 1.5, 1.5, get_width() - 3, get_height() - 3, corner_radius); - cairo_set_source_rgba (cr, 0.905, 0.917, 0.925, 0.8); - double dashes = 1; - cairo_set_dash (cr, &dashes, 1, 0); - cairo_set_line_cap (cr, CAIRO_LINE_CAP_BUTT); - cairo_set_line_width (cr, 1.0); - cairo_stroke (cr); - cairo_set_dash (cr, 0, 0, 0); - } -} - -void -ArdourButton::set_corner_radius (float r) -{ - _corner_radius = r; - CairoWidget::set_dirty (); -} - -void -ArdourButton::on_realize() -{ - CairoWidget::on_realize (); - ensure_layout (); - if (_layout) { - if (_layout->get_text() != _text) { - set_text_internal (); - queue_resize (); - } - } -} - -void -ArdourButton::on_size_request (Gtk::Requisition* req) -{ - req->width = req->height = 0; - CairoWidget::on_size_request (req); - - if (_diameter == 0) { - const float newdia = rintf (11.f * UIConfiguration::instance().get_ui_scale()); - if (_diameter != newdia) { - _pattern_height = 0; - _diameter = newdia; - } - } - - if (_elements & Text) { - - ensure_layout(); - set_text_internal (); - - /* render() needs the size of the displayed text */ - _layout->get_pixel_size (_text_width, _text_height); - - if (_tweaks & OccasionalText) { - - /* size should not change based on presence or absence - * of text. - */ - - } else /*if (!_text.empty() || !_sizing_text.empty()) */ { - - req->height = std::max(req->height, (int) ceil(char_pixel_height() * BASELINESTRETCH + 1.0)); - req->width += rint(1.75 * char_pixel_width()); // padding - - if (!_sizing_text.empty()) { - _layout->set_text (_sizing_text); /* use sizing text */ - } - - int sizing_text_width = 0, sizing_text_height = 0; - _layout->get_pixel_size (sizing_text_width, sizing_text_height); - - req->width += sizing_text_width; - - if (!_sizing_text.empty()) { - set_text_internal (); /* restore display text */ - } - } - - /* XXX hack (surprise). Deal with two common rotation angles */ - - if (_angle == 90 || _angle == 270) { - /* do not swap text width or height because we rely on - these being the un-rotated values in ::render() - */ - swap (req->width, req->height); - } - - } else { - _text_width = 0; - _text_height = 0; - } - - if (_pixbuf) { - req->width += _pixbuf->get_width() + char_pixel_width(); - req->height = std::max(req->height, _pixbuf->get_height() + 4); - } - - if (_elements & Indicator) { - req->width += lrint (_diameter) + char_pixel_width(); - req->height = std::max (req->height, (int) lrint (_diameter) + 4); - } - - if ((_elements & Menu)) { - req->width += _diameter + 4; - } - - if (_elements & (VectorIcon | IconRenderCallback)) { - assert(!(_elements & Text)); - const int wh = std::max (6., std::max (rint (TRACKHEADERBTNW * char_avg_pixel_width()), ceil (char_pixel_height() * BASELINESTRETCH + 1.))); - req->width += wh; - req->height = std::max(req->height, wh); - } - - /* Tweaks to mess the nice stuff above up again. */ - if (_tweaks & TrackHeader) { - // forget everything above and just use a fixed square [em] size - // "TrackHeader Buttons" are single letter (usually uppercase) - // a SizeGroup is much less efficient (lots of gtk work under the hood for each track) - const int wh = std::max (rint (TRACKHEADERBTNW * char_avg_pixel_width()), ceil (char_pixel_height() * BASELINESTRETCH + 1.)); - req->width = wh; - req->height = wh; - } - else if (_tweaks & Square) { - // currerntly unused (again) - if (req->width < req->height) - req->width = req->height; - if (req->height < req->width) - req->height = req->width; - } else if (_sizing_text.empty() && _text_width > 0 && !(_elements & Menu)) { - // properly centered text for those elements that are centered - // (no sub-pixel offset) - if ((req->width - _text_width) & 1) { ++req->width; } - if ((req->height - _text_height) & 1) { ++req->height; } - } -#if 0 - printf("REQ: %s: %dx%d\n", get_name().c_str(), req->width, req->height); -#endif -} - -/** - * This sets the colors used for rendering based on the name of the button, and - * thus uses information from the GUI config data. - */ -void -ArdourButton::set_colors () -{ - _update_colors = false; - - if (_fixed_colors_set == 0x3) { - return; - } - - std::string name = get_name(); - bool failed = false; - - if (!(_fixed_colors_set & 0x1)) { - fill_active_color = UIConfiguration::instance().color (string_compose ("%1: fill active", name), &failed); - if (failed) { - fill_active_color = UIConfiguration::instance().color ("generic button: fill active"); - } - } - - if (!(_fixed_colors_set & 0x2)) { - fill_inactive_color = UIConfiguration::instance().color (string_compose ("%1: fill", name), &failed); - if (failed) { - fill_inactive_color = UIConfiguration::instance().color ("generic button: fill"); - } - } - - text_active_color = ArdourCanvas::contrasting_text_color (fill_active_color); - text_inactive_color = ArdourCanvas::contrasting_text_color (fill_inactive_color); - - led_active_color = UIConfiguration::instance().color (string_compose ("%1: led active", name), &failed); - if (failed) { - led_active_color = UIConfiguration::instance().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_inactive_color = inactive.color (); -} - -/** - * This sets the colors used for rendering based on two fixed values, rather - * than basing them on the button name, and thus information in the GUI config - * data. - */ -void ArdourButton::set_fixed_colors (const uint32_t color_active, const uint32_t color_inactive) -{ - set_active_color (color_active); - set_inactive_color (color_inactive); -} - -void ArdourButton::set_active_color (const uint32_t color) -{ - _fixed_colors_set |= 0x1; - - fill_active_color = color; - - unsigned char r, g, b, a; - UINT_TO_RGBA(color, &r, &g, &b, &a); - - double white_contrast = (max (double(r), 255.) - min (double(r), 255.)) + - (max (double(g), 255.) - min (double(g), 255.)) + - (max (double(b), 255.) - min (double(b), 255.)); - - double black_contrast = (max (double(r), 0.) - min (double(r), 0.)) + - (max (double(g), 0.) - min (double(g), 0.)) + - (max (double(b), 0.) - min (double(b), 0.)); - - text_active_color = (white_contrast > black_contrast) ? - RGBA_TO_UINT(255, 255, 255, 255) : /* use white */ - RGBA_TO_UINT( 0, 0, 0, 255); /* use black */ - - /* XXX what about led colors ? */ - CairoWidget::set_dirty (); -} - -void ArdourButton::set_inactive_color (const uint32_t color) -{ - _fixed_colors_set |= 0x2; - - fill_inactive_color = color; - - unsigned char r, g, b, a; - UINT_TO_RGBA(color, &r, &g, &b, &a); - - double white_contrast = (max (double(r), 255.) - min (double(r), 255.)) + - (max (double(g), 255.) - min (double(g), 255.)) + - (max (double(b), 255.) - min (double(b), 255.)); - - double black_contrast = (max (double(r), 0.) - min (double(r), 0.)) + - (max (double(g), 0.) - min (double(g), 0.)) + - (max (double(b), 0.) - min (double(b), 0.)); - - text_inactive_color = (white_contrast > black_contrast) ? - RGBA_TO_UINT(255, 255, 255, 255) : /* use white */ - RGBA_TO_UINT( 0, 0, 0, 255); /* use black */ - - /* XXX what about led colors ? */ - CairoWidget::set_dirty (); -} - -void -ArdourButton::build_patterns () -{ - if (convex_pattern) { - cairo_pattern_destroy (convex_pattern); - convex_pattern = 0; - } - - if (concave_pattern) { - cairo_pattern_destroy (concave_pattern); - concave_pattern = 0; - } - - if (led_inset_pattern) { - cairo_pattern_destroy (led_inset_pattern); - led_inset_pattern = 0; - } - - //convex gradient - convex_pattern = cairo_pattern_create_linear (0.0, 0, 0.0, get_height()); - cairo_pattern_add_color_stop_rgba (convex_pattern, 0.0, 0,0,0, 0.0); - cairo_pattern_add_color_stop_rgba (convex_pattern, 1.0, 0,0,0, 0.35); - - //concave gradient - concave_pattern = cairo_pattern_create_linear (0.0, 0, 0.0, get_height()); - cairo_pattern_add_color_stop_rgba (concave_pattern, 0.0, 0,0,0, 0.5); - cairo_pattern_add_color_stop_rgba (concave_pattern, 0.7, 0,0,0, 0.0); - - led_inset_pattern = cairo_pattern_create_linear (0.0, 0.0, 0.0, _diameter); - cairo_pattern_add_color_stop_rgba (led_inset_pattern, 0, 0,0,0, 0.4); - cairo_pattern_add_color_stop_rgba (led_inset_pattern, 1, 1,1,1, 0.7); - - _pattern_height = get_height() ; -} - -void -ArdourButton::set_led_left (bool yn) -{ - _led_left = yn; -} - -bool -ArdourButton::on_button_press_event (GdkEventButton *ev) -{ - focus_handler (this); - - 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; - } - } - - if (binding_proxy.button_press_handler (ev)) { - return true; - } - - _grabbed = true; - CairoWidget::set_dirty (); - - if (ev->button == 1 && !_act_on_release) { - if (_action) { - _action->activate (); - return true; - } - } - - if (_fallthrough_to_parent) - return false; - - return true; -} - -bool -ArdourButton::on_button_release_event (GdkEventButton *ev) -{ - 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(ev); /* EMIT SIGNAL */ - return true; - } - } - - _grabbed = false; - CairoWidget::set_dirty (); - - if (ev->button == 1 && _hovering) { - signal_clicked (); - if (_act_on_release) { - if (_action) { - _action->activate (); - return true; - } - } - } - - if (_fallthrough_to_parent) - return false; - - return true; -} - -void -ArdourButton::set_distinct_led_click (bool yn) -{ - _distinct_led_click = yn; - setup_led_rect (); -} - -void -ArdourButton::color_handler () -{ - _update_colors = true; - CairoWidget::set_dirty (); -} - -void -ArdourButton::on_size_allocate (Allocation& alloc) -{ - CairoWidget::on_size_allocate (alloc); - setup_led_rect (); -} - -void -ArdourButton::set_controllable (boost::shared_ptr c) -{ - watch_connection.disconnect (); - binding_proxy.set_controllable (c); -} - -void -ArdourButton::watch () -{ - boost::shared_ptr c (binding_proxy.get_controllable ()); - - if (!c) { - warning << _("button cannot watch state of non-existing Controllable\n") << endmsg; - return; - } - c->Changed.connect (watch_connection, invalidator(*this), boost::bind (&ArdourButton::controllable_changed, this), gui_context()); -} - -void -ArdourButton::controllable_changed () -{ - float val = binding_proxy.get_controllable()->get_value(); - - if (fabs (val) >= 0.5f) { - set_active_state (Gtkmm2ext::ExplicitActive); - } else { - unset_active_state (); - } - CairoWidget::set_dirty (); -} - -void -ArdourButton::set_related_action (RefPtr act) -{ - Gtkmm2ext::Activatable::set_related_action (act); - - if (_action) { - - action_tooltip_changed (); - action_sensitivity_changed (); - - Glib::RefPtr tact = Glib::RefPtr::cast_dynamic (_action); - if (tact) { - action_toggled (); - tact->signal_toggled().connect (sigc::mem_fun (*this, &ArdourButton::action_toggled)); - } - - _action->connect_property_changed ("sensitive", sigc::mem_fun (*this, &ArdourButton::action_sensitivity_changed)); - _action->connect_property_changed ("visible", sigc::mem_fun (*this, &ArdourButton::action_visibility_changed)); - _action->connect_property_changed ("tooltip", sigc::mem_fun (*this, &ArdourButton::action_tooltip_changed)); - } -} - -void -ArdourButton::action_toggled () -{ - Glib::RefPtr tact = Glib::RefPtr::cast_dynamic (_action); - - if (tact) { - if (tact->get_active()) { - set_active_state (Gtkmm2ext::ExplicitActive); - } else { - unset_active_state (); - } - } -} - -void -ArdourButton::on_style_changed (const RefPtr&) -{ - _update_colors = true; - CairoWidget::set_dirty (); - _char_pixel_width = 0; - _char_pixel_height = 0; - if (is_realized()) { - queue_resize (); - } -} - -void -ArdourButton::on_name_changed () -{ - _char_pixel_width = 0; - _char_pixel_height = 0; - _diameter = 0; - _update_colors = true; - if (is_realized()) { - queue_resize (); - } -} - -void -ArdourButton::setup_led_rect () -{ - if (!(_elements & Indicator)) { - delete _led_rect; - _led_rect = 0; - return; - } - - if (!_led_rect) { - _led_rect = new cairo_rectangle_t; - } - - if (_elements & Text) { - if (_led_left) { - _led_rect->x = char_pixel_width(); - } else { - _led_rect->x = get_width() - char_pixel_width() + _diameter; - } - } else { - /* centered */ - _led_rect->x = .5 * get_width() - _diameter; - } - - _led_rect->y = .5 * (get_height() - _diameter); - _led_rect->width = _diameter; - _led_rect->height = _diameter; -} - -void -ArdourButton::set_image (const RefPtr& img) -{ - _elements = (ArdourButton::Element) (_elements & ~ArdourButton::Text); - _pixbuf = img; - if (is_realized()) { - queue_resize (); - } -} - -void -ArdourButton::set_active_state (Gtkmm2ext::ActiveState s) -{ - bool changed = (_active_state != s); - CairoWidget::set_active_state (s); - if (changed) { - _update_colors = true; - CairoWidget::set_dirty (); - } -} - -void -ArdourButton::set_visual_state (Gtkmm2ext::VisualState s) -{ - bool changed = (_visual_state != s); - CairoWidget::set_visual_state (s); - if (changed) { - _update_colors = true; - CairoWidget::set_dirty (); - } -} - -bool -ArdourButton::on_focus_in_event (GdkEventFocus* ev) -{ - _focused = true; - CairoWidget::set_dirty (); - return CairoWidget::on_focus_in_event (ev); -} - -bool -ArdourButton::on_focus_out_event (GdkEventFocus* ev) -{ - _focused = false; - CairoWidget::set_dirty (); - return CairoWidget::on_focus_out_event (ev); -} - -bool -ArdourButton::on_key_release_event (GdkEventKey *ev) { - if (_act_on_release && _focused && - (ev->keyval == GDK_space || ev->keyval == GDK_Return)) - { - signal_clicked(); - if (_action) { - _action->activate (); - } - return true; - } - return CairoWidget::on_key_release_event (ev); -} - -bool -ArdourButton::on_key_press_event (GdkEventKey *ev) { - if (!_act_on_release && _focused && - (ev->keyval == GDK_space || ev->keyval == GDK_Return)) - { - signal_clicked(); - if (_action) { - _action->activate (); - } - return true; - } - return CairoWidget::on_key_release_event (ev); -} - -bool -ArdourButton::on_enter_notify_event (GdkEventCrossing* ev) -{ - _hovering = (_elements & Inactive) ? false : true; - - if (UIConfiguration::instance().get_widget_prelight()) { - CairoWidget::set_dirty (); - } - - boost::shared_ptr c (binding_proxy.get_controllable ()); - if (c) { - PBD::Controllable::GUIFocusChanged (boost::weak_ptr (c)); - } - - return CairoWidget::on_enter_notify_event (ev); -} - -bool -ArdourButton::on_leave_notify_event (GdkEventCrossing* ev) -{ - _hovering = false; - - if (UIConfiguration::instance().get_widget_prelight()) { - CairoWidget::set_dirty (); - } - - if (binding_proxy.get_controllable()) { - PBD::Controllable::GUIFocusChanged (boost::weak_ptr ()); - } - - return CairoWidget::on_leave_notify_event (ev); -} - -bool -ArdourButton::on_grab_broken_event(GdkEventGrabBroken* grab_broken_event) { - /* Our implicit grab due to a button_press was broken by another grab: - * the button will not get any button_release event if the mouse leaves - * while the grab is taken, so unpress ourselves */ - _grabbed = false; - CairoWidget::set_dirty (); - return true; -} - -void -ArdourButton::set_tweaks (Tweaks t) -{ - if (_tweaks != t) { - _tweaks = t; - if (is_realized()) { - queue_resize (); - } - } -} - -void -ArdourButton::action_sensitivity_changed () -{ - if (_action->property_sensitive ()) { - set_visual_state (Gtkmm2ext::VisualState (visual_state() & ~Gtkmm2ext::Insensitive)); - } else { - set_visual_state (Gtkmm2ext::VisualState (visual_state() | Gtkmm2ext::Insensitive)); - } -} - -void -ArdourButton::set_layout_ellipsize_width (int w) -{ - if (_layout_ellipsize_width == w) { - return; - } - _layout_ellipsize_width = w; - if (!_layout) { - return; - } - if (_layout_ellipsize_width > 3 * PANGO_SCALE) { - _layout->set_width (_layout_ellipsize_width - 3 * PANGO_SCALE); - } - if (is_realized ()) { - queue_resize (); - } -} - -void -ArdourButton::set_text_ellipsize (Pango::EllipsizeMode e) -{ - if (_ellipsis == e) { - return; - } - _ellipsis = e; - if (!_layout) { - return; - } - _layout->set_ellipsize(_ellipsis); - if (_layout_ellipsize_width > 3 * PANGO_SCALE) { - _layout->set_width (_layout_ellipsize_width - 3 * PANGO_SCALE); - } - if (is_realized ()) { - queue_resize (); - } -} - -void -ArdourButton::ensure_layout () -{ - if (!_layout) { - ensure_style (); - _layout = Pango::Layout::create (get_pango_context()); - _layout->set_ellipsize(_ellipsis); - if (_layout_ellipsize_width > 3 * PANGO_SCALE) { - _layout->set_width (_layout_ellipsize_width - 3* PANGO_SCALE); - } - } -} - -void -ArdourButton::recalc_char_pixel_geometry () -{ - if (_char_pixel_height > 0 && _char_pixel_width > 0) { - return; - } - ensure_layout(); - // NB. this is not static, since the geometry is different - // depending on the font used. - int w, h; - std::string x = _("@ABCDEFGHIJLKMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789"); - _layout->set_text (x); - _layout->get_pixel_size (w, h); - _char_pixel_height = std::max(4, h); - // number of actual chars in the string (not bytes) - // Glib to the rescue. - Glib::ustring gx(x); - _char_avg_pixel_width = w / (float)gx.size(); - _char_pixel_width = std::max(4, (int) ceil (_char_avg_pixel_width)); - set_text_internal (); /* restore display text */ -} - -void -ArdourButton::action_visibility_changed () -{ - if (_action->property_visible ()) { - show (); - } else { - hide (); - } -} - -void -ArdourButton::action_tooltip_changed () -{ - string str = _action->property_tooltip().get_value(); - set_tooltip (*this, str); -} - -void -ArdourButton::set_elements (Element e) -{ - _elements = e; - CairoWidget::set_dirty (); -} - -void -ArdourButton::add_elements (Element e) -{ - _elements = (ArdourButton::Element) (_elements | e); - CairoWidget::set_dirty (); -} - -void -ArdourButton::set_icon (Gtkmm2ext::ArdourIcon::Icon i) -{ - _icon = i; - _icon_render_cb = 0; - _icon_render_cb_data = 0; - _elements = (ArdourButton::Element) ((_elements | VectorIcon) & ~(ArdourButton::Text | IconRenderCallback)); - CairoWidget::set_dirty (); -} - -void -ArdourButton::set_icon (rendercallback_t cb, void* d) -{ - if (!cb) { - _elements = (ArdourButton::Element) ((_elements | ArdourButton::Text) & ~(IconRenderCallback | VectorIcon)); - _icon_render_cb = 0; - _icon_render_cb_data = 0; - } else { - _elements = (ArdourButton::Element) ((_elements | IconRenderCallback) & ~(ArdourButton::Text | VectorIcon)); - _icon_render_cb = cb; - _icon_render_cb_data = d; - } - 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 (); -} diff --git a/gtk2_ardour/ardour_button.h b/gtk2_ardour/ardour_button.h deleted file mode 100644 index edccfd209f..0000000000 --- a/gtk2_ardour/ardour_button.h +++ /dev/null @@ -1,215 +0,0 @@ -/* - Copyright (C) 2010 Paul Davis - - This program is free software; you can redistribute it and/or modify - it under the terms of the GNU General Public License as published by - the Free Software Foundation; either version 2 of the License, or - (at your option) any later version. - - This program is distributed in the hope that it will be useful, - but WITHOUT ANY WARRANTY; without even the implied warranty of - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - GNU General Public License for more details. - - You should have received a copy of the GNU General Public License - along with this program; if not, write to the Free Software - Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. -*/ - -#ifndef __gtk2_ardour_ardour_button_h__ -#define __gtk2_ardour_ardour_button_h__ - -#include -#include - -#include - -#include "pbd/signals.h" -#include "gtkmm2ext/ardour_icon.h" -#include "gtkmm2ext/binding_proxy.h" -#include "gtkmm2ext/activatable.h" -#include "gtkmm2ext/cairo_widget.h" - -class ArdourButton : public CairoWidget , public Gtkmm2ext::Activatable -{ - public: - enum Element { - Edge = 0x1, - Body = 0x2, - Text = 0x4, - Indicator = 0x8, - unused = 0x10, - Menu = 0x20, - Inactive = 0x40, // no _action is defined AND state is not used - VectorIcon = 0x80, - IconRenderCallback = 0x100, - }; - - typedef void (* rendercallback_t) (cairo_t*, int, int, uint32_t, void*); - - static Element default_elements; - static Element led_default_elements; - static Element just_led_default_elements; - - ArdourButton (Element e = default_elements); - ArdourButton (const std::string&, Element e = default_elements); - virtual ~ArdourButton (); - - enum Tweaks { - Square = 0x1, - TrackHeader = 0x2, - OccasionalText = 0x4, - unused4 = 0x8, - }; - - Tweaks tweaks() const { return _tweaks; } - void set_tweaks (Tweaks); - - void set_active_state (Gtkmm2ext::ActiveState); - void set_visual_state (Gtkmm2ext::VisualState); - - void set_custom_led_color (const uint32_t c, const bool useit = true); - - void set_act_on_release (bool onRelease) { _act_on_release = onRelease; } - - Element elements() const { return _elements; } - void set_elements (Element); - void add_elements (Element); - - Gtkmm2ext::ArdourIcon::Icon icon() const { return _icon; } - void set_icon (Gtkmm2ext::ArdourIcon::Icon); - void set_icon (rendercallback_t, void*); - - void set_corner_radius (float); - - void set_text (const std::string&, bool markup = false); - const std::string& get_text () { return _text; } - bool get_markup () const { return _markup; } - void set_angle (const double); - void set_alignment (const float, const float); - void get_alignment (float& xa, float& ya) {xa = _xalign; ya = _yalign;}; - - void set_led_left (bool yn); - void set_distinct_led_click (bool yn); - - void set_layout_ellipsize_width (int w); - void set_layout_font (const Pango::FontDescription&); - void set_text_ellipsize (Pango::EllipsizeMode); - - /* Sets the text used for size request computation. Pass an - * empty string to return to the default behavior which uses - * the currently displayed text for measurement. */ - void set_sizing_text (const std::string&); - const std::string& get_sizing_text () {return _sizing_text;} - - sigc::signal signal_led_clicked; - sigc::signal signal_clicked; - - boost::shared_ptr get_controllable() { return binding_proxy.get_controllable(); } - void set_controllable (boost::shared_ptr c); - void watch (); - - void set_related_action (Glib::RefPtr); - - bool on_button_press_event (GdkEventButton*); - bool on_button_release_event (GdkEventButton*); - - void set_image (const Glib::RefPtr&); - - void set_fixed_colors (const uint32_t active_color, const uint32_t inactive_color); - void set_active_color (const uint32_t active_color); - void set_inactive_color (const uint32_t inactive_color); - - void set_fallthrough_to_parent(bool fall) { _fallthrough_to_parent = fall; } - - unsigned int char_pixel_width() { if (_char_pixel_width < 1) recalc_char_pixel_geometry() ; return _char_pixel_width; } - unsigned int char_pixel_height() { if (_char_pixel_height < 1) recalc_char_pixel_geometry() ; return _char_pixel_height; } - float char_avg_pixel_width() { if (_char_pixel_width < 1) recalc_char_pixel_geometry() ; return _char_avg_pixel_width; } - - protected: - void render (Cairo::RefPtr const&, cairo_rectangle_t*); - void on_size_request (Gtk::Requisition* req); - void on_size_allocate (Gtk::Allocation&); - void on_style_changed (const Glib::RefPtr&); - void on_name_changed (); - void on_realize (); - bool on_enter_notify_event (GdkEventCrossing*); - bool on_leave_notify_event (GdkEventCrossing*); - bool on_grab_broken_event(GdkEventGrabBroken*); - bool on_focus_in_event (GdkEventFocus*); - bool on_focus_out_event (GdkEventFocus*); - bool on_key_release_event (GdkEventKey *); - bool on_key_press_event (GdkEventKey *); - - void controllable_changed (); - PBD::ScopedConnection watch_connection; - - protected: - Glib::RefPtr _layout; - Glib::RefPtr _pixbuf; - std::string _text; - std::string _sizing_text; - bool _markup; - Element _elements; - Gtkmm2ext::ArdourIcon::Icon _icon; - rendercallback_t _icon_render_cb; - void* _icon_render_cb_data; - Tweaks _tweaks; - BindingProxy binding_proxy; - - void set_text_internal (); - void recalc_char_pixel_geometry (); - unsigned int _char_pixel_width; - unsigned int _char_pixel_height; - float _char_avg_pixel_width; - - int _text_width; - int _text_height; - float _diameter; - float _corner_radius; - int _corner_mask; - - double _angle; - float _xalign, _yalign; - - uint32_t fill_inactive_color; - uint32_t fill_active_color; - - uint32_t text_active_color; - uint32_t text_inactive_color; - - uint32_t led_active_color; - uint32_t led_inactive_color; - uint32_t led_custom_color; - bool use_custom_led_color; - - cairo_pattern_t* convex_pattern; - cairo_pattern_t* concave_pattern; - cairo_pattern_t* led_inset_pattern; - cairo_rectangle_t* _led_rect; - - bool _act_on_release; - bool _led_left; - bool _distinct_led_click; - bool _hovering; - bool _focused; - int _fixed_colors_set; - bool _fallthrough_to_parent; - int _layout_ellipsize_width; - Pango::EllipsizeMode _ellipsis; - bool _update_colors; - int _pattern_height; - - void setup_led_rect (); - void set_colors (); - void color_handler (); - void build_patterns (); - void ensure_layout (); - - void action_toggled (); - void action_sensitivity_changed (); - void action_visibility_changed (); - void action_tooltip_changed (); -}; - -#endif /* __gtk2_ardour_ardour_button_h__ */ diff --git a/gtk2_ardour/ardour_display.cc b/gtk2_ardour/ardour_display.cc deleted file mode 100644 index 67220dcf9e..0000000000 --- a/gtk2_ardour/ardour_display.cc +++ /dev/null @@ -1,141 +0,0 @@ -/* - Copyright (C) 2014 Paul Davis - - This program is free software; you can redistribute it and/or modify - it under the terms of the GNU General Public License as published by - the Free Software Foundation; either version 2 of the License, or - (at your option) any later version. - - This program is distributed in the hope that it will be useful, - but WITHOUT ANY WARRANTY; without even the implied warranty of - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - GNU General Public License for more details. - - You should have received a copy of the GNU General Public License - along with this program; if not, write to the Free Software - Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. - -*/ - -#include -#include -#include - -#include - -#include "pbd/compose.h" -#include "pbd/controllable.h" -#include "pbd/error.h" -#include "pbd/stacktrace.h" - -#include "gtkmm2ext/utils.h" -#include "gtkmm2ext/rgb_macros.h" -#include "gtkmm2ext/gui_thread.h" -#include "gtkmm2ext/keyboard.h" - -#include "ardour/rc_configuration.h" // for widget prelight preference - -#include "ardour_display.h" - -#include "pbd/i18n.h" - -using namespace Gtkmm2ext; -using namespace Gdk; -using namespace Gtk; -using namespace Glib; -using namespace PBD; -using std::max; -using std::min; -using namespace std; - - -ArdourDisplay::ArdourDisplay (Element e) -{ - add_elements(ArdourButton::Text); -} - -ArdourDisplay::~ArdourDisplay () -{ -} - - -bool -ArdourDisplay::on_scroll_event (GdkEventScroll* ev) -{ - /* mouse wheel */ - - float scale = 1.0; - if (ev->state & Keyboard::GainFineScaleModifier) { - if (ev->state & Keyboard::GainExtraFineScaleModifier) { - scale *= 0.01; - } else { - scale *= 0.10; - } - } - - boost::shared_ptr c = binding_proxy.get_controllable(); - if (c) { - float val = c->get_interface(); - - if ( ev->direction == GDK_SCROLL_UP ) - val += 0.05 * scale; //by default, we step in 1/20ths of the knob travel - else - val -= 0.05 * scale; - - c->set_interface(val); - } - - return true; -} - - -void -ArdourDisplay::add_controllable_preset (const char *txt, float val) -{ - using namespace Menu_Helpers; - AddMenuElem(MenuElem (txt, sigc::bind (sigc::mem_fun(*this, &ArdourDisplay::handle_controllable_preset), val))); -} - - -void -ArdourDisplay::handle_controllable_preset (float p) -{ - boost::shared_ptr c = binding_proxy.get_controllable(); - - if (!c) return; - - /* This should not use dB_to_coefficient(), but the Controllable's value. - * - * The only user of this API is currently monitor_section.cc which conveniently - * binds dB values. Once there are other use-cases, for this, this (GUI only) API - * needs fixing. - */ - c->set_value(dB_to_coefficient (p), Controllable::NoGroup); -} - - -void -ArdourDisplay::set_controllable (boost::shared_ptr c) -{ - watch_connection.disconnect (); //stop watching the old controllable - - if (!c) return; - - binding_proxy.set_controllable (c); - - c->Changed.connect (watch_connection, invalidator(*this), boost::bind (&ArdourDisplay::controllable_changed, this), gui_context()); - - controllable_changed(); -} - -void -ArdourDisplay::controllable_changed () -{ - boost::shared_ptr c = binding_proxy.get_controllable(); - - if (!c) return; - - set_text(c->get_user_string()); - - set_dirty(); -} diff --git a/gtk2_ardour/ardour_display.h b/gtk2_ardour/ardour_display.h deleted file mode 100644 index e80f8fdc57..0000000000 --- a/gtk2_ardour/ardour_display.h +++ /dev/null @@ -1,51 +0,0 @@ -/* - Copyright (C) 2014 Paul Davis - - This program is free software; you can redistribute it and/or modify - it under the terms of the GNU General Public License as published by - the Free Software Foundation; either version 2 of the License, or - (at your option) any later version. - - This program is distributed in the hope that it will be useful, - but WITHOUT ANY WARRANTY; without even the implied warranty of - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - GNU General Public License for more details. - - You should have received a copy of the GNU General Public License - along with this program; if not, write to the Free Software - Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. -*/ - -#ifndef __gtk2_ardour_ardour_display_h__ -#define __gtk2_ardour_ardour_display_h__ - -#include -#include - -#include -#include -#include - - -#include "ardour_dropdown.h" - -class ArdourDisplay : public ArdourDropdown -{ -public: - - ArdourDisplay (Element e = default_elements); - virtual ~ArdourDisplay (); - - boost::shared_ptr get_controllable() { return binding_proxy.get_controllable(); } - void set_controllable (boost::shared_ptr c); - - bool on_scroll_event (GdkEventScroll* ev); - - void add_controllable_preset (const char*, float); - void handle_controllable_preset (float p); - - void controllable_changed (); - PBD::ScopedConnection watch_connection; -}; - -#endif /* __gtk2_ardour_ardour_menu_h__ */ diff --git a/gtk2_ardour/ardour_dropdown.cc b/gtk2_ardour/ardour_dropdown.cc deleted file mode 100644 index be18af5056..0000000000 --- a/gtk2_ardour/ardour_dropdown.cc +++ /dev/null @@ -1,165 +0,0 @@ -/* - Copyright (C) 2014 Paul Davis - - This program is free software; you can redistribute it and/or modify - it under the terms of the GNU General Public License as published by - the Free Software Foundation; either version 2 of the License, or - (at your option) any later version. - - This program is distributed in the hope that it will be useful, - but WITHOUT ANY WARRANTY; without even the implied warranty of - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - GNU General Public License for more details. - - You should have received a copy of the GNU General Public License - along with this program; if not, write to the Free Software - Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. - -*/ - -#include -#include -#include - -#include - -#include "pbd/compose.h" -#include "pbd/error.h" -#include "pbd/stacktrace.h" - -#include "gtkmm2ext/utils.h" -#include "gtkmm2ext/rgb_macros.h" -#include "gtkmm2ext/gui_thread.h" - -#include "ardour/rc_configuration.h" // for widget prelight preference - -#include "ardour_dropdown.h" - -#include "pbd/i18n.h" - -#define REFLECTION_HEIGHT 2 - -using namespace Gdk; -using namespace Gtk; -using namespace Glib; -using namespace PBD; -using namespace std; - - -ArdourDropdown::ArdourDropdown (Element e) - : _scrolling_disabled(false) -{ -// signal_button_press_event().connect (sigc::mem_fun(*this, &ArdourDropdown::on_mouse_pressed)); - _menu.signal_size_request().connect (sigc::mem_fun(*this, &ArdourDropdown::menu_size_request)); - - _menu.set_reserve_toggle_size(false); - - add_elements(e); - add_elements(ArdourButton::Menu); -} - -ArdourDropdown::~ArdourDropdown () -{ -} - -void -ArdourDropdown::menu_size_request(Requisition *req) { - req->width = max(req->width, get_allocation().get_width()); -} - -bool -ArdourDropdown::on_button_press_event (GdkEventButton* ev) -{ - if (binding_proxy.button_press_handler (ev)) { - return true; - } - - if (ev->type == GDK_BUTTON_PRESS && ev->button == 1) { - Gtkmm2ext::anchored_menu_popup(&_menu, this, get_text(), 1, ev->time); - } - - return true; -} - -bool -ArdourDropdown::on_scroll_event (GdkEventScroll* ev) -{ - using namespace Menu_Helpers; - - if (_scrolling_disabled) { - return false; - } - - const MenuItem * current_active = _menu.get_active(); - const MenuList& items = _menu.items (); - int c = 0; - - if (!current_active) { - return true; - } - - /* work around another gtkmm API clusterfuck - * const MenuItem* get_active () const - * void set_active (guint index) - * - * also MenuList.activate_item does not actually - * set it as active in the menu. - * - */ - - switch (ev->direction) { - case GDK_SCROLL_UP: - - for (MenuList::const_reverse_iterator i = items.rbegin(); i != items.rend(); ++i, ++c) { - if ( &(*i) != current_active) { - continue; - } - if (++i != items.rend()) { - c = items.size() - 2 - c; - assert(c >= 0); - _menu.set_active(c); - _menu.activate_item(*i); - } - break; - } - break; - case GDK_SCROLL_DOWN: - for (MenuList::const_iterator i = items.begin(); i != items.end(); ++i, ++c) { - if ( &(*i) != current_active) { - continue; - } - if (++i != items.end()) { - assert(c + 1 < (int) items.size()); - _menu.set_active(c + 1); - _menu.activate_item(*i); - } - break; - } - break; - default: - break; - } - return true; -} - -void -ArdourDropdown::clear_items () -{ - _menu.items ().clear (); -} - -void -ArdourDropdown::AddMenuElem (Menu_Helpers::Element e) -{ - using namespace Menu_Helpers; - - MenuList& items = _menu.items (); - - items.push_back (e); -} - -void -ArdourDropdown::disable_scrolling() -{ - _scrolling_disabled = true; -} diff --git a/gtk2_ardour/ardour_dropdown.h b/gtk2_ardour/ardour_dropdown.h deleted file mode 100644 index 9931a91e3c..0000000000 --- a/gtk2_ardour/ardour_dropdown.h +++ /dev/null @@ -1,56 +0,0 @@ -/* - Copyright (C) 2014 Paul Davis - - This program is free software; you can redistribute it and/or modify - it under the terms of the GNU General Public License as published by - the Free Software Foundation; either version 2 of the License, or - (at your option) any later version. - - This program is distributed in the hope that it will be useful, - but WITHOUT ANY WARRANTY; without even the implied warranty of - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - GNU General Public License for more details. - - You should have received a copy of the GNU General Public License - along with this program; if not, write to the Free Software - Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. -*/ - -#ifndef __gtk2_ardour_ardour_dropdown_h__ -#define __gtk2_ardour_ardour_dropdown_h__ - -#include -#include - -#include -#include -#include - - -#include "ardour_button.h" - -class ArdourDropdown : public ArdourButton -{ -public: - - ArdourDropdown (Element e = default_elements); - virtual ~ArdourDropdown (); - - bool on_button_press_event (GdkEventButton*); - bool on_scroll_event (GdkEventScroll*); - void menu_size_request(Gtk::Requisition*); - - void clear_items (); - void AddMenuElem (Gtk::Menu_Helpers::Element e); - - void disable_scrolling(); - - Gtk::Menu_Helpers::MenuList& items () { return _menu.items (); } - -private: - Gtk::Menu _menu; - - bool _scrolling_disabled; -}; - -#endif /* __gtk2_ardour_ardour_dropdown_h__ */ diff --git a/gtk2_ardour/ardour_knob.cc b/gtk2_ardour/ardour_knob.cc deleted file mode 100644 index 25d9c44630..0000000000 --- a/gtk2_ardour/ardour_knob.cc +++ /dev/null @@ -1,599 +0,0 @@ -/* - Copyright (C) 2010 Paul Davis - - This program is free software; you can redistribute it and/or modify - it under the terms of the GNU General Public License as published by - the Free Software Foundation; either version 2 of the License, or - (at your option) any later version. - - This program is distributed in the hope that it will be useful, - but WITHOUT ANY WARRANTY; without even the implied warranty of - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - GNU General Public License for more details. - - You should have received a copy of the GNU General Public License - along with this program; if not, write to the Free Software - Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. - -*/ - -#include -#include -#include - -#include - -#include "pbd/compose.h" -#include "pbd/controllable.h" -#include "pbd/error.h" -#include "pbd/stacktrace.h" - -#include "gtkmm2ext/utils.h" -#include "gtkmm2ext/rgb_macros.h" -#include "gtkmm2ext/gui_thread.h" -#include "gtkmm2ext/keyboard.h" - -#include "ardour/automation_control.h" -#include "ardour/rc_configuration.h" // for widget prelight preference - -#include "ardour_knob.h" -#include "timers.h" -#include "ui_config.h" - -#include "canvas/colors.h" -#include "canvas/utils.h" - -#include "pbd/i18n.h" - -using namespace Gtkmm2ext; -using namespace Gtk; -using namespace Glib; -using namespace PBD; -using std::max; -using std::min; -using namespace std; - -ArdourKnob::Element ArdourKnob::default_elements = ArdourKnob::Element (ArdourKnob::Arc); - -ArdourKnob::ArdourKnob (Element e, Flags flags) - : _elements (e) - , _hovering (false) - , _grabbed_x (0) - , _grabbed_y (0) - , _val (0) - , _normal (0) - , _dead_zone_delta (0) - , _flags (flags) - , _tooltip (this) -{ - UIConfiguration::instance().ColorsChanged.connect (sigc::mem_fun (*this, &ArdourKnob::color_handler)); - - // watch automation :( - // TODO only use for GainAutomation - Timers::rapid_connect (sigc::bind (sigc::mem_fun (*this, &ArdourKnob::controllable_changed), false)); -} - -ArdourKnob::~ArdourKnob() -{ -} - -void -ArdourKnob::render (Cairo::RefPtr const& ctx, cairo_rectangle_t*) -{ - cairo_t* cr = ctx->cobj(); - cairo_pattern_t* shade_pattern; - - float width = get_width(); - float height = get_height(); - - const float scale = min(width, height); - const float pointer_thickness = 3.0 * (scale/80); //(if the knob is 80 pixels wide, we want a 3-pix line on it) - - const float start_angle = ((180 - 65) * G_PI) / 180; - const float end_angle = ((360 + 65) * G_PI) / 180; - - float zero = 0; - if (_flags & ArcToZero) { - zero = _normal; - } - - const float value_angle = start_angle + (_val * (end_angle - start_angle)); - const float zero_angle = start_angle + (zero * (end_angle - start_angle)); - - float value_x = cos (value_angle); - float value_y = sin (value_angle); - - float xc = 0.5 + width/ 2.0; - float yc = 0.5 + height/ 2.0; - - cairo_translate (cr, xc, yc); //after this, everything is based on the center of the knob - - //get the knob color from the theme - ArdourCanvas::Color knob_color = UIConfiguration::instance().color (string_compose ("%1", get_name())); - - float center_radius = 0.48*scale; - float border_width = 0.8; - - bool arc = (_elements & Arc)==Arc; - bool bevel = (_elements & Bevel)==Bevel; - bool flat = _flat_buttons; - - if ( arc ) { - center_radius = scale*0.33; - - float inner_progress_radius = scale*0.38; - float outer_progress_radius = scale*0.48; - float progress_width = (outer_progress_radius-inner_progress_radius); - float progress_radius = inner_progress_radius + progress_width/2.0; - - //dark arc background - cairo_set_source_rgb (cr, 0.3, 0.3, 0.3 ); - cairo_set_line_width (cr, progress_width); - cairo_arc (cr, 0, 0, progress_radius, start_angle, end_angle); - cairo_stroke (cr); - - //look up the arc colors from the config - double red_start, green_start, blue_start, unused; - ArdourCanvas::Color arc_start_color = UIConfiguration::instance().color ( string_compose ("%1: arc start", get_name())); - ArdourCanvas::color_to_rgba( arc_start_color, red_start, green_start, blue_start, unused ); - double red_end, green_end, blue_end; - ArdourCanvas::Color arc_end_color = UIConfiguration::instance().color ( string_compose ("%1: arc end", get_name()) ); - ArdourCanvas::color_to_rgba( arc_end_color, red_end, green_end, blue_end, unused ); - - //vary the arc color over the travel of the knob - float intensity = fabsf (_val - zero) / std::max(zero, (1.f - zero)); - const float intensity_inv = 1.0 - intensity; - float r = intensity_inv * red_end + intensity * red_start; - float g = intensity_inv * green_end + intensity * green_start; - float b = intensity_inv * blue_end + intensity * blue_start; - - //draw the arc - cairo_set_source_rgb (cr, r,g,b); - cairo_set_line_width (cr, progress_width); - if (zero_angle > value_angle) { - cairo_arc (cr, 0, 0, progress_radius, value_angle, zero_angle); - } else { - cairo_arc (cr, 0, 0, progress_radius, zero_angle, value_angle); - } - cairo_stroke (cr); - - //shade the arc - if (!flat) { - shade_pattern = cairo_pattern_create_linear (0.0, -yc, 0.0, yc); //note we have to offset the pattern from our centerpoint - cairo_pattern_add_color_stop_rgba (shade_pattern, 0.0, 1,1,1, 0.15); - cairo_pattern_add_color_stop_rgba (shade_pattern, 0.5, 1,1,1, 0.0); - cairo_pattern_add_color_stop_rgba (shade_pattern, 1.0, 1,1,1, 0.0); - cairo_set_source (cr, shade_pattern); - cairo_arc (cr, 0, 0, outer_progress_radius-1, 0, 2.0*G_PI); - cairo_fill (cr); - cairo_pattern_destroy (shade_pattern); - } - -#if 0 //black border - const float start_angle_x = cos (start_angle); - const float start_angle_y = sin (start_angle); - const float end_angle_x = cos (end_angle); - const float end_angle_y = sin (end_angle); - - cairo_set_source_rgb (cr, 0, 0, 0 ); - cairo_set_line_width (cr, border_width); - cairo_move_to (cr, (outer_progress_radius * start_angle_x), (outer_progress_radius * start_angle_y)); - cairo_line_to (cr, (inner_progress_radius * start_angle_x), (inner_progress_radius * start_angle_y)); - cairo_stroke (cr); - cairo_move_to (cr, (outer_progress_radius * end_angle_x), (outer_progress_radius * end_angle_y)); - cairo_line_to (cr, (inner_progress_radius * end_angle_x), (inner_progress_radius * end_angle_y)); - cairo_stroke (cr); - cairo_arc (cr, 0, 0, outer_progress_radius, start_angle, end_angle); - cairo_stroke (cr); -#endif - } - - if (!flat) { - //knob shadow - cairo_save(cr); - cairo_translate(cr, pointer_thickness+1, pointer_thickness+1 ); - cairo_set_source_rgba (cr, 0, 0, 0, 0.1 ); - cairo_arc (cr, 0, 0, center_radius-1, 0, 2.0*G_PI); - cairo_fill (cr); - cairo_restore(cr); - - //inner circle - ArdourCanvas::set_source_rgba(cr, knob_color); - cairo_arc (cr, 0, 0, center_radius, 0, 2.0*G_PI); - cairo_fill (cr); - - //gradient - if (bevel) { - //knob gradient - shade_pattern = cairo_pattern_create_linear (0.0, -yc, 0.0, yc); //note we have to offset the gradient from our centerpoint - cairo_pattern_add_color_stop_rgba (shade_pattern, 0.0, 1,1,1, 0.2); - cairo_pattern_add_color_stop_rgba (shade_pattern, 0.2, 1,1,1, 0.2); - cairo_pattern_add_color_stop_rgba (shade_pattern, 0.8, 0,0,0, 0.2); - cairo_pattern_add_color_stop_rgba (shade_pattern, 1.0, 0,0,0, 0.2); - cairo_set_source (cr, shade_pattern); - cairo_arc (cr, 0, 0, center_radius, 0, 2.0*G_PI); - cairo_fill (cr); - cairo_pattern_destroy (shade_pattern); - - //flat top over beveled edge - ArdourCanvas::set_source_rgb_a (cr, knob_color, 0.5 ); - cairo_arc (cr, 0, 0, center_radius-pointer_thickness, 0, 2.0*G_PI); - cairo_fill (cr); - } else { - //radial gradient - shade_pattern = cairo_pattern_create_radial ( -center_radius, -center_radius, 1, -center_radius, -center_radius, center_radius*2.5 ); //note we have to offset the gradient from our centerpoint - cairo_pattern_add_color_stop_rgba (shade_pattern, 0.0, 1,1,1, 0.2); - cairo_pattern_add_color_stop_rgba (shade_pattern, 1.0, 0,0,0, 0.3); - cairo_set_source (cr, shade_pattern); - cairo_arc (cr, 0, 0, center_radius, 0, 2.0*G_PI); - cairo_fill (cr); - cairo_pattern_destroy (shade_pattern); - } - - } else { - //inner circle - ArdourCanvas::set_source_rgba(cr, knob_color); - cairo_arc (cr, 0, 0, center_radius, 0, 2.0*G_PI); - cairo_fill (cr); - } - - - //black knob border - cairo_set_line_width (cr, border_width); - cairo_set_source_rgba (cr, 0,0,0, 1 ); - cairo_arc (cr, 0, 0, center_radius, 0, 2.0*G_PI); - cairo_stroke (cr); - - //line shadow - if (!flat) { - cairo_save(cr); - cairo_translate(cr, 1, 1 ); - cairo_set_source_rgba (cr, 0,0,0,0.3 ); - cairo_set_line_cap (cr, CAIRO_LINE_CAP_ROUND); - cairo_set_line_width (cr, pointer_thickness); - cairo_move_to (cr, (center_radius * value_x), (center_radius * value_y)); - cairo_line_to (cr, ((center_radius*0.4) * value_x), ((center_radius*0.4) * value_y)); - cairo_stroke (cr); - cairo_restore(cr); - } - - //line - cairo_set_source_rgba (cr, 1,1,1, 1 ); - cairo_set_line_cap (cr, CAIRO_LINE_CAP_ROUND); - cairo_set_line_width (cr, pointer_thickness); - cairo_move_to (cr, (center_radius * value_x), (center_radius * value_y)); - cairo_line_to (cr, ((center_radius*0.4) * value_x), ((center_radius*0.4) * value_y)); - cairo_stroke (cr); - - //highlight if grabbed or if mouse is hovering over me - if (_tooltip.dragging() || (_hovering && UIConfiguration::instance().get_widget_prelight() ) ) { - cairo_set_source_rgba (cr, 1,1,1, 0.12 ); - cairo_arc (cr, 0, 0, center_radius, 0, 2.0*G_PI); - cairo_fill (cr); - } - - cairo_identity_matrix(cr); -} - -void -ArdourKnob::on_size_request (Gtk::Requisition* req) -{ - // see ardour-button VectorIcon size, use font scaling as default - CairoWidget::on_size_request (req); // allow to override - - // we're square - if (req->width < req->height) { - req->width = req->height; - } - if (req->height < req->width) { - req->height = req->width; - } -} - -bool -ArdourKnob::on_scroll_event (GdkEventScroll* ev) -{ - /* mouse wheel */ - - float scale = 0.05; //by default, we step in 1/20ths of the knob travel - if (ev->state & Keyboard::GainFineScaleModifier) { - if (ev->state & Keyboard::GainExtraFineScaleModifier) { - scale *= 0.01; - } else { - scale *= 0.10; - } - } - - boost::shared_ptr c = binding_proxy.get_controllable(); - if (c) { - float val = c->get_interface(); - - if ( ev->direction == GDK_SCROLL_UP ) - val += scale; - else - val -= scale; - - c->set_interface(val); - } - - return true; -} - -bool -ArdourKnob::on_motion_notify_event (GdkEventMotion *ev) -{ - if (!(ev->state & Gdk::BUTTON1_MASK)) { - return true; - } - - boost::shared_ptr c = binding_proxy.get_controllable(); - if (!c) { - return true; - } - - - //scale the adjustment based on keyboard modifiers & GUI size - const float ui_scale = max (1.f, UIConfiguration::instance().get_ui_scale()); - float scale = 0.0025 / ui_scale; - - if (ev->state & Keyboard::GainFineScaleModifier) { - if (ev->state & Keyboard::GainExtraFineScaleModifier) { - scale *= 0.01; - } else { - scale *= 0.10; - } - } - - //calculate the travel of the mouse - int delta = (_grabbed_y - ev->y) - (_grabbed_x - ev->x); - if (delta == 0) { - return true; - } - - _grabbed_x = ev->x; - _grabbed_y = ev->y; - float val = c->get_interface(); - - if (_flags & Detent) { - const float px_deadzone = 42.f * ui_scale; - - if ((val - _normal) * (val - _normal + delta * scale) < 0) { - /* detent */ - const int tozero = (_normal - val) * scale; - int remain = delta - tozero; - if (abs (remain) > px_deadzone) { - /* slow down passing the default value */ - remain += (remain > 0) ? px_deadzone * -.5 : px_deadzone * .5; - delta = tozero + remain; - _dead_zone_delta = 0; - } else { - c->set_value (c->normal(), Controllable::NoGroup); - _dead_zone_delta = remain / px_deadzone; - return true; - } - } - - if (fabsf (rintf((val - _normal) / scale) + _dead_zone_delta) < 1) { - c->set_value (c->normal(), Controllable::NoGroup); - _dead_zone_delta += delta / px_deadzone; - return true; - } - - _dead_zone_delta = 0; - } - - val += delta * scale; - c->set_interface(val); - - return true; -} - -bool -ArdourKnob::on_button_press_event (GdkEventButton *ev) -{ - _grabbed_x = ev->x; - _grabbed_y = ev->y; - _dead_zone_delta = 0; - - if (ev->type != GDK_BUTTON_PRESS) { - if (_grabbed) { - remove_modal_grab(); - gdk_pointer_ungrab (GDK_CURRENT_TIME); - } - return true; - } - - if (binding_proxy.button_press_handler (ev)) { - return true; - } - - if (ev->button != 1 && ev->button != 2) { - return false; - } - - set_active_state (Gtkmm2ext::ExplicitActive); - _tooltip.start_drag(); - add_modal_grab(); - _grabbed = true; - gdk_pointer_grab(ev->window,false, - GdkEventMask( Gdk::POINTER_MOTION_MASK | Gdk::BUTTON_PRESS_MASK |Gdk::BUTTON_RELEASE_MASK), - NULL,NULL,ev->time); - return true; -} - -bool -ArdourKnob::on_button_release_event (GdkEventButton *ev) -{ - _tooltip.stop_drag(); - _grabbed = false; - remove_modal_grab(); - gdk_pointer_ungrab (GDK_CURRENT_TIME); - - if ( (_grabbed_y == ev->y && _grabbed_x == ev->x) && Keyboard::modifier_state_equals (ev->state, Keyboard::TertiaryModifier)) { //no move, shift-click sets to default - boost::shared_ptr c = binding_proxy.get_controllable(); - if (!c) return false; - c->set_value (c->normal(), Controllable::NoGroup); - return true; - } - - unset_active_state (); - - return true; -} - -void -ArdourKnob::color_handler () -{ - set_dirty (); -} - -void -ArdourKnob::on_size_allocate (Allocation& alloc) -{ - CairoWidget::on_size_allocate (alloc); -} - -void -ArdourKnob::set_controllable (boost::shared_ptr c) -{ - watch_connection.disconnect (); //stop watching the old controllable - - if (!c) return; - - binding_proxy.set_controllable (c); - - c->Changed.connect (watch_connection, invalidator(*this), boost::bind (&ArdourKnob::controllable_changed, this, false), gui_context()); - - _normal = c->internal_to_interface(c->normal()); - - controllable_changed(); -} - -void -ArdourKnob::controllable_changed (bool force_update) -{ - boost::shared_ptr c = binding_proxy.get_controllable(); - if (!c) return; - - float val = c->get_interface(); - val = min( max(0.0f, val), 1.0f); // clamp - - if (val == _val && !force_update) { - return; - } - - _val = val; - if (!_tooltip_prefix.empty()) { - boost::shared_ptr ac = boost::dynamic_pointer_cast (c); - _tooltip.set_tip (_tooltip_prefix + c->get_user_string()); - } - set_dirty(); -} - -void -ArdourKnob::on_style_changed (const RefPtr&) -{ - set_dirty (); -} - -void -ArdourKnob::on_name_changed () -{ - set_dirty (); -} - - -void -ArdourKnob::set_active_state (Gtkmm2ext::ActiveState s) -{ - if (_active_state != s) - CairoWidget::set_active_state (s); -} - -void -ArdourKnob::set_visual_state (Gtkmm2ext::VisualState s) -{ - if (_visual_state != s) - CairoWidget::set_visual_state (s); -} - - -bool -ArdourKnob::on_focus_in_event (GdkEventFocus* ev) -{ - set_dirty (); - return CairoWidget::on_focus_in_event (ev); -} - -bool -ArdourKnob::on_focus_out_event (GdkEventFocus* ev) -{ - set_dirty (); - return CairoWidget::on_focus_out_event (ev); -} - -bool -ArdourKnob::on_enter_notify_event (GdkEventCrossing* ev) -{ - _hovering = true; - - set_dirty (); - - boost::shared_ptr c (binding_proxy.get_controllable ()); - if (c) { - PBD::Controllable::GUIFocusChanged (boost::weak_ptr (c)); - } - - return CairoWidget::on_enter_notify_event (ev); -} - -bool -ArdourKnob::on_leave_notify_event (GdkEventCrossing* ev) -{ - _hovering = false; - - set_dirty (); - - if (binding_proxy.get_controllable()) { - PBD::Controllable::GUIFocusChanged (boost::weak_ptr ()); - } - - return CairoWidget::on_leave_notify_event (ev); -} - -void -ArdourKnob::set_elements (Element e) -{ - _elements = e; -} - -void -ArdourKnob::add_elements (Element e) -{ - _elements = (ArdourKnob::Element) (_elements | e); -} - - -KnobPersistentTooltip::KnobPersistentTooltip (Gtk::Widget* w) - : PersistentTooltip (w, true, 3) - , _dragging (false) -{ -} - -void -KnobPersistentTooltip::start_drag () -{ - _dragging = true; -} - -void -KnobPersistentTooltip::stop_drag () -{ - _dragging = false; -} - -bool -KnobPersistentTooltip::dragging () const -{ - return _dragging; -} diff --git a/gtk2_ardour/ardour_knob.h b/gtk2_ardour/ardour_knob.h deleted file mode 100644 index f3291270cc..0000000000 --- a/gtk2_ardour/ardour_knob.h +++ /dev/null @@ -1,128 +0,0 @@ -/* - Copyright (C) 2014 Paul Davis - - This program is free software; you can redistribute it and/or modify - it under the terms of the GNU General Public License as published by - the Free Software Foundation; either version 2 of the License, or - (at your option) any later version. - - This program is distributed in the hope that it will be useful, - but WITHOUT ANY WARRANTY; without even the implied warranty of - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - GNU General Public License for more details. - - You should have received a copy of the GNU General Public License - along with this program; if not, write to the Free Software - Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. -*/ - -#ifndef __gtk2_ardour_ardour_knob_h__ -#define __gtk2_ardour_ardour_knob_h__ - -#include -#include - -#include - -#include "pbd/signals.h" -#include "ardour/automatable.h" - -#include "gtkmm2ext/binding_proxy.h" -#include "gtkmm2ext/activatable.h" -#include "gtkmm2ext/cairo_widget.h" -#include "gtkmm2ext/persistent_tooltip.h" - -class KnobPersistentTooltip : public Gtkmm2ext::PersistentTooltip -{ -public: - KnobPersistentTooltip (Gtk::Widget* w); - - void start_drag (); - void stop_drag (); - bool dragging () const; - -private: - bool _dragging; -}; - - -class ArdourKnob : public CairoWidget , public Gtkmm2ext::Activatable -{ -public: - - enum Element { - Arc = 0x1, - Bevel = 0x2, - unused2 = 0x4, - unused3 = 0x8, - unused4 = 0x10, - unused5 = 0x20, - }; - - enum Flags { - NoFlags = 0, - Detent = 0x1, - ArcToZero = 0x2, - }; - - ArdourKnob (Element e = default_elements, Flags flags = NoFlags); - virtual ~ArdourKnob (); - - void set_active_state (Gtkmm2ext::ActiveState); - void set_visual_state (Gtkmm2ext::VisualState); - - Element elements() const { return _elements; } - void set_elements (Element); - void add_elements (Element); - static Element default_elements; - - void set_tooltip_prefix (std::string pfx) { _tooltip_prefix = pfx; controllable_changed (true); } - - boost::shared_ptr get_controllable() { return binding_proxy.get_controllable(); } - void set_controllable (boost::shared_ptr c); - - bool on_button_press_event (GdkEventButton*); - bool on_button_release_event (GdkEventButton*); - bool on_scroll_event (GdkEventScroll* ev); - bool on_motion_notify_event (GdkEventMotion *ev) ; - - void color_handler (); - - protected: - void render (Cairo::RefPtr const&, cairo_rectangle_t*); - void on_size_request (Gtk::Requisition* req); - void on_size_allocate (Gtk::Allocation&); - void on_style_changed (const Glib::RefPtr&); - void on_name_changed (); - bool on_enter_notify_event (GdkEventCrossing*); - bool on_leave_notify_event (GdkEventCrossing*); - bool on_focus_in_event (GdkEventFocus*); - bool on_focus_out_event (GdkEventFocus*); - - void controllable_changed (bool force_update = false); - PBD::ScopedConnection watch_connection; - - - private: - Element _elements; - BindingProxy binding_proxy; - - bool _hovering; - float _grabbed_x; - float _grabbed_y; - - float _val; // current value [0..1] - float _normal; // default value, arc - float _dead_zone_delta; - - Flags _flags; - - void action_sensitivity_changed (); - void action_visibility_changed (); - void action_tooltip_changed (); - - std::string _tooltip_prefix; - KnobPersistentTooltip _tooltip; -}; - -#endif /* __gtk2_ardour_ardour_knob_h__ */ diff --git a/gtk2_ardour/ardour_spacer.h b/gtk2_ardour/ardour_spacer.h deleted file mode 100644 index 28d2f1c378..0000000000 --- a/gtk2_ardour/ardour_spacer.h +++ /dev/null @@ -1,47 +0,0 @@ -/* - * Copyright (C) 2016 Robin Gareus - * - * This program is free software; you can redistribute it and/or - * modify it under the terms of the GNU General Public License - * as published by the Free Software Foundation; either version 2 - * of the License, or (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program; if not, write to the Free Software - * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. - */ - -#ifndef __gtkardour_ardour_spacer_h__ -#define __gtkardour_ardour_spacer_h__ - -#include "gtkmm2ext/cairo_widget.h" - -class ArdourVSpacer : public CairoWidget -{ -public: - ArdourVSpacer (float r = 0.75f) : CairoWidget (), ratio (r) {} - -protected: - void render (Cairo::RefPtr const& ctx, cairo_rectangle_t* r) { - float h = r->height * ratio; - float t = .5f * (r->height - h); - ctx->rectangle (0, t, 1, h); - ctx->set_source_rgb (0, 0, 0); - ctx->fill (); - } - - void on_size_request (Gtk::Requisition* req) { - req->width = 1; - req->height = 0; - CairoWidget::on_size_request (req); - } - - float ratio; -}; - -#endif diff --git a/gtk2_ardour/ardour_spinner.cc b/gtk2_ardour/ardour_spinner.cc deleted file mode 100644 index e579d7e5fe..0000000000 --- a/gtk2_ardour/ardour_spinner.cc +++ /dev/null @@ -1,207 +0,0 @@ -/* - * Copyright (C) 2016 Robin Gareus - * Copyright (C) 2011 Paul Davis - * - * This program is free software; you can redistribute it and/or - * modify it under the terms of the GNU General Public License - * as published by the Free Software Foundation; either version 2 - * of the License, or (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program; if not, write to the Free Software - * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. - */ - -#include "gtkmm2ext/gui_thread.h" -#include "gtkmm2ext/utils.h" -#include "gtkmm2ext/keyboard.h" - -#include "ardour/value_as_string.h" - -#include "ardour_spinner.h" - -using namespace ARDOUR; - -ArdourSpinner::ArdourSpinner ( - boost::shared_ptr c, - Gtk::Adjustment* adj) - : _btn (ArdourButton::Text) - , _ctrl_adj (adj) - , _spin_adj (0, c->lower (), c->upper (), .1, .01) - , _spinner (_spin_adj) - , _switching (false) - , _switch_on_release (false) - , _ctrl_ignore (false) - , _spin_ignore (false) - , _controllable (c) -{ - add_events (Gdk::BUTTON_PRESS_MASK | Gdk::BUTTON_RELEASE_MASK); - set (.5, .5, 1.0, 1.0); - set_border_width (0); - - _btn.set_controllable (c); - _btn.set_fallthrough_to_parent (true); - - _spinner.signal_activate().connect (mem_fun (*this, &ArdourSpinner::entry_activated)); - _spinner.signal_focus_out_event().connect (mem_fun (*this, &ArdourSpinner::entry_focus_out)); - _spinner.set_digits (4); - _spinner.set_numeric (true); - _spinner.set_name ("BarControlSpinner"); - - _spin_adj.set_step_increment(c->interface_to_internal(_ctrl_adj->get_step_increment()) - c->lower ()); - _spin_adj.set_page_increment(c->interface_to_internal(_ctrl_adj->get_page_increment()) - c->lower ()); - - _spin_adj.signal_value_changed().connect (sigc::mem_fun(*this, &ArdourSpinner::spin_adjusted)); - adj->signal_value_changed().connect (sigc::mem_fun(*this, &ArdourSpinner::ctrl_adjusted)); - c->Changed.connect (watch_connection, invalidator(*this), boost::bind (&ArdourSpinner::controllable_changed, this), gui_context()); - - - // this assume the "upper" value needs most space. - std::string txt = ARDOUR::value_as_string (c->desc(), c->upper ()); - Gtkmm2ext::set_size_request_to_display_given_text (*this, txt, 2, 2); - - add (_btn); - show_all (); - - controllable_changed(); - ctrl_adjusted (); -} - - -ArdourSpinner::~ArdourSpinner () -{ -} - -bool -ArdourSpinner::on_button_press_event (GdkEventButton* ev) -{ - if (get_child() != &_btn) { - return false; - } - - if (ev->button == 1 && ev->type == GDK_2BUTTON_PRESS) { - _switch_on_release = true; - return true; - } else { - _switch_on_release = false; - } - return false; -} - -bool -ArdourSpinner::on_button_release_event (GdkEventButton* ev) -{ - if (get_child() != &_btn) { - return false; - } - if (ev->button == 1 && _switch_on_release) { - Glib::signal_idle().connect (mem_fun (*this, &ArdourSpinner::switch_to_spinner)); - return true; - } - return false; -} - -bool -ArdourSpinner::on_scroll_event (GdkEventScroll* ev) -{ - float scale = 1.0; - if (ev->state & Gtkmm2ext::Keyboard::GainFineScaleModifier) { - if (ev->state & Gtkmm2ext::Keyboard::GainExtraFineScaleModifier) { - scale *= 0.01; - } else { - scale *= 0.10; - } - } - - boost::shared_ptr c = _btn.get_controllable(); - if (c) { - float val = c->get_interface(); - - if ( ev->direction == GDK_SCROLL_UP ) - val += 0.05 * scale; //by default, we step in 1/20ths of the knob travel - else - val -= 0.05 * scale; - - c->set_interface(val); - } - - return true; -} - -gint -ArdourSpinner::switch_to_button () -{ - if (_switching || get_child() == &_btn) { - return false; - } - _switching = true; - remove (); - add (_btn); - _btn.show (); - _btn.set_dirty (); - _switching = false; - return false; -} - -gint -ArdourSpinner::switch_to_spinner () -{ - if (_switching || get_child() != &_btn) { - return false; - } - _switching = true; - remove (); - add (_spinner); - _spinner.show (); - _spinner.select_region (0, _spinner.get_text_length ()); - _spinner.grab_focus (); - _switching = false; - return false; -} - -void -ArdourSpinner::entry_activated () -{ - switch_to_button (); -} - -bool -ArdourSpinner::entry_focus_out (GdkEventFocus* /*ev*/) -{ - entry_activated (); - return true; -} - -void -ArdourSpinner::ctrl_adjusted () -{ - if (_spin_ignore) { - return; - } - _ctrl_ignore = true; - _spin_adj.set_value (_controllable->interface_to_internal (_ctrl_adj->get_value ())); - _ctrl_ignore = false; -} - -void -ArdourSpinner::spin_adjusted () -{ - if (_ctrl_ignore) { - return; - } - _spin_ignore = true; - _ctrl_adj->set_value (_controllable->internal_to_interface (_spin_adj.get_value ())); - _spin_ignore = false; -} - -void -ArdourSpinner::controllable_changed () -{ - _btn.set_text (_controllable->get_user_string()); - _btn.set_dirty(); -} diff --git a/gtk2_ardour/ardour_spinner.h b/gtk2_ardour/ardour_spinner.h deleted file mode 100644 index b6ed229829..0000000000 --- a/gtk2_ardour/ardour_spinner.h +++ /dev/null @@ -1,70 +0,0 @@ -/* - * Copyright (C) 2016 Robin Gareus - * Copyright (C) 2011 Paul Davis - * - * This program is free software; you can redistribute it and/or - * modify it under the terms of the GNU General Public License - * as published by the Free Software Foundation; either version 2 - * of the License, or (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program; if not, write to the Free Software - * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. - */ - -#include -#ifndef __gtk2_ardour_ardour_spinner_h__ -#define __gtk2_ardour_ardour_spinner_h__ - -#include - -#include "ardour/automatable.h" -#include "ardour/automation_control.h" -#include "ardour_button.h" - -class ArdourSpinner : public Gtk::Alignment -{ - public: - ArdourSpinner ( - boost::shared_ptr, - Gtk::Adjustment* adj); - - virtual ~ArdourSpinner (); - - protected: - bool on_button_press_event (GdkEventButton*); - bool on_button_release_event (GdkEventButton*); - bool on_scroll_event (GdkEventScroll* ev); - - void controllable_changed (); - PBD::ScopedConnection watch_connection; - - private: - - bool entry_focus_out (GdkEventFocus*); - void entry_activated (); - gint switch_to_button (); - gint switch_to_spinner (); - - void ctrl_adjusted(); - void spin_adjusted(); - - ArdourButton _btn; - Gtk::Adjustment* _ctrl_adj; - Gtk::Adjustment _spin_adj; - Gtk::SpinButton _spinner; - bool _switching; - bool _switch_on_release; - bool _ctrl_ignore; - bool _spin_ignore; - - boost::shared_ptr _controllable; - -}; - -#endif /* __gtk2_ardour_ardour_menu_h__ */ diff --git a/gtk2_ardour/ardour_ui.cc b/gtk2_ardour/ardour_ui.cc index 4a4b385957..19745ede31 100644 --- a/gtk2_ardour/ardour_ui.cc +++ b/gtk2_ardour/ardour_ui.cc @@ -193,6 +193,7 @@ using namespace ARDOUR; using namespace ARDOUR_UI_UTILS; using namespace PBD; using namespace Gtkmm2ext; +using namespace ArdourWidgets; using namespace Gtk; using namespace std; using namespace Editing; @@ -297,8 +298,8 @@ ARDOUR_UI::ARDOUR_UI (int *argcp, char **argvp[], const char* localedir) , solo_alert_button (_("Solo")) , feedback_alert_button (_("Feedback")) , error_alert_button ( ArdourButton::just_led_default_elements ) - , editor_meter(0) , editor_meter_peak_display() + , editor_meter(0) , _suspend_editor_meter_callbacks (false) , _numpad_locate_happening (false) , _session_is_new (false) diff --git a/gtk2_ardour/ardour_ui.h b/gtk2_ardour/ardour_ui.h index b22c2f7ad9..43a77fe523 100644 --- a/gtk2_ardour/ardour_ui.h +++ b/gtk2_ardour/ardour_ui.h @@ -70,10 +70,11 @@ #include "video_timeline.h" +#include "widgets/ardour_button.h" +#include "widgets/ardour_spacer.h" + #include "add_route_dialog.h" -#include "ardour_button.h" #include "ardour_dialog.h" -#include "ardour_spacer.h" #include "ardour_window.h" #include "editing.h" #include "enums.h" @@ -120,7 +121,6 @@ class IdleOMeter; class VideoTimeLine; class ArdourKeyboard; -class ArdourVSpacer; class AudioClock; class ButtonJoiner; class ConnectionEditor; @@ -480,7 +480,7 @@ private: Gtk::Frame transport_frame; Gtk::HBox transport_hbox; - ArdourVSpacer *secondary_clock_spacer; + ArdourWidgets::ArdourVSpacer* secondary_clock_spacer; void repack_transport_hbox (); void update_clock_visibility (); @@ -516,23 +516,23 @@ private: void set_transport_controllable_state (const XMLNode&); XMLNode& get_transport_controllable_state (); - ArdourButton roll_button; - ArdourButton stop_button; - ArdourButton goto_start_button; - ArdourButton goto_end_button; - ArdourButton auto_loop_button; - ArdourButton play_selection_button; - ArdourButton rec_button; - ArdourButton punch_in_button; - ArdourButton punch_out_button; - ArdourButton layered_button; + ArdourWidgets::ArdourButton roll_button; + ArdourWidgets::ArdourButton stop_button; + ArdourWidgets::ArdourButton goto_start_button; + ArdourWidgets::ArdourButton goto_end_button; + ArdourWidgets::ArdourButton auto_loop_button; + ArdourWidgets::ArdourButton play_selection_button; + ArdourWidgets::ArdourButton rec_button; + ArdourWidgets::ArdourButton punch_in_button; + ArdourWidgets::ArdourButton punch_out_button; + ArdourWidgets::ArdourButton layered_button; - ArdourVSpacer recpunch_spacer; - ArdourVSpacer monitoring_spacer; + ArdourWidgets::ArdourVSpacer recpunch_spacer; + ArdourWidgets::ArdourVSpacer monitoring_spacer; - ArdourButton monitor_in_button; - ArdourButton monitor_disk_button; - ArdourButton auto_input_button; + ArdourWidgets::ArdourButton monitor_in_button; + ArdourWidgets::ArdourButton monitor_disk_button; + ArdourWidgets::ArdourButton auto_input_button; Gtk::Label punch_label; Gtk::Label layered_label; @@ -548,25 +548,25 @@ private: MiniTimeline mini_timeline; TimeInfoBox *time_info_box; - ArdourButton auto_return_button; - ArdourButton follow_edits_button; - ArdourButton click_button; - ArdourButton sync_button; + ArdourWidgets::ArdourButton auto_return_button; + ArdourWidgets::ArdourButton follow_edits_button; + ArdourWidgets::ArdourButton click_button; + ArdourWidgets::ArdourButton sync_button; - ArdourButton auditioning_alert_button; - ArdourButton solo_alert_button; - ArdourButton feedback_alert_button; - ArdourButton error_alert_button; + ArdourWidgets::ArdourButton auditioning_alert_button; + ArdourWidgets::ArdourButton solo_alert_button; + ArdourWidgets::ArdourButton feedback_alert_button; + ArdourWidgets::ArdourButton error_alert_button; - ArdourButton action_script_call_btn[10]; + ArdourWidgets::ArdourButton action_script_call_btn[10]; Gtk::Table action_script_table; Gtk::VBox alert_box; Gtk::VBox meter_box; - LevelMeterHBox * editor_meter; - float editor_meter_max_peak; - ArdourButton editor_meter_peak_display; - bool editor_meter_peak_button_release (GdkEventButton*); + ArdourWidgets::ArdourButton editor_meter_peak_display; + LevelMeterHBox * editor_meter; + float editor_meter_max_peak; + bool editor_meter_peak_button_release (GdkEventButton*); bool editor_meter_button_press (GdkEventButton* ev); void popup_editor_meter_menu (GdkEventButton* ev); @@ -870,7 +870,7 @@ private: void feedback_detected (); - ArdourButton midi_panic_button; + ArdourWidgets::ArdourButton midi_panic_button; void midi_panic (); void successful_graph_sort (); @@ -902,9 +902,9 @@ private: void tabs_switch (GtkNotebookPage*, guint page_number); void tabs_page_added (Gtk::Widget*, guint); void tabs_page_removed (Gtk::Widget*, guint); - ArdourButton editor_visibility_button; - ArdourButton mixer_visibility_button; - ArdourButton prefs_visibility_button; + ArdourWidgets::ArdourButton editor_visibility_button; + ArdourWidgets::ArdourButton mixer_visibility_button; + ArdourWidgets::ArdourButton prefs_visibility_button; bool key_press_focus_accelerator_handler (Gtk::Window& window, GdkEventKey* ev, Gtkmm2ext::Bindings*); bool try_gtk_accel_binding (GtkWindow* win, GdkEventKey* ev, bool translate, GdkModifierType modifier); diff --git a/gtk2_ardour/ardour_ui2.cc b/gtk2_ardour/ardour_ui2.cc index cd97a876fb..0bad50de0b 100644 --- a/gtk2_ardour/ardour_ui2.cc +++ b/gtk2_ardour/ardour_ui2.cc @@ -64,6 +64,7 @@ using namespace std; using namespace ARDOUR; using namespace PBD; using namespace Gtkmm2ext; +using namespace ArdourWidgets; using namespace Gtk; using namespace Glib; using namespace ARDOUR_UI_UTILS; diff --git a/gtk2_ardour/ardour_ui_dialogs.cc b/gtk2_ardour/ardour_ui_dialogs.cc index cd735c5df4..023f3ad133 100644 --- a/gtk2_ardour/ardour_ui_dialogs.cc +++ b/gtk2_ardour/ardour_ui_dialogs.cc @@ -77,6 +77,7 @@ using namespace PBD; using namespace Glib; using namespace Gtk; using namespace Gtkmm2ext; +using namespace ArdourWidgets; void ARDOUR_UI::set_session (Session *s) diff --git a/gtk2_ardour/ardour_ui_options.cc b/gtk2_ardour/ardour_ui_options.cc index f8dab139ad..638743897b 100644 --- a/gtk2_ardour/ardour_ui_options.cc +++ b/gtk2_ardour/ardour_ui_options.cc @@ -45,6 +45,7 @@ using namespace Gtk; using namespace Gtkmm2ext; using namespace ARDOUR; using namespace PBD; +using namespace ArdourWidgets; void ARDOUR_UI::toggle_external_sync() diff --git a/gtk2_ardour/audio_clock.cc b/gtk2_ardour/audio_clock.cc index 809a6637fe..e43a16377e 100644 --- a/gtk2_ardour/audio_clock.cc +++ b/gtk2_ardour/audio_clock.cc @@ -30,6 +30,8 @@ #include "gtkmm2ext/utils.h" #include "gtkmm2ext/rgb_macros.h" +#include "widgets/tooltips.h" + #include "ardour/profile.h" #include "ardour/lmath.h" #include "ardour/session.h" @@ -42,7 +44,6 @@ #include "enums_convert.h" #include "gui_thread.h" #include "keyboard.h" -#include "tooltips.h" #include "ui_config.h" #include "utils.h" @@ -50,6 +51,7 @@ using namespace ARDOUR; using namespace ARDOUR_UI_UTILS; +using namespace ArdourWidgets; using namespace PBD; using namespace Gtk; using namespace std; diff --git a/gtk2_ardour/audio_clock.h b/gtk2_ardour/audio_clock.h index 82b12b0eca..9ff8221229 100644 --- a/gtk2_ardour/audio_clock.h +++ b/gtk2_ardour/audio_clock.h @@ -34,7 +34,7 @@ #include "ardour/session_handle.h" #include "gtkmm2ext/cairo_widget.h" -#include "ardour_button.h" +#include "widgets/ardour_button.h" namespace ARDOUR { class Session; @@ -82,8 +82,8 @@ class AudioClock : public CairoWidget, public ARDOUR::SessionHandlePtr void set_session (ARDOUR::Session *s); void set_negative_allowed (bool yn); - ArdourButton* left_btn () { return &_left_btn; } - ArdourButton* right_btn () { return &_right_btn; } + ArdourWidgets::ArdourButton* left_btn () { return &_left_btn; } + ArdourWidgets::ArdourButton* right_btn () { return &_right_btn; } /** Alter cairo scaling during rendering. * @@ -112,8 +112,8 @@ class AudioClock : public CairoWidget, public ARDOUR::SessionHandlePtr bool on_button_press_event (GdkEventButton *ev); bool on_button_release_event(GdkEventButton *ev); - ArdourButton _left_btn; - ArdourButton _right_btn; + ArdourWidgets::ArdourButton _left_btn; + ArdourWidgets::ArdourButton _right_btn; private: Mode _mode; diff --git a/gtk2_ardour/audio_time_axis.cc b/gtk2_ardour/audio_time_axis.cc index d06a4c53e3..2567306a52 100644 --- a/gtk2_ardour/audio_time_axis.cc +++ b/gtk2_ardour/audio_time_axis.cc @@ -36,12 +36,13 @@ #include "gtkmm2ext/bindable_button.h" #include "gtkmm2ext/utils.h" +#include "widgets/ardour_button.h" + #include "ardour/event_type_map.h" #include "ardour/pannable.h" #include "ardour/panner.h" #include "ardour/panner_shell.h" -#include "ardour_button.h" #include "audio_time_axis.h" #include "automation_line.h" #include "enums.h" @@ -59,6 +60,7 @@ using namespace std; using namespace ARDOUR; +using namespace ArdourWidgets; using namespace ARDOUR_UI_UTILS; using namespace PBD; using namespace Gtk; diff --git a/gtk2_ardour/automation_controller.cc b/gtk2_ardour/automation_controller.cc index 6816bffa93..5fc86e9276 100644 --- a/gtk2_ardour/automation_controller.cc +++ b/gtk2_ardour/automation_controller.cc @@ -29,8 +29,8 @@ #include "ardour/session.h" #include "ardour/tempo.h" -#include "ardour_button.h" -#include "ardour_knob.h" +#include "widgets/ardour_button.h" +#include "widgets/ardour_knob.h" #include "automation_controller.h" #include "gui_thread.h" #include "note_select_dialog.h" @@ -40,6 +40,7 @@ using namespace ARDOUR; using namespace Gtk; +using namespace ArdourWidgets; using PBD::Controllable; diff --git a/gtk2_ardour/automation_time_axis.cc b/gtk2_ardour/automation_time_axis.cc index 011c53997f..a0052032b0 100644 --- a/gtk2_ardour/automation_time_axis.cc +++ b/gtk2_ardour/automation_time_axis.cc @@ -39,6 +39,8 @@ #include "canvas/debug.h" +#include "widgets/tooltips.h" + #include "automation_time_axis.h" #include "automation_streamview.h" #include "gui_thread.h" @@ -47,7 +49,6 @@ #include "paste_context.h" #include "public_editor.h" #include "selection.h" -#include "tooltips.h" #include "rgb_macros.h" #include "point_selection.h" #include "control_point.h" @@ -59,6 +60,7 @@ using namespace std; using namespace ARDOUR; +using namespace ArdourWidgets; using namespace ARDOUR_UI_UTILS; using namespace PBD; using namespace Gtk; diff --git a/gtk2_ardour/automation_time_axis.h b/gtk2_ardour/automation_time_axis.h index e95199ae15..573d88a4d5 100644 --- a/gtk2_ardour/automation_time_axis.h +++ b/gtk2_ardour/automation_time_axis.h @@ -32,10 +32,11 @@ #include "canvas/rectangle.h" +#include "widgets/ardour_button.h" +#include "widgets/ardour_dropdown.h" + #include "time_axis_view.h" #include "automation_controller.h" -#include "ardour_button.h" -#include "ardour_dropdown.h" namespace ARDOUR { class Session; @@ -154,8 +155,8 @@ protected: bool ignore_toggle; bool first_call_to_set_height; - ArdourButton hide_button; - ArdourDropdown auto_dropdown; + ArdourWidgets::ArdourButton hide_button; + ArdourWidgets::ArdourDropdown auto_dropdown; Gtk::Label* plugname; bool plugname_packed; diff --git a/gtk2_ardour/button_joiner.cc b/gtk2_ardour/button_joiner.cc index eaa22363aa..a7e360e064 100644 --- a/gtk2_ardour/button_joiner.cc +++ b/gtk2_ardour/button_joiner.cc @@ -27,11 +27,13 @@ #include "gtkmm2ext/utils.h" #include "gtkmm2ext/rgb_macros.h" +#include "widgets/tooltips.h" + #include "button_joiner.h" -#include "tooltips.h" #include "ui_config.h" using namespace Gtk; +using namespace ArdourWidgets; using namespace ARDOUR_UI_UTILS; ButtonJoiner::ButtonJoiner (const std::string& str, Gtk::Widget& lw, Gtk::Widget& rw, bool central_joiner) diff --git a/gtk2_ardour/color_theme_manager.cc b/gtk2_ardour/color_theme_manager.cc index 013a0764d0..30eeed162f 100644 --- a/gtk2_ardour/color_theme_manager.cc +++ b/gtk2_ardour/color_theme_manager.cc @@ -39,7 +39,6 @@ #include "canvas/scroll_group.h" #include "canvas/wave_view.h" -#include "ardour_button.h" #include "ardour_dialog.h" #include "color_theme_manager.h" #include "rgb_macros.h" diff --git a/gtk2_ardour/control_slave_ui.cc b/gtk2_ardour/control_slave_ui.cc index fa14d46518..14467a0118 100644 --- a/gtk2_ardour/control_slave_ui.cc +++ b/gtk2_ardour/control_slave_ui.cc @@ -31,13 +31,13 @@ #include "gtkmm2ext/gtk_ui.h" #include "gtkmm2ext/utils.h" -#include "ardour_button.h" #include "control_slave_ui.h" #include "gui_thread.h" #include "pbd/i18n.h" using namespace ARDOUR; +using namespace ArdourWidgets; using namespace Gtk; using std::string; diff --git a/gtk2_ardour/control_slave_ui.h b/gtk2_ardour/control_slave_ui.h index 8a7ae5fd6d..f54b1c72cb 100644 --- a/gtk2_ardour/control_slave_ui.h +++ b/gtk2_ardour/control_slave_ui.h @@ -31,7 +31,7 @@ #include "ardour/session_handle.h" -#include "ardour_button.h" +#include "widgets/ardour_button.h" namespace ARDOUR { class VCA; @@ -48,9 +48,9 @@ public: private: boost::shared_ptr stripable; - PBD::ScopedConnectionList connections; - PBD::ScopedConnectionList master_connections; - ArdourButton initial_button; + PBD::ScopedConnectionList connections; + PBD::ScopedConnectionList master_connections; + ArdourWidgets::ArdourButton initial_button; void master_property_changed (PBD::PropertyChange const &); void update_vca_display (); diff --git a/gtk2_ardour/editor.cc b/gtk2_ardour/editor.cc index c716068647..7ea217733b 100644 --- a/gtk2_ardour/editor.cc +++ b/gtk2_ardour/editor.cc @@ -84,11 +84,13 @@ #include "canvas/debug.h" #include "canvas/text.h" +#include "widgets/ardour_spacer.h" +#include "widgets/tooltips.h" + #include "control_protocol/control_protocol.h" #include "actions.h" #include "analysis_window.h" -#include "ardour_spacer.h" #include "audio_clock.h" #include "audio_region_view.h" #include "audio_streamview.h" @@ -137,7 +139,6 @@ #include "time_axis_view.h" #include "time_info_box.h" #include "timers.h" -#include "tooltips.h" #include "ui_config.h" #include "utils.h" #include "vca_time_axis.h" @@ -147,6 +148,7 @@ using namespace std; using namespace ARDOUR; +using namespace ArdourWidgets; using namespace ARDOUR_UI_UTILS; using namespace PBD; using namespace Gtk; diff --git a/gtk2_ardour/editor.h b/gtk2_ardour/editor.h index c78c85ffc6..606444c6bd 100644 --- a/gtk2_ardour/editor.h +++ b/gtk2_ardour/editor.h @@ -52,9 +52,10 @@ #include "canvas/fwd.h" #include "canvas/ruler.h" -#include "ardour_button.h" +#include "widgets/ardour_button.h" +#include "widgets/ardour_dropdown.h" + #include "ardour_dialog.h" -#include "ardour_dropdown.h" #include "public_editor.h" #include "editing.h" #include "enums.h" @@ -1769,14 +1770,14 @@ private: void editor_mixer_button_toggled (); void editor_list_button_toggled (); - ArdourButton zoom_in_button; - ArdourButton zoom_out_button; - ArdourButton zoom_out_full_button; + ArdourWidgets::ArdourButton zoom_in_button; + ArdourWidgets::ArdourButton zoom_out_button; + ArdourWidgets::ArdourButton zoom_out_full_button; - ArdourButton tav_expand_button; - ArdourButton tav_shrink_button; - ArdourDropdown visible_tracks_selector; - ArdourDropdown zoom_preset_selector; + ArdourWidgets::ArdourButton tav_expand_button; + ArdourWidgets::ArdourButton tav_shrink_button; + ArdourWidgets::ArdourDropdown visible_tracks_selector; + ArdourWidgets::ArdourDropdown zoom_preset_selector; int32_t _visible_track_count; void build_track_count_menu (); @@ -1789,15 +1790,15 @@ private: Gtk::Table toolbar_selection_clock_table; Gtk::Label toolbar_selection_cursor_label; - ArdourButton mouse_select_button; - ArdourButton mouse_draw_button; - ArdourButton mouse_move_button; - ArdourButton mouse_timefx_button; - ArdourButton mouse_content_button; - ArdourButton mouse_audition_button; - ArdourButton mouse_cut_button; + ArdourWidgets::ArdourButton mouse_select_button; + ArdourWidgets::ArdourButton mouse_draw_button; + ArdourWidgets::ArdourButton mouse_move_button; + ArdourWidgets::ArdourButton mouse_timefx_button; + ArdourWidgets::ArdourButton mouse_content_button; + ArdourWidgets::ArdourButton mouse_audition_button; + ArdourWidgets::ArdourButton mouse_cut_button; - ArdourButton smart_mode_button; + ArdourWidgets::ArdourButton smart_mode_button; Glib::RefPtr smart_mode_action; void mouse_mode_toggled (Editing::MouseMode m); @@ -1810,20 +1811,20 @@ private: Gtk::Button automation_mode_button; //edit mode menu stuff - ArdourDropdown edit_mode_selector; - void edit_mode_selection_done ( ARDOUR::EditMode m ); + ArdourWidgets::ArdourDropdown edit_mode_selector; + void edit_mode_selection_done (ARDOUR::EditMode); void build_edit_mode_menu (); - Gtk::VBox edit_mode_box; + Gtk::VBox edit_mode_box; void set_edit_mode (ARDOUR::EditMode); void cycle_edit_mode (); - ArdourDropdown snap_type_selector; + ArdourWidgets::ArdourDropdown snap_type_selector; void build_snap_type_menu (); - ArdourDropdown snap_mode_selector; + ArdourWidgets::ArdourDropdown snap_mode_selector; void build_snap_mode_menu (); - Gtk::HBox snap_box; + Gtk::HBox snap_box; std::vector snap_type_strings; std::vector snap_mode_strings; @@ -1837,8 +1838,8 @@ private: Glib::RefPtr snap_mode_action (Editing::SnapMode); //zoom focus meu stuff - ArdourDropdown zoom_focus_selector; - void zoom_focus_selection_done ( Editing::ZoomFocus f ); + ArdourWidgets::ArdourDropdown zoom_focus_selector; + void zoom_focus_selection_done (Editing::ZoomFocus); void build_zoom_focus_menu (); std::vector zoom_focus_strings; @@ -1846,16 +1847,16 @@ private: Glib::RefPtr zoom_focus_action (Editing::ZoomFocus); - Gtk::HBox _track_box; + Gtk::HBox _track_box; - Gtk::HBox _zoom_box; - void zoom_adjustment_changed(); + Gtk::HBox _zoom_box; + void zoom_adjustment_changed(); void setup_toolbar (); void setup_tooltips (); - Gtk::HBox toolbar_hbox; + Gtk::HBox toolbar_hbox; void setup_midi_toolbar (); @@ -1893,35 +1894,35 @@ private: /* transport range select process */ - ArdourCanvas::Rectangle* cd_marker_bar_drag_rect; - ArdourCanvas::Rectangle* range_bar_drag_rect; - ArdourCanvas::Rectangle* transport_bar_drag_rect; - ArdourCanvas::Rectangle *transport_bar_range_rect; - ArdourCanvas::Rectangle *transport_bar_preroll_rect; - ArdourCanvas::Rectangle *transport_bar_postroll_rect; - ArdourCanvas::Rectangle *transport_loop_range_rect; - ArdourCanvas::Rectangle *transport_punch_range_rect; - ArdourCanvas::Line *transport_punchin_line; - ArdourCanvas::Line *transport_punchout_line; - ArdourCanvas::Rectangle *transport_preroll_rect; - ArdourCanvas::Rectangle *transport_postroll_rect; + ArdourCanvas::Rectangle* cd_marker_bar_drag_rect; + ArdourCanvas::Rectangle* range_bar_drag_rect; + ArdourCanvas::Rectangle* transport_bar_drag_rect; + ArdourCanvas::Rectangle* transport_bar_range_rect; + ArdourCanvas::Rectangle* transport_bar_preroll_rect; + ArdourCanvas::Rectangle* transport_bar_postroll_rect; + ArdourCanvas::Rectangle* transport_loop_range_rect; + ArdourCanvas::Rectangle* transport_punch_range_rect; + ArdourCanvas::Line* transport_punchin_line; + ArdourCanvas::Line* transport_punchout_line; + ArdourCanvas::Rectangle* transport_preroll_rect; + ArdourCanvas::Rectangle* transport_postroll_rect; - ARDOUR::Location* transport_loop_location(); - ARDOUR::Location* transport_punch_location(); + ARDOUR::Location* transport_loop_location(); + ARDOUR::Location* transport_punch_location(); - ARDOUR::Location *temp_location; + ARDOUR::Location* temp_location; /* object rubberband select process */ void select_all_within (framepos_t, framepos_t, double, double, TrackViewList const &, Selection::Operation, bool); - ArdourCanvas::Rectangle *rubberband_rect; + ArdourCanvas::Rectangle* rubberband_rect; EditorRouteGroups* _route_groups; - EditorRoutes* _routes; - EditorRegions* _regions; - EditorSnapshots* _snapshots; - EditorLocations* _locations; + EditorRoutes* _routes; + EditorRegions* _regions; + EditorSnapshots* _snapshots; + EditorLocations* _locations; /* diskstream/route display management */ Glib::RefPtr rec_enabled_icon; @@ -1931,7 +1932,7 @@ private: bool sync_track_view_list_and_routes (); - Gtk::VBox list_vpacker; + Gtk::VBox list_vpacker; /* autoscrolling */ @@ -2089,8 +2090,8 @@ private: /* nudge */ - ArdourButton nudge_forward_button; - ArdourButton nudge_backward_button; + ArdourWidgets::ArdourButton nudge_forward_button; + ArdourWidgets::ArdourButton nudge_backward_button; Gtk::HBox nudge_hbox; Gtk::VBox nudge_vbox; AudioClock* nudge_clock; @@ -2152,7 +2153,7 @@ private: Editing::EditPoint _edit_point; - ArdourDropdown edit_point_selector; + ArdourWidgets::ArdourDropdown edit_point_selector; void build_edit_point_menu(); void set_edit_point_preference (Editing::EditPoint ep, bool force = false); diff --git a/gtk2_ardour/editor_ops.cc b/gtk2_ardour/editor_ops.cc index 53a2aa8bb2..3cb62da846 100644 --- a/gtk2_ardour/editor_ops.cc +++ b/gtk2_ardour/editor_ops.cc @@ -110,6 +110,7 @@ using namespace ARDOUR; using namespace PBD; using namespace Gtk; using namespace Gtkmm2ext; +using namespace ArdourWidgets; using namespace Editing; using Gtkmm2ext::Keyboard; diff --git a/gtk2_ardour/editor_regions.cc b/gtk2_ardour/editor_regions.cc index 6ee68a0896..83b3f00165 100644 --- a/gtk2_ardour/editor_regions.cc +++ b/gtk2_ardour/editor_regions.cc @@ -37,6 +37,8 @@ #include "gtkmm2ext/treeutils.h" #include "gtkmm2ext/utils.h" +#include "widgets/tooltips.h" + #include "audio_clock.h" #include "editor.h" #include "editing.h" @@ -50,13 +52,13 @@ #include "editor_regions.h" #include "editor_drag.h" #include "main_clock.h" -#include "tooltips.h" #include "ui_config.h" #include "pbd/i18n.h" using namespace std; using namespace ARDOUR; +using namespace ArdourWidgets; using namespace ARDOUR_UI_UTILS; using namespace PBD; using namespace Gtk; diff --git a/gtk2_ardour/editor_route_groups.cc b/gtk2_ardour/editor_route_groups.cc index e9fca92bc3..871a003563 100644 --- a/gtk2_ardour/editor_route_groups.cc +++ b/gtk2_ardour/editor_route_groups.cc @@ -29,6 +29,8 @@ #include "gtkmm2ext/gtk_ui.h" #include "gtkmm2ext/cell_renderer_color_selector.h" +#include "widgets/tooltips.h" + #include "ardour/route_group.h" #include "ardour/route.h" #include "ardour/session.h" @@ -45,7 +47,6 @@ #include "route_group_dialog.h" #include "route_time_axis.h" #include "time_axis_view.h" -#include "tooltips.h" #include "utils.h" #include "pbd/i18n.h" @@ -53,6 +54,7 @@ using namespace std; using namespace ARDOUR; using namespace ARDOUR_UI_UTILS; +using namespace ArdourWidgets; using namespace PBD; using namespace Gtk; using Gtkmm2ext::Keyboard; diff --git a/gtk2_ardour/editor_routes.cc b/gtk2_ardour/editor_routes.cc index 45b9797f78..c64683c341 100644 --- a/gtk2_ardour/editor_routes.cc +++ b/gtk2_ardour/editor_routes.cc @@ -42,6 +42,8 @@ #include "gtkmm2ext/cell_renderer_pixbuf_toggle.h" #include "gtkmm2ext/treeutils.h" +#include "widgets/tooltips.h" + #include "actions.h" #include "ardour_ui.h" #include "audio_time_axis.h" @@ -54,7 +56,6 @@ #include "mixer_strip.h" #include "plugin_setup_dialog.h" #include "route_sorter.h" -#include "tooltips.h" #include "vca_time_axis.h" #include "utils.h" @@ -62,6 +63,7 @@ using namespace std; using namespace ARDOUR; +using namespace ArdourWidgets; using namespace ARDOUR_UI_UTILS; using namespace PBD; using namespace Gtk; diff --git a/gtk2_ardour/engine_dialog.cc b/gtk2_ardour/engine_dialog.cc index d0ecdcfa7c..f96bcf1b8b 100644 --- a/gtk2_ardour/engine_dialog.cc +++ b/gtk2_ardour/engine_dialog.cc @@ -64,6 +64,7 @@ using namespace Gtk; using namespace Gtkmm2ext; using namespace PBD; using namespace Glib; +using namespace ArdourWidgets; using namespace ARDOUR_UI_UTILS; #define DEBUG_ECONTROL(msg) DEBUG_TRACE (PBD::DEBUG::EngineControl, string_compose ("%1: %2\n", __LINE__, msg)); diff --git a/gtk2_ardour/engine_dialog.h b/gtk2_ardour/engine_dialog.h index f10e37bae6..b9bfabb61e 100644 --- a/gtk2_ardour/engine_dialog.h +++ b/gtk2_ardour/engine_dialog.h @@ -35,8 +35,9 @@ #include "pbd/signals.h" +#include "widgets/ardour_button.h" + #include "ardour_dialog.h" -#include "ardour_button.h" class EngineControl : public ArdourDialog, public PBD::ScopedConnectionList { @@ -84,31 +85,31 @@ private: Gtk::Adjustment ports_adjustment; Gtk::SpinButton ports_spinner; - Gtk::Label have_control_text; - ArdourButton control_app_button; - ArdourButton midi_devices_button; - ArdourButton start_stop_button; - ArdourButton update_devices_button; - ArdourButton use_buffered_io_button; + Gtk::Label have_control_text; + ArdourWidgets::ArdourButton control_app_button; + ArdourWidgets::ArdourButton midi_devices_button; + ArdourWidgets::ArdourButton start_stop_button; + ArdourWidgets::ArdourButton update_devices_button; + ArdourWidgets::ArdourButton use_buffered_io_button; Gtk::Button connect_disconnect_button; /* latency measurement */ - Gtk::ComboBoxText lm_output_channel_combo; - Gtk::ComboBoxText lm_input_channel_combo; - Gtk::Label lm_measure_label; - Gtk::Button lm_measure_button; - Gtk::Button lm_use_button; - Gtk::Button lm_back_button; - ArdourButton lm_button_audio; - Gtk::Label lm_title; - Gtk::Label lm_preamble; - Gtk::Label lm_results; - Gtk::Table lm_table; - Gtk::VBox lm_vbox; - bool have_lm_results; - bool lm_running; + Gtk::ComboBoxText lm_output_channel_combo; + Gtk::ComboBoxText lm_input_channel_combo; + Gtk::Label lm_measure_label; + Gtk::Button lm_measure_button; + Gtk::Button lm_use_button; + Gtk::Button lm_back_button; + ArdourWidgets::ArdourButton lm_button_audio; + Gtk::Label lm_title; + Gtk::Label lm_preamble; + Gtk::Label lm_results; + Gtk::Table lm_table; + Gtk::VBox lm_vbox; + bool have_lm_results; + bool lm_running; /* MIDI Tab */ @@ -346,7 +347,7 @@ private: MidiDeviceSettings _measure_midi; void midi_latency_adjustment_changed(Gtk::Adjustment *, MidiDeviceSettings, bool); - void midi_device_enabled_toggled(ArdourButton *, MidiDeviceSettings); + void midi_device_enabled_toggled(ArdourWidgets::ArdourButton *, MidiDeviceSettings); sigc::connection lm_back_button_signal; }; diff --git a/gtk2_ardour/export_format_dialog.cc b/gtk2_ardour/export_format_dialog.cc index 862401f704..5707f3beb7 100644 --- a/gtk2_ardour/export_format_dialog.cc +++ b/gtk2_ardour/export_format_dialog.cc @@ -21,9 +21,11 @@ #include "ardour/session.h" #include "ardour/export_format_specification.h" +#include "widgets/tooltips.h" + #include "export_format_dialog.h" #include "gui_thread.h" -#include "tooltips.h" + #include "pbd/i18n.h" using namespace ARDOUR; @@ -120,7 +122,7 @@ ExportFormatDialog::ExportFormatDialog (FormatPtr format, bool new_dialog) : normalize_hbox.pack_start (normalize_dbtp_spinbutton, false, false, 2); normalize_hbox.pack_start (normalize_dbtp_label, false, false, 0); - ARDOUR_UI_UTILS::set_tooltip (normalize_loudness_rb, + ArdourWidgets::set_tooltip (normalize_loudness_rb, _("Normalize to EBU-R128 LUFS target loudness without exceeding the given true-peak limit. EBU-R128 normalization is only available for mono and stereo targets, true-peak works for any channel layout.")); normalize_dbfs_spinbutton.configure (normalize_dbfs_adjustment, 0.1, 2); @@ -147,7 +149,7 @@ ExportFormatDialog::ExportFormatDialog (FormatPtr format, bool new_dialog) : get_vbox()->pack_start (command_label, false, false); get_vbox()->pack_start (command_entry, false, false); - ARDOUR_UI_UTILS::set_tooltip (command_entry, + ArdourWidgets::set_tooltip (command_entry, _( "%a Artist name\n" "%b File's base-name\n" diff --git a/gtk2_ardour/gain_meter.cc b/gtk2_ardour/gain_meter.cc index e60c6613eb..4a17d4f640 100644 --- a/gtk2_ardour/gain_meter.cc +++ b/gtk2_ardour/gain_meter.cc @@ -27,11 +27,15 @@ #include "ardour/utils.h" #include -#include -#include -#include -#include -#include + +#include "gtkmm/style.h" +#include "gdkmm/color.h" +#include "gtkmm2ext/utils.h" +#include "gtkmm2ext/fastmeter.h" +#include "gtkmm2ext/gtk_ui.h" + +#include "widgets/tooltips.h" + #include "pbd/fastlog.h" #include "pbd/stacktrace.h" @@ -42,7 +46,6 @@ #include "utils.h" #include "meter_patterns.h" #include "timers.h" -#include "tooltips.h" #include "ui_config.h" #include "ardour/session.h" @@ -55,7 +58,7 @@ #include "pbd/i18n.h" using namespace ARDOUR; -using namespace ARDOUR_UI_UTILS; +using namespace ArdourWidgets; using namespace PBD; using namespace Gtkmm2ext; using namespace Gtk; @@ -408,7 +411,7 @@ GainMeter::set_type (MeterType t) bool GainMeterBase::gain_key_press (GdkEventKey* ev) { - if (key_is_legal_for_numeric_entry (ev->keyval)) { + if (ARDOUR_UI_UTILS::key_is_legal_for_numeric_entry (ev->keyval)) { /* drop through to normal handling */ return false; } diff --git a/gtk2_ardour/gain_meter.h b/gtk2_ardour/gain_meter.h index 943fe36ae4..5517151ebb 100644 --- a/gtk2_ardour/gain_meter.h +++ b/gtk2_ardour/gain_meter.h @@ -38,7 +38,7 @@ #include "ardour/types.h" #include "ardour/session_handle.h" -#include "ardour_button.h" +#include "widgets/ardour_button.h" #include "gtkmm2ext/click_box.h" #include "gtkmm2ext/focus_entry.h" @@ -134,11 +134,11 @@ protected: sigc::connection gain_watching; - ArdourButton gain_automation_state_button; + ArdourWidgets::ArdourButton gain_automation_state_button; Gtk::Menu gain_astate_menu; - ArdourButton meter_point_button; + ArdourWidgets::ArdourButton meter_point_button; Gtk::Menu meter_point_menu; diff --git a/gtk2_ardour/generic_pluginui.cc b/gtk2_ardour/generic_pluginui.cc index bcc91a673d..4b30388087 100644 --- a/gtk2_ardour/generic_pluginui.cc +++ b/gtk2_ardour/generic_pluginui.cc @@ -32,12 +32,15 @@ #include "pbd/xml++.h" #include "pbd/failed_constructor.h" -#include -#include -#include -#include -#include -#include +#include "gtkmm2ext/click_box.h" +#include "gtkmm2ext/fastmeter.h" +#include "gtkmm2ext/barcontroller.h" +#include "gtkmm2ext/utils.h" +#include "gtkmm2ext/doi.h" +#include "gtkmm2ext/slider_controller.h" + +#include "widgets/ardour_knob.h" +#include "widgets/tooltips.h" #include "ardour/plugin.h" #include "ardour/plugin_insert.h" @@ -48,10 +51,8 @@ #include "plugin_ui.h" #include "gui_thread.h" #include "automation_controller.h" -#include "ardour_knob.h" #include "gain_meter.h" #include "timers.h" -#include "tooltips.h" #include "ui_config.h" #include "pbd/i18n.h" @@ -60,6 +61,7 @@ using namespace std; using namespace ARDOUR; using namespace PBD; using namespace Gtkmm2ext; +using namespace ArdourWidgets; using namespace Gtk; using namespace ARDOUR_UI_UTILS; diff --git a/gtk2_ardour/location_ui.cc b/gtk2_ardour/location_ui.cc index 0f9af3ff56..83c261e474 100644 --- a/gtk2_ardour/location_ui.cc +++ b/gtk2_ardour/location_ui.cc @@ -24,6 +24,7 @@ #include "ardour/session.h" #include "pbd/memento_command.h" +#include "widgets/tooltips.h" #include "ardour_ui.h" #include "clock_group.h" @@ -35,14 +36,13 @@ #include "prompter.h" #include "utils.h" #include "public_editor.h" -#include "tooltips.h" #include "ui_config.h" #include "pbd/i18n.h" using namespace std; using namespace ARDOUR; -using namespace ARDOUR_UI_UTILS; +using namespace ArdourWidgets; using namespace PBD; using namespace Gtk; using namespace Gtkmm2ext; diff --git a/gtk2_ardour/location_ui.h b/gtk2_ardour/location_ui.h index 3be45dc329..0d1115feba 100644 --- a/gtk2_ardour/location_ui.h +++ b/gtk2_ardour/location_ui.h @@ -33,9 +33,9 @@ #include "ardour/location.h" #include "ardour/session_handle.h" -#include +#include "gtkmm2ext/pane.h" +#include "widgets/ardour_button.h" -#include "ardour_button.h" #include "ardour_window.h" #include "audio_clock.h" @@ -82,13 +82,13 @@ protected: Gtk::HBox start_hbox; AudioClock start_clock; - ArdourButton start_to_playhead_button; - ArdourButton locate_to_start_button; + ArdourWidgets::ArdourButton start_to_playhead_button; + ArdourWidgets::ArdourButton locate_to_start_button; Gtk::HBox end_hbox; AudioClock end_clock; - ArdourButton end_to_playhead_button; - ArdourButton locate_to_end_button; + ArdourWidgets::ArdourButton end_to_playhead_button; + ArdourWidgets::ArdourButton locate_to_end_button; AudioClock length_clock; Gtk::CheckButton cd_check_button; @@ -96,7 +96,7 @@ protected: Gtk::CheckButton lock_check_button; Gtk::CheckButton glue_check_button; - ArdourButton remove_button; + ArdourWidgets::ArdourButton remove_button; Gtk::HBox cd_track_details_hbox; Gtk::Entry isrc_entry; diff --git a/gtk2_ardour/luadialog.cc b/gtk2_ardour/luadialog.cc index 93c55261ad..ce34e121fd 100644 --- a/gtk2_ardour/luadialog.cc +++ b/gtk2_ardour/luadialog.cc @@ -24,8 +24,9 @@ #include "gtkmm2ext/slider_controller.h" #include "gtkmm2ext/utils.h" +#include "widgets/ardour_dropdown.h" + #include "ardour_dialog.h" -#include "ardour_dropdown.h" #include "luadialog.h" #include "utils.h" @@ -431,7 +432,7 @@ protected: _rv = rv; } - ArdourDropdown _dd; + ArdourWidgets::ArdourDropdown _dd; std::vector _refs; luabridge::LuaRef* _rv; }; diff --git a/gtk2_ardour/luawindow.cc b/gtk2_ardour/luawindow.cc index 90fa41a166..8a9c2aee3b 100644 --- a/gtk2_ardour/luawindow.cc +++ b/gtk2_ardour/luawindow.cc @@ -38,6 +38,8 @@ #include "gtkmm2ext/utils.h" #include "gtkmm2ext/window_title.h" +#include "widgets/tooltips.h" + #include "ardour/filesystem_paths.h" #include "ardour/luabindings.h" #include "LuaBridge/LuaBridge.h" @@ -47,14 +49,12 @@ #include "luainstance.h" #include "luawindow.h" #include "public_editor.h" -#include "tooltips.h" #include "utils.h" #include "utils_videotl.h" #include "pbd/i18n.h" using namespace ARDOUR; -using namespace ARDOUR_UI_UTILS; using namespace PBD; using namespace Gtk; using namespace Glib; @@ -164,7 +164,7 @@ LuaWindow::LuaWindow () vpane->show_all (); add (*vpane); set_size_request (640, 480); // XXX - ARDOUR_UI_UTILS::set_tooltip (script_select, _("Select Editor Buffer")); + ArdourWidgets::set_tooltip (script_select, _("Select Editor Buffer")); setup_buffers (); LuaScripting::instance().scripts_changed.connect (*this, invalidator (*this), boost::bind (&LuaWindow::refresh_scriptlist, this), gui_context()); @@ -190,7 +190,7 @@ LuaWindow::hide_window (GdkEventAny *ev) { if (!_visible) return 0; _visible = false; - return just_hide_it (ev, static_cast(this)); + return ARDOUR_UI_UTILS::just_hide_it (ev, static_cast(this)); } void LuaWindow::reinit_lua () diff --git a/gtk2_ardour/luawindow.h b/gtk2_ardour/luawindow.h index 21caa54a11..3994970adb 100644 --- a/gtk2_ardour/luawindow.h +++ b/gtk2_ardour/luawindow.h @@ -38,8 +38,8 @@ #include "lua/luastate.h" -#include "ardour_button.h" -#include "ardour_dropdown.h" +#include "widgets/ardour_button.h" +#include "widgets/ardour_dropdown.h" class LuaWindow : public Gtk::Window, @@ -100,14 +100,14 @@ private: Gtk::TextView outtext; Gtk::ScrolledWindow scrollout; - ArdourButton _btn_run; - ArdourButton _btn_clear; - ArdourButton _btn_open; - ArdourButton _btn_save; - ArdourButton _btn_delete; - ArdourButton _btn_revert; + ArdourWidgets::ArdourButton _btn_run; + ArdourWidgets::ArdourButton _btn_clear; + ArdourWidgets::ArdourButton _btn_open; + ArdourWidgets::ArdourButton _btn_save; + ArdourWidgets::ArdourButton _btn_delete; + ArdourWidgets::ArdourButton _btn_revert; - ArdourDropdown script_select; + ArdourWidgets::ArdourDropdown script_select; typedef boost::shared_ptr ScriptBufferPtr; typedef std::vector ScriptBufferList; diff --git a/gtk2_ardour/meter_strip.cc b/gtk2_ardour/meter_strip.cc index c3b0834525..5e2ee92e4f 100644 --- a/gtk2_ardour/meter_strip.cc +++ b/gtk2_ardour/meter_strip.cc @@ -30,14 +30,15 @@ #include "ardour/audio_track.h" #include "ardour/midi_track.h" -#include -#include -#include -#include +#include "gtkmm2ext/gtk_ui.h" +#include "gtkmm2ext/keyboard.h" +#include "gtkmm2ext/utils.h" +#include "gtkmm2ext/rgb_macros.h" + +#include "widgets/tooltips.h" #include "gui_thread.h" #include "ardour_window.h" -#include "tooltips.h" #include "ui_config.h" #include "utils.h" @@ -48,6 +49,7 @@ #include "pbd/i18n.h" using namespace ARDOUR; +using namespace ArdourWidgets; using namespace ARDOUR_UI_UTILS; using namespace PBD; using namespace Gtk; diff --git a/gtk2_ardour/meter_strip.h b/gtk2_ardour/meter_strip.h index a5f74fd99f..ab484f0658 100644 --- a/gtk2_ardour/meter_strip.h +++ b/gtk2_ardour/meter_strip.h @@ -28,8 +28,10 @@ #include "ardour/types.h" #include "ardour/ardour.h" + +#include "widgets/ardour_button.h" + #include "route_ui.h" -#include "ardour_button.h" #include "level_meter.h" @@ -108,8 +110,8 @@ private: Gtk::HBox spacer; Gtk::HBox namebx; Gtk::VBox namenumberbx; - ArdourButton name_label; - ArdourButton number_label; + ArdourWidgets::ArdourButton name_label; + ArdourWidgets::ArdourButton number_label; Gtk::DrawingArea meter_metric_area; Gtk::DrawingArea meter_ticks1_area; Gtk::DrawingArea meter_ticks2_area; @@ -124,7 +126,7 @@ private: Gtk::Alignment peak_align; Gtk::HBox peakbx; Gtk::VBox btnbox; - ArdourButton peak_display; + ArdourWidgets::ArdourButton peak_display; std::vector _types; ARDOUR::MeterType metric_type; diff --git a/gtk2_ardour/midi_time_axis.cc b/gtk2_ardour/midi_time_axis.cc index 524cacc35d..63e7f90113 100644 --- a/gtk2_ardour/midi_time_axis.cc +++ b/gtk2_ardour/midi_time_axis.cc @@ -39,6 +39,8 @@ #include "gtkmm2ext/bindable_button.h" #include "gtkmm2ext/utils.h" +#include "widgets/tooltips.h" + #include "ardour/event_type_map.h" #include "ardour/midi_patch_manager.h" #include "ardour/midi_playlist.h" @@ -61,7 +63,6 @@ #include "ardour/track.h" #include "ardour/types.h" -#include "ardour_button.h" #include "automation_line.h" #include "automation_time_axis.h" #include "editor.h" @@ -85,7 +86,6 @@ #include "rgb_macros.h" #include "selection.h" #include "step_editor.h" -#include "tooltips.h" #include "utils.h" #include "note_base.h" @@ -94,7 +94,6 @@ #include "pbd/i18n.h" using namespace ARDOUR; -using namespace ARDOUR_UI_UTILS; using namespace PBD; using namespace Gtk; using namespace Gtkmm2ext; @@ -154,7 +153,7 @@ MidiTimeAxisView::set_route (boost::shared_ptr rt) */ RouteTimeAxisView::set_route (rt); - _view->apply_color (gdk_color_to_rgba (color()), StreamView::RegionColor); + _view->apply_color (ARDOUR_UI_UTILS::gdk_color_to_rgba (color()), StreamView::RegionColor); subplugin_menu.set_name ("ArdourContextMenu"); @@ -261,8 +260,8 @@ MidiTimeAxisView::set_route (boost::shared_ptr rt) } } - set_tooltip (_midnam_model_selector, _("External MIDI Device")); - set_tooltip (_midnam_custom_device_mode_selector, _("External Device Mode")); + ArdourWidgets::set_tooltip (_midnam_model_selector, _("External MIDI Device")); + ArdourWidgets::set_tooltip (_midnam_custom_device_mode_selector, _("External Device Mode")); _midi_controls_box.pack_start (_midnam_model_selector, false, false, 2); _midi_controls_box.pack_start (_midnam_custom_device_mode_selector, false, false, 2); diff --git a/gtk2_ardour/midi_time_axis.h b/gtk2_ardour/midi_time_axis.h index c562718853..9319aa3ec9 100644 --- a/gtk2_ardour/midi_time_axis.h +++ b/gtk2_ardour/midi_time_axis.h @@ -34,8 +34,9 @@ #include "ardour/types.h" #include "ardour/region.h" +#include "widgets/ardour_dropdown.h" + #include "ardour_dialog.h" -#include "ardour_dropdown.h" #include "route_ui.h" #include "enums.h" #include "route_time_axis.h" @@ -147,20 +148,20 @@ private: void update_control_names (); - bool _ignore_signals; - MidiScroomer* _range_scroomer; - PianoRollHeader* _piano_roll_header; - ARDOUR::NoteMode _note_mode; - Gtk::RadioMenuItem* _note_mode_item; - Gtk::RadioMenuItem* _percussion_mode_item; - ARDOUR::ColorMode _color_mode; - Gtk::RadioMenuItem* _meter_color_mode_item; - Gtk::RadioMenuItem* _channel_color_mode_item; - Gtk::RadioMenuItem* _track_color_mode_item; - Gtk::VBox _midi_controls_box; - MidiChannelSelectorWindow* _channel_selector; - ArdourDropdown _midnam_model_selector; - ArdourDropdown _midnam_custom_device_mode_selector; + bool _ignore_signals; + MidiScroomer* _range_scroomer; + PianoRollHeader* _piano_roll_header; + ARDOUR::NoteMode _note_mode; + Gtk::RadioMenuItem* _note_mode_item; + Gtk::RadioMenuItem* _percussion_mode_item; + ARDOUR::ColorMode _color_mode; + Gtk::RadioMenuItem* _meter_color_mode_item; + Gtk::RadioMenuItem* _channel_color_mode_item; + Gtk::RadioMenuItem* _track_color_mode_item; + Gtk::VBox _midi_controls_box; + MidiChannelSelectorWindow* _channel_selector; + ArdourWidgets::ArdourDropdown _midnam_model_selector; + ArdourWidgets::ArdourDropdown _midnam_custom_device_mode_selector; Gtk::CheckMenuItem* _step_edit_item; Gtk::Menu* default_channel_menu; diff --git a/gtk2_ardour/mini_timeline.cc b/gtk2_ardour/mini_timeline.cc index 3c99a12f1e..b5259af310 100644 --- a/gtk2_ardour/mini_timeline.cc +++ b/gtk2_ardour/mini_timeline.cc @@ -26,12 +26,13 @@ #include "canvas/colors.h" #include "canvas/utils.h" +#include "widgets/tooltips.h" + #include "ardour_ui.h" #include "public_editor.h" #include "main_clock.h" #include "mini_timeline.h" #include "timers.h" -#include "tooltips.h" #include "ui_config.h" #include "pbd/i18n.h" @@ -70,7 +71,7 @@ MiniTimeline::MiniTimeline () Location::start_changed.connect (marker_connection, invalidator (*this), boost::bind (&MiniTimeline::update_minitimeline, this), gui_context ()); Location::flags_changed.connect (marker_connection, invalidator (*this), boost::bind (&MiniTimeline::update_minitimeline, this), gui_context ()); - ARDOUR_UI_UTILS::set_tooltip (*this, + ArdourWidgets::set_tooltip (*this, string_compose (_("Navigation Timeline. Use left-click to locate to time position or marker; scroll-wheel to jump, hold %1 for fine grained and %2 + %3 for extra-fine grained control. Right-click to set display range. The display unit is defined by the primary clock."), Gtkmm2ext::Keyboard::primary_modifier_name(), Gtkmm2ext::Keyboard::primary_modifier_name (), diff --git a/gtk2_ardour/mixer_strip.cc b/gtk2_ardour/mixer_strip.cc index 884a840491..ac80fbea4f 100644 --- a/gtk2_ardour/mixer_strip.cc +++ b/gtk2_ardour/mixer_strip.cc @@ -35,6 +35,8 @@ #include "gtkmm2ext/slider_controller.h" #include "gtkmm2ext/bindable_button.h" +#include "widgets/tooltips.h" + #include "ardour/amp.h" #include "ardour/audio_track.h" #include "ardour/audioengine.h" @@ -62,7 +64,6 @@ #include "mixer_strip.h" #include "mixer_ui.h" #include "keyboard.h" -#include "ardour_button.h" #include "public_editor.h" #include "send_ui.h" #include "io_selector.h" @@ -70,13 +71,12 @@ #include "gui_thread.h" #include "route_group_menu.h" #include "meter_patterns.h" -#include "tooltips.h" #include "ui_config.h" #include "pbd/i18n.h" using namespace ARDOUR; -using namespace ARDOUR_UI_UTILS; +using namespace ArdourWidgets; using namespace PBD; using namespace Gtk; using namespace Gtkmm2ext; @@ -1621,6 +1621,7 @@ MixerStrip::route_group_changed () void MixerStrip::route_color_changed () { + using namespace ARDOUR_UI_UTILS; name_button.modify_bg (STATE_NORMAL, color()); number_label.set_fixed_colors (gdk_color_to_rgba (color()), gdk_color_to_rgba (color())); reset_strip_style (); diff --git a/gtk2_ardour/mixer_strip.h b/gtk2_ardour/mixer_strip.h index f6a81cdf86..7197f42285 100644 --- a/gtk2_ardour/mixer_strip.h +++ b/gtk2_ardour/mixer_strip.h @@ -47,9 +47,11 @@ #include "pbd/fastlog.h" +#include "widgets/ardour_button.h" +#include "widgets/ardour_knob.h" + #include "axis_view.h" #include "control_slave_ui.h" -#include "ardour_knob.h" #include "route_ui.h" #include "gain_meter.h" #include "panner_ui.h" @@ -162,11 +164,11 @@ private: Width _width; void* _width_owner; - ArdourButton hide_button; - ArdourButton width_button; - ArdourButton number_label; - Gtk::HBox width_hide_box; - Gtk::EventBox spacer; + ArdourWidgets::ArdourButton hide_button; + ArdourWidgets::ArdourButton width_button; + ArdourWidgets::ArdourButton number_label; + Gtk::HBox width_hide_box; + Gtk::EventBox spacer; void hide_clicked(); bool width_button_pressed (GdkEventButton *); @@ -191,17 +193,17 @@ private: void meter_changed (); void monitor_changed (); - ArdourButton input_button; - ArdourButton output_button; + ArdourWidgets::ArdourButton input_button; + ArdourWidgets::ArdourButton output_button; - ArdourButton* monitor_section_button; + ArdourWidgets::ArdourButton* monitor_section_button; void input_button_resized (Gtk::Allocation&); void output_button_resized (Gtk::Allocation&); void comment_button_resized (Gtk::Allocation&); - ArdourButton* midi_input_enable_button; - Gtk::HBox input_button_box; + ArdourWidgets::ArdourButton* midi_input_enable_button; + Gtk::HBox input_button_box; std::string longest_label; @@ -215,16 +217,14 @@ private: gint mark_update_safe (); guint32 mode_switch_in_progress; - ArdourButton name_button; - - ArdourButton _comment_button; - - ArdourKnob trim_control; + ArdourWidgets::ArdourButton name_button; + ArdourWidgets::ArdourButton _comment_button; + ArdourWidgets::ArdourKnob trim_control; void setup_comment_button (); - ArdourButton group_button; - RouteGroupMenu *group_menu; + ArdourWidgets::ArdourButton group_button; + RouteGroupMenu* group_menu; gint input_press (GdkEventButton *); gint input_release (GdkEventButton *); diff --git a/gtk2_ardour/monitor_section.cc b/gtk2_ardour/monitor_section.cc index 2cd46c051a..4a01da2d30 100644 --- a/gtk2_ardour/monitor_section.cc +++ b/gtk2_ardour/monitor_section.cc @@ -31,6 +31,8 @@ #include #include +#include "widgets/tooltips.h" + #include "ardour/amp.h" #include "ardour/audioengine.h" #include "ardour/monitor_processor.h" @@ -46,13 +48,13 @@ #include "monitor_section.h" #include "public_editor.h" #include "timers.h" -#include "tooltips.h" #include "ui_config.h" #include "utils.h" #include "pbd/i18n.h" using namespace ARDOUR; +using namespace ArdourWidgets; using namespace ARDOUR_UI_UTILS; using namespace Gtk; using namespace Gtkmm2ext; diff --git a/gtk2_ardour/monitor_section.h b/gtk2_ardour/monitor_section.h index 037ce528dc..a61f5a2fa5 100644 --- a/gtk2_ardour/monitor_section.h +++ b/gtk2_ardour/monitor_section.h @@ -24,9 +24,10 @@ #include "gtkmm2ext/bindable_button.h" #include "gtkmm2ext/bindings.h" -#include "ardour_button.h" -#include "ardour_knob.h" -#include "ardour_display.h" +#include "widgets/ardour_button.h" +#include "widgets/ardour_knob.h" +#include "widgets/ardour_display.h" + #include "level_meter.h" #include "route_ui.h" #include "monitor_selector.h" @@ -68,10 +69,10 @@ private: Glib::RefPtr channel_size_group; struct ChannelButtonSet { - ArdourButton cut; - ArdourButton dim; - ArdourButton solo; - ArdourButton invert; + ArdourWidgets::ArdourButton cut; + ArdourWidgets::ArdourButton dim; + ArdourWidgets::ArdourButton solo; + ArdourWidgets::ArdourButton invert; ChannelButtonSet (); }; @@ -79,20 +80,20 @@ private: typedef std::vector ChannelButtons; ChannelButtons _channel_buttons; - ArdourKnob* gain_control; - ArdourKnob* dim_control; - ArdourKnob* solo_boost_control; - ArdourKnob* solo_cut_control; + ArdourWidgets::ArdourKnob* gain_control; + ArdourWidgets::ArdourKnob* dim_control; + ArdourWidgets::ArdourKnob* solo_boost_control; + ArdourWidgets::ArdourKnob* solo_cut_control; - ArdourDisplay* gain_display; - ArdourDisplay* dim_display; - ArdourDisplay* solo_boost_display; - ArdourDisplay* solo_cut_display; + ArdourWidgets::ArdourDisplay* gain_display; + ArdourWidgets::ArdourDisplay* dim_display; + ArdourWidgets::ArdourDisplay* solo_boost_display; + ArdourWidgets::ArdourDisplay* solo_cut_display; std::list > output_menu_bundles; Gtk::Menu output_menu; MonitorSelectorWindow *_output_selector; - ArdourButton* output_button; + ArdourWidgets::ArdourButton* output_button; void maybe_add_bundle_to_output_menu (boost::shared_ptr, ARDOUR::BundleList const &); void bundle_output_chosen (boost::shared_ptr); @@ -147,24 +148,24 @@ private: gint output_press (GdkEventButton *); gint output_release (GdkEventButton *); - ArdourButton solo_in_place_button; - ArdourButton afl_button; - ArdourButton pfl_button; + ArdourWidgets::ArdourButton solo_in_place_button; + ArdourWidgets::ArdourButton afl_button; + ArdourWidgets::ArdourButton pfl_button; Gtk::VBox solo_model_box; void solo_use_in_place (); void solo_use_afl (); void solo_use_pfl (); - ArdourButton cut_all_button; - ArdourButton dim_all_button; - ArdourButton mono_button; - ArdourButton rude_solo_button; - ArdourButton rude_iso_button; - ArdourButton rude_audition_button; - ArdourButton exclusive_solo_button; - ArdourButton solo_mute_override_button; - ArdourButton toggle_processorbox_button; + ArdourWidgets::ArdourButton cut_all_button; + ArdourWidgets::ArdourButton dim_all_button; + ArdourWidgets::ArdourButton mono_button; + ArdourWidgets::ArdourButton rude_solo_button; + ArdourWidgets::ArdourButton rude_iso_button; + ArdourWidgets::ArdourButton rude_audition_button; + ArdourWidgets::ArdourButton exclusive_solo_button; + ArdourWidgets::ArdourButton solo_mute_override_button; + ArdourWidgets::ArdourButton toggle_processorbox_button; void do_blink (bool); void solo_blink (bool); diff --git a/gtk2_ardour/panner_ui.cc b/gtk2_ardour/panner_ui.cc index e8f3a8f435..0fd588dfdf 100644 --- a/gtk2_ardour/panner_ui.cc +++ b/gtk2_ardour/panner_ui.cc @@ -27,12 +27,13 @@ #include "ardour/panner_shell.h" #include "ardour/session.h" +#include "widgets/tooltips.h" + #include "panner_ui.h" #include "panner2d.h" #include "gui_thread.h" #include "stereo_panner.h" #include "timers.h" -#include "tooltips.h" #include "mono_panner.h" #include "ui_config.h" @@ -43,7 +44,6 @@ using namespace ARDOUR; using namespace PBD; using namespace Gtkmm2ext; using namespace Gtk; -using namespace ARDOUR_UI_UTILS; PannerUI::PannerUI (Session* s) : _current_nouts (-1) @@ -67,7 +67,7 @@ PannerUI::PannerUI (Session* s) pan_automation_state_button.set_name ("MixerAutomationPlaybackButton"); - set_tooltip (pan_automation_state_button, _("Pan automation mode")); + ArdourWidgets::set_tooltip (pan_automation_state_button, _("Pan automation mode")); //set_size_request_to_display_given_text (pan_automation_state_button, X_("O"), 2, 2); diff --git a/gtk2_ardour/plugin_pin_dialog.cc b/gtk2_ardour/plugin_pin_dialog.cc index 37f453da7e..33a961fdf5 100644 --- a/gtk2_ardour/plugin_pin_dialog.cc +++ b/gtk2_ardour/plugin_pin_dialog.cc @@ -29,6 +29,8 @@ #include "gtkmm2ext/rgb_macros.h" #include "gtkmm2ext/menu_elems.h" +#include "widgets/tooltips.h" + #include "ardour/amp.h" #include "ardour/audioengine.h" #include "ardour/pannable.h" @@ -42,7 +44,6 @@ #include "plugin_pin_dialog.h" #include "gui_thread.h" #include "timers.h" -#include "tooltips.h" #include "ui_config.h" #include "pbd/i18n.h" @@ -52,6 +53,7 @@ using namespace PBD; using namespace std; using namespace Gtk; using namespace Gtkmm2ext; +using namespace ArdourWidgets; PluginPinWidget::PluginPinWidget (boost::shared_ptr pi) : _set_config (_("Manual Config"), ArdourButton::led_default_elements) @@ -191,7 +193,7 @@ PluginPinWidget::PluginPinWidget (boost::shared_ptr pi) tl->pack_start (*manage (new Label ("")), true, true); // invisible separator tl->pack_start (*manage (new HSeparator ()), false, false, 4); _out_presets.disable_scrolling (); - ARDOUR_UI_UTILS::set_tooltip (_out_presets, _("Output Presets")); + ArdourWidgets::set_tooltip (_out_presets, _("Output Presets")); tl->pack_start (_out_presets, false, false); /* right side */ @@ -602,7 +604,7 @@ PluginPinWidget::add_port_to_table (boost::shared_ptr p, uint32_t r, bool ArdourButton *pb = manage (new ArdourButton (lbl)); pb->set_text_ellipsize (Pango::ELLIPSIZE_MIDDLE); pb->set_layout_ellipsize_width (108 * PANGO_SCALE); - ARDOUR_UI_UTILS::set_tooltip (*pb, tip); + ArdourWidgets::set_tooltip (*pb, tip); _sidechain_tbl->attach (*pb, 0, 1, r, r +1 , EXPAND|FILL, SHRINK); pb->signal_button_press_event ().connect (sigc::bind (sigc::mem_fun (*this, &PluginPinWidget::sc_input_press), boost::weak_ptr (p)), false); diff --git a/gtk2_ardour/plugin_pin_dialog.h b/gtk2_ardour/plugin_pin_dialog.h index 33047c6ee7..c1da44c53b 100644 --- a/gtk2_ardour/plugin_pin_dialog.h +++ b/gtk2_ardour/plugin_pin_dialog.h @@ -33,8 +33,9 @@ #include "gtkmm2ext/persistent_tooltip.h" #include "gtkmm2ext/slider_controller.h" -#include "ardour_button.h" -#include "ardour_dropdown.h" +#include "widgets/ardour_button.h" +#include "widgets/ardour_dropdown.h" + #include "ardour_window.h" #include "io_selector.h" @@ -94,22 +95,23 @@ private: Gtk::DrawingArea darea; - ArdourButton _set_config; - ArdourButton _tgl_sidechain; - ArdourButton _add_plugin; - ArdourButton _del_plugin; - ArdourButton _add_input_audio; - ArdourButton _del_input_audio; - ArdourButton _add_input_midi; - ArdourButton _del_input_midi; - ArdourButton _add_output_audio; - ArdourButton _del_output_audio; - ArdourButton _add_output_midi; - ArdourButton _del_output_midi; - ArdourButton _add_sc_audio; - ArdourButton _add_sc_midi; - - ArdourDropdown _out_presets; + + ArdourWidgets::ArdourButton _set_config; + ArdourWidgets::ArdourButton _tgl_sidechain; + ArdourWidgets::ArdourButton _add_plugin; + ArdourWidgets::ArdourButton _del_plugin; + ArdourWidgets::ArdourButton _add_input_audio; + ArdourWidgets::ArdourButton _del_input_audio; + ArdourWidgets::ArdourButton _add_input_midi; + ArdourWidgets::ArdourButton _del_input_midi; + ArdourWidgets::ArdourButton _add_output_audio; + ArdourWidgets::ArdourButton _del_output_audio; + ArdourWidgets::ArdourButton _add_output_midi; + ArdourWidgets::ArdourButton _del_output_midi; + ArdourWidgets::ArdourButton _add_sc_audio; + ArdourWidgets::ArdourButton _add_sc_midi; + + ArdourWidgets::ArdourDropdown _out_presets; Gtk::Menu reset_menu; Gtk::Menu input_menu; diff --git a/gtk2_ardour/plugin_selector.cc b/gtk2_ardour/plugin_selector.cc index c67af473a0..cd904f6cd9 100644 --- a/gtk2_ardour/plugin_selector.cc +++ b/gtk2_ardour/plugin_selector.cc @@ -30,9 +30,9 @@ #include #include -#include - +#include "gtkmm2ext/utils.h" #include "pbd/convert.h" +#include "widgets/tooltips.h" #include "ardour/plugin_manager.h" #include "ardour/plugin.h" @@ -40,7 +40,6 @@ #include "plugin_selector.h" #include "gui_thread.h" -#include "tooltips.h" #include "pbd/i18n.h" @@ -48,7 +47,7 @@ using namespace ARDOUR; using namespace PBD; using namespace Gtk; using namespace std; -using namespace ARDOUR_UI_UTILS; +using namespace ArdourWidgets; static const char* _filter_mode_strings[] = { N_("Name contains"), diff --git a/gtk2_ardour/plugin_selector.h b/gtk2_ardour/plugin_selector.h index 7ab332d3b4..8f4aec1304 100644 --- a/gtk2_ardour/plugin_selector.h +++ b/gtk2_ardour/plugin_selector.h @@ -28,9 +28,10 @@ #include "ardour/plugin.h" #include "ardour/session_handle.h" -#include "plugin_interest.h" -#include "ardour_button.h" +#include "widgets/ardour_button.h" + +#include "plugin_interest.h" #include "ardour_dialog.h" namespace ARDOUR { @@ -63,10 +64,10 @@ private: Gtk::Entry filter_entry; Gtk::Button filter_button; - ArdourButton fil_hidden_button; - ArdourButton fil_instruments_button; - ArdourButton fil_analysis_button; - ArdourButton fil_utils_button; + ArdourWidgets::ArdourButton fil_hidden_button; + ArdourWidgets::ArdourButton fil_instruments_button; + ArdourWidgets::ArdourButton fil_analysis_button; + ArdourWidgets::ArdourButton fil_utils_button; void filter_button_clicked (); void filter_entry_changed (); diff --git a/gtk2_ardour/plugin_setup_dialog.cc b/gtk2_ardour/plugin_setup_dialog.cc index 3df0fe6491..c3bbc0dbc0 100644 --- a/gtk2_ardour/plugin_setup_dialog.cc +++ b/gtk2_ardour/plugin_setup_dialog.cc @@ -24,6 +24,7 @@ #include "pbd/i18n.h" using namespace ARDOUR; +using namespace ArdourWidgets; using namespace Gtk; PluginSetupDialog::PluginSetupDialog (boost::shared_ptr r, boost::shared_ptr pi, ARDOUR::Route::PluginSetupOptions flags) diff --git a/gtk2_ardour/plugin_setup_dialog.h b/gtk2_ardour/plugin_setup_dialog.h index 8d07b62539..2b326b110b 100644 --- a/gtk2_ardour/plugin_setup_dialog.h +++ b/gtk2_ardour/plugin_setup_dialog.h @@ -22,7 +22,9 @@ #include "ardour/plugin_insert.h" #include "ardour/route.h" -#include "ardour_dropdown.h" +#include "widgets/ardour_button.h" +#include "widgets/ardour_dropdown.h" + #include "ardour_dialog.h" class PluginSetupDialog : public ArdourDialog @@ -46,9 +48,9 @@ private: boost::shared_ptr _route; boost::shared_ptr _pi; - ArdourDropdown _out_presets; - ArdourButton _keep_mapping; - ArdourButton _fan_out; + ArdourWidgets::ArdourDropdown _out_presets; + ArdourWidgets::ArdourButton _keep_mapping; + ArdourWidgets::ArdourButton _fan_out; ARDOUR::ChanCount _cur_inputs; ARDOUR::ChanCount _cur_outputs; }; diff --git a/gtk2_ardour/plugin_ui.cc b/gtk2_ardour/plugin_ui.cc index 7314eb0042..32e7fb18c9 100644 --- a/gtk2_ardour/plugin_ui.cc +++ b/gtk2_ardour/plugin_ui.cc @@ -30,15 +30,17 @@ #include "pbd/xml++.h" #include "pbd/failed_constructor.h" -#include -#include -#include -#include -#include -#include -#include -#include -#include +#include "gtkmm/widget.h" +#include "gtkmm/box.h" +#include "gtkmm2ext/click_box.h" +#include "gtkmm2ext/fastmeter.h" +#include "gtkmm2ext/barcontroller.h" +#include "gtkmm2ext/utils.h" +#include "gtkmm2ext/doi.h" +#include "gtkmm2ext/slider_controller.h" +#include "gtkmm2ext/application.h" + +#include "widgets/tooltips.h" #include "ardour/session.h" #include "ardour/plugin.h" @@ -73,13 +75,13 @@ #include "latency_gui.h" #include "plugin_eq_gui.h" #include "new_plugin_preset_dialog.h" -#include "tooltips.h" #include "pbd/i18n.h" using namespace std; using namespace ARDOUR; using namespace ARDOUR_UI_UTILS; +using namespace ArdourWidgets; using namespace PBD; using namespace Gtkmm2ext; using namespace Gtk; diff --git a/gtk2_ardour/plugin_ui.h b/gtk2_ardour/plugin_ui.h index 860772c8c4..b7c6866867 100644 --- a/gtk2_ardour/plugin_ui.h +++ b/gtk2_ardour/plugin_ui.h @@ -48,9 +48,10 @@ #include "ardour/plugin.h" #include "ardour/variant.h" -#include "ardour_button.h" -#include "ardour_dropdown.h" -#include "ardour_spinner.h" +#include "widgets/ardour_button.h" +#include "widgets/ardour_dropdown.h" +#include "widgets/ardour_spinner.h" + #include "ardour_window.h" #include "automation_controller.h" @@ -117,21 +118,21 @@ protected: /* UI elements that can subclasses can add to their widgets */ /** a ComboBoxText which lists presets and manages their selection */ - ArdourDropdown _preset_combo; + ArdourWidgets::ArdourDropdown _preset_combo; /** a label which has a * in if the current settings are different from the preset being shown */ Gtk::Label _preset_modified; /** a button to add a preset */ - ArdourButton add_button; + ArdourWidgets::ArdourButton add_button; /** a button to save the current settings as a new user preset */ - ArdourButton save_button; + ArdourWidgets::ArdourButton save_button; /** a button to delete the current preset (if it is a user one) */ - ArdourButton delete_button; + ArdourWidgets::ArdourButton delete_button; /** a button to delete the reset the plugin params */ - ArdourButton reset_button; + ArdourWidgets::ArdourButton reset_button; /** a button to bypass the plugin */ - ArdourButton bypass_button; + ArdourWidgets::ArdourButton bypass_button; /** and self-explaining button :) */ - ArdourButton pin_management_button; + ArdourWidgets::ArdourButton pin_management_button; /** a button to acquire keyboard focus */ Gtk::EventBox focus_button; /** an expander containing the plugin description */ @@ -139,15 +140,15 @@ protected: /** an expander containing the plugin analysis graph */ Gtk::Expander plugin_analysis_expander; /** a button which, when clicked, opens the latency GUI */ - ArdourButton latency_button; + ArdourWidgets::ArdourButton latency_button; /** a button which sets all controls' automation setting to Manual */ - ArdourButton automation_manual_all_button; + ArdourWidgets::ArdourButton automation_manual_all_button; /** a button which sets all controls' automation setting to Play */ - ArdourButton automation_play_all_button; + ArdourWidgets::ArdourButton automation_play_all_button; /** a button which sets all controls' automation setting to Write */ - ArdourButton automation_write_all_button; + ArdourWidgets::ArdourButton automation_write_all_button; /** a button which sets all controls' automation setting to Touch */ - ArdourButton automation_touch_all_button; + ArdourWidgets::ArdourButton automation_touch_all_button; void set_latency_label (); @@ -227,12 +228,12 @@ private: boost::shared_ptr scale_points; boost::shared_ptr controller; - ArdourButton automate_button; + ArdourWidgets::ArdourButton automate_button; Gtk::Label label; - ArdourDropdown* combo; + ArdourWidgets::ArdourDropdown* combo; Gtkmm2ext::ClickBox* clickbox; Gtk::FileChooserButton* file_button; - ArdourSpinner* spin_box; + ArdourWidgets::ArdourSpinner* spin_box; bool button; bool update_pending; diff --git a/gtk2_ardour/processor_box.cc b/gtk2_ardour/processor_box.cc index 876165e5d3..a3d1833e34 100644 --- a/gtk2_ardour/processor_box.cc +++ b/gtk2_ardour/processor_box.cc @@ -34,13 +34,15 @@ #include -#include +#include "gtkmm2ext/gtk_ui.h" #include "gtkmm2ext/menu_elems.h" -#include -#include -#include -#include -#include +#include "gtkmm2ext/utils.h" +#include "gtkmm2ext/choice.h" +#include "gtkmm2ext/utils.h" +#include "gtkmm2ext/doi.h" +#include "gtkmm2ext/rgb_macros.h" + +#include "widgets/tooltips.h" #include "ardour/amp.h" #include "ardour/audio_track.h" @@ -84,7 +86,6 @@ #include "script_selector.h" #include "send_ui.h" #include "timers.h" -#include "tooltips.h" #include "new_plugin_preset_dialog.h" #include "pbd/i18n.h" @@ -103,6 +104,7 @@ using namespace PBD; using namespace Gtk; using namespace Glib; using namespace Gtkmm2ext; +using namespace ArdourWidgets; ProcessorBox* ProcessorBox::_current_processor_box = 0; RefPtr ProcessorBox::paste_action; @@ -516,10 +518,10 @@ ProcessorEntry::setup_tooltip () } if (pi->plugin()->has_editor()) { - ARDOUR_UI_UTILS::set_tooltip (_button, + set_tooltip (_button, string_compose (_("%1\nDouble-click to show GUI.\n%2+double-click to show generic GUI.%3"), name (Wide), Keyboard::secondary_modifier_name (), postfix)); } else { - ARDOUR_UI_UTILS::set_tooltip (_button, + set_tooltip (_button, string_compose (_("%1\nDouble-click to show generic GUI.%2"), name (Wide), postfix)); } return; @@ -533,14 +535,14 @@ ProcessorEntry::setup_tooltip () if ((send = boost::dynamic_pointer_cast (_processor)) != 0 && !boost::dynamic_pointer_cast(_processor)) { if (send->remove_on_disconnect ()) { - ARDOUR_UI_UTILS::set_tooltip (_button, string_compose ("> %1\nThis (sidechain) send will be removed when disconnected.", _processor->name())); + set_tooltip (_button, string_compose ("> %1\nThis (sidechain) send will be removed when disconnected.", _processor->name())); } else { - ARDOUR_UI_UTILS::set_tooltip (_button, string_compose ("> %1", _processor->name())); + set_tooltip (_button, string_compose ("> %1", _processor->name())); } return; } } - ARDOUR_UI_UTILS::set_tooltip (_button, string_compose ("%1", name (Wide))); + set_tooltip (_button, string_compose ("%1", name (Wide))); } string @@ -880,7 +882,7 @@ ProcessorEntry::Control::set_tooltip () std::string tt = _name + ": " + ARDOUR::value_as_string (c->desc(), c->get_value ()); string sm = Gtkmm2ext::markup_escape_text (tt); _slider_persistant_tooltip.set_tip (sm); - ARDOUR_UI_UTILS::set_tooltip (_button, sm); + ArdourWidgets::set_tooltip (_button, sm); } void @@ -1556,10 +1558,10 @@ ProcessorEntry::PluginDisplay::PluginDisplay (ProcessorEntry& e, boost::shared_p std::string postfix = string_compose(_("\n%1+double-click to toggle inline-display"), Keyboard::tertiary_modifier_name ()); if (_plug->has_editor()) { - ARDOUR_UI_UTILS::set_tooltip (*this, + set_tooltip (*this, string_compose (_("%1\nDouble-click to show GUI.\n%2+double-click to show generic GUI.%3"), e.name (Wide), Keyboard::primary_modifier_name (), postfix)); } else { - ARDOUR_UI_UTILS::set_tooltip (*this, + set_tooltip (*this, string_compose (_("%1\nDouble-click to show generic GUI.%2"), e.name (Wide), postfix)); } } @@ -1856,7 +1858,7 @@ ProcessorBox::ProcessorBox (ARDOUR::Session* sess, boost::function #include -#include -#include -#include -#include -#include +#include "gtkmm2ext/utils.h" +#include "gtkmm2ext/slider_controller.h" +#include "gtkmm2ext/gtk_ui.h" +#include "gtkmm2ext/paths_dialog.h" +#include "gtkmm2ext/window_title.h" #include "pbd/fpu.h" #include "pbd/cpus.h" @@ -54,6 +54,7 @@ #include "control_protocol/control_protocol.h" #include "canvas/wave_view.h" +#include "widgets/tooltips.h" #include "ardour_dialog.h" #include "ardour_ui.h" @@ -65,7 +66,6 @@ #include "midi_tracer.h" #include "rc_option_editor.h" #include "sfdb_ui.h" -#include "tooltips.h" #include "ui_config.h" #include "utils.h" @@ -75,6 +75,7 @@ using namespace Gtkmm2ext; using namespace PBD; using namespace ARDOUR; using namespace ARDOUR_UI_UTILS; +using namespace ArdourWidgets; class ClickOptions : public OptionEditorMiniPage { diff --git a/gtk2_ardour/region_editor.cc b/gtk2_ardour/region_editor.cc index b480750810..156e89378b 100644 --- a/gtk2_ardour/region_editor.cc +++ b/gtk2_ardour/region_editor.cc @@ -24,6 +24,8 @@ #include "pbd/memento_command.h" #include "pbd/stateful_diff_command.h" +#include "widgets/tooltips.h" + #include "ardour/region.h" #include "ardour/session.h" #include "ardour/source.h" @@ -34,7 +36,6 @@ #include "gui_thread.h" #include "region_editor.h" #include "public_editor.h" -#include "tooltips.h" #include "pbd/i18n.h" @@ -42,7 +43,6 @@ using namespace ARDOUR; using namespace PBD; using namespace std; using namespace Gtkmm2ext; -using namespace ARDOUR_UI_UTILS; RegionEditor::RegionEditor (Session* s, boost::shared_ptr r) : ArdourDialog (_("Region")) @@ -78,7 +78,7 @@ RegionEditor::RegionEditor (Session* s, boost::shared_ptr r) sync_offset_absolute_clock.set_session (_session); start_clock.set_session (_session); - set_tooltip (audition_button, _("audition this region")); + ArdourWidgets::set_tooltip (audition_button, _("audition this region")); audition_button.unset_flags (Gtk::CAN_FOCUS); diff --git a/gtk2_ardour/route_time_axis.cc b/gtk2_ardour/route_time_axis.cc index c1fa5e26ba..62a68557ce 100644 --- a/gtk2_ardour/route_time_axis.cc +++ b/gtk2_ardour/route_time_axis.cc @@ -35,12 +35,15 @@ #include "pbd/enumwriter.h" #include "pbd/stateful_diff_command.h" -#include -#include -#include -#include -#include -#include +#include "gtkmm/menu.h" +#include "gtkmm/menuitem.h" +#include "gtkmm2ext/gtk_ui.h" +#include "gtkmm2ext/selector.h" +#include "gtkmm2ext/bindable_button.h" +#include "gtkmm2ext/utils.h" + +#include "widgets/ardour_button.h" +#include "widgets/tooltips.h" #include "ardour/amp.h" #include "ardour/meter.h" @@ -58,7 +61,6 @@ #include "canvas/debug.h" #include "ardour_ui.h" -#include "ardour_button.h" #include "audio_streamview.h" #include "debug.h" #include "enums_convert.h" @@ -77,7 +79,6 @@ #include "rgb_macros.h" #include "selection.h" #include "streamview.h" -#include "tooltips.h" #include "ui_config.h" #include "utils.h" #include "route_group_menu.h" @@ -87,7 +88,7 @@ #include "pbd/i18n.h" using namespace ARDOUR; -using namespace ARDOUR_UI_UTILS; +using namespace ArdourWidgets; using namespace PBD; using namespace Gtkmm2ext; using namespace Gtk; @@ -1080,10 +1081,10 @@ RouteTimeAxisView::set_height (uint32_t h, TrackHeightMode m) void RouteTimeAxisView::route_color_changed () { + using namespace ARDOUR_UI_UTILS; if (_view) { _view->apply_color (color(), StreamView::RegionColor); } - number_label.set_fixed_colors (gdk_color_to_rgba (color()), gdk_color_to_rgba (color())); } diff --git a/gtk2_ardour/route_time_axis.h b/gtk2_ardour/route_time_axis.h index 2b069ff519..50070c537a 100644 --- a/gtk2_ardour/route_time_axis.h +++ b/gtk2_ardour/route_time_axis.h @@ -35,10 +35,11 @@ #include #include +#include "widgets/ardour_button.h" + #include "ardour/playlist.h" #include "ardour/types.h" -#include "ardour_button.h" #include "ardour_dialog.h" #include "route_ui.h" #include "enums.h" @@ -246,10 +247,10 @@ protected: Gtk::HBox other_button_hbox; Gtk::Table button_table; - ArdourButton route_group_button; - ArdourButton playlist_button; - ArdourButton automation_button; - ArdourButton number_label; + ArdourWidgets::ArdourButton route_group_button; + ArdourWidgets::ArdourButton playlist_button; + ArdourWidgets::ArdourButton automation_button; + ArdourWidgets::ArdourButton number_label; Gtk::Menu subplugin_menu; Gtk::Menu* automation_action_menu; diff --git a/gtk2_ardour/route_ui.cc b/gtk2_ardour/route_ui.cc index 817594e1b7..92fdbd3892 100644 --- a/gtk2_ardour/route_ui.cc +++ b/gtk2_ardour/route_ui.cc @@ -20,13 +20,15 @@ #include #include -#include -#include -#include -#include -#include -#include -#include +#include "gtkmm2ext/gtk_ui.h" +#include "gtkmm2ext/choice.h" +#include "gtkmm2ext/doi.h" +#include "gtkmm2ext/bindable_button.h" +#include "gtkmm2ext/barcontroller.h" +#include "gtkmm2ext/gtk_ui.h" +#include "gtkmm2ext/utils.h" + +#include "widgets/ardour_button.h" #include "pbd/memento_command.h" #include "pbd/stacktrace.h" @@ -53,7 +55,7 @@ #include "ardour/session.h" #include "ardour/template_utils.h" -#include "ardour_button.h" + #include "ardour_dialog.h" #include "ardour_ui.h" #include "automation_time_axis.h" @@ -79,6 +81,7 @@ using namespace Gtk; using namespace Gtkmm2ext; using namespace ARDOUR; using namespace ARDOUR_UI_UTILS; +using namespace ArdourWidgets; using namespace PBD; using namespace std; diff --git a/gtk2_ardour/route_ui.h b/gtk2_ardour/route_ui.h index 9ec4d56313..d4f15f0c7b 100644 --- a/gtk2_ardour/route_ui.h +++ b/gtk2_ardour/route_ui.h @@ -55,7 +55,10 @@ namespace Gtk { class Widget; } -class ArdourButton; +namespace ArdourWidgets { + class ArdourButton; +} + class ArdourWindow; class IOSelectorWindow; class ControlSlaveUI; @@ -114,17 +117,17 @@ public: bool multiple_solo_change; Gtk::HBox _invert_button_box; - ArdourButton* mute_button; - ArdourButton* solo_button; - ArdourButton* rec_enable_button; /* audio tracks */ - ArdourButton* show_sends_button; /* busses */ - ArdourButton* monitor_input_button; - ArdourButton* monitor_disk_button; + ArdourWidgets::ArdourButton* mute_button; + ArdourWidgets::ArdourButton* solo_button; + ArdourWidgets::ArdourButton* rec_enable_button; /* audio tracks */ + ArdourWidgets::ArdourButton* show_sends_button; /* busses */ + ArdourWidgets::ArdourButton* monitor_input_button; + ArdourWidgets::ArdourButton* monitor_disk_button; Glib::RefPtr solo_safe_pixbuf; - ArdourButton* solo_safe_led; - ArdourButton* solo_isolated_led; + ArdourWidgets::ArdourButton* solo_safe_led; + ArdourWidgets::ArdourButton* solo_isolated_led; Gtk::Label monitor_input_button_label; @@ -329,7 +332,7 @@ private: bool invert_release (GdkEventButton *, uint32_t i); int _i_am_the_modifier; - std::vector _invert_buttons; + std::vector _invert_buttons; Gtk::Menu* _invert_menu; StripableColorDialog _color_picker; diff --git a/gtk2_ardour/session_dialog.cc b/gtk2_ardour/session_dialog.cc index e110316693..7490b48b8f 100644 --- a/gtk2_ardour/session_dialog.cc +++ b/gtk2_ardour/session_dialog.cc @@ -43,6 +43,8 @@ #include "gtkmm2ext/utils.h" #include "gtkmm2ext/keyboard.h" +#include "widgets/tooltips.h" + #include "ardour/audioengine.h" #include "ardour/filesystem_paths.h" #include "ardour/recent_sessions.h" @@ -56,7 +58,6 @@ #include "opts.h" #include "engine_dialog.h" #include "pbd/i18n.h" -#include "tooltips.h" #include "ui_config.h" #include "utils.h" @@ -66,6 +67,7 @@ using namespace Gdk; using namespace Glib; using namespace PBD; using namespace ARDOUR; +using namespace ArdourWidgets; using namespace ARDOUR_UI_UTILS; SessionDialog::SessionDialog (bool require_new, const std::string& session_name, const std::string& session_path, const std::string& template_name, bool cancel_not_quit) diff --git a/gtk2_ardour/shuttle_control.cc b/gtk2_ardour/shuttle_control.cc index d4936098d0..98249bc62b 100644 --- a/gtk2_ardour/shuttle_control.cc +++ b/gtk2_ardour/shuttle_control.cc @@ -36,17 +36,18 @@ #include "canvas/utils.h" #include "canvas/colors.h" +#include "widgets/tooltips.h" + #include "actions.h" #include "rgb_macros.h" #include "shuttle_control.h" -#include "tooltips.h" #include "pbd/i18n.h" using namespace Gtk; using namespace Gtkmm2ext; using namespace ARDOUR; -using namespace ARDOUR_UI_UTILS; +using namespace ArdourWidgets; using std::min; using std::max; diff --git a/gtk2_ardour/shuttle_control.h b/gtk2_ardour/shuttle_control.h index f7d3bd3601..1b6cce5870 100644 --- a/gtk2_ardour/shuttle_control.h +++ b/gtk2_ardour/shuttle_control.h @@ -29,7 +29,7 @@ #include "ardour/session_handle.h" #include "ardour/types.h" -#include "ardour_button.h" +#include "widgets/ardour_button.h" namespace Gtk { class Menu; @@ -60,7 +60,7 @@ public: boost::shared_ptr controllable() const { return _controllable; } void set_colors (); - ArdourButton* info_button () { return &_info_button; } + ArdourWidgets::ArdourButton* info_button () { return &_info_button; } protected: bool _hovering; @@ -75,7 +75,7 @@ protected: cairo_pattern_t* shine_pattern; ARDOUR::microseconds_t last_shuttle_request; PBD::ScopedConnection parameter_connection; - ArdourButton _info_button; + ArdourWidgets::ArdourButton _info_button; Gtk::Menu* shuttle_unit_menu; Gtk::Menu* shuttle_style_menu; Gtk::Menu* shuttle_context_menu; diff --git a/gtk2_ardour/step_entry.cc b/gtk2_ardour/step_entry.cc index 639b8b7317..4184068eb4 100644 --- a/gtk2_ardour/step_entry.cc +++ b/gtk2_ardour/step_entry.cc @@ -24,13 +24,14 @@ #include "gtkmm2ext/actions.h" #include "gtkmm2ext/keyboard.h" +#include "widgets/tooltips.h" + #include "ardour/filesystem_paths.h" #include "midi_channel_selector.h" #include "midi_time_axis.h" #include "step_editor.h" #include "step_entry.h" -#include "tooltips.h" #include "utils.h" #include "pbd/i18n.h" @@ -42,6 +43,7 @@ using namespace Gtkmm2ext; using namespace PBD; using namespace ARDOUR; using namespace ARDOUR_UI_UTILS; +using namespace ArdourWidgets; static void _note_off_event_handler (GtkWidget* /*widget*/, int note, gpointer arg) diff --git a/gtk2_ardour/time_axis_view.cc b/gtk2_ardour/time_axis_view.cc index 05d93f696c..403ab88eb6 100644 --- a/gtk2_ardour/time_axis_view.cc +++ b/gtk2_ardour/time_axis_view.cc @@ -39,6 +39,8 @@ #include "canvas/utils.h" #include "canvas/colors.h" +#include "widgets/tooltips.h" + #include "ardour/profile.h" #include "ardour_dialog.h" @@ -55,7 +57,6 @@ #include "streamview.h" #include "editor_drag.h" #include "editor.h" -#include "tooltips.h" #include "ui_config.h" #include "pbd/i18n.h" @@ -64,10 +65,10 @@ using namespace std; using namespace Gtk; using namespace Gdk; using namespace ARDOUR; -using namespace ARDOUR_UI_UTILS; using namespace PBD; using namespace Editing; using namespace ArdourCanvas; +using namespace ArdourWidgets; using Gtkmm2ext::Keyboard; #define TOP_LEVEL_WIDGET controls_ebox diff --git a/gtk2_ardour/time_info_box.h b/gtk2_ardour/time_info_box.h index 14dff4e36b..b705291a35 100644 --- a/gtk2_ardour/time_info_box.h +++ b/gtk2_ardour/time_info_box.h @@ -31,8 +31,6 @@ #include "ardour/ardour.h" #include "ardour/session_handle.h" -#include "ardour_button.h" - namespace ARDOUR { class Session; class Location; diff --git a/gtk2_ardour/tooltips.cc b/gtk2_ardour/tooltips.cc deleted file mode 100644 index 5860412aca..0000000000 --- a/gtk2_ardour/tooltips.cc +++ /dev/null @@ -1,41 +0,0 @@ -/* - Copyright (C) 2014 Paul Davis - - This program is free software; you can redistribute it and/or modify - it under the terms of the GNU General Public License as published by - the Free Software Foundation; either version 2 of the License, or - (at your option) any later version. - - This program is distributed in the hope that it will be useful, - but WITHOUT ANY WARRANTY; without even the implied warranty of - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - GNU General Public License for more details. - - You should have received a copy of the GNU General Public License - along with this program; if not, write to the Free Software - Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. - -*/ - -#include "tooltips.h" - -#include "gtkmm2ext/gtk_ui.h" - -namespace ARDOUR_UI_UTILS { - -void -set_tooltip (Gtk::Widget& w, const std::string& text) { - Gtkmm2ext::UI::instance()->set_tip(w, text); -} - -void -set_tooltip (Gtk::Widget* w, const std::string& text) { - Gtkmm2ext::UI::instance()->set_tip(*w, text); -} - -void -set_tooltip (Gtk::Widget* w, const std::string& text, const std::string& help_text) { - Gtkmm2ext::UI::instance()->set_tip(w, text.c_str(), help_text.c_str()); -} - -} // ARDOUR_UI_UTILS diff --git a/gtk2_ardour/tooltips.h b/gtk2_ardour/tooltips.h deleted file mode 100644 index 715fd02ef6..0000000000 --- a/gtk2_ardour/tooltips.h +++ /dev/null @@ -1,41 +0,0 @@ -/* - Copyright (C) 2014 Paul Davis - - This program is free software; you can redistribute it and/or modify - it under the terms of the GNU General Public License as published by - the Free Software Foundation; either version 2 of the License, or - (at your option) any later version. - - This program is distributed in the hope that it will be useful, - but WITHOUT ANY WARRANTY; without even the implied warranty of - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - GNU General Public License for more details. - - You should have received a copy of the GNU General Public License - along with this program; if not, write to the Free Software - Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. - -*/ - -#ifndef UI_TOOLTIPS_H -#define UI_TOOLTIPS_H - -#include - -namespace Gtk { - class Widget; -} - -// Reduce these down to just one function -namespace ARDOUR_UI_UTILS { - -void set_tooltip (Gtk::Widget& w, const std::string& text); - -void set_tooltip (Gtk::Widget* w, const std::string& text); - -void set_tooltip (Gtk::Widget* w, const std::string& text, const std::string& help_text); - -} - -#endif // UI_TOOLTIPS_H - diff --git a/gtk2_ardour/ui_config.cc b/gtk2_ardour/ui_config.cc index 8b1d5a8c27..a5f80dc741 100644 --- a/gtk2_ardour/ui_config.cc +++ b/gtk2_ardour/ui_config.cc @@ -72,6 +72,7 @@ UIConfiguration& UIConfiguration::instance () { static UIConfiguration s_instance; + _instance = &s_instance; return s_instance; } diff --git a/gtk2_ardour/ui_config.h b/gtk2_ardour/ui_config.h index d5801f5545..159884a14f 100644 --- a/gtk2_ardour/ui_config.h +++ b/gtk2_ardour/ui_config.h @@ -35,10 +35,11 @@ #include "pbd/configuration_variable.h" #include "canvas/colors.h" +#include "widgets/ui_config.h" #include "utils.h" -class UIConfiguration : public PBD::Stateful +class UIConfiguration : public ArdourWidgets::UIConfigurationBase { private: UIConfiguration(); @@ -87,14 +88,9 @@ public: static std::string color_to_hex_string (ArdourCanvas::Color c); static std::string color_to_hex_string_no_alpha (ArdourCanvas::Color c); - sigc::signal ColorsChanged; - void reset_dpi (); - float get_ui_scale (); - sigc::signal DPIReset; - sigc::signal ParameterChanged; void map_parameters (boost::function&); diff --git a/gtk2_ardour/vca_master_strip.cc b/gtk2_ardour/vca_master_strip.cc index 4f592334c7..eea92eec45 100644 --- a/gtk2_ardour/vca_master_strip.cc +++ b/gtk2_ardour/vca_master_strip.cc @@ -27,12 +27,12 @@ #include "gtkmm2ext/doi.h" #include "gtkmm2ext/keyboard.h" +#include "widgets/tooltips.h" #include "ardour_dialog.h" #include "floating_text_entry.h" #include "gui_thread.h" #include "mixer_ui.h" -#include "tooltips.h" #include "ui_config.h" #include "utils.h" #include "vca_master_strip.h" @@ -40,7 +40,7 @@ #include "pbd/i18n.h" using namespace ARDOUR; -using namespace ARDOUR_UI_UTILS; +using namespace ArdourWidgets; using namespace Gtkmm2ext; using namespace Gtk; using namespace PBD; @@ -59,7 +59,7 @@ VCAMasterStrip::VCAMasterStrip (Session* s, boost::shared_ptr v) /* set color for the VCA, if not already done. */ if (!_vca->presentation_info().color_set()) { - _vca->presentation_info().set_color (gdk_color_to_rgba (unique_random_color())); + _vca->presentation_info().set_color (ARDOUR_UI_UTILS::gdk_color_to_rgba (unique_random_color())); } control_slave_ui.set_stripable (boost::dynamic_pointer_cast (v)); @@ -521,7 +521,7 @@ VCAMasterStrip::drop_all_slaves () Gdk::Color VCAMasterStrip::color () const { - return gdk_color_from_rgba (_vca->presentation_info().color ()); + return ARDOUR_UI_UTILS::gdk_color_from_rgba (_vca->presentation_info().color ()); } string diff --git a/gtk2_ardour/vca_master_strip.h b/gtk2_ardour/vca_master_strip.h index 232962d2cd..12120b7ecc 100644 --- a/gtk2_ardour/vca_master_strip.h +++ b/gtk2_ardour/vca_master_strip.h @@ -21,11 +21,12 @@ #include -#include -#include -#include +#include "gtkmm/box.h" +#include "gtkmm/menuitem.h" +#include "gtkmm/colorselection.h" + +#include "widgets/ardour_button.h" -#include "ardour_button.h" #include "axis_view.h" #include "control_slave_ui.h" #include "gain_meter.h" @@ -61,22 +62,22 @@ private: boost::shared_ptr _vca; GainMeter gain_meter; - Gtk::Frame global_frame; - Gtk::VBox global_vpacker; - Gtk::HBox top_padding; - Gtk::HBox bottom_padding; - Gtk::HBox solo_mute_box; - ArdourButton width_button; - ArdourButton color_button; - ArdourButton hide_button; - ArdourButton number_label; - ArdourButton solo_button; - ArdourButton mute_button; - Gtk::Menu* context_menu; - Gtk::MessageDialog* delete_dialog; - ArdourButton vertical_button; - ControlSlaveUI control_slave_ui; - PBD::ScopedConnectionList vca_connections; + Gtk::Frame global_frame; + Gtk::VBox global_vpacker; + Gtk::HBox top_padding; + Gtk::HBox bottom_padding; + Gtk::HBox solo_mute_box; + ArdourWidgets::ArdourButton width_button; + ArdourWidgets::ArdourButton color_button; + ArdourWidgets::ArdourButton hide_button; + ArdourWidgets::ArdourButton number_label; + ArdourWidgets::ArdourButton solo_button; + ArdourWidgets::ArdourButton mute_button; + Gtk::Menu* context_menu; + Gtk::MessageDialog* delete_dialog; + ArdourWidgets::ArdourButton vertical_button; + ControlSlaveUI control_slave_ui; + PBD::ScopedConnectionList vca_connections; void spill (); void spill_change (boost::shared_ptr); diff --git a/gtk2_ardour/vca_time_axis.cc b/gtk2_ardour/vca_time_axis.cc index f5eb1be7d7..887a666934 100644 --- a/gtk2_ardour/vca_time_axis.cc +++ b/gtk2_ardour/vca_time_axis.cc @@ -28,18 +28,18 @@ #include "ardour/vca.h" #include "gtkmm2ext/doi.h" -#include +#include "gtkmm2ext/utils.h" +#include "widgets/tooltips.h" #include "gui_thread.h" #include "public_editor.h" -#include "tooltips.h" #include "ui_config.h" #include "vca_time_axis.h" #include "pbd/i18n.h" using namespace ARDOUR; -using namespace ARDOUR_UI_UTILS; +using namespace ArdourWidgets; using namespace Gtk; using namespace Gtkmm2ext; using namespace PBD; @@ -334,7 +334,7 @@ VCATimeAxisView::stripable () const Gdk::Color VCATimeAxisView::color () const { - return gdk_color_from_rgb (_vca->presentation_info().color ()); + return ARDOUR_UI_UTILS::gdk_color_from_rgb (_vca->presentation_info().color ()); } void diff --git a/gtk2_ardour/vca_time_axis.h b/gtk2_ardour/vca_time_axis.h index f2d2e31ccb..9620310237 100644 --- a/gtk2_ardour/vca_time_axis.h +++ b/gtk2_ardour/vca_time_axis.h @@ -20,7 +20,8 @@ #ifndef __ardour_vca_time_axis_h__ #define __ardour_vca_time_axis_h__ -#include "ardour_button.h" +#include "widgets/ardour_button.h" + #include "stripable_time_axis.h" #include "gain_meter.h" @@ -57,13 +58,13 @@ public: protected: boost::shared_ptr _vca; - ArdourButton solo_button; - ArdourButton mute_button; - ArdourButton automation_button; - ArdourButton drop_button; - ArdourButton number_label; - GainMeterBase gain_meter; - PBD::ScopedConnectionList vca_connections; + ArdourWidgets::ArdourButton solo_button; + ArdourWidgets::ArdourButton mute_button; + ArdourWidgets::ArdourButton automation_button; + ArdourWidgets::ArdourButton drop_button; + ArdourWidgets::ArdourButton number_label; + GainMeterBase gain_meter; + PBD::ScopedConnectionList vca_connections; void create_gain_automation_child (const Evoral::Parameter &, bool); void create_trim_automation_child (const Evoral::Parameter &, bool) {} diff --git a/gtk2_ardour/wscript b/gtk2_ardour/wscript index 92cb059379..123cf1e994 100644 --- a/gtk2_ardour/wscript +++ b/gtk2_ardour/wscript @@ -31,13 +31,8 @@ gtk2_ardour_sources = [ 'add_route_dialog.cc', 'ambiguous_file_dialog.cc', 'analysis_window.cc', - 'ardour_button.cc', 'ardour_dialog.cc', - 'ardour_display.cc', - 'ardour_dropdown.cc', 'ardour_http.cc', - 'ardour_knob.cc', - 'ardour_spinner.cc', 'ardour_ui.cc', 'ardour_ui2.cc', 'ardour_ui_dependents.cc', @@ -260,7 +255,6 @@ gtk2_ardour_sources = [ 'time_info_box.cc', 'time_selection.cc', 'timers.cc', - 'tooltips.cc', 'track_selection.cc', 'track_view_list.cc', 'transform_dialog.cc', @@ -489,6 +483,7 @@ def build(bld): 'libmidipp', 'libgtkmm2ext', 'libcanvas', + 'libwidgets', 'libptformat', ] obj.defines = [ @@ -510,36 +505,36 @@ def build(bld): obj.defines += [ 'LXVST_SUPPORT' ] obj.use += [ 'X11' ] - # Tool to test libcanvas - if re.search ("linux", sys.platform) != None and bld.env['CANVASTESTUI']: - obj = bld (features = 'cxx c cxxprogram') - obj.install_path = None - obj.source = list(gtk2_ardour_sources) - obj.source = [ 'ardour_button.cc', 'ui_config.cc', 'tooltips.cc' ] - obj.target = 'canvas_test' - obj.includes = ['.', '../libs'] - obj.ldflags = ['-no-undefined'] - obj.use = [ - 'libpbd', - 'libardour', - 'libardour_cp', - 'libtimecode', - 'libmidipp', - 'libgtkmm2ext', - 'libcanvas', - 'libptformat', - ] - obj.defines = [ - 'NOMAIN', - 'PACKAGE="' + I18N_PACKAGE + '"', - 'DATA_DIR="' + os.path.normpath(bld.env['DATADIR']) + '"', - 'CONFIG_DIR="' + os.path.normpath(bld.env['SYSCONFDIR']) + '"', - 'LOCALEDIR="' + os.path.normpath(bld.env['LOCALEDIR']) + '"', - ] - obj.linkflags = '' - obj.uselib = 'UUID FLAC FONTCONFIG GLIBMM GTHREAD GTK OGG CURL DL GTKMM CANVAS FFTW3F LO TAGLIB XML ' - # obj.source += [ 'canvas_test.cc', ] - obj.source += [ 'toolbar_test.cc', 'enums.cc'] +# # Tool to test libcanvas +# if re.search ("linux", sys.platform) != None and bld.env['CANVASTESTUI']: +# obj = bld (features = 'cxx c cxxprogram') +# obj.install_path = None +# obj.source = list(gtk2_ardour_sources) +# obj.source = [ 'ardour_button.cc', 'ui_config.cc', 'tooltips.cc' ] +# obj.target = 'canvas_test' +# obj.includes = ['.', '../libs'] +# obj.ldflags = ['-no-undefined'] +# obj.use = [ +# 'libpbd', +# 'libardour', +# 'libardour_cp', +# 'libtimecode', +# 'libmidipp', +# 'libgtkmm2ext', +# 'libcanvas', +# 'libptformat', +# ] +# obj.defines = [ +# 'NOMAIN', +# 'PACKAGE="' + I18N_PACKAGE + '"', +# 'DATA_DIR="' + os.path.normpath(bld.env['DATADIR']) + '"', +# 'CONFIG_DIR="' + os.path.normpath(bld.env['SYSCONFDIR']) + '"', +# 'LOCALEDIR="' + os.path.normpath(bld.env['LOCALEDIR']) + '"', +# ] +# obj.linkflags = '' +# obj.uselib = 'UUID FLAC FONTCONFIG GLIBMM GTHREAD GTK OGG CURL DL GTKMM CANVAS FFTW3F LO TAGLIB XML ' +# # obj.source += [ 'canvas_test.cc', ] +# obj.source += [ 'toolbar_test.cc', 'enums.cc'] if bld.is_defined('WINDOWS_VST_SUPPORT') and bld.env['build_target'] != 'mingw': @@ -560,6 +555,7 @@ def build(bld): 'libgtk2_ardour', 'libgtkmm2ext', 'libcanvas', + 'libwidgets', 'libptformat', ] obj.target = 'ardour-' + str (bld.env['VERSION']) + '-vst.exe.so' @@ -605,6 +601,7 @@ def build(bld): 'libmidipp', 'libgtkmm2ext', 'libcanvas', + 'libwidgets', 'libptformat', ] diff --git a/libs/widgets/ardour_button.cc b/libs/widgets/ardour_button.cc new file mode 100644 index 0000000000..913e18bae8 --- /dev/null +++ b/libs/widgets/ardour_button.cc @@ -0,0 +1,1340 @@ +/* + Copyright (C) 2010 Paul Davis + + This program is free software; you can redistribute it and/or modify + it under the terms of the GNU General Public License as published by + the Free Software Foundation; either version 2 of the License, or + (at your option) any later version. + + This program is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU General Public License + along with this program; if not, write to the Free Software + Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. + +*/ + +#include +#include +#include + +#include + +#include "pbd/compose.h" +#include "pbd/controllable.h" +#include "pbd/error.h" +#include "pbd/stacktrace.h" + +#include "gtkmm2ext/utils.h" +#include "gtkmm2ext/rgb_macros.h" +#include "gtkmm2ext/gui_thread.h" + +#include "canvas/utils.h" +#include "canvas/colors.h" + +#include "widgets/ardour_button.h" +#include "widgets/tooltips.h" +#include "widgets/ui_config.h" + +#include "pbd/i18n.h" + +#define BASELINESTRETCH (1.25) +#define TRACKHEADERBTNW (3.10) + +using namespace Gtk; +using namespace Glib; +using namespace PBD; +using namespace ArdourWidgets; +using std::max; +using std::min; +using namespace std; + +ArdourButton::Element ArdourButton::default_elements = ArdourButton::Element (ArdourButton::Edge|ArdourButton::Body|ArdourButton::Text); +ArdourButton::Element ArdourButton::led_default_elements = ArdourButton::Element (ArdourButton::default_elements|ArdourButton::Indicator); +ArdourButton::Element ArdourButton::just_led_default_elements = ArdourButton::Element (ArdourButton::Edge|ArdourButton::Body|ArdourButton::Indicator); + +ArdourButton::ArdourButton (Element e) + : _sizing_text("") + , _markup (false) + , _elements (e) + , _icon (Gtkmm2ext::ArdourIcon::NoIcon) + , _icon_render_cb (0) + , _icon_render_cb_data (0) + , _tweaks (Tweaks (0)) + , _char_pixel_width (0) + , _char_pixel_height (0) + , _char_avg_pixel_width (0) + , _text_width (0) + , _text_height (0) + , _diameter (0) + , _corner_radius (3.5) + , _corner_mask (0xf) + , _angle(0) + , _xalign(.5) + , _yalign(.5) + , fill_inactive_color (0) + , fill_active_color (0) + , text_active_color(0) + , 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) + , _led_rect (0) + , _act_on_release (true) + , _led_left (false) + , _distinct_led_click (false) + , _hovering (false) + , _focused (false) + , _fixed_colors_set (false) + , _fallthrough_to_parent (false) + , _layout_ellipsize_width (-1) + , _ellipsis (Pango::ELLIPSIZE_NONE) + , _update_colors (true) + , _pattern_height (0) +{ + UIConfigurationBase::instance().ColorsChanged.connect (sigc::mem_fun (*this, &ArdourButton::color_handler)); + /* This is not provided by gtkmm */ + signal_grab_broken_event().connect (sigc::mem_fun (*this, &ArdourButton::on_grab_broken_event)); +} + +ArdourButton::ArdourButton (const std::string& str, Element e) + : _sizing_text("") + , _markup (false) + , _elements (e) + , _icon (Gtkmm2ext::ArdourIcon::NoIcon) + , _tweaks (Tweaks (0)) + , _char_pixel_width (0) + , _char_pixel_height (0) + , _char_avg_pixel_width (0) + , _text_width (0) + , _text_height (0) + , _diameter (0) + , _corner_radius (3.5) + , _corner_mask (0xf) + , _angle(0) + , _xalign(.5) + , _yalign(.5) + , fill_inactive_color (0) + , fill_active_color (0) + , text_active_color(0) + , 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) + , _led_rect (0) + , _act_on_release (true) + , _led_left (false) + , _distinct_led_click (false) + , _hovering (false) + , _focused (false) + , _fixed_colors_set (false) + , _fallthrough_to_parent (false) + , _layout_ellipsize_width (-1) + , _ellipsis (Pango::ELLIPSIZE_NONE) + , _update_colors (true) + , _pattern_height (0) +{ + set_text (str); + UIConfigurationBase::instance().ColorsChanged.connect (sigc::mem_fun (*this, &ArdourButton::color_handler)); + UIConfigurationBase::instance().DPIReset.connect (sigc::mem_fun (*this, &ArdourButton::on_name_changed)); + /* This is not provided by gtkmm */ + signal_grab_broken_event().connect (sigc::mem_fun (*this, &ArdourButton::on_grab_broken_event)); +} + +ArdourButton::~ArdourButton() +{ + delete _led_rect; + + if (convex_pattern) { + cairo_pattern_destroy (convex_pattern); + } + + if (concave_pattern) { + cairo_pattern_destroy (concave_pattern); + } + + if (led_inset_pattern) { + cairo_pattern_destroy (led_inset_pattern); + } +} + +void +ArdourButton::set_layout_font (const Pango::FontDescription& fd) +{ + ensure_layout (); + if (_layout) { + _layout->set_font_description (fd); + queue_resize (); + _char_pixel_width = 0; + _char_pixel_height = 0; + } +} + +void +ArdourButton::set_text_internal () { + assert (_layout); + if (_markup) { + _layout->set_markup (_text); + } else { + _layout->set_text (_text); + } +} + +void +ArdourButton::set_text (const std::string& str, bool markup) +{ + if (!(_elements & Text)) { + return; + } + if (_text == str && _markup == markup) { + return; + } + + _text = str; + _markup = markup; + if (!is_realized()) { + return; + } + ensure_layout (); + if (_layout && _layout->get_text() != _text) { + set_text_internal (); + /* on_size_request() will fill in _text_width/height + * so queue it even if _sizing_text != "" */ + queue_resize (); + } +} + +void +ArdourButton::set_sizing_text (const std::string& str) +{ + if (_sizing_text == str) { + return; + } + _sizing_text = str; + if (!is_realized()) { + return; + } + ensure_layout (); + if (_layout) { + queue_resize (); + } +} + +void +ArdourButton::set_angle (const double angle) +{ + _angle = angle; +} + +void +ArdourButton::set_alignment (const float xa, const float ya) +{ + _xalign = xa; + _yalign = ya; +} + + +/* TODO make this a dedicated function elsewhere. + * + * Option 1: + * virtual ArdourButton::render_vector_icon() + * ArdourIconButton::render_vector_icon + * + * Option 2: + * ARDOUR_UI_UTILS::render_vector_icon() + */ +void +ArdourButton::render (Cairo::RefPtr const& ctx, cairo_rectangle_t*) +{ + cairo_t* cr = ctx->cobj(); + + uint32_t text_color; + uint32_t led_color; + + const float corner_radius = std::max(2.f, _corner_radius * UIConfigurationBase::instance().get_ui_scale()); + + if (_update_colors) { + set_colors (); + } + if (get_height() != _pattern_height) { + build_patterns (); + } + + if ( active_state() == Gtkmm2ext::ExplicitActive ) { + text_color = text_active_color; + led_color = led_active_color; + } else { + text_color = text_inactive_color; + 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) { + case 0x1: /* upper left only */ + rounded_function = Gtkmm2ext::rounded_top_left_rectangle; + break; + case 0x2: /* upper right only */ + rounded_function = Gtkmm2ext::rounded_top_right_rectangle; + break; + case 0x3: /* upper only */ + rounded_function = Gtkmm2ext::rounded_top_rectangle; + break; + /* should really have functions for lower right, lower left, + lower only, but for now, we don't + */ + default: + rounded_function = Gtkmm2ext::rounded_rectangle; + } + + // draw edge (filling a rect underneath, rather than stroking a border on top, allows the corners to be lighter-weight. + if ((_elements & (Body|Edge)) == (Body|Edge)) { + rounded_function (cr, 0, 0, get_width(), get_height(), corner_radius + 1.5); + cairo_set_source_rgba (cr, 0, 0, 0, 1); + cairo_fill(cr); + } + + // background fill + if ((_elements & Body)==Body) { + rounded_function (cr, 1, 1, get_width() - 2, get_height() - 2, corner_radius); + if (active_state() == Gtkmm2ext::ImplicitActive && !((_elements & Indicator)==Indicator)) { + ArdourCanvas::set_source_rgba (cr, fill_inactive_color); + cairo_fill (cr); + } else if ( (active_state() == Gtkmm2ext::ExplicitActive) && !((_elements & Indicator)==Indicator) ) { + //background color + ArdourCanvas::set_source_rgba (cr, fill_active_color); + cairo_fill (cr); + } else { //inactive, or it has an indicator + //background color + ArdourCanvas::set_source_rgba (cr, fill_inactive_color); + } + cairo_fill (cr); + } + + // IMPLICIT ACTIVE: draw a border of the active color + if ((_elements & Body)==Body) { + if (active_state() == Gtkmm2ext::ImplicitActive && !((_elements & Indicator)==Indicator)) { + cairo_set_line_width (cr, 2.0); + rounded_function (cr, 2, 2, get_width() - 4, get_height() - 4, corner_radius-0.5); + ArdourCanvas::set_source_rgba (cr, fill_active_color); + cairo_stroke (cr); + } + } + + //show the "convex" or "concave" gradient + if (!_flat_buttons && (_elements & Body)==Body) { + 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); + cairo_fill (cr); + } else { + cairo_set_source (cr, convex_pattern); + Gtkmm2ext::rounded_rectangle (cr, 1, 1, get_width() - 2, get_height() - 2, corner_radius); + cairo_fill (cr); + } + } + + //Pixbuf, if any + if (_pixbuf) { + double x = rint((get_width() - _pixbuf->get_width()) * .5); + const double y = rint((get_height() - _pixbuf->get_height()) * .5); +#if 0 // DEBUG style (print on hover) + if (_hovering || (_elements & Inactive)) { + printf("%s: p:%dx%d (%dx%d)\n", + get_name().c_str(), + _pixbuf->get_width(), _pixbuf->get_height(), + get_width(), get_height()); + } +#endif + if (_elements & Menu) { + //if this is a DropDown with an icon, then we need to + //move the icon left slightly to accomomodate the arrow + x -= _diameter - 2; + } + cairo_rectangle (cr, x, y, _pixbuf->get_width(), _pixbuf->get_height()); + gdk_cairo_set_source_pixbuf (cr, _pixbuf->gobj(), x, y); + cairo_fill (cr); + } + else /* VectorIcon, IconRenderCallback are exclusive to Pixbuf Icons */ + if (_elements & (VectorIcon | IconRenderCallback)) { + int vw = get_width(); + int vh = get_height(); + if (_elements & Menu) { + vw -= _diameter + 4; + } + if (_elements & VectorIcon) { + Gtkmm2ext::ArdourIcon::render (cr, _icon, vw, vh, active_state(), text_color); + } else { + cairo_save (cr); + rounded_function (cr, 0, 0, get_width(), get_height(), corner_radius + 1.5); + cairo_clip (cr); + _icon_render_cb (cr, vw, vh, text_color, _icon_render_cb_data); + cairo_restore (cr); + } + } + + const int text_margin = char_pixel_width(); + // Text, if any + if (!_pixbuf && ((_elements & Text)==Text) && !_text.empty()) { + assert(_layout); +#if 0 // DEBUG style (print on hover) + if (_hovering || (_elements & Inactive)) { + bool layout_font = true; + Pango::FontDescription fd = _layout->get_font_description(); + if (fd.gobj() == NULL) { + layout_font = false; + fd = get_pango_context()->get_font_description(); + } + printf("%s: f:%dx%d aw:%.3f bh:%.0f t:%dx%d (%dx%d) %s\"%s\"\n", + get_name().c_str(), + char_pixel_width(), char_pixel_height(), char_avg_pixel_width(), + ceil(char_pixel_height() * BASELINESTRETCH), + _text_width, _text_height, + get_width(), get_height(), + layout_font ? "L:" : "W:", + fd.to_string().c_str()); + } +#endif + + cairo_save (cr); + cairo_rectangle (cr, 2, 1, get_width() - 4, get_height() - 2); + cairo_clip(cr); + + cairo_new_path (cr); + ArdourCanvas::set_source_rgba (cr, text_color); + const double text_ypos = (get_height() - _text_height) * .5; + + if (_elements & Menu) { + // always left align (dropdown) + cairo_move_to (cr, text_margin, text_ypos); + pango_cairo_show_layout (cr, _layout->gobj()); + } else if ( (_elements & Indicator) == Indicator) { + // left/right align depending on LED position + if (_led_left) { + cairo_move_to (cr, text_margin + _diameter + .5 * char_pixel_width(), text_ypos); + } else { + cairo_move_to (cr, text_margin, text_ypos); + } + pango_cairo_show_layout (cr, _layout->gobj()); + } else { + /* centered text otherwise */ + double ww, wh; + double xa, ya; + ww = get_width(); + wh = get_height(); + + cairo_matrix_t m1; + cairo_get_matrix (cr, &m1); + cairo_matrix_t m2 = m1; + m2.x0 = 0; + m2.y0 = 0; + cairo_set_matrix (cr, &m2); + + if (_angle) { + cairo_rotate(cr, _angle * M_PI / 180.0); + } + + cairo_device_to_user(cr, &ww, &wh); + xa = text_margin + (ww - _text_width - 2 * text_margin) * _xalign; + ya = (wh - _text_height) * _yalign; + + /* quick hack for left/bottom alignment at -90deg + * TODO this should be generalized incl rotation. + * currently only 'user' of this API is meter_strip.cc + */ + if (_xalign < 0) xa = ceil(.5 + (ww * fabs(_xalign) + text_margin)); + + cairo_move_to (cr, xa + m1.x0, ya + m1.y0); + pango_cairo_update_layout(cr, _layout->gobj()); + pango_cairo_show_layout (cr, _layout->gobj()); + } + cairo_restore (cr); + } + + //Menu "triangle" + if (_elements & Menu) { + const float trih = ceil(_diameter * .5); + const float triw2 = ceil(.577 * _diameter * .5); // 1/sqrt(3) Equilateral triangle + //menu arrow + cairo_set_source_rgba (cr, 1, 1, 1, 0.4); + cairo_move_to(cr, get_width() - triw2 - 3. , rint((get_height() + trih) * .5)); + cairo_rel_line_to(cr, -triw2, -trih); + cairo_rel_line_to(cr, 2. * triw2, 0); + cairo_close_path(cr); + + cairo_set_source_rgba (cr, 1, 1, 1, 0.4); + cairo_fill(cr); + + cairo_move_to(cr, get_width() - triw2 - 3 , rint((get_height() + trih) * .5)); + cairo_rel_line_to(cr, .5 - triw2, .5 - trih); + cairo_rel_line_to(cr, 2. * triw2 - 1, 0); + cairo_close_path(cr); + cairo_set_source_rgba (cr, 0, 0, 0, 0.8); + cairo_set_line_width(cr, 1); + cairo_stroke(cr); + } + + //Indicator LED + if (_elements & Indicator) { + cairo_save (cr); + + /* move to the center of the indicator/led */ + if (_elements & Text) { + int led_xoff = ceil(char_pixel_width() + _diameter * .5); + if (_led_left) { + cairo_translate (cr, led_xoff, get_height() * .5); + } else { + cairo_translate (cr, get_width() - led_xoff, get_height() * .5); + } + } else { + cairo_translate (cr, get_width() * .5, get_height() * .5); + } + + //inset + if (!_flat_buttons) { + cairo_arc (cr, 0, 0, _diameter * .5, 0, 2 * M_PI); + cairo_set_source (cr, led_inset_pattern); + cairo_fill (cr); + } + + //black ring + cairo_set_source_rgb (cr, 0, 0, 0); + cairo_arc (cr, 0, 0, _diameter * .5 - 1 * UIConfigurationBase::instance().get_ui_scale(), 0, 2 * M_PI); + cairo_fill(cr); + + //led color + ArdourCanvas::set_source_rgba (cr, led_color); + cairo_arc (cr, 0, 0, _diameter * .5 - 3 * UIConfigurationBase::instance().get_ui_scale(), 0, 2 * M_PI); + cairo_fill(cr); + + cairo_restore (cr); + } + + // a transparent overlay to indicate insensitivity + if ((visual_state() & Gtkmm2ext::Insensitive)) { + rounded_function (cr, 0, 0, get_width(), get_height(), corner_radius); + uint32_t ins_color = UIConfigurationBase::instance().color ("gtk_background"); + ArdourCanvas::set_source_rgb_a (cr, ins_color, 0.6); + cairo_fill (cr); + } + + // if requested, show hovering + if (UIConfigurationBase::instance().get_widget_prelight() + && !((visual_state() & Gtkmm2ext::Insensitive))) { + if (_hovering) { + rounded_function (cr, 1, 1, get_width() - 2, get_height() - 2, corner_radius); + cairo_set_source_rgba (cr, 0.905, 0.917, 0.925, 0.2); + cairo_fill (cr); + } + } + + //user is currently pressing the button. dark outline helps to indicate this + if (_grabbed && !(_elements & (Inactive|Menu))) { + rounded_function (cr, 1, 1, get_width() - 2, get_height() - 2, corner_radius); + cairo_set_line_width(cr, 2); + cairo_set_source_rgba (cr, 0.1, 0.1, 0.1, .5); + cairo_stroke (cr); + } + + //some buttons (like processor boxes) can be selected (so they can be deleted). Draw a selection indicator + if (visual_state() & Gtkmm2ext::Selected) { + cairo_set_line_width(cr, 1); + cairo_set_source_rgba (cr, 1, 0, 0, 0.8); + rounded_function (cr, 0.5, 0.5, get_width() - 1, get_height() - 1, corner_radius); + cairo_stroke (cr); + } + + //I guess this means we have keyboard focus. I don't think this works currently + // + //A: yes, it's keyboard focus and it does work when there's no editor window + // (the editor is always the first receiver for KeyDown). + // It's needed for eg. the engine-dialog at startup or after closing a sesion. + if (_focused) { + rounded_function (cr, 1.5, 1.5, get_width() - 3, get_height() - 3, corner_radius); + cairo_set_source_rgba (cr, 0.905, 0.917, 0.925, 0.8); + double dashes = 1; + cairo_set_dash (cr, &dashes, 1, 0); + cairo_set_line_cap (cr, CAIRO_LINE_CAP_BUTT); + cairo_set_line_width (cr, 1.0); + cairo_stroke (cr); + cairo_set_dash (cr, 0, 0, 0); + } +} + +void +ArdourButton::set_corner_radius (float r) +{ + _corner_radius = r; + CairoWidget::set_dirty (); +} + +void +ArdourButton::on_realize() +{ + CairoWidget::on_realize (); + ensure_layout (); + if (_layout) { + if (_layout->get_text() != _text) { + set_text_internal (); + queue_resize (); + } + } +} + +void +ArdourButton::on_size_request (Gtk::Requisition* req) +{ + req->width = req->height = 0; + CairoWidget::on_size_request (req); + + if (_diameter == 0) { + const float newdia = rintf (11.f * UIConfigurationBase::instance().get_ui_scale()); + if (_diameter != newdia) { + _pattern_height = 0; + _diameter = newdia; + } + } + + if (_elements & Text) { + + ensure_layout(); + set_text_internal (); + + /* render() needs the size of the displayed text */ + _layout->get_pixel_size (_text_width, _text_height); + + if (_tweaks & OccasionalText) { + + /* size should not change based on presence or absence + * of text. + */ + + } else /*if (!_text.empty() || !_sizing_text.empty()) */ { + + req->height = std::max(req->height, (int) ceil(char_pixel_height() * BASELINESTRETCH + 1.0)); + req->width += rint(1.75 * char_pixel_width()); // padding + + if (!_sizing_text.empty()) { + _layout->set_text (_sizing_text); /* use sizing text */ + } + + int sizing_text_width = 0, sizing_text_height = 0; + _layout->get_pixel_size (sizing_text_width, sizing_text_height); + + req->width += sizing_text_width; + + if (!_sizing_text.empty()) { + set_text_internal (); /* restore display text */ + } + } + + /* XXX hack (surprise). Deal with two common rotation angles */ + + if (_angle == 90 || _angle == 270) { + /* do not swap text width or height because we rely on + these being the un-rotated values in ::render() + */ + swap (req->width, req->height); + } + + } else { + _text_width = 0; + _text_height = 0; + } + + if (_pixbuf) { + req->width += _pixbuf->get_width() + char_pixel_width(); + req->height = std::max(req->height, _pixbuf->get_height() + 4); + } + + if (_elements & Indicator) { + req->width += lrint (_diameter) + char_pixel_width(); + req->height = std::max (req->height, (int) lrint (_diameter) + 4); + } + + if ((_elements & Menu)) { + req->width += _diameter + 4; + } + + if (_elements & (VectorIcon | IconRenderCallback)) { + assert(!(_elements & Text)); + const int wh = std::max (6., std::max (rint (TRACKHEADERBTNW * char_avg_pixel_width()), ceil (char_pixel_height() * BASELINESTRETCH + 1.))); + req->width += wh; + req->height = std::max(req->height, wh); + } + + /* Tweaks to mess the nice stuff above up again. */ + if (_tweaks & TrackHeader) { + // forget everything above and just use a fixed square [em] size + // "TrackHeader Buttons" are single letter (usually uppercase) + // a SizeGroup is much less efficient (lots of gtk work under the hood for each track) + const int wh = std::max (rint (TRACKHEADERBTNW * char_avg_pixel_width()), ceil (char_pixel_height() * BASELINESTRETCH + 1.)); + req->width = wh; + req->height = wh; + } + else if (_tweaks & Square) { + // currerntly unused (again) + if (req->width < req->height) + req->width = req->height; + if (req->height < req->width) + req->height = req->width; + } else if (_sizing_text.empty() && _text_width > 0 && !(_elements & Menu)) { + // properly centered text for those elements that are centered + // (no sub-pixel offset) + if ((req->width - _text_width) & 1) { ++req->width; } + if ((req->height - _text_height) & 1) { ++req->height; } + } +#if 0 + printf("REQ: %s: %dx%d\n", get_name().c_str(), req->width, req->height); +#endif +} + +/** + * This sets the colors used for rendering based on the name of the button, and + * thus uses information from the GUI config data. + */ +void +ArdourButton::set_colors () +{ + _update_colors = false; + + if (_fixed_colors_set == 0x3) { + return; + } + + std::string name = get_name(); + bool failed = false; + + if (!(_fixed_colors_set & 0x1)) { + fill_active_color = UIConfigurationBase::instance().color (string_compose ("%1: fill active", name), &failed); + if (failed) { + fill_active_color = UIConfigurationBase::instance().color ("generic button: fill active"); + } + } + + if (!(_fixed_colors_set & 0x2)) { + fill_inactive_color = UIConfigurationBase::instance().color (string_compose ("%1: fill", name), &failed); + if (failed) { + fill_inactive_color = UIConfigurationBase::instance().color ("generic button: fill"); + } + } + + text_active_color = ArdourCanvas::contrasting_text_color (fill_active_color); + text_inactive_color = ArdourCanvas::contrasting_text_color (fill_inactive_color); + + led_active_color = UIConfigurationBase::instance().color (string_compose ("%1: led active", name), &failed); + if (failed) { + led_active_color = UIConfigurationBase::instance().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_inactive_color = inactive.color (); +} + +/** + * This sets the colors used for rendering based on two fixed values, rather + * than basing them on the button name, and thus information in the GUI config + * data. + */ +void ArdourButton::set_fixed_colors (const uint32_t color_active, const uint32_t color_inactive) +{ + set_active_color (color_active); + set_inactive_color (color_inactive); +} + +void ArdourButton::set_active_color (const uint32_t color) +{ + _fixed_colors_set |= 0x1; + + fill_active_color = color; + + unsigned char r, g, b, a; + UINT_TO_RGBA(color, &r, &g, &b, &a); + + double white_contrast = (max (double(r), 255.) - min (double(r), 255.)) + + (max (double(g), 255.) - min (double(g), 255.)) + + (max (double(b), 255.) - min (double(b), 255.)); + + double black_contrast = (max (double(r), 0.) - min (double(r), 0.)) + + (max (double(g), 0.) - min (double(g), 0.)) + + (max (double(b), 0.) - min (double(b), 0.)); + + text_active_color = (white_contrast > black_contrast) ? + RGBA_TO_UINT(255, 255, 255, 255) : /* use white */ + RGBA_TO_UINT( 0, 0, 0, 255); /* use black */ + + /* XXX what about led colors ? */ + CairoWidget::set_dirty (); +} + +void ArdourButton::set_inactive_color (const uint32_t color) +{ + _fixed_colors_set |= 0x2; + + fill_inactive_color = color; + + unsigned char r, g, b, a; + UINT_TO_RGBA(color, &r, &g, &b, &a); + + double white_contrast = (max (double(r), 255.) - min (double(r), 255.)) + + (max (double(g), 255.) - min (double(g), 255.)) + + (max (double(b), 255.) - min (double(b), 255.)); + + double black_contrast = (max (double(r), 0.) - min (double(r), 0.)) + + (max (double(g), 0.) - min (double(g), 0.)) + + (max (double(b), 0.) - min (double(b), 0.)); + + text_inactive_color = (white_contrast > black_contrast) ? + RGBA_TO_UINT(255, 255, 255, 255) : /* use white */ + RGBA_TO_UINT( 0, 0, 0, 255); /* use black */ + + /* XXX what about led colors ? */ + CairoWidget::set_dirty (); +} + +void +ArdourButton::build_patterns () +{ + if (convex_pattern) { + cairo_pattern_destroy (convex_pattern); + convex_pattern = 0; + } + + if (concave_pattern) { + cairo_pattern_destroy (concave_pattern); + concave_pattern = 0; + } + + if (led_inset_pattern) { + cairo_pattern_destroy (led_inset_pattern); + led_inset_pattern = 0; + } + + //convex gradient + convex_pattern = cairo_pattern_create_linear (0.0, 0, 0.0, get_height()); + cairo_pattern_add_color_stop_rgba (convex_pattern, 0.0, 0,0,0, 0.0); + cairo_pattern_add_color_stop_rgba (convex_pattern, 1.0, 0,0,0, 0.35); + + //concave gradient + concave_pattern = cairo_pattern_create_linear (0.0, 0, 0.0, get_height()); + cairo_pattern_add_color_stop_rgba (concave_pattern, 0.0, 0,0,0, 0.5); + cairo_pattern_add_color_stop_rgba (concave_pattern, 0.7, 0,0,0, 0.0); + + led_inset_pattern = cairo_pattern_create_linear (0.0, 0.0, 0.0, _diameter); + cairo_pattern_add_color_stop_rgba (led_inset_pattern, 0, 0,0,0, 0.4); + cairo_pattern_add_color_stop_rgba (led_inset_pattern, 1, 1,1,1, 0.7); + + _pattern_height = get_height() ; +} + +void +ArdourButton::set_led_left (bool yn) +{ + _led_left = yn; +} + +bool +ArdourButton::on_button_press_event (GdkEventButton *ev) +{ + focus_handler (this); + + 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; + } + } + + if (binding_proxy.button_press_handler (ev)) { + return true; + } + + _grabbed = true; + CairoWidget::set_dirty (); + + if (ev->button == 1 && !_act_on_release) { + if (_action) { + _action->activate (); + return true; + } + } + + if (_fallthrough_to_parent) + return false; + + return true; +} + +bool +ArdourButton::on_button_release_event (GdkEventButton *ev) +{ + 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(ev); /* EMIT SIGNAL */ + return true; + } + } + + _grabbed = false; + CairoWidget::set_dirty (); + + if (ev->button == 1 && _hovering) { + signal_clicked (); + if (_act_on_release) { + if (_action) { + _action->activate (); + return true; + } + } + } + + if (_fallthrough_to_parent) + return false; + + return true; +} + +void +ArdourButton::set_distinct_led_click (bool yn) +{ + _distinct_led_click = yn; + setup_led_rect (); +} + +void +ArdourButton::color_handler () +{ + _update_colors = true; + CairoWidget::set_dirty (); +} + +void +ArdourButton::on_size_allocate (Allocation& alloc) +{ + CairoWidget::on_size_allocate (alloc); + setup_led_rect (); +} + +void +ArdourButton::set_controllable (boost::shared_ptr c) +{ + watch_connection.disconnect (); + binding_proxy.set_controllable (c); +} + +void +ArdourButton::watch () +{ + boost::shared_ptr c (binding_proxy.get_controllable ()); + + if (!c) { + warning << _("button cannot watch state of non-existing Controllable\n") << endmsg; + return; + } + c->Changed.connect (watch_connection, invalidator(*this), boost::bind (&ArdourButton::controllable_changed, this), gui_context()); +} + +void +ArdourButton::controllable_changed () +{ + float val = binding_proxy.get_controllable()->get_value(); + + if (fabs (val) >= 0.5f) { + set_active_state (Gtkmm2ext::ExplicitActive); + } else { + unset_active_state (); + } + CairoWidget::set_dirty (); +} + +void +ArdourButton::set_related_action (RefPtr act) +{ + Gtkmm2ext::Activatable::set_related_action (act); + + if (_action) { + + action_tooltip_changed (); + action_sensitivity_changed (); + + Glib::RefPtr tact = Glib::RefPtr::cast_dynamic (_action); + if (tact) { + action_toggled (); + tact->signal_toggled().connect (sigc::mem_fun (*this, &ArdourButton::action_toggled)); + } + + _action->connect_property_changed ("sensitive", sigc::mem_fun (*this, &ArdourButton::action_sensitivity_changed)); + _action->connect_property_changed ("visible", sigc::mem_fun (*this, &ArdourButton::action_visibility_changed)); + _action->connect_property_changed ("tooltip", sigc::mem_fun (*this, &ArdourButton::action_tooltip_changed)); + } +} + +void +ArdourButton::action_toggled () +{ + Glib::RefPtr tact = Glib::RefPtr::cast_dynamic (_action); + + if (tact) { + if (tact->get_active()) { + set_active_state (Gtkmm2ext::ExplicitActive); + } else { + unset_active_state (); + } + } +} + +void +ArdourButton::on_style_changed (const RefPtr&) +{ + _update_colors = true; + CairoWidget::set_dirty (); + _char_pixel_width = 0; + _char_pixel_height = 0; + if (is_realized()) { + queue_resize (); + } +} + +void +ArdourButton::on_name_changed () +{ + _char_pixel_width = 0; + _char_pixel_height = 0; + _diameter = 0; + _update_colors = true; + if (is_realized()) { + queue_resize (); + } +} + +void +ArdourButton::setup_led_rect () +{ + if (!(_elements & Indicator)) { + delete _led_rect; + _led_rect = 0; + return; + } + + if (!_led_rect) { + _led_rect = new cairo_rectangle_t; + } + + if (_elements & Text) { + if (_led_left) { + _led_rect->x = char_pixel_width(); + } else { + _led_rect->x = get_width() - char_pixel_width() + _diameter; + } + } else { + /* centered */ + _led_rect->x = .5 * get_width() - _diameter; + } + + _led_rect->y = .5 * (get_height() - _diameter); + _led_rect->width = _diameter; + _led_rect->height = _diameter; +} + +void +ArdourButton::set_image (const RefPtr& img) +{ + _elements = (ArdourButton::Element) (_elements & ~ArdourButton::Text); + _pixbuf = img; + if (is_realized()) { + queue_resize (); + } +} + +void +ArdourButton::set_active_state (Gtkmm2ext::ActiveState s) +{ + bool changed = (_active_state != s); + CairoWidget::set_active_state (s); + if (changed) { + _update_colors = true; + CairoWidget::set_dirty (); + } +} + +void +ArdourButton::set_visual_state (Gtkmm2ext::VisualState s) +{ + bool changed = (_visual_state != s); + CairoWidget::set_visual_state (s); + if (changed) { + _update_colors = true; + CairoWidget::set_dirty (); + } +} + +bool +ArdourButton::on_focus_in_event (GdkEventFocus* ev) +{ + _focused = true; + CairoWidget::set_dirty (); + return CairoWidget::on_focus_in_event (ev); +} + +bool +ArdourButton::on_focus_out_event (GdkEventFocus* ev) +{ + _focused = false; + CairoWidget::set_dirty (); + return CairoWidget::on_focus_out_event (ev); +} + +bool +ArdourButton::on_key_release_event (GdkEventKey *ev) { + if (_act_on_release && _focused && + (ev->keyval == GDK_space || ev->keyval == GDK_Return)) + { + signal_clicked(); + if (_action) { + _action->activate (); + } + return true; + } + return CairoWidget::on_key_release_event (ev); +} + +bool +ArdourButton::on_key_press_event (GdkEventKey *ev) { + if (!_act_on_release && _focused && + (ev->keyval == GDK_space || ev->keyval == GDK_Return)) + { + signal_clicked(); + if (_action) { + _action->activate (); + } + return true; + } + return CairoWidget::on_key_release_event (ev); +} + +bool +ArdourButton::on_enter_notify_event (GdkEventCrossing* ev) +{ + _hovering = (_elements & Inactive) ? false : true; + + if (UIConfigurationBase::instance().get_widget_prelight()) { + CairoWidget::set_dirty (); + } + + boost::shared_ptr c (binding_proxy.get_controllable ()); + if (c) { + PBD::Controllable::GUIFocusChanged (boost::weak_ptr (c)); + } + + return CairoWidget::on_enter_notify_event (ev); +} + +bool +ArdourButton::on_leave_notify_event (GdkEventCrossing* ev) +{ + _hovering = false; + + if (UIConfigurationBase::instance().get_widget_prelight()) { + CairoWidget::set_dirty (); + } + + if (binding_proxy.get_controllable()) { + PBD::Controllable::GUIFocusChanged (boost::weak_ptr ()); + } + + return CairoWidget::on_leave_notify_event (ev); +} + +bool +ArdourButton::on_grab_broken_event(GdkEventGrabBroken* grab_broken_event) { + /* Our implicit grab due to a button_press was broken by another grab: + * the button will not get any button_release event if the mouse leaves + * while the grab is taken, so unpress ourselves */ + _grabbed = false; + CairoWidget::set_dirty (); + return true; +} + +void +ArdourButton::set_tweaks (Tweaks t) +{ + if (_tweaks != t) { + _tweaks = t; + if (is_realized()) { + queue_resize (); + } + } +} + +void +ArdourButton::action_sensitivity_changed () +{ + if (_action->property_sensitive ()) { + set_visual_state (Gtkmm2ext::VisualState (visual_state() & ~Gtkmm2ext::Insensitive)); + } else { + set_visual_state (Gtkmm2ext::VisualState (visual_state() | Gtkmm2ext::Insensitive)); + } +} + +void +ArdourButton::set_layout_ellipsize_width (int w) +{ + if (_layout_ellipsize_width == w) { + return; + } + _layout_ellipsize_width = w; + if (!_layout) { + return; + } + if (_layout_ellipsize_width > 3 * PANGO_SCALE) { + _layout->set_width (_layout_ellipsize_width - 3 * PANGO_SCALE); + } + if (is_realized ()) { + queue_resize (); + } +} + +void +ArdourButton::set_text_ellipsize (Pango::EllipsizeMode e) +{ + if (_ellipsis == e) { + return; + } + _ellipsis = e; + if (!_layout) { + return; + } + _layout->set_ellipsize(_ellipsis); + if (_layout_ellipsize_width > 3 * PANGO_SCALE) { + _layout->set_width (_layout_ellipsize_width - 3 * PANGO_SCALE); + } + if (is_realized ()) { + queue_resize (); + } +} + +void +ArdourButton::ensure_layout () +{ + if (!_layout) { + ensure_style (); + _layout = Pango::Layout::create (get_pango_context()); + _layout->set_ellipsize(_ellipsis); + if (_layout_ellipsize_width > 3 * PANGO_SCALE) { + _layout->set_width (_layout_ellipsize_width - 3* PANGO_SCALE); + } + } +} + +void +ArdourButton::recalc_char_pixel_geometry () +{ + if (_char_pixel_height > 0 && _char_pixel_width > 0) { + return; + } + ensure_layout(); + // NB. this is not static, since the geometry is different + // depending on the font used. + int w, h; + std::string x = _("@ABCDEFGHIJLKMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789"); + _layout->set_text (x); + _layout->get_pixel_size (w, h); + _char_pixel_height = std::max(4, h); + // number of actual chars in the string (not bytes) + // Glib to the rescue. + Glib::ustring gx(x); + _char_avg_pixel_width = w / (float)gx.size(); + _char_pixel_width = std::max(4, (int) ceil (_char_avg_pixel_width)); + set_text_internal (); /* restore display text */ +} + +void +ArdourButton::action_visibility_changed () +{ + if (_action->property_visible ()) { + show (); + } else { + hide (); + } +} + +void +ArdourButton::action_tooltip_changed () +{ + string str = _action->property_tooltip().get_value(); + set_tooltip (*this, str); +} + +void +ArdourButton::set_elements (Element e) +{ + _elements = e; + CairoWidget::set_dirty (); +} + +void +ArdourButton::add_elements (Element e) +{ + _elements = (ArdourButton::Element) (_elements | e); + CairoWidget::set_dirty (); +} + +void +ArdourButton::set_icon (Gtkmm2ext::ArdourIcon::Icon i) +{ + _icon = i; + _icon_render_cb = 0; + _icon_render_cb_data = 0; + _elements = (ArdourButton::Element) ((_elements | VectorIcon) & ~(ArdourButton::Text | IconRenderCallback)); + CairoWidget::set_dirty (); +} + +void +ArdourButton::set_icon (rendercallback_t cb, void* d) +{ + if (!cb) { + _elements = (ArdourButton::Element) ((_elements | ArdourButton::Text) & ~(IconRenderCallback | VectorIcon)); + _icon_render_cb = 0; + _icon_render_cb_data = 0; + } else { + _elements = (ArdourButton::Element) ((_elements | IconRenderCallback) & ~(ArdourButton::Text | VectorIcon)); + _icon_render_cb = cb; + _icon_render_cb_data = d; + } + 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 (); +} diff --git a/libs/widgets/ardour_display.cc b/libs/widgets/ardour_display.cc new file mode 100644 index 0000000000..ef23edb586 --- /dev/null +++ b/libs/widgets/ardour_display.cc @@ -0,0 +1,142 @@ +/* + Copyright (C) 2014 Paul Davis + + This program is free software; you can redistribute it and/or modify + it under the terms of the GNU General Public License as published by + the Free Software Foundation; either version 2 of the License, or + (at your option) any later version. + + This program is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU General Public License + along with this program; if not, write to the Free Software + Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. + +*/ + +#include +#include +#include + +#include + +#include "pbd/compose.h" +#include "pbd/controllable.h" +#include "pbd/error.h" +#include "pbd/stacktrace.h" + +#include "gtkmm2ext/utils.h" +#include "gtkmm2ext/rgb_macros.h" +#include "gtkmm2ext/gui_thread.h" +#include "gtkmm2ext/keyboard.h" + +#include "widgets/ardour_display.h" + +#include "pbd/i18n.h" + +using namespace Gtkmm2ext; +using namespace Gdk; +using namespace Gtk; +using namespace Glib; +using namespace PBD; +using namespace ArdourWidgets; +using std::max; +using std::min; +using namespace std; + +ArdourDisplay::ArdourDisplay (Element e) +{ + add_elements(ArdourButton::Text); +} + +ArdourDisplay::~ArdourDisplay () +{ +} + + +bool +ArdourDisplay::on_scroll_event (GdkEventScroll* ev) +{ + /* mouse wheel */ + + float scale = 1.0; + if (ev->state & Keyboard::GainFineScaleModifier) { + if (ev->state & Keyboard::GainExtraFineScaleModifier) { + scale *= 0.01; + } else { + scale *= 0.10; + } + } + + boost::shared_ptr c = binding_proxy.get_controllable(); + if (c) { + float val = c->get_interface(); + + if ( ev->direction == GDK_SCROLL_UP ) + val += 0.05 * scale; //by default, we step in 1/20ths of the knob travel + else + val -= 0.05 * scale; + + c->set_interface(val); + } + + return true; +} + + +void +ArdourDisplay::add_controllable_preset (const char *txt, float val) +{ + using namespace Menu_Helpers; + AddMenuElem(MenuElem (txt, sigc::bind (sigc::mem_fun(*this, &ArdourDisplay::handle_controllable_preset), val))); +} + +static inline float dB_to_coefficient (float dB) { + return dB > -318.8f ? pow (10.0f, dB * 0.05f) : 0.0f; +} + +void +ArdourDisplay::handle_controllable_preset (float p) +{ + boost::shared_ptr c = binding_proxy.get_controllable(); + + if (!c) return; + + /* This should not use dB_to_coefficient(), but the Controllable's value. + * + * The only user of this API is currently monitor_section.cc which conveniently + * binds dB values. Once there are other use-cases, for this, this (GUI only) API + * needs fixing. + */ + c->set_value(dB_to_coefficient (p), Controllable::NoGroup); +} + + +void +ArdourDisplay::set_controllable (boost::shared_ptr c) +{ + watch_connection.disconnect (); //stop watching the old controllable + + if (!c) return; + + binding_proxy.set_controllable (c); + + c->Changed.connect (watch_connection, invalidator(*this), boost::bind (&ArdourDisplay::controllable_changed, this), gui_context()); + + controllable_changed(); +} + +void +ArdourDisplay::controllable_changed () +{ + boost::shared_ptr c = binding_proxy.get_controllable(); + + if (!c) return; + + set_text(c->get_user_string()); + + set_dirty(); +} diff --git a/libs/widgets/ardour_dropdown.cc b/libs/widgets/ardour_dropdown.cc new file mode 100644 index 0000000000..24c8d030a0 --- /dev/null +++ b/libs/widgets/ardour_dropdown.cc @@ -0,0 +1,166 @@ +/* + Copyright (C) 2014 Paul Davis + + This program is free software; you can redistribute it and/or modify + it under the terms of the GNU General Public License as published by + the Free Software Foundation; either version 2 of the License, or + (at your option) any later version. + + This program is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU General Public License + along with this program; if not, write to the Free Software + Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. + +*/ + +#include +#include +#include + +#include + +#include "pbd/compose.h" +#include "pbd/error.h" +#include "pbd/stacktrace.h" + +#include "gtkmm2ext/utils.h" +#include "gtkmm2ext/rgb_macros.h" +#include "gtkmm2ext/gui_thread.h" + +#include "ardour/rc_configuration.h" // for widget prelight preference + +#include "widgets/ardour_dropdown.h" + +#include "pbd/i18n.h" + +#define REFLECTION_HEIGHT 2 + +using namespace Gdk; +using namespace Gtk; +using namespace Glib; +using namespace PBD; +using namespace ArdourWidgets; +using namespace std; + + +ArdourDropdown::ArdourDropdown (Element e) + : _scrolling_disabled(false) +{ +// signal_button_press_event().connect (sigc::mem_fun(*this, &ArdourDropdown::on_mouse_pressed)); + _menu.signal_size_request().connect (sigc::mem_fun(*this, &ArdourDropdown::menu_size_request)); + + _menu.set_reserve_toggle_size(false); + + add_elements(e); + add_elements(ArdourButton::Menu); +} + +ArdourDropdown::~ArdourDropdown () +{ +} + +void +ArdourDropdown::menu_size_request(Requisition *req) { + req->width = max(req->width, get_allocation().get_width()); +} + +bool +ArdourDropdown::on_button_press_event (GdkEventButton* ev) +{ + if (binding_proxy.button_press_handler (ev)) { + return true; + } + + if (ev->type == GDK_BUTTON_PRESS && ev->button == 1) { + Gtkmm2ext::anchored_menu_popup(&_menu, this, get_text(), 1, ev->time); + } + + return true; +} + +bool +ArdourDropdown::on_scroll_event (GdkEventScroll* ev) +{ + using namespace Menu_Helpers; + + if (_scrolling_disabled) { + return false; + } + + const MenuItem * current_active = _menu.get_active(); + const MenuList& items = _menu.items (); + int c = 0; + + if (!current_active) { + return true; + } + + /* work around another gtkmm API clusterfuck + * const MenuItem* get_active () const + * void set_active (guint index) + * + * also MenuList.activate_item does not actually + * set it as active in the menu. + * + */ + + switch (ev->direction) { + case GDK_SCROLL_UP: + + for (MenuList::const_reverse_iterator i = items.rbegin(); i != items.rend(); ++i, ++c) { + if ( &(*i) != current_active) { + continue; + } + if (++i != items.rend()) { + c = items.size() - 2 - c; + assert(c >= 0); + _menu.set_active(c); + _menu.activate_item(*i); + } + break; + } + break; + case GDK_SCROLL_DOWN: + for (MenuList::const_iterator i = items.begin(); i != items.end(); ++i, ++c) { + if ( &(*i) != current_active) { + continue; + } + if (++i != items.end()) { + assert(c + 1 < (int) items.size()); + _menu.set_active(c + 1); + _menu.activate_item(*i); + } + break; + } + break; + default: + break; + } + return true; +} + +void +ArdourDropdown::clear_items () +{ + _menu.items ().clear (); +} + +void +ArdourDropdown::AddMenuElem (Menu_Helpers::Element e) +{ + using namespace Menu_Helpers; + + MenuList& items = _menu.items (); + + items.push_back (e); +} + +void +ArdourDropdown::disable_scrolling() +{ + _scrolling_disabled = true; +} diff --git a/libs/widgets/ardour_knob.cc b/libs/widgets/ardour_knob.cc new file mode 100644 index 0000000000..6948a88993 --- /dev/null +++ b/libs/widgets/ardour_knob.cc @@ -0,0 +1,598 @@ +/* + Copyright (C) 2010 Paul Davis + + This program is free software; you can redistribute it and/or modify + it under the terms of the GNU General Public License as published by + the Free Software Foundation; either version 2 of the License, or + (at your option) any later version. + + This program is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU General Public License + along with this program; if not, write to the Free Software + Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. + +*/ + +#include +#include +#include + +#include + +#include "pbd/compose.h" +#include "pbd/controllable.h" +#include "pbd/error.h" +#include "pbd/stacktrace.h" + +#include "gtkmm2ext/utils.h" +#include "gtkmm2ext/rgb_macros.h" +#include "gtkmm2ext/gui_thread.h" +#include "gtkmm2ext/keyboard.h" + +#include "pbd/controllable.h" + +#include "widgets/ardour_knob.h" +#include "widgets/ui_config.h" +//#include "timers.h" + +#include "canvas/colors.h" +#include "canvas/utils.h" + +#include "pbd/i18n.h" + +using namespace Gtkmm2ext; +using namespace ArdourWidgets; +using namespace Gtk; +using namespace Glib; +using namespace PBD; +using std::max; +using std::min; +using namespace std; + +ArdourKnob::Element ArdourKnob::default_elements = ArdourKnob::Element (ArdourKnob::Arc); + +ArdourKnob::ArdourKnob (Element e, Flags flags) + : _elements (e) + , _hovering (false) + , _grabbed_x (0) + , _grabbed_y (0) + , _val (0) + , _normal (0) + , _dead_zone_delta (0) + , _flags (flags) + , _tooltip (this) +{ + UIConfigurationBase::instance().ColorsChanged.connect (sigc::mem_fun (*this, &ArdourKnob::color_handler)); + + // watch automation :( + // TODO only use for GainAutomation + //Timers::rapid_connect (sigc::bind (sigc::mem_fun (*this, &ArdourKnob::controllable_changed), false)); +} + +ArdourKnob::~ArdourKnob() +{ +} + +void +ArdourKnob::render (Cairo::RefPtr const& ctx, cairo_rectangle_t*) +{ + cairo_t* cr = ctx->cobj(); + cairo_pattern_t* shade_pattern; + + float width = get_width(); + float height = get_height(); + + const float scale = min(width, height); + const float pointer_thickness = 3.0 * (scale/80); //(if the knob is 80 pixels wide, we want a 3-pix line on it) + + const float start_angle = ((180 - 65) * G_PI) / 180; + const float end_angle = ((360 + 65) * G_PI) / 180; + + float zero = 0; + if (_flags & ArcToZero) { + zero = _normal; + } + + const float value_angle = start_angle + (_val * (end_angle - start_angle)); + const float zero_angle = start_angle + (zero * (end_angle - start_angle)); + + float value_x = cos (value_angle); + float value_y = sin (value_angle); + + float xc = 0.5 + width/ 2.0; + float yc = 0.5 + height/ 2.0; + + cairo_translate (cr, xc, yc); //after this, everything is based on the center of the knob + + //get the knob color from the theme + ArdourCanvas::Color knob_color = UIConfigurationBase::instance().color (string_compose ("%1", get_name())); + + float center_radius = 0.48*scale; + float border_width = 0.8; + + bool arc = (_elements & Arc)==Arc; + bool bevel = (_elements & Bevel)==Bevel; + bool flat = _flat_buttons; + + if ( arc ) { + center_radius = scale*0.33; + + float inner_progress_radius = scale*0.38; + float outer_progress_radius = scale*0.48; + float progress_width = (outer_progress_radius-inner_progress_radius); + float progress_radius = inner_progress_radius + progress_width/2.0; + + //dark arc background + cairo_set_source_rgb (cr, 0.3, 0.3, 0.3 ); + cairo_set_line_width (cr, progress_width); + cairo_arc (cr, 0, 0, progress_radius, start_angle, end_angle); + cairo_stroke (cr); + + //look up the arc colors from the config + double red_start, green_start, blue_start, unused; + ArdourCanvas::Color arc_start_color = UIConfigurationBase::instance().color ( string_compose ("%1: arc start", get_name())); + ArdourCanvas::color_to_rgba( arc_start_color, red_start, green_start, blue_start, unused ); + double red_end, green_end, blue_end; + ArdourCanvas::Color arc_end_color = UIConfigurationBase::instance().color ( string_compose ("%1: arc end", get_name()) ); + ArdourCanvas::color_to_rgba( arc_end_color, red_end, green_end, blue_end, unused ); + + //vary the arc color over the travel of the knob + float intensity = fabsf (_val - zero) / std::max(zero, (1.f - zero)); + const float intensity_inv = 1.0 - intensity; + float r = intensity_inv * red_end + intensity * red_start; + float g = intensity_inv * green_end + intensity * green_start; + float b = intensity_inv * blue_end + intensity * blue_start; + + //draw the arc + cairo_set_source_rgb (cr, r,g,b); + cairo_set_line_width (cr, progress_width); + if (zero_angle > value_angle) { + cairo_arc (cr, 0, 0, progress_radius, value_angle, zero_angle); + } else { + cairo_arc (cr, 0, 0, progress_radius, zero_angle, value_angle); + } + cairo_stroke (cr); + + //shade the arc + if (!flat) { + shade_pattern = cairo_pattern_create_linear (0.0, -yc, 0.0, yc); //note we have to offset the pattern from our centerpoint + cairo_pattern_add_color_stop_rgba (shade_pattern, 0.0, 1,1,1, 0.15); + cairo_pattern_add_color_stop_rgba (shade_pattern, 0.5, 1,1,1, 0.0); + cairo_pattern_add_color_stop_rgba (shade_pattern, 1.0, 1,1,1, 0.0); + cairo_set_source (cr, shade_pattern); + cairo_arc (cr, 0, 0, outer_progress_radius-1, 0, 2.0*G_PI); + cairo_fill (cr); + cairo_pattern_destroy (shade_pattern); + } + +#if 0 //black border + const float start_angle_x = cos (start_angle); + const float start_angle_y = sin (start_angle); + const float end_angle_x = cos (end_angle); + const float end_angle_y = sin (end_angle); + + cairo_set_source_rgb (cr, 0, 0, 0 ); + cairo_set_line_width (cr, border_width); + cairo_move_to (cr, (outer_progress_radius * start_angle_x), (outer_progress_radius * start_angle_y)); + cairo_line_to (cr, (inner_progress_radius * start_angle_x), (inner_progress_radius * start_angle_y)); + cairo_stroke (cr); + cairo_move_to (cr, (outer_progress_radius * end_angle_x), (outer_progress_radius * end_angle_y)); + cairo_line_to (cr, (inner_progress_radius * end_angle_x), (inner_progress_radius * end_angle_y)); + cairo_stroke (cr); + cairo_arc (cr, 0, 0, outer_progress_radius, start_angle, end_angle); + cairo_stroke (cr); +#endif + } + + if (!flat) { + //knob shadow + cairo_save(cr); + cairo_translate(cr, pointer_thickness+1, pointer_thickness+1 ); + cairo_set_source_rgba (cr, 0, 0, 0, 0.1 ); + cairo_arc (cr, 0, 0, center_radius-1, 0, 2.0*G_PI); + cairo_fill (cr); + cairo_restore(cr); + + //inner circle + ArdourCanvas::set_source_rgba(cr, knob_color); + cairo_arc (cr, 0, 0, center_radius, 0, 2.0*G_PI); + cairo_fill (cr); + + //gradient + if (bevel) { + //knob gradient + shade_pattern = cairo_pattern_create_linear (0.0, -yc, 0.0, yc); //note we have to offset the gradient from our centerpoint + cairo_pattern_add_color_stop_rgba (shade_pattern, 0.0, 1,1,1, 0.2); + cairo_pattern_add_color_stop_rgba (shade_pattern, 0.2, 1,1,1, 0.2); + cairo_pattern_add_color_stop_rgba (shade_pattern, 0.8, 0,0,0, 0.2); + cairo_pattern_add_color_stop_rgba (shade_pattern, 1.0, 0,0,0, 0.2); + cairo_set_source (cr, shade_pattern); + cairo_arc (cr, 0, 0, center_radius, 0, 2.0*G_PI); + cairo_fill (cr); + cairo_pattern_destroy (shade_pattern); + + //flat top over beveled edge + ArdourCanvas::set_source_rgb_a (cr, knob_color, 0.5 ); + cairo_arc (cr, 0, 0, center_radius-pointer_thickness, 0, 2.0*G_PI); + cairo_fill (cr); + } else { + //radial gradient + shade_pattern = cairo_pattern_create_radial ( -center_radius, -center_radius, 1, -center_radius, -center_radius, center_radius*2.5 ); //note we have to offset the gradient from our centerpoint + cairo_pattern_add_color_stop_rgba (shade_pattern, 0.0, 1,1,1, 0.2); + cairo_pattern_add_color_stop_rgba (shade_pattern, 1.0, 0,0,0, 0.3); + cairo_set_source (cr, shade_pattern); + cairo_arc (cr, 0, 0, center_radius, 0, 2.0*G_PI); + cairo_fill (cr); + cairo_pattern_destroy (shade_pattern); + } + + } else { + //inner circle + ArdourCanvas::set_source_rgba(cr, knob_color); + cairo_arc (cr, 0, 0, center_radius, 0, 2.0*G_PI); + cairo_fill (cr); + } + + + //black knob border + cairo_set_line_width (cr, border_width); + cairo_set_source_rgba (cr, 0,0,0, 1 ); + cairo_arc (cr, 0, 0, center_radius, 0, 2.0*G_PI); + cairo_stroke (cr); + + //line shadow + if (!flat) { + cairo_save(cr); + cairo_translate(cr, 1, 1 ); + cairo_set_source_rgba (cr, 0,0,0,0.3 ); + cairo_set_line_cap (cr, CAIRO_LINE_CAP_ROUND); + cairo_set_line_width (cr, pointer_thickness); + cairo_move_to (cr, (center_radius * value_x), (center_radius * value_y)); + cairo_line_to (cr, ((center_radius*0.4) * value_x), ((center_radius*0.4) * value_y)); + cairo_stroke (cr); + cairo_restore(cr); + } + + //line + cairo_set_source_rgba (cr, 1,1,1, 1 ); + cairo_set_line_cap (cr, CAIRO_LINE_CAP_ROUND); + cairo_set_line_width (cr, pointer_thickness); + cairo_move_to (cr, (center_radius * value_x), (center_radius * value_y)); + cairo_line_to (cr, ((center_radius*0.4) * value_x), ((center_radius*0.4) * value_y)); + cairo_stroke (cr); + + //highlight if grabbed or if mouse is hovering over me + if (_tooltip.dragging() || (_hovering && UIConfigurationBase::instance().get_widget_prelight() ) ) { + cairo_set_source_rgba (cr, 1,1,1, 0.12 ); + cairo_arc (cr, 0, 0, center_radius, 0, 2.0*G_PI); + cairo_fill (cr); + } + + cairo_identity_matrix(cr); +} + +void +ArdourKnob::on_size_request (Gtk::Requisition* req) +{ + // see ardour-button VectorIcon size, use font scaling as default + CairoWidget::on_size_request (req); // allow to override + + // we're square + if (req->width < req->height) { + req->width = req->height; + } + if (req->height < req->width) { + req->height = req->width; + } +} + +bool +ArdourKnob::on_scroll_event (GdkEventScroll* ev) +{ + /* mouse wheel */ + + float scale = 0.05; //by default, we step in 1/20ths of the knob travel + if (ev->state & Keyboard::GainFineScaleModifier) { + if (ev->state & Keyboard::GainExtraFineScaleModifier) { + scale *= 0.01; + } else { + scale *= 0.10; + } + } + + boost::shared_ptr c = binding_proxy.get_controllable(); + if (c) { + float val = c->get_interface(); + + if ( ev->direction == GDK_SCROLL_UP ) + val += scale; + else + val -= scale; + + c->set_interface(val); + } + + return true; +} + +bool +ArdourKnob::on_motion_notify_event (GdkEventMotion *ev) +{ + if (!(ev->state & Gdk::BUTTON1_MASK)) { + return true; + } + + boost::shared_ptr c = binding_proxy.get_controllable(); + if (!c) { + return true; + } + + + //scale the adjustment based on keyboard modifiers & GUI size + const float ui_scale = max (1.f, UIConfigurationBase::instance().get_ui_scale()); + float scale = 0.0025 / ui_scale; + + if (ev->state & Keyboard::GainFineScaleModifier) { + if (ev->state & Keyboard::GainExtraFineScaleModifier) { + scale *= 0.01; + } else { + scale *= 0.10; + } + } + + //calculate the travel of the mouse + int delta = (_grabbed_y - ev->y) - (_grabbed_x - ev->x); + if (delta == 0) { + return true; + } + + _grabbed_x = ev->x; + _grabbed_y = ev->y; + float val = c->get_interface(); + + if (_flags & Detent) { + const float px_deadzone = 42.f * ui_scale; + + if ((val - _normal) * (val - _normal + delta * scale) < 0) { + /* detent */ + const int tozero = (_normal - val) * scale; + int remain = delta - tozero; + if (abs (remain) > px_deadzone) { + /* slow down passing the default value */ + remain += (remain > 0) ? px_deadzone * -.5 : px_deadzone * .5; + delta = tozero + remain; + _dead_zone_delta = 0; + } else { + c->set_value (c->normal(), Controllable::NoGroup); + _dead_zone_delta = remain / px_deadzone; + return true; + } + } + + if (fabsf (rintf((val - _normal) / scale) + _dead_zone_delta) < 1) { + c->set_value (c->normal(), Controllable::NoGroup); + _dead_zone_delta += delta / px_deadzone; + return true; + } + + _dead_zone_delta = 0; + } + + val += delta * scale; + c->set_interface(val); + + return true; +} + +bool +ArdourKnob::on_button_press_event (GdkEventButton *ev) +{ + _grabbed_x = ev->x; + _grabbed_y = ev->y; + _dead_zone_delta = 0; + + if (ev->type != GDK_BUTTON_PRESS) { + if (_grabbed) { + remove_modal_grab(); + gdk_pointer_ungrab (GDK_CURRENT_TIME); + } + return true; + } + + if (binding_proxy.button_press_handler (ev)) { + return true; + } + + if (ev->button != 1 && ev->button != 2) { + return false; + } + + set_active_state (Gtkmm2ext::ExplicitActive); + _tooltip.start_drag(); + add_modal_grab(); + _grabbed = true; + gdk_pointer_grab(ev->window,false, + GdkEventMask( Gdk::POINTER_MOTION_MASK | Gdk::BUTTON_PRESS_MASK |Gdk::BUTTON_RELEASE_MASK), + NULL,NULL,ev->time); + return true; +} + +bool +ArdourKnob::on_button_release_event (GdkEventButton *ev) +{ + _tooltip.stop_drag(); + _grabbed = false; + remove_modal_grab(); + gdk_pointer_ungrab (GDK_CURRENT_TIME); + + if ( (_grabbed_y == ev->y && _grabbed_x == ev->x) && Keyboard::modifier_state_equals (ev->state, Keyboard::TertiaryModifier)) { //no move, shift-click sets to default + boost::shared_ptr c = binding_proxy.get_controllable(); + if (!c) return false; + c->set_value (c->normal(), Controllable::NoGroup); + return true; + } + + unset_active_state (); + + return true; +} + +void +ArdourKnob::color_handler () +{ + set_dirty (); +} + +void +ArdourKnob::on_size_allocate (Allocation& alloc) +{ + CairoWidget::on_size_allocate (alloc); +} + +void +ArdourKnob::set_controllable (boost::shared_ptr c) +{ + watch_connection.disconnect (); //stop watching the old controllable + + if (!c) return; + + binding_proxy.set_controllable (c); + + c->Changed.connect (watch_connection, invalidator(*this), boost::bind (&ArdourKnob::controllable_changed, this, false), gui_context()); + + _normal = c->internal_to_interface(c->normal()); + + controllable_changed(); +} + +void +ArdourKnob::controllable_changed (bool force_update) +{ + boost::shared_ptr c = binding_proxy.get_controllable(); + if (!c) return; + + float val = c->get_interface(); + val = min( max(0.0f, val), 1.0f); // clamp + + if (val == _val && !force_update) { + return; + } + + _val = val; + if (!_tooltip_prefix.empty()) { + _tooltip.set_tip (_tooltip_prefix + c->get_user_string()); + } + set_dirty(); +} + +void +ArdourKnob::on_style_changed (const RefPtr&) +{ + set_dirty (); +} + +void +ArdourKnob::on_name_changed () +{ + set_dirty (); +} + + +void +ArdourKnob::set_active_state (Gtkmm2ext::ActiveState s) +{ + if (_active_state != s) + CairoWidget::set_active_state (s); +} + +void +ArdourKnob::set_visual_state (Gtkmm2ext::VisualState s) +{ + if (_visual_state != s) + CairoWidget::set_visual_state (s); +} + + +bool +ArdourKnob::on_focus_in_event (GdkEventFocus* ev) +{ + set_dirty (); + return CairoWidget::on_focus_in_event (ev); +} + +bool +ArdourKnob::on_focus_out_event (GdkEventFocus* ev) +{ + set_dirty (); + return CairoWidget::on_focus_out_event (ev); +} + +bool +ArdourKnob::on_enter_notify_event (GdkEventCrossing* ev) +{ + _hovering = true; + + set_dirty (); + + boost::shared_ptr c (binding_proxy.get_controllable ()); + if (c) { + PBD::Controllable::GUIFocusChanged (boost::weak_ptr (c)); + } + + return CairoWidget::on_enter_notify_event (ev); +} + +bool +ArdourKnob::on_leave_notify_event (GdkEventCrossing* ev) +{ + _hovering = false; + + set_dirty (); + + if (binding_proxy.get_controllable()) { + PBD::Controllable::GUIFocusChanged (boost::weak_ptr ()); + } + + return CairoWidget::on_leave_notify_event (ev); +} + +void +ArdourKnob::set_elements (Element e) +{ + _elements = e; +} + +void +ArdourKnob::add_elements (Element e) +{ + _elements = (ArdourKnob::Element) (_elements | e); +} + + +KnobPersistentTooltip::KnobPersistentTooltip (Gtk::Widget* w) + : PersistentTooltip (w, true, 3) + , _dragging (false) +{ +} + +void +KnobPersistentTooltip::start_drag () +{ + _dragging = true; +} + +void +KnobPersistentTooltip::stop_drag () +{ + _dragging = false; +} + +bool +KnobPersistentTooltip::dragging () const +{ + return _dragging; +} diff --git a/libs/widgets/ardour_spacer.cc b/libs/widgets/ardour_spacer.cc new file mode 100644 index 0000000000..4155a17ee4 --- /dev/null +++ b/libs/widgets/ardour_spacer.cc @@ -0,0 +1,27 @@ +/* + * Copyright (C) 2017 Robin Gareus + * + * This program is free software; you can redistribute it and/or + * modify it under the terms of the GNU General Public License + * as published by the Free Software Foundation; either version 2 + * of the License, or (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software + * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. + */ + +#include "widgets/ardour_spacer.h" + +using namespace ArdourWidgets; + +ArdourVSpacer::ArdourVSpacer (float r) + : CairoWidget () + , ratio (r) +{ +} diff --git a/libs/widgets/ardour_spinner.cc b/libs/widgets/ardour_spinner.cc new file mode 100644 index 0000000000..071caf310e --- /dev/null +++ b/libs/widgets/ardour_spinner.cc @@ -0,0 +1,206 @@ +/* + * Copyright (C) 2016 Robin Gareus + * Copyright (C) 2011 Paul Davis + * + * This program is free software; you can redistribute it and/or + * modify it under the terms of the GNU General Public License + * as published by the Free Software Foundation; either version 2 + * of the License, or (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software + * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. + */ + +#include "gtkmm2ext/gui_thread.h" +#include "gtkmm2ext/utils.h" +#include "gtkmm2ext/keyboard.h" + +#include "widgets/ardour_spinner.h" + +//#include "ardour/value_as_string.h" // XXX + +using namespace ArdourWidgets; + +ArdourSpinner::ArdourSpinner (boost::shared_ptr c, Gtk::Adjustment* adj) + : _btn (ArdourButton::Text) + , _ctrl_adj (adj) + , _spin_adj (0, c->lower (), c->upper (), .1, .01) + , _spinner (_spin_adj) + , _switching (false) + , _switch_on_release (false) + , _ctrl_ignore (false) + , _spin_ignore (false) + , _controllable (c) +{ + add_events (Gdk::BUTTON_PRESS_MASK | Gdk::BUTTON_RELEASE_MASK); + set (.5, .5, 1.0, 1.0); + set_border_width (0); + + _btn.set_controllable (c); + _btn.set_fallthrough_to_parent (true); + + _spinner.signal_activate().connect (mem_fun (*this, &ArdourSpinner::entry_activated)); + _spinner.signal_focus_out_event().connect (mem_fun (*this, &ArdourSpinner::entry_focus_out)); + _spinner.set_digits (4); + _spinner.set_numeric (true); + _spinner.set_name ("BarControlSpinner"); + + _spin_adj.set_step_increment(c->interface_to_internal(_ctrl_adj->get_step_increment()) - c->lower ()); + _spin_adj.set_page_increment(c->interface_to_internal(_ctrl_adj->get_page_increment()) - c->lower ()); + + _spin_adj.signal_value_changed().connect (sigc::mem_fun(*this, &ArdourSpinner::spin_adjusted)); + adj->signal_value_changed().connect (sigc::mem_fun(*this, &ArdourSpinner::ctrl_adjusted)); + c->Changed.connect (watch_connection, invalidator(*this), boost::bind (&ArdourSpinner::controllable_changed, this), gui_context()); + +#if 0 + // this assume the "upper" value needs most space. + std::string txt = ARDOUR::value_as_string (c->desc(), c->upper ()); + Gtkmm2ext::set_size_request_to_display_given_text (*this, txt, 2, 2); +#endif + + add (_btn); + show_all (); + + controllable_changed(); + ctrl_adjusted (); +} + + +ArdourSpinner::~ArdourSpinner () +{ +} + +bool +ArdourSpinner::on_button_press_event (GdkEventButton* ev) +{ + if (get_child() != &_btn) { + return false; + } + + if (ev->button == 1 && ev->type == GDK_2BUTTON_PRESS) { + _switch_on_release = true; + return true; + } else { + _switch_on_release = false; + } + return false; +} + +bool +ArdourSpinner::on_button_release_event (GdkEventButton* ev) +{ + if (get_child() != &_btn) { + return false; + } + if (ev->button == 1 && _switch_on_release) { + Glib::signal_idle().connect (mem_fun (*this, &ArdourSpinner::switch_to_spinner)); + return true; + } + return false; +} + +bool +ArdourSpinner::on_scroll_event (GdkEventScroll* ev) +{ + float scale = 1.0; + if (ev->state & Gtkmm2ext::Keyboard::GainFineScaleModifier) { + if (ev->state & Gtkmm2ext::Keyboard::GainExtraFineScaleModifier) { + scale *= 0.01; + } else { + scale *= 0.10; + } + } + + boost::shared_ptr c = _btn.get_controllable(); + if (c) { + float val = c->get_interface(); + + if ( ev->direction == GDK_SCROLL_UP ) + val += 0.05 * scale; //by default, we step in 1/20ths of the knob travel + else + val -= 0.05 * scale; + + c->set_interface(val); + } + + return true; +} + +gint +ArdourSpinner::switch_to_button () +{ + if (_switching || get_child() == &_btn) { + return false; + } + _switching = true; + remove (); + add (_btn); + _btn.show (); + _btn.set_dirty (); + _switching = false; + return false; +} + +gint +ArdourSpinner::switch_to_spinner () +{ + if (_switching || get_child() != &_btn) { + return false; + } + _switching = true; + remove (); + add (_spinner); + _spinner.show (); + _spinner.select_region (0, _spinner.get_text_length ()); + _spinner.grab_focus (); + _switching = false; + return false; +} + +void +ArdourSpinner::entry_activated () +{ + switch_to_button (); +} + +bool +ArdourSpinner::entry_focus_out (GdkEventFocus* /*ev*/) +{ + entry_activated (); + return true; +} + +void +ArdourSpinner::ctrl_adjusted () +{ + if (_spin_ignore) { + return; + } + _ctrl_ignore = true; + _spin_adj.set_value (_controllable->interface_to_internal (_ctrl_adj->get_value ())); + _ctrl_ignore = false; +} + +void +ArdourSpinner::spin_adjusted () +{ + if (_ctrl_ignore) { + return; + } + _spin_ignore = true; + _ctrl_adj->set_value (_controllable->internal_to_interface (_spin_adj.get_value ())); + _spin_ignore = false; +} + +void +ArdourSpinner::controllable_changed () +{ + _btn.set_text (_controllable->get_user_string()); + _btn.set_dirty(); +} diff --git a/libs/widgets/tooltips.cc b/libs/widgets/tooltips.cc new file mode 100644 index 0000000000..990355b6ad --- /dev/null +++ b/libs/widgets/tooltips.cc @@ -0,0 +1,40 @@ +/* + Copyright (C) 2014 Paul Davis + + This program is free software; you can redistribute it and/or modify + it under the terms of the GNU General Public License as published by + the Free Software Foundation; either version 2 of the License, or + (at your option) any later version. + + This program is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU General Public License + along with this program; if not, write to the Free Software + Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. + +*/ + +#include "gtkmm2ext/gtk_ui.h" +#include "widgets/tooltips.h" + +namespace ArdourWidgets { + +void +set_tooltip (Gtk::Widget& w, const std::string& text) { + Gtkmm2ext::UI::instance()->set_tip(w, text); +} + +void +set_tooltip (Gtk::Widget* w, const std::string& text) { + Gtkmm2ext::UI::instance()->set_tip(*w, text); +} + +void +set_tooltip (Gtk::Widget* w, const std::string& text, const std::string& help_text) { + Gtkmm2ext::UI::instance()->set_tip(w, text.c_str(), help_text.c_str()); +} + +} diff --git a/libs/widgets/ui_config.cc b/libs/widgets/ui_config.cc new file mode 100644 index 0000000000..0325697ba4 --- /dev/null +++ b/libs/widgets/ui_config.cc @@ -0,0 +1,7 @@ +#include "widgets/ui_config.h" + +namespace ArdourWidgets { + +UIConfigurationBase* UIConfigurationBase::_instance = 0; + +}; diff --git a/libs/widgets/widgets/ardour_button.h b/libs/widgets/widgets/ardour_button.h new file mode 100644 index 0000000000..a51575e616 --- /dev/null +++ b/libs/widgets/widgets/ardour_button.h @@ -0,0 +1,221 @@ +/* + Copyright (C) 2010 Paul Davis + + This program is free software; you can redistribute it and/or modify + it under the terms of the GNU General Public License as published by + the Free Software Foundation; either version 2 of the License, or + (at your option) any later version. + + This program is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU General Public License + along with this program; if not, write to the Free Software + Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. +*/ + +#ifndef _WIDGETS_ARDOUR_BUTTON_H_ +#define _WIDGETS_ARDOUR_BUTTON_H_ + +#include +#include + +#include + +#include "pbd/signals.h" +#include "gtkmm2ext/ardour_icon.h" +#include "gtkmm2ext/binding_proxy.h" +#include "gtkmm2ext/activatable.h" +#include "gtkmm2ext/cairo_widget.h" + +#include "widgets/visibility.h" + +namespace ArdourWidgets { + +class LIBWIDGETS_API ArdourButton : public CairoWidget , public Gtkmm2ext::Activatable +{ + public: + enum Element { + Edge = 0x1, + Body = 0x2, + Text = 0x4, + Indicator = 0x8, + unused = 0x10, + Menu = 0x20, + Inactive = 0x40, // no _action is defined AND state is not used + VectorIcon = 0x80, + IconRenderCallback = 0x100, + }; + + typedef void (* rendercallback_t) (cairo_t*, int, int, uint32_t, void*); + + static Element default_elements; + static Element led_default_elements; + static Element just_led_default_elements; + + ArdourButton (Element e = default_elements); + ArdourButton (const std::string&, Element e = default_elements); + virtual ~ArdourButton (); + + enum Tweaks { + Square = 0x1, + TrackHeader = 0x2, + OccasionalText = 0x4, + unused4 = 0x8, + }; + + Tweaks tweaks() const { return _tweaks; } + void set_tweaks (Tweaks); + + void set_active_state (Gtkmm2ext::ActiveState); + void set_visual_state (Gtkmm2ext::VisualState); + + void set_custom_led_color (const uint32_t c, const bool useit = true); + + void set_act_on_release (bool onRelease) { _act_on_release = onRelease; } + + Element elements() const { return _elements; } + void set_elements (Element); + void add_elements (Element); + + Gtkmm2ext::ArdourIcon::Icon icon() const { return _icon; } + void set_icon (Gtkmm2ext::ArdourIcon::Icon); + void set_icon (rendercallback_t, void*); + + void set_corner_radius (float); + + void set_text (const std::string&, bool markup = false); + const std::string& get_text () { return _text; } + bool get_markup () const { return _markup; } + void set_angle (const double); + void set_alignment (const float, const float); + void get_alignment (float& xa, float& ya) {xa = _xalign; ya = _yalign;}; + + void set_led_left (bool yn); + void set_distinct_led_click (bool yn); + + void set_layout_ellipsize_width (int w); + void set_layout_font (const Pango::FontDescription&); + void set_text_ellipsize (Pango::EllipsizeMode); + + /* Sets the text used for size request computation. Pass an + * empty string to return to the default behavior which uses + * the currently displayed text for measurement. */ + void set_sizing_text (const std::string&); + const std::string& get_sizing_text () {return _sizing_text;} + + sigc::signal signal_led_clicked; + sigc::signal signal_clicked; + + boost::shared_ptr get_controllable() { return binding_proxy.get_controllable(); } + void set_controllable (boost::shared_ptr c); + void watch (); + + void set_related_action (Glib::RefPtr); + + bool on_button_press_event (GdkEventButton*); + bool on_button_release_event (GdkEventButton*); + + void set_image (const Glib::RefPtr&); + + void set_fixed_colors (const uint32_t active_color, const uint32_t inactive_color); + void set_active_color (const uint32_t active_color); + void set_inactive_color (const uint32_t inactive_color); + + void set_fallthrough_to_parent(bool fall) { _fallthrough_to_parent = fall; } + + unsigned int char_pixel_width() { if (_char_pixel_width < 1) recalc_char_pixel_geometry() ; return _char_pixel_width; } + unsigned int char_pixel_height() { if (_char_pixel_height < 1) recalc_char_pixel_geometry() ; return _char_pixel_height; } + float char_avg_pixel_width() { if (_char_pixel_width < 1) recalc_char_pixel_geometry() ; return _char_avg_pixel_width; } + + protected: + void render (Cairo::RefPtr const&, cairo_rectangle_t*); + void on_size_request (Gtk::Requisition* req); + void on_size_allocate (Gtk::Allocation&); + void on_style_changed (const Glib::RefPtr&); + void on_name_changed (); + void on_realize (); + bool on_enter_notify_event (GdkEventCrossing*); + bool on_leave_notify_event (GdkEventCrossing*); + bool on_grab_broken_event(GdkEventGrabBroken*); + bool on_focus_in_event (GdkEventFocus*); + bool on_focus_out_event (GdkEventFocus*); + bool on_key_release_event (GdkEventKey *); + bool on_key_press_event (GdkEventKey *); + + void controllable_changed (); + PBD::ScopedConnection watch_connection; + + protected: + Glib::RefPtr _layout; + Glib::RefPtr _pixbuf; + std::string _text; + std::string _sizing_text; + bool _markup; + Element _elements; + Gtkmm2ext::ArdourIcon::Icon _icon; + rendercallback_t _icon_render_cb; + void* _icon_render_cb_data; + Tweaks _tweaks; + BindingProxy binding_proxy; + + void set_text_internal (); + void recalc_char_pixel_geometry (); + unsigned int _char_pixel_width; + unsigned int _char_pixel_height; + float _char_avg_pixel_width; + + int _text_width; + int _text_height; + float _diameter; + float _corner_radius; + int _corner_mask; + + double _angle; + float _xalign, _yalign; + + uint32_t fill_inactive_color; + uint32_t fill_active_color; + + uint32_t text_active_color; + uint32_t text_inactive_color; + + uint32_t led_active_color; + uint32_t led_inactive_color; + uint32_t led_custom_color; + bool use_custom_led_color; + + cairo_pattern_t* convex_pattern; + cairo_pattern_t* concave_pattern; + cairo_pattern_t* led_inset_pattern; + cairo_rectangle_t* _led_rect; + + bool _act_on_release; + bool _led_left; + bool _distinct_led_click; + bool _hovering; + bool _focused; + int _fixed_colors_set; + bool _fallthrough_to_parent; + int _layout_ellipsize_width; + Pango::EllipsizeMode _ellipsis; + bool _update_colors; + int _pattern_height; + + void setup_led_rect (); + void set_colors (); + void color_handler (); + void build_patterns (); + void ensure_layout (); + + void action_toggled (); + void action_sensitivity_changed (); + void action_visibility_changed (); + void action_tooltip_changed (); +}; + +} /* end namespace */ + +#endif diff --git a/libs/widgets/widgets/ardour_display.h b/libs/widgets/widgets/ardour_display.h new file mode 100644 index 0000000000..c8d566cd85 --- /dev/null +++ b/libs/widgets/widgets/ardour_display.h @@ -0,0 +1,55 @@ +/* + Copyright (C) 2014 Paul Davis + + This program is free software; you can redistribute it and/or modify + it under the terms of the GNU General Public License as published by + the Free Software Foundation; either version 2 of the License, or + (at your option) any later version. + + This program is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU General Public License + along with this program; if not, write to the Free Software + Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. +*/ + +#ifndef _WIDGETS_ARDOUR_DISPLAY_H_ +#define _WIDGETS_ARDOUR_DISPLAY_H_ + +#include +#include + +#include +#include +#include + +#include "widgets/ardour_dropdown.h" +#include "widgets/visibility.h" + +namespace ArdourWidgets { + +class LIBWIDGETS_API ArdourDisplay : public ArdourWidgets::ArdourDropdown +{ +public: + + ArdourDisplay (Element e = default_elements); + virtual ~ArdourDisplay (); + + boost::shared_ptr get_controllable() { return binding_proxy.get_controllable(); } + void set_controllable (boost::shared_ptr c); + + bool on_scroll_event (GdkEventScroll* ev); + + void add_controllable_preset (const char*, float); + void handle_controllable_preset (float p); + + void controllable_changed (); + PBD::ScopedConnection watch_connection; +}; + +} /* end namespace */ + +#endif /* __gtk2_ardour_ardour_menu_h__ */ diff --git a/libs/widgets/widgets/ardour_dropdown.h b/libs/widgets/widgets/ardour_dropdown.h new file mode 100644 index 0000000000..93e866d011 --- /dev/null +++ b/libs/widgets/widgets/ardour_dropdown.h @@ -0,0 +1,60 @@ +/* + Copyright (C) 2014 Paul Davis + + This program is free software; you can redistribute it and/or modify + it under the terms of the GNU General Public License as published by + the Free Software Foundation; either version 2 of the License, or + (at your option) any later version. + + This program is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU General Public License + along with this program; if not, write to the Free Software + Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. +*/ + +#ifndef _WIDGETS_ARDOUR_DROPDOWN_H_ +#define _WIDGETS_ARDOUR_DROPDOWN_H_ + +#include +#include + +#include +#include +#include + +#include "widgets/ardour_button.h" +#include "widgets/visibility.h" + +namespace ArdourWidgets { + +class LIBWIDGETS_API ArdourDropdown : public ArdourButton +{ +public: + + ArdourDropdown (Element e = default_elements); + virtual ~ArdourDropdown (); + + bool on_button_press_event (GdkEventButton*); + bool on_scroll_event (GdkEventScroll*); + void menu_size_request(Gtk::Requisition*); + + void clear_items (); + void AddMenuElem (Gtk::Menu_Helpers::Element e); + + void disable_scrolling(); + + Gtk::Menu_Helpers::MenuList& items () { return _menu.items (); } + +private: + Gtk::Menu _menu; + + bool _scrolling_disabled; +}; + +} /* end namespace */ + +#endif diff --git a/libs/widgets/widgets/ardour_knob.h b/libs/widgets/widgets/ardour_knob.h new file mode 100644 index 0000000000..84bb974adf --- /dev/null +++ b/libs/widgets/widgets/ardour_knob.h @@ -0,0 +1,133 @@ +/* + Copyright (C) 2014 Paul Davis + + This program is free software; you can redistribute it and/or modify + it under the terms of the GNU General Public License as published by + the Free Software Foundation; either version 2 of the License, or + (at your option) any later version. + + This program is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU General Public License + along with this program; if not, write to the Free Software + Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. +*/ + +#ifndef __gtk2_ardour_ardour_knob_h__ +#define __gtk2_ardour_ardour_knob_h__ + +#include +#include + +#include + +#include "pbd/signals.h" + +#include "gtkmm2ext/binding_proxy.h" +#include "gtkmm2ext/activatable.h" +#include "gtkmm2ext/cairo_widget.h" +#include "gtkmm2ext/persistent_tooltip.h" + +#include "widgets/visibility.h" + +namespace ArdourWidgets { + +class LIBWIDGETS_API KnobPersistentTooltip : public Gtkmm2ext::PersistentTooltip +{ +public: + KnobPersistentTooltip (Gtk::Widget* w); + + void start_drag (); + void stop_drag (); + bool dragging () const; + +private: + bool _dragging; +}; + + +class LIBWIDGETS_API ArdourKnob : public CairoWidget , public Gtkmm2ext::Activatable +{ +public: + + enum Element { + Arc = 0x1, + Bevel = 0x2, + unused2 = 0x4, + unused3 = 0x8, + unused4 = 0x10, + unused5 = 0x20, + }; + + enum Flags { + NoFlags = 0, + Detent = 0x1, + ArcToZero = 0x2, + }; + + ArdourKnob (Element e = default_elements, Flags flags = NoFlags); + virtual ~ArdourKnob (); + + void set_active_state (Gtkmm2ext::ActiveState); + void set_visual_state (Gtkmm2ext::VisualState); + + Element elements() const { return _elements; } + void set_elements (Element); + void add_elements (Element); + static Element default_elements; + + void set_tooltip_prefix (std::string pfx) { _tooltip_prefix = pfx; controllable_changed (true); } + + boost::shared_ptr get_controllable() { return binding_proxy.get_controllable(); } + void set_controllable (boost::shared_ptr c); + + bool on_button_press_event (GdkEventButton*); + bool on_button_release_event (GdkEventButton*); + bool on_scroll_event (GdkEventScroll* ev); + bool on_motion_notify_event (GdkEventMotion *ev) ; + + void color_handler (); + + protected: + void render (Cairo::RefPtr const&, cairo_rectangle_t*); + void on_size_request (Gtk::Requisition* req); + void on_size_allocate (Gtk::Allocation&); + void on_style_changed (const Glib::RefPtr&); + void on_name_changed (); + bool on_enter_notify_event (GdkEventCrossing*); + bool on_leave_notify_event (GdkEventCrossing*); + bool on_focus_in_event (GdkEventFocus*); + bool on_focus_out_event (GdkEventFocus*); + + void controllable_changed (bool force_update = false); + PBD::ScopedConnection watch_connection; + + + private: + Element _elements; + BindingProxy binding_proxy; + + bool _hovering; + float _grabbed_x; + float _grabbed_y; + + float _val; // current value [0..1] + float _normal; // default value, arc + float _dead_zone_delta; + + Flags _flags; + + void action_sensitivity_changed (); + void action_visibility_changed (); + void action_tooltip_changed (); + + std::string _tooltip_prefix; + KnobPersistentTooltip _tooltip; +}; + +} /* namespace */ + +#endif /* __gtk2_ardour_ardour_knob_h__ */ diff --git a/libs/widgets/widgets/ardour_spacer.h b/libs/widgets/widgets/ardour_spacer.h new file mode 100644 index 0000000000..520ad670af --- /dev/null +++ b/libs/widgets/widgets/ardour_spacer.h @@ -0,0 +1,53 @@ +/* + * Copyright (C) 2016 Robin Gareus + * + * This program is free software; you can redistribute it and/or + * modify it under the terms of the GNU General Public License + * as published by the Free Software Foundation; either version 2 + * of the License, or (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software + * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. + */ + +#ifndef _WIDGETS_ARDOUR_SPACER_H_ +#define _WIDGETS_ARDOUR_SPACER_H_ + +#include "gtkmm2ext/cairo_widget.h" + +#include "widgets/visibility.h" + +namespace ArdourWidgets { + +class LIBWIDGETS_API ArdourVSpacer : public CairoWidget +{ +public: + ArdourVSpacer (float r = 0.75f); + +protected: + void render (Cairo::RefPtr const& ctx, cairo_rectangle_t* r) { + float h = r->height * ratio; + float t = .5f * (r->height - h); + ctx->rectangle (0, t, 1, h); + ctx->set_source_rgb (0, 0, 0); + ctx->fill (); + } + + void on_size_request (Gtk::Requisition* req) { + req->width = 1; + req->height = 0; + CairoWidget::on_size_request (req); + } + + float ratio; +}; + +} /* end namespace */ + +#endif diff --git a/libs/widgets/widgets/ardour_spinner.h b/libs/widgets/widgets/ardour_spinner.h new file mode 100644 index 0000000000..b0928fa432 --- /dev/null +++ b/libs/widgets/widgets/ardour_spinner.h @@ -0,0 +1,73 @@ +/* + * Copyright (C) 2016 Robin Gareus + * Copyright (C) 2011 Paul Davis + * + * This program is free software; you can redistribute it and/or + * modify it under the terms of the GNU General Public License + * as published by the Free Software Foundation; either version 2 + * of the License, or (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software + * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. + */ + +#ifndef _WIDGETS_ARDOUR_SPINNER_H_ +#define _WIDGETS_ARDOUR_SPINNER_H_ + +#include +#include + +#include "pbd/controllable.h" + +#include "widgets/ardour_button.h" +#include "widgets/visibility.h" + +namespace ArdourWidgets { + +class LIBWIDGETS_API ArdourSpinner : public Gtk::Alignment +{ + public: + ArdourSpinner (boost::shared_ptr, Gtk::Adjustment* adj); + + virtual ~ArdourSpinner (); + + protected: + bool on_button_press_event (GdkEventButton*); + bool on_button_release_event (GdkEventButton*); + bool on_scroll_event (GdkEventScroll* ev); + + void controllable_changed (); + PBD::ScopedConnection watch_connection; + + private: + + bool entry_focus_out (GdkEventFocus*); + void entry_activated (); + gint switch_to_button (); + gint switch_to_spinner (); + + void ctrl_adjusted(); + void spin_adjusted(); + + ArdourWidgets::ArdourButton _btn; + Gtk::Adjustment* _ctrl_adj; + Gtk::Adjustment _spin_adj; + Gtk::SpinButton _spinner; + bool _switching; + bool _switch_on_release; + bool _ctrl_ignore; + bool _spin_ignore; + + boost::shared_ptr _controllable; + +}; + +} /* end namespace */ + +#endif diff --git a/libs/widgets/widgets/tooltips.h b/libs/widgets/widgets/tooltips.h new file mode 100644 index 0000000000..1a75e1c5eb --- /dev/null +++ b/libs/widgets/widgets/tooltips.h @@ -0,0 +1,41 @@ +/* + Copyright (C) 2014 Paul Davis + + This program is free software; you can redistribute it and/or modify + it under the terms of the GNU General Public License as published by + the Free Software Foundation; either version 2 of the License, or + (at your option) any later version. + + This program is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU General Public License + along with this program; if not, write to the Free Software + Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. + +*/ + +#ifndef _WIDGETS_TOOLTIPS_H_ +#define _WIDGETS_TOOLTIPS_H_ + +#include + +namespace Gtk { + class Widget; +} + +#include "widgets/visibility.h" + +namespace ArdourWidgets { + +extern LIBWIDGETS_API void set_tooltip (Gtk::Widget& w, const std::string& text); + +extern LIBWIDGETS_API void set_tooltip (Gtk::Widget* w, const std::string& text); + +extern LIBWIDGETS_API void set_tooltip (Gtk::Widget* w, const std::string& text, const std::string& help_text); + +} + +#endif diff --git a/libs/widgets/widgets/ui_config.h b/libs/widgets/widgets/ui_config.h new file mode 100644 index 0000000000..4087dae192 --- /dev/null +++ b/libs/widgets/widgets/ui_config.h @@ -0,0 +1,31 @@ +#ifndef _WIDGETS_UI_BASE_H_ +#define _WIDGETS_UI_BASE_H_ + +#include + +#include "pbd/stateful.h" +#include "canvas/colors.h" + +#include "widgets/visibility.h" + +namespace ArdourWidgets { + +class LIBWIDGETS_API UIConfigurationBase : public PBD::Stateful +{ +protected: + virtual ~UIConfigurationBase() { _instance = 0; } + static UIConfigurationBase* _instance; + +public: + static UIConfigurationBase& instance() { return *_instance; } + + sigc::signal DPIReset; + sigc::signal ColorsChanged; + + virtual float get_ui_scale () = 0; + virtual bool get_widget_prelight () const = 0; + virtual ArdourCanvas::Color color (const std::string&, bool* failed = 0) const = 0; +}; + +} +#endif diff --git a/libs/widgets/widgets/visibility.h b/libs/widgets/widgets/visibility.h new file mode 100644 index 0000000000..e12f2522ab --- /dev/null +++ b/libs/widgets/widgets/visibility.h @@ -0,0 +1,45 @@ +/* + Copyright (C) 2013 Paul Davis + + This program is free software; you can redistribute it and/or modify + it under the terms of the GNU General Public License as published by + the Free Software Foundation; either version 2 of the License, or + (at your option) any later version. + + This program is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU General Public License + along with this program; if not, write to the Free Software + Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. + +*/ + +#ifndef __libwidgets_visibility_h__ +#define __libwidgets_visibility_h__ + +#if defined(COMPILER_MSVC) + #define LIBWIDGETS_DLL_IMPORT __declspec(dllimport) + #define LIBWIDGETS_DLL_EXPORT __declspec(dllexport) + #define LIBWIDGETS_DLL_LOCAL +#else + #define LIBWIDGETS_DLL_IMPORT __attribute__ ((visibility ("default"))) + #define LIBWIDGETS_DLL_EXPORT __attribute__ ((visibility ("default"))) + #define LIBWIDGETS_DLL_LOCAL __attribute__ ((visibility ("hidden"))) +#endif + +#ifdef LIBWIDGETS_STATIC // libwidgets is not a DLL +#define LIBWIDGETS_API +#define LIBWIDGETS_LOCAL +#else + #ifdef LIBWIDGETS_DLL_EXPORTS // defined if we are building the libwidgets DLL (instead of using it) + #define LIBWIDGETS_API LIBWIDGETS_DLL_EXPORT + #else + #define LIBWIDGETS_API LIBWIDGETS_DLL_IMPORT + #endif + #define LIBWIDGETS_LOCAL LIBWIDGETS_DLL_LOCAL +#endif + +#endif /* __libwidgets_visibility_h__ */ diff --git a/libs/widgets/wscript b/libs/widgets/wscript new file mode 100644 index 0000000000..6432589177 --- /dev/null +++ b/libs/widgets/wscript @@ -0,0 +1,70 @@ +#!/usr/bin/env python +from waflib.extras import autowaf as autowaf +from waflib import Options +from waflib import TaskGen +import os + +# Version of this package (even if built as a child) +MAJOR = '0' +MINOR = '0' +MICRO = '0' +WIDGETS_VERSION = "%s.%s.%s" % (MAJOR, MINOR, MICRO) + +# Library version (UNIX style major, minor, micro) +# major increment <=> incompatible changes +# minor increment <=> compatible changes (additions) +# micro increment <=> no interface changes +WIDGETS_LIB_VERSION = '0.0.0' + +# Variables for 'waf dist' +APPNAME = 'widgets' +VERSION = WIDGETS_VERSION +I18N_PACKAGE = 'libwidgets' + +# Mandatory variables +top = '.' +out = 'build' + +widgets_sources = [ + 'ardour_button.cc', + 'ardour_display.cc', + 'ardour_dropdown.cc', + 'ardour_knob.cc', + 'ardour_spacer.cc', + 'ardour_spinner.cc', + 'tooltips.cc', + 'ui_config.cc', +] + +def options(opt): + autowaf.set_options(opt) + +def configure(conf): + conf.load ('compiler_cxx') + autowaf.configure(conf) + autowaf.check_pkg(conf, 'cairomm-1.0', uselib_store='CAIROMM', atleast_version='1.8.4') + +def build(bld): + # Library + if bld.is_defined ('INTERNAL_SHARED_LIBS'): + obj = bld.shlib(features = 'cxx cxxshlib', source=widgets_sources) + obj.defines = [ 'LIBWIDGETS_DLL_EXPORTS=1' ] + else: + obj = bld.stlib(features = 'cxx cxxstlib', source=widgets_sources) + obj.cxxflags = [ '-fPIC' ] + obj.cflags = [ '-fPIC' ] + obj.defines = [ ] + + obj.export_includes = ['.'] + obj.includes = ['.'] + obj.uselib = 'SIGCPP CAIROMM GTKMM BOOST XML' + obj.use = [ 'libpbd', 'libcanvas', 'libgtkmm2ext' ] + obj.name = 'libwidgets' + obj.target = 'widgets' + obj.vnum = WIDGETS_LIB_VERSION + obj.install_path = bld.env['LIBDIR'] + obj.defines += [ 'PACKAGE="' + I18N_PACKAGE + '"' ] + +def shutdown(): + autowaf.shutdown() + diff --git a/wscript b/wscript index ed45d7bad6..c0ee26f87d 100644 --- a/wscript +++ b/wscript @@ -220,6 +220,7 @@ children = [ 'libs/gtkmm2ext', 'libs/audiographer', 'libs/canvas', + 'libs/widgets', 'libs/plugins/reasonablesynth.lv2', 'libs/plugins/a-comp.lv2', 'libs/plugins/a-delay.lv2', -- cgit v1.2.3