• Main Page
  • Modules
  • Namespaces
  • Classes
  • Files
  • File List

flowcanvas/Port.hpp

Go to the documentation of this file.
00001 /* This file is part of FlowCanvas.
00002  * Copyright (C) 2007-2009 David 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 <stdint.h>
00022 
00023 #include <algorithm>
00024 #include <list>
00025 #include <string>
00026 #include <vector>
00027 
00028 #include <boost/shared_ptr.hpp>
00029 #include <boost/weak_ptr.hpp>
00030 
00031 #include <libgnomecanvasmm.h>
00032 
00033 #include "flowcanvas/Connectable.hpp"
00034 
00035 namespace FlowCanvas {
00036 
00037 class Connection;
00038 class Module;
00039 
00040 
00041 static const int PORT_LABEL_SIZE = 8000; // in thousandths of a point
00042 
00043 
00050 class Port : public Gnome::Canvas::Group, public Connectable
00051 {
00052 public:
00053     Port(boost::shared_ptr<Module> module,
00054          const std::string&        name,
00055          bool                      is_input,
00056          uint32_t                  color);
00057 
00058     virtual ~Port();
00059 
00060     void disconnect_all();
00061 
00062     virtual Gnome::Art::Point src_connection_point();
00063     virtual Gnome::Art::Point dst_connection_point(const Gnome::Art::Point& src);
00064     virtual Gnome::Art::Point connection_point_vector(double dx, double dy);
00065 
00066     boost::weak_ptr<Module> module() const { return _module; }
00067 
00068     void set_fill_color(uint32_t c) { _rect->property_fill_color_rgba() = c; }
00069 
00070     void show_label(bool b);
00071     void set_selected(bool b);
00072     bool selected() const { return _selected; }
00073 
00074     void set_highlighted(bool highlight,
00075                          bool highlight_parent=true,
00076                          bool highlight_connections=true,
00077                          bool raise_connections=true);
00078 
00079     void zoom(float z);
00080 
00081     void popup_menu(guint button, guint32 activate_time) {
00082         if ( ! _menu)
00083             create_menu();
00084         if (_menu)
00085             _menu->popup(button, activate_time);
00086     }
00087 
00088     virtual void create_menu();
00089     void         set_menu(Gtk::Menu* m);
00090 
00091     Gtk::Menu* menu() const { return _menu; }
00092 
00093     double width() const { return _width; }
00094     void   set_width(double w);
00095     void   set_height(double h);
00096 
00097     double border_width() const { return _border_width; }
00098     void   set_border_width(double w);
00099 
00100     double natural_width() const;
00101 
00102     const std::string& name() const { return _name; }
00103     virtual void       set_name(const std::string& n);
00104 
00105     bool     is_input()  const { return _is_input; }
00106     bool     is_output() const { return !_is_input; }
00107     uint32_t color()     const { return _color; }
00108     double   height()    const { return _height; }
00109 
00110     virtual bool is_toggled() const { return _toggled; }
00111     virtual void set_toggled(bool b) { _toggled = b; }
00112     virtual void toggle(bool signal=true);
00113 
00114     virtual void set_control(float value, bool signal=true);
00115     virtual void set_control_min(float min);
00116     virtual void set_control_max(float max);
00117 
00118     float control_value() const { return _control ? _control->value : 0.0f; }
00119     float control_min()   const { return _control ? _control->min   : 0.0f; }
00120     float control_max()   const { return _control ? _control->max   : 1.0f; }
00121 
00122     void show_control();
00123     void hide_control();
00124 
00125     inline bool operator==(const std::string& name) { return (_name == name); }
00126 
00127     sigc::signal<void>       signal_renamed;
00128     sigc::signal<void,float> signal_control_changed;
00129 
00130 protected:
00131     friend class Canvas;
00132 
00133     void on_menu_hide();
00134 
00135     boost::weak_ptr<Module> _module;
00136     std::string             _name;
00137     Gnome::Canvas::Text*    _label;
00138     Gnome::Canvas::Rect*    _rect;
00139     Gtk::Menu*              _menu;
00140 
00142     struct Control {
00143         explicit Control(Gnome::Canvas::Rect* r)
00144             : rect(r)
00145             , value(0.0f)
00146             , min(0.0f)
00147             , max(1.0f)
00148             {}
00149 
00150         ~Control() {
00151             delete rect;
00152         }
00153         
00154         Gnome::Canvas::Rect* rect;
00155         float                value;
00156         float                min;
00157         float                max;
00158     };
00159 
00160     Control* _control;
00161     
00162     double   _width;
00163     double   _height;
00164     double   _border_width;
00165     uint32_t _color;
00166     
00167     bool _is_input :1;
00168     bool _selected :1;
00169     bool _toggled  :1;
00170 };
00171 
00172 typedef std::vector<boost::shared_ptr<Port> > PortVector;
00173 
00174 
00175 } // namespace FlowCanvas
00176 
00177 #endif // FLOWCANVAS_PORT_HPP

Generated on Tue Jan 11 2011 19:26:04 for FlowCanvas by  doxygen 1.7.1