[cairo] Dealing with drawingArea update (refresh) for multiple drawings.

Gustavo Sikora wildsoul at gmail.com
Fri Aug 25 13:35:07 PDT 2006

Hi there,

I'll go straight to the point: I'm trying to draw some data structures
like, leftist heaps, B tree, binomial heaps and I'm in a hurry trying
to use gtk and cairo to draw and develop all of the GUI. But I'm new
to this matters, and I'm not finding an apropriate way to draw
multiple nodes as I walk the structures. ie: I have an empty
drawingArea and buttons to let me insert elements. After each insetion
I wish to draw the current state of the structure. Now, I'm only able
to draw the first node, and for some reason the expose_event only
applies when I minimize the interface and open it again.

Some code of what I'm doing:

gboolean expose_event_callback (GtkWidget *widget, GdkEventExpose *event)
    cairo_t *cr;

	/* get a cairo_t */
	cr = gdk_cairo_create (widget->window);

	cairo_rectangle (cr,
			event->area.x, event->area.y,
			event->area.width, event->area.height);
	cairo_clip (cr);
	cairo_destroy (cr);

    return TRUE;

void insert_callback(GtkWidget *widget, gpointer info)
    const gchar *key, *priority;

    key = gtk_entry_get_text(GTK_ENTRY(keyValue));
    priority = gtk_entry_get_text(GTK_ENTRY(priorityValue));
    gtk_entry_set_text (GTK_ENTRY (keyValue), "");
    gtk_entry_set_text (GTK_ENTRY (priorityValue), "");
    insert(atoi(key), atoi(priority), newHeap);

//initialization of my drawingArea
drawArea = gtk_drawing_area_new();
gtk_box_pack_start (GTK_BOX (box1), drawArea, FALSE, FALSE, 0);
gtk_drawing_area_size(GTK_DRAWING_AREA (drawArea), 1010, 657);
gtk_signal_connect(GTK_OBJECT (drawArea), "expose_event",
GTK_SIGNAL_FUNC (expose_event_callback), 0);

//drawHeap from my leftistHeap.h - not complete, only testing for real drawing
template<class T>
void leftisitHeap<T>::drawHeap(cairo_t *cr)
	drawHeap(raizPtr, cr);

template<class T>
void leftistHeap<T>::drawHeap(nodeLeftHeap<T> *auxPtr, cairo_t *cr)
	if (raizPtr == 0)		
		if (auxPtr != 0)

                double x, y;
                x = 505;
                y = 25;
                double radius;
                radius = 12;
                cairo_arc (cr, x, y, radius, 0, 2 * M_PI);
                cairo_set_source_rgb (cr, i, i, i);
                cairo_fill_preserve (cr);
                cairo_set_source_rgb (cr, 0, 0, 0);
                cairo_stroke (cr);

      	        drawHeap(auxPtr->getClftPtr(), cr);
		drawHeap(auxPtr->getCrgtPtr(), cr);

My question again: How can I draw multiple figures (nodes) and make
them visible as soon as I insert a new element?

I found something like swapbuffers for ogl + gtk; pixmap or pixbuff
for simple gtk+ and even only the regular expose_event callback...

I'll really apreciate any help. (links, materials, tutorials... I
"googled" a lot and find a lot of stuff, but too many things regarding
python and ruby... I'm dealing with C/C++

Thanks in advance

More information about the cairo mailing list