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
Handle(Gnome::Canvas::Group &parent)
Definition: Connection.hpp:97
A connection (line) between two canvas objects.
Definition: Connection.hpp:42
Definition: Connection.hpp:77
Gnome::Canvas::Shape * shape
Definition: Connection.hpp:100
bool _selected
Definition: Connection.hpp:107
const boost::weak_ptr< Connectable > source() const
Definition: Connection.hpp:72
Connection(boost::shared_ptr< Canvas > canvas, boost::shared_ptr< Connectable > source, boost::shared_ptr< Connectable > dest, uint32_t color, bool show_arrow_head=false)
A handle on a connection line to allow mouse interaction.
Definition: Connection.hpp:96
void set_selected(bool b)
virtual void move(double, double)
Definition: Connection.hpp:53
const boost::weak_ptr< Connectable > _dest
Definition: Connection.hpp:90
Gnome::Canvas::Bpath _bpath
Definition: Connection.hpp:92
HandleStyle
Definition: Connection.hpp:75
GnomeCanvasPathDef * _path
Definition: Connection.hpp:93
An object a Connection can connect to.
Definition: Connectable.hpp:32
uint32_t _color
Definition: Connection.hpp:104
void set_color(uint32_t color)
const boost::weak_ptr< Connectable > dest() const
Definition: Connection.hpp:73
bool selected() const
Definition: Connection.hpp:58
std::list< boost::shared_ptr< Connection > > ConnectionList
Definition: Connection.hpp:111
bool _show_arrowhead
Definition: Connection.hpp:108
void set_handle_style(HandleStyle s)
Definition: Connection.hpp:81
void set_highlighted(bool b)
FlowCanvas::Connection::Handle * _handle
void show_handle(bool show)
Definition: Connection.hpp:78
virtual void zoom(double z)
Definition: Connection.hpp:76
The &#39;master&#39; canvas widget which contains all other objects.
Definition: Canvas.hpp:58
void set_label(const std::string &str)
virtual double length_hint() const
Definition: Connection.hpp:61
FlowCanvas namespace, everything is defined under this.
Definition: Canvas.hpp:38
~Handle()
Definition: Connection.hpp:99
Gnome::Canvas::Text * text
Definition: Connection.hpp:101
const boost::weak_ptr< Canvas > _canvas
Definition: Connection.hpp:88
HandleStyle _handle_style
Definition: Connection.hpp:105
const boost::weak_ptr< Connectable > _source
Definition: Connection.hpp:89