FlowCanvas 0.5.1
/usr/src/RPM/BUILD/libflowcanvas-0.5.1/flowcanvas/Port.hpp
Go to the documentation of this file.
00001 /* This file is part of FlowCanvas.
00002  * Copyright (C) 2007 Dave Robillard <http://drobilla.net>
00003  * 
00004  * FlowCanvas is free software; you can redistribute it and/or modify it under the
00005  * terms of the GNU General Public License as published by the Free Software
00006  * Foundation; either version 2 of the License, or (at your option) any later
00007  * version.
00008  * 
00009  * FlowCanvas is distributed in the hope that it will be useful, but WITHOUT ANY
00010  * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
00011  * FOR A PARTICULAR PURPOSE.  See the GNU General Public License for details.
00012  * 
00013  * You should have received a copy of the GNU General Public License along
00014  * with this program; if not, write to the Free Software Foundation, Inc.,
00015  * 51 Franklin St, Fifth Floor, Boston, MA  02110-1301, USA
00016  */
00017 
00018 #ifndef FLOWCANVAS_PORT_HPP
00019 #define FLOWCANVAS_PORT_HPP
00020 
00021 #include <string>
00022 #include <list>
00023 #include <vector>
00024 #include <inttypes.h>
00025 #include <libgnomecanvasmm.h>
00026 #include <boost/shared_ptr.hpp>
00027 #include <boost/weak_ptr.hpp>
00028 #include <flowcanvas/Connectable.hpp>
00029 
00030 namespace FlowCanvas {
00031     
00032 class Connection;
00033 class Module;
00034 
00035 
00036 static const int PORT_LABEL_SIZE = 8000; // in thousandths of a point
00037 
00038 
00045 class Port : public Gnome::Canvas::Group, public Connectable
00046 {
00047 public:
00048     Port(boost::shared_ptr<Module> module,
00049          const std::string&        name,
00050          bool                      is_input,
00051          uint32_t                  color);
00052     
00053     virtual ~Port();
00054     
00055     void disconnect_all();
00056     
00057     virtual Gnome::Art::Point src_connection_point();
00058     virtual Gnome::Art::Point dst_connection_point(const Gnome::Art::Point& src);
00059     
00060     boost::weak_ptr<Module> module() const { return _module; }
00061     
00062     void set_fill_color(uint32_t c) { _rect->property_fill_color_rgba() = c; }
00063     
00064     void set_selected(bool b);
00065     bool selected() const { return _selected; }
00066 
00067     void set_highlighted(bool highlight,
00068                          bool highlight_parent=true,
00069                          bool highlight_connections=true,
00070                          bool raise_connections=true);
00071     
00072     void zoom(float z);
00073     
00074     void popup_menu(guint button, guint32 activate_time) {
00075         if ( ! _menu)
00076             create_menu();
00077         if (_menu)
00078             _menu->popup(button, activate_time);
00079     }
00080 
00081     virtual void create_menu();
00082     void         set_menu(Gtk::Menu* m);
00083 
00084     Gtk::Menu* menu() const           { return _menu; }
00085 
00086     double width() const { return _width; }
00087     void   set_width(double w);
00088     
00089     double border_width() const { return _border_width; }
00090     void   set_border_width(double w);
00091 
00092     const std::string& name() const { return _name; }
00093     virtual void       set_name(const std::string& n);
00094     
00095     bool     is_input()  const { return _is_input; }
00096     bool     is_output() const { return !_is_input; }
00097     uint32_t color()     const { return _color; }
00098     double   height()    const { return _height; }
00099 
00100     virtual bool is_toggled() const { return _toggled; }
00101     virtual void set_toggled(bool b) { _toggled = b; }
00102     virtual void toggle(bool signal=true);
00103 
00104     virtual void set_control(float value, bool signal=true);
00105     virtual void set_control_min(float min) { _control_min = min; set_control(_control_value, false);  }
00106     virtual void set_control_max(float max) { _control_max = max; set_control(_control_value, false);  }
00107     
00108     float control_value() { return _control_value; }
00109     float control_min()   { return _control_min; }
00110     float control_max()   { return _control_max; }
00111     
00112     void show_control();
00113     void hide_control();
00114 
00115     inline bool operator==(const std::string& name) { return (_name == name); }
00116 
00117     sigc::signal<void>       signal_renamed;
00118     sigc::signal<void,float> signal_control_changed;
00119 
00120 protected:
00121     friend class Canvas;
00122 
00123     void on_menu_hide();
00124 
00125     boost::weak_ptr<Module> _module;
00126     std::string             _name;
00127     bool                    _is_input;
00128     double                  _width;
00129     double                  _height;
00130     double                  _border_width;
00131     uint32_t                _color;
00132     bool                    _selected;
00133 
00134     bool  _toggled;
00135     float _control_value;
00136     float _control_min;
00137     float _control_max;
00138     
00139     Gnome::Canvas::Text* _label;
00140     Gnome::Canvas::Rect* _rect;
00141     Gnome::Canvas::Rect* _control_rect;
00142     Gtk::Menu*           _menu;
00143 };
00144 
00145 typedef std::vector<boost::shared_ptr<Port> > PortVector;
00146 
00147 
00148 } // namespace FlowCanvas
00149 
00150 #endif // FLOWCANVAS_PORT_HPP