[Gtk-sharp-list] DrawingArea - allocating needed space

Richard Boaz riboaz at xs4all.nl
Sat Nov 11 02:12:55 EST 2006

> White Spirit wrote:
>> If you're able to move the drawn elements, another possibility is to
>> destroy the drawing area and recreate it with the new dimensions, and
>> then redraw from your starting point.
> Well, it's a kind of what I've been planning to do but I thought there
> may be a slicker way. If I want to move everything I have to recalculate
>   positions of all elements and that costs time.

One way, here, is to have two coordinate systems.  One defining your
drawing coordinates, i.e., absolute pixel positions, and the other your
user coordinates, i.e, the layout of your images in relation to each
other.  In providing your own transform function between the two, you then
do all drawing to absolute pixel positions always only specifying your
user coordinates to the transform function.

This way, when your drawing area necessarily must change size, you simply
modify the coordinate system boundary definitions of your transform and
then replot your image using the same drawing routine as before.  In this
manner, the only cost in time is to replot, and this you must do anyway.

You can get even fancier (or, rather, more complicated, but faster) by not
redrawing anything that has previously been drawn.  For example, when you
must make your drawing area larger, say 100x100, make a new drawing area
and copy the currently displayed image to the new drawing area, copying
from (0,0) to the new (0,0) equivalent (e.g., (50,50)).  Having reset your
transform accordingly, the new elements can now be added using the
transform from above.

and, there's always a slicker way: imagine, experiment, and persist, you
will find it.



>> Assuming you're using a
>> Gdk.Pixmap, it'll be a simple matter of displaying the contents again.
> Actually, I'm using Cairo to draw in the DrawingArea and that is one of
> the reasons why I'm trying to keep it as slick as possible elsewhere.
> Thanks,
> Piotr
> _______________________________________________
> gtk-list mailing list
> gtk-list at gnome.org
> http://mail.gnome.org/mailman/listinfo/gtk-list

More information about the Gtk-sharp-list mailing list