fix keyboard event handling for host-provided plugin GUIs
[ardour2.git] / gtk2_ardour / panner.cc
blob23fae953a16042e4aa8cefad8c453cf833250e18
1 /*
2 Copyright (C) 2000-2007 Paul Davis
4 This program is free software; you can redistribute it and/or modify
5 it under the terms of the GNU General Public License as published by
6 the Free Software Foundation; either version 2 of the License, or
7 (at your option) any later version.
9 This program is distributed in the hope that it will be useful,
10 but WITHOUT ANY WARRANTY; without even the implied warranty of
11 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 GNU General Public License for more details.
14 You should have received a copy of the GNU General Public License
15 along with this program; if not, write to the Free Software
16 Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
20 #include <iostream>
22 #include "panner.h"
24 using namespace std;
26 static const int triangle_size = 5;
28 static void
29 null_label_callback (char* buf, unsigned int bufsize)
31 /* no label */
33 buf[0] = '\0';
37 PannerBar::PannerBar (Gtk::Adjustment& adj, PBD::Controllable& c)
38 : BarController (adj, c, sigc::ptr_fun (null_label_callback))
40 set_style (BarController::Line);
43 PannerBar::~PannerBar ()
47 bool
48 PannerBar::expose (GdkEventExpose* ev)
50 Glib::RefPtr<Gdk::Window> win (darea.get_window());
51 Glib::RefPtr<Gdk::GC> gc (get_style()->get_base_gc (get_state()));
53 BarController::expose (ev);
55 /* now draw triangles for left, right and center */
57 GdkPoint points[3];
59 // left
61 points[0].x = 0;
62 points[0].y = 0;
64 points[1].x = triangle_size;
65 points[1].y = 0;
67 points[2].x = 0;
68 points[2].y = triangle_size;
70 gdk_draw_polygon (win->gobj(), gc->gobj(), true, points, 3);
72 // center
74 points[0].x = (darea.get_width()/2 - triangle_size);
75 points[0].y = 0;
77 points[1].x = (darea.get_width()/2 + triangle_size);
78 points[1].y = 0;
80 points[2].x = darea.get_width()/2;
81 points[2].y = triangle_size - 1;
83 gdk_draw_polygon (win->gobj(), gc->gobj(), true, points, 3);
85 // right
87 points[0].x = (darea.get_width() - triangle_size);
88 points[0].y = 0;
90 points[1].x = darea.get_width();
91 points[1].y = 0;
93 points[2].x = darea.get_width();
94 points[2].y = triangle_size;
96 gdk_draw_polygon (win->gobj(), gc->gobj(), true, points, 3);
98 return true;
101 bool
102 PannerBar::button_press (GdkEventButton* ev)
104 if (ev->button == 1 && ev->type == GDK_BUTTON_PRESS && ev->y < 10) {
105 if (ev->x < triangle_size) {
106 adjustment.set_value (adjustment.get_lower());
107 } else if (ev->x > (darea.get_width() - triangle_size)) {
108 adjustment.set_value (adjustment.get_upper());
109 } else if (ev->x > (darea.get_width()/2 - triangle_size) &&
110 ev->x < (darea.get_width()/2 + triangle_size)) {
111 adjustment.set_value (adjustment.get_lower() + ((adjustment.get_upper() - adjustment.get_lower()) / 2.0));
115 return BarController::button_press (ev);
118 bool
119 PannerBar::button_release (GdkEventButton* ev)
121 return BarController::button_release (ev);