FlowCanvas  0.7.1
Connection.hpp
Go to the documentation of this file.
1 /* This file is part of FlowCanvas.
2  * Copyright (C) 2007-2009 David Robillard <http://drobilla.net>
3  *
4  * FlowCanvas is free software; you can redistribute it and/or modify it under the
5  * terms of the GNU General Public License as published by the Free Software
6  * Foundation; either version 2 of the License, or (at your option) any later
7  * version.
8  *
9  * FlowCanvas is distributed in the hope that it will be useful, but WITHOUT ANY
10  * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
11  * FOR A PARTICULAR PURPOSE. See the GNU General Public License for details.
12  *
13  * You should have received a copy of the GNU General Public License along
14  * with this program; if not, write to the Free Software Foundation, Inc.,
15  * 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA
16  */
17 
18 #ifndef FLOWCANVAS_CONNECTION_HPP
19 #define FLOWCANVAS_CONNECTION_HPP
20 
21 #include <stdint.h>
22 
23 #include <list>
24 #include <string>
25 
26 #include <boost/weak_ptr.hpp>
27 
28 #include <libgnomecanvasmm.h>
29 #include <libgnomecanvasmm/bpath.h>
30 #include <libgnomecanvasmm/path-def.h>
31 
32 namespace FlowCanvas {
33 
34 class Canvas;
35 class Connectable;
36 
37 
42 class Connection : public Gnome::Canvas::Group
43 {
44 public:
45  Connection(boost::shared_ptr<Canvas> canvas,
46  boost::shared_ptr<Connectable> source,
47  boost::shared_ptr<Connectable> dest,
48  uint32_t color,
49  bool show_arrow_head = false);
50 
51  virtual ~Connection();
52 
53  virtual void move(double /*dx*/, double /*dy*/)
54  { /* ignore, src/dst take care of it */ }
55 
56  virtual void zoom(double z);
57 
58  bool selected() const { return _selected; }
59  void set_selected(bool b);
60 
61  virtual double length_hint() const { return 0.0; }
62 
63  void set_label(const std::string& str);
64  void show_handle(bool show);
65 
66  void set_color(uint32_t color);
67  void set_highlighted(bool b);
68  void raise_to_top();
69 
70  void select_tick();
71 
72  const boost::weak_ptr<Connectable> source() const { return _source; }
73  const boost::weak_ptr<Connectable> dest() const { return _dest; }
74 
75  enum HandleStyle {
79  };
80 
82 
83 protected:
84  friend class Canvas;
85  friend class Connectable;
86  void update_location();
87 
88  const boost::weak_ptr<Canvas> _canvas;
89  const boost::weak_ptr<Connectable> _source;
90  const boost::weak_ptr<Connectable> _dest;
91 
92  Gnome::Canvas::Bpath _bpath;
93  GnomeCanvasPathDef* _path;
94 
96  struct Handle : public Gnome::Canvas::Group {
97  explicit Handle(Gnome::Canvas::Group& parent)
98  : Gnome::Canvas::Group(parent), shape(NULL), text(NULL) {}
99  ~Handle() { delete shape; delete text; }
100  Gnome::Canvas::Shape* shape;
101  Gnome::Canvas::Text* text;
102  }* _handle;
103 
104  uint32_t _color;
106 
107  bool _selected :1;
109 };
110 
111 typedef std::list<boost::shared_ptr<Connection> > ConnectionList;
112 
113 
114 } // namespace FlowCanvas
115 
116 #endif // FLOWCANVAS_CONNECTION_HPP