use std::sync::{Arc, Mutex};
use psdk_father::{
args::{ArgContext, PsdkArgBase, PsdkEasyArg},
command::{CommandClause, PsdkTextCommand},
errors::PsdkFatherResult,
};
#[derive(Clone, Debug)]
pub struct CLineOptions {
pub line_width: i32,
pub start_x: i32,
pub start_y: i32,
pub end_x: i32,
pub end_y: i32,
pub is_solid_line: bool,
}
#[derive(Clone, Debug)]
pub struct CLine {
options: CLineOptions,
ctx: Arc<Mutex<ArgContext>>,
}
impl CLine {
pub fn new(options: CLineOptions) -> Self {
Self {
options,
ctx: Default::default(),
}
}
}
impl From<(i32, i32, i32, i32, i32)> for CLine {
fn from((line_width, start_x, start_y, end_x, end_y): (i32, i32, i32, i32, i32)) -> Self {
Self::new(CLineOptions {
line_width,
start_x,
start_y,
end_x,
end_y,
is_solid_line: true,
})
}
}
impl PsdkEasyArg<String> for CLine {
fn context(&self) -> Arc<Mutex<ArgContext>> {
self.ctx.clone()
}
}
impl PsdkArgBase<String> for CLine {
fn header(&self) -> String {
if self.options.is_solid_line {
"L".to_string()
} else {
"LP".to_string()
}
}
fn clause(&self) -> PsdkFatherResult<CommandClause> {
let mut ptc = PsdkTextCommand::with_header_format_cpcl(self.header());
ptc
.append(self.options.start_x)
.append(self.options.start_y)
.append(self.options.end_x)
.append(self.options.end_y)
.append(self.options.line_width + 1);
Ok(ptc.clause())
}
}
psdk_father::impl_psdk_arg_to_easy_arg!(String, CLine, true);