Keyboard Shortcut Patch (can be used for tabbing)

Garthy

01-03-2011 00:27:01

Hi everyone. :)

I've written a work-in-progress keyboard shortcut patch that I'd like to share. It is designed to be applied against a subversion checkout of MyGUI from 23/1/10 (this is the main version I am using), but may work against other versions too. I don't expect it to work against the 3.0 series though.

Using this patch, you can create a shortcut key/modifier pair for any widget, and attach any delegate to it. If the particular key/modifier sequence is triggered whilst the focus (keyboard if present, mouse if not) is in a child, the delegate will be fired.

In simpler terms, and as an example, you can attach say a shortcut to Enter to the root of a dialog, and if Enter is pressed, you can fire off a delegate to act as if the "Ok" button was pressed.

I've used this code to implement both shortcuts and tabbing. Tabbing can be implemented by creating your own delegate to manage the process, which I've done in my own code. This code is external to MyGUI though, so I can't easily share it. However, the basic idea is to use the InputManager to get the current keyboard tab focus, and based on that, determine what the keyboard tab focus should be set to.

I could not figure out how to implement a proper "addShortcut" call, so the syntax is a bit more convoluted than I'd like. If someone can figure out how to create this call to make it easier to use, please let me know. :) The problem is my being unsure of the precise type of the third argument (the templating makes it more complex than you'd expect!).

A quick example of use:


widget->getShortcutDelegates(MyGUI::KeyCode::Tab, MyGUI::Modifier::Shift) = delegate;


My ideal would be this:


widget->addShortcut(MyGUI::KeyCode::Tab, MyGUI::Modifier::Shift, delegate);


but I couldn't quite figure it out.

This patch could possibly be built on in the future to allow shortcuts to be specified in the Layout Manager for certain buttons. It could also be used as a base to implement a proper tab ordering system. The patch does not do this at this time, and I am not planning to add these at present.

I don't want to stall the MyGUI 3.2.0 release at all, so I'm just passing this on as an external patch and I'm not specifically looking to get it in before the 3.2.0 release.

My plans for this patch, and some of the others I've worked on this last month or so, are presently as follows:

- Wait for the official MyGUI 3.2.0, or *maybe* the next RC- I'm not sure.

- Update my own project to use that version, along with the patches that I am using, getting rid of any that are no longer needed, or already integrated.

- Summarise and share the updated patches in this forum for other people to use.

I *think* this will be my last patch before the 3.2.0 release, but this depends on a number of things outside of my control.

I hope this patch is useful. :)

UPDATE: Bugfix- shift/ctrl modifiers weren't working properly.