all repos — mgba @ 6a5348121aa062d51f54765f2d3c0d24e2e4459c

mGBA Game Boy Advance Emulator

GUI: Add key repeat
Jeffrey Pfau jeffrey@endrift.com
Mon, 24 Aug 2015 22:11:12 -0700
commit

6a5348121aa062d51f54765f2d3c0d24e2e4459c

parent

ea12461c5ba577c7056ffb9348098d3f0f592822

2 files changed, 15 insertions(+), 3 deletions(-)

jump to
M src/util/gui.hsrc/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.csrc/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(&currentFiles, 0); _refreshDirectory(currentPath, &currentFiles); + 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;