surfaces
Steven J Abner
pheonix.sja at att.net
Thu Jul 18 18:13:09 UTC 2024
Start by saying cairo rocks!
I'm doing conversion of an interface drawing project, and love the
cairo way. But in
doing gdk/gtk encountered something I'd like to see if correct, no
bumps down the line.
The design is a window, normally the top-most, with one 'main'
cairo_surface_t. Rather than a bunch of 'widgets/windows', the
cairo_surface_t may be broken into multiple 'drawing ports' by means of
cairo_surface_create_for_rectangle(). On XCB this is a breeze, and
doesn't force destruction of all the multiple ports, just ones that may
be effected. This is because of the wonderful
cairo_xcb_surface_set_size(). For others, the solution eludes me. But I
did get a working solution to the design.
This solution is where you all come in. Is this a sound method? Is
there a way to adapt cairo_xcb_surface_set_size() to other surfaces?
Maybe something hidden or overlooked?
Here is the questionable:
static void
_interface_configure(PhxInterface *iface, int16_t hD, int16_t vD) {
iface->mete_box.w += hD;
iface->draw_box.w += hD;
iface->mete_box.h += vD;
iface->draw_box.h += vD;
#ifdef XCB
cairo_xcb_surface_set_size(iface->surface,
iface->mete_box.w,
iface->mete_box.h);
#else
for (int ndx = 0; ndx < iface->ncount; ndx++) {
PhxNexus *inspect = iface->nexus[ndx];
inspect->state |= 4;
cairo_surface_destroy(inspect->surface);
inspect->surface = NULL;
}
cairo_surface_destroy(iface->surface);
/* create window's drawing surface */
master_iface->surface = gdk_window_create_similar_surface(
iface->window,
CAIRO_CONTENT_COLOR_ALPHA,
iface->draw_box.w,
iface->draw_box.h);
cairo_status_t error = cairo_surface_status(iface->surface);
if (error != CAIRO_STATUS_SUCCESS) {
fprintf(stderr, "Some weird cairo error...?!");
return;
}
#endif
if (iface->nexus[0] != NULL) {
_interface_delta_sweep(iface, hD, vD);
_interface_resurface(iface);
}
}
A small description:
iface is global controller/variables, holds 'surface'.
nexus are drawing ports listed within iface, sub-surfaces.
nexus->state | 4 just informs to destroy/resurface the sub-surface.
delta_sweep moves/resizes based on window's changes and marks if needs
resurface.
resurface destroy/create_for_rectangle a marked nexus.
A visual example of multiple ports is provided to aid in attempt to
convey.
The #else ... #endif is the code of needing advice.
Any insight you can share would be highly appreciated.
Steve
-------------- next part --------------
A non-text attachment was scrubbed...
Name: config.png
Type: image/png
Size: 18551 bytes
Desc: not available
URL: <https://lists.cairographics.org/archives/cairo/attachments/20240718/9acc03e8/attachment-0001.png>
More information about the cairo
mailing list