use bevy::camera::visibility::{VisibilityClass, add_visibility_class};
use bevy::color::palettes::css;
use bevy::math::primitives::Rectangle;
use bevy::prelude::*;
use bevy::render::sync_world::SyncToRenderWorld;
use crate::DEFAULT_FILL_HANDLE;
#[derive(Reflect, Debug, Clone, Copy, PartialEq, Eq, Default, Hash)]
pub enum BlendMode {
#[default]
Alpha,
Additive,
}
#[derive(Component, Reflect, Debug, Clone)]
#[require(Transform, Visibility, SyncToRenderWorld, VisibilityClass)] #[reflect(Component, Default, Debug, Clone)]
#[component(on_add = add_visibility_class::<SmudShape>)]
pub struct SmudShape {
pub color: Color,
pub sdf: Handle<Shader>,
pub fill: Handle<Shader>, pub bounds: Rectangle,
pub params: Vec4,
pub blend_mode: BlendMode,
pub extra_bounds: f32,
}
impl Default for SmudShape {
fn default() -> Self {
Self {
color: css::PINK.into(),
sdf: default(),
bounds: default(),
params: default(),
fill: DEFAULT_FILL_HANDLE,
blend_mode: BlendMode::default(),
extra_bounds: 5.0,
}
}
}
impl SmudShape {
pub fn with_color(mut self, color: impl Into<Color>) -> Self {
self.color = color.into();
self
}
pub fn with_fill(mut self, fill: Handle<Shader>) -> Self {
self.fill = fill;
self
}
pub fn with_blend_mode(mut self, blend_mode: BlendMode) -> Self {
self.blend_mode = blend_mode;
self
}
}