Re: [gtk-list] gdk drawing funks




Stefan Ottosson <ottosson@canit.se> writes:

> hi, 
> I'm trying to make use of gdks drawing funktions.
> All I want to do is draw a rectangle on the toplevel window.
> 
> Here's what I tried to do, this generates a "drawable != null" message..
...
> canvas = gtk_drawing_area_new();
> gtk_drawing_area_size(GTK_DRAWING_AREA(canvas), 200, 200);
> gtk_widget_show(canvas);
> 
> gtk_container_add(GTK_CONTAINER(topwin), canvas);
> 
> gdk_draw_rectangle(canvas->window, canvas->style->black_gc, TRUE, 10, 10,
> 80, 50); 

Just to amplify a bit on what people have said - in most cases
you should do all your drawing inside an "expose_event" callback. The
window is in general not created until after you call gtk_main().

Even after the window is created, you have to be prepared to redraw
everything when you get an "expose_event" because the contents of
the window will not be saved. You can take a look at the testinput.c
program in the gtk+/gtk directory - it has a halfway clear example
of how to handle drawing to a offscreen pixmap - which generally make
things look better and makes life a bit simpler.

Regards,
                                        Owen



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