pub mod painter;
pub mod path;
pub mod render;
pub mod tess;
use bevy::prelude::*;
pub use painter::{PainterConfig, VectorPainter, VectorPainterQueue};
pub use path::{
Brush, DashPattern, FillRule, GradientStop, LineCap, LineJoin, PathCommand, PathStyle,
StrokeStyle,
};
#[derive(Component, Clone, Copy, Debug)]
pub struct HudTransform {
pub translation: Vec3,
pub rotation: f32,
pub scale: Vec2,
}
impl Default for HudTransform {
fn default() -> Self {
Self { translation: Vec3::ZERO, rotation: 0.0, scale: Vec2::ONE }
}
}
impl HudTransform {
pub fn from_xyz(x: f32, y: f32, z: f32) -> Self {
Self { translation: Vec3::new(x, y, z), ..Default::default() }
}
pub(crate) fn decompose(&self) -> ([f32; 4], [f32; 2], f32) {
let (sin, cos) = bevy::math::ops::sin_cos(self.rotation);
(
[
cos * self.scale.x,
sin * self.scale.x,
-sin * self.scale.y,
cos * self.scale.y,
],
[self.translation.x, self.translation.y],
self.translation.z,
)
}
}
#[derive(Component, Clone, Debug)]
#[require(Transform)]
pub struct VectorShape {
pub commands: Vec<PathCommand>,
pub style: PathStyle,
}
#[derive(Component, Clone, Copy, Debug)]
#[require(Transform)]
pub enum VectorPrimitive {
Arc {
inner: f32,
outer: f32,
start: f32,
sweep: f32,
color: LinearRgba,
},
Rect {
size: Vec2,
radius: f32,
thickness: f32,
color: LinearRgba,
},
}
impl VectorPrimitive {
pub fn circle(radius: f32, thickness: f32, color: LinearRgba) -> Self {
Self::Rect {
size: Vec2::splat(radius * 2.0),
radius,
thickness,
color,
}
}
pub fn line(length: f32, thickness: f32, color: LinearRgba) -> Self {
Self::Rect {
size: Vec2::new(length + thickness, thickness),
radius: thickness * 0.5,
thickness: 0.0,
color,
}
}
}
#[derive(Component, Clone, Copy, Debug)]
#[require(Transform)]
pub enum VectorClipShape {
RoundedRect { half_extents: Vec2, radius: f32 },
Circle { radius: f32 },
}
#[derive(Component, Clone, Copy, Debug)]
pub struct ClippedBy(pub Entity);
pub struct PfVectorPlugin;
impl Plugin for PfVectorPlugin {
fn build(&self, app: &mut App) {
app.init_resource::<painter::VectorPainterQueue>()
.add_systems(First, painter::clear_painter_queue)
.add_plugins(render::VectorRenderPlugin);
}
}