all repos — mgba @ 32c5fd6d90508ce5291d400fee17044062e12a78

mGBA Game Boy Advance Emulator

mGUI: Add variants
Vicki Pfau vi@endrift.com
Sat, 29 Sep 2018 11:09:16 -0700
commit

32c5fd6d90508ce5291d400fee17044062e12a78

parent

927f8b0d8859fbfb8fe3f75e8ff8460ff74adf26

4 files changed, 110 insertions(+), 2 deletions(-)

jump to
M CHANGESCHANGES

@@ -108,8 +108,10 @@ - PSP2: Fix audio crackling when buffer is full

- 3DS: Fix unused screens not clearing (fixes mgba.io/i/1184) - GBA Video: Fix caching with background toggling (fixes mgba.io/i/1118) - Wii: Fix drawing caching regression (fixes mgba.io/i/1185) + - Switch: Fix incorrect mapping for fast forward cap Misc: - mGUI: Add SGB border configuration option + - mGUI: Add support for different settings types 0.7 beta 1: (2018-09-24) - Initial beta for 0.7
M include/mgba-util/gui/menu.hinclude/mgba-util/gui/menu.h

@@ -12,12 +12,37 @@ CXX_GUARD_START

#include <mgba-util/vector.h> +#define GUI_V_V (struct GUIVariant) { .type = GUI_VARIANT_VOID } +#define GUI_V_U(U) (struct GUIVariant) { .type = GUI_VARIANT_UNSIGNED, .v.u = (U) } +#define GUI_V_I(I) (struct GUIVariant) { .type = GUI_VARIANT_INT, .v.i = (I) } +#define GUI_V_F(F) (struct GUIVariant) { .type = GUI_VARIANT_FLOAT, .v.f = (F) } +#define GUI_V_S(S) (struct GUIVariant) { .type = GUI_VARIANT_STRING, .v.s = (S) } + +enum GUIVariantType { + GUI_VARIANT_VOID = 0, + GUI_VARIANT_UNSIGNED, + GUI_VARIANT_INT, + GUI_VARIANT_FLOAT, + GUI_VARIANT_STRING +}; + +struct GUIVariant { + enum GUIVariantType type; + union { + unsigned u; + int i; + float f; + const char* s; + } v; +}; + struct GUIMenu; struct GUIMenuItem { const char* title; void* data; unsigned state; const char* const* validStates; + const struct GUIVariant* stateMappings; unsigned nStates; struct GUIMenu* submenu; };
M src/feature/gui/gui-config.csrc/feature/gui/gui-config.c

@@ -162,7 +162,50 @@ item = GUIMenuItemListGetPointer(&menu.items, i);

if (!item->validStates || !item->data) { continue; } - mCoreConfigGetUIntValue(&runner->config, item->data, &item->state); + if (item->stateMappings) { + item->state = 0; + + size_t j; + for (j = 0; j < item->nStates; ++j) { + const struct GUIVariant* v = &item->stateMappings[j]; + struct GUIVariant test; + switch (v->type) { + case GUI_VARIANT_VOID: + if (!mCoreConfigGetValue(&runner->config, item->data)) { + item->state = j; + break; + } + break; + case GUI_VARIANT_UNSIGNED: + if (mCoreConfigGetUIntValue(&runner->config, item->data, &test.v.u) && test.v.u == v->v.u) { + item->state = j; + break; + } + break; + case GUI_VARIANT_INT: + if (mCoreConfigGetIntValue(&runner->config, item->data, &test.v.i) && test.v.i == v->v.i) { + item->state = j; + break; + } + break; + case GUI_VARIANT_FLOAT: + if (mCoreConfigGetFloatValue(&runner->config, item->data, &test.v.f) && fabsf(test.v.f - v->v.f) <= 1e-3f) { + item->state = j; + break; + } + break; + case GUI_VARIANT_STRING: + test.v.s = mCoreConfigGetValue(&runner->config, item->data); + if (test.v.s && strcmp(test.v.s, v->v.s) == 0) { + item->state = j; + break; + } + break; + } + } + } else { + mCoreConfigGetUIntValue(&runner->config, item->data, &item->state); + } } while (true) {

@@ -188,7 +231,28 @@ item = GUIMenuItemListGetPointer(&menu.items, i);

if (!item->validStates || !item->data) { continue; } - mCoreConfigSetUIntValue(&runner->config, item->data, item->state); + if (item->stateMappings) { + const struct GUIVariant* v = &item->stateMappings[item->state]; + switch (v->type) { + case GUI_VARIANT_VOID: + mCoreConfigSetValue(&runner->config, item->data, NULL); + break; + case GUI_VARIANT_UNSIGNED: + mCoreConfigSetUIntValue(&runner->config, item->data, v->v.u); + break; + case GUI_VARIANT_INT: + mCoreConfigSetUIntValue(&runner->config, item->data, v->v.i); + break; + case GUI_VARIANT_FLOAT: + mCoreConfigSetFloatValue(&runner->config, item->data, v->v.f); + break; + case GUI_VARIANT_STRING: + mCoreConfigSetValue(&runner->config, item->data, v->v.s); + break; + } + } else { + mCoreConfigSetUIntValue(&runner->config, item->data, item->state); + } } if (runner->keySources) { size_t i;
M src/platform/switch/main.csrc/platform/switch/main.c

@@ -528,6 +528,23 @@ "3", "4", "5", "6", "7", "8", "9",

"10", "11", "12", "13", "14", "15", "20", "30" }, + .stateMappings = (const struct GUIVariant[]) { + GUI_V_U(3), + GUI_V_U(4), + GUI_V_U(5), + GUI_V_U(6), + GUI_V_U(7), + GUI_V_U(8), + GUI_V_U(9), + GUI_V_U(10), + GUI_V_U(11), + GUI_V_U(12), + GUI_V_U(13), + GUI_V_U(14), + GUI_V_U(15), + GUI_V_U(20), + GUI_V_U(30), + }, .nStates = 15 }, },