ButtonComboAPI: Hold duration is now measure in ms instead of frames

This commit is contained in:
Maschell 2024-12-30 13:38:11 +01:00
parent 014181fd53
commit d9ce5d71b0
3 changed files with 19 additions and 18 deletions

View File

@ -138,7 +138,7 @@ typedef struct WUPSButtonCombo_ButtonComboOptions {
typedef struct WUPSButtonCombo_ButtonComboInfoEx { typedef struct WUPSButtonCombo_ButtonComboInfoEx {
WUPSButtonCombo_ComboType type; WUPSButtonCombo_ComboType type;
WUPSButtonCombo_ButtonComboOptions basicCombo; WUPSButtonCombo_ButtonComboOptions basicCombo;
uint32_t optionalHoldForXFrames; uint32_t optionalHoldForXMs;
} WUPSButtonCombo_ButtonComboInfoEx; } WUPSButtonCombo_ButtonComboInfoEx;
typedef struct WUPSButtonCombo_ComboOptions { typedef struct WUPSButtonCombo_ComboOptions {
@ -205,11 +205,11 @@ WUPSButtonCombo_Error WUPSButtonComboAPI_AddButtonComboPressDownObserver(const c
WUPSButtonCombo_ComboHandle *outHandle, WUPSButtonCombo_ComboHandle *outHandle,
WUPSButtonCombo_ComboStatus *outStatus); WUPSButtonCombo_ComboStatus *outStatus);
/** /**
* @brief Adds a button combo which triggers a callback if a certain button combination was hold for X frames on any controller. * @brief Adds a button combo which triggers a callback if a certain button combination was hold for X ms on any controller.
* *
* Registers a unique button combination which will trigger a callback if the combo is held for a certain amount of frames **on any connected controller** and the button combo is valid. * Registers a unique button combination which will trigger a callback if the combo is held for a certain amount of ms **on any connected controller** and the button combo is valid.
* *
* The callback is triggered if the given button combination has been held down for the given number of frames (frame rate might vary from game to game). * The callback is triggered if the given button combination has been held down for at least X ms
* *
* Conflict management: * Conflict management:
* The button combination is only active if this function returns WUPS_BUTTON_COMBO_ERROR_SUCCESS and outStatus is WUPS_BUTTON_COMBO_COMBO_STATUS_VALID. * The button combination is only active if this function returns WUPS_BUTTON_COMBO_ERROR_SUCCESS and outStatus is WUPS_BUTTON_COMBO_COMBO_STATUS_VALID.
@ -225,15 +225,16 @@ WUPSButtonCombo_Error WUPSButtonComboAPI_AddButtonComboPressDownObserver(const c
* *
* @param label Label of this button combo * @param label Label of this button combo
* @param combo Combination which should be checked * @param combo Combination which should be checked
* @param holdDurationInFrames * @param holdDurationInMs
* @param callbackOptions Information about the callbacks that will be called if the combo is triggered * @param callback
* @param context
* @param outHandle The handle of the combo will be stored here. Must not be nullptr. * @param outHandle The handle of the combo will be stored here. Must not be nullptr.
* @param outStatus The status of the combo will be stored here. Only if the status is WUPS_BUTTON_COMBO_COMBO_STATUS_VALID the combo is valid. Must not be nullptr. * @param outStatus The status of the combo will be stored here. Only if the status is WUPS_BUTTON_COMBO_COMBO_STATUS_VALID the combo is valid. Must not be nullptr.
* @return * @return
**/ **/
WUPSButtonCombo_Error WUPSButtonComboAPI_AddButtonComboHold(const char *label, WUPSButtonCombo_Error WUPSButtonComboAPI_AddButtonComboHold(const char *label,
WUPSButtonCombo_Buttons combo, WUPSButtonCombo_Buttons combo,
uint32_t holdDurationInFrames, uint32_t holdDurationInMs,
WUPSButtonCombo_ComboCallback callback, WUPSButtonCombo_ComboCallback callback,
void *context, void *context,
WUPSButtonCombo_ComboHandle *outHandle, WUPSButtonCombo_ComboHandle *outHandle,
@ -241,7 +242,7 @@ WUPSButtonCombo_Error WUPSButtonComboAPI_AddButtonComboHold(const char *label,
WUPSButtonCombo_Error WUPSButtonComboAPI_AddButtonComboHoldObserver(const char *label, WUPSButtonCombo_Error WUPSButtonComboAPI_AddButtonComboHoldObserver(const char *label,
WUPSButtonCombo_Buttons combo, WUPSButtonCombo_Buttons combo,
uint32_t holdDurationInFrames, uint32_t holdDurationInMs,
WUPSButtonCombo_ComboCallback callback, WUPSButtonCombo_ComboCallback callback,
void *context, void *context,
WUPSButtonCombo_ComboHandle *outHandle, WUPSButtonCombo_ComboHandle *outHandle,
@ -277,7 +278,7 @@ WUPSButtonCombo_Error WUPSButtonComboAPI_UpdateButtonCombo(WUPSButtonCombo_Combo
WUPSButtonCombo_ComboStatus *outStatus); WUPSButtonCombo_ComboStatus *outStatus);
WUPSButtonCombo_Error WUPSButtonComboAPI_UpdateHoldDuration(WUPSButtonCombo_ComboHandle handle, WUPSButtonCombo_Error WUPSButtonComboAPI_UpdateHoldDuration(WUPSButtonCombo_ComboHandle handle,
uint32_t holdDurationInFrames); uint32_t holdDurationInMs);
WUPSButtonCombo_Error WUPSButtonComboAPI_GetButtonComboMeta(WUPSButtonCombo_ComboHandle handle, WUPSButtonCombo_Error WUPSButtonComboAPI_GetButtonComboMeta(WUPSButtonCombo_ComboHandle handle,
WUPSButtonCombo_MetaOptionsOut *outOptions); WUPSButtonCombo_MetaOptionsOut *outOptions);

View File

@ -64,7 +64,7 @@ typedef WUPSButtonCombo_Error (*WUPSButtonCombo_UpdateButtonComboFunction)(void
*/ */
typedef WUPSButtonCombo_Error (*WUPSButtonCombo_UpdateHoldDurationFunction)(void *identifier, typedef WUPSButtonCombo_Error (*WUPSButtonCombo_UpdateHoldDurationFunction)(void *identifier,
WUPSButtonCombo_ComboHandle handle, WUPSButtonCombo_ComboHandle handle,
uint32_t holdDurationInFrames); uint32_t holdDurationInMs);
/** /**
* @typedef WUPSButtonCombo_GetButtonComboMetaFunction * @typedef WUPSButtonCombo_GetButtonComboMetaFunction

View File

@ -103,7 +103,7 @@ WUPSButtonCombo_Error WUPSButtonComboAPI_AddButtonComboPressDownObserver(const c
static WUPSButtonCombo_Error WUPSButtonComboAPI_AddButtonComboHoldEx(const char *label, static WUPSButtonCombo_Error WUPSButtonComboAPI_AddButtonComboHoldEx(const char *label,
const WUPSButtonCombo_Buttons combo, const WUPSButtonCombo_Buttons combo,
const uint32_t holdDurationInFrames, const uint32_t holdDurationInMs,
const WUPSButtonCombo_ComboCallback callback, const WUPSButtonCombo_ComboCallback callback,
void *context, void *context,
const bool observer, const bool observer,
@ -115,29 +115,29 @@ static WUPSButtonCombo_Error WUPSButtonComboAPI_AddButtonComboHoldEx(const char
options.buttonComboOptions.type = observer ? WUPS_BUTTON_COMBO_COMBO_TYPE_HOLD_OBSERVER : WUPS_BUTTON_COMBO_COMBO_TYPE_HOLD; options.buttonComboOptions.type = observer ? WUPS_BUTTON_COMBO_COMBO_TYPE_HOLD_OBSERVER : WUPS_BUTTON_COMBO_COMBO_TYPE_HOLD;
options.buttonComboOptions.basicCombo.combo = combo; options.buttonComboOptions.basicCombo.combo = combo;
options.buttonComboOptions.basicCombo.controllerMask = WUPS_BUTTON_COMBO_CONTROLLER_ALL; options.buttonComboOptions.basicCombo.controllerMask = WUPS_BUTTON_COMBO_CONTROLLER_ALL;
options.buttonComboOptions.optionalHoldForXFrames = holdDurationInFrames; options.buttonComboOptions.optionalHoldForXMs = holdDurationInMs;
return WUPSButtonComboAPI_AddButtonCombo(&options, outHandle, outStatus); return WUPSButtonComboAPI_AddButtonCombo(&options, outHandle, outStatus);
} }
WUPSButtonCombo_Error WUPSButtonComboAPI_AddButtonComboHold(const char *label, WUPSButtonCombo_Error WUPSButtonComboAPI_AddButtonComboHold(const char *label,
const WUPSButtonCombo_Buttons combo, const WUPSButtonCombo_Buttons combo,
const uint32_t holdDurationInFrames, const uint32_t holdDurationInMs,
const WUPSButtonCombo_ComboCallback callback, const WUPSButtonCombo_ComboCallback callback,
void *context, void *context,
WUPSButtonCombo_ComboHandle *outHandle, WUPSButtonCombo_ComboHandle *outHandle,
WUPSButtonCombo_ComboStatus *outStatus) { WUPSButtonCombo_ComboStatus *outStatus) {
return WUPSButtonComboAPI_AddButtonComboHoldEx(label, combo, holdDurationInFrames, callback, context, false, outHandle, outStatus); return WUPSButtonComboAPI_AddButtonComboHoldEx(label, combo, holdDurationInMs, callback, context, false, outHandle, outStatus);
} }
WUPSButtonCombo_Error WUPSButtonComboAPI_AddButtonComboHoldObserver(const char *label, WUPSButtonCombo_Error WUPSButtonComboAPI_AddButtonComboHoldObserver(const char *label,
const WUPSButtonCombo_Buttons combo, const WUPSButtonCombo_Buttons combo,
const uint32_t holdDurationInFrames, const uint32_t holdDurationInMs,
const WUPSButtonCombo_ComboCallback callback, const WUPSButtonCombo_ComboCallback callback,
void *context, void *context,
WUPSButtonCombo_ComboHandle *outHandle, WUPSButtonCombo_ComboHandle *outHandle,
WUPSButtonCombo_ComboStatus *outStatus) { WUPSButtonCombo_ComboStatus *outStatus) {
return WUPSButtonComboAPI_AddButtonComboHoldEx(label, combo, holdDurationInFrames, callback, context, true, outHandle, outStatus); return WUPSButtonComboAPI_AddButtonComboHoldEx(label, combo, holdDurationInMs, callback, context, true, outHandle, outStatus);
} }
WUPSButtonCombo_Error WUPSButtonComboAPI_AddButtonCombo(const WUPSButtonCombo_ComboOptions *options, WUPSButtonCombo_Error WUPSButtonComboAPI_AddButtonCombo(const WUPSButtonCombo_ComboOptions *options,
@ -233,14 +233,14 @@ WUPSButtonCombo_Error WUPSButtonComboAPI_UpdateButtonCombo(const WUPSButtonCombo
} }
WUPSButtonCombo_Error WUPSButtonComboAPI_UpdateHoldDuration(const WUPSButtonCombo_ComboHandle handle, WUPSButtonCombo_Error WUPSButtonComboAPI_UpdateHoldDuration(const WUPSButtonCombo_ComboHandle handle,
const uint32_t holdDurationInFrames) { const uint32_t holdDurationInMs) {
if (__internal_functions.update_hold_duration_function_ptr == nullptr) { if (__internal_functions.update_hold_duration_function_ptr == nullptr) {
return WUPS_BUTTON_COMBO_ERROR_INTERNAL_NOT_INITIALIZED; return WUPS_BUTTON_COMBO_ERROR_INTERNAL_NOT_INITIALIZED;
} }
if (__internal_functions.identifier == nullptr) { if (__internal_functions.identifier == nullptr) {
return WUPS_BUTTON_COMBO_ERROR_INTERNAL_NOT_INITIALIZED; return WUPS_BUTTON_COMBO_ERROR_INTERNAL_NOT_INITIALIZED;
} }
return __internal_functions.update_hold_duration_function_ptr(__internal_functions.identifier, handle, holdDurationInFrames); return __internal_functions.update_hold_duration_function_ptr(__internal_functions.identifier, handle, holdDurationInMs);
} }
WUPSButtonCombo_Error WUPSButtonComboAPI_GetButtonComboMeta(const WUPSButtonCombo_ComboHandle handle, WUPSButtonCombo_Error WUPSButtonComboAPI_GetButtonComboMeta(const WUPSButtonCombo_ComboHandle handle,