mirror of https://github.com/mgba-emu/mgba.git
GUI: Start moving state out of locals
This commit is contained in:
parent
dd3b56eb7a
commit
7e74cba49a
|
@ -0,0 +1,27 @@
|
||||||
|
/* Copyright (c) 2013-2015 Jeffrey Pfau
|
||||||
|
*
|
||||||
|
* This Source Code Form is subject to the terms of the Mozilla Public
|
||||||
|
* License, v. 2.0. If a copy of the MPL was not distributed with this
|
||||||
|
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */
|
||||||
|
#include "gui.h"
|
||||||
|
|
||||||
|
void GUIPollInput(struct GUIParams* params, int* newInputOut, int* heldInput) {
|
||||||
|
int input = params->pollInput();
|
||||||
|
int newInput = 0;
|
||||||
|
for (int i = 0; i < GUI_INPUT_MAX; ++i) {
|
||||||
|
if (input & (1 << i)) {
|
||||||
|
++params->inputHistory[i];
|
||||||
|
} else {
|
||||||
|
params->inputHistory[i] = -1;
|
||||||
|
}
|
||||||
|
if (!params->inputHistory[i] || (params->inputHistory[i] >= 30 && !(params->inputHistory[i] % 6))) {
|
||||||
|
newInput |= (1 << i);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if (newInputOut) {
|
||||||
|
*newInputOut = newInput;
|
||||||
|
}
|
||||||
|
if (heldInput) {
|
||||||
|
*heldInput = input;
|
||||||
|
}
|
||||||
|
}
|
|
@ -32,6 +32,11 @@ struct GUIParams {
|
||||||
void (*drawStart)(void);
|
void (*drawStart)(void);
|
||||||
void (*drawEnd)(void);
|
void (*drawEnd)(void);
|
||||||
int (*pollInput)(void);
|
int (*pollInput)(void);
|
||||||
|
|
||||||
|
// State
|
||||||
|
int inputHistory[GUI_INPUT_MAX];
|
||||||
};
|
};
|
||||||
|
|
||||||
|
void GUIPollInput(struct GUIParams* params, int* newInput, int* heldInput);
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
|
|
@ -46,7 +46,7 @@ static int _strpcmp(const void* a, const void* b) {
|
||||||
return strcmp(*(const char**) a, *(const char**) b);
|
return strcmp(*(const char**) a, *(const char**) b);
|
||||||
}
|
}
|
||||||
|
|
||||||
static bool _refreshDirectory(const struct GUIParams* params, const char* currentPath, struct FileList* currentFiles, bool (*filter)(struct VFile*)) {
|
static bool _refreshDirectory(struct GUIParams* params, const char* currentPath, struct FileList* currentFiles, bool (*filter)(struct VFile*)) {
|
||||||
_cleanFiles(currentFiles);
|
_cleanFiles(currentFiles);
|
||||||
|
|
||||||
struct VDir* dir = VDirOpen(currentPath);
|
struct VDir* dir = VDirOpen(currentPath);
|
||||||
|
@ -59,7 +59,8 @@ static bool _refreshDirectory(const struct GUIParams* params, const char* curren
|
||||||
while ((de = dir->listNext(dir))) {
|
while ((de = dir->listNext(dir))) {
|
||||||
++i;
|
++i;
|
||||||
if (i % SCANNING_THRESHOLD == SCANNING_THRESHOLD - 1) {
|
if (i % SCANNING_THRESHOLD == SCANNING_THRESHOLD - 1) {
|
||||||
int input = params->pollInput();
|
int input = 0;
|
||||||
|
GUIPollInput(params, &input, 0);
|
||||||
if (input & (1 << GUI_INPUT_CANCEL)) {
|
if (input & (1 << GUI_INPUT_CANCEL)) {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
@ -90,7 +91,7 @@ static bool _refreshDirectory(const struct GUIParams* params, const char* curren
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
bool selectFile(const struct GUIParams* params, const char* basePath, char* outPath, char* currentPath, size_t outLen, bool (*filter)(struct VFile*)) {
|
bool selectFile(struct GUIParams* params, const char* basePath, char* outPath, char* currentPath, size_t outLen, bool (*filter)(struct VFile*)) {
|
||||||
if (!currentPath[0]) {
|
if (!currentPath[0]) {
|
||||||
strncpy(currentPath, basePath, outLen);
|
strncpy(currentPath, basePath, outLen);
|
||||||
}
|
}
|
||||||
|
@ -107,21 +108,9 @@ bool selectFile(const struct GUIParams* params, const char* basePath, char* outP
|
||||||
FileListInit(¤tFiles, 0);
|
FileListInit(¤tFiles, 0);
|
||||||
_refreshDirectory(params, currentPath, ¤tFiles, filter);
|
_refreshDirectory(params, currentPath, ¤tFiles, filter);
|
||||||
|
|
||||||
int inputHistory[GUI_INPUT_MAX] = { 0 };
|
|
||||||
|
|
||||||
while (true) {
|
while (true) {
|
||||||
int input = params->pollInput();
|
|
||||||
int newInput = 0;
|
int newInput = 0;
|
||||||
for (int i = 0; i < GUI_INPUT_MAX; ++i) {
|
GUIPollInput(params, &newInput, 0);
|
||||||
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) {
|
if (newInput & (1 << GUI_INPUT_UP) && fileIndex > 0) {
|
||||||
--fileIndex;
|
--fileIndex;
|
||||||
|
@ -167,21 +156,24 @@ bool selectFile(const struct GUIParams* params, const char* basePath, char* outP
|
||||||
}
|
}
|
||||||
snprintf(outPath, outLen, "%s%s%s", currentPath, sep, *FileListGetPointer(¤tFiles, fileIndex));
|
snprintf(outPath, outLen, "%s%s%s", currentPath, sep, *FileListGetPointer(¤tFiles, fileIndex));
|
||||||
if (!_refreshDirectory(params, outPath, ¤tFiles, filter)) {
|
if (!_refreshDirectory(params, outPath, ¤tFiles, filter)) {
|
||||||
struct VFile* vf = VFileOpen(currentPath, O_RDONLY);
|
struct VFile* vf = VFileOpen(outPath, O_RDONLY);
|
||||||
if (!vf) {
|
if (!vf) {
|
||||||
break;
|
if (!_refreshDirectory(params, currentPath, ¤tFiles, filter)) {
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
continue;
|
||||||
}
|
}
|
||||||
if (!filter || filter(vf)) {
|
if (!filter || filter(vf)) {
|
||||||
vf->close(vf);
|
vf->close(vf);
|
||||||
|
_cleanFiles(¤tFiles);
|
||||||
|
FileListDeinit(¤tFiles);
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
vf->close(vf);
|
vf->close(vf);
|
||||||
_upDirectory(currentPath);
|
break;
|
||||||
if (!_refreshDirectory(params, currentPath, ¤tFiles, filter)) {
|
} else {
|
||||||
break;
|
strncpy(currentPath, outPath, outLen);
|
||||||
}
|
|
||||||
}
|
}
|
||||||
strncpy(currentPath, outPath, outLen);
|
|
||||||
}
|
}
|
||||||
fileIndex = 0;
|
fileIndex = 0;
|
||||||
}
|
}
|
||||||
|
|
|
@ -10,6 +10,6 @@
|
||||||
|
|
||||||
struct VFile;
|
struct VFile;
|
||||||
|
|
||||||
bool selectFile(const struct GUIParams*, const char* basePath, char* outPath, char* currentPath, size_t outLen, bool (*filter)(struct VFile*));
|
bool selectFile(struct GUIParams*, const char* basePath, char* outPath, char* currentPath, size_t outLen, bool (*filter)(struct VFile*));
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
|
Loading…
Reference in New Issue