pub fn send_controller_event(
        &mut self,
        event: &ControllerEvent,
        event_handler: &mut EventChannel<InputEvent<AC>>,
    ) {
        use self::ControllerEvent::*;

        match *event {
            ControllerAxisMoved { which, axis, value } => {
                if let Some(controller_id) = self.controller_idx_to_id(which) {
                    self.controller_axes
                        .iter_mut()
                        .find(|(id, a, _)| *id == controller_id && *a == axis)
                        .map(|entry| entry.2 = value)
                        .unwrap_or_else(|| {
                            self.controller_axes.push((controller_id, axis, value));
                        });
                    event_handler.single_write(event.into());
                }
            }
            ControllerButtonPressed { which, button } => {
                if let Some(controller_id) = self.controller_idx_to_id(which) {
                    if self.pressed_controller_buttons
                        .iter()
                        .all(|&(id, b)| id != controller_id || b != button)
                    {
                        self.pressed_controller_buttons
                            .push((controller_id, button));
                        event_handler.iter_write(
                            [
                                event.into(),
                                ButtonPressed(Button::Controller(controller_id, button)),
                            ].iter()
                                .cloned(),
                        );
                        for (k, v) in self.bindings.actions.iter() {
                            for &b in v {
                                if Button::Controller(controller_id, button) == b {
                                    event_handler.single_write(ActionPressed(k.clone()));
                                }
                            }
                        }
                    }
                }
            }
            ControllerButtonReleased { which, button } => {
                if let Some(controller_id) = self.controller_idx_to_id(which) {
                    let index = self.pressed_controller_buttons
                        .iter()
                        .position(|&(id, b)| id == controller_id && b == button);
                    if let Some(i) = index {
                        self.pressed_controller_buttons.swap_remove(i);
                        event_handler.iter_write(
                            [
                                event.into(),
                                ButtonReleased(Button::Controller(controller_id, button)),
                            ].iter()
                                .cloned(),
                        );
                        for (k, v) in self.bindings.actions.iter() {
                            for &b in v {
                                if Button::Controller(controller_id, button) == b {
                                    event_handler.single_write(ActionReleased(k.clone()));
                                }
                            }
                        }
                    }
                }
            }
            ControllerConnected { which } => {
                if self.controller_idx_to_id(which).is_none() {
                    let controller_id = self.alloc_controller_id();
                    if self.connected_controllers
                        .iter()
                        .all(|&ids| ids.0 != controller_id)
                    {
                        self.connected_controllers.push((controller_id, which));
                    }
                }
            }
            ControllerDisconnected { which } => {
                if let Some(controller_id) = self.controller_idx_to_id(which) {
                    let index = self.connected_controllers
                        .iter()
                        .position(|&ids| ids.0 == controller_id);
                    if let Some(i) = index {
                        self.connected_controllers.swap_remove(i);
                        self.controller_axes.retain(|a| a.0 != controller_id);
                        self.pressed_controller_buttons
                            .retain(|b| b.0 != controller_id);
                    }
                }
            }
        }
    }
/// Updates the input handler with a new controller event.
///
/// Called internally from SdlEventsSystem when using sdl_controller feature.
/// You should invoke it in your system if you provide
/// your own controller input implementation.
Updates the input handler with a new controller event.
Called internally from SdlEventsSystem when using sdl_controller feature.
You should invoke it in your system if you provide
your own controller input implementation.
Updates the input handler with a new controller event . Called internally from SdlEventsSystem when using sdl_controller feature . You should invoke it in your system if you provide your own controller input implementation .
pub fn send_controller_event(
        &mut self,
        event: &ControllerEvent,
        event_handler: &mut EventChannel<InputEvent<AC>>,
    ) {
        use self::ControllerEvent::*;
        match *event {
            ControllerAxisMoved { which, axis, value } => {
                if let Some(controller_id) = self.controller_idx_to_id(which) {
                    self.controller_axes
                        .iter_mut()
                        .find(|(id, a, _)| *id == controller_id && *a == axis)
                        .map(|entry| entry.2 = value)
                        .unwrap_or_else(|| {
                            self.controller_axes.push((controller_id, axis, value));
                        });
                    event_handler.single_write(event.into());
                }
            }
            ControllerButtonPressed { which, button } => {
                if let Some(controller_id) = self.controller_idx_to_id(which) {
                    if self.pressed_controller_buttons
                        .iter()
                        .all(|&(id, b)| id != controller_id || b != button)
                    {
                        self.pressed_controller_buttons
                            .push((controller_id, button));
                        event_handler.iter_write(
                            [
                                event.into(),
                                ButtonPressed(Button::Controller(controller_id, button)),
                            ].iter()
                                .cloned(),
                        );
                        for (k, v) in self.bindings.actions.iter() {
                            for &b in v {
                                if Button::Controller(controller_id, button) == b {
                                    event_handler.single_write(ActionPressed(k.clone()));
                                }
                            }
                        }
                    }
                }
            }
            ControllerButtonReleased { which, button } => {
                if let Some(controller_id) = self.controller_idx_to_id(which) {
                    let index = self.pressed_controller_buttons
                        .iter()
                        .position(|&(id, b)| id == controller_id && b == button);
                    if let Some(i) = index {
                        self.pressed_controller_buttons.swap_remove(i);
                        event_handler.iter_write(
                            [
                                event.into(),
                                ButtonReleased(Button::Controller(controller_id, button)),
                            ].iter()
                                .cloned(),
                        );
                        for (k, v) in self.bindings.actions.iter() {
                            for &b in v {
                                if Button::Controller(controller_id, button) == b {
                                    event_handler.single_write(ActionReleased(k.clone()));
                                }
                            }
                        }
                    }
                }
            }
            ControllerConnected { which } => {
                if self.controller_idx_to_id(which).is_none() {
                    let controller_id = self.alloc_controller_id();
                    if self.connected_controllers
                        .iter()
                        .all(|&ids| ids.0 != controller_id)
                    {
                        self.connected_controllers.push((controller_id, which));
                    }
                }
            }
            ControllerDisconnected { which } => {
                if let Some(controller_id) = self.controller_idx_to_id(which) {
                    let index = self.connected_controllers
                        .iter()
                        .position(|&ids| ids.0 == controller_id);
                    if let Some(i) = index {
                        self.connected_controllers.swap_remove(i);
                        self.controller_axes.retain(|a| a.0 != controller_id);
                        self.pressed_controller_buttons
                            .retain(|b| b.0 != controller_id);
                    }
                }
            }
        }
    }
pub fn send_controller_event ( & mut self , event : & ControllerEvent , event_handler : & mut EventChannel < InputEvent < AC > > , ) { use self :: ControllerEvent :: * ; match * event { ControllerAxisMoved { which , axis , value } => { if let Some ( controller_id ) = self . controller_idx_to_id ( which ) { self . controller_axes . iter_mut ( ) . find ( | ( id , a , _ ) | * id == controller_id && * a == axis ) . map ( | entry | entry . 2 = value ) . unwrap_or_else ( | | { self . controller_axes . push ( ( controller_id , axis , value ) ) ; } ) ; event_handler . single_write ( event . into ( ) ) ; } } ControllerButtonPressed { which , button } => { if let Some ( controller_id ) = self . controller_idx_to_id ( which ) { if self . pressed_controller_buttons . iter ( ) . all ( | & ( id , b ) | id != controller_id || b != button ) { self . pressed_controller_buttons . push ( ( controller_id , button ) ) ; event_handler . iter_write ( [ event . into ( ) , ButtonPressed ( Button :: Controller ( controller_id , button ) ) , ] . iter ( ) . cloned ( ) , ) ; for ( k , v ) in self . bindings . actions . iter ( ) { for & b in v { if Button :: Controller ( controller_id , button ) == b { event_handler . single_write ( ActionPressed ( k . clone ( ) ) ) ; } } } } } } ControllerButtonReleased { which , button } => { if let Some ( controller_id ) = self . controller_idx_to_id ( which ) { let index = self . pressed_controller_buttons . iter ( ) . position ( | & ( id , b ) | id == controller_id && b == button ) ; if let Some ( i ) = index { self . pressed_controller_buttons . swap_remove ( i ) ; event_handler . iter_write ( [ event . into ( ) , ButtonReleased ( Button :: Controller ( controller_id , button ) ) , ] . iter ( ) . cloned ( ) , ) ; for ( k , v ) in self . bindings . actions . iter ( ) { for & b in v { if Button :: Controller ( controller_id , button ) == b { event_handler . single_write ( ActionReleased ( k . clone ( ) ) ) ; } } } } } } ControllerConnected { which } => { if self . controller_idx_to_id ( which ) . is_none ( ) { let controller_id = self . alloc_controller_id ( ) ; if self . connected_controllers . iter ( ) . all ( | & ids | ids . 0 != controller_id ) { self . connected_controllers . push ( ( controller_id , which ) ) ; } } } ControllerDisconnected { which } => { if let Some ( controller_id ) = self . controller_idx_to_id ( which ) { let index = self . connected_controllers . iter ( ) . position ( | & ids | ids . 0 == controller_id ) ; if let Some ( i ) = index { self . connected_controllers . swap_remove ( i ) ; self . controller_axes . retain ( | a | a . 0 != controller_id ) ; self . pressed_controller_buttons . retain ( | b | b . 0 != controller_id ) ; } } } } }
Updates the input handler with a new controller event.
Updates the input handler with a new controller event .
&mut self
event
&ControllerEvent
event_handler
&mut EventChannel<InputEvent<AC>>
&mut self
event
&ControllerEvent
event_handler
&mut EventChannel<InputEvent<AC>>