Canvas API proposal



Hi,

  some time ago (~1.5 years) I have been talking to Tim Janik about
several things, so I came up to think about a canvas that provides the
stuff that the GnomeCanvas provides (layers, easy redrawing, hit
testing, etc.) without the ugly parts of the gnomecanvas api.

  With that in ming I started to elaborate a list of things that I want
a canvas to provide:

1. Almost the same possibilities that GnomeCanvas provides
2. MVC split
3. To be extended easily (keyword: custom canvas objects)

GtkTreeModel like API
=====================
With this in mind I wanted to have an API similar to the one of the
GtkTreeView, though the GtkTreeModel has some limitations so it doesn't
fit as a model for this case.

The problem is that a TreeView is basically a tree with some kind of an
array of data (thus the tree store is modelled in some kind of column
based way). This can be done as each node of the tree has the same
structure. As a canvas can e.g. include a rectangle, a circle and an
image we have to deal with different kinds of nodes.

My resolution about this was to have a HashTable that maps strings to
attributes (so we are more flexible and still have the model managed
quite easily).

Custom canvas objects
=====================
With most MVC based implementations one usually has to write both a
model object (read: an object that contains the data) and a view element
(read: an object that renders data from a model object); if you have no
idea about this, take a look at criawips' CVS [1] (block, slide,
backround and the corresponding renderers). This would make extending
the canvas quite hard as every custom canvas item needs to be written as
a data item and a display item.

As we store the data in a HashTable within the model, we can easily map
these values to GObject properties. So we just need to implement the
display part as a GObject derived type and we have the model being
already as flexible as necessary.

Result
======
I have a small implementation called CCC (criawips' cairo-based canvas)
which can be made available to the public within 24 hours. It features a
basic rectangle type and a canvas model that easily allows grouping. It
is based upon cairo and I plan to use it as a foundation for the next
rendering infrastructure for criawips.

I used it as a demonstration for GObject code at the 21C3 [2] late
december, so it is already a working base which needs to be extended to
provide all the object types that the gnome canvas provides. I don't
know (yet) how to integrate pango into the canvas to provide the same
rendering flexibility that GTK+ provides. The next thing is that I don't
know (yet) how to provide support for some GnomeCanvasWidget-style
element.

[1]http://cvs.gnome.org/viewcvs/criawips
[2]http://21c3.ccc.de/

Regards,
  Sven
-- 
Sven Herzberg <herzi abi02 de>    · GNOME Deutschland <www.gnome.de>
Jabber <herzi jabber org>         · ICQ <177176642>
GnuPG <F020 B158 2696 6D6A 2870 F53C 0565 FD6B B1C3 0AFE>
Criawips <www.nongnu.org/criawips>· GnomeGCJ <gnome-gcj.sourceforge.net>

Attachment: signature.asc
Description: This is a digitally signed message part



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