use objc::runtime::*;
use objc::*;
use super::PLYCallback;
use crate::foundation::NSNumber;
use crate::{IntoRaw, Raw};
pub struct PLYKeyframeAnimation {
object: *mut Object,
}
impl PLYKeyframeAnimation {
pub fn new<T>(duration: f64, times: &[f64], values: &[T]) -> PLYKeyframeAnimation
where
T: Copy + IntoRaw,
{
unsafe {
let mut object: *mut Object = msg_send![class!(PLYKeyframeAnimation), alloc];
let times = times.into_raw();
let values = values.into_raw();
object = msg_send![object, initWithDuration: duration
times: times.as_raw()
values: values.as_raw()];
PLYKeyframeAnimation::from_raw(object)
}
}
}
impl Raw for PLYKeyframeAnimation {
unsafe fn from_raw(object: *mut Object) -> Self {
PLYKeyframeAnimation { object }
}
unsafe fn as_raw(&self) -> *mut Object {
self.object
}
}
impl Drop for PLYKeyframeAnimation {
fn drop(&mut self) {
unsafe { objc_release(self.object) }
}
}
pub struct PLYAnimationHandle {
object: *mut Object,
}
impl PLYAnimationHandle {
pub fn set_on_stop(&mut self, callback: PLYCallback<NSNumber>) {
unsafe {
let _: () = msg_send![self.object, setOnStop: callback.as_raw()];
}
}
}
impl Raw for PLYAnimationHandle {
unsafe fn from_raw(object: *mut Object) -> Self {
PLYAnimationHandle { object }
}
unsafe fn as_raw(&self) -> *mut Object {
self.object
}
}
impl Drop for PLYAnimationHandle {
fn drop(&mut self) {
unsafe { objc_release(self.object) }
}
}