Use dialog background colour for the port matrix.
[ardour.git] / gtk2_ardour / port_matrix_component.cc
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 #include "port_matrix_component.h"
21 #include "port_matrix.h"
22 #include "port_matrix_body.h"
23
24 /** Constructor.
25  *  @param p Port matrix that we're in.
26  */
27 PortMatrixComponent::PortMatrixComponent (PortMatrix* m, PortMatrixBody* b)
28         : _matrix (m),
29           _body (b),
30           _pixmap (0),
31           _render_required (true),
32           _dimension_computation_required (true)
33 {
34         
35 }
36
37 /** Destructor */
38 PortMatrixComponent::~PortMatrixComponent ()
39 {
40         if (_pixmap) {
41                 gdk_pixmap_unref (_pixmap);
42         }
43 }
44
45 void
46 PortMatrixComponent::setup ()
47 {
48         _dimension_computation_required = true;
49         _render_required = true;
50 }
51
52 GdkPixmap *
53 PortMatrixComponent::get_pixmap (GdkDrawable *drawable)
54 {
55         if (_render_required) {
56
57                 if (_dimension_computation_required) {
58                         compute_dimensions ();
59                         _dimension_computation_required = false;
60                         _body->component_size_changed ();
61                 }
62
63                 /* we may be zero width or height; if so, just
64                    use the smallest allowable pixmap */
65                 if (_width == 0) {
66                         _width = 1;
67                 }
68                 if (_height == 0) {
69                         _height = 1;
70                 }
71
72                 /* make a pixmap of the right size */
73                 if (_pixmap) {
74                         gdk_pixmap_unref (_pixmap);
75                 }
76                 _pixmap = gdk_pixmap_new (drawable, _width, _height, -1);
77
78                 /* render */
79                 cairo_t* cr = gdk_cairo_create (_pixmap);
80                 render (cr);
81                 cairo_destroy (cr);
82
83                 _render_required = false;
84         }
85
86         return _pixmap;
87 }
88
89 void
90 PortMatrixComponent::set_source_rgb (cairo_t *cr, Gdk::Color const & c)
91 {
92         cairo_set_source_rgb (cr, c.get_red_p(), c.get_green_p(), c.get_blue_p());
93 }
94
95 void
96 PortMatrixComponent::set_source_rgba (cairo_t *cr, Gdk::Color const & c, double a)
97 {
98         cairo_set_source_rgba (cr, c.get_red_p(), c.get_green_p(), c.get_blue_p(), a);
99 }
100
101 std::pair<uint32_t, uint32_t>
102 PortMatrixComponent::dimensions ()
103 {
104         if (_dimension_computation_required) {
105                 compute_dimensions ();
106                 _dimension_computation_required = false;
107                 _body->component_size_changed ();
108         }
109
110         return std::make_pair (_width, _height);
111 }
112
113 Gdk::Color
114 PortMatrixComponent::background_colour ()
115 {
116         return _matrix->get_style()->get_bg (Gtk::STATE_NORMAL);
117 }