X-Git-Url: https://main.carlh.net/gitweb/?a=blobdiff_plain;f=gtk2_ardour%2Fpanner2d.cc;h=69326f8fba86e1893f13b8bc33382d41288d2781;hb=4050ca5633dda03679f9aa9fab87d3bbf517395b;hp=a3befff5cf8a78c07d069115f40521d621aa9dda;hpb=58def58bf50f29e42babdb5de7ca34819c00909f;p=ardour.git diff --git a/gtk2_ardour/panner2d.cc b/gtk2_ardour/panner2d.cc index a3befff5cf..69326f8fba 100644 --- a/gtk2_ardour/panner2d.cc +++ b/gtk2_ardour/panner2d.cc @@ -1,21 +1,25 @@ /* - Copyright (C) 2002 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. - -*/ + * Copyright (C) 2005-2016 Paul Davis + * Copyright (C) 2005 Taybin Rutkin + * Copyright (C) 2008-2011 David Robillard + * Copyright (C) 2010-2011 Carl Hetherington + * Copyright (C) 2014-2019 Robin Gareus + * Copyright (C) 2015 Tim Mayberry + * + * 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 #include @@ -33,20 +37,28 @@ #include "ardour/pannable.h" #include "ardour/speakers.h" +#include "gtkmm2ext/colors.h" + #include "panner2d.h" #include "keyboard.h" #include "gui_thread.h" +#include "rgb_macros.h" #include "utils.h" #include "public_editor.h" +#include "ui_config.h" -#include "i18n.h" +#include "pbd/i18n.h" using namespace std; using namespace Gtk; using namespace ARDOUR; +using namespace ARDOUR_UI_UTILS; using namespace PBD; using Gtkmm2ext::Keyboard; +Panner2d::ColorScheme Panner2d::colors; +bool Panner2d::have_colors = false; + static const int large_size_threshold = 100; static const int large_border_width = 25; static const int small_border_width = 8; @@ -75,7 +87,15 @@ Panner2d::Panner2d (boost::shared_ptr p, int32_t h) , height (h) , last_width (0) , have_elevation (false) + , _send_mode (false) { + if (!have_colors) { + set_colors (); + have_colors = true; + } + + UIConfiguration::instance().ColorsChanged.connect (sigc::mem_fun (*this, &Panner2d::color_handler)); + panner_shell->Changed.connect (panshell_connections, invalidator (*this), boost::bind (&Panner2d::handle_state_change, this), gui_context()); panner_shell->panner()->SignalPositionChanged.connect (panner_connections, invalidator(*this), boost::bind (&Panner2d::handle_position_change, this), gui_context()); @@ -92,6 +112,34 @@ Panner2d::~Panner2d() for (Targets::iterator i = speakers.begin(); i != speakers.end(); ++i) { delete *i; } + for (Targets::iterator i = signals.begin(); i != signals.end(); ++i) { + delete *i; + } +} + +void +Panner2d::set_colors () +{ + // TODO get all colors from theme, resolve dups + colors.background = UIConfiguration::instance().color ("mono panner bg"); + colors.crosshairs = 0x4884a9ff; // 0.282, 0.517, 0.662, 1.0 + colors.signalcircle_border = 0x84c5e1ff; // 0.517, 0.772, 0.882, 1.0 + colors.signalcircle = 0x4884a9ff; // 0.282, 0.517, 0.662, 1.0 // also used with a = 0.9 + colors.diffusion = 0x4884a973; // 0.282, 0.517, 0.662, 0.45 + colors.diffusion_inv = 0xff6b6b73; // 1.0, 0.419, 0.419, 0.45 + colors.pos_outline = 0xffe7e7d9; // 1.0, 0.905, 0.905, 0.85 + colors.pos_fill = 0xff6b6bd9; // 1.0, 0.419, 0.419, 0.85 + colors.signal_outline = 0x84c5e1cc; // 0.517, 0.772, 0.882, 0.8 + colors.signal_fill = 0x4884a9bf; // 0.282, 0.517, 0.662, 0.75 + colors.speaker_fill = 0x4884a9ff; // 0.282, 0.517, 0.662, 1.0 + colors.text = 0x84c5e1e6; // 0.517, 0.772, 0.882, 0.9 +} + +void +Panner2d::color_handler () +{ + set_colors (); + queue_draw (); } void @@ -232,8 +280,8 @@ Panner2d::label_signals () break; case 2: - signals[0]->set_text (_("L")); - signals[1]->set_text (_("R")); + signals[0]->set_text (S_("Panner|L")); + signals[1]->set_text (S_("Panner|R")); break; default: @@ -252,8 +300,8 @@ Panner2d::handle_position_change () uint32_t n; double w = panner_shell->pannable()->pan_width_control->get_value(); - position.position = AngularVector (panner_shell->pannable()->pan_azimuth_control->get_value() * 360.0, - panner_shell->pannable()->pan_elevation_control->get_value() * 90.0); + position.position = AngularVector (panner_shell->pannable()->pan_azimuth_control->get_value() * 360.0, + panner_shell->pannable()->pan_elevation_control->get_value() * 90.0); for (uint32_t i = 0; i < signals.size(); ++i) { signals[i]->position = panner_shell->panner()->signal_position (i); @@ -297,10 +345,10 @@ Panner2d::find_closest_object (gdouble x, gdouble y, bool& is_signal) /* start with the position itself */ - PBD::AngularVector dp = position.position; - if (!have_elevation) dp.ele = 0; - dp.azi = 270 - dp.azi; - dp.cartesian (c); + PBD::AngularVector dp = position.position; + if (!have_elevation) dp.ele = 0; + dp.azi = 270 - dp.azi; + dp.cartesian (c); cart_to_gtk (c); best_distance = sqrt ((c.x - x) * (c.x - x) + @@ -343,11 +391,11 @@ Panner2d::find_closest_object (gdouble x, gdouble y, bool& is_signal) if (!closest) { for (Targets::const_iterator i = speakers.begin(); i != speakers.end(); ++i) { candidate = *i; - PBD::AngularVector sp = candidate->position; - sp.azi = 270 -sp.azi; - CartesianVector c; - sp.cartesian (c); - cart_to_gtk (c); + PBD::AngularVector sp = candidate->position; + sp.azi = 270 -sp.azi; + CartesianVector c; + sp.cartesian (c); + cart_to_gtk (c); distance = sqrt ((c.x - x) * (c.x - x) + (c.y - y) * (c.y - y)); @@ -378,6 +426,15 @@ Panner2d::find_closest_object (gdouble x, gdouble y, bool& is_signal) return closest; } +void +Panner2d::set_send_drawing_mode (bool onoff) +{ + if (_send_mode != onoff) { + _send_mode = onoff; + queue_draw (); + } +} + bool Panner2d::on_motion_notify_event (GdkEventMotion *ev) { @@ -399,12 +456,17 @@ Panner2d::on_motion_notify_event (GdkEventMotion *ev) return handle_motion (x, y, state); } +#define CSSRGBA(CL) \ + cairo_set_source_rgba (cr, UINT_RGBA_R_FLT(CL), UINT_RGBA_G_FLT(CL), UINT_RGBA_B_FLT(CL), UINT_RGBA_A_FLT(CL)); + +#define CSSRGB(CL, A) \ + cairo_set_source_rgba (cr, UINT_RGBA_R_FLT(CL), UINT_RGBA_G_FLT(CL), UINT_RGBA_B_FLT(CL), A); bool Panner2d::on_expose_event (GdkEventExpose *event) { CartesianVector c; cairo_t* cr; - bool small = (height <= large_size_threshold); + bool xsmall = (height <= large_size_threshold); const double diameter = radius*2.0; cr = gdk_cairo_create (get_window()->gobj()); @@ -412,10 +474,16 @@ Panner2d::on_expose_event (GdkEventExpose *event) /* background */ cairo_rectangle (cr, event->area.x, event->area.y, event->area.width, event->area.height); + + uint32_t bg = colors.background; + if (_send_mode) { + bg = UIConfiguration::instance().color ("send bg"); + } + if (!panner_shell->bypassed()) { - cairo_set_source_rgba (cr, 0.1, 0.1, 0.1, 1.0); + CSSRGBA(bg); } else { - cairo_set_source_rgba (cr, 0.1, 0.1, 0.1, 0.2); + CSSRGB(bg, 0.2); } cairo_fill_preserve (cr); cairo_clip (cr); @@ -428,7 +496,7 @@ Panner2d::on_expose_event (GdkEventExpose *event) /* horizontal line of "crosshairs" */ - cairo_set_source_rgba (cr, 0.282, 0.517, 0.662, 1.0); + CSSRGBA(colors.crosshairs); cairo_move_to (cr, 0.0, radius); cairo_line_to (cr, diameter, radius); cairo_stroke (cr); @@ -442,16 +510,16 @@ Panner2d::on_expose_event (GdkEventExpose *event) /* the circle on which signals live */ cairo_set_line_width (cr, 1.5); - cairo_set_source_rgba (cr, 0.517, 0.772, 0.882, 1.0); + CSSRGBA(colors.signalcircle_border); cairo_arc (cr, radius, radius, radius, 0.0, 2.0 * M_PI); cairo_stroke (cr); for (uint32_t rad = 15; rad < 90; rad += 15) { cairo_set_line_width (cr, .5 + (float)rad / 150.0); if (rad == 45) { - cairo_set_source_rgba (cr, 0.282, 0.517, 0.662, 1.0); + CSSRGBA(colors.signalcircle); } else { - cairo_set_source_rgba (cr, 0.282, 0.517, 0.662, 0.8); + CSSRGB(colors.signalcircle, 0.9); } cairo_new_path (cr); cairo_arc (cr, radius, radius, radius * sin(M_PI * (float) rad / 180.0), 0, 2.0 * M_PI); @@ -459,7 +527,7 @@ Panner2d::on_expose_event (GdkEventExpose *event) } if (!panner_shell->bypassed()) { - /* convention top == front ^= azimuth == .5 (same as stereo/mono panners) */ + /* convention top == front ^= azimuth == .5 (same as stereo/mono panners) */ if (signals.size() > 1) { /* arc to show "diffusion" */ @@ -469,17 +537,17 @@ Panner2d::on_expose_event (GdkEventExpose *event) cairo_save (cr); cairo_translate (cr, radius, radius); - cairo_rotate (cr, M_PI / 2.0); + cairo_rotate (cr, M_PI / 2.0); cairo_rotate (cr, position_angle - (width_angle/2.0)); cairo_move_to (cr, 0, 0); cairo_arc_negative (cr, 0, 0, radius, width_angle, 0.0); cairo_close_path (cr); if (panner_shell->pannable()->pan_width_control->get_value() >= 0.0) { /* normal width */ - cairo_set_source_rgba (cr, 0.282, 0.517, 0.662, 0.45); + CSSRGBA(colors.diffusion); } else { /* inverse width */ - cairo_set_source_rgba (cr, 1.0, 0.419, 0.419, 0.45); + CSSRGBA(colors.diffusion_inv); } cairo_fill (cr); cairo_restore (cr); @@ -489,7 +557,7 @@ Panner2d::on_expose_event (GdkEventExpose *event) cairo_select_font_face (cr, "sans", CAIRO_FONT_SLANT_NORMAL, CAIRO_FONT_WEIGHT_NORMAL); - if (small) { + if (xsmall) { arc_radius = 4.0; } else { cairo_set_font_size (cr, 10); @@ -498,17 +566,17 @@ Panner2d::on_expose_event (GdkEventExpose *event) /* draw position */ - PBD::AngularVector dp = position.position; - if (!have_elevation) dp.ele = 0; - dp.azi = 270 - dp.azi; + PBD::AngularVector dp = position.position; + if (!have_elevation) dp.ele = 0; + dp.azi = 270 - dp.azi; dp.cartesian (c); cart_to_gtk (c); cairo_new_path (cr); cairo_arc (cr, c.x, c.y, arc_radius + 1.0, 0, 2.0 * M_PI); - cairo_set_source_rgba (cr, 1.0, 0.419, 0.419, 0.85); + CSSRGBA(colors.pos_fill); cairo_fill_preserve (cr); - cairo_set_source_rgba (cr, 1.0, 0.905, 0.905, 0.85); + CSSRGBA(colors.pos_outline); cairo_stroke (cr); /* signals */ @@ -524,23 +592,23 @@ Panner2d::on_expose_event (GdkEventExpose *event) */ PBD::AngularVector sp = signal->position; if (!have_elevation) sp.ele = 0; - sp.azi += 270.0; + sp.azi += 270.0; sp.cartesian (c); cart_to_gtk (c); cairo_new_path (cr); cairo_arc (cr, c.x, c.y, arc_radius, 0, 2.0 * M_PI); - cairo_set_source_rgba (cr, 0.282, 0.517, 0.662, 0.75); + CSSRGBA(colors.signal_fill); cairo_fill_preserve (cr); - cairo_set_source_rgba (cr, 0.517, 0.772, 0.882, 0.8); + CSSRGBA(colors.signal_outline); cairo_stroke (cr); - if (!small && !signal->text.empty()) { - cairo_set_source_rgba (cr, 0.517, 0.772, 0.882, .9); + if (!xsmall && !signal->text.empty()) { + CSSRGBA(colors.text); /* the +/- adjustments are a hack to try to center the text in the circle * TODO use pango get_pixel_size() -- see mono_panner.cc */ - if (small) { + if (xsmall) { cairo_move_to (cr, c.x - 1, c.y + 1); } else { cairo_move_to (cr, c.x - 4, c.y + 4); @@ -562,8 +630,8 @@ Panner2d::on_expose_event (GdkEventExpose *event) if (speaker->visible) { - PBD::AngularVector sp = speaker->position; - sp.azi += 270.0; + PBD::AngularVector sp = speaker->position; + sp.azi += 270.0; CartesianVector c; sp.cartesian (c); cart_to_gtk (c); @@ -575,7 +643,7 @@ Panner2d::on_expose_event (GdkEventExpose *event) cairo_move_to (cr, c.x, c.y); cairo_save (cr); cairo_rotate (cr, -(sp.azi/360.0) * (2.0 * M_PI)); - if (small) { + if (xsmall) { cairo_scale (cr, 0.8, 0.8); } else { cairo_scale (cr, 1.2, 1.2); @@ -589,11 +657,11 @@ Panner2d::on_expose_event (GdkEventExpose *event) cairo_rel_line_to (cr, -5, +5); cairo_rel_line_to (cr, 0, -7); cairo_close_path (cr); - cairo_set_source_rgba (cr, 0.282, 0.517, 0.662, 1.0); + CSSRGBA(colors.speaker_fill); cairo_fill (cr); cairo_restore (cr); - if (!small) { + if (!xsmall) { cairo_set_font_size (cr, 16); /* move the text in just a bit */ @@ -619,29 +687,29 @@ bool Panner2d::on_button_press_event (GdkEventButton *ev) { GdkModifierType state; - int x; - int y; - bool is_signal; + int x; + int y; + bool is_signal; if (ev->type == GDK_2BUTTON_PRESS && ev->button == 1) { return false; } - did_move = false; + did_move = false; switch (ev->button) { case 1: case 2: - x = ev->x - hoffset; - y = ev->y - voffset; + x = ev->x - hoffset; + y = ev->y - voffset; if ((drag_target = find_closest_object (x, y, is_signal)) != 0) { - if (!is_signal) { - panner_shell->panner()->set_position (drag_target->position.azi/360.0); - drag_target = 0; - } else { - drag_target->set_selected (true); - } + if (!is_signal) { + panner_shell->panner()->set_position (drag_target->position.azi/360.0); + drag_target = 0; + } else { + drag_target->set_selected (true); + } } state = (GdkModifierType) ev->state; @@ -667,7 +735,7 @@ Panner2d::on_button_release_event (GdkEventButton *ev) x = (int) floor (ev->x); y = (int) floor (ev->y); state = (GdkModifierType) ev->state; - ret = handle_motion (x, y, state); + ret = handle_motion (x, y, state); drag_target = 0; break; @@ -727,7 +795,7 @@ Panner2d::handle_motion (gint evx, gint evy, GdkModifierType state) if (!have_elevation) { clamp_to_circle (cp.x, cp.y); cp.angular (av); - av.azi = fmod(270 - av.azi, 360); + av.azi = fmod(270 - av.azi, 360); if (drag_target == &position) { double degree_fract = av.azi / 360.0; panner_shell->panner()->set_position (degree_fract); @@ -739,7 +807,7 @@ Panner2d::handle_motion (gint evx, gint evy, GdkModifierType state) double r2d = 180.0 / M_PI; av.azi = r2d * atan2(cp.y, cp.x); av.ele = r2d * asin(cp.z); - av.azi = fmod(270 - av.azi, 360); + av.azi = fmod(270 - av.azi, 360); if (drag_target == &position) { double azi_fract = av.azi / 360.0; @@ -757,47 +825,47 @@ Panner2d::handle_motion (gint evx, gint evy, GdkModifierType state) bool Panner2d::on_scroll_event (GdkEventScroll* ev) { - switch (ev->direction) { - case GDK_SCROLL_UP: - case GDK_SCROLL_RIGHT: - panner_shell->panner()->set_position (panner_shell->pannable()->pan_azimuth_control->get_value() - 1.0/360.0); - break; + switch (ev->direction) { + case GDK_SCROLL_UP: + case GDK_SCROLL_RIGHT: + panner_shell->panner()->set_position (panner_shell->pannable()->pan_azimuth_control->get_value() - 1.0/360.0); + break; - case GDK_SCROLL_DOWN: - case GDK_SCROLL_LEFT: - panner_shell->panner()->set_position (panner_shell->pannable()->pan_azimuth_control->get_value() + 1.0/360.0); - break; - } - return true; + case GDK_SCROLL_DOWN: + case GDK_SCROLL_LEFT: + panner_shell->panner()->set_position (panner_shell->pannable()->pan_azimuth_control->get_value() + 1.0/360.0); + break; + } + return true; } void Panner2d::cart_to_gtk (CartesianVector& c) const { /* cartesian coordinate space: - center = 0.0 - dimension = 2.0 * 2.0 - increasing y moves up - so max values along each axis are -1..+1 - - GTK uses a coordinate space that is: - top left = 0.0 - dimension = (radius*2.0) * (radius*2.0) - increasing y moves down + * center = 0.0 + * dimension = 2.0 * 2.0 + * increasing y moves up + * so max values along each axis are -1..+1 + * + * GTK uses a coordinate space that is: + * top left = 0.0 + * dimension = (radius*2.0) * (radius*2.0) + * increasing y moves down */ - const double diameter = radius*2.0; + const double diameter = radius*2.0; - c.x = diameter * ((c.x + 1.0) / 2.0); - /* extra subtraction inverts the y-axis to match "increasing y moves down" */ - c.y = diameter - (diameter * ((c.y + 1.0) / 2.0)); + c.x = diameter * ((c.x + 1.0) / 2.0); + /* extra subtraction inverts the y-axis to match "increasing y moves down" */ + c.y = diameter - (diameter * ((c.y + 1.0) / 2.0)); } void Panner2d::gtk_to_cart (CartesianVector& c) const { - const double diameter = radius*2.0; + const double diameter = radius*2.0; c.x = ((c.x / diameter) * 2.0) - 1.0; - c.y = (((diameter - c.y) / diameter) * 2.0) - 1.0; + c.y = (((diameter - c.y) / diameter) * 2.0) - 1.0; } void @@ -952,7 +1020,7 @@ Panner2dWindow::set_width () bool Panner2dWindow::on_key_press_event (GdkEventKey* event) { - return relay_key_press (event, &PublicEditor::instance()); + return relay_key_press (event, this); } bool