// Code generated by cmd/cgo; DO NOT EDIT.

//line /home/josie/.cache/paru/clone/wiiudownloader/src/pkg/mod/github.com/gotk3/gotk3@v0.6.5-0.20240618185848-ff349ae13f56/cairo/region.go:1:1
// region.go

package cairo

// #include <cairo.h>
// #include <cairo-gobject.h>
import _ "unsafe"

import (
	"runtime"
	"unsafe"

	"github.com/gotk3/gotk3/glib"
)

func init() {
	tm := []glib.TypeMarshaler{
		// Enums
		{glib.Type(( /*line :19:14*/_Cfunc_cairo_gobject_region_overlap_get_type /*line :19:52*/)()), marshalRegionOverlap},

		// Boxed
		{glib.Type(( /*line :22:14*/_Cfunc_cairo_gobject_region_get_type /*line :22:44*/)()), marshalRegion},
	}
	glib.RegisterGValueMarshalers(tm)
}

// RegionOverlap is a representation of Cairo's cairo_region_overlap_t.
type RegionOverlap int

const (
	REGION_OVERLAP_IN   RegionOverlap = ( /*line :31:38*/_Ciconst_CAIRO_REGION_OVERLAP_IN /*line :31:62*/)
	REGION_OVERLAP_OUT  RegionOverlap = ( /*line :32:38*/_Ciconst_CAIRO_REGION_OVERLAP_OUT /*line :32:63*/)
	REGION_OVERLAP_PART RegionOverlap = ( /*line :33:38*/_Ciconst_CAIRO_REGION_OVERLAP_PART /*line :33:64*/)
)

func marshalRegionOverlap(p uintptr) (interface{}, error) {
	c := ( /*line :37:7*/_Cfunc_g_value_get_enum /*line :37:24*/)((* /*line :37:28*/_Ctype_GValue /*line :37:36*/)(unsafe.Pointer(p)))
	return RegionOverlap(c), nil
}

/*
 * Rectangle
 */

// Rectangle is a representation of Cairo's cairo_rectangle_int_t.
type Rectangle struct {
	X, Y          int
	Width, Height int
}

// commodity function to ceate Rectangle cairo object.
func RectangleNew(x, y, width, height int) *Rectangle {
	r := new(Rectangle)
	r.X = x
	r.Y = y
	r.Width = width
	r.Height = height
	return r
}

func (v *Rectangle) native() * /*line :61:31*/_Ctype_cairo_rectangle_int_t /*line :61:54*/ {
	r := new( /*line :62:11*/_Ctype_cairo_rectangle_int_t /*line :62:34*/)
	r.x =  /*line :63:8*/_Ctype_int /*line :63:13*/(v.X)
	r.y =  /*line :64:8*/_Ctype_int /*line :64:13*/(v.Y)
	r.width =  /*line :65:12*/_Ctype_int /*line :65:17*/(v.Width)
	r.height =  /*line :66:13*/_Ctype_int /*line :66:18*/(v.Height)
	return r
}

func toRectangle(cr * /*line :70:22*/_Ctype_cairo_rectangle_int_t /*line :70:45*/) *Rectangle {
	return &Rectangle{
		X: int(cr.x), Y: int(cr.y),
		Width: int(cr.width), Height: int(cr.height)}
}

/*
 * Region
 */

// Region is a representation of Cairo's cairo_region_t.
type Region struct {
	region * /*line :82:10*/_Ctype_cairo_region_t /*line :82:26*/
}

// native returns a pointer to the underlying cairo_region_t.
func (v *Region) native() * /*line :86:28*/_Ctype_cairo_region_t /*line :86:44*/ {
	if v == nil {
		return nil
	}
	return v.region
}

// Native returns a pointer to the underlying cairo_region_t.
func (v *Region) Native() uintptr {
	return uintptr(unsafe.Pointer(v.native()))
}

func marshalRegion(p uintptr) (interface{}, error) {
	c := ( /*line :99:7*/_Cfunc_g_value_get_boxed /*line :99:25*/)((* /*line :99:29*/_Ctype_GValue /*line :99:37*/)(unsafe.Pointer(p)))
	region := (* /*line :100:14*/_Ctype_cairo_region_t /*line :100:30*/)(unsafe.Pointer(c))
	return wrapRegion(region), nil
}

func wrapRegion(region * /*line :104:25*/_Ctype_cairo_region_t /*line :104:41*/) *Region {
	return &Region{region}
}

// newRegionFromNative that handle finalizer.
func newRegionFromNative(regionNative * /*line :109:40*/_Ctype_cairo_region_t /*line :109:56*/) (*Region, error) {
	ptr := wrapRegion(regionNative)
	e := ptr.Status().ToError()
	if e != nil {
		return nil, e
	}
	runtime.SetFinalizer(ptr, func(v *Region) { glib.FinalizerStrategy(v.destroy) })
	return ptr, nil
}

// RegionCreate is a wrapper around cairo_region_create().
func RegionCreate() (*Region, error) {

	return newRegionFromNative(( /*line :122:29*/_Cfunc_cairo_region_create /*line :122:49*/)())
}

// CreateRectangle is a wrapper around cairo_region_create_rectangle().
func (v *Region) CreateRectangle(rectangle *Rectangle) (*Region, error) {

	return newRegionFromNative(( /*line :128:29*/_Cfunc_cairo_region_create_rectangle /*line :128:59*/)(
		rectangle.native()))
}

// CreateRectangles is a wrapper around cairo_region_create_rectangles().
func (v *Region) CreateRectangles(rectangles ...*Rectangle) (*Region, error) {

	length := len(rectangles)

	cRectangles := make([] /*line :137:24*/_Ctype_cairo_rectangle_int_t /*line :137:47*/, length)

	for i := 0; i < length; i++ {
		cRectangles[i] = *rectangles[i].native()
	}

	pRect := &cRectangles[0]

	return newRegionFromNative(
		( /*line :146:3*/_Cfunc_cairo_region_create_rectangles /*line :146:34*/)(
			pRect,
			 /*line :148:4*/_Ctype_int /*line :148:9*/(length)))
}

// Copy is a wrapper around cairo_region_copy().
func (v *Region) Copy() (*Region, error) {

	return newRegionFromNative(func() *_Ctype_struct__cairo_region{ _cgo0 := /*line :154:49*/v.native(); _cgoCheckPointer(_cgo0, nil); return /*line :154:60*/_Cfunc_cairo_region_copy(_cgo0); }())
}

// reference is a wrapper around cairo_region_reference().
func (v *Region) reference() {
	v.region = func() *_Ctype_struct__cairo_region{ _cgo0 := /*line :159:38*/v.native(); _cgoCheckPointer(_cgo0, nil); return /*line :159:49*/_Cfunc_cairo_region_reference(_cgo0); }()
}

// destroy is a wrapper around cairo_region_destroy().
func (v *Region) destroy() {
	func() { _cgo0 := /*line :164:25*/v.native(); _cgoCheckPointer(_cgo0, nil); /*line :164:36*/_Cfunc_cairo_region_destroy(_cgo0); }()
}

// Status is a wrapper around cairo_region_status().
func (v *Region) Status() Status {
	c := func() _Ctype_cairo_status_t{ _cgo0 := /*line :169:29*/v.native(); _cgoCheckPointer(_cgo0, nil); return /*line :169:40*/_Cfunc_cairo_region_status(_cgo0); }()
	return Status(c)
}

// GetExtents is a wrapper around cairo_region_get_extents().
func (v *Region) GetExtents(extents *Rectangle) {

	func() { _cgo0 := /*line :176:29*/v.native(); var _cgo1 *_Ctype_struct__cairo_rectangle_int = /*line :176:41*/extents.native(); _cgoCheckPointer(_cgo0, nil); /*line :176:58*/_Cfunc_cairo_region_get_extents(_cgo0, _cgo1); }()
}

// NumRectangles is a wrapper around cairo_region_num_rectangles().
func (v *Region) NumRectangles() int {

	return int(func() _Ctype_int{ _cgo0 := /*line :182:43*/v.native(); _cgoCheckPointer(_cgo0, nil); return /*line :182:54*/_Cfunc_cairo_region_num_rectangles(_cgo0); }())
}

// GetRectangle is a wrapper around cairo_region_get_rectangle().
func (v *Region) GetRectangle(nth int) *Rectangle {

	cr := new( /*line :188:12*/_Ctype_cairo_rectangle_int_t /*line :188:35*/)
	func() { _cgo0 := /*line :189:31*/v.native(); var _cgo1 _Ctype_int = _Ctype_int /*line :189:48*/(nth); var _cgo2 *_Ctype_struct__cairo_rectangle_int = /*line :189:55*/cr; _cgoCheckPointer(_cgo0, nil); /*line :189:58*/_Cfunc_cairo_region_get_rectangle(_cgo0, _cgo1, _cgo2); }()

	return toRectangle(cr)
}

// IsEmpty is a wrapper around cairo_region_is_empty().
func (v *Region) IsEmpty() bool {

	return gobool(func() _Ctype_cairo_bool_t{ _cgo0 := /*line :197:40*/v.native(); _cgoCheckPointer(_cgo0, nil); return /*line :197:51*/_Cfunc_cairo_region_is_empty(_cgo0); }())
}

// ContainsPoint is a wrapper around cairo_region_contains_point().
func (v *Region) ContainsPoint(x, y int) bool {

	return gobool(func() _Ctype_cairo_bool_t{ _cgo0 := /*line :204:3*/v.native(); var _cgo1 _Ctype_int = _Ctype_int /*line :204:20*/(x); var _cgo2 _Ctype_int = _Ctype_int /*line :204:30*/(y); _cgoCheckPointer(_cgo0, nil); return /*line :204:34*/_Cfunc_cairo_region_contains_point(_cgo0, _cgo1, _cgo2); }())
}

// ContainsRectangle is a wrapper around cairo_region_contains_rectangle().
func (v *Region) ContainsRectangle(rectangle *Rectangle) RegionOverlap {

	return RegionOverlap(
		func() _Ctype_cairo_region_overlap_t{ _cgo0 := /*line :212:4*/v.native(); var _cgo1 *_Ctype_struct__cairo_rectangle_int = /*line :212:16*/rectangle.native(); _cgoCheckPointer(_cgo0, nil); return /*line :212:35*/_Cfunc_cairo_region_contains_rectangle(_cgo0, _cgo1); }())
}

// Equal is a wrapper around cairo_region_equal().
func (v *Region) Equal(region *Region) bool {

	return gobool(func() _Ctype_cairo_bool_t{ _cgo0 := /*line :218:37*/v.native(); _cgo1 := /*line :218:49*/region.native(); _cgoCheckPointer(_cgo0, nil); _cgoCheckPointer(_cgo1, nil); return /*line :218:65*/_Cfunc_cairo_region_equal(_cgo0, _cgo1); }())
}

// Translate is a wrapper around cairo_region_translate().
func (v *Region) Translate(dx, dy int) {

	func() { _cgo0 := /*line :224:27*/v.native(); var _cgo1 _Ctype_int = _Ctype_int /*line :224:44*/(dx); var _cgo2 _Ctype_int = _Ctype_int /*line :224:55*/(dy); _cgoCheckPointer(_cgo0, nil); /*line :224:60*/_Cfunc_cairo_region_translate(_cgo0, _cgo1, _cgo2); }()
}

// Intersect is a wrapper around cairo_region_intersect().
// Note: contrary to the original statement, the source
// 'Region' remains preserved.
func (v *Region) Intersect(other *Region) (*Region, error) {

	dst, err := v.Copy()
	if err != nil {
		return nil, err
	}
	err = Status(
		func() _Ctype_cairo_status_t{ _cgo0 := /*line :238:4*/dst.native(); _cgo1 := /*line :239:4*/other.native(); _cgoCheckPointer(_cgo0, nil); _cgoCheckPointer(_cgo1, nil); return /*line :239:19*/_Cfunc_cairo_region_intersect(_cgo0, _cgo1); }()).ToError()
	if err != nil {
		return nil, err
	}

	return dst, nil
}

// IntersectRectangle is a wrapper around cairo_region_intersect_rectangle().
// Note: contrary to the original statement, the source 'Region' remains preserved.
func (v *Region) IntersectRectangle(rectangle *Rectangle) (*Region, error) {

	dst, err := v.Copy()
	if err != nil {
		return nil, err
	}
	err = Status(
		func() _Ctype_cairo_status_t{ _cgo0 := /*line :257:4*/dst.native(); var _cgo1 *_Ctype_struct__cairo_rectangle_int = /*line :258:4*/rectangle.native(); _cgoCheckPointer(_cgo0, nil); return /*line :258:23*/_Cfunc_cairo_region_intersect_rectangle(_cgo0, _cgo1); }()).ToError()
	if err != nil {
		return nil, err
	}

	return dst, nil
}

// Substract is a wrapper around cairo_region_subtract().
// Note: contrary to the original statement, the source
// 'Region' remains preserved.
func (v *Region) Substract(other *Region) (*Region, error) {

	dst, err := v.Copy()
	if err != nil {
		return nil, err
	}
	err = Status(
		func() _Ctype_cairo_status_t{ _cgo0 := /*line :277:4*/dst.native(); _cgo1 := /*line :278:4*/other.native(); _cgoCheckPointer(_cgo0, nil); _cgoCheckPointer(_cgo1, nil); return /*line :278:19*/_Cfunc_cairo_region_subtract(_cgo0, _cgo1); }()).ToError()
	if err != nil {
		return nil, err
	}

	return dst, nil
}

// SubstractRectangle is a wrapper around cairo_region_subtract_rectangle().
// Note: contrary to the original statement, the source 'Region' remains preserved.
func (v *Region) SubstractRectangle(rectangle *Rectangle) (*Region, error) {

	dst, err := v.Copy()
	if err != nil {
		return nil, err
	}
	err = Status(
		func() _Ctype_cairo_status_t{ _cgo0 := /*line :296:4*/dst.native(); var _cgo1 *_Ctype_struct__cairo_rectangle_int = /*line :297:4*/rectangle.native(); _cgoCheckPointer(_cgo0, nil); return /*line :297:23*/_Cfunc_cairo_region_subtract_rectangle(_cgo0, _cgo1); }()).ToError()
	if err != nil {
		return nil, err
	}

	return dst, nil
}

// Union is a wrapper around cairo_region_union().
// Note: contrary to the original statement, the source
// 'Region' remains preserved.
func (v *Region) Union(other *Region) (*Region, error) {

	dst, err := v.Copy()
	if err != nil {
		return nil, err
	}
	err = Status(
		func() _Ctype_cairo_status_t{ _cgo0 := /*line :316:4*/dst.native(); _cgo1 := /*line :317:4*/other.native(); _cgoCheckPointer(_cgo0, nil); _cgoCheckPointer(_cgo1, nil); return /*line :317:19*/_Cfunc_cairo_region_union(_cgo0, _cgo1); }()).ToError()
	if err != nil {
		return nil, err
	}

	return dst, nil
}

// UnionRectangle is a wrapper around cairo_region_union_rectangle().
// Note: contrary to the original statement, the source 'Region' remains preserved.
func (v *Region) UnionRectangle(rectangle *Rectangle) (*Region, error) {

	dst, err := v.Copy()
	if err != nil {
		return nil, err
	}
	err = Status(
		func() _Ctype_cairo_status_t{ _cgo0 := /*line :335:4*/dst.native(); var _cgo1 *_Ctype_struct__cairo_rectangle_int = /*line :336:4*/rectangle.native(); _cgoCheckPointer(_cgo0, nil); return /*line :336:23*/_Cfunc_cairo_region_union_rectangle(_cgo0, _cgo1); }()).ToError()
	if err != nil {
		return nil, err
	}

	return dst, nil
}

// Xor is a wrapper around cairo_region_xor().
// Note: contrary to the original statement, the source
// 'Region' remains preserved.
func (v *Region) Xor(other *Region) (*Region, error) {

	dst, err := v.Copy()
	if err != nil {
		return nil, err
	}
	err = Status(
		func() _Ctype_cairo_status_t{ _cgo0 := /*line :355:4*/dst.native(); _cgo1 := /*line :356:4*/other.native(); _cgoCheckPointer(_cgo0, nil); _cgoCheckPointer(_cgo1, nil); return /*line :356:19*/_Cfunc_cairo_region_xor(_cgo0, _cgo1); }()).ToError()
	if err != nil {
		return nil, err
	}

	return dst, nil
}

// XorRectangle is a wrapper around cairo_region_xor_rectangle().
// Note: contrary to the original statement, the source 'Region' remains preserved.
func (v *Region) XorRectangle(rectangle *Rectangle) (*Region, error) {

	dst, err := v.Copy()
	if err != nil {
		return nil, err
	}
	err = Status(
		func() _Ctype_cairo_status_t{ _cgo0 := /*line :374:4*/dst.native(); var _cgo1 *_Ctype_struct__cairo_rectangle_int = /*line :375:4*/rectangle.native(); _cgoCheckPointer(_cgo0, nil); return /*line :375:23*/_Cfunc_cairo_region_xor_rectangle(_cgo0, _cgo1); }()).ToError()
	if err != nil {
		return nil, err
	}

	return dst, nil
}
