-
Notifications
You must be signed in to change notification settings - Fork 174
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
ImGui-SFML keyboard and gamepad input support #51
Comments
I think it'll be fine. In addition to that, Steam hooks XInput on Windows in case of a SteamController / DS4
Can you provide 'sane' defaults? So users will only need to change the threshold if really needed |
Awesome.
Sure. I'll test on two gamepads and try to find the ones that are good enough at least for these two: I have Xbox 360 gamepad and Logitech F310. |
I have a wireless Xbox One controller I could test with. |
Neat. I'll notify you when the testing will be needed. :) |
Sounds fine to me in general. My concern about having the user bind the buttons is the following: As you noticed, axes are different on different controllers. When the user of your library binds for example the button 12 to ImGuiNavInput_Menu, because he's using a playstation controller, the enduser can only use a playstation controller. Or would you expect the user to detect the controller type and then do the mapping dependent on it? That's how I did it to support both XBox and Playstation controllers. (https://github.com/tizian/Cendric2/blob/feature/controller_support/src/Controller/GamepadController.cpp) You could also have different defaults for your ImGuiNavInput depending on different controller types and only have the user map them if they really need it. About setting the active gamepad: You could also default to the first connected one and poll events JoystickConnected and JoystickDisconnected to update it. Unless you want to have support for multiple controllers at once. |
ImGui-SFML won't try to detect the type of the gamepad. It'll just set Xbox 360 mapping by default and then the users will be able to change it if it's needed later (e.g. if they check for gamepad type and see that it's a PS4 one). As for the gamepadId... I'm now considering possible behaviours for gamepads:
Example: If user wants to use gamepad "B" instead of "A", they'll be able to set active gamepad id via a function call, e.g.
|
I'd strongly advise to go for 2., 1. will most likely cause confusion. |
Okay. It'll much easier to implement it as well, which is very good. :) |
Here's the branch |
See this for controls and more info on gamepads. ImGuiIO& io = ImGui::GetIO();
io.ConfigFlags |= ImGuiConfigFlags_NavEnableGamepad; and for keyboard navigation it'll be: ImGuiIO& io = ImGui::GetIO();
io.ConfigFlags |= ImGuiConfigFlags_NavEnableKeyboard; |
Working great over here! |
Looking good! Also tested keyboard and gamepad navigation with a non-wireless Xbox One and 360 controller. |
Merged into "master". Feels free to open new issues if any problems arise. |
UPD: It's here, check it out!
Hey everyone! So, ImGui 1.60 got released and keyboard/gamepad navigation looks really sweet. There are some things that I want to discuss before implementing them.
So, there's this enum:
So, most of the time Dpad is PovX/PovY, but sometimes the Y axis on dpad is inverted (on Linux).
Left stick is X/Y, I don't know if any gamepad has it differently. And other keys (A, B, X, Y, etc.) are totally different for all the gamepads.
Here's what I want to do - by default it'll map to XInput/Xbox 360 gamepad input, as it's the most popular controller for the PC. Is it a good idea? Or maybe not? Maybe users should do all the mapping themselves?
As for button bindings, I think I'll provide an interface like this:
Handling axes is a bit harder, probably users will need to set thresholds for D-pad and stick, so that only if axis is more than that value, we'll say that "Down/Left/Right/Up" is pressed for a stick or a D-pad.
And of course, users will need to tell ImGui-SFML which controller to use. Something like
ImGui::SFML::SetActiveGamepad(2); // gamepad with id 2
ImGui-SFML should probably then check for this joystick's disconnection event so that if it gets disconnected, it won't poll its state incorrectly. I think that if id won't be set, the gamepad support will be disabled.
There'll also be a function for a keyboard input enabling/disabling. Something like:
ImGui::SFML::SetKeyboardNavigationEnabled(true);
Okay, any other concerns? I think we'll probably will need a lot of them during the testing, but if you have something to say now - please do, it'll make the implementation easier.
The text was updated successfully, but these errors were encountered: