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_CONNECTION_HPP 00019 #define FLOWCANVAS_CONNECTION_HPP 00020 00021 #include <stdint.h> 00022 00023 #include <list> 00024 #include <string> 00025 00026 #include <boost/weak_ptr.hpp> 00027 00028 #include <libgnomecanvasmm.h> 00029 #include <libgnomecanvasmm/bpath.h> 00030 #include <libgnomecanvasmm/path-def.h> 00031 00032 namespace FlowCanvas { 00033 00034 class Canvas; 00035 class Connectable; 00036 00037 00042 class Connection : public Gnome::Canvas::Group 00043 { 00044 public: 00045 Connection(boost::shared_ptr<Canvas> canvas, 00046 boost::shared_ptr<Connectable> source, 00047 boost::shared_ptr<Connectable> dest, 00048 uint32_t color, 00049 bool show_arrow_head = false); 00050 00051 virtual ~Connection(); 00052 00053 virtual void move(double /*dx*/, double /*dy*/) 00054 { /* ignore, src/dst take care of it */ } 00055 00056 virtual void zoom(double z); 00057 00058 bool selected() const { return _selected; } 00059 void set_selected(bool b); 00060 00061 virtual double length_hint() const { return 0.0; } 00062 00063 void set_label(const std::string& str); 00064 void show_handle(bool show); 00065 00066 void set_color(uint32_t color); 00067 void set_highlighted(bool b); 00068 void raise_to_top(); 00069 00070 void select_tick(); 00071 00072 const boost::weak_ptr<Connectable> source() const { return _source; } 00073 const boost::weak_ptr<Connectable> dest() const { return _dest; } 00074 00075 enum HandleStyle { 00076 HANDLE_NONE, 00077 HANDLE_RECT, 00078 HANDLE_CIRCLE, 00079 }; 00080 00081 void set_handle_style(HandleStyle s) { _handle_style = s; } 00082 00083 protected: 00084 friend class Canvas; 00085 friend class Connectable; 00086 void update_location(); 00087 00088 const boost::weak_ptr<Canvas> _canvas; 00089 const boost::weak_ptr<Connectable> _source; 00090 const boost::weak_ptr<Connectable> _dest; 00091 00092 Gnome::Canvas::Bpath _bpath; 00093 GnomeCanvasPathDef* _path; 00094 00096 struct Handle : public Gnome::Canvas::Group { 00097 explicit Handle(Gnome::Canvas::Group& parent) 00098 : Gnome::Canvas::Group(parent), shape(NULL), text(NULL) {} 00099 ~Handle() { delete shape; delete text; } 00100 Gnome::Canvas::Shape* shape; 00101 Gnome::Canvas::Text* text; 00102 }* _handle; 00103 00104 uint32_t _color; 00105 HandleStyle _handle_style; 00106 00107 bool _selected :1; 00108 bool _show_arrowhead :1; 00109 }; 00110 00111 typedef std::list<boost::shared_ptr<Connection> > ConnectionList; 00112 00113 00114 } // namespace FlowCanvas 00115 00116 #endif // FLOWCANVAS_CONNECTION_HPP