From 0cc32d98fb2dee03f519fa59c059c55a2d9fbb5a Mon Sep 17 00:00:00 2001 From: Jeffrey Pfau Date: Mon, 24 Aug 2015 22:11:12 -0700 Subject: [PATCH] GUI: Add key repeat --- src/util/gui.h | 2 ++ src/util/gui/file-select.c | 16 +++++++++++++--- 2 files changed, 15 insertions(+), 3 deletions(-) diff --git a/src/util/gui.h b/src/util/gui.h index d8b2bb058..f2d267655 100644 --- a/src/util/gui.h +++ b/src/util/gui.h @@ -20,6 +20,8 @@ enum GUIInput { GUI_INPUT_DOWN, GUI_INPUT_LEFT, GUI_INPUT_RIGHT, + + GUI_INPUT_MAX }; struct GUIParams { diff --git a/src/util/gui/file-select.c b/src/util/gui/file-select.c index 8e40372e0..0f25d6db5 100644 --- a/src/util/gui/file-select.c +++ b/src/util/gui/file-select.c @@ -58,7 +58,6 @@ static bool _refreshDirectory(const char* currentPath, struct FileList* currentF 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 @@ bool selectFile(const struct GUIParams* params, const char* basePath, char* outP 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;