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