surface clipping
Steven J Abner
pheonix.sja at att.net
Sun Jul 28 01:50:12 UTC 2024
I'm at a point where I could use expert knowledge of surfaces, and
maybe operators. I'm having to clip surfaces for configuration of
drawing ports, or some could call them layers, containers, windows, etc.
The cairo_clip() works within a surface, but doesn't apply the a
surface inside the cairo_clip() surface. Say you have a surface inside
a main surface, cairo_xcb_surface_create() for main, then
cairo_surface_create_for_rectangle() for
a 'drawing port' within the main. This 'drawing port' will act and
behave like a window inside our main window. This 'sub-port' can be
grabbed for resize, just like a window, sidebar, 'paned' areas. Now
when you 'grab' to resize, any 'sub-ports' within the sub-port have to
be sized/position just as a window would. The resize of the sub-ports
are determined by whether it shrinks/grows or moves, given on what a
user wants to do with the sub-ports.
That's the concept, for the issue, is there an operator that handles
this or is it up to the programmer to calculate clipping of surfaces?
I am providing the clipping code and pics hoping that one may gleam
what I'm trying to do.
/* clipping code to clip surfaces */
PhxInterface *mount = nexus->i_mount;
if (mount != master_iface) {
PhxRectangle mbox = mount->mete_box;
int16_t wD, hD, xD, yD;
wD = (mbox.w < nexus->draw_box.w) ? (mbox.w -
nexus->draw_box.w) : 0;
hD = (mbox.h < nexus->draw_box.h) ? (mbox.h -
nexus->draw_box.h) : 0;
if (nexus->type == PHX_NFUSE) {
xD = (nexus->mete_box.x < 0) ? nexus->mete_box.x : 0;
yD = (nexus->mete_box.y < 0) ? nexus->mete_box.y : 0;
} else if (nexus->type == PHX_NEXUS) {
xD = ((nexus->mete_box.x + mbox.x) < 0)
? nexus->mete_box.x + mbox.x : 0;
yD = ((nexus->mete_box.y + mbox.y) < 0)
? nexus->mete_box.y + mbox.y : 0;
}
if ((xD | yD | wD | hD) != 0) {
mbox = nexus->draw_box;
if ( ((mbox.w + xD) < 0) || ((mbox.h + yD) < 0) ) {
cairo_destroy(cr);
continue;
}
cairo_rectangle(cr, mbox.x - xD - wD,
mbox.y - yD - hD,
mbox.w + xD,
mbox.h + yD);
cairo_clip(cr);
}
}
/* end clipping code */
In the pics, the 4 dots per surface are to show corner positions to
make sure clips are as expected.
Steve
-------------- next part --------------
A non-text attachment was scrubbed...
Name: with_clip_code.png
Type: image/png
Size: 6663 bytes
Desc: not available
URL: <https://lists.cairographics.org/archives/cairo/attachments/20240727/104bef50/attachment-0003.png>
-------------- next part --------------
A non-text attachment was scrubbed...
Name: Window_in window.png
Type: image/png
Size: 8691 bytes
Desc: not available
URL: <https://lists.cairographics.org/archives/cairo/attachments/20240727/104bef50/attachment-0004.png>
-------------- next part --------------
A non-text attachment was scrubbed...
Name: without_clip_code.png
Type: image/png
Size: 7299 bytes
Desc: not available
URL: <https://lists.cairographics.org/archives/cairo/attachments/20240727/104bef50/attachment-0005.png>
More information about the cairo
mailing list