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.
21 #include "port_matrix_component.h"
24 * @param p Port matrix that we're in.
26 PortMatrixComponent::PortMatrixComponent (PortMatrixBody* b)
29 _render_required (true),
30 _dimension_computation_required (true)
36 PortMatrixComponent::~PortMatrixComponent ()
39 gdk_pixmap_unref (_pixmap);
44 PortMatrixComponent::setup ()
46 _dimension_computation_required = true;
47 _render_required = true;
51 PortMatrixComponent::get_pixmap (GdkDrawable *drawable)
53 if (_render_required) {
55 if (_dimension_computation_required) {
56 compute_dimensions ();
57 _dimension_computation_required = false;
60 /* we may be zero width or height; if so, just
61 use the smallest allowable pixmap */
69 /* make a pixmap of the right size */
71 gdk_pixmap_unref (_pixmap);
73 _pixmap = gdk_pixmap_new (drawable, _width, _height, -1);
76 cairo_t* cr = gdk_cairo_create (_pixmap);
80 _render_required = false;
87 PortMatrixComponent::set_source_rgb (cairo_t *cr, Gdk::Color const & c)
89 cairo_set_source_rgb (cr, c.get_red_p(), c.get_green_p(), c.get_blue_p());
93 PortMatrixComponent::set_source_rgba (cairo_t *cr, Gdk::Color const & c, double a)
95 cairo_set_source_rgba (cr, c.get_red_p(), c.get_green_p(), c.get_blue_p(), a);
98 std::pair<uint32_t, uint32_t>
99 PortMatrixComponent::dimensions ()
101 if (_dimension_computation_required) {
102 compute_dimensions ();
103 _dimension_computation_required = false;
106 return std::make_pair (_width, _height);
109 std::pair<std::string, double>
110 PortMatrixComponent::display_port_name (cairo_t* cr, std::string const &n, double avail) const
112 /* XXX hopefully there exists a more efficient way of doing this */
114 Glib::ustring name = Glib::ustring (n).uppercase ();
115 bool abbreviated = false;
119 if (name.length() <= 2) {
123 cairo_text_extents_t ext;
124 cairo_text_extents (cr, name.c_str(), &ext);
125 if (ext.width < avail) {
131 name = name.substr (0, name.length() - 2) + ".";
133 name = name.substr (0, name.length() - 1) + ".";
138 return std::make_pair (name, width);