GanvCanvas

GanvCanvas

Functions

void (*GanvEdgeFunc) ()
void (*GanvNodeFunc) ()
GanvCanvas * ganv_canvas_new ()
void ganv_canvas_clear ()
gboolean ganv_canvas_empty ()
void ganv_canvas_resize ()
GanvItem * ganv_canvas_root ()
void ganv_canvas_set_scroll_region ()
void ganv_canvas_get_scroll_region ()
void ganv_canvas_set_center_scroll_region ()
gboolean ganv_canvas_get_center_scroll_region ()
void ganv_canvas_scroll_to ()
void ganv_canvas_get_scroll_offsets ()
void ganv_canvas_w2c_affine ()
void ganv_canvas_w2c ()
void ganv_canvas_w2c_d ()
void ganv_canvas_c2w ()
void ganv_canvas_window_to_world ()
void ganv_canvas_world_to_window ()
GanvItem * ganv_canvas_get_item_at ()
GanvEdge * ganv_canvas_get_edge ()
void ganv_canvas_remove_edge ()
void ganv_canvas_remove_edge_between ()
GanvDirection ganv_canvas_get_direction ()
void ganv_canvas_set_direction ()
void ganv_canvas_arrange ()
void ganv_canvas_export_dot ()
gboolean ganv_canvas_supports_sprung_layout ()
gboolean ganv_canvas_set_sprung_layout ()
gboolean ganv_canvas_get_locked ()
void ganv_canvas_for_each_node ()
void ganv_canvas_for_each_selected_node ()
void ganv_canvas_for_each_edge ()
void ganv_canvas_for_each_edge_from ()
void ganv_canvas_for_each_edge_to ()
void ganv_canvas_for_each_edge_on ()
void ganv_canvas_for_each_selected_edge ()
void ganv_canvas_select_all ()
void ganv_canvas_clear_selection ()
double ganv_canvas_get_zoom ()
void ganv_canvas_set_zoom ()
void ganv_canvas_zoom_full ()
double ganv_canvas_get_default_font_size ()
double ganv_canvas_get_font_size ()
void ganv_canvas_set_font_size ()
GdkCursor * ganv_canvas_get_move_cursor ()
void ganv_canvas_move_contents_to ()

Types and Values

Description

Functions

GanvEdgeFunc ()

void
(*GanvEdgeFunc) (GanvEdge *edge,
                 void *data);

A node function that takes a user data argument (for callbacks).

Note that in the Gtk world it is considered safe to cast a function to a function with more arguments and call the resulting pointer, so functions like ganv_edge_select can safely be used where a GanvEdgeFunc is expected.

Parameters

edge

Canvas edge.

 

data

User callback data.

 

GanvNodeFunc ()

void
(*GanvNodeFunc) (GanvNode *node,
                 void *data);

A node function that takes a user data argument (for callbacks).

Note that in the Gtk world it is considered safe to cast a function to a function with more arguments and call the resulting pointer, so functions like ganv_node_select can safely be used where a GanvNodeFunc is expected.

Parameters

node

Canvas node.

 

data

User callback data.

 

ganv_canvas_new ()

GanvCanvas *
ganv_canvas_new (double width,
                 double height);

Returns

A newly-created canvas.


ganv_canvas_clear ()

void
ganv_canvas_clear (GanvCanvas *canvas);

Remove all items from the canvas.


ganv_canvas_empty ()

gboolean
ganv_canvas_empty (const GanvCanvas *canvas);

Returns

True if there are no items on the canvas.


ganv_canvas_resize ()

void
ganv_canvas_resize (GanvCanvas *canvas,
                    double width,
                    double height);

Resize the canvas to the given dimensions.


ganv_canvas_root ()

GanvItem *
ganv_canvas_root (GanvCanvas *canvas);

Parameters

canvas

A canvas.

 

Returns

The root group of the canvas.

[transfer none]


ganv_canvas_set_scroll_region ()

void
ganv_canvas_set_scroll_region (GanvCanvas *canvas,
                               double x1,
                               double y1,
                               double x2,
                               double y2);

Sets the scrolling region of a canvas to the specified rectangle. The canvas will then be able to scroll only within this region. The view of the canvas is adjusted as appropriate to display as much of the new region as possible.

Parameters

canvas

A canvas.

 

x1

Leftmost limit of the scrolling region.

 

y1

Upper limit of the scrolling region.

 

x2

Rightmost limit of the scrolling region.

 

y2

Lower limit of the scrolling region.

 

ganv_canvas_get_scroll_region ()

void
ganv_canvas_get_scroll_region (GanvCanvas *canvas,
                               double *x1,
                               double *y1,
                               double *x2,
                               double *y2);

Queries the scrolling region of a canvas.

Parameters

canvas

A canvas.

 

x1

Leftmost limit of the scrolling region (return value).

 

y1

Upper limit of the scrolling region (return value).

 

x2

Rightmost limit of the scrolling region (return value).

 

y2

Lower limit of the scrolling region (return value).

 

ganv_canvas_set_center_scroll_region ()

void
ganv_canvas_set_center_scroll_region (GanvCanvas *canvas,
                                      gboolean center_scroll_region);

When the scrolling region of the canvas is smaller than the canvas window, e.g. the allocation of the canvas, it can be either centered on the window or simply made to be on the upper-left corner on the window. This function lets you configure this property.

Parameters

canvas

A canvas.

 

center_scroll_region

Whether to center the scrolling region in the canvas window when it is smaller than the canvas' allocation.

 

ganv_canvas_get_center_scroll_region ()

gboolean
ganv_canvas_get_center_scroll_region (const GanvCanvas *canvas);

Returns whether the canvas is set to center the scrolling region in the window if the former is smaller than the canvas' allocation.

Parameters

canvas

A canvas.

 

Returns

Whether the scroll region is being centered in the canvas window.


ganv_canvas_scroll_to ()

void
ganv_canvas_scroll_to (GanvCanvas *canvas,
                       int cx,
                       int cy);

Makes a canvas scroll to the specified offsets, given in canvas pixel units. The canvas will adjust the view so that it is not outside the scrolling region. This function is typically not used, as it is better to hook scrollbars to the canvas layout's scrolling adjusments.

Parameters

canvas

A canvas.

 

cx

Horizontal scrolling offset in canvas pixel units.

 

cy

Vertical scrolling offset in canvas pixel units.

 

ganv_canvas_get_scroll_offsets ()

void
ganv_canvas_get_scroll_offsets (const GanvCanvas *canvas,
                                int *cx,
                                int *cy);

Queries the scrolling offsets of a canvas. The values are returned in canvas pixel units.

Parameters

canvas

A canvas.

 

cx

Horizontal scrolling offset (return value).

 

cy

Vertical scrolling offset (return value).

 

ganv_canvas_w2c_affine ()

void
ganv_canvas_w2c_affine (GanvCanvas *canvas,
                        cairo_matrix_t *matrix);

Gets the affine transform that converts from world coordinates to canvas pixel coordinates.

Parameters

canvas

A canvas.

 

matrix

An affine transformation matrix (return value).

 

ganv_canvas_w2c ()

void
ganv_canvas_w2c (GanvCanvas *canvas,
                 double wx,
                 double wy,
                 int *cx,
                 int *cy);

Converts world coordinates into canvas pixel coordinates.

Parameters

canvas

A canvas.

 

wx

World X coordinate.

 

wy

World Y coordinate.

 

cx

X pixel coordinate (return value).

 

cy

Y pixel coordinate (return value).

 

ganv_canvas_w2c_d ()

void
ganv_canvas_w2c_d (GanvCanvas *canvas,
                   double wx,
                   double wy,
                   double *cx,
                   double *cy);

Converts world coordinates into canvas pixel coordinates. This version uses floating point coordinates for greater precision.

Parameters

canvas

A canvas.

 

wx

World X coordinate.

 

wy

World Y coordinate.

 

cx

X pixel coordinate (return value).

 

cy

Y pixel coordinate (return value).

 

ganv_canvas_c2w ()

void
ganv_canvas_c2w (GanvCanvas *canvas,
                 int cx,
                 int cy,
                 double *wx,
                 double *wy);

Converts canvas pixel coordinates to world coordinates.

Parameters

canvas

A canvas.

 

cx

Canvas pixel X coordinate.

 

cy

Canvas pixel Y coordinate.

 

wx

X world coordinate (return value).

 

wy

Y world coordinate (return value).

 

ganv_canvas_window_to_world ()

void
ganv_canvas_window_to_world (GanvCanvas *canvas,
                             double winx,
                             double winy,
                             double *worldx,
                             double *worldy);

Converts window-relative coordinates into world coordinates. You can use this when you need to convert mouse coordinates into world coordinates, for example.

Parameters

canvas

A canvas.

 

winx

Window-relative X coordinate.

 

winy

Window-relative Y coordinate.

 

worldx

X world coordinate (return value).

 

worldy

Y world coordinate (return value).

 

ganv_canvas_world_to_window ()

void
ganv_canvas_world_to_window (GanvCanvas *canvas,
                             double worldx,
                             double worldy,
                             double *winx,
                             double *winy);

Converts world coordinates into window-relative coordinates.

Parameters

canvas

A canvas.

 

worldx

World X coordinate.

 

worldy

World Y coordinate.

 

winx

X window-relative coordinate.

 

winy

Y window-relative coordinate.

 

ganv_canvas_get_item_at ()

GanvItem *
ganv_canvas_get_item_at (GanvCanvas *canvas,
                         double x,
                         double y);

Looks for the item that is under the specified position, which must be specified in world coordinates.

Parameters

canvas

A canvas.

 

x

X position in world coordinates.

 

y

Y position in world coordinates.

 

Returns

The sought item, or NULL if no item is at the specified coordinates.

[transfer none]


ganv_canvas_get_edge ()

GanvEdge *
ganv_canvas_get_edge (GanvCanvas *canvas,
                      GanvNode *tail,
                      GanvNode *head);

Get the edge between two nodes, or NULL if none exists.

Returns

The root group of canvas .

[transfer none]


ganv_canvas_remove_edge ()

void
ganv_canvas_remove_edge (GanvCanvas *canvas,
                         GanvEdge *edge);

Remove edge from the canvas.


ganv_canvas_remove_edge_between ()

void
ganv_canvas_remove_edge_between (GanvCanvas *canvas,
                                 GanvNode *tail,
                                 GanvNode *head);

Remove the edge from tail to head if one exists.


ganv_canvas_get_direction ()

GanvDirection
ganv_canvas_get_direction (GanvCanvas *canvas);

Return the direction of signal flow.


ganv_canvas_set_direction ()

void
ganv_canvas_set_direction (GanvCanvas *canvas,
                           GanvDirection dir);

Set the direction of signal flow.


ganv_canvas_arrange ()

void
ganv_canvas_arrange (GanvCanvas *canvas);

Automatically arrange the canvas contents.


ganv_canvas_export_dot ()

void
ganv_canvas_export_dot (GanvCanvas *canvas,
                        const char *filename);

Write a Graphviz DOT description of the canvas to a file.


ganv_canvas_supports_sprung_layout ()

gboolean
ganv_canvas_supports_sprung_layout (const GanvCanvas *canvas);

Returns

true iff ganv is compiled with sprung layout support.


ganv_canvas_set_sprung_layout ()

gboolean
ganv_canvas_set_sprung_layout (GanvCanvas *canvas,
                               gboolean sprung_layout);

Enable or disable "live" force-directed canvas layout.

Returns

true iff sprung layout was enabled.


ganv_canvas_get_locked ()

gboolean
ganv_canvas_get_locked (const GanvCanvas *canvas);

Return true iff the canvas is locked and nodes may not move.


ganv_canvas_for_each_node ()

void
ganv_canvas_for_each_node (GanvCanvas *canvas,
                           GanvNodeFunc f,
                           void *data);

Parameters

canvas

The canvas.

 

f

A function to call on every node on canvas .

[scope call]

data

Data to pass to f .

 

ganv_canvas_for_each_selected_node ()

void
ganv_canvas_for_each_selected_node (GanvCanvas *canvas,
                                    GanvNodeFunc f,
                                    void *data);

Parameters

canvas

The canvas.

 

f

A function to call on every selected node on canvas .

[scope call]

data

Data to pass to f .

 

ganv_canvas_for_each_edge ()

void
ganv_canvas_for_each_edge (GanvCanvas *canvas,
                           GanvEdgeFunc f,
                           void *data);

Parameters

canvas

The canvas.

 

f

A function to call on every edge on canvas .

[scope call]

data

Data to pass to f .

 

ganv_canvas_for_each_edge_from ()

void
ganv_canvas_for_each_edge_from (GanvCanvas *canvas,
                                const GanvNode *tail,
                                GanvEdgeFunc f,
                                void *data);

Parameters

canvas

The canvas.

 

tail

The tail to enumerate every edge for.

 

f

A function to call on every edge leaving tail .

[scope call]

ganv_canvas_for_each_edge_to ()

void
ganv_canvas_for_each_edge_to (GanvCanvas *canvas,
                              const GanvNode *head,
                              GanvEdgeFunc f,
                              void *data);

Parameters

canvas

The canvas.

 

head

The head to enumerate every edge for.

 

f

A function to call on every edge entering head .

[scope call]

ganv_canvas_for_each_edge_on ()

void
ganv_canvas_for_each_edge_on (GanvCanvas *canvas,
                              const GanvNode *node,
                              GanvEdgeFunc f,
                              void *data);

Parameters

canvas

The canvas.

 

node

The node to enumerate every edge for.

 

f

A function to call on every edge attached to node .

[scope call]

ganv_canvas_for_each_selected_edge ()

void
ganv_canvas_for_each_selected_edge (GanvCanvas *canvas,
                                    GanvEdgeFunc f,
                                    void *data);

Parameters

canvas

The canvas.

 

f

A function to call on every edge attached to node .

[scope call]

data

Data to pass to f .

 

ganv_canvas_select_all ()

void
ganv_canvas_select_all (GanvCanvas *canvas);

Select all items on the canvas.


ganv_canvas_clear_selection ()

void
ganv_canvas_clear_selection (GanvCanvas *canvas);

Deselect any selected items on the canvas.


ganv_canvas_get_zoom ()

double
ganv_canvas_get_zoom (const GanvCanvas *canvas);

Return the current zoom factor (pixels per unit).


ganv_canvas_set_zoom ()

void
ganv_canvas_set_zoom (GanvCanvas *canvas,
                      double zoom);

The anchor point for zooming, i.e. the point that stays fixed and all others zoom inwards or outwards from it, depends on whether the canvas is set to center the scrolling region or not. You can control this using the ganv_canvas_set_center_scroll_region() function. If the canvas is set to center the scroll region, then the center of the canvas window is used as the anchor point for zooming. Otherwise, the upper-left corner of the canvas window is used as the anchor point.

Parameters

canvas

A canvas.

 

zoom

The number of pixels that correspond to one canvas unit.

 

ganv_canvas_zoom_full ()

void
ganv_canvas_zoom_full (GanvCanvas *canvas);

Zoom so all canvas contents are visible.


ganv_canvas_get_default_font_size ()

double
ganv_canvas_get_default_font_size (const GanvCanvas *canvas);

Get the default font size in points.


ganv_canvas_get_font_size ()

double
ganv_canvas_get_font_size (const GanvCanvas *canvas);

Get the current font size in points.


ganv_canvas_set_font_size ()

void
ganv_canvas_set_font_size (GanvCanvas *canvas,
                           double points);

Set the current font size in points.


ganv_canvas_get_move_cursor ()

GdkCursor *
ganv_canvas_get_move_cursor (const GanvCanvas *canvas);

Return the cursor to use while dragging canvas objects.


ganv_canvas_move_contents_to ()

void
ganv_canvas_move_contents_to (GanvCanvas *canvas,
                              double x,
                              double y);

Shift all canvas contents so the top-left object is at (x, y).

Types and Values

GanvCanvasImpl

typedef struct GanvCanvasImpl   GanvCanvasImpl;

enum GanvDirection

Specifies the direction of signal flow on the canvas, which affects the appearance of modules and how the canvas is auto-arranged.

Members

GANV_DIRECTION_DOWN

Signal flows from top to bottom.

 

GANV_DIRECTION_RIGHT

Signal flows from left to right.