FlowCanvas 0.7.1
Port.hpp
Go to the documentation of this file.
1/* This file is part of FlowCanvas.
2 * Copyright (C) 2007-2009 David Robillard <http://drobilla.net>
3 *
4 * FlowCanvas is free software; you can redistribute it and/or modify it under the
5 * terms of the GNU General Public License as published by the Free Software
6 * Foundation; either version 2 of the License, or (at your option) any later
7 * version.
8 *
9 * FlowCanvas is distributed in the hope that it will be useful, but WITHOUT ANY
10 * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
11 * FOR A PARTICULAR PURPOSE. See the GNU General Public License for details.
12 *
13 * You should have received a copy of the GNU General Public License along
14 * with this program; if not, write to the Free Software Foundation, Inc.,
15 * 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA
16 */
17
18#ifndef FLOWCANVAS_PORT_HPP
19#define FLOWCANVAS_PORT_HPP
20
21#include <stdint.h>
22
23#include <algorithm>
24#include <list>
25#include <string>
26#include <vector>
27
28#include <boost/shared_ptr.hpp>
29#include <boost/weak_ptr.hpp>
30
31#include <libgnomecanvasmm.h>
32
34
35namespace FlowCanvas {
36
37class Connection;
38class Module;
39
40
41static const int PORT_LABEL_SIZE = 8000; // in thousandths of a point
42
43
50class Port : public Gnome::Canvas::Group, public Connectable
51{
52public:
53 Port(boost::shared_ptr<Module> module,
54 const std::string& name,
55 bool is_input,
56 uint32_t color);
57
58 virtual ~Port();
59
61
62 virtual Gnome::Art::Point src_connection_point();
63 virtual Gnome::Art::Point dst_connection_point(const Gnome::Art::Point& src);
64 virtual Gnome::Art::Point connection_point_vector(double dx, double dy);
65
66 boost::weak_ptr<Module> module() const { return _module; }
67
68 void set_fill_color(uint32_t c) { _rect->property_fill_color_rgba() = c; }
69
70 void show_label(bool b);
71 void set_selected(bool b);
72 bool selected() const { return _selected; }
73
74 void set_highlighted(bool highlight,
75 bool highlight_parent=true,
76 bool highlight_connections=true,
77 bool raise_connections=true);
78
79 void zoom(float z);
80
81 void popup_menu(guint button, guint32 activate_time) {
82 if ( ! _menu)
84 if (_menu)
85 _menu->popup(button, activate_time);
86 }
87
88 virtual void create_menu();
89 void set_menu(Gtk::Menu* m);
90
91 Gtk::Menu* menu() const { return _menu; }
92
93 double width() const { return _width; }
94 void set_width(double w);
95 void set_height(double h);
96
97 double border_width() const { return _border_width; }
98 void set_border_width(double w);
99
100 double natural_width() const;
101
102 const std::string& name() const { return _name; }
103 virtual void set_name(const std::string& n);
104
105 bool is_input() const { return _is_input; }
106 bool is_output() const { return !_is_input; }
107 uint32_t color() const { return _color; }
108 double height() const { return _height; }
109
110 virtual bool is_toggled() const { return _toggled; }
111 virtual void set_toggled(bool b) { _toggled = b; }
112 virtual void toggle(bool signal=true);
113
114 virtual void set_control(float value, bool signal=true);
115 virtual void set_control_min(float min);
116 virtual void set_control_max(float max);
117
118 float control_value() const { return _control ? _control->value : 0.0f; }
119 float control_min() const { return _control ? _control->min : 0.0f; }
120 float control_max() const { return _control ? _control->max : 1.0f; }
121
124
125 inline bool operator==(const std::string& name) { return (_name == name); }
126
127 sigc::signal<void> signal_renamed;
128 sigc::signal<void,float> signal_control_changed;
129
130protected:
131 friend class Canvas;
132
134
135 boost::weak_ptr<Module> _module;
136 std::string _name;
137 Gnome::Canvas::Text* _label;
138 Gnome::Canvas::Rect* _rect;
139 Gtk::Menu* _menu;
140
142 struct Control {
143 explicit Control(Gnome::Canvas::Rect* r)
144 : rect(r)
145 , value(0.0f)
146 , min(0.0f)
147 , max(1.0f)
148 {}
149
151 delete rect;
152 }
153
154 Gnome::Canvas::Rect* rect;
155 float value;
156 float min;
157 float max;
158 };
159
161
162 double _width;
163 double _height;
165 uint32_t _color;
166
167 bool _is_input :1;
168 bool _selected :1;
169 bool _toggled :1;
170};
171
172typedef std::vector<boost::shared_ptr<Port> > PortVector;
173
174
175} // namespace FlowCanvas
176
177#endif // FLOWCANVAS_PORT_HPP
The 'master' canvas widget which contains all other objects.
Definition: Canvas.hpp:61
An object a Connection can connect to.
Definition: Connectable.hpp:32
virtual void raise_connections()
A port on a Module.
Definition: Port.hpp:51
double border_width() const
Definition: Port.hpp:97
bool _selected
Definition: Port.hpp:168
virtual void set_control_min(float min)
Port(boost::shared_ptr< Module > module, const std::string &name, bool is_input, uint32_t color)
boost::weak_ptr< Module > module() const
Definition: Port.hpp:66
bool is_output() const
Definition: Port.hpp:106
Gtk::Menu * menu() const
Definition: Port.hpp:91
void popup_menu(guint button, guint32 activate_time)
Definition: Port.hpp:81
double natural_width() const
bool operator==(const std::string &name)
Definition: Port.hpp:125
double _border_width
Definition: Port.hpp:164
const std::string & name() const
Definition: Port.hpp:102
uint32_t _color
Definition: Port.hpp:165
virtual void toggle(bool signal=true)
void zoom(float z)
void set_height(double h)
sigc::signal< void > signal_renamed
Definition: Port.hpp:127
virtual Gnome::Art::Point dst_connection_point(const Gnome::Art::Point &src)
void set_width(double w)
float control_value() const
Definition: Port.hpp:118
bool _toggled
Definition: Port.hpp:169
void set_highlighted(bool highlight, bool highlight_parent=true, bool highlight_connections=true, bool raise_connections=true)
void set_border_width(double w)
virtual void set_control(float value, bool signal=true)
uint32_t color() const
Definition: Port.hpp:107
void set_selected(bool b)
bool _is_input
Definition: Port.hpp:167
virtual bool is_toggled() const
Definition: Port.hpp:110
virtual Gnome::Art::Point src_connection_point()
Gnome::Canvas::Rect * _rect
Definition: Port.hpp:138
Gtk::Menu * _menu
Definition: Port.hpp:139
virtual void create_menu()
virtual Gnome::Art::Point connection_point_vector(double dx, double dy)
virtual void set_control_max(float max)
boost::weak_ptr< Module > _module
Definition: Port.hpp:135
double _width
Definition: Port.hpp:162
void show_label(bool b)
double height() const
Definition: Port.hpp:108
void set_menu(Gtk::Menu *m)
sigc::signal< void, float > signal_control_changed
Definition: Port.hpp:128
void set_fill_color(uint32_t c)
Definition: Port.hpp:68
Gnome::Canvas::Text * _label
Definition: Port.hpp:137
std::string _name
Definition: Port.hpp:136
float control_max() const
Definition: Port.hpp:120
float control_min() const
Definition: Port.hpp:119
bool selected() const
Definition: Port.hpp:72
double width() const
Definition: Port.hpp:93
Control * _control
Definition: Port.hpp:160
virtual void set_toggled(bool b)
Definition: Port.hpp:111
virtual void set_name(const std::string &n)
double _height
Definition: Port.hpp:163
bool is_input() const
Definition: Port.hpp:105
FlowCanvas namespace, everything is defined under this.
Definition: Canvas.hpp:38
std::vector< boost::shared_ptr< Port > > PortVector
Definition: Port.hpp:172
Port control value indicator "gauge".
Definition: Port.hpp:142
float value
Definition: Port.hpp:155
Control(Gnome::Canvas::Rect *r)
Definition: Port.hpp:143
float min
Definition: Port.hpp:156
Gnome::Canvas::Rect * rect
Definition: Port.hpp:154
float max
Definition: Port.hpp:157
~Control()
Definition: Port.hpp:150