1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
use crate::{
    c::{
        spClippingAttachment, spSkeletonClipping, spSkeletonClipping_clipEnd,
        spSkeletonClipping_clipEnd2, spSkeletonClipping_clipStart, spSkeletonClipping_create,
        spSkeletonClipping_dispose, spSkeletonClipping_isClipping,
    },
    c_interface::SyncPtr,
    clipping_attachment::ClippingAttachment,
    slot::Slot,
};

#[derive(Debug)]
pub struct SkeletonClipping {
    c_skeleton_clipping: SyncPtr<spSkeletonClipping>,
    owns_memory: bool,
}

impl Default for SkeletonClipping {
    fn default() -> Self {
        Self::new()
    }
}

impl SkeletonClipping {
    pub fn new() -> Self {
        Self {
            c_skeleton_clipping: unsafe { SyncPtr(spSkeletonClipping_create()) },
            owns_memory: true,
        }
    }

    pub fn clip_start(&mut self, slot: &Slot, clip: &ClippingAttachment) {
        unsafe {
            spSkeletonClipping_clipStart(
                self.c_ptr_mut(),
                slot.c_ptr(),
                clip.c_ptr() as *mut spClippingAttachment,
            );
        }
    }

    pub fn clip_end(&mut self, slot: &Slot) {
        unsafe {
            spSkeletonClipping_clipEnd(self.c_ptr_mut(), slot.c_ptr());
        }
    }

    pub fn clip_end2(&mut self) {
        unsafe {
            spSkeletonClipping_clipEnd2(self.c_ptr_mut());
        }
    }

    pub fn is_clipping(&self) -> bool {
        unsafe { spSkeletonClipping_isClipping(self.c_ptr_mut()) != 0 }
    }

    c_ptr!(c_skeleton_clipping, spSkeletonClipping);
    /*spTriangulator *triangulator;
    spFloatArray *clippingPolygon;
    spFloatArray *clipOutput;
    spFloatArray *clippedVertices;
    spFloatArray *clippedUVs;
    spUnsignedShortArray *clippedTriangles;
    spFloatArray *scratch;
    spClippingAttachment *clipAttachment;
    spArrayFloatArray *clippingPolygons;*/
}

impl Drop for SkeletonClipping {
    fn drop(&mut self) {
        if self.owns_memory {
            unsafe {
                spSkeletonClipping_dispose(self.c_skeleton_clipping.0);
            }
        }
    }
}