aurora: Implement Controller events

This commit is contained in:
Phillip Stephens 2022-02-19 06:36:03 -08:00
parent cbe268a0fc
commit 8863003855
Signed by: Antidote
GPG Key ID: F8BEE4C83DACA60D
2 changed files with 19 additions and 11 deletions

View File

@ -16,6 +16,7 @@ add_library(aurora STATIC
lib/aurora.cpp
lib/gpu.cpp
lib/imgui.cpp
lib/input.cpp
lib/dawn/BackendBinding.cpp
lib/gfx/common.cpp
lib/gfx/texture.cpp

View File

@ -1,7 +1,7 @@
#include <aurora/aurora.hpp>
#include "gfx/common.hpp"
#include "gpu.hpp"
#include "input.hpp"
#include "imgui.hpp"
#include <SDL.h>
@ -123,18 +123,27 @@ static bool poll_events() noexcept {
break;
}
case SDL_CONTROLLERDEVICEADDED: {
auto instance = input::add_controller(event.cdevice.which);
if (instance != -1) {
g_AppDelegate->onControllerAdded(instance);
}
break;
}
case SDL_CONTROLLERDEVICEREMOVED: {
input::remove_controller(event.cdevice.which);
break;
}
case SDL_CONTROLLERBUTTONUP:
case SDL_CONTROLLERBUTTONDOWN: {
break;
}
case SDL_CONTROLLERBUTTONUP: {
g_AppDelegate->onControllerButton(
event.cbutton.which, input::translate_button(static_cast<SDL_GameControllerButton>(event.cbutton.button)),
event.cbutton.state == SDL_PRESSED);
break;
}
case SDL_CONTROLLERAXISMOTION: {
g_AppDelegate->onControllerAxis(event.caxis.which,
input::translate_axis(static_cast<SDL_GameControllerAxis>(event.caxis.axis)),
event.caxis.value);
break;
}
case SDL_KEYDOWN: {
@ -335,18 +344,16 @@ void set_fullscreen(bool fullscreen) noexcept {
}
int32_t get_controller_player_index(uint32_t which) noexcept {
return -1; // TODO
return input::player_index(which); // TODO
}
void set_controller_player_index(uint32_t which, int32_t index) noexcept {
// TODO
}
void set_controller_player_index(uint32_t which, int32_t index) noexcept { input::set_player_index(which, index); }
bool is_controller_gamecube(uint32_t which) noexcept {
return true; // TODO
return input::is_gamecube(which); // TODO
}
std::string get_controller_name(uint32_t which) noexcept {
return ""; // TODO
std::string get_controller_name(uint32_t instance) noexcept {
return input::name(instance); // TODO
}
} // namespace aurora