I’ve got to know goocanvas (API documentation, browse CVS) better over the last week. I achieved what I needed, but it could have been easier.
You can’t set the position of goocanvas items. Well, you can set the x,y position of a GooCanvasRect, and you can set the points in a GooCanvasPolyline, but there is no generic position API in the base GooCanvasItem interface.
This makes it very difficult to write generic code for dragging, loading, and saving. All the items could support a generic API – it wouldn’t matter if the x,y is some arbitrary point in the item. I have implemented this in derived classes in C++, with some multiple inheritance awkwardness, but life would be far easier if it was in the GooCanvasItem base class itself. Erik Osheim did this in Python too. You wouldn’t want to do it in C. It seems to be a regression compared to libgnomecanvas, which has gnome_canvas_item_move().
Note that you can “translate” generic GooCanvasItem items, but
I guess this is the cairo drawing system, but the canvas API shouldn’t force that on me. This is a major problem in the API for me, so I hope I can persuade Damon to let us add this.
Update: We created a GooCanvas generic positioning patch for this.
You have to implement too much yourself. Not every application needs the ability to drag and resize items, but many do, and it would be nice if this was easy and consistent. I implemented drag-to-move, snap to grid, snap to rules, ctrl-to-restrict-drag-to-one-axis, resizing via corners and edges with appropriate arrow cursors, and signalling for a context menu on right-click. I still need to do selection highlighting and moving of multiple selections. I did that with a CanvasGroupResizable class that can take a child to be manipulated, though it currently only works with a rectangle child. It uses the generically-movable rectangles and lines that I mentioned above.
The next person to reimplement this will probably make it behave subtly differently.
Now that I finally have a canvas with the basic functionality that I need, I was able to reimplement and improve Glom’s Relationships Overview. I’ll now start using it to implement print layouts showing field data.
goo_canvas_render() makes printing really easy with GtkPrintOperation.
At first glance, libccc has many of the same problems. Note that I was dissuaded from trying libccc first because it was started after goocanvas, without any stated reason, and due to the lack of documentation on the functions that I looked at.
I should look at HippoCanvas too.
June 30th, 2008 at 12:24 am
Hey Murray, I’m getting hit with similar issues. Like not being able to resize the RectangleItem using pixel size, will it is constructed that way. etc.
I wonder if we couldn’t add that directly to goocanvasmm.
June 30th, 2008 at 5:52 am
Hub, do you mean the “No generic positioning of items”? I think we need to do this in a branch of goocanvas and then try really hard to get it used by goocanvas itself. If not then we’ll have a useful fork.
For now, I have a parallel hierarchy of canvas items in Glom that makes this possible. You might find it useful.
June 30th, 2008 at 12:42 pm
I’m up to the point where I might rewrite something for just what I need. It is gonna suck.
June 30th, 2008 at 12:46 pm
It would be far easier (and more useful) to fork rather than to reimplement.
December 8th, 2008 at 8:28 am
By the way, I updated this post with links to 2 patches to add generic positioning and to move child API into a Container class.