RE: Canvas limitations (was Re: Coding question, canvas)




On Tue, 9 Feb 1999, Richard Hult wrote:
> 
> translate: perform a simple translation (dx, dy), then request an
> update.
> 
> bounds: return the item's bounding box.
> 
> update: build an ArtVpath, make an affine transformation and update the
> region of the canvas that is covered by the calculated svpclip. This
> would be done by putting lots of small paths together, one for each
> dot, as you suggested, right?
> 

Hmm not quite. You *can* build a vpath; you could also draw to the RGB
buffer, or if using the canvas in no-AA mode, do some X stuff.

See this for the difference between update() and render():
http://www.levien.com/gnome/canvas-aa-items.html

Basically update() is totally free-form; you just do anything you need to
do in order to prepare to render(). For most items, this means getting
your SVP ready.

You don't want to put lots of small paths together as in EZPaste; that's
what's broken about it. It is *slow*. Instead, you want to create a single
small path, and in the render method, translate it over and over and
re-render. i.e. have just one dot SVP, and stamp it multiple times.

Alternatively just draw to the RGB buffer (which actually is probably
better for a grid like this).

The affine you get in update() must be accounted for in render(). So if
you don't transform the SVP in update, you have to save the affine to use
in render.

> render:	gnome_canvas_render_svp for the item, and then propagate
> towards to root of the class tree.
> 

Yes. Well, just draw to the buffer you are passed, how you decide to do
that is up to you. If you use the canvas-util.h SVP routines it saves some
worrying with internals, if you don't you have to do some special stuff
see canvas-scatter.cc in Guppi.

> point: calculate the distance from a point to the item. In my example,
> with lots of small dots, would this be the distance from the point to
> the nearest dot then? Or would it be zero since it's within the
> bounding box? The bounding box would be the complete area of the grid in
> my case, if I got that part right.
> 

Realistically I think only 0 vs. non-zero matters much. You can make up
the distance number to your liking.

> event: take care of events.
> 

You don't have to provide an event handler unless you want to. You could
instead just connect to "event" from outside the item.

> Did I get this right? 

You have the idea.

The #1 thing to watch out for is item coordinates vs. world coordinates
vs. canvas pixel coordinates. These are confusing as hell.
The rule is basically: all coordinates are item coordinates, except that
you should draw in canvas pixel coordinates.

Havoc



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