FlowCanvas 0.7.1
|
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_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 bool show_port_labels = true); 00046 00047 virtual ~Module(); 00048 00049 const PortVector& ports() const { return _ports; } 00050 PortVector& ports() { return _ports; } 00051 00052 inline boost::shared_ptr<Port> get_port(const std::string& name) const; 00053 00054 void add_port(boost::shared_ptr<Port> port); 00055 void remove_port(boost::shared_ptr<Port> port); 00056 boost::shared_ptr<Port> port_at(double x, double y); 00057 00058 void zoom(double z); 00059 void resize(); 00060 00061 bool show_port_labels(bool b) { return _show_port_labels; } 00062 void set_show_port_labels(bool b); 00063 00064 virtual void move(double dx, double dy); 00065 virtual void move_to(double x, double y); 00066 00067 virtual void set_name(const std::string& n); 00068 00069 double border_width() const { return _border_width; } 00070 void set_border_width(double w); 00071 00072 void select_tick(); 00073 void set_selected(bool b); 00074 00075 void set_highlighted(bool b); 00076 void set_border_color(uint32_t c); 00077 void set_base_color(uint32_t c); 00078 void set_default_base_color(); 00079 void set_stacked_border(bool b); 00080 void set_icon(const Glib::RefPtr<Gdk::Pixbuf>& icon); 00081 00082 size_t num_ports() const { return _ports.size(); } 00083 00084 double empty_port_breadth() const; 00085 double empty_port_depth() const; 00086 00087 protected: 00088 virtual bool on_event(GdkEvent* ev); 00089 00090 virtual void set_width(double w); 00091 virtual void set_height(double h); 00092 00093 void fit_canvas(); 00094 void measure_ports(); 00095 void resize_horiz(); 00096 void resize_vert(); 00097 00098 void port_renamed() { _port_renamed = true; } 00099 00100 void embed(Gtk::Container* widget); 00101 00102 PortVector _ports; 00103 00104 Gnome::Canvas::Rect _module_box; 00105 Gnome::Canvas::Text _canvas_title; 00106 Gnome::Canvas::Rect* _stacked_border; 00107 Gnome::Canvas::Pixbuf* _icon_box; 00108 Gtk::Container* _embed_container; 00109 Gnome::Canvas::Widget* _embed_item; 00110 00111 double _border_width; 00112 double _embed_width; 00113 double _embed_height; 00114 double _icon_size; 00115 double _widest_input; 00116 double _widest_output; 00117 double _title_width; 00118 double _title_height; 00119 bool _title_visible :1; 00120 bool _port_renamed :1; 00121 bool _show_port_labels :1; 00122 00123 private: 00124 friend class Canvas; 00125 00126 struct PortComparator { 00127 explicit PortComparator(const std::string& name) : _name(name) {} 00128 inline bool operator()(const boost::shared_ptr<Port> port) 00129 { return (port && port->name() == _name); } 00130 const std::string& _name; 00131 }; 00132 00133 void embed_size_request(Gtk::Requisition* req, bool force); 00134 }; 00135 00136 00137 00138 // Performance critical functions: 00139 00140 00142 inline boost::shared_ptr<Port> 00143 Module::get_port(const std::string& port_name) const 00144 { 00145 PortComparator comp(port_name); 00146 PortVector::const_iterator i = std::find_if(_ports.begin(), _ports.end(), comp); 00147 return (i != _ports.end()) ? *i : boost::shared_ptr<Port>(); 00148 } 00149 00150 00151 } // namespace FlowCanvas 00152 00153 #endif // FLOWCANVAS_MODULE_HPP