Initial import of gtk2_ardour.
[ardour.git] / gtk2_ardour / panner2d.h
1 /*
2     Copyright (C) 2002 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     $Id$
19 */
20
21 #ifndef __ardour_panner_2d_h__
22 #define __ardour_panner_2d_h__
23
24 #include <sys/types.h>
25 #include <map>
26 #include <string>
27 #include <gtk--.h>
28
29 using std::map;
30 using std::string;
31
32 namespace ARDOUR {
33         class Panner;
34 }
35
36 class Panner2d : public Gtk::DrawingArea
37 {
38   public:
39         Panner2d (ARDOUR::Panner&, int32_t width, int32_t height);
40         ~Panner2d ();
41         
42         int puck_position (int which_puck, float& x, float& y);
43         int target_position (int which_target, float& x, float& y);
44
45         void allow_x_motion(bool);
46         void allow_y_motion(bool);
47         void allow_target_motion (bool);
48
49         void hide_puck (int which);
50         void show_puck (int which);
51         int  add_target (float x, float y);
52         int  add_puck (const char* text, float x, float y);
53         void hide_target (int);
54         void show_target (int);
55         void remove_target (int);
56         void drop_targets ();
57         void drop_pucks ();
58         void move_target (int, float x, float y);
59         void move_puck (int, float x, float y);
60         void reset (uint32_t n_inputs);
61
62         SigC::Signal1<void,int> PuckMoved;
63         SigC::Signal1<void,int> TargetMoved;
64
65   protected:
66         gint expose_event_impl (GdkEventExpose *);
67         gint button_press_event_impl (GdkEventButton *);
68         gint button_release_event_impl (GdkEventButton *);
69         gint motion_notify_event_impl (GdkEventMotion *);
70         void size_allocate_impl (GtkAllocation* alloc);
71
72   private:
73         struct Target {
74             float x;
75             float y;
76             bool visible;
77             char* text;
78             size_t textlen;
79
80             Target (float xa, float ya, const char* txt = 0);
81             ~Target ();
82         };
83
84         ARDOUR::Panner& panner;
85         Gtk::Menu* context_menu;
86         Gtk::CheckMenuItem* bypass_menu_item;
87
88         typedef map<int,Target *> Targets;
89         Targets targets;
90         Targets pucks;
91
92         Target *drag_target;
93         int     drag_index;
94         bool    drag_is_puck;
95         bool  allow_x;
96         bool  allow_y;
97         bool  allow_target;
98         int width;
99         int height;
100
101         bool bypassflag;
102         
103         gint compute_x (float);
104         gint compute_y (float);
105
106         Target *find_closest_object (gdouble x, gdouble y, int& which, bool& is_puck) const;
107
108         gint handle_motion (gint, gint, GdkModifierType);
109
110         void toggle_bypass ();
111         void show_context_menu ();
112         void handle_state_change ();
113 };
114
115 #endif /* __ardour_panner_2d_h__ */