Re: the right way to draw in a drawingarea



I've done something similar to this. It was just basic drawing with the mouse.

I did the standard inheriting from a Gtk::DrawingArea and overriding the on_expose_event. In the mouse even signals I just added the notified the drawing area with the necessary information( simple x,y coordinates if I recall )
then just call queue_redraw()

You could probably make this a bit more efficient by only queuing (queueing? ) the redraw in a rectangle of some small area around the mouse event or something. But it worked well without flickering.

If that doesn't make any sense I can try and dig up that code somewhere. But the main idea is to just queue redraws.

Cheers,
Paul

Amadeus W. M. wrote:

I need to draw stuff (shapes rectangles, ellipses, splines, points,
etc), overlayed on top of an image, and I want to update the display in
real time, as the mouse moves. This is similar to doing a selection in
gimp. The way I do this right now is as follows:

The background image is in a Gdk::Pixbuf. I also have a Gtk::DrawingArea
in which I draw my shapes. The display needs to be repainted upon each
expose event, but upon mouse movement as well. So upon each mouse movement
event I render the pixbuf and the shapes into the Darea->get_window(). This works ok, but when the user draws something by dragging the mouse,
the display flickers, even when drawing a simple square.

Now this does not happen in gimp: it does not happen e.g. when a selection
is made, nor when I move the nodes of a path, even though the display must
be re-drawn as the mouse moves, etc. The window is steady and the
drawing smooth.
So I guess there's a better way of overlaying shapes on top of an image,
than the obvious Pixbuf + Darea method. Does anybody know anything about
this?
Thanks!


_______________________________________________
gtkmm-list mailing list
gtkmm-list gnome org
http://mail.gnome.org/mailman/listinfo/gtkmm-list




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