rusty_spine/
path_constraint.rs1use crate::{
2 c::{
3 spBone, spPathConstraint, spPathConstraintData, spPathConstraint_setToSetupPose,
4 spPathConstraint_update, spSlot,
5 },
6 c_interface::{NewFromPtr, SyncPtr},
7 Bone, PathConstraintData, Slot,
8};
9
10#[cfg(feature = "mint")]
11use mint::Vector2;
12
13#[derive(Debug)]
15pub struct PathConstraint {
16 c_path_constraint: SyncPtr<spPathConstraint>,
17}
18
19impl NewFromPtr<spPathConstraint> for PathConstraint {
20 unsafe fn new_from_ptr(c_slot: *mut spPathConstraint) -> Self {
21 Self {
22 c_path_constraint: SyncPtr(c_slot),
23 }
24 }
25}
26
27impl PathConstraint {
28 pub fn update(&self) {
30 unsafe {
31 spPathConstraint_update(self.c_path_constraint.0);
32 }
33 }
34
35 pub fn set_to_setup_pose(&self) {
36 unsafe {
37 spPathConstraint_setToSetupPose(self.c_path_constraint.0);
38 }
39 }
40
41 c_accessor_tmp_ptr_mut!(
42 data,
44 data_mut,
45 data,
46 PathConstraintData,
47 spPathConstraintData
48 );
49
50 c_accessor_bool!(active, active);
51 c_accessor_mut!(
52 mix_rotate,
55 set_mix_rotate,
56 mixRotate,
57 f32
58 );
59 c_accessor_mut!(
60 mix_x,
63 set_mix_x,
64 mixX,
65 f32
66 );
67 c_accessor_mut!(
68 mix_y,
71 set_mix_y,
72 mixY,
73 f32
74 );
75 c_accessor_mut!(
76 position,
78 set_position,
79 position,
80 f32
81 );
82 c_accessor_mut!(
83 spacing,
85 set_spacing,
86 spacing,
87 f32
88 );
89
90 c_accessor!(bones_count, bonesCount, usize);
91 c_accessor_array!(
92 bones,
94 bone_at_index,
95 PathConstraint,
96 Bone,
97 spBone,
98 bones,
99 bones_count
100 );
101 c_accessor_tmp_ptr_mut!(
102 target,
104 target_mut,
105 target,
106 Slot,
107 spSlot
108 );
109
110 c_ptr!(c_path_constraint, spPathConstraint);
111}
112
113#[cfg(feature = "mint")]
115impl PathConstraint {
116 #[must_use]
117 pub fn mix(&self) -> Vector2<f32> {
118 Vector2 {
119 x: self.mix_x(),
120 y: self.mix_y(),
121 }
122 }
123
124 pub fn set_mix(&mut self, mix: impl Into<Vector2<f32>>) {
125 let mix: Vector2<f32> = mix.into();
126 self.set_mix_x(mix.x);
127 self.set_mix_y(mix.y);
128 }
129}