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:
parent
64f12bea4a
commit
37c9fb490e
49 changed files with 197 additions and 174 deletions
|
@ -293,7 +293,7 @@ int GetGamepadImageElementAt(GamepadImage *ctx, float x, float y)
|
|||
|
||||
if (ctx->showing_front) {
|
||||
for (i = 0; i < SDL_arraysize(axis_positions); ++i) {
|
||||
const int element = SDL_GAMEPAD_BUTTON_MAX + i;
|
||||
const int element = SDL_GAMEPAD_BUTTON_COUNT + i;
|
||||
SDL_FRect rect;
|
||||
|
||||
if (element == SDL_GAMEPAD_ELEMENT_AXIS_LEFT_TRIGGER ||
|
||||
|
@ -431,7 +431,7 @@ void UpdateGamepadImageFromGamepad(GamepadImage *ctx, SDL_Gamepad *gamepad)
|
|||
SetGamepadImageElement(ctx, button, SDL_GetGamepadButton(gamepad, button));
|
||||
}
|
||||
|
||||
for (i = 0; i < SDL_GAMEPAD_AXIS_MAX; ++i) {
|
||||
for (i = 0; i < SDL_GAMEPAD_AXIS_COUNT; ++i) {
|
||||
const SDL_GamepadAxis axis = (SDL_GamepadAxis)i;
|
||||
const Sint16 deadzone = 8000; /* !!! FIXME: real deadzone */
|
||||
const Sint16 value = SDL_GetGamepadAxis(gamepad, axis);
|
||||
|
@ -553,7 +553,7 @@ void RenderGamepadImage(GamepadImage *ctx)
|
|||
|
||||
if (ctx->showing_front) {
|
||||
for (i = 0; i < SDL_arraysize(axis_positions); ++i) {
|
||||
const int element = SDL_GAMEPAD_BUTTON_MAX + i;
|
||||
const int element = SDL_GAMEPAD_BUTTON_COUNT + i;
|
||||
if (ctx->elements[element]) {
|
||||
const double angle = axis_positions[i].angle;
|
||||
dst.w = ctx->axis_width;
|
||||
|
@ -676,7 +676,7 @@ static const char *gamepad_button_names[] = {
|
|||
"Misc5",
|
||||
"Misc6",
|
||||
};
|
||||
SDL_COMPILE_TIME_ASSERT(gamepad_button_names, SDL_arraysize(gamepad_button_names) == SDL_GAMEPAD_BUTTON_MAX);
|
||||
SDL_COMPILE_TIME_ASSERT(gamepad_button_names, SDL_arraysize(gamepad_button_names) == SDL_GAMEPAD_BUTTON_COUNT);
|
||||
|
||||
static const char *gamepad_axis_names[] = {
|
||||
"LeftX",
|
||||
|
@ -686,7 +686,7 @@ static const char *gamepad_axis_names[] = {
|
|||
"Left Trigger",
|
||||
"Right Trigger",
|
||||
};
|
||||
SDL_COMPILE_TIME_ASSERT(gamepad_axis_names, SDL_arraysize(gamepad_axis_names) == SDL_GAMEPAD_AXIS_MAX);
|
||||
SDL_COMPILE_TIME_ASSERT(gamepad_axis_names, SDL_arraysize(gamepad_axis_names) == SDL_GAMEPAD_AXIS_COUNT);
|
||||
|
||||
struct GamepadDisplay
|
||||
{
|
||||
|
@ -915,7 +915,7 @@ int GetGamepadDisplayElementAt(GamepadDisplay *ctx, SDL_Gamepad *gamepad, float
|
|||
rect.w = ctx->area.w - (margin * 2);
|
||||
rect.h = ctx->button_height;
|
||||
|
||||
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 (ctx->display_mode == CONTROLLER_MODE_TESTING &&
|
||||
|
@ -931,7 +931,7 @@ int GetGamepadDisplayElementAt(GamepadDisplay *ctx, SDL_Gamepad *gamepad, float
|
|||
rect.y += ctx->button_height + 2.0f;
|
||||
}
|
||||
|
||||
for (i = 0; i < SDL_GAMEPAD_AXIS_MAX; ++i) {
|
||||
for (i = 0; i < SDL_GAMEPAD_AXIS_COUNT; ++i) {
|
||||
SDL_GamepadAxis axis = (SDL_GamepadAxis)i;
|
||||
SDL_FRect area;
|
||||
|
||||
|
@ -1033,7 +1033,7 @@ void RenderGamepadDisplay(GamepadDisplay *ctx, SDL_Gamepad *gamepad)
|
|||
x = ctx->area.x + margin;
|
||||
y = ctx->area.y + margin;
|
||||
|
||||
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 (ctx->display_mode == CONTROLLER_MODE_TESTING &&
|
||||
|
@ -1072,7 +1072,7 @@ void RenderGamepadDisplay(GamepadDisplay *ctx, SDL_Gamepad *gamepad)
|
|||
y += ctx->button_height + 2.0f;
|
||||
}
|
||||
|
||||
for (i = 0; i < SDL_GAMEPAD_AXIS_MAX; ++i) {
|
||||
for (i = 0; i < SDL_GAMEPAD_AXIS_COUNT; ++i) {
|
||||
SDL_GamepadAxis axis = (SDL_GamepadAxis)i;
|
||||
SDL_bool has_negative = (axis != SDL_GAMEPAD_AXIS_LEFT_TRIGGER && axis != SDL_GAMEPAD_AXIS_RIGHT_TRIGGER);
|
||||
Sint16 value;
|
||||
|
@ -1376,7 +1376,7 @@ int GetGamepadTypeDisplayAt(GamepadTypeDisplay *ctx, float x, float y)
|
|||
x = ctx->area.x + margin;
|
||||
y = ctx->area.y + margin;
|
||||
|
||||
for (i = SDL_GAMEPAD_TYPE_UNKNOWN; i < SDL_GAMEPAD_TYPE_MAX; ++i) {
|
||||
for (i = SDL_GAMEPAD_TYPE_UNKNOWN; i < SDL_GAMEPAD_TYPE_COUNT; ++i) {
|
||||
highlight.x = x;
|
||||
highlight.y = y;
|
||||
highlight.w = ctx->area.w - (margin * 2);
|
||||
|
@ -1430,7 +1430,7 @@ void RenderGamepadTypeDisplay(GamepadTypeDisplay *ctx)
|
|||
x = ctx->area.x + margin;
|
||||
y = ctx->area.y + margin;
|
||||
|
||||
for (i = SDL_GAMEPAD_TYPE_UNKNOWN; i < SDL_GAMEPAD_TYPE_MAX; ++i) {
|
||||
for (i = SDL_GAMEPAD_TYPE_UNKNOWN; i < SDL_GAMEPAD_TYPE_COUNT; ++i) {
|
||||
highlight.x = x;
|
||||
highlight.y = y;
|
||||
highlight.w = ctx->area.w - (margin * 2);
|
||||
|
@ -2662,14 +2662,14 @@ SDL_bool MappingHasBindings(const char *mapping)
|
|||
}
|
||||
|
||||
SplitMapping(mapping, &parts);
|
||||
for (i = 0; i < SDL_GAMEPAD_BUTTON_MAX; ++i) {
|
||||
for (i = 0; i < SDL_GAMEPAD_BUTTON_COUNT; ++i) {
|
||||
if (FindMappingKey(&parts, SDL_GetGamepadStringForButton((SDL_GamepadButton)i)) >= 0) {
|
||||
result = SDL_TRUE;
|
||||
break;
|
||||
}
|
||||
}
|
||||
if (!result) {
|
||||
for (i = 0; i < SDL_GAMEPAD_AXIS_MAX; ++i) {
|
||||
for (i = 0; i < SDL_GAMEPAD_AXIS_COUNT; ++i) {
|
||||
if (FindMappingKey(&parts, SDL_GetGamepadStringForAxis((SDL_GamepadAxis)i)) >= 0) {
|
||||
result = SDL_TRUE;
|
||||
break;
|
||||
|
@ -2795,7 +2795,7 @@ char *SetMappingType(char *mapping, SDL_GamepadType type)
|
|||
|
||||
static const char *GetElementKey(int element)
|
||||
{
|
||||
if (element < SDL_GAMEPAD_BUTTON_MAX) {
|
||||
if (element < SDL_GAMEPAD_BUTTON_COUNT) {
|
||||
return SDL_GetGamepadStringForButton((SDL_GamepadButton)element);
|
||||
} else {
|
||||
static char key[16];
|
||||
|
|
|
@ -26,7 +26,7 @@ enum
|
|||
|
||||
/* ... SDL_GamepadButton ... */
|
||||
|
||||
SDL_GAMEPAD_ELEMENT_AXIS_LEFTX_NEGATIVE = SDL_GAMEPAD_BUTTON_MAX,
|
||||
SDL_GAMEPAD_ELEMENT_AXIS_LEFTX_NEGATIVE = SDL_GAMEPAD_BUTTON_COUNT,
|
||||
SDL_GAMEPAD_ELEMENT_AXIS_LEFTX_POSITIVE,
|
||||
SDL_GAMEPAD_ELEMENT_AXIS_LEFTY_NEGATIVE,
|
||||
SDL_GAMEPAD_ELEMENT_AXIS_LEFTY_POSITIVE,
|
||||
|
|
|
@ -29,8 +29,8 @@ static int SDLCALL TestVirtualJoystick(void *arg)
|
|||
|
||||
SDL_INIT_INTERFACE(&desc);
|
||||
desc.type = SDL_JOYSTICK_TYPE_GAMEPAD;
|
||||
desc.naxes = SDL_GAMEPAD_AXIS_MAX;
|
||||
desc.nbuttons = SDL_GAMEPAD_BUTTON_MAX;
|
||||
desc.naxes = SDL_GAMEPAD_AXIS_COUNT;
|
||||
desc.nbuttons = SDL_GAMEPAD_BUTTON_COUNT;
|
||||
desc.vendor_id = USB_VENDOR_NVIDIA;
|
||||
desc.product_id = USB_PRODUCT_NVIDIA_SHIELD_CONTROLLER_V104;
|
||||
desc.name = "Virtual NVIDIA SHIELD Controller";
|
||||
|
|
|
@ -223,7 +223,7 @@ static int SDLCALL keyboard_getScancodeNameNegative(void *arg)
|
|||
SDLTest_AssertPass("Call to SDL_ClearError()");
|
||||
|
||||
/* Out-of-bounds scancode */
|
||||
scancode = (SDL_Scancode)SDL_NUM_SCANCODES;
|
||||
scancode = (SDL_Scancode)SDL_SCANCODE_COUNT;
|
||||
result = SDL_GetScancodeName(scancode);
|
||||
SDLTest_AssertPass("Call to SDL_GetScancodeName(%d/large)", scancode);
|
||||
SDLTest_AssertCheck(result != NULL, "Verify result from call is not NULL");
|
||||
|
|
|
@ -479,8 +479,8 @@ static void CommitBindingElement(const char *binding, SDL_bool force)
|
|||
/* If the controller generates multiple events for a single element, pick the best one */
|
||||
if (!force && binding_advance_time) {
|
||||
char *current = GetElementBinding(mapping, binding_element);
|
||||
SDL_bool native_button = (binding_element < SDL_GAMEPAD_BUTTON_MAX);
|
||||
SDL_bool native_axis = (binding_element >= SDL_GAMEPAD_BUTTON_MAX &&
|
||||
SDL_bool native_button = (binding_element < SDL_GAMEPAD_BUTTON_COUNT);
|
||||
SDL_bool native_axis = (binding_element >= SDL_GAMEPAD_BUTTON_COUNT &&
|
||||
binding_element <= SDL_GAMEPAD_ELEMENT_AXIS_MAX);
|
||||
SDL_bool native_trigger = (binding_element == SDL_GAMEPAD_ELEMENT_AXIS_LEFT_TRIGGER ||
|
||||
binding_element == SDL_GAMEPAD_ELEMENT_AXIS_RIGHT_TRIGGER);
|
||||
|
@ -1161,8 +1161,8 @@ static void OpenVirtualGamepad(void)
|
|||
|
||||
SDL_INIT_INTERFACE(&desc);
|
||||
desc.type = SDL_JOYSTICK_TYPE_GAMEPAD;
|
||||
desc.naxes = SDL_GAMEPAD_AXIS_MAX;
|
||||
desc.nbuttons = SDL_GAMEPAD_BUTTON_MAX;
|
||||
desc.naxes = SDL_GAMEPAD_AXIS_COUNT;
|
||||
desc.nbuttons = SDL_GAMEPAD_BUTTON_COUNT;
|
||||
desc.ntouchpads = 1;
|
||||
desc.touchpads = &virtual_touchpad;
|
||||
desc.nsensors = 1;
|
||||
|
@ -1269,7 +1269,7 @@ static void VirtualGamepadMouseDown(float x, float y)
|
|||
return;
|
||||
}
|
||||
|
||||
if (element < SDL_GAMEPAD_BUTTON_MAX) {
|
||||
if (element < SDL_GAMEPAD_BUTTON_COUNT) {
|
||||
virtual_button_active = (SDL_GamepadButton)element;
|
||||
SDL_SetJoystickVirtualButton(virtual_joystick, virtual_button_active, SDL_TRUE);
|
||||
} else {
|
||||
|
|
|
@ -219,8 +219,8 @@ static SDL_Cursor *init_system_cursor(const char *image[])
|
|||
|
||||
static SDLTest_CommonState *state;
|
||||
static int done;
|
||||
static SDL_Cursor *cursors[3 + SDL_NUM_SYSTEM_CURSORS];
|
||||
static SDL_SystemCursor cursor_types[3 + SDL_NUM_SYSTEM_CURSORS];
|
||||
static SDL_Cursor *cursors[3 + SDL_SYSTEM_CURSOR_COUNT];
|
||||
static SDL_SystemCursor cursor_types[3 + SDL_SYSTEM_CURSOR_COUNT];
|
||||
static int num_cursors;
|
||||
static int current_cursor;
|
||||
static SDL_bool show_cursor;
|
||||
|
@ -437,7 +437,7 @@ int main(int argc, char *argv[])
|
|||
num_cursors++;
|
||||
}
|
||||
|
||||
for (i = 0; i < SDL_NUM_SYSTEM_CURSORS; ++i) {
|
||||
for (i = 0; i < SDL_SYSTEM_CURSOR_COUNT; ++i) {
|
||||
cursor = SDL_CreateSystemCursor((SDL_SystemCursor)i);
|
||||
if (cursor) {
|
||||
cursors[num_cursors] = cursor;
|
||||
|
|
|
@ -41,7 +41,7 @@ int main(int argc, char *argv[])
|
|||
SDL_LogError(SDL_LOG_CATEGORY_APPLICATION, "Couldn't initialize SDL: %s\n", SDL_GetError());
|
||||
exit(1);
|
||||
}
|
||||
for (scancode = 0; scancode < SDL_NUM_SCANCODES; ++scancode) {
|
||||
for (scancode = 0; scancode < SDL_SCANCODE_COUNT; ++scancode) {
|
||||
SDL_Log("Scancode #%d, \"%s\"\n", scancode,
|
||||
SDL_GetScancodeName(scancode));
|
||||
}
|
||||
|
|
|
@ -19,7 +19,7 @@ typedef struct Pen
|
|||
{
|
||||
SDL_PenID pen;
|
||||
Uint8 r, g, b;
|
||||
float axes[SDL_PEN_NUM_AXES];
|
||||
float axes[SDL_PEN_AXIS_COUNT];
|
||||
float x;
|
||||
float y;
|
||||
Uint32 buttons;
|
||||
|
|
|
@ -43,7 +43,7 @@ static const char *cursorNames[] = {
|
|||
"window bottom left",
|
||||
"window left"
|
||||
};
|
||||
SDL_COMPILE_TIME_ASSERT(cursorNames, SDL_arraysize(cursorNames) == SDL_NUM_SYSTEM_CURSORS);
|
||||
SDL_COMPILE_TIME_ASSERT(cursorNames, SDL_arraysize(cursorNames) == SDL_SYSTEM_CURSOR_COUNT);
|
||||
|
||||
static int system_cursor = -1;
|
||||
static SDL_Cursor *cursor = NULL;
|
||||
|
@ -193,12 +193,12 @@ static void loop(void)
|
|||
} else if (event.key.key == SDLK_LEFT) {
|
||||
--system_cursor;
|
||||
if (system_cursor < 0) {
|
||||
system_cursor = SDL_NUM_SYSTEM_CURSORS - 1;
|
||||
system_cursor = SDL_SYSTEM_CURSOR_COUNT - 1;
|
||||
}
|
||||
updateCursor = SDL_TRUE;
|
||||
} else if (event.key.key == SDLK_RIGHT) {
|
||||
++system_cursor;
|
||||
if (system_cursor >= SDL_NUM_SYSTEM_CURSORS) {
|
||||
if (system_cursor >= SDL_SYSTEM_CURSOR_COUNT) {
|
||||
system_cursor = 0;
|
||||
}
|
||||
updateCursor = SDL_TRUE;
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue