Changed enums to use XXX_COUNT for the count or number of values

Fixes https://github.com/libsdl-org/SDL/issues/10763
This commit is contained in:
Sam Lantinga
2024-09-11 08:08:18 -07:00
parent 64f12bea4a
commit 37c9fb490e
49 changed files with 197 additions and 174 deletions

View File

@@ -78,9 +78,9 @@ static const char * const SDL_priority_names[] = {
"ERROR",
"CRITICAL"
};
SDL_COMPILE_TIME_ASSERT(priority_names, SDL_arraysize(SDL_priority_names) == SDL_NUM_LOG_PRIORITIES);
SDL_COMPILE_TIME_ASSERT(priority_names, SDL_arraysize(SDL_priority_names) == SDL_LOG_PRIORITY_COUNT);
static const char *SDL_priority_prefixes[SDL_NUM_LOG_PRIORITIES];
static const char *SDL_priority_prefixes[SDL_LOG_PRIORITY_COUNT];
// If this list changes, update the documentation for SDL_HINT_LOGGING
static const char * const SDL_category_names[] = {
@@ -102,7 +102,7 @@ SDL_COMPILE_TIME_ASSERT(category_names, SDL_arraysize(SDL_category_names) == SDL
#endif
#ifdef SDL_PLATFORM_ANDROID
static int SDL_android_priority[SDL_NUM_LOG_PRIORITIES] = {
static int SDL_android_priority[SDL_LOG_PRIORITY_COUNT] = {
ANDROID_LOG_UNKNOWN,
ANDROID_LOG_VERBOSE,
ANDROID_LOG_DEBUG,
@@ -196,10 +196,10 @@ static bool SDL_ParseLogPriority(const char *string, size_t length, SDL_LogPrior
i = SDL_atoi(string);
if (i == 0) {
// 0 has a special meaning of "disable this category"
*priority = SDL_NUM_LOG_PRIORITIES;
*priority = SDL_LOG_PRIORITY_COUNT;
return true;
}
if (i >= SDL_LOG_PRIORITY_VERBOSE && i < SDL_NUM_LOG_PRIORITIES) {
if (i >= SDL_LOG_PRIORITY_VERBOSE && i < SDL_LOG_PRIORITY_COUNT) {
*priority = (SDL_LogPriority)i;
return true;
}
@@ -207,11 +207,11 @@ static bool SDL_ParseLogPriority(const char *string, size_t length, SDL_LogPrior
}
if (SDL_strncasecmp(string, "quiet", length) == 0) {
*priority = SDL_NUM_LOG_PRIORITIES;
*priority = SDL_LOG_PRIORITY_COUNT;
return true;
}
for (i = SDL_LOG_PRIORITY_VERBOSE; i < SDL_NUM_LOG_PRIORITIES; ++i) {
for (i = SDL_LOG_PRIORITY_VERBOSE; i < SDL_LOG_PRIORITY_COUNT; ++i) {
if (SDL_strncasecmp(string, SDL_priority_names[i], length) == 0) {
*priority = (SDL_LogPriority)i;
return true;
@@ -319,7 +319,7 @@ static void SDL_ResetLogPrefixes(void)
static const char *SDL_GetLogPriorityPrefix(SDL_LogPriority priority)
{
if (priority < SDL_LOG_PRIORITY_VERBOSE || priority >= SDL_NUM_LOG_PRIORITIES) {
if (priority < SDL_LOG_PRIORITY_VERBOSE || priority >= SDL_LOG_PRIORITY_COUNT) {
return "";
}
@@ -341,7 +341,7 @@ static const char *SDL_GetLogPriorityPrefix(SDL_LogPriority priority)
SDL_bool SDL_SetLogPriorityPrefix(SDL_LogPriority priority, const char *prefix)
{
if (priority < SDL_LOG_PRIORITY_VERBOSE || priority >= SDL_NUM_LOG_PRIORITIES) {
if (priority < SDL_LOG_PRIORITY_VERBOSE || priority >= SDL_LOG_PRIORITY_COUNT) {
return SDL_InvalidParamError("priority");
}
@@ -456,7 +456,7 @@ void SDL_LogMessageV(int category, SDL_LogPriority priority, SDL_PRINTF_FORMAT_S
}
// Make sure we don't exceed array bounds
if ((int)priority < 0 || priority >= SDL_NUM_LOG_PRIORITIES) {
if ((int)priority < 0 || priority >= SDL_LOG_PRIORITY_COUNT) {
return;
}

View File

@@ -2122,8 +2122,8 @@ bool Android_JNI_ShowMessageBox(const SDL_MessageBoxData *messageboxdata, int *b
}
if (messageboxdata->colorScheme) {
colors = (*env)->NewIntArray(env, SDL_MESSAGEBOX_COLOR_MAX);
for (i = 0; i < SDL_MESSAGEBOX_COLOR_MAX; ++i) {
colors = (*env)->NewIntArray(env, SDL_MESSAGEBOX_COLOR_COUNT);
for (i = 0; i < SDL_MESSAGEBOX_COLOR_COUNT; ++i) {
temp = (0xFFU << 24) |
(messageboxdata->colorScheme->colors[i].r << 16) |
(messageboxdata->colorScheme->colors[i].g << 8) |

View File

@@ -808,7 +808,7 @@ static void updateKeyboard(SDL_WSCONS_input_data *input)
}
} break;
case WSCONS_EVENT_ALL_KEYS_UP:
for (i = 0; i < SDL_NUM_SCANCODES; i++) {
for (i = 0; i < SDL_SCANCODE_COUNT; i++) {
SDL_SendKeyboardKey(0, input->keyboardID, 0, (SDL_Scancode)i, false);
}
break;

View File

@@ -379,7 +379,7 @@ static void SDLCALL SDL_EventLoggingChanged(void *userdata, const char *name, co
static void SDL_LogEvent(const SDL_Event *event)
{
static const char *pen_axisnames[] = { "PRESSURE", "XTILT", "YTILT", "DISTANCE", "ROTATION", "SLIDER", "TANGENTIAL_PRESSURE" };
SDL_COMPILE_TIME_ASSERT(pen_axisnames_array_matches, SDL_arraysize(pen_axisnames) == SDL_PEN_NUM_AXES);
SDL_COMPILE_TIME_ASSERT(pen_axisnames_array_matches, SDL_arraysize(pen_axisnames) == SDL_PEN_AXIS_COUNT);
char name[64];
char details[128];

View File

@@ -53,8 +53,8 @@ typedef struct SDL_Keyboard
// Data common to all keyboards
SDL_Window *focus;
SDL_Keymod modstate;
Uint8 keysource[SDL_NUM_SCANCODES];
SDL_bool keystate[SDL_NUM_SCANCODES];
Uint8 keysource[SDL_SCANCODE_COUNT];
SDL_bool keystate[SDL_SCANCODE_COUNT];
SDL_Keymap *keymap;
bool french_numbers;
bool latin_letters;
@@ -219,7 +219,7 @@ void SDL_ResetKeyboard(void)
#ifdef DEBUG_KEYBOARD
printf("Resetting keyboard\n");
#endif
for (scancode = SDL_SCANCODE_UNKNOWN; scancode < SDL_NUM_SCANCODES; ++scancode) {
for (scancode = SDL_SCANCODE_UNKNOWN; scancode < SDL_SCANCODE_COUNT; ++scancode) {
if (keyboard->keystate[scancode]) {
SDL_SendKeyboardKey(0, SDL_GLOBAL_KEYBOARD_ID, 0, (SDL_Scancode)scancode, false);
}
@@ -510,7 +510,7 @@ static bool SDL_SendKeyboardKeyInternal(Uint64 timestamp, Uint32 flags, SDL_Keyb
type = SDL_EVENT_KEY_UP;
}
if (scancode > SDL_SCANCODE_UNKNOWN && scancode < SDL_NUM_SCANCODES) {
if (scancode > SDL_SCANCODE_UNKNOWN && scancode < SDL_SCANCODE_COUNT) {
// Drop events that don't change state
if (down) {
if (keyboard->keystate[scancode]) {
@@ -691,7 +691,7 @@ void SDL_ReleaseAutoReleaseKeys(void)
int scancode;
if (keyboard->autorelease_pending) {
for (scancode = SDL_SCANCODE_UNKNOWN; scancode < SDL_NUM_SCANCODES; ++scancode) {
for (scancode = SDL_SCANCODE_UNKNOWN; scancode < SDL_SCANCODE_COUNT; ++scancode) {
if (keyboard->keysource[scancode] == KEYBOARD_AUTORELEASE) {
SDL_SendKeyboardKeyInternal(0, KEYBOARD_AUTORELEASE, SDL_GLOBAL_KEYBOARD_ID, 0, (SDL_Scancode)scancode, false);
}
@@ -712,7 +712,7 @@ bool SDL_HardwareKeyboardKeyPressed(void)
SDL_Keyboard *keyboard = &SDL_keyboard;
int scancode;
for (scancode = SDL_SCANCODE_UNKNOWN; scancode < SDL_NUM_SCANCODES; ++scancode) {
for (scancode = SDL_SCANCODE_UNKNOWN; scancode < SDL_SCANCODE_COUNT; ++scancode) {
if (keyboard->keysource[scancode] & KEYBOARD_HARDWARE) {
return true;
}
@@ -868,7 +868,7 @@ const SDL_bool *SDL_GetKeyboardState(int *numkeys)
SDL_Keyboard *keyboard = &SDL_keyboard;
if (numkeys != (int *)0) {
*numkeys = SDL_NUM_SCANCODES;
*numkeys = SDL_SCANCODE_COUNT;
}
return keyboard->keystate;
}

View File

@@ -192,7 +192,7 @@ static const SDL_Keycode shifted_default_symbols[] = {
static SDL_Keycode SDL_GetDefaultKeyFromScancode(SDL_Scancode scancode, SDL_Keymod modstate)
{
if (((int)scancode) < SDL_SCANCODE_UNKNOWN || scancode >= SDL_NUM_SCANCODES) {
if (((int)scancode) < SDL_SCANCODE_UNKNOWN || scancode >= SDL_SCANCODE_COUNT) {
SDL_InvalidParamError("scancode");
return SDLK_UNKNOWN;
}
@@ -638,7 +638,7 @@ static SDL_Scancode SDL_GetDefaultScancodeFromKey(SDL_Keycode key, SDL_Keymod *m
return SDL_SCANCODE_UNKNOWN;
}
static const char *SDL_scancode_names[SDL_NUM_SCANCODES] =
static const char *SDL_scancode_names[SDL_SCANCODE_COUNT] =
{
/* 0 */ NULL,
/* 1 */ NULL,
@@ -935,7 +935,7 @@ static const char *SDL_scancode_names[SDL_NUM_SCANCODES] =
SDL_bool SDL_SetScancodeName(SDL_Scancode scancode, const char *name)
{
if (((int)scancode) < SDL_SCANCODE_UNKNOWN || scancode >= SDL_NUM_SCANCODES) {
if (((int)scancode) < SDL_SCANCODE_UNKNOWN || scancode >= SDL_SCANCODE_COUNT) {
return SDL_InvalidParamError("scancode");
}
@@ -946,7 +946,7 @@ SDL_bool SDL_SetScancodeName(SDL_Scancode scancode, const char *name)
const char *SDL_GetScancodeName(SDL_Scancode scancode)
{
const char *name;
if (((int)scancode) < SDL_SCANCODE_UNKNOWN || scancode >= SDL_NUM_SCANCODES) {
if (((int)scancode) < SDL_SCANCODE_UNKNOWN || scancode >= SDL_SCANCODE_COUNT) {
SDL_InvalidParamError("scancode");
return "";
}

View File

@@ -31,7 +31,7 @@ typedef struct SDL_Pen
SDL_PenID instance_id;
char *name;
SDL_PenInfo info;
float axes[SDL_PEN_NUM_AXES];
float axes[SDL_PEN_AXIS_COUNT];
float x;
float y;
SDL_PenInputFlags input_state;
@@ -170,10 +170,10 @@ SDL_PenInputFlags SDL_GetPenStatus(SDL_PenID instance_id, float *axes, int num_a
if (pen) {
result = pen->input_state;
if (axes && num_axes) {
SDL_memcpy(axes, pen->axes, SDL_min(num_axes, SDL_PEN_NUM_AXES) * sizeof (*axes));
SDL_memcpy(axes, pen->axes, SDL_min(num_axes, SDL_PEN_AXIS_COUNT) * sizeof (*axes));
// zero out axes we don't know about, in case the caller built with newer SDL headers that support more of them.
if (num_axes > SDL_PEN_NUM_AXES) {
SDL_memset(&axes[SDL_PEN_NUM_AXES], '\0', (num_axes - SDL_PEN_NUM_AXES) * sizeof (*axes));
if (num_axes > SDL_PEN_AXIS_COUNT) {
SDL_memset(&axes[SDL_PEN_AXIS_COUNT], '\0', (num_axes - SDL_PEN_AXIS_COUNT) * sizeof (*axes));
}
}
}
@@ -368,7 +368,7 @@ void SDL_SendPenTouch(Uint64 timestamp, SDL_PenID instance_id, const SDL_Window
void SDL_SendPenAxis(Uint64 timestamp, SDL_PenID instance_id, const SDL_Window *window, SDL_PenAxis axis, float value)
{
SDL_assert((axis >= 0) && (axis < SDL_PEN_NUM_AXES)); // fix the backend if this triggers.
SDL_assert((axis >= 0) && (axis < SDL_PEN_AXIS_COUNT)); // fix the backend if this triggers.
bool send_event = false;
SDL_PenInputFlags input_state = 0;

View File

@@ -427,7 +427,7 @@ const char *SDL_GetBasePath(void)
}
static char *CachedUserFolders[SDL_FOLDER_TOTAL];
static char *CachedUserFolders[SDL_FOLDER_COUNT];
const char *SDL_GetUserFolder(SDL_Folder folder)
{

View File

@@ -293,14 +293,14 @@ static void RecenterGamepad(SDL_Gamepad *gamepad)
int i;
Uint64 timestamp = SDL_GetTicksNS();
for (i = 0; i < SDL_GAMEPAD_BUTTON_MAX; ++i) {
for (i = 0; i < SDL_GAMEPAD_BUTTON_COUNT; ++i) {
SDL_GamepadButton button = (SDL_GamepadButton)i;
if (SDL_GetGamepadButton(gamepad, button)) {
SDL_SendGamepadButton(timestamp, gamepad, button, false);
}
}
for (i = 0; i < SDL_GAMEPAD_AXIS_MAX; ++i) {
for (i = 0; i < SDL_GAMEPAD_AXIS_COUNT; ++i) {
SDL_GamepadAxis axis = (SDL_GamepadAxis)i;
if (SDL_GetGamepadAxis(gamepad, axis) != 0) {
SDL_SendGamepadAxis(timestamp, gamepad, axis, 0);
@@ -979,7 +979,7 @@ static const char *map_StringForGamepadType[] = {
"joyconright",
"joyconpair"
};
SDL_COMPILE_TIME_ASSERT(map_StringForGamepadType, SDL_arraysize(map_StringForGamepadType) == SDL_GAMEPAD_TYPE_MAX);
SDL_COMPILE_TIME_ASSERT(map_StringForGamepadType, SDL_arraysize(map_StringForGamepadType) == SDL_GAMEPAD_TYPE_COUNT);
/*
* convert a string to its enum equivalent
@@ -1009,7 +1009,7 @@ SDL_GamepadType SDL_GetGamepadTypeFromString(const char *str)
*/
const char *SDL_GetGamepadStringForType(SDL_GamepadType type)
{
if (type >= SDL_GAMEPAD_TYPE_STANDARD && type < SDL_GAMEPAD_TYPE_MAX) {
if (type >= SDL_GAMEPAD_TYPE_STANDARD && type < SDL_GAMEPAD_TYPE_COUNT) {
return map_StringForGamepadType[type];
}
return NULL;
@@ -1023,7 +1023,7 @@ static const char *map_StringForGamepadAxis[] = {
"lefttrigger",
"righttrigger"
};
SDL_COMPILE_TIME_ASSERT(map_StringForGamepadAxis, SDL_arraysize(map_StringForGamepadAxis) == SDL_GAMEPAD_AXIS_MAX);
SDL_COMPILE_TIME_ASSERT(map_StringForGamepadAxis, SDL_arraysize(map_StringForGamepadAxis) == SDL_GAMEPAD_AXIS_COUNT);
/*
* convert a string to its enum equivalent
@@ -1053,7 +1053,7 @@ SDL_GamepadAxis SDL_GetGamepadAxisFromString(const char *str)
*/
const char *SDL_GetGamepadStringForAxis(SDL_GamepadAxis axis)
{
if (axis > SDL_GAMEPAD_AXIS_INVALID && axis < SDL_GAMEPAD_AXIS_MAX) {
if (axis > SDL_GAMEPAD_AXIS_INVALID && axis < SDL_GAMEPAD_AXIS_COUNT) {
return map_StringForGamepadAxis[axis];
}
return NULL;
@@ -1087,7 +1087,7 @@ static const char *map_StringForGamepadButton[] = {
"misc5",
"misc6"
};
SDL_COMPILE_TIME_ASSERT(map_StringForGamepadButton, SDL_arraysize(map_StringForGamepadButton) == SDL_GAMEPAD_BUTTON_MAX);
SDL_COMPILE_TIME_ASSERT(map_StringForGamepadButton, SDL_arraysize(map_StringForGamepadButton) == SDL_GAMEPAD_BUTTON_COUNT);
/*
* convert a string to its enum equivalent
@@ -1132,7 +1132,7 @@ SDL_GamepadButton SDL_GetGamepadButtonFromString(const char *str)
*/
const char *SDL_GetGamepadStringForButton(SDL_GamepadButton button)
{
if (button > SDL_GAMEPAD_BUTTON_INVALID && button < SDL_GAMEPAD_BUTTON_MAX) {
if (button > SDL_GAMEPAD_BUTTON_INVALID && button < SDL_GAMEPAD_BUTTON_COUNT) {
return map_StringForGamepadButton[button];
}
return NULL;

View File

@@ -40,8 +40,8 @@ typedef struct
bool pc_mode;
SDL_JoystickID joysticks[MAX_CONTROLLERS];
Uint8 wireless[MAX_CONTROLLERS];
Uint8 min_axis[MAX_CONTROLLERS * SDL_GAMEPAD_AXIS_MAX];
Uint8 max_axis[MAX_CONTROLLERS * SDL_GAMEPAD_AXIS_MAX];
Uint8 min_axis[MAX_CONTROLLERS * SDL_GAMEPAD_AXIS_COUNT];
Uint8 max_axis[MAX_CONTROLLERS * SDL_GAMEPAD_AXIS_COUNT];
Uint8 rumbleAllowed[MAX_CONTROLLERS];
Uint8 rumble[1 + MAX_CONTROLLERS];
// Without this variable, hid_write starts to lag a TON
@@ -83,12 +83,12 @@ static bool HIDAPI_DriverGameCube_IsSupportedDevice(SDL_HIDAPI_Device *device, c
static void ResetAxisRange(SDL_DriverGameCube_Context *ctx, int joystick_index)
{
SDL_memset(&ctx->min_axis[joystick_index * SDL_GAMEPAD_AXIS_MAX], 128 - 88, SDL_GAMEPAD_AXIS_MAX);
SDL_memset(&ctx->max_axis[joystick_index * SDL_GAMEPAD_AXIS_MAX], 128 + 88, SDL_GAMEPAD_AXIS_MAX);
SDL_memset(&ctx->min_axis[joystick_index * SDL_GAMEPAD_AXIS_COUNT], 128 - 88, SDL_GAMEPAD_AXIS_COUNT);
SDL_memset(&ctx->max_axis[joystick_index * SDL_GAMEPAD_AXIS_COUNT], 128 + 88, SDL_GAMEPAD_AXIS_COUNT);
// Trigger axes may have a higher resting value
ctx->min_axis[joystick_index * SDL_GAMEPAD_AXIS_MAX + SDL_GAMEPAD_AXIS_LEFT_TRIGGER] = 40;
ctx->min_axis[joystick_index * SDL_GAMEPAD_AXIS_MAX + SDL_GAMEPAD_AXIS_RIGHT_TRIGGER] = 40;
ctx->min_axis[joystick_index * SDL_GAMEPAD_AXIS_COUNT + SDL_GAMEPAD_AXIS_LEFT_TRIGGER] = 40;
ctx->min_axis[joystick_index * SDL_GAMEPAD_AXIS_COUNT + SDL_GAMEPAD_AXIS_RIGHT_TRIGGER] = 40;
}
static void SDLCALL SDL_JoystickGameCubeRumbleBrakeHintChanged(void *userdata, const char *name, const char *oldValue, const char *hint)
@@ -252,11 +252,11 @@ static void HIDAPI_DriverGameCube_HandleJoystickPacket(SDL_HIDAPI_Device *device
#define READ_AXIS(off, axis, invert) \
v = invert ? (0xff - packet[off]) : packet[off]; \
if (v < ctx->min_axis[i * SDL_GAMEPAD_AXIS_MAX + axis]) \
ctx->min_axis[i * SDL_GAMEPAD_AXIS_MAX + axis] = v; \
if (v > ctx->max_axis[i * SDL_GAMEPAD_AXIS_MAX + axis]) \
ctx->max_axis[i * SDL_GAMEPAD_AXIS_MAX + axis] = v; \
axis_value = (Sint16)HIDAPI_RemapVal(v, ctx->min_axis[i * SDL_GAMEPAD_AXIS_MAX + axis], ctx->max_axis[i * SDL_GAMEPAD_AXIS_MAX + axis], SDL_MIN_SINT16, SDL_MAX_SINT16); \
if (v < ctx->min_axis[i * SDL_GAMEPAD_AXIS_COUNT + axis]) \
ctx->min_axis[i * SDL_GAMEPAD_AXIS_COUNT + axis] = v; \
if (v > ctx->max_axis[i * SDL_GAMEPAD_AXIS_COUNT + axis]) \
ctx->max_axis[i * SDL_GAMEPAD_AXIS_COUNT + axis] = v; \
axis_value = (Sint16)HIDAPI_RemapVal(v, ctx->min_axis[i * SDL_GAMEPAD_AXIS_COUNT + axis], ctx->max_axis[i * SDL_GAMEPAD_AXIS_COUNT + axis], SDL_MIN_SINT16, SDL_MAX_SINT16); \
SDL_SendJoystickAxis( \
timestamp, \
joystick, \
@@ -334,11 +334,11 @@ static void HIDAPI_DriverGameCube_HandleNintendoPacket(SDL_HIDAPI_Device *device
#undef READ_BUTTON
#define READ_AXIS(off, axis) \
if (curSlot[off] < ctx->min_axis[i * SDL_GAMEPAD_AXIS_MAX + axis]) \
ctx->min_axis[i * SDL_GAMEPAD_AXIS_MAX + axis] = curSlot[off]; \
if (curSlot[off] > ctx->max_axis[i * SDL_GAMEPAD_AXIS_MAX + axis]) \
ctx->max_axis[i * SDL_GAMEPAD_AXIS_MAX + axis] = curSlot[off]; \
axis_value = (Sint16)HIDAPI_RemapVal(curSlot[off], ctx->min_axis[i * SDL_GAMEPAD_AXIS_MAX + axis], ctx->max_axis[i * SDL_GAMEPAD_AXIS_MAX + axis], SDL_MIN_SINT16, SDL_MAX_SINT16); \
if (curSlot[off] < ctx->min_axis[i * SDL_GAMEPAD_AXIS_COUNT + axis]) \
ctx->min_axis[i * SDL_GAMEPAD_AXIS_COUNT + axis] = curSlot[off]; \
if (curSlot[off] > ctx->max_axis[i * SDL_GAMEPAD_AXIS_COUNT + axis]) \
ctx->max_axis[i * SDL_GAMEPAD_AXIS_COUNT + axis] = curSlot[off]; \
axis_value = (Sint16)HIDAPI_RemapVal(curSlot[off], ctx->min_axis[i * SDL_GAMEPAD_AXIS_COUNT + axis], ctx->max_axis[i * SDL_GAMEPAD_AXIS_COUNT + axis], SDL_MIN_SINT16, SDL_MAX_SINT16); \
SDL_SendJoystickAxis( \
timestamp, \
joystick, \
@@ -391,7 +391,7 @@ static bool HIDAPI_DriverGameCube_OpenJoystick(SDL_HIDAPI_Device *device, SDL_Jo
for (i = 0; i < MAX_CONTROLLERS; i += 1) {
if (joystick->instance_id == ctx->joysticks[i]) {
joystick->nbuttons = 12;
joystick->naxes = SDL_GAMEPAD_AXIS_MAX;
joystick->naxes = SDL_GAMEPAD_AXIS_COUNT;
if (ctx->wireless[i]) {
joystick->connection_state = SDL_JOYSTICK_CONNECTION_WIRELESS;
} else {

View File

@@ -101,7 +101,7 @@ static bool HIDAPI_DriverLuna_OpenJoystick(SDL_HIDAPI_Device *device, SDL_Joysti
// Initialize the joystick capabilities
joystick->nbuttons = SDL_GAMEPAD_NUM_LUNA_BUTTONS;
joystick->naxes = SDL_GAMEPAD_AXIS_MAX;
joystick->naxes = SDL_GAMEPAD_AXIS_COUNT;
joystick->nhats = 1;
return true;

View File

@@ -863,7 +863,7 @@ static bool HIDAPI_DriverPS4_OpenJoystick(SDL_HIDAPI_Device *device, SDL_Joystic
if (ctx->touchpad_supported) {
joystick->nbuttons += 1;
}
joystick->naxes = SDL_GAMEPAD_AXIS_MAX;
joystick->naxes = SDL_GAMEPAD_AXIS_COUNT;
joystick->nhats = 1;
SDL_AddHintCallback(SDL_HINT_JOYSTICK_HIDAPI_PS4_REPORT_INTERVAL,

View File

@@ -958,7 +958,7 @@ static bool HIDAPI_DriverPS5_OpenJoystick(SDL_HIDAPI_Device *device, SDL_Joystic
} else {
joystick->nbuttons = 11;
}
joystick->naxes = SDL_GAMEPAD_AXIS_MAX;
joystick->naxes = SDL_GAMEPAD_AXIS_COUNT;
joystick->nhats = 1;
joystick->firmware_version = ctx->firmware_version;

View File

@@ -184,13 +184,13 @@ static bool HIDAPI_DriverShield_OpenJoystick(SDL_HIDAPI_Device *device, SDL_Joys
// Initialize the joystick capabilities
if (device->product_id == USB_PRODUCT_NVIDIA_SHIELD_CONTROLLER_V103) {
joystick->nbuttons = SDL_GAMEPAD_NUM_SHIELD_V103_BUTTONS;
joystick->naxes = SDL_GAMEPAD_AXIS_MAX;
joystick->naxes = SDL_GAMEPAD_AXIS_COUNT;
joystick->nhats = 1;
SDL_PrivateJoystickAddTouchpad(joystick, 1);
} else {
joystick->nbuttons = SDL_GAMEPAD_NUM_SHIELD_V104_BUTTONS;
joystick->naxes = SDL_GAMEPAD_AXIS_MAX;
joystick->naxes = SDL_GAMEPAD_AXIS_COUNT;
joystick->nhats = 1;
}

View File

@@ -107,7 +107,7 @@ static bool HIDAPI_DriverStadia_OpenJoystick(SDL_HIDAPI_Device *device, SDL_Joys
// Initialize the joystick capabilities
joystick->nbuttons = SDL_GAMEPAD_NUM_STADIA_BUTTONS;
joystick->naxes = SDL_GAMEPAD_AXIS_MAX;
joystick->naxes = SDL_GAMEPAD_AXIS_COUNT;
joystick->nhats = 1;
return true;

View File

@@ -1022,7 +1022,7 @@ static bool HIDAPI_DriverSteam_OpenJoystick(SDL_HIDAPI_Device *device, SDL_Joyst
// Initialize the joystick capabilities
joystick->nbuttons = SDL_GAMEPAD_NUM_STEAM_BUTTONS;
joystick->naxes = SDL_GAMEPAD_AXIS_MAX;
joystick->naxes = SDL_GAMEPAD_AXIS_COUNT;
joystick->nhats = 1;
SDL_PrivateJoystickAddSensor(joystick, SDL_SENSOR_GYRO, update_rate_in_hz);

View File

@@ -360,7 +360,7 @@ static bool HIDAPI_DriverSteamDeck_OpenJoystick(SDL_HIDAPI_Device *device, SDL_J
// Initialize the joystick capabilities
joystick->nbuttons = SDL_GAMEPAD_NUM_STEAM_DECK_BUTTONS;
joystick->naxes = SDL_GAMEPAD_AXIS_MAX;
joystick->naxes = SDL_GAMEPAD_AXIS_COUNT;
joystick->nhats = 1;
SDL_PrivateJoystickAddSensor(joystick, SDL_SENSOR_GYRO, update_rate_in_hz);

View File

@@ -1498,7 +1498,7 @@ static bool HIDAPI_DriverSwitch_OpenJoystick(SDL_HIDAPI_Device *device, SDL_Joys
// Initialize the joystick capabilities
joystick->nbuttons = SDL_GAMEPAD_NUM_SWITCH_BUTTONS;
joystick->naxes = SDL_GAMEPAD_AXIS_MAX;
joystick->naxes = SDL_GAMEPAD_AXIS_COUNT;
joystick->nhats = 1;
// Set up for input

View File

@@ -813,7 +813,7 @@ static bool HIDAPI_DriverWii_OpenJoystick(SDL_HIDAPI_Device *device, SDL_Joystic
// Maximum is Classic Controller + Wiimote
joystick->nbuttons = k_eWiiButtons_Max;
}
joystick->naxes = SDL_GAMEPAD_AXIS_MAX;
joystick->naxes = SDL_GAMEPAD_AXIS_COUNT;
ctx->m_ulLastInput = SDL_GetTicks();

View File

@@ -189,7 +189,7 @@ static bool HIDAPI_DriverXbox360_OpenJoystick(SDL_HIDAPI_Device *device, SDL_Joy
// Initialize the joystick capabilities
joystick->nbuttons = 11;
joystick->naxes = SDL_GAMEPAD_AXIS_MAX;
joystick->naxes = SDL_GAMEPAD_AXIS_COUNT;
joystick->nhats = 1;
return true;

View File

@@ -176,7 +176,7 @@ static bool HIDAPI_DriverXbox360W_OpenJoystick(SDL_HIDAPI_Device *device, SDL_Jo
// Initialize the joystick capabilities
joystick->nbuttons = 15;
joystick->naxes = SDL_GAMEPAD_AXIS_MAX;
joystick->naxes = SDL_GAMEPAD_AXIS_COUNT;
return true;
}

View File

@@ -429,7 +429,7 @@ static bool HIDAPI_DriverXboxOne_OpenJoystick(SDL_HIDAPI_Device *device, SDL_Joy
if (ctx->has_paddles) {
joystick->nbuttons += 4;
}
joystick->naxes = SDL_GAMEPAD_AXIS_MAX;
joystick->naxes = SDL_GAMEPAD_AXIS_COUNT;
joystick->nhats = 1;
SDL_AddHintCallback(SDL_HINT_JOYSTICK_HIDAPI_XBOX_ONE_HOME_LED,

View File

@@ -218,7 +218,7 @@ SDL_JoystickID SDL_JoystickAttachVirtualInner(const SDL_VirtualJoystickDesc *des
// Find the trigger axes
axis = 0;
for (i = 0; axis < hwdata->desc.naxes && i < SDL_GAMEPAD_AXIS_MAX; ++i) {
for (i = 0; axis < hwdata->desc.naxes && i < SDL_GAMEPAD_AXIS_COUNT; ++i) {
if (hwdata->desc.axis_mask & (1 << i)) {
if (i == SDL_GAMEPAD_AXIS_LEFT_TRIGGER) {
axis_triggerleft = axis;

View File

@@ -2486,7 +2486,7 @@ typedef struct SDL_WaylandPenTool // a stylus, etc, on a tablet.
float x;
float y;
bool frame_motion_set;
float frame_axes[SDL_PEN_NUM_AXES];
float frame_axes[SDL_PEN_AXIS_COUNT];
Uint32 frame_axes_set;
int frame_pen_down;
int frame_buttons[3];
@@ -2705,7 +2705,7 @@ static void tablet_tool_handle_frame(void *data, struct zwp_tablet_tool_v2 *tool
}
}
for (SDL_PenAxis i = 0; i < SDL_PEN_NUM_AXES; i++) {
for (SDL_PenAxis i = 0; i < SDL_PEN_AXIS_COUNT; i++) {
if (sdltool->frame_axes_set & (1u << i)) {
SDL_SendPenAxis(timestamp, instance_id, window, i, sdltool->frame_axes[i]);
}

View File

@@ -48,7 +48,7 @@
static const char g_MessageBoxFontLatin1[] = "-*-*-medium-r-normal--0-120-*-*-p-0-iso8859-1";
static const char g_MessageBoxFont[] = "-*-*-medium-r-normal--*-120-*-*-*-*-*-*";
static const SDL_MessageBoxColor g_default_colors[SDL_MESSAGEBOX_COLOR_MAX] = {
static const SDL_MessageBoxColor g_default_colors[SDL_MESSAGEBOX_COLOR_COUNT] = {
{ 56, 54, 53 }, // SDL_MESSAGEBOX_COLOR_BACKGROUND,
{ 209, 207, 205 }, // SDL_MESSAGEBOX_COLOR_TEXT,
{ 140, 135, 129 }, // SDL_MESSAGEBOX_COLOR_BUTTON_BORDER,
@@ -110,7 +110,7 @@ typedef struct SDL_MessageBoxDataX11
const SDL_MessageBoxButtonData *buttondata;
SDL_MessageBoxButtonDataX11 buttonpos[MAX_BUTTONS];
Uint32 color[SDL_MESSAGEBOX_COLOR_MAX];
Uint32 color[SDL_MESSAGEBOX_COLOR_COUNT];
const SDL_MessageBoxData *messageboxdata;
} SDL_MessageBoxDataX11;
@@ -216,7 +216,7 @@ static bool X11_MessageBoxInit(SDL_MessageBoxDataX11 *data, const SDL_MessageBox
}
// Convert our SDL_MessageBoxColor r,g,b values to packed RGB format.
for (i = 0; i < SDL_MESSAGEBOX_COLOR_MAX; i++) {
for (i = 0; i < SDL_MESSAGEBOX_COLOR_COUNT; i++) {
data->color[i] = SDL_MAKE_RGB(colorhints[i].r, colorhints[i].g, colorhints[i].b);
}

View File

@@ -249,7 +249,7 @@ static unsigned int GetLegacySystemCursorShape(SDL_SystemCursor id)
case SDL_SYSTEM_CURSOR_S_RESIZE: return XC_bottom_side;
case SDL_SYSTEM_CURSOR_SW_RESIZE: return XC_bottom_left_corner;
case SDL_SYSTEM_CURSOR_W_RESIZE: return XC_left_side;
case SDL_NUM_SYSTEM_CURSORS: break; // so the compiler might notice if an enum value is missing here.
case SDL_SYSTEM_CURSOR_COUNT: break; // so the compiler might notice if an enum value is missing here.
}
SDL_assert(0);

View File

@@ -222,7 +222,7 @@ static X11_PenHandle *X11_MaybeAddPen(SDL_VideoDevice *_this, const XIDeviceInfo
const float min = (float)val_classinfo->min;
const float max = (float)val_classinfo->max;
bool use_this_axis = true;
SDL_PenAxis axis = SDL_PEN_NUM_AXES;
SDL_PenAxis axis = SDL_PEN_AXIS_COUNT;
// afaict, SDL_PEN_AXIS_DISTANCE is never reported by XInput2 (Wayland can offer it, though)
if (vname == data->pen_atom_abs_pressure) {
@@ -336,7 +336,7 @@ void X11_QuitPen(SDL_VideoDevice *_this)
static void X11_XInput2NormalizePenAxes(const X11_PenHandle *pen, float *coords)
{
// Normalise axes
for (int axis = 0; axis < SDL_PEN_NUM_AXES; ++axis) {
for (int axis = 0; axis < SDL_PEN_AXIS_COUNT; ++axis) {
const int valuator = pen->valuator_for_axis[axis];
if (valuator == SDL_X11_PEN_AXIS_VALUATOR_MISSING) {
continue;
@@ -403,9 +403,9 @@ static void X11_XInput2NormalizePenAxes(const X11_PenHandle *pen, float *coords)
void X11_PenAxesFromValuators(const X11_PenHandle *pen,
const double *input_values, const unsigned char *mask, const int mask_len,
float axis_values[SDL_PEN_NUM_AXES])
float axis_values[SDL_PEN_AXIS_COUNT])
{
for (int i = 0; i < SDL_PEN_NUM_AXES; i++) {
for (int i = 0; i < SDL_PEN_AXIS_COUNT; i++) {
const int valuator = pen->valuator_for_axis[i];
if ((valuator == SDL_X11_PEN_AXIS_VALUATOR_MISSING) || (valuator >= mask_len * 8) || !(XIMaskIsSet(mask, valuator))) {
axis_values[i] = 0.0f;

View File

@@ -46,17 +46,17 @@ typedef struct X11_PenHandle
SDL_PenID pen;
bool is_eraser;
int x11_deviceid;
int valuator_for_axis[SDL_PEN_NUM_AXES];
int valuator_for_axis[SDL_PEN_AXIS_COUNT];
float slider_bias; // shift value to add to PEN_AXIS_SLIDER (before normalisation)
float rotation_bias; // rotation to add to PEN_AXIS_ROTATION (after normalisation)
float axis_min[SDL_PEN_NUM_AXES];
float axis_max[SDL_PEN_NUM_AXES];
float axis_min[SDL_PEN_AXIS_COUNT];
float axis_max[SDL_PEN_AXIS_COUNT];
} X11_PenHandle;
// Converts XINPUT2 valuators into pen axis information, including normalisation.
extern void X11_PenAxesFromValuators(const X11_PenHandle *pen,
const double *input_values, const unsigned char *mask, const int mask_len,
float axis_values[SDL_PEN_NUM_AXES]);
float axis_values[SDL_PEN_AXIS_COUNT]);
// Add a pen (if this function's further checks validate it).
extern X11_PenHandle *X11_MaybeAddPenByDeviceID(SDL_VideoDevice *_this, int deviceid);

View File

@@ -458,7 +458,7 @@ void X11_HandleXinput2Event(SDL_VideoDevice *_this, XGenericEventCookie *cookie)
SDL_Window *window = xinput2_get_sdlwindow(videodata, xev->event);
SDL_SendPenMotion(0, pen->pen, window, (float) xev->event_x, (float) xev->event_y);
float axes[SDL_PEN_NUM_AXES];
float axes[SDL_PEN_AXIS_COUNT];
X11_PenAxesFromValuators(pen, xev->valuators.values, xev->valuators.mask, xev->valuators.mask_len, axes);
for (int i = 0; i < SDL_arraysize(axes); i++) {