1 /* This file is part of FlowCanvas. Copyright (C) 2005 Dave Robillard.
3 * FlowCanvas is free software; you can redistribute it and/or modify it under the
4 * terms of the GNU General Public License as published by the Free Software
5 * Foundation; either version 2 of the License, or (at your option) any later
8 * FlowCanvas is distributed in the hope that it will be useful, but WITHOUT ANY
9 * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
10 * FOR A PARTICULAR PURPOSE. See the GNU General Public License for details.
12 * You should have received a copy of the GNU General Public License along
13 * with this program; if not, write to the Free Software Foundation, Inc.,
14 * 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
18 #include <libgnomecanvasmm/libgnomecanvasmm.h>
19 #include "flowcanvas/Port.h"
20 #include "flowcanvas/Module.h"
21 #include "flowcanvas/FlowCanvas.h"
23 namespace LibFlowCanvas {
26 Port::Port(Module* module, const string& name, bool is_input, int color)
27 : Gnome::Canvas::Group(*module, 0, 0),
32 m_label(*this, 1, 1, m_name),
33 m_rect(*this, 0, 0, 0, 0)
35 m_menu.items().push_back(Gtk::Menu_Helpers::MenuElem(
36 "Disconnect All", sigc::mem_fun(this, &Port::disconnect_all)));
38 m_rect.property_fill_color_rgba() = color;
40 // Make rectangle pretty
41 //m_rect.property_outline_color_rgba() = 0x8899AAFF;
42 m_rect.property_outline_color_rgba() = color;
43 m_rect.property_join_style() = Gdk::JOIN_MITER;
47 m_label.property_size() = PORT_LABEL_SIZE;
48 m_label.property_fill_color_rgba() = 0xFFFFFFFF;
49 m_label.property_weight() = 200;
51 m_width = m_label.property_text_width() + 4.0;
52 m_height = m_label.property_text_height();
55 m_rect.property_x1() = 0;
56 m_rect.property_y1() = 0;
57 m_rect.property_x2() = m_width;
58 m_rect.property_y2() = m_height;
59 m_label.property_x() = m_label.property_text_width() / 2 + 1;
60 m_label.property_y() = m_height / 2;
62 m_label.raise_to_top();
67 /** Set the border width of the port's rectangle.
69 * Do NOT directly set the width_units property on the rect, use this function.
72 Port::border_width(double w)
75 m_rect.property_width_units() = w;
80 Port::name(const string& n)
85 m_label.property_text() = m_name;
86 m_width = m_label.property_text_width() + 4.0;
87 m_height = m_label.property_text_height();
88 m_rect.property_x2() = m_width;
89 m_rect.property_y2() = m_height;
90 m_label.property_x() = m_label.property_text_width() / 2 + 1;
91 m_label.property_y() = m_height / 2;
100 m_label.property_size() = static_cast<int>(8000 * z);
104 /** Update the location of all connections to/from this port if this port has moved */
106 Port::move_connections()
108 for (list<Connection*>::iterator i = m_connections.begin(); i != m_connections.end(); i++) {
109 ((Connection*)(*i))->update_location();
115 Port::remove_connection(Connection* c)
118 find(m_connections.begin(), m_connections.end(), c)
124 Port::disconnect_all()
126 Connection* c = NULL;
127 list<Connection*> temp_list = m_connections;
128 for (list<Connection*>::iterator i = temp_list.begin(); i != temp_list.end(); ++i) {
130 m_module->patch_bay()->disconnect(c->source_port(), c->dest_port());
140 for (list<Connection*>::iterator i = m_connections.begin(); i != m_connections.end(); ++i) {
143 (*i)->raise_to_top();
148 m_rect.raise_to_top();
149 m_label.raise_to_top();
150 m_rect.property_fill_color_rgba() = m_colour + 0x33333300;
152 m_rect.property_fill_color_rgba() = m_colour;
158 Port::raise_connections()
160 for (list<Connection*>::iterator i = m_connections.begin(); i != m_connections.end(); ++i) {
161 (*i)->raise_to_top();
166 // Returns the world-relative coordinates of where a connection line
169 Port::connection_coords()
171 double x = (is_input()) ? m_rect.property_x1()-1.0 : m_rect.property_x2()+1.0;
172 double y = m_rect.property_y1() + m_height / 2;
174 i2w(x, y); // convert to world-relative coords
176 return Gnome::Art::Point(x, y);
181 Port::width(double w)
183 double diff = w - m_width;
184 m_rect.property_x2() = m_rect.property_x2() + diff;
189 } // namespace LibFlowCanvas