From a6b2d66e1e5aa873b9bb4b13e311da93b24ae79b Mon Sep 17 00:00:00 2001 From: Phillip Stephens Date: Wed, 9 Feb 2022 00:54:53 -0800 Subject: [PATCH] Input: Add onControllerAdded/Removed callbacks and also display the controller name in the input viewer --- Graphics/include/aurora.hpp | 6 ++- Graphics/include/lib.hpp | 6 ++- Graphics/lib.cpp | 14 ++++-- Graphics/src/cxxbridge.rs | 11 ++++- Graphics/src/sdl.rs | 19 ++++++-- Runtime/CMain.cpp | 26 +++++++++++ Runtime/ImGuiConsole.cpp | 21 ++++++++- Runtime/ImGuiConsole.hpp | 2 + Runtime/Input/CFinalInput.cpp | 28 +++++++----- Runtime/Input/CFinalInput.hpp | 7 ++- Runtime/Input/CInputGenerator.cpp | 76 +++++++++++++++++++++---------- Runtime/Input/CInputGenerator.hpp | 18 ++++---- 12 files changed, 175 insertions(+), 59 deletions(-) diff --git a/Graphics/include/aurora.hpp b/Graphics/include/aurora.hpp index 491e03dc2..711942b75 100644 --- a/Graphics/include/aurora.hpp +++ b/Graphics/include/aurora.hpp @@ -36,8 +36,10 @@ struct AppDelegate { virtual void onSpecialKeyUp(SpecialKey key) noexcept = 0; // Controller - virtual void onControllerButton(uint32_t idx, ControllerButton button, bool pressed) noexcept = 0; - virtual void onControllerAxis(uint32_t idx, ControllerAxis axis, int16_t value) noexcept = 0; + virtual void onControllerAdded(uint32_t which) noexcept = 0; + virtual void onControllerRemoved(uint32_t which) noexcept = 0; + virtual void onControllerButton(uint32_t which, ControllerButton button, bool pressed) noexcept = 0; + virtual void onControllerAxis(uint32_t which, ControllerAxis axis, int16_t value) noexcept = 0; // virtual void resized([[maybe_unused]] const WindowSize& rect, [[maybe_unused]] bool sync) noexcept {} // virtual void mouseDown([[maybe_unused]] const SWindowCoord& coord, [[maybe_unused]] EMouseButton button, diff --git a/Graphics/include/lib.hpp b/Graphics/include/lib.hpp index f6946dfb0..f55839049 100644 --- a/Graphics/include/lib.hpp +++ b/Graphics/include/lib.hpp @@ -15,6 +15,8 @@ void App_onCharKeyUp(AppDelegate& cb, uint8_t code) noexcept; void App_onSpecialKeyDown(AppDelegate& cb, SpecialKey key, bool isRepeat) noexcept; void App_onSpecialKeyUp(AppDelegate& cb, SpecialKey key) noexcept; // Controller -void App_onControllerButton(AppDelegate& cb, uint32_t idx, ControllerButton button, bool pressed) noexcept; -void App_onControllerAxis(AppDelegate& cb, uint32_t idx, ControllerAxis axis, int16_t value) noexcept; +void App_onControllerAdded(AppDelegate& cb, uint32_t which) noexcept; +void App_onControllerRemoved(AppDelegate& cb, uint32_t which) noexcept; +void App_onControllerButton(AppDelegate& cb, uint32_t which, ControllerButton button, bool pressed) noexcept; +void App_onControllerAxis(AppDelegate& cb, uint32_t which, ControllerAxis axis, int16_t value) noexcept; } // namespace aurora diff --git a/Graphics/lib.cpp b/Graphics/lib.cpp index 3ec44a7c4..fa60f5864 100644 --- a/Graphics/lib.cpp +++ b/Graphics/lib.cpp @@ -28,10 +28,16 @@ void App_onSpecialKeyUp(AppDelegate& cb, SpecialKey key) noexcept { } // Controller -void App_onControllerButton(AppDelegate& cb, uint32_t idx, ControllerButton button, bool pressed) noexcept { - cb.onControllerButton(idx, button, pressed); +void App_onControllerAdded(AppDelegate& cb, uint32_t which) noexcept { + cb.onControllerAdded(which); } -void App_onControllerAxis(AppDelegate& cb, uint32_t idx, ControllerAxis axis, int16_t value) noexcept { - cb.onControllerAxis(idx, axis, value); +void App_onControllerRemoved(AppDelegate& cb, uint32_t which) noexcept { + cb.onControllerRemoved(which); +} +void App_onControllerButton(AppDelegate& cb, uint32_t which, ControllerButton button, bool pressed) noexcept { + cb.onControllerButton(which, button, pressed); +} +void App_onControllerAxis(AppDelegate& cb, uint32_t which, ControllerAxis axis, int16_t value) noexcept { + cb.onControllerAxis(which, axis, value); } } // namespace aurora diff --git a/Graphics/src/cxxbridge.rs b/Graphics/src/cxxbridge.rs index 6ac100252..261cc3a74 100644 --- a/Graphics/src/cxxbridge.rs +++ b/Graphics/src/cxxbridge.rs @@ -3,7 +3,12 @@ use sdl2::controller::{Axis, Button}; use crate::{ app_run, get_args, get_backend, get_backend_string, get_dxt_compression_supported, get_window_size, - sdl::{get_controller_player_index, set_controller_player_index}, + sdl::{ + get_controller_player_index, + set_controller_player_index, + is_controller_gamecube, + get_controller_name + }, set_fullscreen, set_window_title, App, WindowContext, }; @@ -33,6 +38,8 @@ pub(crate) mod ffi { ); pub(crate) fn App_onSpecialKeyUp(cb: Pin<&mut AppDelegate>, key: SpecialKey); // Controller + pub(crate) fn App_onControllerAdded(cb: Pin<&mut AppDelegate>, which: u32); + pub(crate) fn App_onControllerRemoved(cb: Pin<&mut AppDelegate>, which: u32); pub(crate) fn App_onControllerButton( cb: Pin<&mut AppDelegate>, idx: u32, @@ -162,6 +169,8 @@ pub(crate) mod ffi { fn set_fullscreen(v: bool); fn get_controller_player_index(which: u32) -> i32; fn set_controller_player_index(which: u32, index: i32); + fn is_controller_gamecube(which: u32) -> bool; + fn get_controller_name(which: u32) -> String; } } impl From