Re: Beginner question about drawing and GC

cowboy cowboy wrote:

    draw = gtk_drawing_area_new();
    drawable = draw->window;
    g_assert(drawable != NULL);

You should draw your graphics in "expose-event" handler. Widget receive this event when there's a need to redraw its part on screen. Use smth like:
static draw_expose (GtkWidget *draw, GdkEventExpose *event, gpointer data)
gdk_draw_rectangle (draw->window, draw->style->black_gc,TRUE, 100,100,(draw->allocation.width)/2,(draw->allocation.height)/2);
   return TRUE;
g_signal_connect(draw, "expose-event", G_CALLBACK(draw_expose), 0); /* use gtk_signal_connect() in GTK+-1.2 */

There's a "scribble-simple" example, coming with GTK+ sources - it shows how to implement a simply canvas.

There's GnomeCanvas widget from libgnomecanvas library for doing things like a drawing primitives (btw, it can zoom and antialias): /* this version is to be used with GTK+-2.0 */


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