MCPcopy Create free account
hub / github.com/PerroEngine/Perro / handle_event

Method handle_event

perro_source/render_stack/perro_app/src/input/gamepad.rs:229–302  ·  view source on GitHub ↗
(
            &mut self,
            app: &mut S,
            gilrs: &Gilrs,
            event: gilrs::Event,
        )

Source from the content-addressed store, hash-verified

227 None
228 }
229
230 fn ensure_gilrs(&mut self) {
231 if self.gilrs.is_some() {
232 return;
233 }
234 if let Ok(gilrs) = Gilrs::new() {
235 self.gilrs = Some(gilrs);
236 }
237 }
238
239 fn handle_event<S: GamepadSink>(
240 &mut self,
241 app: &mut S,
242 gilrs: &Gilrs,
243 event: gilrs::Event,
244 ) {
245 let id = event.id;
246 match event.event {
247 EventType::Connected => {
248 let gp = gilrs.gamepad(id);
249 if is_joycon(&gp) {
250 return;
251 }
252 if let Some(index) = self.assign_index_if_unique(gilrs, id) {
253 log_gamepad_connected(gilrs, id, index);
254 clear_gamepad(app, index);
255 }
256 }
257 EventType::Disconnected => {
258 let disconnected_index = self
259 .id_to_uuid
260 .get(&id)
261 .and_then(|uuid| self.uuid_to_index.get(uuid).copied());
262 self.handle_disconnect(app, id);
263 if let Some(index) = disconnected_index {
264 self.stop_rumble(index);
265 }
266 self.down_masks.remove(&id);
267 if let Some(uuid) = self.id_to_uuid.remove(&id) {
268 self.uuid_in_use.remove(&uuid);
269 }
270 }
271 EventType::ButtonPressed(button, _) => {
272 if let Some(mapped) = map_button(button) {
273 self.set_button(app, gilrs, id, mapped, true);
274 self.set_trigger_axis_from_button(app, gilrs, id, button, 1.0);
275 self.log_raw_like_state(gilrs, id, "button_pressed");
276 }
277 }
278 EventType::ButtonRepeated(button, _) => {
279 if let Some(mapped) = map_button(button) {
280 self.set_button(app, gilrs, id, mapped, true);
281 self.set_trigger_axis_from_button(app, gilrs, id, button, 1.0);
282 self.log_raw_like_state(gilrs, id, "button_repeated");
283 }
284 }
285 EventType::ButtonReleased(button, _) => {
286 if let Some(mapped) = map_button(button) {

Callers 1

begin_frameMethod · 0.45

Calls 15

is_joyconFunction · 0.85
log_gamepad_connectedFunction · 0.85
clear_gamepadFunction · 0.85
map_buttonFunction · 0.85
map_axisFunction · 0.85
handle_disconnectMethod · 0.80
stop_rumbleMethod · 0.80
set_buttonMethod · 0.80
log_raw_like_stateMethod · 0.80
handle_dpad_axisMethod · 0.80

Tested by

no test coverage detected