GUI: Add key repeat
Jeffrey Pfau jeffrey@endrift.com
Mon, 24 Aug 2015 22:11:12 -0700
2 files changed,
15 insertions(+),
3 deletions(-)
M
src/util/gui.h
→
src/util/gui.h
@@ -20,6 +20,8 @@ GUI_INPUT_UP,
GUI_INPUT_DOWN, GUI_INPUT_LEFT, GUI_INPUT_RIGHT, + + GUI_INPUT_MAX }; struct GUIParams {
M
src/util/gui/file-select.c
→
src/util/gui/file-select.c
@@ -58,7 +58,6 @@
bool selectFile(const struct GUIParams* params, const char* basePath, char* outPath, size_t outLen, const char* suffix) { char currentPath[256]; strncpy(currentPath, basePath, sizeof(currentPath)); - int oldInput = -1; size_t fileIndex = 0; size_t start = 0;@@ -66,10 +65,21 @@ struct FileList currentFiles;
FileListInit(¤tFiles, 0); _refreshDirectory(currentPath, ¤tFiles); + int inputHistory[GUI_INPUT_MAX] = { 0 }; + while (true) { int input = params->pollInput(); - int newInput = input & (oldInput ^ input); - oldInput = input; + int newInput = 0; + for (int i = 0; i < GUI_INPUT_MAX; ++i) { + if (input & (1 << i)) { + ++inputHistory[i]; + } else { + inputHistory[i] = -1; + } + if (!inputHistory[i] || (inputHistory[i] >= 30 && !(inputHistory[i] % 6))) { + newInput |= (1 << i); + } + } if (newInput & (1 << GUI_INPUT_UP) && fileIndex > 0) { --fileIndex;