X-Git-Url: https://main.carlh.net/gitweb/?a=blobdiff_plain;f=gtk2_ardour%2Fpanner.cc;h=145ef020e3fc1deeecda716ecd1c22e24d208be5;hb=756ffc26bffa6a6c9276d6f4fff5b47cc54ad35a;hp=49bdf778e43a2253f560aed7a490b6a4e5e76004;hpb=02f714b8c9052e5ada0431df0be00f684294739d;p=ardour.git diff --git a/gtk2_ardour/panner.cc b/gtk2_ardour/panner.cc index 49bdf778e4..145ef020e3 100644 --- a/gtk2_ardour/panner.cc +++ b/gtk2_ardour/panner.cc @@ -1,22 +1,36 @@ -#include +/* + Copyright (C) 2000-2007 Paul Davis -#include "panner.h" + 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. -using namespace std; + 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. -static const int triangle_size = 7; + 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. -static void -null_label_callback (char* buf, unsigned int bufsize) -{ - /* no label */ +*/ - buf[0] = '\0'; -} +#include +#include +#include +#include "ardour/panner.h" +#include "panner.h" +#include "i18n.h" +using namespace std; +using namespace Gtk; + +static const int triangle_size = 5; -PannerBar::PannerBar (Gtk::Adjustment& adj, PBD::Controllable& c) - : BarController (adj, c, sigc::ptr_fun (null_label_callback)) +PannerBar::PannerBar (Adjustment& adj, boost::shared_ptr c) + : BarController (adj, c) { set_style (BarController::Line); } @@ -38,13 +52,13 @@ PannerBar::expose (GdkEventExpose* ev) GdkPoint points[3]; // left - + points[0].x = 0; points[0].y = 0; points[1].x = triangle_size; points[1].y = 0; - + points[2].x = 0; points[2].y = triangle_size; @@ -52,25 +66,25 @@ PannerBar::expose (GdkEventExpose* ev) // center - points[0].x = darea.get_width()/2 - (triangle_size - 2); + points[0].x = (darea.get_width()/2 - triangle_size); points[0].y = 0; - points[1].x = darea.get_width()/2 + (triangle_size - 2); + points[1].x = (darea.get_width()/2 + triangle_size); points[1].y = 0; - - points[2].x = darea.get_width()/2 - 1; - points[2].y = triangle_size - 3; - gdk_draw_polygon (win->gobj(), gc->gobj(), true, points, 3); + points[2].x = darea.get_width()/2; + points[2].y = triangle_size - 1; + + gdk_draw_polygon (win->gobj(), gc->gobj(), true, points, 3); // right - points[0].x = darea.get_width() - triangle_size; + points[0].x = (darea.get_width() - triangle_size); points[0].y = 0; points[1].x = darea.get_width(); points[1].y = 0; - + points[2].x = darea.get_width(); points[2].y = triangle_size; @@ -84,12 +98,12 @@ PannerBar::button_press (GdkEventButton* ev) { if (ev->button == 1 && ev->type == GDK_BUTTON_PRESS && ev->y < 10) { if (ev->x < triangle_size) { - return true; + adjustment.set_value (adjustment.get_lower()); } else if (ev->x > (darea.get_width() - triangle_size)) { - return true; + adjustment.set_value (adjustment.get_upper()); } else if (ev->x > (darea.get_width()/2 - triangle_size) && ev->x < (darea.get_width()/2 + triangle_size)) { - return true; + adjustment.set_value (adjustment.get_lower() + ((adjustment.get_upper() - adjustment.get_lower()) / 2.0)); } } @@ -99,26 +113,90 @@ PannerBar::button_press (GdkEventButton* ev) bool PannerBar::button_release (GdkEventButton* ev) { - if (ev->button == 1 && ev->type == GDK_BUTTON_RELEASE && ev->y < 10) { - if (ev->x < triangle_size) { - adjustment.set_value (adjustment.get_lower()); - return true; - } else if (ev->x > (darea.get_width() - triangle_size)) { - adjustment.set_value (adjustment.get_upper()); - return true; - } else if (ev->x > (darea.get_width()/2 - triangle_size) && - ev->x < (darea.get_width()/2 + triangle_size)) { - adjustment.set_value (adjustment.get_lower() + ((adjustment.get_upper() - adjustment.get_lower()) / 2.0)); - return true; + bool const r = BarController::button_release (ev); + + /* get rid of any `C' labels that may exist */ + queue_draw (); + return r; +} + +bool +PannerBar::entry_input (double *new_value) +{ + Entry* e = dynamic_cast (&spinner); + string const text = e->get_text (); + + string digits; + string letters; + + string const L = _("L"); + string const C = _("C"); + string const R = _("R"); + + for (string::size_type i = 0; i < text.length(); ++i) { + if (isdigit (text[i])) { + digits += text[i]; + } else if (text[i] != '%') { + letters += text[i]; } } - return BarController::button_release (ev); + if (letters.empty()) { + /* no letter specified, so take any number as a percentage where + * 0 is left and 100 right */ + *new_value = digits.empty() ? 0.5 : (atoi (digits.c_str()) / 100.0); + } else { + /* letter given, so value is a percentage to the extreme + * (e.g. 100L is full left, 1L is slightly left */ + if (letters[0] == L[0] || letters[0] == tolower (L[0])) { + *new_value = digits.empty() ? 0 : (0.5 - atoi (digits.c_str()) / 200.0); + } else if (letters[0] == R[0] || letters[0] == tolower (R[0])) { + *new_value = digits.empty() ? 1 : 0.5 + atoi (digits.c_str()) / 200.0; + } else if (letters[0] == C[0] || letters[0] == tolower (C[0])) { + *new_value = 0.5; + } + } + + return true; } -void -PannerBar::on_size_request (Gtk::Requisition* req) +bool +PannerBar::entry_output () { - req->width = -1; - req->height = 50; + Entry* e = dynamic_cast (&spinner); + e->set_text (ARDOUR::Panner::value_as_string (spinner.get_adjustment()->get_value())); + return true; +} + +std::string +PannerBar::get_label (int& x) +{ + double const value = spinner.get_adjustment()->get_value (); + + if (ARDOUR::Panner::equivalent (value, 0.5)) { + + /* centre: only display text during a drag */ + + if (!grabbed) { + return ""; + } + + } else { + + /* non-centre: display text on the side of the panner which has more space */ + + Glib::RefPtr p = get_pango_context (); + Glib::RefPtr l = Pango::Layout::create (p); + l->set_text (ARDOUR::Panner::value_as_string (value)); + + Pango::Rectangle const ext = l->get_ink_extents (); + + if (value < 0.5) { + x = (darea.get_width() - 4 - ext.get_width() / Pango::SCALE); + } else { + x = 4; + } + } + + return ARDOUR::Panner::value_as_string (value); }