use super::{Color, Gradient, Image};
#[derive(Clone, PartialEq, Debug)]
pub enum Brush {
Solid(Color),
Gradient(Gradient),
Image(Image),
}
impl From<Color> for Brush {
fn from(c: Color) -> Self {
Self::Solid(c)
}
}
impl From<Gradient> for Brush {
fn from(g: Gradient) -> Self {
Self::Gradient(g)
}
}
#[derive(Clone, PartialEq, Debug)]
pub enum BrushRef<'a> {
Solid(Color),
Gradient(&'a Gradient),
Image(&'a Image),
}
impl<'a> BrushRef<'a> {
pub fn to_owned(&self) -> Brush {
match self {
Self::Solid(color) => Brush::Solid(*color),
Self::Gradient(gradient) => Brush::Gradient((*gradient).clone()),
Self::Image(image) => Brush::Image((*image).clone()),
}
}
}
impl From<Color> for BrushRef<'_> {
fn from(color: Color) -> Self {
Self::Solid(color)
}
}
impl<'a> From<&'a Color> for BrushRef<'_> {
fn from(color: &'a Color) -> Self {
Self::Solid(*color)
}
}
impl<'a> From<&'a Gradient> for BrushRef<'a> {
fn from(gradient: &'a Gradient) -> Self {
Self::Gradient(gradient)
}
}
impl<'a> From<&'a Image> for BrushRef<'a> {
fn from(image: &'a Image) -> Self {
Self::Image(image)
}
}
impl<'a> From<&'a Brush> for BrushRef<'a> {
fn from(brush: &'a Brush) -> Self {
match brush {
Brush::Solid(color) => Self::Solid(*color),
Brush::Gradient(gradient) => Self::Gradient(gradient),
Brush::Image(image) => Self::Image(image),
}
}
}
#[derive(Copy, Clone, PartialEq, Eq, Default, Debug)]
pub enum Extend {
#[default]
Pad,
Repeat,
Reflect,
}