Add ability to set/get player index on SDL controllers

This commit is contained in:
Phillip Stephens 2022-02-08 01:40:50 -08:00
parent 5a41dab870
commit 5add26b42e
Signed by: Antidote
GPG Key ID: F8BEE4C83DACA60D
4 changed files with 22 additions and 3 deletions

4
Graphics/Cargo.lock generated
View File

@ -1443,7 +1443,7 @@ checksum = "96311ef4a16462c757bb6a39152c40f58f31cd2602a40fceb937e2bc34e6cbab"
[[package]]
name = "sdl2"
version = "0.35.2"
source = "git+https://github.com/encounter/rust-sdl2.git?rev=e282ef3acd7fcb4b2ba16863a7a0a7a8439f9335#e282ef3acd7fcb4b2ba16863a7a0a7a8439f9335"
source = "git+https://github.com/encounter/rust-sdl2.git?rev=f39d7a7549fd59bebb1fb42ec12973200bb3080b#f39d7a7549fd59bebb1fb42ec12973200bb3080b"
dependencies = [
"bitflags",
"lazy_static",
@ -1454,7 +1454,7 @@ dependencies = [
[[package]]
name = "sdl2-sys"
version = "0.35.2"
source = "git+https://github.com/encounter/rust-sdl2.git?rev=e282ef3acd7fcb4b2ba16863a7a0a7a8439f9335#e282ef3acd7fcb4b2ba16863a7a0a7a8439f9335"
source = "git+https://github.com/encounter/rust-sdl2.git?rev=f39d7a7549fd59bebb1fb42ec12973200bb3080b#f39d7a7549fd59bebb1fb42ec12973200bb3080b"
dependencies = [
"cfg-if 1.0.0",
"libc",

View File

@ -30,7 +30,7 @@ scopeguard = "1.1.0"
twox-hash = "1.6.2"
winit = "0.26.1"
# custom sdl2
sdl2 = { git = "https://github.com/encounter/rust-sdl2.git", rev = "e282ef3acd7fcb4b2ba16863a7a0a7a8439f9335", features = ["no-link", "hidapi"] }
sdl2 = { git = "https://github.com/encounter/rust-sdl2.git", rev = "f39d7a7549fd59bebb1fb42ec12973200bb3080b", features = ["no-link", "hidapi"] }
[dependencies.imgui]
git = "https://github.com/imgui-rs/imgui-rs"

View File

@ -183,6 +183,8 @@ mod ffi {
fn get_backend() -> Backend;
fn get_backend_string() -> &'static str;
fn set_fullscreen(v: bool);
fn get_controller_player_index(which: u32) -> i32;
fn set_controller_player_index(which: u32, index: i32);
}
}
impl From<Button> for ffi::ControllerButton {
@ -594,3 +596,19 @@ fn set_fullscreen(v: bool) {
None
});
}
fn get_controller_player_index(which: u32) -> i32 {
let has_controller = get_app().sdl_open_controllers.contains_key(&which);
let result = if has_controller {
get_app().sdl_open_controllers.get(&which).unwrap().player_index()
} else {
-1
};
result as i32
}
fn set_controller_player_index(which: u32, index: i32) {
if get_app().sdl_open_controllers.contains_key(&which) {
get_app().sdl_open_controllers.get(&which).unwrap().set_player_index(index);
}
}

View File

@ -2,6 +2,7 @@
#include "imgui.h"
#include "misc/cpp/imgui_stdlib.h"
#include <memory>
//#include <boo/IWindow.hpp>
//#include <boo/graphicsdev/IGraphicsDataFactory.hpp>