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
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
use std::ffi::CString;
use crate::{
attachment::Attachment,
bone::Bone,
c::{
spAttachment, spBlendMode, spBone, spBoneData, spSkeleton, spSlot, spSlotData,
spSlotData_setAttachmentName, spSlot_setAttachment, spSlot_setToSetupPose,
},
c_interface::{NewFromPtr, SyncPtr},
BoneData, Skeleton,
};
#[derive(Debug)]
pub struct Slot {
c_slot: SyncPtr<spSlot>,
}
impl NewFromPtr<spSlot> for Slot {
unsafe fn new_from_ptr(c_slot: *const spSlot) -> Self {
Self {
c_slot: SyncPtr(c_slot as *mut spSlot),
}
}
}
impl Slot {
pub unsafe fn set_attachment(&mut self, attachment: Option<Attachment>) {
if let Some(attachment) = attachment {
spSlot_setAttachment(self.c_ptr(), attachment.c_ptr());
} else {
spSlot_setAttachment(self.c_ptr(), std::ptr::null_mut());
}
}
pub fn set_to_setup_pose(&mut self) {
unsafe {
spSlot_setToSetupPose(self.c_ptr());
}
}
pub fn handle(&self) -> SlotHandle {
SlotHandle::new(self.c_ptr(), unsafe { self.bone().c_ptr_mut().skeleton })
}
c_accessor_color_mut!(color, color_mut, color);
c_accessor_color_optional!(dark_color, darkColor);
c_accessor_tmp_ptr!(data, data_mut, data, SlotData, spSlotData);
c_accessor_tmp_ptr!(bone, bone_mut, bone, Bone, spBone);
c_accessor_tmp_ptr_optional!(
attachment,
attachment_mut,
attachment,
Attachment,
spAttachment
);
c_ptr!(c_slot, spSlot);
c_accessor!(sequence_index, sequenceIndex, i32);
}
c_handle_decl!(
SlotHandle,
Slot,
Skeleton,
spSlot,
spSkeleton
);
#[derive(Debug)]
pub struct SlotData {
c_slot_data: SyncPtr<spSlotData>,
}
impl NewFromPtr<spSlotData> for SlotData {
unsafe fn new_from_ptr(c_slot_data: *const spSlotData) -> Self {
Self {
c_slot_data: SyncPtr(c_slot_data as *mut spSlotData),
}
}
}
impl SlotData {
pub fn set_attachment_name(&mut self, attachment_name: &str) {
let c_attachment_name = CString::new(attachment_name).unwrap();
unsafe { spSlotData_setAttachmentName(self.c_ptr(), c_attachment_name.as_ptr()) }
}
c_accessor!(index, index, i32);
c_accessor_string!(name, name);
c_accessor_tmp_ptr!(bone_data, bone_data_mut, boneData, BoneData, spBoneData);
c_accessor_string!(attachment_name, attachmentName);
c_accessor_color_mut!(color, color_mut, color);
c_accessor_color_optional!(dark_color, darkColor);
c_accessor_enum_mut!(blend_mode, set_blend_mode, blendMode, BlendMode);
c_ptr!(c_slot_data, spSlotData);
}
#[derive(Debug, Clone, Copy, PartialEq, Eq)]
pub enum BlendMode {
Normal = 0,
Additive = 1,
Multiply = 2,
Screen = 3,
}
impl From<spBlendMode> for BlendMode {
fn from(attachment_type: spBlendMode) -> Self {
match attachment_type {
0 => Self::Normal,
1 => Self::Additive,
2 => Self::Multiply,
3 => Self::Screen,
_ => Self::Normal,
}
}
}