private void ProcessEvent(ref SDL_Event evt) { switch (evt.type) { case SDL_EventType.ControllerAxisMotion: SDL_ControllerAxisEvent axisEvent = Unsafe .As <SDL_Event, SDL_ControllerAxisEvent>(ref evt); if (axisEvent.which == _instanceId) { _axisValues[(int)axisEvent.axis] = axisEvent.value < 0 ? -((float)axisEvent.value / short.MinValue) : (float)axisEvent.value / short.MaxValue; } break; case SDL_EventType.ControllerButtonDown: case SDL_EventType.ControllerButtonUp: SDL_ControllerButtonEvent buttonEvent = Unsafe .As <SDL_Event, SDL_ControllerButtonEvent>(ref evt); if (buttonEvent.which == _instanceId) { int index = (int)buttonEvent.button; bool down = buttonEvent.state == 1; _newButtons[index] = !_buttonState[index] && down; _buttonState[index] = down; } break; } }
private void ProcessAnEvent(ref SDL_Event ev) { int id; switch (ev.type) { case SDL_EventType.ControllerDeviceAdded: UpdateGamepadRegister(); _applicationMessenger.QueueMessage(FrameworkMessage.GamepadAdded); break; case SDL_EventType.ControllerDeviceRemoved: UpdateGamepadRegister(); _applicationMessenger.QueueMessage(FrameworkMessage.GamepadRemoved); break; case SDL_EventType.ControllerDeviceRemapped: //Unsure if am required to process this event. For future investigation break; case SDL_EventType.ControllerButtonUp: case SDL_EventType.ControllerButtonDown: SDL_ControllerButtonEvent buttonEvent = Unsafe.As <SDL_Event, SDL_ControllerButtonEvent>(ref ev); id = buttonEvent.which; if (_controllers.ContainsKey(id)) { var controller = _controllers[id]; var button = ToGamepadButton(buttonEvent.button); var pressed = buttonEvent.state == 1; //SDL_PRESSED and SDL_RELEASED don't appear to exist controller.ProcessButtonEvent(button, pressed); } break; case SDL_EventType.ControllerAxisMotion: SDL_ControllerAxisEvent axisEvent = Unsafe.As <SDL_Event, SDL_ControllerAxisEvent>(ref ev); id = axisEvent.which; if (_controllers.ContainsKey(id)) { var controller = _controllers[id]; var axis = ToGamepadAxis(axisEvent.axis); var value = NormalizeAxis(axisEvent.value); controller.ProcessAxisEvent(axis, value); } break; } }
private void ProcessEvent(ref SDL_Event ev) { switch (ev.type) { case SDL_EventType.ControllerAxisMotion: SDL_ControllerAxisEvent axisEvent = Unsafe.As <SDL_Event, SDL_ControllerAxisEvent>(ref ev); if (axisEvent.which == _controllerIndex) { _axisValues[axisEvent.axis] = Normalize(axisEvent.value); } break; case SDL_EventType.ControllerButtonDown: case SDL_EventType.ControllerButtonUp: SDL_ControllerButtonEvent buttonEvent = Unsafe.As <SDL_Event, SDL_ControllerButtonEvent>(ref ev); if (buttonEvent.which == _controllerIndex) { _buttons[buttonEvent.button] = buttonEvent.state == 1; } break; } }