scoop:scoop.graphics:0.1.0
src/native/geometry_hit.scoop
Selected production source · src/native/geometry_hit.scoop
1
package scoop.graphics.native3
import scoop.graphics.GraphicsException4
import scoop.graphics.Point5
import scoop.graphics.Rect7
/** Native query status: 1 success, 0 unavailable, -1 invalid argument, -2 native failure. */8
@CLayout9
public struct NativeGeometryPoint(val status: Int, val position: Point)11
@CLayout12
public struct NativeGeometryRect(val status: Int, val rect: Rect)14
/**15
* A borrowed native snapshot. Retain before saving or handing off; release each owned reference.16
* The paired functions support concurrent native queries without entering Scoop or its runtime.17
*/18
@CLayout19
public struct NativeGeometry(20
val context: Ptr<Unit>,21
val retain: FunPtr<(Ptr<Unit>) -> Unit>,22
val release: FunPtr<(Ptr<Unit>) -> Unit>,23
val contains: FunPtr<(Ptr<Unit>, Double, Double) -> Int>,24
val toLocal: FunPtr<(Ptr<Unit>, Double, Double) -> NativeGeometryPoint>,25
/** clipped is 0 for full transformed bounds or 1 for the exact visible intersection. */26
val mapRect: FunPtr<(Ptr<Unit>, Rect, Int) -> NativeGeometryRect>27
)29
@CLayout30
private struct NativeGeometryExport(31
val context: Ptr<Unit>?,32
val retain: FunPtr<(Ptr<Unit>) -> Unit>,33
val release: FunPtr<(Ptr<Unit>) -> Unit>,34
val contains: FunPtr<(Ptr<Unit>, Double, Double) -> Int>,35
val toLocal: FunPtr<(Ptr<Unit>, Double, Double) -> NativeGeometryPoint>,36
val mapRect: FunPtr<(Ptr<Unit>, Rect, Int) -> NativeGeometryRect>37
)39
@Unsafe40
internal fun <T> withGeometry(pointer: Ptr<Unit>, block: (NativeGeometry) -> T): T {41
val exported = nativeGeometryExport(pointer)42
val context = exported.context ?: throw GraphicsException("export native hit geometry")43
try {44
return block(45
NativeGeometry(46
context,47
exported.retain,48
exported.release,49
exported.contains,50
exported.toLocal,51
exported.mapRect52
)53
)54
} finally {55
exported.release(context)56
}57
}59
@Extern(name = "scoop_graphics_geometry_export")60
private fun nativeGeometryExport(geometry: Ptr<Unit>): NativeGeometryExport