use teksilo_tokens::Color;
use crate::geometry::Point;
#[derive(Debug, Clone, PartialEq)]
pub enum Paint {
Solid(Color),
LinearGradient {
start: Point,
end: Point,
stops: Vec<GradientStop>,
},
RadialGradient {
center: Point,
radius: f32,
stops: Vec<GradientStop>,
},
ConicGradient {
center: Point,
start_angle: f32,
stops: Vec<GradientStop>,
},
Image(ImageHandle),
}
#[derive(Debug, Clone, PartialEq)]
pub struct ImageHandle {
pub name: String,
}
#[derive(Debug, Clone, Copy, PartialEq)]
pub struct GradientStop {
pub offset: f32,
pub color: Color,
}
#[derive(Debug, Clone, Copy, PartialEq, Eq, Default)]
pub enum LineCap {
#[default]
Butt,
Round,
Square,
}
#[derive(Debug, Clone, Copy, PartialEq, Eq, Default)]
pub enum LineJoin {
#[default]
Miter,
Round,
Bevel,
}
#[derive(Debug, Clone, Copy, PartialEq, Eq, Default)]
pub enum FillRule {
#[default]
Winding,
EvenOdd,
}
#[derive(Debug, Clone, Copy, PartialEq, Eq, Default)]
pub enum StrokeSpace {
#[default]
Logical,
Device,
}
#[derive(Debug, Clone, PartialEq)]
pub struct StrokeStyle {
pub width: f32,
pub dash_pattern: Option<Vec<f32>>,
pub dash_offset: f32,
pub line_cap: LineCap,
pub line_join: LineJoin,
pub miter_limit: f32,
pub space: StrokeSpace,
}
impl StrokeStyle {
pub fn solid(width: f32) -> Self {
Self {
width,
dash_pattern: None,
dash_offset: 0.0,
line_cap: LineCap::Butt,
line_join: LineJoin::Miter,
miter_limit: 4.0,
space: StrokeSpace::Logical,
}
}
pub fn dashed(width: f32, dash: f32, gap: f32) -> Self {
Self {
width,
dash_pattern: Some(vec![dash, gap]),
dash_offset: 0.0,
line_cap: LineCap::Butt,
line_join: LineJoin::Miter,
miter_limit: 4.0,
space: StrokeSpace::Logical,
}
}
pub fn dotted(width: f32, spacing: f32) -> Self {
Self {
width,
dash_pattern: Some(vec![width, spacing]),
dash_offset: 0.0,
line_cap: LineCap::Round,
line_join: LineJoin::Miter,
miter_limit: 4.0,
space: StrokeSpace::Logical,
}
}
pub fn hairline(width: f32) -> Self {
Self {
width,
dash_pattern: None,
dash_offset: 0.0,
line_cap: LineCap::Butt,
line_join: LineJoin::Miter,
miter_limit: 4.0,
space: StrokeSpace::Device,
}
}
}
impl Default for StrokeStyle {
fn default() -> Self {
Self::solid(0.0)
}
}
impl From<f32> for StrokeStyle {
fn from(width: f32) -> Self {
Self::solid(width)
}
}
impl From<Color> for Paint {
fn from(color: Color) -> Self {
Paint::Solid(color)
}
}