New matrix-based editor for connections and bundles, based on thorwil's design.
[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 PortMatrixBody;
26
27 /** One component of the PortMatrix.  This is a cairo-rendered
28  *  Pixmap.
29  */
30 class PortMatrixComponent
31 {
32 public:
33         PortMatrixComponent (PortMatrixBody *);
34         virtual ~PortMatrixComponent ();
35
36         void setup ();
37         GdkPixmap* get_pixmap (GdkDrawable *);
38         std::pair<uint32_t, uint32_t> dimensions ();
39         void require_render () {
40                 _render_required = true;
41         }
42
43         /** @return width of columns in the grid */
44         static uint32_t column_width () {
45                 return 32;
46         }
47
48         /** @return height of rows in the grid */
49         static uint32_t row_height () {
50                 return 32;
51         }
52
53 protected:
54
55         /** @return width of borders drawn around labels */
56         static uint32_t label_border_width () {
57                 return 1;
58         }
59
60         /** @return padding between a name and the nearest line */
61         static uint32_t name_pad () {
62                 return 8;
63         }
64
65         /** @return width of thin lines in the grid */
66         static uint32_t thin_grid_line_width () {
67                 return 1;
68         }
69
70         /** @return width of thick lines in the grid */
71         static uint32_t thick_grid_line_width () {
72                 return 2;
73         }
74
75         /** @return space around the connection indicator */
76         static uint32_t connection_indicator_pad () {
77                 return 8;
78         }
79
80         /** @return angle of column labels, in radians */
81         static double angle () {
82                 return M_PI / 4;
83         }
84
85         /* XXX I guess these colours should come from a theme, or something */
86
87         /* @return background colour */
88         static Gdk::Color background_colour () {
89                 return Gdk::Color ("#000000");
90         }
91
92         /* @return text colour */
93         static Gdk::Color text_colour () {
94                 return Gdk::Color ("#ffffff");
95         }
96
97         /* @return grid line colour */
98         static Gdk::Color grid_colour () {
99                 return Gdk::Color ("#333333");
100         }
101
102         /* @return colour of association blobs */
103         static Gdk::Color association_colour () {
104                 return Gdk::Color ("#00ff00");
105         }
106
107         /* XXX */
108         static Gdk::Color get_a_bundle_colour (int x) {
109                 if ((x % 2) == 0) {
110                         return Gdk::Color ("#547027");
111                 } else {
112                         return Gdk::Color ("#3552a6");
113                 }
114         }
115
116         void set_source_rgb (cairo_t *, Gdk::Color const &);
117         void set_source_rgba (cairo_t *, Gdk::Color const &, double);
118
119         /** Render the complete component to a cairo context. */
120         virtual void render (cairo_t *) = 0;
121         /** Compute any required dimensions.  This must set up
122          *  _width and _height.
123          */
124         virtual void compute_dimensions () = 0;
125
126         PortMatrixBody* _body; ///< the PortMatrixBody that we're in
127         uint32_t _width; ///< full width of the contents
128         uint32_t _height; ///< full height of the contents
129
130 private:        
131         GdkPixmap* _pixmap; ///< pixmap
132         bool _render_required; ///< true if the rendered pixmap is out of date
133         bool _dimension_computation_required; ///< true if the dimensions are out of date
134 };
135
136 #endif