use bevy::prelude::*; use bevy_egui::egui; pub mod create; pub mod helpers; pub mod modify; pub mod ui; pub mod infinite_grid; pub use modify::modify_sys; pub use create::create_sys; pub use helpers::*; #[derive(Debug, Clone)] pub struct SnapGrid { pub width: f32, pub height: f32, pub snap: bool, pub offset: Vec2, pub visible: bool, } impl SnapGrid { pub fn snap_to_grid(&self, v: Vec2) -> Vec2 { if self.snap { let w = v - self.offset + 0.5 * Vec2::new(self.width.copysign(v.x), self.height.copysign(v.y)); let snapped = Vec2::new(w.x - w.x % self.width, w.y - w.y % self.height); snapped + self.offset } else { v } } } impl Default for SnapGrid { fn default() -> Self { Self { width: 15.0, height: 15.0, snap: false, offset: Vec2::ZERO, visible: true } } } #[derive(Clone, Debug)] pub struct PointSize(pub f32); #[derive(Component, Debug, Deref, DerefMut)] pub struct ImageName(pub String); #[derive(Component, Debug, Deref, DerefMut)] pub struct ImageSize(pub Vec2); #[derive(Component, Debug)] pub struct ShapeData { pub name: String, pub shape: CreateShape, pub main_shape: Entity, pub edges: Vec, pub center: Option, } #[derive(Component)] pub struct MainCamera; #[derive(Debug, PartialEq, Eq, Clone, Copy)] pub enum CreateShape { Triangle, Square, Circle, Capsule } #[derive(Debug, PartialEq, Eq, Clone, Copy)] pub enum Action { Create, Modify } pub struct UiState { pub current_action: Action, pub create_shape: CreateShape, } impl Default for UiState { fn default() -> Self { Self { current_action: Action::Modify, create_shape: CreateShape::Square, } } } impl UiState { pub fn create_shape_color(&self, colors: &ButtonsColors, shape: CreateShape) -> egui::Rgba { if self.create_shape == shape { colors.clicked } else { colors.regular } } pub fn current_action_color(&self, colors: &ButtonsColors, action: Action) -> egui::Rgba { if self.current_action == action { colors.clicked } else { colors.regular } } } #[derive(Debug)] pub struct ButtonsColors { pub regular: egui::Rgba, pub clicked: egui::Rgba, } impl Default for ButtonsColors { fn default() -> Self { Self { regular: egui::Rgba::from_rgb(0.3, 0.3, 0.3), clicked: egui::Rgba::from_rgb(1.0, 1.0, 1.0) } } }