Re: Beginner question about drawing and GC
- From: Olexiy Avramchenko <olexiy irtech cn ua>
- To: cowboy cowboy <yong_zhy hotmail com>
- Cc: gtk-app-devel-list gnome org
- Subject: Re: Beginner question about drawing and GC
- Date: Sat, 03 Jan 2004 12:57:14 +0200
cowboy cowboy wrote:
    draw = gtk_drawing_area_new();
    gtk_widget_set_usize(draw,300,300);
    gtk_box_pack_start(GTK_BOX(hbox),draw,TRUE,TRUE,5);
    gtk_widget_show(draw);
    drawable = draw->window;
    g_assert(drawable != NULL);
    
gdk_draw_rectangle(drawable,draw->style->black_gc,TRUE,100,100,(draw->allocation.width)/2,(draw->allocation.height)/2);
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):
http://developer.gnome.org/doc/GGAD/cha-canvas.html
http://developer.gnome.org/doc/API/2.0/libgnomecanvas/index.html    /* 
this version is to be used with GTK+-2.0 */
   Olexiy
[
Date Prev][
Date Next]   [
Thread Prev][
Thread Next]   
[
Thread Index]
[
Date Index]
[
Author Index]