use std::fmt::Debug;
use std::hash::Hash;
use after_effects::Parameters;
use premiere as pr;
use super::value::{Color, ParamValue, Point2};
#[derive(Clone, Copy, Debug, Default, PartialEq)]
pub struct SnapshotGeom {
pub layer_w: u32,
pub layer_h: u32,
pub output_w: u32,
pub output_h: u32,
pub ext_x: i32,
pub ext_y: i32,
}
pub trait FromParamValue: Sized {
fn from_value(v: ParamValue) -> Self;
}
impl FromParamValue for f32 {
fn from_value(v: ParamValue) -> Self {
match v {
ParamValue::Float(x) => x,
ParamValue::Index(i) => i as f32,
_ => 0.0,
}
}
}
impl FromParamValue for bool {
fn from_value(v: ParamValue) -> Self {
matches!(v, ParamValue::Bool(true))
}
}
impl FromParamValue for Color {
fn from_value(v: ParamValue) -> Self {
match v {
ParamValue::Color(c) => c,
_ => Color::default(),
}
}
}
impl FromParamValue for Point2 {
fn from_value(v: ParamValue) -> Self {
match v {
ParamValue::Point(p) => p,
_ => Point2::default(),
}
}
}
impl FromParamValue for u32 {
fn from_value(v: ParamValue) -> Self {
match v {
ParamValue::Index(i) => i,
ParamValue::Float(f) => f.max(0.0) as u32,
_ => 0,
}
}
}
impl FromParamValue for () {
fn from_value(_v: ParamValue) {}
}
pub trait PopupOptions: Copy + 'static {
const LABELS: &'static [&'static str];
fn from_index(index: u32) -> Self;
fn to_index(self) -> u32;
}
pub trait Param: Copy + 'static {
type Spec: ParamsSpec;
type Value: FromParamValue;
const ID: Self::Spec;
}
pub trait Snapshot<P: ParamsSpec>: Copy + Default {
fn value(&self, id: P) -> ParamValue;
fn set(&mut self, id: P, value: ParamValue);
}
pub trait ParamsSpec: Copy + Eq + Hash + Debug + Into<usize> + Send + Sync + 'static {
const COUNT: usize;
const DEBUG_PARAM: Option<Self>;
type Snapshot: Snapshot<Self> + Send + Sync + 'static;
fn register(params: &mut Parameters<Self>) -> Result<(), after_effects::Error>;
fn snapshot_cpu(params: &Parameters<Self>, geom: &SnapshotGeom) -> Result<Self::Snapshot, after_effects::Error>;
fn snapshot_gpu(filter: &pr::GpuFilterData, render_params: &pr::RenderParams, geom: &SnapshotGeom) -> Self::Snapshot;
fn buttons() -> &'static [(Self, fn())];
}