mirror of
https://github.com/wiiu-env/WiiUPluginSystem.git
synced 2026-09-09 18:45:56 -05:00
ConfigAPI: Some more changes, added C++ Wrapper
This commit is contained in:
@@ -2,43 +2,36 @@
|
||||
#include <cstdio>
|
||||
#include <cstdlib>
|
||||
#include <cstring>
|
||||
#include <wups.h>
|
||||
#include <wups/config.h>
|
||||
|
||||
int32_t WUPSConfigItemBoolean_getCurrentValueDisplay(void *context, char *out_buf, int32_t out_size) {
|
||||
static void WUPSConfigItemBoolean_onCloseCallback(void *context) {
|
||||
auto *item = (ConfigItemBoolean *) context;
|
||||
if (item->valueAtCreation != item->value && item->valueChangedCallback != nullptr) {
|
||||
((BooleanValueChangedCallback) (item->valueChangedCallback))(item, item->value);
|
||||
}
|
||||
}
|
||||
|
||||
static inline void toggleValue(ConfigItemBoolean *item) {
|
||||
item->value = !item->value;
|
||||
}
|
||||
|
||||
static void WUPSConfigItemBoolean_onInput(void *context, WUPSConfigSimplePadData input) {
|
||||
auto *item = (ConfigItemBoolean *) context;
|
||||
if ((input.buttons_d & WUPS_CONFIG_BUTTON_A) == WUPS_CONFIG_BUTTON_A) {
|
||||
toggleValue(item);
|
||||
} else if (input.buttons_d & WUPS_CONFIG_BUTTON_LEFT && !item->value) {
|
||||
toggleValue(item);
|
||||
} else if ((input.buttons_d & WUPS_CONFIG_BUTTON_RIGHT) && item->value) {
|
||||
toggleValue(item);
|
||||
}
|
||||
}
|
||||
static int32_t WUPSConfigItemBoolean_getCurrentValueDisplay(void *context, char *out_buf, int32_t out_size) {
|
||||
auto *item = (ConfigItemBoolean *) context;
|
||||
snprintf(out_buf, out_size, " %s", item->value ? item->trueValue : item->falseValue);
|
||||
return 0;
|
||||
}
|
||||
|
||||
void toggleValue(ConfigItemBoolean *item) {
|
||||
item->value = !item->value;
|
||||
}
|
||||
|
||||
bool WUPSConfigItemBoolean_callCallback(void *context) {
|
||||
auto *item = (ConfigItemBoolean *) context;
|
||||
if (item->callback != nullptr) {
|
||||
((BooleanValueChangedCallback) (item->callback))(item, item->value);
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
void WUPSConfigItemBoolean_onButtonPressed(void *context, WUPSConfigButtons buttons) {
|
||||
auto *item = (ConfigItemBoolean *) context;
|
||||
if ((buttons & WUPS_CONFIG_BUTTON_A) == WUPS_CONFIG_BUTTON_A) {
|
||||
toggleValue(item);
|
||||
} else if (buttons & WUPS_CONFIG_BUTTON_LEFT && !item->value) {
|
||||
toggleValue(item);
|
||||
} else if ((buttons & WUPS_CONFIG_BUTTON_RIGHT) && item->value) {
|
||||
toggleValue(item);
|
||||
}
|
||||
}
|
||||
|
||||
bool WUPSConfigItemBoolean_isMovementAllowed(void *context) {
|
||||
return true;
|
||||
}
|
||||
|
||||
int32_t WUPSConfigItemBoolean_getCurrentValueSelectedDisplay(void *context, char *out_buf, int32_t out_size) {
|
||||
static int32_t WUPSConfigItemBoolean_getCurrentValueSelectedDisplay(void *context, char *out_buf, int32_t out_size) {
|
||||
auto *item = (ConfigItemBoolean *) context;
|
||||
if (item->value) {
|
||||
snprintf(out_buf, out_size, " %s >", item->trueValue);
|
||||
@@ -48,77 +41,114 @@ int32_t WUPSConfigItemBoolean_getCurrentValueSelectedDisplay(void *context, char
|
||||
return 0;
|
||||
}
|
||||
|
||||
void WUPSConfigItemBoolean_restoreDefault(void *context) {
|
||||
static void WUPSConfigItemBoolean_restoreDefault(void *context) {
|
||||
auto *item = (ConfigItemBoolean *) context;
|
||||
item->value = item->defaultValue;
|
||||
}
|
||||
|
||||
void WUPSConfigItemBoolean_onSelected(void *context, bool isSelected) {
|
||||
}
|
||||
|
||||
static void WUPSConfigItemBoolean_Cleanup(ConfigItemBoolean *item) {
|
||||
if (!item) {
|
||||
return;
|
||||
}
|
||||
free(item->configId);
|
||||
free((void *) item->identifier);
|
||||
free(item);
|
||||
}
|
||||
|
||||
void WUPSConfigItemBoolean_onDelete(void *context) {
|
||||
static void WUPSConfigItemBoolean_onDelete(void *context) {
|
||||
WUPSConfigItemBoolean_Cleanup((ConfigItemBoolean *) context);
|
||||
}
|
||||
|
||||
extern "C" bool
|
||||
WUPSConfigItemBoolean_AddToCategoryEx(WUPSConfigCategoryHandle cat, const char *configId, const char *displayName, bool defaultValue, BooleanValueChangedCallback callback, const char *trueValue,
|
||||
const char *falseValue) {
|
||||
if (cat == nullptr) {
|
||||
return false;
|
||||
extern "C" WUPSConfigAPIStatus
|
||||
WUPSConfigItemBoolean_CreateEx(const char *identifier,
|
||||
const char *displayName,
|
||||
bool defaultValue,
|
||||
bool currentValue,
|
||||
BooleanValueChangedCallback callback,
|
||||
const char *trueValue,
|
||||
const char *falseValue,
|
||||
WUPSConfigItemHandle *outHandle) {
|
||||
if (outHandle == nullptr) {
|
||||
return WUPSCONFIG_API_RESULT_INVALID_ARGUMENT;
|
||||
}
|
||||
auto *item = (ConfigItemBoolean *) malloc(sizeof(ConfigItemBoolean));
|
||||
if (item == nullptr) {
|
||||
return false;
|
||||
return WUPSCONFIG_API_RESULT_OUT_OF_MEMORY;
|
||||
}
|
||||
|
||||
if (configId != nullptr) {
|
||||
item->configId = strdup(configId);
|
||||
if (identifier != nullptr) {
|
||||
item->identifier = strdup(identifier);
|
||||
} else {
|
||||
item->configId = nullptr;
|
||||
item->identifier = nullptr;
|
||||
}
|
||||
|
||||
item->defaultValue = defaultValue;
|
||||
item->value = defaultValue;
|
||||
item->callback = (void *) callback;
|
||||
item->defaultValue = defaultValue;
|
||||
item->value = currentValue;
|
||||
item->valueAtCreation = currentValue;
|
||||
item->valueChangedCallback = (void *) callback;
|
||||
snprintf(item->trueValue, sizeof(item->trueValue), "%s", trueValue);
|
||||
snprintf(item->falseValue, sizeof(item->falseValue), "%s", falseValue);
|
||||
|
||||
WUPSConfigAPIItemCallbacksV1 callbacks = {
|
||||
WUPSConfigAPIItemCallbacksV2 callbacks = {
|
||||
.getCurrentValueDisplay = &WUPSConfigItemBoolean_getCurrentValueDisplay,
|
||||
.getCurrentValueSelectedDisplay = &WUPSConfigItemBoolean_getCurrentValueSelectedDisplay,
|
||||
.onSelected = &WUPSConfigItemBoolean_onSelected,
|
||||
.onSelected = nullptr,
|
||||
.restoreDefault = &WUPSConfigItemBoolean_restoreDefault,
|
||||
.isMovementAllowed = &WUPSConfigItemBoolean_isMovementAllowed,
|
||||
.callCallback = &WUPSConfigItemBoolean_callCallback,
|
||||
.onButtonPressed = &WUPSConfigItemBoolean_onButtonPressed,
|
||||
.isMovementAllowed = nullptr,
|
||||
.onCloseCallback = &WUPSConfigItemBoolean_onCloseCallback,
|
||||
.onInput = &WUPSConfigItemBoolean_onInput,
|
||||
.onInputEx = nullptr,
|
||||
.onDelete = &WUPSConfigItemBoolean_onDelete};
|
||||
|
||||
WUPSConfigAPIItemOptionsV1 options = {
|
||||
WUPSConfigAPIItemOptionsV2 options = {
|
||||
.displayName = displayName,
|
||||
.context = item,
|
||||
.callbacks = callbacks,
|
||||
};
|
||||
|
||||
if (WUPSConfigAPI_Item_Create(options, &item->handle) != WUPSCONFIG_API_RESULT_SUCCESS) {
|
||||
WUPSConfigAPIStatus err;
|
||||
if ((err = WUPSConfigAPI_Item_Create(options, &item->handle)) != WUPSCONFIG_API_RESULT_SUCCESS) {
|
||||
WUPSConfigItemBoolean_Cleanup(item);
|
||||
return false;
|
||||
return err;
|
||||
}
|
||||
|
||||
if (WUPSConfigAPI_Category_AddItem(cat, item->handle) != WUPSCONFIG_API_RESULT_SUCCESS) {
|
||||
WUPSConfigAPI_Item_Destroy(item->handle);
|
||||
return false;
|
||||
}
|
||||
return true;
|
||||
*outHandle = item->handle;
|
||||
return WUPSCONFIG_API_RESULT_SUCCESS;
|
||||
}
|
||||
|
||||
extern "C" bool WUPSConfigItemBoolean_AddToCategory(WUPSConfigCategoryHandle cat, const char *configID, const char *displayName, bool defaultValue, BooleanValueChangedCallback callback) {
|
||||
return WUPSConfigItemBoolean_AddToCategoryEx(cat, configID, displayName, defaultValue, callback, "true", "false");
|
||||
extern "C" WUPSConfigAPIStatus
|
||||
WUPSConfigItemBoolean_AddToCategoryEx(WUPSConfigCategoryHandle cat,
|
||||
const char *identifier,
|
||||
const char *displayName,
|
||||
bool defaultValue,
|
||||
bool currentValue,
|
||||
BooleanValueChangedCallback callback,
|
||||
const char *trueValue,
|
||||
const char *falseValue) {
|
||||
WUPSConfigItemHandle itemHandle;
|
||||
WUPSConfigAPIStatus res;
|
||||
if ((res = WUPSConfigItemBoolean_CreateEx(identifier,
|
||||
displayName,
|
||||
defaultValue, currentValue,
|
||||
callback,
|
||||
trueValue, falseValue,
|
||||
&itemHandle)) != WUPSCONFIG_API_RESULT_SUCCESS) {
|
||||
return res;
|
||||
}
|
||||
|
||||
if ((res = WUPSConfigAPI_Category_AddItem(cat, itemHandle)) != WUPSCONFIG_API_RESULT_SUCCESS) {
|
||||
|
||||
WUPSConfigAPI_Item_Destroy(itemHandle);
|
||||
return res;
|
||||
}
|
||||
return WUPSCONFIG_API_RESULT_SUCCESS;
|
||||
}
|
||||
|
||||
extern "C" WUPSConfigAPIStatus
|
||||
WUPSConfigItemBoolean_AddToCategory(WUPSConfigCategoryHandle cat,
|
||||
const char *identifier,
|
||||
const char *displayName,
|
||||
bool defaultValue,
|
||||
bool currentValue,
|
||||
BooleanValueChangedCallback callback) {
|
||||
return WUPSConfigItemBoolean_AddToCategoryEx(cat, identifier, displayName, defaultValue, currentValue, callback, "true", "false");
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user