File: Canvas.hpp

package info (click to toggle)
ganv 0~svn4468~dfsg0-1
  • links: PTS, VCS
  • area: main
  • in suites: wheezy
  • size: 1,232 kB
  • sloc: python: 12,014; ansic: 6,656; cpp: 2,437; sh: 40; makefile: 23
file content (133 lines) | stat: -rw-r--r-- 3,725 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
/* This file is part of Ganv.
 * Copyright 2007-2012 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 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 canvas widget for graph-like UIs.
 */

/** 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();

	METHOD0(ganv_canvas, destroy);
	METHOD0(ganv_canvas, clear_selection);
	METHOD0(ganv_canvas, select_all);
	METHOD0(ganv_canvas, get_zoom);
	METHOD1(ganv_canvas, set_zoom, double, pix_per_unit);
	METHOD1(ganv_canvas, set_font_size, double, points);
	METHOD2(ganv_canvas, set_scale, double, zoom, double, points);
	METHOD0(ganv_canvas, zoom_full);
	METHODRET0(ganv_canvas, double, get_font_size)
	METHODRET0(ganv_canvas, double, get_default_font_size)
	METHOD1(ganv_canvas, export_dot, const char*, filename);
	METHOD0(ganv_canvas, arrange);
	METHOD2(ganv_canvas, move_contents_to, double, x, double, y);
	METHOD2(ganv_canvas, resize, double, width, double, height);
	METHOD2(ganv_canvas, for_each_node, GanvNodeFunc, f, void*, data)
	METHOD2(ganv_canvas, for_each_selected_node, GanvNodeFunc, f, void*, data)

	METHOD2(ganv_canvas, for_each_edge_from,
	        const GanvNode*, tail,
	        GanvEdgeFunc, f);

	METHOD2(ganv_canvas, for_each_edge_to,
	        const GanvNode*, head,
	        GanvEdgeFunc, f);

	METHOD2(ganv_canvas, for_each_edge_on,
	        const GanvNode*, node,
	        GanvEdgeFunc, f);

	METHOD0(ganv_canvas, get_move_cursor);

	RW_PROPERTY(gboolean, locked);
	RW_PROPERTY(double, width)
	RW_PROPERTY(double, height)
	RW_PROPERTY(GanvDirection, direction);

	Gtk::Layout& widget();

	/** 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);

	typedef void (*EdgePtrFunc)(GanvEdge* edge, void* data);

	void for_each_edge(EdgePtrFunc f, void* data);
	void for_each_selected_edge(EdgePtrFunc f, void* data);

	void get_scroll_offsets(int& cx, int& cy) const;
	void scroll_to(int x, int y);

	GQuark wrapper_key();

	GanvItem* root();

	GanvCanvas*       gobj();
	const GanvCanvas* gobj() const;

	sigc::signal<bool, GdkEvent*>    signal_event;
	sigc::signal<void, Node*, Node*> signal_connect;
	sigc::signal<void, Node*, Node*> signal_disconnect;

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