[cairo] DrawingArea events - cross posted

Dirk Schönberger dirk.schoenberger at sz-online.de
Fri Nov 9 00:07:46 PST 2007

> Hello,
> Since I have been a visitor here and you have given me some good advice, I
> thought I'd try asking this here too; it's already on the pygtk list. It's
> not strictly anything to do with cairo, but I have to try.
> I have a rudimentary app going that draws <cairo commands> down onto a
> gtk.DrawingArea. On each loop they pile up, like so many pixels.
> I want to be able to bring "life" to each shape (rep by an object
> internally)
> such that they:
> * detect mouse enter/leave
> * detect mouse clicks
> * detect key press
> Being ill informed I wanted to ask here before I start with my first
> thought
> which is: Loop through each object per mouse/key event and check if the
> event.x and event.y is within it's rough bounds and if that object is not
> covered by others. A daunting task and horribly slow.
> Ideally, I would like to set a "hit shape" for each active object so that
> it
> reacts to an accurate area rather than a general bounding circle/box.
> I would appreciate any hints on how to set the ball rolling.
> \d

Looks to me like a classic usecase for a canvas like API, i.e. something
like the already mentioned goocanvas.
Rule of thumb is if you need to use interactivity, plain cairo is no
longer sufficient.
A canvas is basically a collection of objects (which may render themselves
using cairo), which can be manipulated (think setting size etc), and
should be able to react to external events like mouse clicks/hover etc.
Another name for this kind of system is scene graph or retained mode
graphics API.


More information about the cairo mailing list