three_d/renderer/control.rs
1//!
2//! A collection of controls for example to control the camera.
3//!
4
5mod orbit_control;
6#[doc(inline)]
7pub use orbit_control::*;
8
9mod free_orbit_control;
10#[doc(inline)]
11pub use free_orbit_control::*;
12
13mod first_person_control;
14#[doc(inline)]
15pub use first_person_control::*;
16
17mod fly_control;
18#[doc(inline)]
19pub use fly_control::*;
20
21mod control2d;
22#[doc(inline)]
23pub use control2d::*;
24
25pub use three_d_asset::PixelPoint as PhysicalPoint;
26
27use three_d_asset::prelude::*;
28
29/// Type of mouse button.
30#[derive(Clone, Copy, Debug, Eq, Ord, PartialEq, PartialOrd, Hash)]
31pub enum MouseButton {
32 /// Left mouse button or one finger on touch.
33 Left,
34 /// Left mouse button or two fingers on touch.
35 Right,
36 /// Middle mouse button.
37 Middle,
38}
39
40/// An input event (from mouse, keyboard or similar).
41#[derive(Clone, Debug)]
42pub enum Event {
43 /// Fired when a button is pressed or the screen is touched.
44 MousePress {
45 /// Type of button
46 button: MouseButton,
47 /// The screen position in physical pixels.
48 position: PhysicalPoint,
49 /// The state of modifiers.
50 modifiers: Modifiers,
51 /// Whether or not this event already have been handled.
52 handled: bool,
53 },
54 /// Fired when a button is released or the screen is stopped being touched.
55 MouseRelease {
56 /// Type of button
57 button: MouseButton,
58 /// The screen position in physical pixels.
59 position: PhysicalPoint,
60 /// The state of modifiers.
61 modifiers: Modifiers,
62 /// Whether or not this event already have been handled.
63 handled: bool,
64 },
65 /// Fired continuously when the mouse or a finger on the screen is moved.
66 MouseMotion {
67 /// Type of button if a button is pressed.
68 button: Option<MouseButton>,
69 /// The relative movement of the mouse/finger since last [Event::MouseMotion] event in logical pixels.
70 delta: (f32, f32),
71 /// The screen position in physical pixels.
72 position: PhysicalPoint,
73 /// The state of modifiers.
74 modifiers: Modifiers,
75 /// Whether or not this event already have been handled.
76 handled: bool,
77 },
78 /// Fired continuously when the mouse wheel or equivalent is applied.
79 MouseWheel {
80 /// The relative scrolling since the last [Event::MouseWheel] event.
81 delta: (f32, f32),
82 /// The screen position in physical pixels.
83 position: PhysicalPoint,
84 /// The state of modifiers.
85 modifiers: Modifiers,
86 /// Whether or not this event already have been handled.
87 handled: bool,
88 },
89 /// Fired continuously when a pinch input gesture is recognized, such as on a Mac trackpad
90 PinchGesture {
91 /// The relative pinching since the last [Event::PinchGesture] event (positive is zoom in).
92 delta: f32,
93 /// The screen position in physical pixels.
94 position: PhysicalPoint,
95 /// The state of modifiers.
96 modifiers: Modifiers,
97 /// Whether or not this event already have been handled.
98 handled: bool,
99 },
100 /// Fired continuously when a rotation input gesture is recognized, such as on a Mac trackpad
101 RotationGesture {
102 /// The relative rotation since the last [Event::RotationGesture] event (positive is counterclockwise).
103 delta: Radians,
104 /// The screen position in physical pixels.
105 position: PhysicalPoint,
106 /// The state of modifiers.
107 modifiers: Modifiers,
108 /// Whether or not this event already have been handled.
109 handled: bool,
110 },
111 /// Fired when the mouse enters the window.
112 MouseEnter,
113 /// Fired when the mouse leaves the window.
114 MouseLeave,
115 /// Fired when a key is pressed.
116 KeyPress {
117 /// The type of key.
118 kind: Key,
119 /// The state of modifiers.
120 modifiers: Modifiers,
121 /// Whether or not this event already have been handled.
122 handled: bool,
123 },
124 /// Fired when a key is released.
125 KeyRelease {
126 /// The type of key.
127 kind: Key,
128 /// The state of modifiers.
129 modifiers: Modifiers,
130 /// Whether or not this event already have been handled.
131 handled: bool,
132 },
133 /// Fired when the modifiers change.
134 ModifiersChange {
135 /// The state of modifiers after the change.
136 modifiers: Modifiers,
137 },
138 /// Fires when some text has been written.
139 Text(String),
140}
141
142/// Keyboard key input.
143#[allow(missing_docs)]
144#[derive(Clone, Copy, Debug, Eq, Ord, PartialEq, PartialOrd, Hash)]
145pub enum Key {
146 ArrowDown,
147 ArrowLeft,
148 ArrowRight,
149 ArrowUp,
150
151 Escape,
152 Tab,
153 Backspace,
154 Enter,
155 Space,
156
157 Insert,
158 Delete,
159 Home,
160 End,
161 PageUp,
162 PageDown,
163 /// Print Screen/SysRq.
164 Snapshot,
165
166 Mute,
167 VolumeDown,
168 VolumeUp,
169
170 Copy,
171 Paste,
172 Cut,
173
174 /// `=`
175 Equals,
176 /// `-`
177 Minus,
178 /// `+`
179 Plus,
180
181 /// Either from the main row or from the numpad.
182 Num0,
183 /// Either from the main row or from the numpad.
184 Num1,
185 /// Either from the main row or from the numpad.
186 Num2,
187 /// Either from the main row or from the numpad.
188 Num3,
189 /// Either from the main row or from the numpad.
190 Num4,
191 /// Either from the main row or from the numpad.
192 Num5,
193 /// Either from the main row or from the numpad.
194 Num6,
195 /// Either from the main row or from the numpad.
196 Num7,
197 /// Either from the main row or from the numpad.
198 Num8,
199 /// Either from the main row or from the numpad.
200 Num9,
201
202 A,
203 B,
204 C,
205 D,
206 E,
207 F,
208 G,
209 H,
210 I,
211 J,
212 K,
213 L,
214 M,
215 N,
216 O,
217 P,
218 Q,
219 R,
220 S,
221 T,
222 U,
223 V,
224 W,
225 X,
226 Y,
227 Z,
228
229 F1,
230 F2,
231 F3,
232 F4,
233 F5,
234 F6,
235 F7,
236 F8,
237 F9,
238 F10,
239 F11,
240 F12,
241 F13,
242 F14,
243 F15,
244 F16,
245 F17,
246 F18,
247 F19,
248 F20,
249 F21,
250 F22,
251 F23,
252 F24,
253
254 /// `'`
255 Apostrophe,
256 /// `*`
257 Asterisk,
258 /// `\`
259 Backslash,
260 /// `^`
261 Caret,
262 /// `:`
263 Colon,
264 /// `,`
265 Comma,
266 /// `` ` ``
267 Grave,
268 /// `[`
269 LBracket,
270 /// `.`
271 Period,
272 /// `]`
273 RBracket,
274 /// `;`
275 Semicolon,
276 /// `/`
277 Slash,
278 /// `_`
279 Underline,
280}
281
282/// State of modifiers (alt, ctrl, shift and command).
283#[derive(Clone, Copy, Debug, Default, Eq, PartialEq)]
284pub struct Modifiers {
285 /// Either of the alt keys are down (option ⌥ on Mac).
286 pub alt: bool,
287 /// Either of the control keys are down.
288 /// When checking for keyboard shortcuts, consider using [`Self::command`] instead.
289 pub ctrl: bool,
290 /// Either of the shift keys are down.
291 pub shift: bool,
292 /// On Windows and Linux, set this to the same value as `ctrl`.
293 /// On Mac, this should be set whenever one of the ⌘ Command keys are down.
294 pub command: bool,
295}