use crate::input::{EntityId, Vector3};
#[derive(Debug, Clone, Copy, PartialEq, Eq, Default)]
pub enum GizmoMode {
#[default]
Translate,
Rotate,
Scale,
}
#[derive(Debug, Clone, Copy, PartialEq, Eq, Default)]
pub enum GizmoSpace {
#[default]
World,
Local,
}
#[derive(Debug, Clone, PartialEq)]
pub struct Gizmo {
pub target: EntityId,
pub mode: GizmoMode,
pub space: GizmoSpace,
pub size: f32,
pub show_x: bool,
pub show_y: bool,
pub show_z: bool,
pub show_xyz: bool,
pub show_planes: bool,
}
impl Gizmo {
pub fn new(target: EntityId) -> Self {
Self {
target,
mode: GizmoMode::Translate,
space: GizmoSpace::World,
size: 1.0,
show_x: true,
show_y: true,
show_z: true,
show_xyz: true,
show_planes: true,
}
}
pub fn with_mode(mut self, mode: GizmoMode) -> Self {
self.mode = mode;
self
}
pub fn with_space(mut self, space: GizmoSpace) -> Self {
self.space = space;
self
}
pub fn with_size(mut self, size: f32) -> Self {
self.size = size;
self
}
pub fn hide_x(mut self) -> Self {
self.show_x = false;
self
}
pub fn hide_y(mut self) -> Self {
self.show_y = false;
self
}
pub fn hide_z(mut self) -> Self {
self.show_z = false;
self
}
}
#[derive(Debug, Clone)]
pub struct GizmoEvent {
pub target: EntityId,
pub mode: GizmoMode,
pub space: GizmoSpace,
pub transform: GizmoTransform,
pub is_finished: bool,
}
#[derive(Debug, Clone, Copy, Default)]
pub struct GizmoTransform {
pub position: Vector3,
pub rotation: Vector3,
pub scale: Vector3,
}
impl GizmoTransform {
pub fn new() -> Self {
Self {
position: Vector3::new(0.0, 0.0, 0.0),
rotation: Vector3::new(0.0, 0.0, 0.0),
scale: Vector3::new(1.0, 1.0, 1.0),
}
}
}
#[derive(Debug, Clone, Copy, PartialEq, Eq)]
pub enum GizmoHandle {
X,
Y,
Z,
XY,
YZ,
XZ,
XYZ,
}
pub struct GizmoBuilder {
gizmo: Gizmo,
}
impl GizmoBuilder {
pub fn new(target: EntityId) -> Self {
Self {
gizmo: Gizmo::new(target),
}
}
pub fn translate(mut self) -> Self {
self.gizmo.mode = GizmoMode::Translate;
self
}
pub fn rotate(mut self) -> Self {
self.gizmo.mode = GizmoMode::Rotate;
self
}
pub fn scale(mut self) -> Self {
self.gizmo.mode = GizmoMode::Scale;
self
}
pub fn world_space(mut self) -> Self {
self.gizmo.space = GizmoSpace::World;
self
}
pub fn local_space(mut self) -> Self {
self.gizmo.space = GizmoSpace::Local;
self
}
pub fn size(mut self, size: f32) -> Self {
self.gizmo.size = size;
self
}
pub fn build(self) -> Gizmo {
self.gizmo
}
}