mirror of
https://github.com/RetroDECK/ES-DE.git
synced 2024-11-29 09:35:39 +00:00
Fixed hats.
This commit is contained in:
parent
b90497d7fd
commit
3b44f51a9b
|
@ -9,6 +9,7 @@ SDL_Event* InputManager::lastEvent = NULL;
|
||||||
|
|
||||||
std::map<int, InputManager::InputButton> InputManager::joystickButtonMap, InputManager::joystickAxisPosMap, InputManager::joystickAxisNegMap;
|
std::map<int, InputManager::InputButton> InputManager::joystickButtonMap, InputManager::joystickAxisPosMap, InputManager::joystickAxisNegMap;
|
||||||
std::map<int, int> InputManager::axisState;
|
std::map<int, int> InputManager::axisState;
|
||||||
|
InputManager::InputButton InputManager::hatState = InputManager::UNKNOWN;
|
||||||
|
|
||||||
int InputManager::deadzone = 28000;
|
int InputManager::deadzone = 28000;
|
||||||
|
|
||||||
|
@ -85,17 +86,50 @@ void InputManager::processEvent(SDL_Event* event)
|
||||||
}else{
|
}else{
|
||||||
if(event->type == SDL_JOYHATMOTION)
|
if(event->type == SDL_JOYHATMOTION)
|
||||||
{
|
{
|
||||||
//no keyUp for hat movement yet, but this should be easily accomplished by
|
int hat = event->jhat.value;
|
||||||
//keeping the previous hat movement and checking if it moved from centered to anything else (keyDown) or back to centered (keyUp)
|
|
||||||
keyDown = true;
|
if(hat == 0) //centered
|
||||||
if(event->jhat.value & SDL_HAT_UP)
|
{
|
||||||
button = UP;
|
//we need to send a keyUp event for the last hat
|
||||||
if(event->jhat.value & SDL_HAT_DOWN)
|
//keyDown is already false
|
||||||
button = DOWN;
|
button = hatState;
|
||||||
if(event->jhat.value & SDL_HAT_LEFT)
|
}else{
|
||||||
|
keyDown = true;
|
||||||
|
}
|
||||||
|
|
||||||
|
if(hat & SDL_HAT_LEFT)
|
||||||
button = LEFT;
|
button = LEFT;
|
||||||
if(event->jhat.value & SDL_HAT_RIGHT)
|
if(hat & SDL_HAT_RIGHT)
|
||||||
button = RIGHT;
|
button = RIGHT;
|
||||||
|
|
||||||
|
if(hat & SDL_HAT_UP)
|
||||||
|
button = UP;
|
||||||
|
if(hat & SDL_HAT_DOWN)
|
||||||
|
button = DOWN;
|
||||||
|
|
||||||
|
if(button == hatState && keyDown)
|
||||||
|
{
|
||||||
|
//ignore this hat event since the user most likely just made it a diagonal (but it still is using the old direction)
|
||||||
|
button = UNKNOWN;
|
||||||
|
}else{
|
||||||
|
if(hatState != UNKNOWN && keyDown)
|
||||||
|
{
|
||||||
|
//this will occur if the user went down -> downLeft -> Left or similar
|
||||||
|
button = hatState;
|
||||||
|
keyDown = false;
|
||||||
|
hatState = UNKNOWN;
|
||||||
|
processEvent(event);
|
||||||
|
}else{
|
||||||
|
if(!keyDown)
|
||||||
|
hatState = UNKNOWN;
|
||||||
|
else
|
||||||
|
hatState = button;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if(button != UNKNOWN)
|
||||||
|
std::cout << "hat event, button: " << button << ", keyDown: " << keyDown << "\n";
|
||||||
|
|
||||||
}else{
|
}else{
|
||||||
if(event->type == SDL_JOYAXISMOTION)
|
if(event->type == SDL_JOYAXISMOTION)
|
||||||
{
|
{
|
||||||
|
|
|
@ -27,6 +27,7 @@ namespace InputManager {
|
||||||
extern std::map<int, InputButton> joystickButtonMap;
|
extern std::map<int, InputButton> joystickButtonMap;
|
||||||
extern std::map<int, InputButton> joystickAxisPosMap, joystickAxisNegMap;
|
extern std::map<int, InputButton> joystickAxisPosMap, joystickAxisNegMap;
|
||||||
extern std::map<int, int> axisState;
|
extern std::map<int, int> axisState;
|
||||||
|
extern InputButton hatState;
|
||||||
}
|
}
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
|
|
@ -76,6 +76,7 @@ int main()
|
||||||
{
|
{
|
||||||
switch(event.type)
|
switch(event.type)
|
||||||
{
|
{
|
||||||
|
case SDL_JOYHATMOTION:
|
||||||
case SDL_JOYAXISMOTION:
|
case SDL_JOYAXISMOTION:
|
||||||
case SDL_JOYBUTTONDOWN:
|
case SDL_JOYBUTTONDOWN:
|
||||||
case SDL_JOYBUTTONUP:
|
case SDL_JOYBUTTONUP:
|
||||||
|
|
Loading…
Reference in a new issue