// Copyright Citra Emulator Project / Azahar Emulator Project // Licensed under GPLv2 or any later version // Refer to the license.txt file included. #pragma once #include #include #include #include #include #include #include "common/vector_math.h" #include "input_common/sdl/sdl.h" union SDL_Event; using SDL_Joystick = struct _SDL_Joystick; using SDL_JoystickID = s32; using SDL_GameController = struct _SDL_GameController; namespace InputCommon::SDL { class SDLJoystick { public: SDLJoystick(std::string guid_, int port_, SDL_Joystick* joystick, SDL_GameController* game_controller); bool IsButtonMappedToController(int button) const; void EnableMotion(); bool HasMotion() const; bool GetButton(int button, bool isController) const; float GetAxis(int axis, bool isController) const; std::tuple GetAnalog(int axis_x, int axis_y, bool isController) const; bool GetHatDirection(int hat, uint8_t direction) const; void SetTouchpad(float x, float y, int touchpad, bool down); void SetAccel(const float x, const float y, const float z); void SetGyro(const float pitch, const float yaw, const float roll); std::tuple, Common::Vec3> GetMotion() const; /** * The guid of the joystick */ const std::string& GetGUID() const; /** * The number of joystick from the same type that were connected before this joystick */ int GetPort() const; std::tuple GetTouch(int pad) const; SDL_Joystick* GetSDLJoystick() const; SDL_GameController* GetSDLGameController() const; void SetSDLJoystick(SDL_Joystick* joystick, SDL_GameController* controller); private: struct State { Common::Vec3 accel; Common::Vec3 gyro; std::unordered_map> touchpad; } state; std::string guid; int port; bool has_gyro{false}; bool has_accel{false}; std::unique_ptr sdl_joystick; std::unique_ptr sdl_controller; mutable std::mutex mutex; std::unordered_set mapped_joystick_buttons; void CreateControllerButtonMap(); }; } // namespace InputCommon::SDL