1use crate::input::{EntityId, Vector3};
7
8#[derive(Debug, Clone, Copy, PartialEq, Eq, Default)]
10pub enum GizmoMode {
11 #[default]
13 Translate,
14 Rotate,
16 Scale,
18}
19
20#[derive(Debug, Clone, Copy, PartialEq, Eq, Default)]
22pub enum GizmoSpace {
23 #[default]
25 World,
26 Local,
28}
29
30#[derive(Debug, Clone, PartialEq)]
32pub struct Gizmo {
33 pub target: EntityId,
35 pub mode: GizmoMode,
37 pub space: GizmoSpace,
39 pub size: f32,
41 pub show_x: bool,
43 pub show_y: bool,
45 pub show_z: bool,
47 pub show_xyz: bool,
49 pub show_planes: bool,
51}
52
53impl Gizmo {
54 pub fn new(target: EntityId) -> Self {
55 Self {
56 target,
57 mode: GizmoMode::Translate,
58 space: GizmoSpace::World,
59 size: 1.0,
60 show_x: true,
61 show_y: true,
62 show_z: true,
63 show_xyz: true,
64 show_planes: true,
65 }
66 }
67
68 pub fn with_mode(mut self, mode: GizmoMode) -> Self {
69 self.mode = mode;
70 self
71 }
72
73 pub fn with_space(mut self, space: GizmoSpace) -> Self {
74 self.space = space;
75 self
76 }
77
78 pub fn with_size(mut self, size: f32) -> Self {
79 self.size = size;
80 self
81 }
82
83 pub fn hide_x(mut self) -> Self {
84 self.show_x = false;
85 self
86 }
87
88 pub fn hide_y(mut self) -> Self {
89 self.show_y = false;
90 self
91 }
92
93 pub fn hide_z(mut self) -> Self {
94 self.show_z = false;
95 self
96 }
97}
98
99#[derive(Debug, Clone)]
101pub struct GizmoEvent {
102 pub target: EntityId,
104 pub mode: GizmoMode,
106 pub space: GizmoSpace,
108 pub transform: GizmoTransform,
110 pub is_finished: bool,
112}
113
114#[derive(Debug, Clone, Copy, Default)]
116pub struct GizmoTransform {
117 pub position: Vector3,
118 pub rotation: Vector3,
119 pub scale: Vector3,
120}
121
122impl GizmoTransform {
123 pub fn new() -> Self {
124 Self {
125 position: Vector3::new(0.0, 0.0, 0.0),
126 rotation: Vector3::new(0.0, 0.0, 0.0),
127 scale: Vector3::new(1.0, 1.0, 1.0),
128 }
129 }
130}
131
132#[derive(Debug, Clone, Copy, PartialEq, Eq)]
134pub enum GizmoHandle {
135 X,
137 Y,
139 Z,
141 XY,
143 YZ,
145 XZ,
147 XYZ,
149}
150
151pub struct GizmoBuilder {
153 gizmo: Gizmo,
154}
155
156impl GizmoBuilder {
157 pub fn new(target: EntityId) -> Self {
158 Self {
159 gizmo: Gizmo::new(target),
160 }
161 }
162
163 pub fn translate(mut self) -> Self {
164 self.gizmo.mode = GizmoMode::Translate;
165 self
166 }
167
168 pub fn rotate(mut self) -> Self {
169 self.gizmo.mode = GizmoMode::Rotate;
170 self
171 }
172
173 pub fn scale(mut self) -> Self {
174 self.gizmo.mode = GizmoMode::Scale;
175 self
176 }
177
178 pub fn world_space(mut self) -> Self {
179 self.gizmo.space = GizmoSpace::World;
180 self
181 }
182
183 pub fn local_space(mut self) -> Self {
184 self.gizmo.space = GizmoSpace::Local;
185 self
186 }
187
188 pub fn size(mut self, size: f32) -> Self {
189 self.gizmo.size = size;
190 self
191 }
192
193 pub fn build(self) -> Gizmo {
194 self.gizmo
195 }
196}