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
21pub use three_d_asset::PixelPoint as PhysicalPoint;
22
23use three_d_asset::Radians;
24
25/// Type of mouse button.
26#[derive(Clone, Copy, Debug, Eq, Ord, PartialEq, PartialOrd, Hash)]
27pub enum MouseButton {
28 /// Left mouse button or one finger on touch.
29 Left,
30 /// Left mouse button or two fingers on touch.
31 Right,
32 /// Middle mouse button.
33 Middle,
34}
35
36/// An input event (from mouse, keyboard or similar).
37#[derive(Clone, Debug)]
38pub enum Event {
39 /// Fired when a button is pressed or the screen is touched.
40 MousePress {
41 /// Type of button
42 button: MouseButton,
43 /// The screen position in physical pixels.
44 position: PhysicalPoint,
45 /// The state of modifiers.
46 modifiers: Modifiers,
47 /// Whether or not this event already have been handled.
48 handled: bool,
49 },
50 /// Fired when a button is released or the screen is stopped being touched.
51 MouseRelease {
52 /// Type of button
53 button: MouseButton,
54 /// The screen position in physical pixels.
55 position: PhysicalPoint,
56 /// The state of modifiers.
57 modifiers: Modifiers,
58 /// Whether or not this event already have been handled.
59 handled: bool,
60 },
61 /// Fired continuously when the mouse or a finger on the screen is moved.
62 MouseMotion {
63 /// Type of button if a button is pressed.
64 button: Option<MouseButton>,
65 /// The relative movement of the mouse/finger since last [Event::MouseMotion] event in logical pixels.
66 delta: (f32, f32),
67 /// The screen position in physical pixels.
68 position: PhysicalPoint,
69 /// The state of modifiers.
70 modifiers: Modifiers,
71 /// Whether or not this event already have been handled.
72 handled: bool,
73 },
74 /// Fired continuously when the mouse wheel or equivalent is applied.
75 MouseWheel {
76 /// The relative scrolling since the last [Event::MouseWheel] event.
77 delta: (f32, f32),
78 /// The screen position in physical pixels.
79 position: PhysicalPoint,
80 /// The state of modifiers.
81 modifiers: Modifiers,
82 /// Whether or not this event already have been handled.
83 handled: bool,
84 },
85 /// Fired continuously when a pinch input gesture is recognized, such as on a Mac trackpad
86 PinchGesture {
87 /// The relative pinching since the last [Event::PinchGesture] event (positive is zoom in).
88 delta: f32,
89 /// The screen position in physical pixels.
90 position: PhysicalPoint,
91 /// The state of modifiers.
92 modifiers: Modifiers,
93 /// Whether or not this event already have been handled.
94 handled: bool,
95 },
96 /// Fired continuously when a rotation input gesture is recognized, such as on a Mac trackpad
97 RotationGesture {
98 /// The relative rotation since the last [Event::RotationGesture] event (positive is counterclockwise).
99 delta: Radians,
100 /// The screen position in physical pixels.
101 position: PhysicalPoint,
102 /// The state of modifiers.
103 modifiers: Modifiers,
104 /// Whether or not this event already have been handled.
105 handled: bool,
106 },
107 /// Fired when the mouse enters the window.
108 MouseEnter,
109 /// Fired when the mouse leaves the window.
110 MouseLeave,
111 /// Fired when a key is pressed.
112 KeyPress {
113 /// The type of key.
114 kind: Key,
115 /// The state of modifiers.
116 modifiers: Modifiers,
117 /// Whether or not this event already have been handled.
118 handled: bool,
119 },
120 /// Fired when a key is released.
121 KeyRelease {
122 /// The type of key.
123 kind: Key,
124 /// The state of modifiers.
125 modifiers: Modifiers,
126 /// Whether or not this event already have been handled.
127 handled: bool,
128 },
129 /// Fired when the modifiers change.
130 ModifiersChange {
131 /// The state of modifiers after the change.
132 modifiers: Modifiers,
133 },
134 /// Fires when some text has been written.
135 Text(String),
136}
137
138/// Keyboard key input.
139#[allow(missing_docs)]
140#[derive(Clone, Copy, Debug, Eq, Ord, PartialEq, PartialOrd, Hash)]
141pub enum Key {
142 ArrowDown,
143 ArrowLeft,
144 ArrowRight,
145 ArrowUp,
146
147 Escape,
148 Tab,
149 Backspace,
150 Enter,
151 Space,
152
153 Insert,
154 Delete,
155 Home,
156 End,
157 PageUp,
158 PageDown,
159
160 /// Either from the main row or from the numpad.
161 Num0,
162 /// Either from the main row or from the numpad.
163 Num1,
164 /// Either from the main row or from the numpad.
165 Num2,
166 /// Either from the main row or from the numpad.
167 Num3,
168 /// Either from the main row or from the numpad.
169 Num4,
170 /// Either from the main row or from the numpad.
171 Num5,
172 /// Either from the main row or from the numpad.
173 Num6,
174 /// Either from the main row or from the numpad.
175 Num7,
176 /// Either from the main row or from the numpad.
177 Num8,
178 /// Either from the main row or from the numpad.
179 Num9,
180
181 A,
182 B,
183 C,
184 D,
185 E,
186 F,
187 G,
188 H,
189 I,
190 J,
191 K,
192 L,
193 M,
194 N,
195 O,
196 P,
197 Q,
198 R,
199 S,
200 T,
201 U,
202 V,
203 W,
204 X,
205 Y,
206 Z,
207}
208
209/// State of modifiers (alt, ctrl, shift and command).
210#[derive(Clone, Copy, Debug, Default, Eq, PartialEq)]
211pub struct Modifiers {
212 /// Either of the alt keys are down (option ⌥ on Mac).
213 pub alt: bool,
214 /// Either of the control keys are down.
215 /// When checking for keyboard shortcuts, consider using [`Self::command`] instead.
216 pub ctrl: bool,
217 /// Either of the shift keys are down.
218 pub shift: bool,
219 /// On Windows and Linux, set this to the same value as `ctrl`.
220 /// On Mac, this should be set whenever one of the ⌘ Command keys are down.
221 pub command: bool,
222}