From 649b94c281c7b1bbf70631a97c1621d88274ac71 Mon Sep 17 00:00:00 2001 From: jabu Date: Sun, 5 May 2024 16:41:58 -0500 Subject: [PATCH] add mint functions --- src/path_constraint.rs | 22 ++++++++++++++++++++ src/transform_constraint.rs | 41 +++++++++++++++++++++++++++++++++++-- 2 files changed, 61 insertions(+), 2 deletions(-) diff --git a/src/path_constraint.rs b/src/path_constraint.rs index 52f0af4..2500dbf 100644 --- a/src/path_constraint.rs +++ b/src/path_constraint.rs @@ -7,6 +7,9 @@ use crate::{ Bone, PathConstraintData, Slot, }; +#[cfg(feature = "mint")] +use mint::Vector2; + /// [Spine API Reference](https://esotericsoftware.com/spine-api-reference#PathConstraint) #[derive(Debug)] pub struct PathConstraint { @@ -106,3 +109,22 @@ impl PathConstraint { c_ptr!(c_path_constraint, spPathConstraint); } + +/// Functions available if using the `mint` feature. +#[cfg(feature = "mint")] +impl PathConstraint { + #[must_use] + pub fn mix(&self) -> Vector2 { + Vector2 { + x: self.mix_x(), + y: self.mix_y(), + } + } + + #[must_use] + pub fn set_mix(&mut self, mix: impl Into>) { + let mix: Vector2 = mix.into(); + self.set_mix_x(mix.x); + self.set_mix_y(mix.y); + } +} diff --git a/src/transform_constraint.rs b/src/transform_constraint.rs index 46d4404..3dc50f8 100644 --- a/src/transform_constraint.rs +++ b/src/transform_constraint.rs @@ -7,6 +7,9 @@ use crate::{ Bone, TransformConstraintData, }; +#[cfg(feature = "mint")] +use mint::Vector2; + /// [Spine API Reference](https://esotericsoftware.com/spine-api-reference#TransformConstraint) #[derive(Debug)] pub struct TransformConstraint { @@ -57,7 +60,7 @@ impl TransformConstraint { /// A percentage (0-1) that controls the mix between the constrained and unconstrained /// scale X. mix_scale_x, - set_scale_x, + set_mix_scale_x, mixScaleX, f32 ); @@ -65,7 +68,7 @@ impl TransformConstraint { /// A percentage (0-1) that controls the mix between the constrained and unconstrained /// scale X. mix_scale_y, - set_scale_y, + set_mix_scale_y, mixScaleY, f32 ); @@ -116,3 +119,37 @@ impl TransformConstraint { c_ptr!(c_transform_constraint, spTransformConstraint); } + +/// Functions available if using the `mint` feature. +#[cfg(feature = "mint")] +impl TransformConstraint { + #[must_use] + pub fn mix_scale(&self) -> Vector2 { + Vector2 { + x: self.mix_scale_x(), + y: self.mix_scale_y(), + } + } + + #[must_use] + pub fn set_mix_scale(&mut self, mix_scale: impl Into>) { + let mix_scale: Vector2 = mix_scale.into(); + self.set_mix_scale_x(mix_scale.x); + self.set_mix_scale_y(mix_scale.y); + } + + #[must_use] + pub fn mix(&self) -> Vector2 { + Vector2 { + x: self.mix_x(), + y: self.mix_y(), + } + } + + #[must_use] + pub fn set_mix(&mut self, mix: impl Into>) { + let mix: Vector2 = mix.into(); + self.set_mix_x(mix.x); + self.set_mix_y(mix.y); + } +}