input: add keyboard and mouse input flags#217
Conversation
|
Add a demo case for this. |
| /** | ||
| * Set the keyboard output pointer. Called when a key is captured with NK_CONSOLE_INPUT_FLAG_KEYBOARD. | ||
| */ | ||
| NK_API void nk_console_input_set_keyboard_out(nk_console* widget, nk_rune* out_key); |
There was a problem hiding this comment.
Add a nk_console_input_set_gamepad_out()... Should take all int gamepad_number, int* out_gamepad_number, enum nk_gamepad_button* out_gamepad_button.
| * Use a bitwise OR of nk_console_input_flags values. | ||
| * Defaults to NK_CONSOLE_INPUT_FLAG_GAMEPAD. | ||
| */ | ||
| NK_API void nk_console_input_set_flags(nk_console* widget, nk_uint flags); |
There was a problem hiding this comment.
Looking to add some helper constructors...
- Add
nk_console_input_gamepad()that just calls nk_console_input() - Add
nk_console_input_key()that sets up the widget just for keyboard input - Add
nk_console_input_mouse()that sets up the widget just for mouse input
| NK_CONSOLE_INPUT_FLAG_GAMEPAD = (1 << 0), | ||
| NK_CONSOLE_INPUT_FLAG_KEYBOARD = (1 << 1), | ||
| NK_CONSOLE_INPUT_FLAG_MOUSE = (1 << 2), |
There was a problem hiding this comment.
Could use NK_FLAG() for NK_CONSOLE_INPUT_FLAG_GAMEPAD NK_CONSOLE_INPUT_FLAG_KEYBOARD and NK_CONSOLE_INPUT_FLAG_MOUSE
| ((nk_console_input_data*)widget->data)->out_key = out_key; | ||
| } | ||
|
|
||
| NK_API void nk_console_input_set_mouse_out(nk_console* widget, enum nk_buttons* out_mouse_button) { |
There was a problem hiding this comment.
Add a helper methods that will check whether or not the selected output is a key, mouse button, or gamepad input devive.
nk_console_input_is_mouse()
nk_console_input_is_key()
nk_console_input_is_gamepad()
| if (nk_input_is_mouse_released(&console->ctx->input, (enum nk_buttons)mi)) { | ||
| if (data->out_mouse_button != NULL) *data->out_mouse_button = (enum nk_buttons)mi; | ||
| nk_console_trigger_event(input, NK_CONSOLE_EVENT_CHANGED); | ||
| finished = nk_true; |
There was a problem hiding this comment.
Make sure the repesented key is presenteed nicely. Copy the nk_console_key_name() function over to nk_console_input_key_name(), and use it when rendering the widget.
| data->out_gamepad_button = out_gamepad_button; | ||
| } | ||
|
|
||
| NK_API nk_bool nk_console_input_is_gamepad(nk_console* widget) { |
There was a problem hiding this comment.
The nk_console_input_is_gamepad and related functions return true wifbthe selected out variables were found to be the related input device.
| } | ||
|
|
||
| NK_API nk_console* nk_console_input_gamepad(nk_console* parent, const char* label, int gamepad_number, int* out_gamepad_number, enum nk_gamepad_button* out_gamepad_button) { | ||
| return nk_console_input(parent, label, gamepad_number, out_gamepad_number, out_gamepad_button); |
There was a problem hiding this comment.
When a gamepad button, mouse button, or keyboard key are pressed, change the other out variables to NULL so that it's known which input device is chosen.
| NK_API nk_console* nk_console_input_key(nk_console* parent, const char* label, nk_rune* out_key) { | ||
| nk_console* widget = nk_console_input(parent, label, -1, NULL, NULL); | ||
| if (widget == NULL) return NULL; | ||
| nk_console_input_set_keyboard_out(widget, out_key); |
There was a problem hiding this comment.
Rename set_keyboard_out to set_key_out
| for (ki = NK_KEY_NONE + 1; ki < NK_KEY_MAX; ki++) { | ||
| if (nk_input_is_key_released(&console->ctx->input, (enum nk_keys)ki)) { | ||
| if (data->out_key != NULL) *data->out_key = (nk_rune)ki; | ||
| data->out_gamepad_button = NULL; |
There was a problem hiding this comment.
When clearing out the out_gamepad_button value, we should also clear out the gamepad_num
This reverts commit 043222a.
Extends nk_console_input with nk_console_input_flags (NK_CONSOLE_INPUT_FLAG_GAMEPAD, _KEYBOARD, _MOUSE). New API: nk_console_input_set_flags(), nk_console_input_get_flags(), nk_console_input_set_keyboard_out(), nk_console_input_set_mouse_out(). The prompt text updates dynamically to reflect active sources; defaults to gamepad-only for backward compatibility. Fixes #16