switch cartesian/spherical function names and make them use length. still a tweak...
[ardour2.git] / gtk2_ardour / panner2d.h
blob4fbf0e131fd5f06e50aae5ff6e5816f9b296e1b3
1 /*
2 Copyright (C) 2002 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 #ifndef __ardour_panner_2d_h__
21 #define __ardour_panner_2d_h__
23 #include <sys/types.h>
24 #include <map>
25 #include <vector>
27 #include <glibmm/refptr.h>
28 #include <gtkmm/drawingarea.h>
29 #include <gtkmm/window.h>
30 #include <gtkmm/box.h>
31 #include <gtkmm/button.h>
32 #include <gtkmm/spinbutton.h>
33 #include <gtkmm/adjustment.h>
35 #include "pbd/cartesian.h"
37 #include "ardour_dialog.h"
39 namespace ARDOUR {
40 class Panner;
43 namespace Gtk {
44 class Menu;
45 class CheckMenuItem;
48 namespace Pango {
49 class Layout;
52 class Panner2dWindow;
54 class Panner2d : public Gtk::DrawingArea
56 public:
57 Panner2d (boost::shared_ptr<ARDOUR::Panner>, int32_t height);
58 ~Panner2d ();
60 void allow_target_motion (bool);
62 int add_target (const PBD::AngularVector&);
63 int add_puck (const char* text, const PBD::AngularVector&);
64 void move_puck (int which, const PBD::AngularVector&);
65 void reset (uint32_t n_inputs);
67 boost::shared_ptr<ARDOUR::Panner> get_panner() const { return panner; }
69 sigc::signal<void,int> PuckMoved;
70 sigc::signal<void,int> TargetMoved;
72 void cart_to_gtk (PBD::CartesianVector&) const;
73 void gtk_to_cart (PBD::CartesianVector&) const;
75 protected:
76 bool on_expose_event (GdkEventExpose *);
77 bool on_button_press_event (GdkEventButton *);
78 bool on_button_release_event (GdkEventButton *);
79 bool on_motion_notify_event (GdkEventMotion *);
80 bool on_scroll_event (GdkEventScroll *);
81 void on_size_allocate (Gtk::Allocation& alloc);
83 private:
84 class Target {
85 public:
86 PBD::AngularVector position;
87 bool visible;
88 std::string text;
90 Target (const PBD::AngularVector&, const char* txt = 0);
91 ~Target ();
93 void set_text (const char*);
94 void set_selected (bool yn) {
95 _selected = yn;
97 bool selected() const {
98 return _selected;
101 private:
102 bool _selected;
105 boost::shared_ptr<ARDOUR::Panner> panner;
106 Glib::RefPtr<Pango::Layout> layout;
108 typedef std::vector<Target*> Targets;
109 Targets targets;
110 Targets pucks;
111 Target position;
113 Target *drag_target;
114 int drag_x;
115 int drag_y;
116 bool allow_target;
117 int width;
118 int height;
119 int dimen;
121 bool bypassflag;
123 gint compute_x (float);
124 gint compute_y (float);
126 Target *find_closest_object (gdouble x, gdouble y);
128 gint handle_motion (gint, gint, GdkModifierType);
130 void toggle_bypass ();
131 void handle_state_change ();
132 void handle_position_change ();
134 PBD::ScopedConnectionList connections;
136 /* cartesian coordinates in GTK units ; adjust to same but on a circle of radius 1.0
137 and centered in the middle of our area
139 void clamp_to_circle (double& x, double& y);
142 class Panner2dWindow : public ArdourDialog
144 public:
145 Panner2dWindow (boost::shared_ptr<ARDOUR::Panner>, int32_t height, uint32_t inputs);
147 void reset (uint32_t n_inputs);
149 private:
150 Panner2d widget;
152 Gtk::HBox hpacker;
153 Gtk::VBox button_box;
154 Gtk::ToggleButton bypass_button;
155 Gtk::VBox spinner_box;
156 Gtk::VBox left_side;
158 std::vector<Gtk::SpinButton*> spinners;
160 void bypass_toggled ();
161 bool on_key_press_event (GdkEventKey*);
162 bool on_key_release_event (GdkEventKey*);
165 #endif /* __ardour_panner_2d_h__ */