Replace tri-state functions SDL_EventState(), SDL_GetJoystickEventState(), SDL_GetGamepadEventState(), SDL_ShowCursor()

`SDL_QUERY`, `SDL_IGNORE`, `SDL_ENABLE`, and `SDL_DISABLE` have been removed.

SDL_EventState() has been replaced with SDL_SetEventEnabled()
SDL_GetEventState() has been replaced with SDL_EventEnabled()
SDL_GameControllerEventState has been replaced with SDL_SetGamepadEventsEnabled() and SDL_GamepadEventsEnabled()
SDL_JoystickEventState has been replaced with SDL_SetJoystickEventsEnabled() and SDL_JoystickEventsEnabled()

SDL_ShowCursor() has been split into three functions: SDL_ShowCursor(), SDL_HideCursor(), and SDL_CursorVisible()

Fixes https://github.com/libsdl-org/SDL/issues/6929
This commit is contained in:
Sam Lantinga
2022-12-28 17:06:38 -08:00
parent 9b8208c195
commit 66351fd4ba
36 changed files with 357 additions and 319 deletions

View File

@@ -247,24 +247,22 @@ int mouse_createFreeColorCursor(void *arg)
}
/* Helper that changes cursor visibility */
void _changeCursorVisibility(int state)
void _changeCursorVisibility(SDL_bool state)
{
int oldState;
int newState;
int result;
SDL_bool newState;
oldState = SDL_ShowCursor(SDL_QUERY);
SDLTest_AssertPass("Call to SDL_ShowCursor(SDL_QUERY)");
if (state) {
SDL_ShowCursor();
} else {
SDL_HideCursor();
}
SDLTest_AssertPass("Call to %s", state ? "SDL_ShowCursor()" : "SDL_HideCursor()");
result = SDL_ShowCursor(state);
SDLTest_AssertPass("Call to SDL_ShowCursor(%s)", (state == SDL_ENABLE) ? "SDL_ENABLE" : "SDL_DISABLE");
SDLTest_AssertCheck(result == oldState, "Validate result from SDL_ShowCursor(%s), expected: %i, got: %i",
(state == SDL_ENABLE) ? "SDL_ENABLE" : "SDL_DISABLE", oldState, result);
newState = SDL_ShowCursor(SDL_QUERY);
SDLTest_AssertPass("Call to SDL_ShowCursor(SDL_QUERY)");
SDLTest_AssertCheck(state == newState, "Validate new state, expected: %i, got: %i",
state, newState);
newState = SDL_CursorVisible();
SDLTest_AssertPass("Call to SDL_CursorVisible()");
SDLTest_AssertCheck(state == newState, "Validate new state, expected: %s, got: %s",
state ? "SDL_TRUE" : "SDL_FALSE",
newState ? "SDL_TRUE" : "SDL_FALSE");
}
/**
@@ -274,23 +272,19 @@ void _changeCursorVisibility(int state)
*/
int mouse_showCursor(void *arg)
{
int currentState;
SDL_bool currentState;
/* Get current state */
currentState = SDL_ShowCursor(SDL_QUERY);
SDLTest_AssertPass("Call to SDL_ShowCursor(SDL_QUERY)");
SDLTest_AssertCheck(currentState == SDL_DISABLE || currentState == SDL_ENABLE,
"Validate result is %i or %i, got: %i", SDL_DISABLE, SDL_ENABLE, currentState);
if (currentState == SDL_DISABLE) {
/* Show the cursor, then hide it again */
_changeCursorVisibility(SDL_ENABLE);
_changeCursorVisibility(SDL_DISABLE);
} else if (currentState == SDL_ENABLE) {
currentState = SDL_CursorVisible();
SDLTest_AssertPass("Call to SDL_CursorVisible()");
if (currentState) {
/* Hide the cursor, then show it again */
_changeCursorVisibility(SDL_DISABLE);
_changeCursorVisibility(SDL_ENABLE);
_changeCursorVisibility(SDL_FALSE);
_changeCursorVisibility(SDL_TRUE);
} else {
return TEST_ABORTED;
/* Show the cursor, then hide it again */
_changeCursorVisibility(SDL_TRUE);
_changeCursorVisibility(SDL_FALSE);
}
return TEST_COMPLETED;

View File

@@ -137,7 +137,7 @@ static SDL_Cursor *cursors[1 + SDL_NUM_SYSTEM_CURSORS];
static SDL_SystemCursor cursor_types[1 + SDL_NUM_SYSTEM_CURSORS];
static int num_cursors;
static int current_cursor;
static int show_cursor;
static SDL_bool show_cursor;
/* Call this instead of exit(), so we can clean up SDL: atexit() is evil. */
static void
@@ -214,7 +214,11 @@ void loop()
} else {
show_cursor = !show_cursor;
SDL_ShowCursor(show_cursor);
if (show_cursor) {
SDL_ShowCursor();
} else {
SDL_HideCursor();
}
}
}
}
@@ -300,7 +304,7 @@ int main(int argc, char *argv[])
SDL_SetCursor(cursors[0]);
}
show_cursor = SDL_ShowCursor(SDL_QUERY);
show_cursor = SDL_CursorVisible();
/* Main render loop */
done = 0;

View File

@@ -67,7 +67,7 @@ int main(int argc, char *argv[])
SDL_RenderPresent(renderer);
}
SDL_EventState(SDL_DROPFILE, SDL_ENABLE);
SDL_SetEventEnabled(SDL_DROPFILE, SDL_TRUE);
/* Main render loop */
done = 0;

View File

@@ -492,7 +492,7 @@ int main(int argc, char **argv)
displayrect.h = window_h;
/* Ignore key up events, they don't even get filtered */
SDL_EventState(SDL_KEYUP, SDL_IGNORE);
SDL_SetEventEnabled(SDL_KEYUP, SDL_FALSE);
/* Main render loop */
frames = 0;

View File

@@ -269,8 +269,8 @@ int main(int argc, char *argv[])
return 1;
}
SDL_EventState(SDL_DROPFILE, SDL_ENABLE);
SDL_EventState(SDL_DROPTEXT, SDL_ENABLE);
SDL_SetEventEnabled(SDL_DROPFILE, SDL_TRUE);
SDL_SetEventEnabled(SDL_DROPTEXT, SDL_TRUE);
for (i = 0; i < state->num_windows; ++i) {
SDL_Renderer *renderer = state->renderers[i];