diff options
Diffstat (limited to 'ganv')
-rw-r--r-- | ganv/Box.hpp | 46 | ||||
-rw-r--r-- | ganv/Canvas.hpp | 216 | ||||
-rw-r--r-- | ganv/Circle.hpp | 82 | ||||
-rw-r--r-- | ganv/Edge.hpp | 99 | ||||
-rw-r--r-- | ganv/Item.hpp | 90 | ||||
-rw-r--r-- | ganv/Module.hpp | 121 | ||||
-rw-r--r-- | ganv/Node.hpp | 81 | ||||
-rw-r--r-- | ganv/Port.hpp | 73 | ||||
-rw-r--r-- | ganv/box.h | 125 | ||||
-rw-r--r-- | ganv/canvas.h | 105 | ||||
-rw-r--r-- | ganv/circle.h | 55 | ||||
-rw-r--r-- | ganv/edge.h | 116 | ||||
-rw-r--r-- | ganv/ganv.hpp | 29 | ||||
-rw-r--r-- | ganv/module.h | 89 | ||||
-rw-r--r-- | ganv/node.h | 209 | ||||
-rw-r--r-- | ganv/port.h | 126 | ||||
-rw-r--r-- | ganv/text.h | 63 | ||||
-rw-r--r-- | ganv/types.h | 29 | ||||
-rw-r--r-- | ganv/types.hpp | 33 | ||||
-rw-r--r-- | ganv/wrap.hpp | 112 |
20 files changed, 1899 insertions, 0 deletions
diff --git a/ganv/Box.hpp b/ganv/Box.hpp new file mode 100644 index 0000000..c35ea26 --- /dev/null +++ b/ganv/Box.hpp @@ -0,0 +1,46 @@ +/* This file is part of Ganv. + * Copyright 2007-2011 David Robillard <http://drobilla.net> + * + * Ganv is free software: you can redistribute it and/or modify it under + * the terms of the GNU General Public License as published by the Free + * Software Foundation, either version 3 of the License, or (at your option) + * any later version. + * + * Ganv is distributed in the hope that it will be useful, but WITHOUT + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for + * details. + * + * You should have received a copy of the GNU General Public License + * along with Ganv. If not, see <http://www.gnu.org/licenses/>. + */ + +#ifndef GANV_BOX_HPP +#define GANV_BOX_HPP + +#include "ganv/Node.hpp" +#include "ganv/box.h" + +namespace Ganv { + +class Box : public Node +{ +public: + Box(Canvas* canvas, GanvBox* gobj) + : Node(canvas, GANV_NODE(gobj)) + {} + + RW_PROPERTY(const char*, label); + + METHODRET0(ganv_box, double, get_width) + METHOD1(ganv_box, set_width, double, width) + METHODRET0(ganv_box, double, get_height) + METHOD1(ganv_box, set_height, double, height) + + GanvBox* gobj() { return GANV_BOX(_gobj); } + const GanvBox* gobj() const { return GANV_BOX(_gobj); } +}; + +} // namespace Ganv + +#endif // GANV_BOX_HPP diff --git a/ganv/Canvas.hpp b/ganv/Canvas.hpp new file mode 100644 index 0000000..032b701 --- /dev/null +++ b/ganv/Canvas.hpp @@ -0,0 +1,216 @@ +/* This file is part of Ganv. + * Copyright 2007-2011 David Robillard <http://drobilla.net> + * + * Ganv is free software: you can redistribute it and/or modify it under + * the terms of the GNU General Public License as published by the Free + * Software Foundation, either version 3 of the License, or (at your option) + * any later version. + * + * Ganv is distributed in the hope that it will be useful, but WITHOUT + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for + * details. + * + * You should have received a copy of the GNU General Public License + * along with Ganv. If not, see <http://www.gnu.org/licenses/>. + */ + +#ifndef GANV_CANVAS_HPP +#define GANV_CANVAS_HPP + +#include <string> + +#include <glib.h> +#include <glibmm.h> +#include <gtkmm/layout.h> + +#include "ganv/canvas.h" +#include "ganv/wrap.hpp" + +GANV_GLIB_WRAP(Canvas) + +/** Ganv namespace, everything is defined under this. + * + * @ingroup Ganv + */ +namespace Ganv { + +class Edge; +class Node; +class Port; + +/** @defgroup Ganv Ganv + * + * A generic dataflow widget using libgnomecanvas. + */ + +/** The 'master' canvas widget which contains all other objects. + * + * Applications must override some virtual methods to make the widget actually + * do anything (e.g. connect). + * + * @ingroup Ganv + */ +class Canvas +{ +public: + Canvas(double width, double height); + virtual ~Canvas(); + + Gtk::Layout& widget(); + + /** Remove all ports and edges and modules. */ + void destroy(); + + /** Get the edge from @c tail to @c head if one exists. */ + Edge* get_edge(Node* tail, Node* head) const; + + /** Delete the edge from @c tail to @c head. */ + void remove_edge(Node* tail, Node* head); + + /** Place @c i at a reasonable default location. */ + void set_default_placement(Node* i); + + /** Unselect all selected objects. */ + virtual void clear_selection(); + + void select_all(); + + /** + Add @a item to the current selection. + All edges between selected items will be automatically selected. + */ + void select_item(Node* item); + + /** Unselect @c item. */ + void unselect_item(Node* item); + + /** Unselect all ports. */ + void unselect_ports(); + + /** Select @c c. */ + void select_edge(Edge* e); + + /** Unselect @c c. */ + void unselect_edge(Edge* c); + + RW_PROPERTY(gboolean, locked); + + /** Return the current zoom factor (pixels per unit). */ + double get_zoom(); + + /** Set the current zoom factor (pixels per unit). */ + void set_zoom(double pix_per_unit); + + /** Zoom so all canvas contents are visible. */ + void zoom_full(); + + METHODRET0(ganv_canvas, double, get_font_size) + METHODRET0(ganv_canvas, double, get_default_font_size) + + /** Set the current font size. */ + void set_font_size(double points); + + /** Set both the zoom factor and font size. */ + void set_zoom_and_font_size(double zoom, double points); + + /** Write a Graphviz DOT description of the canvas to @c filename. */ + void render_to_dot(const std::string& filename); + + /** Automatically arrange the canvas contents if Graphviz is available. */ + void arrange(bool use_length_hints=false); + + /** Shift all canvas contents so the top-left object is at (x, y). */ + void move_contents_to(double x, double y); + + /** Return the width of the canvas. */ + double width() const; + + /** Return the height of the canvas. */ + double height() const; + + /** Resize the canvas to the given dimensions. */ + void resize(double width, double height); + + /** The direction of the "signal flow" on the canvas. */ + enum FlowDirection { + HORIZONTAL, + VERTICAL + }; + + /** Set the flow direction of the canvas. */ + void set_direction(FlowDirection d); + + /** Return the current flow direction of the canvas. */ + FlowDirection direction() const; + + /** + Called whenever a edge is made. + This should be overridden by an implementation to do something. + */ + virtual void connect(Node* /*tail*/, + Node* /*head*/) {} + + /** + Called whenever a edge is severed. + This should be overridden by an implementation to do something. + */ + virtual void disconnect(Node* /*tail*/, + Node* /*head*/) {} + + typedef void (*NodeFunction)(GanvNode* node, void* data); + + void for_each_node(NodeFunction f, void* data); + void for_each_selected_node(NodeFunction f, void* data); + + typedef void (*EdgePtrFunction)(GanvEdge* edge, void* data); + + void for_each_edge(EdgePtrFunction f, void* data); + void for_each_selected_edge(EdgePtrFunction f, void* data); + + METHOD2(ganv_canvas, for_each_edge_from, + const GanvNode*, tail, + GanvEdgeFunction, f); + + METHOD2(ganv_canvas, for_each_edge_to, + const GanvNode*, head, + GanvEdgeFunction, f); + + METHOD2(ganv_canvas, for_each_edge_on, + const GanvNode*, node, + GanvEdgeFunction, f); + + GQuark wrapper_key(); + + GnomeCanvasGroup* root(); + + GdkCursor* move_cursor(); + + void get_scroll_offsets(int& cx, int& cy) const; + void scroll_to(int x, int y); + + GanvCanvas* gobj(); + const GanvCanvas* gobj() const; + + /** Canvas event handler. */ + virtual bool on_event(GdkEvent* event); + + /** Signal emitted when the mouse pointer enters an Item. */ + sigc::signal<void, GnomeCanvasItem*> signal_item_entered; + + /** Signal emitted when the mouse pointer leaves an Item. */ + sigc::signal<void, GnomeCanvasItem*> signal_item_left; + +private: + Canvas(const Canvas&); ///< Noncopyable + const Canvas& operator=(const Canvas&); ///< Noncopyable + + inline GanvCanvasImpl* impl() { return _gobj->impl; } + inline const GanvCanvasImpl* impl() const { return _gobj->impl; } + + GanvCanvas* const _gobj; +}; + +} // namespace Ganv + +#endif // GANV_CANVAS_HPP diff --git a/ganv/Circle.hpp b/ganv/Circle.hpp new file mode 100644 index 0000000..beb1be5 --- /dev/null +++ b/ganv/Circle.hpp @@ -0,0 +1,82 @@ +/* This file is part of Ganv. + * Copyright 2007-2011 David Robillard <http://drobilla.net> + * + * Ganv is free software: you can redistribute it and/or modify it under + * the terms of the GNU General Public License as published by the Free + * Software Foundation, either version 3 of the License, or (at your option) + * any later version. + * + * Ganv is distributed in the hope that it will be useful, but WITHOUT + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for + * details. + * + * You should have received a copy of the GNU General Public License + * along with Ganv. If not, see <http://www.gnu.org/licenses/>. + */ + +#ifndef GANV_CIRCLE_HPP +#define GANV_CIRCLE_HPP + +#include <algorithm> +#include <map> +#include <string> +#include <stdint.h> + +#include <gdkmm/types.h> + +#include "ganv/types.hpp" +#include "ganv/Node.hpp" +#include "ganv/circle.h" + +GANV_GLIB_WRAP(Circle) + +namespace Ganv { + +class Canvas; + +/** An elliptical Item which is Node. + * + * Unlike a Module, this doesn't contain ports, but is directly joinable itself + * (think your classic circles 'n' lines diagram, ala FSM). + * + * @ingroup Ganv + */ +class Circle : public Node +{ +public: + static const uint32_t FILL_COLOUR = 0x1E2224FF; + static const uint32_t BORDER_COLOUR = 0xD3D7CFFF; + + Circle(Canvas& canvas, + const std::string& name, + double x, + double y, + double radius, + bool show_title) + : Node(&canvas, + GANV_NODE( + gnome_canvas_item_new( + GNOME_CANVAS_GROUP(canvas.root()), + ganv_circle_get_type(), + "x", x, + "y", y, + "can-tail", TRUE, + "can-head", TRUE, + "radius", radius, + "fill-color", FILL_COLOUR, + "border-color", BORDER_COLOUR, + "label", name.c_str(), + "draggable", TRUE, + NULL))) + {} + + RW_PROPERTY(double, radius); + + GanvCircle* gobj() { return GANV_CIRCLE(_gobj); } + const GanvCircle* gobj() const { return GANV_CIRCLE(_gobj); } +}; + +} // namespace Ganv + +#endif // GANV_CIRCLE_HPP diff --git a/ganv/Edge.hpp b/ganv/Edge.hpp new file mode 100644 index 0000000..e9760c5 --- /dev/null +++ b/ganv/Edge.hpp @@ -0,0 +1,99 @@ +/* This file is part of Ganv. + * Copyright 2007-2011 David Robillard <http://drobilla.net> + * + * Ganv is free software: you can redistribute it and/or modify it under + * the terms of the GNU General Public License as published by the Free + * Software Foundation, either version 3 of the License, or (at your option) + * any later version. + * + * Ganv is distributed in the hope that it will be useful, but WITHOUT + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for + * details. + * + * You should have received a copy of the GNU General Public License + * along with Ganv. If not, see <http://www.gnu.org/licenses/>. + */ + +#ifndef GANV_EDGE_HPP +#define GANV_EDGE_HPP + +#include <stdint.h> + +#include <libgnomecanvas/gnome-canvas.h> + +#include <gdk/gdkevents.h> + +#include "ganv/Canvas.hpp" +#include "ganv/Item.hpp" +#include "ganv/Node.hpp" +#include "ganv/edge.h" + +GANV_GLIB_WRAP(Edge) + +namespace Ganv { + +class Canvas; + +/** A edge (line) between two Node objects. + * + * @ingroup Ganv + */ +class Edge : public Item +{ +public: + Edge(Canvas& canvas, + Node* tail, + Node* head, + uint32_t color, + bool show_arrowhead = false, + bool curved = true) + : Item(GNOME_CANVAS_ITEM( + g_object_ref( + ganv_edge_new( + canvas.gobj(), + tail->gobj(), + head->gobj(), + "color", color, + "curved", (gboolean)curved, + "arrowhead", (gboolean)show_arrowhead, + NULL)))) + {} + + Edge(GanvEdge* gobj) + : Item(GNOME_CANVAS_ITEM(g_object_ref(gobj))) + {} + + virtual ~Edge() { + if (_gobj && _gobj->parent) { + g_object_unref(_gobj); + } + } + + /** Return true iff the handle is within the given rectangle. */ + virtual gboolean is_within(double x1, double y1, + double x2, double y2) const { + return ganv_edge_is_within(gobj(), x1, y1, x2, y2); + } + + RW_PROPERTY(gboolean, curved) + RW_PROPERTY(gboolean, selected) + RW_PROPERTY(gboolean, highlighted) + RW_PROPERTY(guint, color) + + METHODRETWRAP0(ganv_edge, Node*, get_tail); + METHODRETWRAP0(ganv_edge, Node*, get_head); + + METHOD1(ganv_edge, tick, double, seconds); + + GanvEdge* gobj() { return (GanvEdge*)_gobj; } + const GanvEdge* gobj() const { return (GanvEdge*)_gobj; } + +private: + Edge(const Edge& copy); + Edge& operator=(const Edge& other); +}; + +} // namespace Ganv + +#endif // GANV_EDGE_HPP diff --git a/ganv/Item.hpp b/ganv/Item.hpp new file mode 100644 index 0000000..534048f --- /dev/null +++ b/ganv/Item.hpp @@ -0,0 +1,90 @@ +/* This file is part of Ganv. + * Copyright 2007-2011 David Robillard <http://drobilla.net> + * + * Ganv is free software: you can redistribute it and/or modify it under + * the terms of the GNU General Public License as published by the Free + * Software Foundation, either version 3 of the License, or (at your option) + * any later version. + * + * Ganv is distributed in the hope that it will be useful, but WITHOUT + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for + * details. + * + * You should have received a copy of the GNU General Public License + * along with Ganv. If not, see <http://www.gnu.org/licenses/>. + */ + +#ifndef GANV_ITEM_HPP +#define GANV_ITEM_HPP + +#include <assert.h> + +#include <glib.h> +#include <libgnomecanvas/gnome-canvas.h> + +#include <sigc++/signal.h> +#include <sigc++/trackable.h> + +#include "ganv/wrap.hpp" +#include "ganv/Canvas.hpp" + +namespace Ganv { + +class Canvas; + +/** An item on the canvas. + */ +class Item : public sigc::trackable { +public: + Item(GnomeCanvasItem* gobj) + : _gobj(gobj) + { + GQuark wrapper_key = g_quark_from_string("ganvmm"); + if (gobj && gobj->parent) { + g_object_set_qdata(G_OBJECT(_gobj), wrapper_key, this); + g_signal_connect(G_OBJECT(_gobj), + "event", G_CALLBACK(on_item_event), this); + } + } + + virtual ~Item() {} + RW_PROPERTY(double, x) + RW_PROPERTY(double, y) + + METHOD0(gnome_canvas_item, show); + METHOD0(gnome_canvas_item, hide); + METHOD0(gnome_canvas_item, raise_to_top); + METHOD2(gnome_canvas_item, move, double, dx, double, dy); + + GnomeCanvasItem* property_parent() const { + GnomeCanvasItem* parent; + g_object_get(G_OBJECT(_gobj), "parent", &parent, NULL); + return parent; + } + + Canvas* canvas() const { + return Glib::wrap(GANV_CANVAS(_gobj->canvas)); + } + + GnomeCanvasItem* gobj() const { return _gobj; } + + SIGNAL(event, GdkEvent*) + SIGNAL(click, GdkEventButton*) + +protected: + GnomeCanvasItem* const _gobj; + +private: + static gboolean + on_item_event(GnomeCanvasItem* canvasitem, + GdkEvent* ev, + void* item) + { + return ((Item*)item)->on_event(ev); + } +}; + +} // namespace Ganv + +#endif // GANV_ITEM_HPP diff --git a/ganv/Module.hpp b/ganv/Module.hpp new file mode 100644 index 0000000..3ccabcf --- /dev/null +++ b/ganv/Module.hpp @@ -0,0 +1,121 @@ +/* This file is part of Ganv. + * Copyright 2007-2011 David Robillard <http://drobilla.net> + * + * Ganv is free software: you can redistribute it and/or modify it under + * the terms of the GNU General Public License as published by the Free + * Software Foundation, either version 3 of the License, or (at your option) + * any later version. + * + * Ganv is distributed in the hope that it will be useful, but WITHOUT + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for + * details. + * + * You should have received a copy of the GNU General Public License + * along with Ganv. If not, see <http://www.gnu.org/licenses/>. + */ + +#ifndef GANV_MODULE_HPP +#define GANV_MODULE_HPP + +#include <string> +#include <vector> + +#include <gtkmm/container.h> + +#include "ganv/Canvas.hpp" +#include "ganv/Node.hpp" +#include "ganv/Port.hpp" +#include "ganv/module.h" + +GANV_GLIB_WRAP(Module) + +namespace Ganv { + +class Canvas; + +/** A rectangular Item which can hold a Port. + * + * @ingroup Ganv + */ +class Module : public Box +{ +public: + Module(Canvas& canvas, + const std::string& name, + double x = 0, + double y = 0, + bool show_title = true, + bool show_port_labels = true) + : Box(&canvas, GANV_BOX( + gnome_canvas_item_new( + GNOME_CANVAS_GROUP(canvas.root()), + ganv_module_get_type(), + "x", x, + "y", y, + "can-tail", FALSE, + "can-head", FALSE, + "radius-tl", 4.0, + "radius-tr", 4.0, + "radius-br", 4.0, + "radius-bl", 4.0, + "label", name.c_str(), + "draggable", TRUE, + NULL))) + {} + + template<typename P, typename C> + class iterator_base { + public: + iterator_base(C** p) : _ptr(p) {} + template<typename T, typename U> + iterator_base(const iterator_base<T, U>& i) + : _ptr(const_cast<C**>(i._ptr)) + {} + P* operator*() const { return Glib::wrap(*_ptr); } + P* operator->() const { return Glib::wrap(*_ptr); } + iterator_base operator++(int) { return iterator_base<P, C>(_ptr + 1); } + iterator_base& operator++() { ++_ptr; return *this; } + bool operator==(const iterator_base<P, C>& i) const { return _ptr == i._ptr; } + bool operator!=(const iterator_base<P, C>& i) const { return _ptr != i._ptr; } + private: + template<typename T, typename U> friend class iterator_base; + C** _ptr; + }; + + typedef iterator_base<Port, GanvPort> iterator; + typedef iterator_base<const Port, const GanvPort> const_iterator; + + iterator begin() { return iterator((GanvPort**)gobj()->ports->pdata); } + iterator end() { return iterator((GanvPort**)gobj()->ports->pdata + gobj()->ports->len); } + iterator back() { return iterator((GanvPort**)gobj()->ports->pdata + gobj()->ports->len - 1); } + const_iterator begin() const { return const_iterator((const GanvPort**)gobj()->ports->pdata); } + const_iterator end() const { return const_iterator((const GanvPort**)gobj()->ports->pdata + gobj()->ports->len); } + const_iterator back() const { return const_iterator((const GanvPort**)gobj()->ports->pdata + gobj()->ports->len - 1); } + + void set_icon(Gdk::Pixbuf* icon) { + ganv_module_set_icon(gobj(), icon->gobj()); + } + + void embed(Gtk::Widget* widget) { + ganv_module_embed(gobj(), widget->gobj()); + } + + void for_each_port(GanvPortFunction f, void* data) { + ganv_module_for_each_port(gobj(), f, data); + } + + size_t num_ports() const { return gobj()->ports->len; } + + RW_PROPERTY(gboolean, stacked) + RW_PROPERTY(gboolean, show_port_labels) + METHODRET0(ganv_module, double, get_empty_port_breadth) + METHODRET0(ganv_module, double, get_empty_port_depth) + + GanvModule* gobj() { return GANV_MODULE(_gobj); } + const GanvModule* gobj() const { return GANV_MODULE(_gobj); } +}; + +} // namespace Ganv + +#endif // GANV_MODULE_HPP diff --git a/ganv/Node.hpp b/ganv/Node.hpp new file mode 100644 index 0000000..f040e76 --- /dev/null +++ b/ganv/Node.hpp @@ -0,0 +1,81 @@ +/* This file is part of Ganv. + * Copyright 2007-2011 David Robillard <http://drobilla.net> + * + * Ganv is free software: you can redistribute it and/or modify it under + * the terms of the GNU General Public License as published by the Free + * Software Foundation, either version 3 of the License, or (at your option) + * any later version. + * + * Ganv is distributed in the hope that it will be useful, but WITHOUT + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for + * details. + * + * You should have received a copy of the GNU General Public License + * along with Ganv. If not, see <http://www.gnu.org/licenses/>. + */ + +#ifndef GANV_NODE_HPP +#define GANV_NODE_HPP + +#include <glib.h> +#include <libgnomecanvas/gnome-canvas.h> +#include <assert.h> + +#include "ganv/node.h" +#include "ganv/Item.hpp" + +GANV_GLIB_WRAP(Node) + +namespace Ganv { + +class Canvas; +class Node; + +/** An object a Edge can connect to. + */ +class Node : public Item { +public: + Node(Canvas* canvas, GanvNode* gobj) + : Item(GNOME_CANVAS_ITEM(g_object_ref(gobj))) + {} + + ~Node() { + g_object_unref(_gobj); + } + + RW_PROPERTY(const char*, label) + RW_PROPERTY(double, dash_length) + RW_PROPERTY(double, dash_offset) + RW_PROPERTY(double, border_width) + RW_PROPERTY(guint, fill_color) + RW_PROPERTY(guint, border_color) + RW_PROPERTY(gboolean, can_tail) + RW_PROPERTY(gboolean, can_head) + RW_PROPERTY(gboolean, selected) + RW_PROPERTY(gboolean, highlighted) + RW_PROPERTY(gboolean, draggable) + + RW_OBJECT_PROPERTY(Node*, partner); + + METHOD1(ganv_node, tick, double, seconds); + + virtual gboolean is_within(double x1, double y1, + double x2, double y2) const { + return ganv_node_is_within(gobj(), x1, y1, x2, y2); + } + + GanvNode* gobj() { return GANV_NODE(_gobj); } + const GanvNode* gobj() const { return GANV_NODE(_gobj); } + + METHOD2(ganv_node, move, double, dx, double, dy) + METHOD2(ganv_node, move_to, double, x, double, y) + + METHOD0(ganv_node, disconnect); + + sigc::signal<void> signal_moved; +}; + +} // namespace Ganv + +#endif // GANV_NODE_HPP diff --git a/ganv/Port.hpp b/ganv/Port.hpp new file mode 100644 index 0000000..2645b01 --- /dev/null +++ b/ganv/Port.hpp @@ -0,0 +1,73 @@ +/* This file is part of Ganv. + * Copyright 2007-2011 David Robillard <http://drobilla.net> + * + * Ganv is free software: you can redistribute it and/or modify it under + * the terms of the GNU General Public License as published by the Free + * Software Foundation, either version 3 of the License, or (at your option) + * any later version. + * + * Ganv is distributed in the hope that it will be useful, but WITHOUT + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for + * details. + * + * You should have received a copy of the GNU General Public License + * along with Ganv. If not, see <http://www.gnu.org/licenses/>. + */ + +#ifndef GANV_PORT_HPP +#define GANV_PORT_HPP + +#include <stdint.h> + +#include <string> + +#include <libgnomecanvas/gnome-canvas.h> +#include <gdkmm/types.h> + +#include "ganv/Box.hpp" +#include "ganv/port.h" + +GANV_GLIB_WRAP(Port) + +namespace Ganv { + +class Module; + +/** A port on a Module. + * + * This is a group that contains both the label and rectangle for a port. + * + * @ingroup Ganv + */ +class Port : public Box +{ +public: + Port(Module& module, + const std::string& name, + bool is_input, + uint32_t color); + + METHODRET0(ganv_port, gboolean, is_input) + METHODRET0(ganv_port, gboolean, is_output) + + METHODRET0(ganv_port, double, get_natural_width); + METHODRET0(ganv_port, float, get_control_value) + METHODRET0(ganv_port, float, get_control_min) + METHODRET0(ganv_port, float, get_control_max) + METHOD0(ganv_port, show_control) + METHOD0(ganv_port, hide_control) + METHOD1(ganv_port, set_control_is_toggle, gboolean, is_toggle) + METHOD1(ganv_port, set_control_value, float, value) + METHOD1(ganv_port, set_control_min, float, min) + METHOD1(ganv_port, set_control_max, float, max) + + Module* get_module() const; + + GanvPort* gobj() { return GANV_PORT(_gobj); } + const GanvPort* gobj() const { return GANV_PORT(_gobj); } +}; + +} // namespace Ganv + +#endif // GANV_PORT_HPP diff --git a/ganv/box.h b/ganv/box.h new file mode 100644 index 0000000..c50f5c7 --- /dev/null +++ b/ganv/box.h @@ -0,0 +1,125 @@ +/* This file is part of Ganv. + * Copyright 2007-2011 David Robillard <http://drobilla.net> + * + * Ganv is free software: you can redistribute it and/or modify it under + * the terms of the GNU General Public License as published by the Free + * Software Foundation, either version 3 of the License, or (at your option) + * any later version. + * + * Ganv is distributed in the hope that it will be useful, but WITHOUT + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for + * details. + * + * You should have received a copy of the GNU General Public License + * along with Ganv. If not, see <http://www.gnu.org/licenses/>. + */ + +#ifndef GANV_BOX_H +#define GANV_BOX_H + +#include "ganv/node.h" + +G_BEGIN_DECLS + +#define GANV_TYPE_BOX (ganv_box_get_type()) +#define GANV_BOX(obj) (GTK_CHECK_CAST((obj), GANV_TYPE_BOX, GanvBox)) +#define GANV_BOX_CLASS(klass) (GTK_CHECK_CLASS_CAST((klass), GANV_TYPE_BOX, GanvBoxClass)) +#define GANV_IS_BOX(obj) (GTK_CHECK_TYPE((obj), GANV_TYPE_BOX)) +#define GANV_IS_BOX_CLASS(klass) (GTK_CHECK_CLASS_TYPE((klass), GANV_TYPE_BOX)) +#define GANV_BOX_GET_CLASS(obj) (GTK_CHECK_GET_CLASS((obj), GANV_TYPE_BOX, GanvBoxClass)) + +typedef struct _GanvBox GanvBox; +typedef struct _GanvBoxClass GanvBoxClass; + +typedef struct { + double x1, y1, x2, y2; + double border_width; + gboolean stacked; +} GanvBoxCoords; + +struct _GanvBox +{ + GanvNode node; + GanvBoxCoords coords; + GanvBoxCoords old_coords; + double radius_tl; + double radius_tr; + double radius_br; + double radius_bl; +}; + +struct _GanvBoxClass { + GanvNodeClass parent_class; + + void (*set_width)(GanvBox* box, + double width); + + void (*set_height)(GanvBox* box, + double height); +}; + +GType ganv_box_get_type(void); + +static inline double +ganv_box_get_x1(const GanvBox* box) +{ + return box->coords.x1; +} + +static inline double +ganv_box_get_y1(const GanvBox* box) +{ + return box->coords.y1; +} + +static inline double +ganv_box_get_x2(const GanvBox* box) +{ + return box->coords.x2; +} + +static inline double +ganv_box_get_y2(const GanvBox* box) +{ + return box->coords.y2; +} + +static inline double +ganv_box_get_width(const GanvBox* box) +{ + return box->coords.x2 - box->coords.x1; +} + +static inline void +ganv_box_set_width(GanvBox* box, + double width) +{ + GANV_BOX_GET_CLASS(box)->set_width(box, width); +} + +static inline double +ganv_box_get_height(const GanvBox* box) +{ + return box->coords.y2 - box->coords.y1; +} + +static inline void +ganv_box_set_height(GanvBox* box, + double height) +{ + GANV_BOX_GET_CLASS(box)->set_height(box, height); +} + +static inline double +ganv_box_get_border_width(const GanvBox* box) +{ + return box->coords.border_width; +} + +void +ganv_box_normalize(GanvBox* box); + +G_END_DECLS + +#endif /* GANV_BOX_H */ diff --git a/ganv/canvas.h b/ganv/canvas.h new file mode 100644 index 0000000..00d722d --- /dev/null +++ b/ganv/canvas.h @@ -0,0 +1,105 @@ +/* This file is part of Ganv. + * Copyright 2007-2011 David Robillard <http://drobilla.net> + * + * Ganv is free software: you can redistribute it and/or modify it under + * the terms of the GNU General Public License as published by the Free + * Software Foundation, either version 3 of the License, or (at your option) + * any later version. + * + * Ganv is distributed in the hope that it will be useful, but WITHOUT + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for + * details. + * + * You should have received a copy of the GNU General Public License + * along with Ganv. If not, see <http://www.gnu.org/licenses/>. + */ + +#ifndef GANV_CANVAS_H +#define GANV_CANVAS_H + +#include <libgnomecanvas/libgnomecanvas.h> + +#include "ganv/types.h" +#include "ganv/edge.h" + +G_BEGIN_DECLS + +#define GANV_TYPE_CANVAS (ganv_canvas_get_type()) +#define GANV_CANVAS(obj) (GTK_CHECK_CAST((obj), GANV_TYPE_CANVAS, GanvCanvas)) +#define GANV_CANVAS_CLASS(klass) (GTK_CHECK_CLASS_CAST((klass), GANV_TYPE_CANVAS, GanvCanvasClass)) +#define GANV_IS_CANVAS(obj) (GTK_CHECK_TYPE((obj), GANV_TYPE_CANVAS)) +#define GANV_IS_CANVAS_CLASS(klass) (GTK_CHECK_CLASS_TYPE((klass), GANV_TYPE_CANVAS)) +#define GANV_CANVAS_GET_CLASS(obj) (GTK_CHECK_GET_CLASS((obj), GANV_TYPE_CANVAS, GanvCanvasClass)) + +struct GanvCanvasImpl; + +typedef struct _GanvCanvasClass GanvCanvasClass; + +typedef enum { + GANV_VERTICAL, + GANV_HORIZONTAL +} GanvDirection; + +struct _GanvCanvas +{ + GnomeCanvas canvas; + struct GanvCanvasImpl* impl; + GanvDirection direction; + gboolean locked; +}; + +struct _GanvCanvasClass { + GnomeCanvasClass parent_class; +}; + +GType ganv_canvas_get_type(void); + +GanvCanvas* ganv_canvas_new(void); + +GnomeCanvasGroup* +ganv_canvas_get_root(const GanvCanvas* canvas); + +/** Get the default font size in points. */ +double +ganv_canvas_get_default_font_size(const GanvCanvas* canvas); + +/** Get the current font size in points. */ +double +ganv_canvas_get_font_size(const GanvCanvas* canvas); + +void +ganv_canvas_clear_selection(GanvCanvas* canvas); + +typedef void (*GanvEdgeFunction)(GanvEdge* edge); + +/** + * ganv_canvas_for_each_edge_from: + * @f: (scope call): A function to call on every edge leaving @tail. + */ +void +ganv_canvas_for_each_edge_from(GanvCanvas* canvas, + const GanvNode* tail, + GanvEdgeFunction f); + +/** + * ganv_canvas_for_each_edge_to: + * @f: (scope call): A function to call on every edge entering @head. + */ +void +ganv_canvas_for_each_edge_to(GanvCanvas* canvas, + const GanvNode* head, + GanvEdgeFunction f); + +/** + * ganv_canvas_for_each_edge_on: + * @f: (scope call): A function to call on every edge attached to @node. + */ +void +ganv_canvas_for_each_edge_on(GanvCanvas* canvas, + const GanvNode* node, + GanvEdgeFunction f); + +G_END_DECLS + +#endif /* GANV_CANVAS_H */ diff --git a/ganv/circle.h b/ganv/circle.h new file mode 100644 index 0000000..8356294 --- /dev/null +++ b/ganv/circle.h @@ -0,0 +1,55 @@ +/* This file is part of Ganv. + * Copyright 2007-2011 David Robillard <http://drobilla.net> + * + * Ganv is free software: you can redistribute it and/or modify it under + * the terms of the GNU General Public License as published by the Free + * Software Foundation, either version 3 of the License, or (at your option) + * any later version. + * + * Ganv is distributed in the hope that it will be useful, but WITHOUT + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for + * details. + * + * You should have received a copy of the GNU General Public License + * along with Ganv. If not, see <http://www.gnu.org/licenses/>. + */ + +#ifndef GANV_CIRCLE_H +#define GANV_CIRCLE_H + +#include "ganv/node.h" + +G_BEGIN_DECLS + +#define GANV_TYPE_CIRCLE (ganv_circle_get_type()) +#define GANV_CIRCLE(obj) (GTK_CHECK_CAST((obj), GANV_TYPE_CIRCLE, GanvCircle)) +#define GANV_CIRCLE_CLASS(klass) (GTK_CHECK_CLASS_CAST((klass), GANV_TYPE_CIRCLE, GanvCircleClass)) +#define GANV_IS_CIRCLE(obj) (GTK_CHECK_TYPE((obj), GANV_TYPE_CIRCLE)) +#define GANV_IS_CIRCLE_CLASS(klass) (GTK_CHECK_CLASS_TYPE((klass), GANV_TYPE_CIRCLE)) +#define GANV_CIRCLE_GET_CLASS(obj) (GTK_CHECK_GET_CLASS((obj), GANV_TYPE_CIRCLE, GanvCircleClass)) + +typedef struct _GanvCircle GanvCircle; +typedef struct _GanvCircleClass GanvCircleClass; + +typedef struct { + double x, y, radius; + double width; +} GanvCircleCoords; + +struct _GanvCircle +{ + GanvNode node; + GanvCircleCoords coords; + GanvCircleCoords old_coords; +}; + +struct _GanvCircleClass { + GanvNodeClass parent_class; +}; + +GType ganv_circle_get_type(void); + +G_END_DECLS + +#endif /* GANV_CIRCLE_H */ diff --git a/ganv/edge.h b/ganv/edge.h new file mode 100644 index 0000000..91708ba --- /dev/null +++ b/ganv/edge.h @@ -0,0 +1,116 @@ +/* This file is part of Ganv. + * Copyright 2007-2011 David Robillard <http://drobilla.net> + * + * Ganv is free software: you can redistribute it and/or modify it under + * the terms of the GNU General Public License as published by the Free + * Software Foundation, either version 3 of the License, or (at your option) + * any later version. + * + * Ganv is distributed in the hope that it will be useful, but WITHOUT + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for + * details. + * + * You should have received a copy of the GNU General Public License + * along with Ganv. If not, see <http://www.gnu.org/licenses/>. + */ + +#ifndef GANV_EDGE_H +#define GANV_EDGE_H + +#include <libgnomecanvas/libgnomecanvas.h> + +#include "ganv/types.h" +#include "ganv/node.h" + +G_BEGIN_DECLS + +#define GANV_TYPE_EDGE (ganv_edge_get_type()) +#define GANV_EDGE(obj) (GTK_CHECK_CAST((obj), GANV_TYPE_EDGE, GanvEdge)) +#define GANV_EDGE_CLASS(klass) (GTK_CHECK_CLASS_CAST((klass), GANV_TYPE_EDGE, GanvEdgeClass)) +#define GANV_IS_EDGE(obj) (GTK_CHECK_TYPE((obj), GANV_TYPE_EDGE)) +#define GANV_IS_EDGE_CLASS(klass) (GTK_CHECK_CLASS_TYPE((klass), GANV_TYPE_EDGE)) +#define GANV_EDGE_GET_CLASS(obj) (GTK_CHECK_GET_CLASS((obj), GANV_TYPE_EDGE, GanvEdgeClass)) + +typedef struct _GanvEdgeClass GanvEdgeClass; + +typedef struct { + double x1, y1, x2, y2; + double cx1, cy1, cx2, cy2; + double handle_x, handle_y, handle_radius; + double width; + gboolean curved; + gboolean arrowhead; +} GanvEdgeCoords; + +struct _GanvEdge +{ + GnomeCanvasItem item; + GanvNode* tail; + GanvNode* head; + GanvEdgeCoords coords; + GanvEdgeCoords old_coords; + double dash_length; + double dash_offset; + guint color; + gboolean selected; + gboolean highlighted; + gboolean ghost; +}; + +struct _GanvEdgeClass { + GnomeCanvasItemClass parent_class; +}; + +GType ganv_edge_get_type(void); + +GanvEdge* +ganv_edge_new(GanvCanvas* canvas, + GanvNode* tail, + GanvNode* head, + const char* first_prop_name, ...); + +gboolean +ganv_edge_is_within(const GanvEdge* edge, + double x1, + double y1, + double x2, + double y2); + +void +ganv_edge_update_location(GanvEdge* edge); + +void +ganv_edge_select(GanvEdge* edge); + +void +ganv_edge_unselect(GanvEdge* edge); + +void +ganv_edge_highlight(GanvEdge* edge); + +void +ganv_edge_unhighlight(GanvEdge* edge); + +void +ganv_edge_remove(GanvEdge* edge); + +void +ganv_edge_tick(GanvEdge* edge, + double seconds); + +static inline GanvNode* +ganv_edge_get_tail(const GanvEdge* edge) +{ + return edge->tail; +} + +static inline GanvNode* +ganv_edge_get_head(const GanvEdge* edge) +{ + return edge->head; +} + +G_END_DECLS + +#endif /* GANV_EDGE_H */ diff --git a/ganv/ganv.hpp b/ganv/ganv.hpp new file mode 100644 index 0000000..492f7c8 --- /dev/null +++ b/ganv/ganv.hpp @@ -0,0 +1,29 @@ +/* This file is part of Ganv. + * Copyright 2007-2011 David Robillard <http://drobilla.net> + * + * Ganv is free software: you can redistribute it and/or modify it under + * the terms of the GNU General Public License as published by the Free + * Software Foundation, either version 3 of the License, or (at your option) + * any later version. + * + * Ganv is distributed in the hope that it will be useful, but WITHOUT + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for + * details. + * + * You should have received a copy of the GNU General Public License + * along with Ganv. If not, see <http://www.gnu.org/licenses/>. + */ + +#ifndef GANV_GANV_HPP +#define GANV_GANV_HPP + +#include "ganv/Canvas.hpp" +#include "ganv/Circle.hpp" +#include "ganv/Edge.hpp" +#include "ganv/Module.hpp" +#include "ganv/Node.hpp" +#include "ganv/Port.hpp" + +#endif // GANV_GANV_HPP + diff --git a/ganv/module.h b/ganv/module.h new file mode 100644 index 0000000..46496d6 --- /dev/null +++ b/ganv/module.h @@ -0,0 +1,89 @@ +/* This file is part of Ganv. + * Copyright 2007-2011 David Robillard <http://drobilla.net> + * + * Ganv is free software: you can redistribute it and/or modify it under + * the terms of the GNU General Public License as published by the Free + * Software Foundation, either version 3 of the License, or (at your option) + * any later version. + * + * Ganv is distributed in the hope that it will be useful, but WITHOUT + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for + * details. + * + * You should have received a copy of the GNU General Public License + * along with Ganv. If not, see <http://www.gnu.org/licenses/>. + */ + +#ifndef GANV_MODULE_H +#define GANV_MODULE_H + +#include <glib.h> +#include <gtk/gtk.h> + +#include "ganv/box.h" + +G_BEGIN_DECLS + +#define GANV_TYPE_MODULE (ganv_module_get_type()) +#define GANV_MODULE(obj) (GTK_CHECK_CAST((obj), GANV_TYPE_MODULE, GanvModule)) +#define GANV_MODULE_CLASS(klass) (GTK_CHECK_CLASS_CAST((klass), GANV_TYPE_MODULE, GanvModuleClass)) +#define GANV_IS_MODULE(obj) (GTK_CHECK_TYPE((obj), GANV_TYPE_MODULE)) +#define GANV_IS_MODULE_CLASS(klass) (GTK_CHECK_CLASS_TYPE((klass), GANV_TYPE_MODULE)) +#define GANV_MODULE_GET_CLASS(obj) (GTK_CHECK_GET_CLASS((obj), GANV_TYPE_MODULE, GanvModuleClass)) + +typedef struct _GanvModuleClass GanvModuleClass; + +typedef void (*GanvPortFunction)(GanvPort* port, void* data); + +struct _GanvModule +{ + GanvBox box; + GPtrArray* ports; + GnomeCanvasItem* icon_box; + GnomeCanvasItem* embed_item; + int embed_width; + int embed_height; + double widest_input; + double widest_output; + gboolean show_port_labels; + gboolean must_resize; + gboolean port_size_changed; +}; + +struct _GanvModuleClass { + GanvBoxClass parent_class; +}; + +GType ganv_module_get_type(void); + +void +ganv_module_add_port(GanvModule* module, + GanvPort* port); + +double +ganv_module_get_empty_port_breadth(const GanvModule* module); + +double +ganv_module_get_empty_port_depth(const GanvModule* module); + +void +ganv_module_set_icon(GanvModule* module, + GdkPixbuf* icon); + +void +ganv_module_embed(GanvModule* module, + GtkWidget* widget); + +/** + * ganv_module_for_each_port: + * @f: (scope call): A function to call on every port on @module. + */ +void +ganv_module_for_each_port(GanvModule* module, + GanvPortFunction f, + void* data); + +G_END_DECLS + +#endif /* GANV_MODULE_H */ diff --git a/ganv/node.h b/ganv/node.h new file mode 100644 index 0000000..539ef63 --- /dev/null +++ b/ganv/node.h @@ -0,0 +1,209 @@ +/* This file is part of Ganv. + * Copyright 2007-2011 David Robillard <http://drobilla.net> + * + * Ganv is free software: you can redistribute it and/or modify it under + * the terms of the GNU General Public License as published by the Free + * Software Foundation, either version 3 of the License, or (at your option) + * any later version. + * + * Ganv is distributed in the hope that it will be useful, but WITHOUT + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for + * details. + * + * You should have received a copy of the GNU General Public License + * along with Ganv. If not, see <http://www.gnu.org/licenses/>. + */ + +#ifndef GANV_NODE_H +#define GANV_NODE_H + +#include <libgnomecanvas/libgnomecanvas.h> + +#include "ganv/types.h" +#include "ganv/text.h" + +G_BEGIN_DECLS + +#define GANV_TYPE_NODE (ganv_node_get_type()) +#define GANV_NODE(obj) (GTK_CHECK_CAST((obj), GANV_TYPE_NODE, GanvNode)) +#define GANV_NODE_CLASS(klass) (GTK_CHECK_CLASS_CAST((klass), GANV_TYPE_NODE, GanvNodeClass)) +#define GANV_IS_NODE(obj) (GTK_CHECK_TYPE((obj), GANV_TYPE_NODE)) +#define GANV_IS_NODE_CLASS(klass) (GTK_CHECK_CLASS_TYPE((klass), GANV_TYPE_NODE)) +#define GANV_NODE_GET_CLASS(obj) (GTK_CHECK_GET_CLASS((obj), GANV_TYPE_NODE, GanvNodeClass)) + +typedef struct _GanvNodeClass GanvNodeClass; + +struct _GanvNode { + GnomeCanvasGroup group; + struct _GanvNode* partner; + GanvText* label; + double dash_length; + double dash_offset; + double border_width; + guint fill_color; + guint border_color; + gboolean can_tail; + gboolean can_head; + gboolean selected; + gboolean highlighted; + gboolean draggable; +}; + +struct _GanvNodeClass { + GnomeCanvasGroupClass parent_class; + + void (* tick)(GanvNode* self, + double seconds); + + void (* move)(GanvNode* node, + double dx, + double dy); + + void (* move_to)(GanvNode* node, + double x, + double y); + + void (* resize)(GanvNode* node); + + void (* disconnect)(GanvNode* node); + + gboolean (* is_within)(const GanvNode* self, + double x1, + double y1, + double x2, + double y2); + + + void (* tail_vector)(const GanvNode* self, + const GanvNode* head, + double* x, + double* y, + double* dx, + double* dy); + + void (* head_vector)(const GanvNode* self, + const GanvNode* tail, + double* x, + double* y, + double* dx, + double* dy); + + gboolean (* on_event)(GanvNode* node, + GdkEvent* event); +}; + +GType ganv_node_get_type(void); + +static inline gboolean +ganv_node_can_tail(const GanvNode* self) +{ + return self->can_tail; +} + +static inline gboolean +ganv_node_can_head(const GanvNode* self) +{ + return self->can_head; +} + +static inline gboolean +ganv_node_is_within(const GanvNode* self, + double x1, + double y1, + double x2, + double y2) +{ + return GANV_NODE_GET_CLASS(self)->is_within( + self, x1, y1, x2, y2); +} + +static inline void +ganv_node_tick(GanvNode* self, + double seconds) +{ + GanvNodeClass* klass = GANV_NODE_GET_CLASS(self); + if (klass->tick) { + klass->tick(self, seconds); + } +} + +static inline void +ganv_node_tail_vector(const GanvNode* self, + const GanvNode* head, + double* x1, + double* y1, + double* x2, + double* y2) +{ + GANV_NODE_GET_CLASS(self)->tail_vector( + self, head, x1, y1, x2, y2); +} + +static inline void +ganv_node_head_vector(const GanvNode* self, + const GanvNode* tail, + double* x1, + double* y1, + double* x2, + double* y2) +{ + GANV_NODE_GET_CLASS(self)->head_vector( + self, tail, x1, y1, x2, y2); +} + +/** + Get the colours that should currently be used for drawing this node. + Note these may not be identical to the property values because of + highlighting and selection. +*/ +void ganv_node_get_draw_properties(const GanvNode* node, + double* dash_length, + double* border_color, + double* fill_color); + +const char* ganv_node_get_label(const GanvNode* node); + +static inline GanvNode* +ganv_node_get_partner(const GanvNode* node) +{ + return node->partner; +} + +void ganv_node_set_label(GanvNode* node, + const char* str); + +static inline void +ganv_node_move(GanvNode* node, + double dx, + double dy) +{ + GANV_NODE_GET_CLASS(node)->move(node, dx, dy); +} + +static inline void +ganv_node_move_to(GanvNode* node, + double x, + double y) +{ + GANV_NODE_GET_CLASS(node)->move_to(node, x, y); +} + +static inline void +ganv_node_resize(GanvNode* node) +{ + GanvNodeClass* klass = GANV_NODE_GET_CLASS(node); + if (klass->resize) { + klass->resize(node); + } +} + +static inline void +ganv_node_disconnect(GanvNode* node) +{ + GANV_NODE_GET_CLASS(node)->disconnect(node); +} + +G_END_DECLS + +#endif /* GANV_NODE_H */ diff --git a/ganv/port.h b/ganv/port.h new file mode 100644 index 0000000..433eadd --- /dev/null +++ b/ganv/port.h @@ -0,0 +1,126 @@ +/* This file is part of Ganv. + * Copyright 2007-2011 David Robillard <http://drobilla.net> + * + * Ganv is free software: you can redistribute it and/or modify it under + * the terms of the GNU General Public License as published by the Free + * Software Foundation, either version 3 of the License, or (at your option) + * any later version. + * + * Ganv is distributed in the hope that it will be useful, but WITHOUT + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for + * details. + * + * You should have received a copy of the GNU General Public License + * along with Ganv. If not, see <http://www.gnu.org/licenses/>. + */ + +#ifndef GANV_PORT_H +#define GANV_PORT_H + +#include "ganv/box.h" + +struct _GanvModule; + +G_BEGIN_DECLS + +#define GANV_TYPE_PORT (ganv_port_get_type()) +#define GANV_PORT(obj) (GTK_CHECK_CAST((obj), GANV_TYPE_PORT, GanvPort)) +#define GANV_PORT_CLASS(klass) (GTK_CHECK_CLASS_CAST((klass), GANV_TYPE_PORT, GanvPortClass)) +#define GANV_IS_PORT(obj) (GTK_CHECK_TYPE((obj), GANV_TYPE_PORT)) +#define GANV_IS_PORT_CLASS(klass) (GTK_CHECK_CLASS_TYPE((klass), GANV_TYPE_PORT)) +#define GANV_PORT_GET_CLASS(obj) (GTK_CHECK_GET_CLASS((obj), GANV_TYPE_PORT, GanvPortClass)) + +typedef struct _GanvPortClass GanvPortClass; + +typedef struct { + GanvBox* rect; + float value; + float min; + float max; + gboolean is_toggle; +} GanvPortControl; + +struct _GanvPort +{ + GanvBox box; + GanvPortControl* control; + gboolean is_input; +}; + +struct _GanvPortClass { + GanvBoxClass parent_class; +}; + +GType ganv_port_get_type(void); + +GanvPort* +ganv_port_new(GanvModule* module, + gboolean is_input, + const char* first_prop_name, ...); + +void +ganv_port_show_control(GanvPort* port); + +void +ganv_port_hide_control(GanvPort* port); + +void +ganv_port_set_control_is_toggle(GanvPort* port, + gboolean is_toggle); + +void +ganv_port_set_control_value(GanvPort* port, + float value); + +void +ganv_port_set_control_min(GanvPort* port, + float min); + +void +ganv_port_set_control_max(GanvPort* port, + float max); + +double +ganv_port_get_natural_width(const GanvPort* port); + +/** + * ganv_port_get_module: + * Return value: (transfer none): The module @a port is on. + */ +GanvModule* +ganv_port_get_module(const GanvPort* port); + +static inline float +ganv_port_get_control_value(const GanvPort* port) +{ + return port->control ? port->control->value : 0.0f; +} + +static inline float +ganv_port_get_control_min(const GanvPort* port) +{ + return port->control ? port->control->min : 0.0f; +} + +static inline float +ganv_port_get_control_max(const GanvPort* port) +{ + return port->control ? port->control->max : 0.0f; +} + +static inline gboolean +ganv_port_is_input(const GanvPort* port) +{ + return port->is_input; +} + +static inline gboolean +ganv_port_is_output(const GanvPort* port) +{ + return !port->is_input; +} + +G_END_DECLS + +#endif /* GANV_PORT_H */ diff --git a/ganv/text.h b/ganv/text.h new file mode 100644 index 0000000..3c312aa --- /dev/null +++ b/ganv/text.h @@ -0,0 +1,63 @@ +/* This file is part of Ganv. + * Copyright 2007-2011 David Robillard <http://drobilla.net> + * + * Ganv is free software: you can redistribute it and/or modify it under + * the terms of the GNU General Public License as published by the Free + * Software Foundation, either version 3 of the License, or (at your option) + * any later version. + * + * Ganv is distributed in the hope that it will be useful, but WITHOUT + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for + * details. + * + * You should have received a copy of the GNU General Public License + * along with Ganv. If not, see <http://www.gnu.org/licenses/>. + */ + +#ifndef GANV_TEXT_H +#define GANV_TEXT_H + +#include <libgnomecanvas/libgnomecanvas.h> + +#include <cairo.h> + +G_BEGIN_DECLS + +#define GANV_TYPE_TEXT (ganv_text_get_type()) +#define GANV_TEXT(obj) (GTK_CHECK_CAST((obj), GANV_TYPE_TEXT, GanvText)) +#define GANV_TEXT_CLASS(klass) (GTK_CHECK_CLASS_CAST((klass), GANV_TYPE_TEXT, GanvTextClass)) +#define GANV_IS_TEXT(obj) (GTK_CHECK_TYPE((obj), GANV_TYPE_TEXT)) +#define GANV_IS_TEXT_CLASS(klass) (GTK_CHECK_CLASS_TYPE((klass), GANV_TYPE_TEXT)) +#define GANV_TEXT_GET_CLASS(obj) (GTK_CHECK_GET_CLASS((obj), GANV_TYPE_TEXT, GanvTextClass)) + +typedef struct _GanvText GanvText; +typedef struct _GanvTextClass GanvTextClass; + +typedef struct +{ + double x; + double y; + double width; + double height; +} GanvTextCoords; + +struct _GanvText +{ + GnomeCanvasItem item; + cairo_surface_t* surface; + char* text; + GanvTextCoords coords; + GanvTextCoords old_coords; + guint color; +}; + +struct _GanvTextClass { + GnomeCanvasItemClass parent_class; +}; + +GType ganv_text_get_type(void); + +G_END_DECLS + +#endif /* GANV_TEXT_H */ diff --git a/ganv/types.h b/ganv/types.h new file mode 100644 index 0000000..6566f06 --- /dev/null +++ b/ganv/types.h @@ -0,0 +1,29 @@ +/* This file is part of Ganv. + * Copyright 2007-2011 David Robillard <http://drobilla.net> + * + * Ganv is free software: you can redistribute it and/or modify it under + * the terms of the GNU General Public License as published by the Free + * Software Foundation, either version 3 of the License, or (at your option) + * any later version. + * + * Ganv is distributed in the hope that it will be useful, but WITHOUT + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for + * details. + * + * You should have received a copy of the GNU General Public License + * along with Ganv. If not, see <http://www.gnu.org/licenses/>. + */ + +#ifndef GANV_TYPES_H +#define GANV_TYPES_H + +typedef struct _GanvCanvas GanvCanvas; +typedef struct _GanvEdge GanvEdge; +typedef struct _GanvItem GanvItem; +typedef struct _GanvModule GanvModule; +typedef struct _GanvNode GanvNode; +typedef struct _GanvPort GanvPort; + +#endif // GANV_TYPES_H + diff --git a/ganv/types.hpp b/ganv/types.hpp new file mode 100644 index 0000000..c164d72 --- /dev/null +++ b/ganv/types.hpp @@ -0,0 +1,33 @@ +/* This file is part of Ganv. + * Copyright 2007-2011 David Robillard <http://drobilla.net> + * + * Ganv is free software: you can redistribute it and/or modify it under + * the terms of the GNU General Public License as published by the Free + * Software Foundation, either version 3 of the License, or (at your option) + * any later version. + * + * Ganv is distributed in the hope that it will be useful, but WITHOUT + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for + * details. + * + * You should have received a copy of the GNU General Public License + * along with Ganv. If not, see <http://www.gnu.org/licenses/>. + */ + +#ifndef GANV_TYPES_HPP +#define GANV_TYPES_HPP + +namespace Ganv { + +class Canvas; +class Edge; +class Item; +class Module; +class Node; +class Port; + +}; // namespace Ganv + +#endif // GANV_TYPES_HPP + diff --git a/ganv/wrap.hpp b/ganv/wrap.hpp new file mode 100644 index 0000000..40c2d13 --- /dev/null +++ b/ganv/wrap.hpp @@ -0,0 +1,112 @@ +/* This file is part of Ganv. + * Copyright 2007-2011 David Robillard <http://drobilla.net> + * + * Ganv is free software: you can redistribute it and/or modify it under + * the terms of the GNU General Public License as published by the Free + * Software Foundation, either version 3 of the License, or (at your option) + * any later version. + * + * Ganv is distributed in the hope that it will be useful, but WITHOUT + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for + * details. + * + * You should have received a copy of the GNU General Public License + * along with Ganv. If not, see <http://www.gnu.org/licenses/>. + */ + +#ifndef GANV_WRAP_HPP +#define GANV_WRAP_HPP + +#include <glib.h> +#define RW_PROPERTY(type, name) \ + virtual type get_##name() const { \ + type value; \ + g_object_get(G_OBJECT(_gobj), #name, &value, NULL); \ + return value; \ + } \ + virtual void set_##name(type value) { \ + g_object_set(G_OBJECT(_gobj), #name, value, NULL); \ + } + +#define RW_OBJECT_PROPERTY(type, name) \ + type get_##name() const { \ + if (!_gobj) return NULL; \ + Ganv##type ptr; \ + g_object_get(G_OBJECT(_gobj), #name, &ptr, NULL); \ + return Glib::wrap(ptr); \ + } \ + void set_##name(type value) { \ + if (!_gobj) return; \ + gnome_canvas_item_set(GNOME_CANVAS_ITEM(_gobj), \ + #name, value->gobj(), \ + NULL); \ + } + +#define METHOD0(prefix, name) \ + virtual void name() { \ + prefix##_##name(gobj()); \ + } + +#define METHOD1(prefix, name, t1, a1) \ + virtual void name(t1 a1) { \ + prefix##_##name(gobj(), a1); \ + } + +#define METHODRET0(prefix, ret, name) \ + virtual ret name() const { \ + return prefix##_##name(gobj()); \ + } + +#define METHODRETWRAP0(prefix, ret, name) \ + virtual ret name() const { \ + if (gobj()) { \ + return Glib::wrap(prefix##_##name(gobj())); \ + } else { \ + return NULL; \ + } \ + } + +#define METHOD2(prefix, name, t1, a1, t2, a2) \ + virtual void name(t1 a1, t2 a2) { \ + prefix##_##name(gobj(), a1, a2); \ + } + +#define SIGNAL(name, argtype) \ +public: \ + virtual bool on_##name(argtype arg) { \ + return _signal_##name.emit(arg); \ + } \ + sigc::signal<bool, argtype>& signal_##name() { return _signal_##name; } \ +private: \ + sigc::signal<bool, argtype> _signal_##name; + +#define GANV_GLIB_WRAP(Name) \ + namespace Ganv { \ + class Name; \ + } \ + namespace Glib { \ + /** Return a Ganv::CPPType wrapper for a CType. */ \ + static inline Ganv::Name* \ + wrap(Ganv##Name* gobj) \ + { \ + if (gobj) { \ + GQuark key = g_quark_from_string("ganvmm"); \ + return (Ganv::Name*)g_object_get_qdata(G_OBJECT(gobj), key); \ + } else { \ + return NULL; \ + } \ + } \ + static inline const Ganv::Name* \ + wrap(const Ganv##Name* gobj) \ + { \ + if (gobj) { \ + GQuark key = g_quark_from_string("ganvmm"); \ + return (const Ganv::Name*)g_object_get_qdata(G_OBJECT(gobj), key); \ + } else { \ + return NULL; \ + } \ + } \ + } + +#endif // GANV_WRAP_HPP |