fixed typo
[ardour.git] / gtk2_ardour / panner.cc
1 /*
2     Copyright (C) 2000-2007 Paul Davis 
3
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.
8
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.
13
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.
17
18 */
19
20 #include <iostream>
21
22 #include "panner.h"
23
24 using namespace std;
25
26 static const int triangle_size = 5;
27
28 static void
29 null_label_callback (char* buf, unsigned int bufsize)
30 {
31         /* no label */
32
33         buf[0] = '\0';
34 }
35
36
37 PannerBar::PannerBar (Gtk::Adjustment& adj, boost::shared_ptr<PBD::Controllable> c)
38         : BarController (adj, *c.get(), sigc::ptr_fun (null_label_callback))
39 {
40         set_style (BarController::Line);
41 }
42
43 PannerBar::~PannerBar ()
44 {
45 }
46
47 bool
48 PannerBar::expose (GdkEventExpose* ev)
49 {
50         Glib::RefPtr<Gdk::Window> win (darea.get_window());
51         Glib::RefPtr<Gdk::GC> gc (get_style()->get_base_gc (get_state()));
52
53         BarController::expose (ev);
54
55         /* now draw triangles for left, right and center */
56
57         GdkPoint points[3];
58
59         // left
60         
61         points[0].x = 0;
62         points[0].y = 0;
63
64         points[1].x = triangle_size;
65         points[1].y = 0;
66         
67         points[2].x = 0;
68         points[2].y = triangle_size;
69
70         gdk_draw_polygon (win->gobj(), gc->gobj(), true, points, 3);
71
72         // center
73
74         points[0].x = (darea.get_width()/2 - triangle_size);
75         points[0].y = 0;
76
77         points[1].x = (darea.get_width()/2 + triangle_size);
78         points[1].y = 0;
79         
80         points[2].x = darea.get_width()/2;
81         points[2].y = triangle_size - 1;
82
83         gdk_draw_polygon (win->gobj(), gc->gobj(), true, points, 3); 
84
85         // right
86
87         points[0].x = (darea.get_width() - triangle_size);
88         points[0].y = 0;
89
90         points[1].x = darea.get_width();
91         points[1].y = 0;
92         
93         points[2].x = darea.get_width();
94         points[2].y = triangle_size;
95
96         gdk_draw_polygon (win->gobj(), gc->gobj(), true, points, 3);
97
98         return true;
99 }
100
101 bool
102 PannerBar::button_press (GdkEventButton* ev)
103 {
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));
112                 }
113         }
114
115         return BarController::button_press (ev);
116 }
117
118 bool
119 PannerBar::button_release (GdkEventButton* ev)
120 {
121         return BarController::button_release (ev);
122 }
123