Fix dragging grid lines when you move the mouse outside of the grid during the drag.
[ardour.git] / gtk2_ardour / port_matrix_component.h
1 /*
2     Copyright (C) 2002-2009 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 #ifndef __gtk_ardour_port_matrix_component_h__
21 #define __gtk_ardour_port_matrix_component_h__
22
23 #include <stdint.h>
24 #include <gtkmm/eventbox.h>
25 #include <boost/shared_ptr.hpp>
26
27 class PortMatrix;
28 class PortMatrixBody;
29 class PortMatrixNode;
30 class PortGroup;
31 class PortGroupList;
32
33 namespace ARDOUR {
34         class BundleChannel;
35 }
36
37 /** One component of the PortMatrix.  This is a cairo-rendered
38  *  Pixmap.
39  */
40 class PortMatrixComponent
41 {
42 public:
43         PortMatrixComponent (PortMatrix *, PortMatrixBody *);
44         virtual ~PortMatrixComponent ();
45
46         virtual double component_to_parent_x (double x) const = 0;
47         virtual double parent_to_component_x (double x) const = 0;
48         virtual double component_to_parent_y (double y) const = 0;
49         virtual double parent_to_component_y (double y) const = 0;
50         virtual void mouseover_changed (std::list<PortMatrixNode> const &) = 0;
51         virtual void draw_extra (cairo_t *) = 0;
52         virtual void button_press (double, double, int, uint32_t) {}
53         virtual void button_release (double, double, int, uint32_t) {}
54         virtual void motion (double, double) {}
55
56         void set_show_ports (bool);
57         void setup ();
58         GdkPixmap* get_pixmap (GdkDrawable *);
59         std::pair<uint32_t, uint32_t> dimensions ();
60
61         void require_render () {
62                 _render_required = true;
63         }
64
65         void require_rebuild () {
66                 _dimension_computation_required = true;
67                 _render_required = true;
68         }
69
70         void set_parent_rectangle (Gdk::Rectangle const & r) {
71                 _parent_rectangle = r;
72         }
73
74         Gdk::Rectangle parent_rectangle () const {
75                 return _parent_rectangle;
76         }
77
78         /** @return grid spacing */
79         static uint32_t grid_spacing () {
80                 return 24;
81         }
82
83 protected:
84
85         /** @return width of borders drawn around labels */
86         static uint32_t label_border_width () {
87                 return 1;
88         }
89
90         /** @return padding between a name and the nearest line */
91         static uint32_t name_pad () {
92                 return 8;
93         }
94
95         /** @return width of thin lines in the grid */
96         static double thin_grid_line_width () {
97                 return 0.5;
98         }
99
100         /** @return width of thick lines in the grid */
101         static double thick_grid_line_width () {
102                 return 1;
103         }
104
105         /** @return space around the connection indicator */
106         static uint32_t connection_indicator_pad () {
107                 return 6;
108         }
109
110         static uint32_t mouseover_line_width () {
111                 return 4;
112         }
113
114         /** @return angle of column labels, in radians */
115         static double angle () {
116                 return M_PI / 4;
117         }
118
119         /** @return background colour */
120         Gdk::Color background_colour ();
121
122         /* XXX I guess these colours should come from a theme, or something */
123
124         /** @return text colour */
125         static Gdk::Color text_colour () {
126                 return Gdk::Color ("#ffffff");
127         }
128
129         /** @return grid line colour */
130         static Gdk::Color grid_colour () {
131                 return Gdk::Color ("#000000");
132         }
133
134         /** @return colour of association blobs */
135         static Gdk::Color association_colour () {
136                 return Gdk::Color ("#00ff00");
137         }
138
139         /** @return colour to paint grid squares when they can't be associated */
140         static Gdk::Color unknown_colour () {
141                 return Gdk::Color ("#cccccc");
142         }
143
144         /** @return colour to paint mouseover lines */
145         static Gdk::Color mouseover_line_colour () {
146                 return Gdk::Color ("#ff0000");
147         }
148
149         /** @return colour to paint channel highlights */
150         static Gdk::Color highlighted_channel_colour () {
151                 return Gdk::Color ("#777777");
152         }
153
154         /* XXX */
155         static Gdk::Color get_a_bundle_colour (int x) {
156                 if ((x % 2) == 0) {
157                         return Gdk::Color ("#547027");
158                 } else {
159                         return Gdk::Color ("#3552a6");
160                 }
161         }
162
163         /* XXX */
164         static Gdk::Color get_a_group_colour (int x) {
165                 if ((x % 2) == 0) {
166                         return Gdk::Color ("#222222");
167                 } else {
168                         return Gdk::Color ("#444444");
169                 }
170         }
171
172         void set_source_rgb (cairo_t *, Gdk::Color const &);
173         void set_source_rgba (cairo_t *, Gdk::Color const &, double);
174         uint32_t group_size (boost::shared_ptr<const PortGroup>) const;
175         uint32_t channel_to_position (ARDOUR::BundleChannel, boost::shared_ptr<const PortGroup>) const;
176         virtual ARDOUR::BundleChannel position_to_channel (double, double, boost::shared_ptr<const PortGroup>) const;
177
178         /** Render the complete component to a cairo context. */
179         virtual void render (cairo_t *) = 0;
180         /** Compute any required dimensions.  This must set up
181          *  _width and _height.
182          */
183         virtual void compute_dimensions () = 0;
184
185         PortMatrix* _matrix;
186         PortMatrixBody* _body; ///< the PortMatrixBody that we're in
187         uint32_t _width; ///< full width of the contents
188         uint32_t _height; ///< full height of the contents
189         Gdk::Rectangle _parent_rectangle;
190
191 private:
192         GdkPixmap* _pixmap; ///< pixmap
193         bool _render_required; ///< true if the rendered pixmap is out of date
194         bool _dimension_computation_required; ///< true if the dimensions are out of date
195 };
196
197 #endif