Custom widgets with Cairo.

Dear lazyweb:

Is there a way to create a custom widget with Cairo so that it is “clickable” only in the painted area?

picture by Davyd Madeley

e.g.: capture the mouse click only in the white area.

Published by


I'm a brazilian guy who loves GNOME!!!

10 thoughts on “Custom widgets with Cairo.”

  1. you can’t have X only give you events for this area without using a separate window and xshape. this is not what you want to do.

    what you want to do, instead, is capture all events but then use cairo_in_fill or cairo_in_stroke to check if the point that was clicked on is within the area that you’re interested in.

  2. You can use cairo_in_fill() to check if you’re in a given path you constructed in cairo or cairo_in_stroke() for strokes. And then you have to check that for every mouse move. It’s how I do it in Swfdec.

    So it is possible, but it’s not a drop-in one-line function that does that for you.

  3. On receiving a click event create a dummy surface, draw the clock, then use cairo_in_fill for hit testing.

  4. As people have said, you can easily calculate whether or not you’re inside the area, either using Cairo or by doing your own geometry calculations. You could overload the vcall for the signal and eat the event in the case where you don’t want to send it out (probably shouldn’t do this).

    Alternatively, if you were using GooCanvas, you could connect button-press-event directly to the clock object. It makes a lot of this stuff much simpler to do.

Comments are closed.

Leave a Reply

Your email address will not be published. Required fields are marked *