diff options
Diffstat (limited to 'libs')
-rw-r--r-- | libs/widgets/ardour_button.cc | 1340 | ||||
-rw-r--r-- | libs/widgets/ardour_display.cc | 142 | ||||
-rw-r--r-- | libs/widgets/ardour_dropdown.cc | 166 | ||||
-rw-r--r-- | libs/widgets/ardour_knob.cc | 598 | ||||
-rw-r--r-- | libs/widgets/ardour_spacer.cc | 27 | ||||
-rw-r--r-- | libs/widgets/ardour_spinner.cc | 206 | ||||
-rw-r--r-- | libs/widgets/tooltips.cc | 40 | ||||
-rw-r--r-- | libs/widgets/ui_config.cc | 7 | ||||
-rw-r--r-- | libs/widgets/widgets/ardour_button.h | 221 | ||||
-rw-r--r-- | libs/widgets/widgets/ardour_display.h | 55 | ||||
-rw-r--r-- | libs/widgets/widgets/ardour_dropdown.h | 60 | ||||
-rw-r--r-- | libs/widgets/widgets/ardour_knob.h | 133 | ||||
-rw-r--r-- | libs/widgets/widgets/ardour_spacer.h | 53 | ||||
-rw-r--r-- | libs/widgets/widgets/ardour_spinner.h | 73 | ||||
-rw-r--r-- | libs/widgets/widgets/tooltips.h | 41 | ||||
-rw-r--r-- | libs/widgets/widgets/ui_config.h | 31 | ||||
-rw-r--r-- | libs/widgets/widgets/visibility.h | 45 | ||||
-rw-r--r-- | libs/widgets/wscript | 70 |
18 files changed, 3308 insertions, 0 deletions
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 <iostream> +#include <cmath> +#include <algorithm> + +#include <pangomm/layout.h> + +#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<Cairo::Context> 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<Controllable> c) +{ + watch_connection.disconnect (); + binding_proxy.set_controllable (c); +} + +void +ArdourButton::watch () +{ + boost::shared_ptr<Controllable> 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<Action> act) +{ + Gtkmm2ext::Activatable::set_related_action (act); + + if (_action) { + + action_tooltip_changed (); + action_sensitivity_changed (); + + Glib::RefPtr<ToggleAction> tact = Glib::RefPtr<ToggleAction>::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<ToggleAction> tact = Glib::RefPtr<ToggleAction>::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<Gtk::Style>&) +{ + _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<Gdk::Pixbuf>& 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<PBD::Controllable> c (binding_proxy.get_controllable ()); + if (c) { + PBD::Controllable::GUIFocusChanged (boost::weak_ptr<PBD::Controllable> (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<PBD::Controllable> ()); + } + + 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 <iostream> +#include <cmath> +#include <algorithm> + +#include <pangomm/layout.h> + +#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<PBD::Controllable> 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<PBD::Controllable> 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<Controllable> 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<PBD::Controllable> 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 <iostream> +#include <cmath> +#include <algorithm> + +#include <pangomm/layout.h> + +#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 <iostream> +#include <cmath> +#include <algorithm> + +#include <pangomm/layout.h> + +#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<Cairo::Context> 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<PBD::Controllable> 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<PBD::Controllable> 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<PBD::Controllable> 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<Controllable> 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<PBD::Controllable> 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<Gtk::Style>&) +{ + 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<PBD::Controllable> c (binding_proxy.get_controllable ()); + if (c) { + PBD::Controllable::GUIFocusChanged (boost::weak_ptr<PBD::Controllable> (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<PBD::Controllable> ()); + } + + 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 <robin@gareus.org> + * + * 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 <robin@gareus.org> + * 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<PBD::Controllable> 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<PBD::Controllable> 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 <list> +#include <stdint.h> + +#include <gtkmm/action.h> + +#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<void, GdkEventButton*> signal_led_clicked; + sigc::signal<void> signal_clicked; + + boost::shared_ptr<PBD::Controllable> get_controllable() { return binding_proxy.get_controllable(); } + void set_controllable (boost::shared_ptr<PBD::Controllable> c); + void watch (); + + void set_related_action (Glib::RefPtr<Gtk::Action>); + + bool on_button_press_event (GdkEventButton*); + bool on_button_release_event (GdkEventButton*); + + void set_image (const Glib::RefPtr<Gdk::Pixbuf>&); + + 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<Cairo::Context> const&, cairo_rectangle_t*); + void on_size_request (Gtk::Requisition* req); + void on_size_allocate (Gtk::Allocation&); + void on_style_changed (const Glib::RefPtr<Gtk::Style>&); + 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<Pango::Layout> _layout; + Glib::RefPtr<Gdk::Pixbuf> _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 <list> +#include <stdint.h> + +#include <gtkmm/action.h> +#include <gtkmm/menu.h> +#include <gtkmm/menuitem.h> + +#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<PBD::Controllable> get_controllable() { return binding_proxy.get_controllable(); } + void set_controllable (boost::shared_ptr<PBD::Controllable> 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 <list> +#include <stdint.h> + +#include <gtkmm/action.h> +#include <gtkmm/menu.h> +#include <gtkmm/menuitem.h> + +#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 <list> +#include <stdint.h> + +#include <gtkmm/action.h> + +#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<PBD::Controllable> get_controllable() { return binding_proxy.get_controllable(); } + void set_controllable (boost::shared_ptr<PBD::Controllable> 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<Cairo::Context> const&, cairo_rectangle_t*); + void on_size_request (Gtk::Requisition* req); + void on_size_allocate (Gtk::Allocation&); + void on_style_changed (const Glib::RefPtr<Gtk::Style>&); + 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 <robin@gareus.org> + * + * 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<Cairo::Context> 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 <robin@gareus.org> + * 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 <boost/algorithm/string.hpp> +#include <gtkmm.h> + +#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<PBD::Controllable>, 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<PBD::Controllable> _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 <string> + +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 <cassert> + +#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<void> DPIReset; + sigc::signal<void> 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() + |