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