[cairo] Drawing selected data?
thinker at branda.to
Fri Feb 6 19:09:38 PST 2009
Ian Britten wrote:
> Hi all,
> [ Sorry for the length, but I hope to prevent needless questions... ]
> I'm using Cairo to export data to various file formats, and need to
> match what was rendered on-screen (via our current non-Cairo stuff).
> When the user selects a polygon on-screen, it is drawn as transparent
> in a selection colour (eg: Red), on top of all the other data. Note
> that there may be other data on top of the polygon (text, lines),
> and the selection is drawn on top of all that. I need my exported
> drawing to show this selection too.
> Current on-screen (non-Cairo) approach:
> When the selected polygon is rendered, it is also drawn to a
> separate 1-bit offscreen bitmap, in addition to the background
> bitmap. (The polygon knows it's selected) When finally painting
> the window, the selection bitmap is simply painted (with an alpha
> and a colour) after first drawing the background bitmap.
> I'm currently wondering how to best achieve this with Cairo.
> For example, as a start, I could simply carry around a second
> surface. However, this would mean that in all my code, everything
> that I'm currently doing, I would need to do twice, wouldn't it?
> Twice the configuration setups, twice the path definitions, etc.
> That seems like a lot of extra code (Esp since I actually need 2-3
> of these extra surfaces, but I'm just keeping my example simple...)
I am working on an MadButterfly, a SVG/vector-based UI toolkit, project.
I had some experiences on this issue. My idea is selection objects is
an interactive task that human's responsive time is relative long.
Longer computation time for selection is acceptable, but it can not too
long that human eyes can aware it. So, I associate a bounding box for
every object draw by Cairo. To delect which object is selected,
bounding boxes are checked at first. After checking, we have a few
candidates. The candidates are checked with cairo_in_fill() or/and
cairo_in_stroke() in advance. Although, polygons are draw for every
selection and it costs a lot of computation. But, with bounding box
number of candidates are reduced to an acceptable number (depend on your
application). cairo_in_fill() and cairo_in_stroke() does not actually
render graphics into destinate surface, it is less heavy than actually
drawing. We have a few examples with MadButterfly, they show the
performance of selection with bounding box and cairo_in_*() is
acceptable with 200MHz CPU (set CPU clock of a notebook at 200MHz).
Homepage of MadButterfly is http://www.assembla.com/spaces/MadButterfly
More information about the cairo