2 Copyright (C) 2002-2009 Paul Davis
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.
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.
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.
20 #include "port_matrix_component.h"
21 #include "port_matrix.h"
22 #include "port_matrix_body.h"
25 * @param p Port matrix that we're in.
27 PortMatrixComponent::PortMatrixComponent (PortMatrix* m, PortMatrixBody* b)
31 _render_required (true),
32 _dimension_computation_required (true)
38 PortMatrixComponent::~PortMatrixComponent ()
41 gdk_pixmap_unref (_pixmap);
46 PortMatrixComponent::setup ()
48 _dimension_computation_required = true;
49 _render_required = true;
53 PortMatrixComponent::get_pixmap (GdkDrawable *drawable)
55 if (_render_required) {
57 if (_dimension_computation_required) {
58 compute_dimensions ();
59 _dimension_computation_required = false;
60 _body->component_size_changed ();
63 /* we may be zero width or height; if so, just
64 use the smallest allowable pixmap */
72 /* make a pixmap of the right size */
74 gdk_pixmap_unref (_pixmap);
76 _pixmap = gdk_pixmap_new (drawable, _width, _height, -1);
79 cairo_t* cr = gdk_cairo_create (_pixmap);
83 _render_required = false;
90 PortMatrixComponent::set_source_rgb (cairo_t *cr, Gdk::Color const & c)
92 cairo_set_source_rgb (cr, c.get_red_p(), c.get_green_p(), c.get_blue_p());
96 PortMatrixComponent::set_source_rgba (cairo_t *cr, Gdk::Color const & c, double a)
98 cairo_set_source_rgba (cr, c.get_red_p(), c.get_green_p(), c.get_blue_p(), a);
101 std::pair<uint32_t, uint32_t>
102 PortMatrixComponent::dimensions ()
104 if (_dimension_computation_required) {
105 compute_dimensions ();
106 _dimension_computation_required = false;
107 _body->component_size_changed ();
110 return std::make_pair (_width, _height);
113 std::pair<std::string, double>
114 PortMatrixComponent::display_port_name (cairo_t* cr, std::string const &n, double avail) const
116 /* XXX hopefully there exists a more efficient way of doing this */
118 Glib::ustring name = Glib::ustring (n).uppercase ();
119 bool abbreviated = false;
123 if (name.length() <= 2) {
127 cairo_text_extents_t ext;
128 cairo_text_extents (cr, name.c_str(), &ext);
129 if (ext.width < avail) {
135 name = name.substr (0, name.length() - 2) + ".";
137 name = name.substr (0, name.length() - 1) + ".";
142 return std::make_pair (name, width);