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.
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.
Bad Behavior has blocked 34 access attempts in the last 7 days.
March 9th, 2008 at 10:39 pm
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.
March 9th, 2008 at 11:14 pm
see:
http://library.gnome.org/devel/gdk/stable/gdk-Windows.html#gdk-window-input-shape-combine-mask
I don’t know whether it already works on windows. You could also manually construct a bitmask (you can use almost the same cairo code) and check whether the input falls in the mask manually.
March 9th, 2008 at 11:27 pm
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.
March 9th, 2008 at 11:29 pm
On receiving a click event create a dummy surface, draw the clock, then use cairo_in_fill for hit testing.
March 10th, 2008 at 12:20 am
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.
March 10th, 2008 at 12:53 am
alternately, use something like goocanvas.
March 10th, 2008 at 8:45 am
Have you looked at the gsm_color_button.c/h code in gnome-system-monitor
That does it
March 10th, 2008 at 8:47 am
Oops, I should have noticed, you only want the input shaped… /halfasleep
March 10th, 2008 at 1:43 pm
another possibility for rounded shapes is checking that x^2 + y^2 < 1
March 11th, 2008 at 12:24 am
[…] Bruno Boaventura (brunobol) « Custom widgets with Cairo. […]