#pragma once #include #include #include "controls/controller_buttons.h" #ifndef USE_SDL1 namespace devilution { class GameController { static std::vector *const controllers_; public: static void Add(int joystick_index); static void Remove(SDL_JoystickID instance_id); static GameController *Get(SDL_JoystickID instance_id); static GameController *Get(const SDL_Event &event); static const std::vector &All(); static bool IsPressedOnAnyController(ControllerButton button); // NOTE: Not idempotent. // Must be called exactly once for each SDL input event. ControllerButton ToControllerButton(const SDL_Event &event); bool IsPressed(ControllerButton button) const; static bool ProcessAxisMotion(const SDL_Event &event); private: static SDL_GameControllerButton ToSdlGameControllerButton(ControllerButton button); SDL_GameController *sdl_game_controller_ = NULL; SDL_JoystickID instance_id_ = -1; bool trigger_left_is_down_ = false; bool trigger_right_is_down_ = false; }; } // namespace devilution #endif