diff --git a/aurora/CMakeLists.txt b/aurora/CMakeLists.txt index 08bc23450..09386ac34 100644 --- a/aurora/CMakeLists.txt +++ b/aurora/CMakeLists.txt @@ -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 diff --git a/aurora/lib/aurora.cpp b/aurora/lib/aurora.cpp index 3f57a4c80..3605598ef 100644 --- a/aurora/lib/aurora.cpp +++ b/aurora/lib/aurora.cpp @@ -1,7 +1,7 @@ #include - #include "gfx/common.hpp" #include "gpu.hpp" +#include "input.hpp" #include "imgui.hpp" #include @@ -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(event.cbutton.button)), + event.cbutton.state == SDL_PRESSED); break; } case SDL_CONTROLLERAXISMOTION: { + g_AppDelegate->onControllerAxis(event.caxis.which, + input::translate_axis(static_cast(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