[Vala] Graphing from C to Vala



I have written a C snippet to work with the Vala API to create a GtkWindow with
a grava widget (graph) creating two nodes and one edge.

Here's the source:

To compile it:

  $ valac gravac.c --save-temps *.vala --pkg gtk+-2.0 --pkg cairo -o a.out

Fetch the latest grava sources from:

  http://news.nopcode.org/miau/pvc.cgi?dist=grava

#include "widget.h"
#include "node.h"
#include "edge.h"

int main(int argc, char **argv)
{
        GtkWindow *w;
        GravaNode *node, *node2;
        GravaEdge *edge;
        GravaWidget *grava;

        gtk_init(&argc, &argv);

        grava = grava_widget_new();

        node = grava_node_new();
        grava_node_set(node, "label", "foo:");
        grava_node_set(node, "body", "mov eax, 33\nxor ebx, ebx");
        grava_graph_add_node(grava->graph, node);

        node2 = grava_node_new();
        grava_node_set(node2, "label", "bar:");
        grava_node_set(node2, "body", "mov eax, 33\nxor ebx, ebx");
        grava_graph_add_node(grava->graph, node2);

        edge = grava_edge_with(grava_edge_new(), node, node2);
        grava_graph_add_edge(grava->graph, edge);

        grava_graph_update(grava->graph);

        w = gtk_window_new(GTK_WINDOW_TOPLEVEL);

        gtk_container_add(w, grava_widget_get_widget(grava));

        gtk_widget_show_all(w);

        gtk_main();
}


  --pancake



[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]