GUI: Add key repeat

This commit is contained in:
Jeffrey Pfau 2015-08-24 22:11:12 -07:00
parent 86c7b478e2
commit 0cc32d98fb
2 changed files with 15 additions and 3 deletions

View File

@ -20,6 +20,8 @@ enum GUIInput {
GUI_INPUT_DOWN,
GUI_INPUT_LEFT,
GUI_INPUT_RIGHT,
GUI_INPUT_MAX
};
struct GUIParams {

View File

@ -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(&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;