re: non-interactive drawing area



I am new to GTK and I read the tutorial on www.gtk.org.
I want to use an area in my program, where I can draw things on,
e.g. rectangles or a diagram. It should be non-interactive,
means, the user should not be able to modify the area in any way
(no events). And the backgound should be white.

In the tutorial are examples, but they are interactive and
I don't know if I need the widgets like DrawingArea ...

What widgets do I have to use and how can I draw things on?
(you don't need to answer in detail, some hints and a link
to a manual would be enough ...)

By default, a DrawingArea is non-interactive, it starts
to be interactive only when you connect signals. Usually 
you would connect a DrawingArea to the signals below 
(taken from my own code).

In your case, just remove the "motion_notify_event" and
the "button_press_event" signals, which handle mouse movements
and clicks. You still need "expose_event" and "configure_event",
to redraw the picture and resize it, when the window size changes
or parts of the image were hidden before, for example. You might
ignore "realize" , particularly if you have little experience.

If you need to draw 3D stuff, then use OpenGL on top of your
DrawingArea (as I do), otherwise just use plain drawingArea.
For plain DrawingArea examples, I suggest the scribble example 
that comes with Gtk, and if you need something more elaborated,
you could look into Eric Harlow's example of a analog watch
made with DrawingArea, the code is free and you should be able
to find it with Google (perhaps it is at www.gtk.org, I don't
know).

Carlos
http://www.gamgi.org/

/*************************************
 * Redraw image when window exposed. *
 *************************************/

gtk_signal_connect (GTK_OBJECT (gl_area), "expose_event",
GTK_SIGNAL_FUNC (gamgi_mesa_gl_area_expose), window);

/**************************************
 * Handle mouse motion in the gl_area *
 **************************************/

gtk_signal_connect (GTK_OBJECT (gl_area), "motion_notify_event",
GTK_SIGNAL_FUNC (gamgi_mesa_gl_area_notify), window);

/*************************************
 * Handle mouse press in the gl_area *
 *************************************/

gtk_signal_connect (GTK_OBJECT (gl_area), "button_press_event",
GTK_SIGNAL_FUNC (gamgi_mesa_gl_area_press), window);

/*************************************************************
 * When window is resized viewport needs to be resized also. *
 *************************************************************/

gtk_signal_connect (GTK_OBJECT (gl_area), "configure_event",
GTK_SIGNAL_FUNC (gamgi_mesa_gl_area_configure), window);

/****************************************************
 * Do initialization when widget has been realized. *
 ****************************************************/

gtk_signal_connect(GTK_OBJECT (gl_area), "realize",
GTK_SIGNAL_FUNC (gamgi_mesa_gl_area_start), window);



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