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 
35 namespace FlowCanvas {
36 
37 class Connection;
38 class Module;
39 
40 
41 static const int PORT_LABEL_SIZE = 8000; // in thousandths of a point
42 
43 
50 class Port : public Gnome::Canvas::Group, public Connectable
51 {
52 public:
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 
60  void disconnect_all();
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)
83  create_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 
122  void show_control();
123  void hide_control();
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 
130 protected:
131  friend class Canvas;
132 
133  void on_menu_hide();
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 
172 typedef std::vector<boost::shared_ptr<Port> > PortVector;
173 
174 
175 } // namespace FlowCanvas
176 
177 #endif // FLOWCANVAS_PORT_HPP