Files
devilutionX/SourceX/controls/controller.cpp
T
Anders Jenbo 45844b71ae Make controls more responsive
- Fix double events
- Fix ignored events
- Allow moving diagonal in the inventory
- Fix mouse wobbling in inventory when scalling
- Make controler actions cursor independants
- Make sure secoundery and primery key doesn't fire each others events
- Highlight both primary and secondary target
- Automatic switch between controller and keyboard+mouse
- Allow the user to change facing direction when blocked
- Make code event based instead of relying on time outs
2019-11-06 02:13:07 +01:00

63 lines
1.3 KiB
C++

#include "controls/controller.h"
#include "controls/devices/kbcontroller.h"
#include "controls/devices/joystick.h"
#include "controls/devices/game_controller.h"
namespace dvl {
ControllerButtonEvent ToControllerButtonEvent(const SDL_Event &event)
{
ControllerButtonEvent result{ ControllerButton::NONE, false };
switch (event.type) {
#ifndef USE_SDL1
case SDL_CONTROLLERBUTTONUP:
#endif
case SDL_JOYBUTTONUP:
case SDL_KEYUP:
result.up = true;
break;
default:
break;
}
#if HAS_KBCTRL == 1
result.button = KbCtrlToControllerButton(event);
if (result.button != ControllerButton::NONE)
return result;
#endif
#ifndef USE_SDL1
result.button = GameControllerToControllerButton(event);
if (result.button != ControllerButton::NONE)
return result;
#endif
result.button = JoyButtonToControllerButton(event);
return result;
}
bool IsControllerButtonPressed(ControllerButton button)
{
bool result = false;
#ifndef USE_SDL1
result = result || IsGameControllerButtonPressed(button);
#endif
#if HAS_KBCTRL == 1
result = result || IsKbCtrlButtonPressed(button);
#endif
result = result || IsJoystickButtonPressed(button);
return result;
}
void InitController()
{
InitJoystick();
#ifndef USE_SDL1
InitGameController();
#endif
}
} // namespace dvl