FlowCanvas 0.5.1
|
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_MODULE_HPP 00019 #define FLOWCANVAS_MODULE_HPP 00020 00021 #include <string> 00022 #include <algorithm> 00023 #include <boost/shared_ptr.hpp> 00024 #include <libgnomecanvasmm.h> 00025 #include <flowcanvas/Port.hpp> 00026 #include <flowcanvas/Item.hpp> 00027 00028 namespace FlowCanvas { 00029 00030 class Canvas; 00031 00032 00037 class Module : public Item 00038 { 00039 public: 00040 Module(boost::shared_ptr<Canvas> canvas, 00041 const std::string& name, 00042 double x = 0, 00043 double y = 0, 00044 bool show_title = true); 00045 00046 virtual ~Module(); 00047 00048 const PortVector& ports() const { return _ports; } 00049 00050 inline boost::shared_ptr<Port> get_port(const std::string& name) const; 00051 00052 void add_port(boost::shared_ptr<Port> port); 00053 void remove_port(boost::shared_ptr<Port> port); 00054 boost::shared_ptr<Port> remove_port(const std::string& name); 00055 boost::shared_ptr<Port> port_at(double x, double y); 00056 00057 void zoom(double z); 00058 void resize(); 00059 00060 virtual void move(double dx, double dy); 00061 virtual void move_to(double x, double y); 00062 00063 virtual void set_name(const std::string& n); 00064 00065 double border_width() const { return _border_width; } 00066 void set_border_width(double w); 00067 00068 void select_tick(); 00069 void set_selected(bool b); 00070 00071 void set_highlighted(bool b); 00072 void set_border_color(uint32_t c); 00073 void set_base_color(uint32_t c); 00074 void set_default_base_color(); 00075 void set_stacked_border(bool b); 00076 void set_icon(const Glib::RefPtr<Gdk::Pixbuf>& icon); 00077 00078 size_t num_ports() const { return _ports.size(); } 00079 00080 protected: 00081 virtual void on_drop(double new_x, double new_y); 00082 virtual bool on_event(GdkEvent* ev); 00083 00084 virtual void set_width(double w); 00085 virtual void set_height(double h); 00086 00087 void fit_canvas(); 00088 00089 void embed(Gtk::Container* widget); 00090 00091 double _border_width; 00092 bool _title_visible; 00093 double _embed_width; 00094 double _embed_height; 00095 double _icon_size; 00096 double _widest_input; 00097 double _widest_output; 00098 00099 PortVector _ports; 00100 00101 Gnome::Canvas::Rect _module_box; 00102 Gnome::Canvas::Text _canvas_title; 00103 Gnome::Canvas::Rect* _stacked_border; 00104 Gnome::Canvas::Pixbuf* _icon_box; 00105 Gtk::Container* _embed_container; 00106 Gnome::Canvas::Widget* _embed_item; 00107 00108 private: 00109 friend class Canvas; 00110 00111 struct PortComparator { 00112 PortComparator(const std::string& name) : _name(name) {} 00113 inline bool operator()(const boost::shared_ptr<Port> port) 00114 { return (port && port->name() == _name); } 00115 const std::string& _name; 00116 }; 00117 00118 void embed_size_request(Gtk::Requisition* req, bool force); 00119 }; 00120 00121 00122 00123 // Performance critical functions: 00124 00125 00127 inline boost::shared_ptr<Port> 00128 Module::get_port(const std::string& port_name) const 00129 { 00130 PortComparator comp(port_name); 00131 PortVector::const_iterator i = std::find_if(_ports.begin(), _ports.end(), comp); 00132 return (i != _ports.end()) ? *i : boost::shared_ptr<Port>(); 00133 } 00134 00135 00136 } // namespace FlowCanvas 00137 00138 #endif // FLOWCANVAS_MODULE_HPP