#pragma once #include #include #include "controls/controller_buttons.h" namespace devilution { class GameController { static std::vector controllers_; public: static void Add(int joystickIndex); static void Remove(SDL_JoystickID instanceId); static GameController *Get(SDL_JoystickID instanceId); static GameController *Get(const SDL_Event &event); static const std::vector &All(); static bool IsPressedOnAnyController(ControllerButton button, SDL_JoystickID *which = nullptr); // Must be called exactly once at the start of each SDL input event. void UnlockTriggerState(); ControllerButton ToControllerButton(const SDL_Event &event); bool IsPressed(ControllerButton button) const; static bool ProcessAxisMotion(const SDL_Event &event); static SDL_GameControllerButton ToSdlGameControllerButton(ControllerButton button); private: SDL_GameController *sdl_game_controller_ = NULL; SDL_JoystickID instance_id_ = -1; ControllerButton trigger_left_state_ = ControllerButton_NONE; ControllerButton trigger_right_state_ = ControllerButton_NONE; bool trigger_left_is_down_ = false; bool trigger_right_is_down_ = false; }; } // namespace devilution