use crate::{c_api::ffi, NcBlitter, NcPlane, NcRgba, NcScale};
use core::ptr::null_mut;
mod builder;
pub use builder::NcVisualOptionsBuilder;
pub type NcVisualOptions = crate::c_api::ffi::ncvisual_options;
impl<'ncplane> NcVisualOptions {
pub fn builder() -> NcVisualOptionsBuilder<'ncplane> {
NcVisualOptionsBuilder::default()
}
pub fn new(
plane: Option<&mut NcPlane>,
scale: impl Into<NcScale>,
y: i32,
x: i32,
section_yx_lenyx: Option<(u32, u32, u32, u32)>,
cell_offset_yx: Option<(u32, u32)>,
blitter: impl Into<NcBlitter>,
flags: impl Into<NcVisualFlag>,
transcolor: impl Into<NcRgba>,
) -> Self {
let plane_ptr = if let Some(p) = plane { p } else { null_mut() };
let (begy, begx, leny, lenx) =
if let Some(s) = section_yx_lenyx { (s.0, s.1, s.2, s.3) } else { (0, 0, 0, 0) };
let (pxoffy, pxoffx) = if let Some(o) = cell_offset_yx { (o.0, o.1) } else { (0, 0) };
Self {
n: plane_ptr,
scaling: scale.into().into(),
y,
x,
begy,
begx,
leny,
lenx,
blitter: blitter.into().into(),
flags: flags.into().into(),
transcolor: transcolor.into().into(),
pxoffy,
pxoffx,
}
}
}
impl NcVisualOptions {
pub fn does_plane(&self) -> bool {
!self.n.is_null()
}
pub fn does_child_plane(&self) -> bool {
self.flags & NcVisualFlag::ChildPlane != NcVisualFlag::None
}
pub fn does_alpha(&self) -> bool {
self.flags & NcVisualFlag::AddAlpha != NcVisualFlag::None
}
pub fn does_blend(&self) -> bool {
self.flags & NcVisualFlag::Blend != NcVisualFlag::None
}
pub fn does_degrade(&self) -> bool {
self.flags & NcVisualFlag::NoDegrade == NcVisualFlag::None
}
pub fn does_interpolate(&self) -> bool {
self.flags & NcVisualFlag::NoInterpolate == NcVisualFlag::None
}
pub fn is_veraligned(&self) -> bool {
self.flags & NcVisualFlag::VerAligned != NcVisualFlag::None
}
pub fn is_horaligned(&self) -> bool {
self.flags & NcVisualFlag::HorAligned != NcVisualFlag::None
}
}
#[derive(Copy, Clone, Debug, PartialEq, Eq)]
pub struct NcVisualFlag(pub c_api::NcVisualFlag_u64);
impl NcVisualFlag {
pub const None: Self = Self(0);
pub const AddAlpha: Self = Self(c_api::NCVISUAL_OPTION_ADDALPHA);
pub const Blend: Self = Self(c_api::NCVISUAL_OPTION_BLEND);
pub const ChildPlane: Self = Self(c_api::NCVISUAL_OPTION_CHILDPLANE);
pub const NoDegrade: Self = Self(c_api::NCVISUAL_OPTION_NODEGRADE);
pub const VerAligned: Self = Self(c_api::NCVISUAL_OPTION_VERALIGNED);
pub const HorAligned: Self = Self(c_api::NCVISUAL_OPTION_HORALIGNED);
pub const NoInterpolate: Self = Self(c_api::NCVISUAL_OPTION_NOINTERPOLATE);
}
mod core_impls {
use super::{c_api::NcVisualFlag_u64, NcVisualFlag};
impl Default for NcVisualFlag {
fn default() -> Self {
Self::None
}
}
crate::from_primitive![NcVisualFlag, NcVisualFlag_u64];
crate::unit_impl_from![NcVisualFlag, NcVisualFlag_u64];
crate::unit_impl_ops![bitwise; NcVisualFlag, NcVisualFlag_u64];
crate::unit_impl_fmt![bases+display; NcVisualFlag];
}
pub(crate) mod c_api {
use super::ffi;
pub type NcVisualFlag_u64 = u64;
pub const NCVISUAL_OPTION_ADDALPHA: NcVisualFlag_u64 =
ffi::NCVISUAL_OPTION_ADDALPHA as NcVisualFlag_u64;
pub const NCVISUAL_OPTION_BLEND: NcVisualFlag_u64 =
ffi::NCVISUAL_OPTION_BLEND as NcVisualFlag_u64;
pub const NCVISUAL_OPTION_CHILDPLANE: NcVisualFlag_u64 =
ffi::NCVISUAL_OPTION_CHILDPLANE as NcVisualFlag_u64;
pub const NCVISUAL_OPTION_NODEGRADE: NcVisualFlag_u64 =
ffi::NCVISUAL_OPTION_NODEGRADE as NcVisualFlag_u64;
pub const NCVISUAL_OPTION_VERALIGNED: NcVisualFlag_u64 =
ffi::NCVISUAL_OPTION_VERALIGNED as NcVisualFlag_u64;
pub const NCVISUAL_OPTION_HORALIGNED: NcVisualFlag_u64 =
ffi::NCVISUAL_OPTION_HORALIGNED as NcVisualFlag_u64;
pub const NCVISUAL_OPTION_NOINTERPOLATE: NcVisualFlag_u64 =
ffi::NCVISUAL_OPTION_NOINTERPOLATE as NcVisualFlag_u64;
}