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




> So a "grid" (dots that objects snap to) would be a candidate for an own
> canvas item? I tried putting lots of rectangles on my canvas and it's not
> exactly slow but it takes a bit of memory.

Yes, this is a good candidate for a Canvas item.

Consider the Gnumeric "grid" you see, it is a specialized canvas item
that draw the grid (and the sheet contents while it is at it).

Doing a grid as a canvas should be very simple to do.

> Something that comes to mind is that it's a kind of weird object. It covers
> the whole canvas but there is a lot of space really, just some dots here and
> there. Will this cause lots of redraw requests, when objects move over the
> grid, even over the space between the dots? This seems a bit inefficient.

Yes, this is the case.  But it is not inneficient at all, the Canvas
creates a Pixmap on the server for the exposed region, and you draw on 
that Pixmap.  Only this exposed region is ever drawn into.

Your code could basically only clear, compute the grids it has to draw
and draw those for the exposed region.

> Is there a commented example of this somewhere in the sources? Is a
> copy-and-paste-operation from the already defined canvasitems the way to go?

The canvas items as shipped on the gnome-libs/libgnomeui are a good
example of those.

gnumeric/src/item-grid.c is a canvas item that draws the spreadsheet
grid and the cell contents.

gnumeric/src/item-bar.c is a canvas item used to draw the column and
row labels in Gnumeric.

gnumeric/src/item-cursor.c is a specialized canvas item for drawing
the "selection" cursor of the spreadsheet.

gnome-libs/libgnomeui/gnome-icon-item.c is a specialized and
non-complete canvas item that implements a little editable text.  It
is not a full blown canvas item.  I just did one to use the
anti-flicker side effect of the canvas in the gnome-icon-list.

Miguel
-- 
miguel@gnu.org



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