Core: Round out input API pre-revamp

This commit is contained in:
Vicki Pfau 2023-01-16 22:58:17 -08:00
parent 8c5940e540
commit 1584023f34
2 changed files with 35 additions and 0 deletions

View File

@ -55,6 +55,7 @@ int mInputMapKeyBits(const struct mInputMap* map, uint32_t type, uint32_t bits,
void mInputBindKey(struct mInputMap*, uint32_t type, int key, int input);
int mInputQueryBinding(const struct mInputMap*, uint32_t type, int input);
void mInputUnbindKey(struct mInputMap*, uint32_t type, int input);
void mInputUnbindAllKeys(struct mInputMap*, uint32_t type);
int mInputMapAxis(const struct mInputMap*, uint32_t type, int axis, int value);
int mInputClearAxis(const struct mInputMap*, uint32_t type, int axis, int keys);
@ -69,6 +70,7 @@ void mInputBindHat(struct mInputMap*, uint32_t type, int id, const struct mInput
bool mInputQueryHat(const struct mInputMap*, uint32_t type, int id, struct mInputHatBindings* bindings);
void mInputUnbindHat(struct mInputMap*, uint32_t type, int id);
void mInputUnbindAllHats(struct mInputMap*, uint32_t type);
void mInputEnumerateHats(const struct mInputMap*, uint32_t type, void (handler(int hat, const struct mInputHatBindings* bindings, void* user)), void* user);
bool mInputMapLoad(struct mInputMap*, uint32_t type, const struct Configuration*);
void mInputMapSave(const struct mInputMap*, uint32_t type, struct Configuration*);

View File

@ -38,6 +38,11 @@ struct mInputAxisEnumerate {
void* user;
};
struct mInputHatEnumerate {
void (*handler)(int axis, const struct mInputHatBindings* bindings, void* user);
void* user;
};
static void _makeSectionName(const char* platform, char* sectionName, size_t len, uint32_t type) {
snprintf(sectionName, len, "%s.input.%c%c%c%c", platform, type >> 24, type >> 16, type >> 8, type);
sectionName[len - 1] = '\0';
@ -304,6 +309,12 @@ void _unbindAxis(uint32_t axis, void* dp, void* user) {
}
}
void _enumerateHat(uint32_t axis, void* dp, void* ep) {
struct mInputHatEnumerate* enumUser = ep;
const struct mInputHatBindings* description = dp;
enumUser->handler(axis, description, enumUser->user);
}
static bool _loadAll(struct mInputMap* map, uint32_t type, const char* sectionName, const struct Configuration* config) {
if (!ConfigurationHasSection(config, sectionName)) {
return false;
@ -415,6 +426,16 @@ void mInputUnbindKey(struct mInputMap* map, uint32_t type, int input) {
}
}
void mInputUnbindAllKeys(struct mInputMap* map, uint32_t type) {
struct mInputMapImpl* impl = _lookupMap(map, type);
if (impl) {
size_t i;
for (i = 0; i < map->info->nKeys; ++i) {
impl->map[i] = -1;
}
}
}
int mInputQueryBinding(const struct mInputMap* map, uint32_t type, int input) {
if (input < 0 || (size_t) input >= map->info->nKeys) {
return -1;
@ -578,6 +599,18 @@ void mInputUnbindAllHats(struct mInputMap* map, uint32_t type) {
}
}
void mInputEnumerateHats(const struct mInputMap* map, uint32_t type, void (handler(int hat, const struct mInputHatBindings* bindings, void* user)), void* user) {
const struct mInputMapImpl* impl = _lookupMapConst(map, type);
if (!impl) {
return;
}
struct mInputHatEnumerate enumUser = {
handler,
user
};
TableEnumerate(&impl->axes, _enumerateHat, &enumUser);
}
bool mInputMapLoad(struct mInputMap* map, uint32_t type, const struct Configuration* config) {
char sectionName[SECTION_NAME_MAX];
_makeSectionName(map->info->platformName, sectionName, SECTION_NAME_MAX, type);