Skip to content
This repository has been archived by the owner on Dec 2, 2019. It is now read-only.

Keyboard Navigation / Gamepad #50

Open
andres-asm opened this issue Feb 15, 2016 · 13 comments
Open

Keyboard Navigation / Gamepad #50

andres-asm opened this issue Feb 15, 2016 · 13 comments

Comments

@andres-asm
Copy link

Hey
First of all, thanks a lot for this toolkit, it's great, I've been looking for a cross platform gui toolkit for a while and this fits the bill correctly and this one does.

I'm implementing zahnrad in RetroArch as a new menu driver (retroarch is a sort of multi system emulator and we have several menu drivers but we don't have a traditional mouse + kb driver).

Now I made a basic implementation on our menu driver and I'm wondering, is it possible to navigate the controls with keyboard only or a gamepad? maybe assign an ID to each control and have a selected property that highlights the selected widget? reacting to the click keyevent should be doable already but I'm not sure about the navigation.

@vurtun
Copy link
Owner

vurtun commented Feb 15, 2016

Hey and thanks for your feedback.

First of all, thanks a lot for this toolkit, it's great, I've been looking for a cross platform gui toolkit for a while and this fits the bill correctly and this one does.

Happy that it can be of use.

Now I made a basic implementation on our menu driver and I'm wondering, is it possible to navigate the controls with keyboard only or a gamepad? maybe assign an ID to each control and have a selected property that highlights the selected widget? reacting to the click keyevent should be doable already but I'm not sure about the navigation.

I previously thought about gamepad and keyboard only support. The problem is both require knowledge about the total layout (position, size) of a widgets to know what widget/window should be selected next by directional input. Another thing is like you already said the identification of the currently active widget. Some widget already do this like properties and edit widgets, but it would require an ID for every widget which would make the default library case more tedious to use, because every widget needs an unique name.

That being said, if the resulting UI is static and not complex it is possible to modify this library and create a custom version to get it to work.

A simple version would be to only add IDs to all the widgets you need and add an currently hot item to the internal window struct and do the selecting by having a ID hash table describing the widget layout with widget position and size and use that to control the mouse which then again controls widget behavior. This would be quite hacky but should work.

The second and way more complex idea is to add an additional optional layer of abstraction to this library to create a retain mode API (which would also allow things like an UI editor to place widgets). The problem is that imguis are a rather new concept and no one has ever tried something like adding a retain mode API on top and currently at this moment I do not have the time to try and find out if it is something doable or not. So it is not a solution that could be implemented in the near future, but is definitely on my long term todo list.

@vurtun
Copy link
Owner

vurtun commented Feb 22, 2016

To come back to this I took some time and wrote a test case and was able to get something to work. But I had to heavily bend the library to make it possible (the gif quality is a little bit shitty but hopefully is good enough):
out

So far what I learned is that it is possible to create a UI with zahnrad that works for gamepads as well as keyboard and mouse input. But it requires you to write your own custom made widgets that support both input methods and create additional special abstractions on top of zahnrad.
For example selection was achieved by having a growing ID for every widget and having a currently active widget variable. Selecting the next or previous widget in that case only requires incrementing or decrementing the active widget variable.
So for anyone who wants to use zahnrad with gamepad + mouse and keyboard support probably has to spend some time into converting and bending the library.

@andres-asm
Copy link
Author

wow, that's great thanks for the implementation idea

@dumblob
Copy link
Contributor

dumblob commented Feb 22, 2016

Great news, thank you.

I see yet another option. It's a bit ad-hoc, but should be easier to implement. Namely emulating keyboard and mouse with gamepad - i.e. writing a filter/translator of gamepad commands/signals into keyboard and mouse ones without changing Zahnrad and without writing any abstraction layer over Zahnrad. So the gamepad would then act as a second keyboard and a second mouse. I didn't try to implement this solution, so there might be (and I'm expecting that) a devil in a detail.

@vurtun
Copy link
Owner

vurtun commented Feb 23, 2016

You already can use gamepads as a mouse by using the analog stick and two gamepad buttons as "mouse" buttons (at least under Linux and X11) if it is that what you mean. But the actual reason why I came up with the growing ID is because I am currently extending zahnrad with something resembling glCallList, glNewList and glEndList in OpenGL but for widgets and need growing widget IDs. So far I am still figuring and testing things out, but I can say that it looks promising and could have a major impact on this library. As a side effect it would make things like gampad controlled UI a lot easier (but would still require custom widgets).

@andres-asm
Copy link
Author

Just wondering, do you have the code for that sample readily available? I'd like to play with it

@vurtun
Copy link
Owner

vurtun commented Mar 23, 2016

Yeah sure I upload it here: https://gist.github.com/vurtun/519801825b4ccfad6767. The test uses an older version of zahnrad so I don't know if it will just compile. Also everything is just written in user space to get something done so if there is something you need in the library to get something done just say. It is not perfect but hopefully helps a little bit.

@andres-asm
Copy link
Author

thanks a lot

@andres-asm
Copy link
Author

Hey works really well! I didn't really read it lol! I just copy pasted into my program and fixed compilation issues till it worked but it's really neat. I'll try to build on top of this

@BenJuan26
Copy link

@vurtun Do you still have the code for the gamepad/keyboard example? The linked gist no longer exists. It would be great to have for reference.

@kbirk
Copy link

kbirk commented Nov 6, 2018

@vurtun I am also very interested in a code sample of how to impl gamepad support. Do you still have the code to post?

@BenJuan26
Copy link

Or perhaps @fr500 you have a copy of that code floating around somewhere?

@andres-asm
Copy link
Author

I linked my code experiments here:

#349

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

No branches or pull requests

5 participants