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