FlowCanvas  0.7.1
Module.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_MODULE_HPP
19 #define FLOWCANVAS_MODULE_HPP
20 
21 #include <string>
22 #include <algorithm>
23 #include <boost/shared_ptr.hpp>
24 #include <libgnomecanvasmm.h>
25 #include "flowcanvas/Port.hpp"
26 #include "flowcanvas/Item.hpp"
27 
28 namespace FlowCanvas {
29 
30 class Canvas;
31 
32 
37 class Module : public Item
38 {
39 public:
40  Module(boost::shared_ptr<Canvas> canvas,
41  const std::string& name,
42  double x = 0,
43  double y = 0,
44  bool show_title = true,
45  bool show_port_labels = true);
46 
47  virtual ~Module();
48 
49  const PortVector& ports() const { return _ports; }
50  PortVector& ports() { return _ports; }
51 
52  inline boost::shared_ptr<Port> get_port(const std::string& name) const;
53 
54  void add_port(boost::shared_ptr<Port> port);
55  void remove_port(boost::shared_ptr<Port> port);
56  boost::shared_ptr<Port> port_at(double x, double y);
57 
58  void zoom(double z);
59  void resize();
60 
61  bool show_port_labels(bool b) { return _show_port_labels; }
62  void set_show_port_labels(bool b);
63 
64  virtual void move(double dx, double dy);
65  virtual void move_to(double x, double y);
66 
67  virtual void set_name(const std::string& n);
68 
69  double border_width() const { return _border_width; }
70  void set_border_width(double w);
71 
72  void select_tick();
73  void set_selected(bool b);
74 
75  void set_highlighted(bool b);
76  void set_border_color(uint32_t c);
77  void set_base_color(uint32_t c);
79  void set_stacked_border(bool b);
80  void set_icon(const Glib::RefPtr<Gdk::Pixbuf>& icon);
81 
82  size_t num_ports() const { return _ports.size(); }
83 
84  double empty_port_breadth() const;
85  double empty_port_depth() const;
86 
87 protected:
88  virtual bool on_event(GdkEvent* ev);
89 
90  virtual void set_width(double w);
91  virtual void set_height(double h);
92 
93  void fit_canvas();
94  void measure_ports();
95  void resize_horiz();
96  void resize_vert();
97 
98  void port_renamed() { _port_renamed = true; }
99 
100  void embed(Gtk::Container* widget);
101 
103 
104  Gnome::Canvas::Rect _module_box;
105  Gnome::Canvas::Text _canvas_title;
106  Gnome::Canvas::Rect* _stacked_border;
107  Gnome::Canvas::Pixbuf* _icon_box;
108  Gtk::Container* _embed_container;
109  Gnome::Canvas::Widget* _embed_item;
110 
112  double _embed_width;
114  double _icon_size;
117  double _title_width;
119  bool _title_visible :1;
120  bool _port_renamed :1;
122 
123 private:
124  friend class Canvas;
125 
126  struct PortComparator {
127  explicit PortComparator(const std::string& name) : _name(name) {}
128  inline bool operator()(const boost::shared_ptr<Port> port)
129  { return (port && port->name() == _name); }
130  const std::string& _name;
131  };
132 
133  void embed_size_request(Gtk::Requisition* req, bool force);
134 };
135 
136 
137 
138 // Performance critical functions:
139 
140 
142 inline boost::shared_ptr<Port>
143 Module::get_port(const std::string& port_name) const
144 {
145  PortComparator comp(port_name);
146  PortVector::const_iterator i = std::find_if(_ports.begin(), _ports.end(), comp);
147  return (i != _ports.end()) ? *i : boost::shared_ptr<Port>();
148 }
149 
150 
151 } // namespace FlowCanvas
152 
153 #endif // FLOWCANVAS_MODULE_HPP
FlowCanvas::Module::_widest_input
double _widest_input
Definition: Module.hpp:115
FlowCanvas::Module::_title_visible
bool _title_visible
Definition: Module.hpp:119
FlowCanvas::Module::empty_port_breadth
double empty_port_breadth() const
FlowCanvas::Module::empty_port_depth
double empty_port_depth() const
FlowCanvas::Module::_icon_size
double _icon_size
Definition: Module.hpp:114
FlowCanvas::Module::set_border_color
void set_border_color(uint32_t c)
FlowCanvas::Module::select_tick
void select_tick()
FlowCanvas::Module::remove_port
void remove_port(boost::shared_ptr< Port > port)
FlowCanvas::Module::_port_renamed
bool _port_renamed
Definition: Module.hpp:120
FlowCanvas::Module::move
virtual void move(double dx, double dy)
FlowCanvas::Module::set_selected
void set_selected(bool b)
FlowCanvas::Module::port_renamed
void port_renamed()
Definition: Module.hpp:98
FlowCanvas::Module::add_port
void add_port(boost::shared_ptr< Port > port)
FlowCanvas::Module::resize_horiz
void resize_horiz()
FlowCanvas::Module
A named block (possibly) containing input and output ports.
Definition: Module.hpp:37
FlowCanvas::Module::set_name
virtual void set_name(const std::string &n)
FlowCanvas::Module::set_stacked_border
void set_stacked_border(bool b)
FlowCanvas::Module::on_event
virtual bool on_event(GdkEvent *ev)
FlowCanvas::Module::set_highlighted
void set_highlighted(bool b)
FlowCanvas::Module::set_icon
void set_icon(const Glib::RefPtr< Gdk::Pixbuf > &icon)
FlowCanvas::Item::name
const std::string & name() const
Definition: Item.hpp:93
FlowCanvas::Canvas
The 'master' canvas widget which contains all other objects.
Definition: Canvas.hpp:58
FlowCanvas::Module::set_width
virtual void set_width(double w)
FlowCanvas::Module::show_port_labels
bool show_port_labels(bool b)
Definition: Module.hpp:61
FlowCanvas::Module::border_width
double border_width() const
Definition: Module.hpp:69
FlowCanvas::Module::_ports
PortVector _ports
Definition: Module.hpp:102
FlowCanvas::Item
An item on a Canvas.
Definition: Item.hpp:42
FlowCanvas::Item::_name
std::string _name
Definition: Item.hpp:139
FlowCanvas::Module::set_default_base_color
void set_default_base_color()
FlowCanvas::Module::set_show_port_labels
void set_show_port_labels(bool b)
FlowCanvas::Module::_title_height
double _title_height
Definition: Module.hpp:118
FlowCanvas::Module::_embed_width
double _embed_width
Definition: Module.hpp:112
FlowCanvas::Module::_border_width
double _border_width
Definition: Module.hpp:111
FlowCanvas::Module::move_to
virtual void move_to(double x, double y)
FlowCanvas::Module::resize
void resize()
FlowCanvas::Module::get_port
boost::shared_ptr< Port > get_port(const std::string &name) const
Find a port on this module.
Definition: Module.hpp:143
FlowCanvas::Module::Module
Module(boost::shared_ptr< Canvas > canvas, const std::string &name, double x=0, double y=0, bool show_title=true, bool show_port_labels=true)
FlowCanvas::Module::_embed_container
Gtk::Container * _embed_container
Definition: Module.hpp:108
FlowCanvas::Module::_icon_box
Gnome::Canvas::Pixbuf * _icon_box
Definition: Module.hpp:107
FlowCanvas::Module::set_height
virtual void set_height(double h)
Port.hpp
FlowCanvas::Module::fit_canvas
void fit_canvas()
FlowCanvas::Module::ports
PortVector & ports()
Definition: Module.hpp:50
FlowCanvas::Module::set_base_color
void set_base_color(uint32_t c)
FlowCanvas::Module::port_at
boost::shared_ptr< Port > port_at(double x, double y)
FlowCanvas::Module::num_ports
size_t num_ports() const
Definition: Module.hpp:82
FlowCanvas
FlowCanvas namespace, everything is defined under this.
Definition: Canvas.hpp:38
FlowCanvas::Module::embed
void embed(Gtk::Container *widget)
FlowCanvas::Module::_stacked_border
Gnome::Canvas::Rect * _stacked_border
Definition: Module.hpp:106
FlowCanvas::PortVector
std::vector< boost::shared_ptr< Port > > PortVector
Definition: Port.hpp:172
FlowCanvas::Module::_title_width
double _title_width
Definition: Module.hpp:117
FlowCanvas::Module::_canvas_title
Gnome::Canvas::Text _canvas_title
Definition: Module.hpp:105
FlowCanvas::Module::zoom
void zoom(double z)
FlowCanvas::Module::ports
const PortVector & ports() const
Definition: Module.hpp:49
FlowCanvas::Module::~Module
virtual ~Module()
Item.hpp
FlowCanvas::Module::_widest_output
double _widest_output
Definition: Module.hpp:116
FlowCanvas::Module::measure_ports
void measure_ports()
FlowCanvas::Module::_show_port_labels
bool _show_port_labels
Definition: Module.hpp:121
FlowCanvas::Module::_embed_item
Gnome::Canvas::Widget * _embed_item
Definition: Module.hpp:109
FlowCanvas::Module::resize_vert
void resize_vert()
FlowCanvas::Module::set_border_width
void set_border_width(double w)
FlowCanvas::Module::_embed_height
double _embed_height
Definition: Module.hpp:113
FlowCanvas::Item::canvas
boost::weak_ptr< Canvas > canvas() const
Definition: Item.hpp:64
FlowCanvas::Module::_module_box
Gnome::Canvas::Rect _module_box
Definition: Module.hpp:104