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
28namespace FlowCanvas {
29
30class Canvas;
31
32
37class Module : public Item
38{
39public:
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; }
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
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
87protected:
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();
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
122
123private:
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
142inline boost::shared_ptr<Port>
143Module::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
The 'master' canvas widget which contains all other objects.
Definition: Canvas.hpp:61
An item on a Canvas.
Definition: Item.hpp:44
const std::string & name() const
Definition: Item.hpp:93
boost::weak_ptr< Canvas > canvas() const
Definition: Item.hpp:64
A named block (possibly) containing input and output ports.
Definition: Module.hpp:38
void set_border_width(double w)
void embed(Gtk::Container *widget)
bool show_port_labels(bool b)
Definition: Module.hpp:61
double _border_width
Definition: Module.hpp:111
bool _title_visible
Definition: Module.hpp:119
void remove_port(boost::shared_ptr< Port > port)
Gtk::Container * _embed_container
Definition: Module.hpp:108
virtual void set_width(double w)
double empty_port_depth() const
size_t num_ports() const
Definition: Module.hpp:82
void set_icon(const Glib::RefPtr< Gdk::Pixbuf > &icon)
bool _port_renamed
Definition: Module.hpp:120
virtual bool on_event(GdkEvent *ev)
Gnome::Canvas::Text _canvas_title
Definition: Module.hpp:105
Gnome::Canvas::Widget * _embed_item
Definition: Module.hpp:109
void set_default_base_color()
virtual void set_name(const std::string &n)
Gnome::Canvas::Rect * _stacked_border
Definition: Module.hpp:106
void set_show_port_labels(bool b)
virtual void set_height(double h)
virtual void move_to(double x, double y)
double empty_port_breadth() const
double _embed_height
Definition: Module.hpp:113
virtual void move(double dx, double dy)
void set_border_color(uint32_t c)
const PortVector & ports() const
Definition: Module.hpp:49
Gnome::Canvas::Rect _module_box
Definition: Module.hpp:104
double _embed_width
Definition: Module.hpp:112
void zoom(double z)
void set_selected(bool b)
double _title_height
Definition: Module.hpp:118
void set_base_color(uint32_t c)
PortVector & ports()
Definition: Module.hpp:50
void set_highlighted(bool b)
void port_renamed()
Definition: Module.hpp:98
double _widest_output
Definition: Module.hpp:116
Gnome::Canvas::Pixbuf * _icon_box
Definition: Module.hpp:107
boost::shared_ptr< Port > port_at(double x, double y)
boost::shared_ptr< Port > get_port(const std::string &name) const
Find a port on this module.
Definition: Module.hpp:143
double _title_width
Definition: Module.hpp:117
void set_stacked_border(bool b)
PortVector _ports
Definition: Module.hpp:102
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)
void add_port(boost::shared_ptr< Port > port)
bool _show_port_labels
Definition: Module.hpp:121
double border_width() const
Definition: Module.hpp:69
double _widest_input
Definition: Module.hpp:115
double _icon_size
Definition: Module.hpp:114
FlowCanvas namespace, everything is defined under this.
Definition: Canvas.hpp:38
std::vector< boost::shared_ptr< Port > > PortVector
Definition: Port.hpp:172