12 changed files with 288 additions and 129 deletions
@ -1,22 +1,42 @@
|
||||
|
||||
#pragma once |
||||
|
||||
#include <vector> |
||||
|
||||
#include <SDL.h> |
||||
|
||||
#include "controls/controller_buttons.h" |
||||
|
||||
#ifndef USE_SDL1 |
||||
namespace dvl { |
||||
|
||||
ControllerButton GameControllerToControllerButton(const SDL_Event &event); |
||||
class GameController { |
||||
static std::vector<GameController> *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<GameController> &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 IsGameControllerButtonPressed(ControllerButton button); |
||||
bool IsPressed(ControllerButton button) const; |
||||
bool ProcessAxisMotion(const SDL_Event &event); |
||||
|
||||
bool ProcessGameControllerAxisMotion(const SDL_Event &event); |
||||
private: |
||||
SDL_GameControllerButton ToSdlGameControllerButton(ControllerButton button) const; |
||||
|
||||
SDL_GameController *CurrentGameController(); |
||||
SDL_GameController *sdl_game_controller_ = NULL; |
||||
SDL_JoystickID instance_id_ = -1; |
||||
|
||||
// Must be called after InitJoystick().
|
||||
void InitGameController(); |
||||
bool trigger_left_is_down_ = false; |
||||
bool trigger_right_is_down_ = false; |
||||
}; |
||||
|
||||
} // namespace dvl
|
||||
#endif |
||||
|
||||
@ -1,21 +1,44 @@
|
||||
#pragma once |
||||
|
||||
// Joystick mappings for SDL1 and additional buttons on SDL2.
|
||||
|
||||
#include <SDL.h> |
||||
#include "controls/controller_buttons.h" |
||||
|
||||
namespace dvl { |
||||
#include <vector> |
||||
|
||||
ControllerButton JoyButtonToControllerButton(const SDL_Event &event); |
||||
#include <SDL.h> |
||||
|
||||
bool IsJoystickButtonPressed(ControllerButton button); |
||||
#ifdef USE_SDL1 |
||||
#include "sdl2_to_1_2_backports.h" |
||||
#endif |
||||
|
||||
bool ProcessJoystickAxisMotion(const SDL_Event &event); |
||||
#include "controls/controller_buttons.h" |
||||
|
||||
SDL_Joystick *CurrentJoystick(); |
||||
int CurrentJoystickIndex(); |
||||
namespace dvl { |
||||
|
||||
void InitJoystick(); |
||||
class Joystick { |
||||
static std::vector<Joystick> *const joysticks_; |
||||
|
||||
public: |
||||
static void Add(int device_index); |
||||
static void Remove(SDL_JoystickID instance_id); |
||||
static Joystick *Get(SDL_JoystickID instance_id); |
||||
static Joystick *Get(const SDL_Event &event); |
||||
static const std::vector<Joystick> &All(); |
||||
static bool IsPressedOnAnyJoystick(ControllerButton button); |
||||
|
||||
ControllerButton ToControllerButton(const SDL_Event &event) const; |
||||
bool IsPressed(ControllerButton button) const; |
||||
bool ProcessAxisMotion(const SDL_Event &event); |
||||
|
||||
SDL_JoystickID instance_id() const |
||||
{ |
||||
return instance_id_; |
||||
} |
||||
|
||||
private: |
||||
int ToSdlJoyButton(ControllerButton button) const; |
||||
bool IsHatButtonPressed(ControllerButton button) const; |
||||
|
||||
SDL_Joystick *sdl_joystick_ = NULL; |
||||
SDL_JoystickID instance_id_ = -1; |
||||
}; |
||||
|
||||
} // namespace dvl
|
||||
|
||||
Loading…
Reference in new issue