Add basic infrastructure for JoyStick support

This commit is contained in:
Lorenzooone 2024-04-26 13:00:50 +02:00
parent 3a63c04f7f
commit 54ef5f52fd
2 changed files with 15 additions and 2 deletions

View File

@ -44,11 +44,15 @@ struct PACKED VideoOutputData {
#pragma pack(pop) #pragma pack(pop)
struct SFEvent { struct SFEvent {
SFEvent(sf::Event::EventType type, sf::Keyboard::Key code, uint32_t unicode) : type(type), code(code), unicode(unicode) {} SFEvent(sf::Event::EventType type, sf::Keyboard::Key code, uint32_t unicode, uint32_t joystickId, uint32_t button, sf::Joystick::Axis axis, float position) : type(type), code(code), unicode(unicode), joystickId(joystickId), button(button), axis(axis), position(position) {}
sf::Event::EventType type; sf::Event::EventType type;
sf::Keyboard::Key code; sf::Keyboard::Key code;
uint32_t unicode; uint32_t unicode;
uint32_t joystickId;
uint32_t button;
sf::Joystick::Axis axis;
float position;
}; };
struct out_rect_data { struct out_rect_data {

View File

@ -312,6 +312,10 @@ void WindowScreen::poll() {
break; break;
} }
break;
case sf::Event::JoystickButtonPressed:
break;
case sf::Event::JoystickMoved:
break; break;
default: default:
break; break;
@ -508,7 +512,12 @@ void WindowScreen::poll_window() {
sf::Event event; sf::Event event;
this->events_access->lock(); this->events_access->lock();
while(this->m_win.pollEvent(event)) { while(this->m_win.pollEvent(event)) {
events_queue.emplace(event.type, event.key.code, event.text.unicode); int joystickId = event.joystickConnect.joystickId;
if(event.type == sf::Event::JoystickButtonPressed)
joystickId = event.joystickButton.joystickId;
else if(event.type == sf::Event::JoystickMoved)
joystickId = event.joystickMove.joystickId;
events_queue.emplace(event.type, event.key.code, event.text.unicode, joystickId, event.joystickButton.button, event.joystickMove.axis, event.joystickMove.position);
} }
this->events_access->unlock(); this->events_access->unlock();
} }