napperley
07/30/2021, 3:13 AMcairo_region_create_rectangles
function ( https://www.cairographics.org/manual/cairo-Regions.html#cairo-region-create-rectangles ) from the Cairo library, but the function is after CValuesRef<cairo_rectangle_int_t>?
as the first parameter and I don't know how to provide a CValuesRef
that contains multiple struct pointers. Below is the code that fails to compile (the values variable doesn't match what the cairo_region_create_rectangles function
is expecting):
// ...
fun createWithMultipleRectangles(vararg rectangles: IntRectangle): Region {
val tmpArr = rectangles.map { it.cairoRect.ptr }.toTypedArray()
val values = cValuesOf(*tmpArr)
return Region(cairo_region_create_rectangles(values, rectangles.size))
}
// ...
napperley
07/30/2021, 3:45 AMfun createWithMultipleRectangles(vararg rectangles: IntRectangle): Region = memScoped {
val tmpArr = allocArray<_cairo_rectangle_int>(rectangles.size)
rectangles.forEachIndexed { pos, item ->
tmpArr[pos].height = item.height
tmpArr[pos].width = item.width
tmpArr[pos].x = item.xPos
tmpArr[pos].y = item.yPos
}
return Region(cairo_region_create_rectangles(tmpArr, rectangles.size))
}
Although this works (no compile errors) rectangles is deep copied, which isn't what I want to achieve. I want to pass through the _cairo_rectangle_int
pointers to the function as the first parameter.