summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--ganv/Canvas.hpp40
-rw-r--r--ganv/canvas.h73
-rw-r--r--src/Canvas.cpp170
3 files changed, 157 insertions, 126 deletions
diff --git a/ganv/Canvas.hpp b/ganv/Canvas.hpp
index 477277d..05ba6e7 100644
--- a/ganv/Canvas.hpp
+++ b/ganv/Canvas.hpp
@@ -57,8 +57,7 @@ public:
Gtk::Layout& widget();
- /** Remove all ports and edges and modules. */
- void destroy();
+ METHOD0(ganv_canvas, destroy);
/** Get the edge from @c tail to @c head if one exists. */
Edge* get_edge(Node* tail, Node* head) const;
@@ -66,18 +65,12 @@ public:
/** 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();
+ METHOD0(ganv_canvas, clear_selection);
+ METHOD0(ganv_canvas, select_all);
RW_PROPERTY(gboolean, locked);
- /** Return the current zoom factor (pixels per unit). */
- double get_zoom();
+ METHOD0(ganv_canvas, get_zoom);
/** Set the current zoom factor (pixels per unit). */
void set_zoom(double pix_per_unit);
@@ -98,21 +91,22 @@ public:
void render_to_dot(const std::string& filename);
/** Automatically arrange the canvas contents if Graphviz is available. */
- void arrange(bool use_length_hints=false);
+ void arrange();
- /** Shift all canvas contents so the top-left object is at (x, y). */
- void move_contents_to(double x, double y);
+ METHOD2(ganv_canvas, move_contents_to, double, x, double, y);
RW_PROPERTY(double, width)
RW_PROPERTY(double, height)
- /** Resize the canvas to the given dimensions. */
- void resize(double width, double height);
+ METHOD2(ganv_canvas, resize, double, width, double, height);
RW_PROPERTY(GanvDirection, direction);
- void for_each_node(GanvNodeFunction f, void* data);
- void for_each_selected_node(GanvNodeFunction f, void* data);
+ METHOD2(ganv_canvas, for_each_node,
+ GanvNodeFunction, f, void*, data)
+
+ METHOD2(ganv_canvas, for_each_selected_node,
+ GanvNodeFunction, f, void*, data)
typedef void (*EdgePtrFunction)(GanvEdge* edge, void* data);
@@ -131,15 +125,15 @@ public:
const GanvNode*, node,
GanvEdgeFunction, f);
- GQuark wrapper_key();
-
- GanvItem* root();
-
- GdkCursor* move_cursor();
+ METHOD0(ganv_canvas, get_move_cursor);
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;
diff --git a/ganv/canvas.h b/ganv/canvas.h
index 352c13c..829b8e2 100644
--- a/ganv/canvas.h
+++ b/ganv/canvas.h
@@ -63,6 +63,10 @@ GType ganv_canvas_get_type(void);
GanvCanvas* ganv_canvas_new(double width, double height);
+/**
+ * ganv_canvas_resize:
+ * Resize the canvas to the given dimensions.
+ */
void
ganv_canvas_resize(GanvCanvas* canvas, double width, double height);
@@ -90,10 +94,6 @@ ganv_canvas_remove_edge_between(GanvCanvas* canvas,
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_set_font_size(GanvCanvas* canvas, double points);
@@ -118,6 +118,22 @@ ganv_canvas_for_each_node(GanvCanvas* canvas,
GanvNodeFunction f,
void* data);
+void
+ganv_canvas_for_each_selected_node(GanvCanvas* canvas,
+ GanvNodeFunction f,
+ void* data);
+
+/**
+ * ganv_canvas_for_each_edge:
+ * @canvas: The canvas.
+ * @f: (scope call): A function to call on every edge on @canvas.
+ * @data: Data to pass to @f.
+ */
+void
+ganv_canvas_for_each_edge(GanvCanvas* canvas,
+ GanvEdgeFunction f,
+ void* data);
+
/**
* ganv_canvas_for_each_edge_from:
* @canvas: The canvas.
@@ -151,6 +167,55 @@ ganv_canvas_for_each_edge_on(GanvCanvas* canvas,
const GanvNode* node,
GanvEdgeFunction f);
+/**
+ * ganv_canvas_destroy:
+ * Remove all items from the canvas.
+ */
+void
+ganv_canvas_destroy(GanvCanvas* canvas);
+
+/**
+ * ganv_canvas_select_all:
+ * Select all items on the canvas.
+ */
+void
+ganv_canvas_select_all(GanvCanvas* canvas);
+
+/**
+ * ganv_canvas_get_zoom:
+ * Return the current zoom factor (pixels per unit).
+ */
+double
+ganv_canvas_get_zoom(GanvCanvas* canvas);
+
+/**
+ * ganv_canvas_get_font_size:
+ * Get the current font size in points.
+ */
+double
+ganv_canvas_get_font_size(const GanvCanvas* canvas);
+
+/**
+ * ganv_canvas_set_scale:
+ * Set the zoom and font size for the canvas.
+ */
+void
+ganv_canvas_set_scale(GanvCanvas* canvas, double zoom, double points);
+
+/**
+ * ganv_canvas_get_move_cursor:
+ * Return the cursor to use while dragging canvas objects.
+ */
+GdkCursor*
+ganv_canvas_get_move_cursor(const GanvCanvas* canvas);
+
+/**
+ * ganv_canvas_move_contents_to:
+ * Shift all canvas contents so the top-left object is at (x, y).
+ */
+void
+ganv_canvas_move_contents_to(GanvCanvas* canvas, double x, double y);
+
G_END_DECLS
#endif /* GANV_CANVAS_H */
diff --git a/src/Canvas.cpp b/src/Canvas.cpp
index 2303ee4..e8be715 100644
--- a/src/Canvas.cpp
+++ b/src/Canvas.cpp
@@ -185,7 +185,7 @@ struct GanvCanvasImpl {
void selection_move_finished();
#ifdef HAVE_AGRAPH
- GVNodes layout_dot(bool use_length_hints, const std::string& filename);
+ GVNodes layout_dot(const std::string& filename);
#endif
void remove_edge(GanvEdge* c);
@@ -453,7 +453,7 @@ gv_set(void* subject, const char* key, double value)
}
GVNodes
-GanvCanvasImpl::layout_dot(bool use_length_hints, const std::string& filename)
+GanvCanvasImpl::layout_dot(const std::string& filename)
{
GVNodes nodes;
@@ -1502,59 +1502,6 @@ Canvas::zoom_full()
}
void
-Canvas::clear_selection()
-{
- impl()->clear_selection();
-}
-
-double
-Canvas::get_zoom()
-{
- return impl()->_zoom;
-}
-
-void
-Canvas::select_all()
-{
- clear_selection();
- FOREACH_ITEM(impl()->_items, m) {
- impl()->select_item(*m);
- }
-}
-
-void
-Canvas::destroy()
-{
- impl()->_selected_items.clear();
- impl()->_selected_edges.clear();
-
- Items items = impl()->_items; // copy
- FOREACH_ITEM(items, i) {
- gtk_object_destroy(GTK_OBJECT(*i));
- }
- impl()->_items.clear();
-
- GanvCanvasImpl::Edges edges = impl()->_edges; // copy
- FOREACH_EDGE(edges, i) {
- gtk_object_destroy(GTK_OBJECT(*i));
- }
- impl()->_edges.clear();
-
- impl()->_selected_ports.clear();
- impl()->_connect_port = NULL;
-}
-
-void
-Canvas::set_default_placement(Node* i)
-{
- // Simple cascade. This will get more clever in the future.
- double x = ((get_width() / 2.0) + (impl()->_items.size() * 25));
- double y = ((get_height() / 2.0) + (impl()->_items.size() * 25));
-
- i->move_to(x, y);
-}
-
-void
Canvas::remove_edge(Node* item1, Node* item2)
{
Edge* edge = get_edge(item1, item2);
@@ -1586,16 +1533,16 @@ void
Canvas::render_to_dot(const string& dot_output_filename)
{
#ifdef HAVE_AGRAPH
- GVNodes nodes = impl()->layout_dot(false, dot_output_filename);
+ GVNodes nodes = impl()->layout_dot(dot_output_filename);
nodes.cleanup();
#endif
}
void
-Canvas::arrange(bool use_length_hints)
+Canvas::arrange()
{
#ifdef HAVE_AGRAPH
- GVNodes nodes = impl()->layout_dot(use_length_hints, "");
+ GVNodes nodes = impl()->layout_dot("");
double least_x=HUGE_VAL, least_y=HUGE_VAL, most_x=0, most_y=0;
@@ -1661,41 +1608,6 @@ Canvas::arrange(bool use_length_hints)
}
void
-Canvas::move_contents_to(double x, double y)
-{
- double min_x=HUGE_VAL, min_y=HUGE_VAL;
- FOREACH_ITEM(impl()->_items, i) {
- double x, y;
- g_object_get(*i, "x", &x, "y", &y, NULL);
- min_x = std::min(min_x, x);
- min_y = std::min(min_y, y);
- }
- impl()->move_contents_to_internal(x, y, min_x, min_y);
-}
-
-void
-Canvas::resize(double width, double height)
-{
- impl()->resize(width, height);
-}
-
-void
-Canvas::for_each_node(GanvNodeFunction f, void* data)
-{
- FOREACH_ITEM(impl()->_items, i) {
- f(*i, data);
- }
-}
-
-void
-Canvas::for_each_selected_node(GanvNodeFunction f, void* data)
-{
- FOREACH_ITEM(impl()->_selected_items, i) {
- f(*i, data);
- }
-}
-
-void
Canvas::for_each_edge(EdgePtrFunction f, void* data)
{
FOREACH_EDGE(impl()->_edges, i) {
@@ -1741,12 +1653,6 @@ Canvas::wrapper_key()
return impl()->_wrapper_key;
}
-GdkCursor*
-Canvas::move_cursor()
-{
- return impl()->_move_cursor;
-}
-
GanvCanvas*
Canvas::gobj()
{
@@ -1975,6 +1881,12 @@ ganv_canvas_set_font_size(GanvCanvas* canvas, double points)
canvas->impl->set_zoom_and_font_size(canvas->impl->_zoom, points);
}
+void
+ganv_canvas_set_scale(GanvCanvas* canvas, double zoom, double points)
+{
+ canvas->impl->set_zoom_and_font_size(zoom, points);
+}
+
static void
set_node_direction(GanvNode* node, void* data)
{
@@ -2094,6 +2006,16 @@ ganv_canvas_for_each_node(GanvCanvas* canvas,
}
void
+ganv_canvas_for_each_selected_node(GanvCanvas* canvas,
+ GanvNodeFunction f,
+ void* data)
+{
+ FOREACH_ITEM(canvas->impl->_selected_items, i) {
+ f(*i, data);
+ }
+}
+
+void
ganv_canvas_for_each_edge_from(GanvCanvas* canvas,
const GanvNode* tail,
GanvEdgeFunction f)
@@ -2131,4 +2053,54 @@ ganv_canvas_port_event(GanvCanvas* canvas,
return canvas->impl->port_event(event, port);
}
+void
+ganv_canvas_destroy(GanvCanvas* canvas)
+{
+ canvas->impl->_selected_items.clear();
+ canvas->impl->_selected_edges.clear();
+
+ Items items = canvas->impl->_items; // copy
+ FOREACH_ITEM(items, i) {
+ gtk_object_destroy(GTK_OBJECT(*i));
+ }
+ canvas->impl->_items.clear();
+
+ GanvCanvasImpl::Edges edges = canvas->impl->_edges; // copy
+ FOREACH_EDGE(edges, i) {
+ gtk_object_destroy(GTK_OBJECT(*i));
+ }
+ canvas->impl->_edges.clear();
+
+ canvas->impl->_selected_ports.clear();
+ canvas->impl->_connect_port = NULL;
+}
+
+void
+ganv_canvas_select_all(GanvCanvas* canvas)
+{
+ ganv_canvas_clear_selection(canvas);
+ FOREACH_ITEM(canvas->impl->_items, m) {
+ canvas->impl->select_item(*m);
+ }
+}
+
+double
+ganv_canvas_get_zoom(GanvCanvas* canvas)
+{
+ return canvas->impl->_zoom;
+}
+
+void
+ganv_canvas_move_contents_to(GanvCanvas* canvas, double x, double y)
+{
+ double min_x=HUGE_VAL, min_y=HUGE_VAL;
+ FOREACH_ITEM(canvas->impl->_items, i) {
+ double x, y;
+ g_object_get(*i, "x", &x, "y", &y, NULL);
+ min_x = std::min(min_x, x);
+ min_y = std::min(min_y, y);
+ }
+ canvas->impl->move_contents_to_internal(x, y, min_x, min_y);
+}
+
} // extern "C"