update SDL3 to latest commit

This commit is contained in:
Sasha Szpakowski
2024-10-06 20:30:44 -03:00
parent 1b0fdc338b
commit 9e5eb1b018
1426 changed files with 242456 additions and 103496 deletions
+25 -26
View File
@@ -125,7 +125,7 @@ SDL_COMPILE_TIME_ASSERT(keyboard_colors, SDL_arraysize(colors) == MAX_KEYBOARDS)
typedef struct
{
SDL_MouseID instance_id;
SDL_bool active;
bool active;
Uint8 button_state;
SDL_FPoint position;
int trail_head;
@@ -138,7 +138,7 @@ static MouseState mice[MAX_MICE];
typedef struct
{
SDL_KeyboardID instance_id;
SDL_bool active;
bool active;
Uint8 button_state;
SDL_FPoint position;
} KeyboardState;
@@ -157,7 +157,7 @@ static SDL_Texture *CreateTexture(const char *image[], SDL_Renderer *renderer)
SDL_memcpy((Uint8 *)surface->pixels + row * surface->pitch, image[4 + row], surface->w);
}
palette = SDL_CreatePalette(256);
palette = SDL_CreateSurfacePalette(surface);
if (!palette) {
SDL_DestroySurface(surface);
return NULL;
@@ -171,10 +171,8 @@ static SDL_Texture *CreateTexture(const char *image[], SDL_Renderer *renderer)
palette->colors['X'].r = 0x00;
palette->colors['X'].g = 0x00;
palette->colors['X'].b = 0x00;
SDL_SetSurfacePalette(surface, palette);
SDL_DestroyPalette(palette);
SDL_SetSurfaceColorKey(surface, SDL_TRUE, ' ');
SDL_SetSurfaceColorKey(surface, true, ' ');
texture = SDL_CreateTextureFromSurface(renderer, surface);
SDL_DestroySurface(surface);
@@ -186,13 +184,13 @@ static void HandleMouseAdded(SDL_MouseID instance_id)
SDL_Window *window = state->windows[0];
int i, w = 0, h = 0;
SDL_GetWindowSize(window, &w, &h);
SDL_GetWindowSizeInPixels(window, &w, &h);
for (i = 0; i < SDL_arraysize(mice); ++i) {
MouseState *mouse_state = &mice[i];
if (!mouse_state->active) {
mouse_state->instance_id = instance_id;
mouse_state->active = SDL_TRUE;
mouse_state->active = true;
mouse_state->position.x = w * 0.5f;
mouse_state->position.y = h * 0.5f;
return;
@@ -239,7 +237,7 @@ static void HandleMouseMotion(SDL_MouseMotionEvent *event)
ActivateMouse(event->which);
SDL_GetWindowSize(window, &w, &h);
SDL_GetWindowSizeInPixels(window, &w, &h);
for (i = 0; i < SDL_arraysize(mice); ++i) {
MouseState *mouse_state = &mice[i];
@@ -287,10 +285,10 @@ static void HandleMouseButton(SDL_MouseButtonEvent *event)
continue;
}
if (event->which == mouse_state->instance_id) {
if (event->state) {
mouse_state->button_state |= SDL_BUTTON(event->button);
if (event->down) {
mouse_state->button_state |= SDL_BUTTON_MASK(event->button);
} else {
mouse_state->button_state &= ~SDL_BUTTON(event->button);
mouse_state->button_state &= ~SDL_BUTTON_MASK(event->button);
}
}
}
@@ -341,7 +339,7 @@ static void HandleKeyboardAdded(SDL_KeyboardID instance_id)
KeyboardState *keyboard_state = &keyboards[i];
if (!keyboard_state->active) {
keyboard_state->instance_id = instance_id;
keyboard_state->active = SDL_TRUE;
keyboard_state->active = true;
keyboard_state->position.x = w * 0.5f;
keyboard_state->position.y = h * 0.5f;
return;
@@ -391,7 +389,7 @@ static void HandleKeyboardKeyDown(SDL_KeyboardEvent *event)
continue;
}
if (event->which == keyboard_state->instance_id) {
switch (event->keysym.sym) {
switch (event->key) {
case SDLK_LEFT:
keyboard_state->position.x -= CURSOR_SIZE;
if (keyboard_state->position.x < 0.0f) {
@@ -401,7 +399,7 @@ static void HandleKeyboardKeyDown(SDL_KeyboardEvent *event)
case SDLK_RIGHT:
keyboard_state->position.x += CURSOR_SIZE;
if (keyboard_state->position.x > w) {
keyboard_state->position.x = w;
keyboard_state->position.x = (float)w;
}
break;
case SDLK_UP:
@@ -413,7 +411,7 @@ static void HandleKeyboardKeyDown(SDL_KeyboardEvent *event)
case SDLK_DOWN:
keyboard_state->position.y += CURSOR_SIZE;
if (keyboard_state->position.y > h) {
keyboard_state->position.y = h;
keyboard_state->position.y = (float)h;
}
break;
default:
@@ -479,8 +477,8 @@ static void loop(void)
for (i = 0; i < state->num_windows; ++i) {
SDL_Window *window = state->windows[i];
SDL_Renderer *renderer = state->renderers[i];
SDL_Texture *arrow_cursor = (SDL_Texture *)SDL_GetProperty(SDL_GetRendererProperties(renderer), PROP_ARROW_CURSOR_TEXTURE, NULL);
SDL_Texture *cross_cursor = (SDL_Texture *)SDL_GetProperty(SDL_GetRendererProperties(renderer), PROP_CROSS_CURSOR_TEXTURE, NULL);
SDL_Texture *arrow_cursor = (SDL_Texture *)SDL_GetPointerProperty(SDL_GetRendererProperties(renderer), PROP_ARROW_CURSOR_TEXTURE, NULL);
SDL_Texture *cross_cursor = (SDL_Texture *)SDL_GetPointerProperty(SDL_GetRendererProperties(renderer), PROP_CROSS_CURSOR_TEXTURE, NULL);
SDL_SetRenderDrawColor(renderer, 128, 128, 128, 255);
SDL_RenderClear(renderer);
@@ -501,12 +499,12 @@ int main(int argc, char *argv[])
{
int i;
/* Enable standard application logging */
SDL_LogSetPriority(SDL_LOG_CATEGORY_APPLICATION, SDL_LOG_PRIORITY_INFO);
/* Log all events, including mouse motion */
SDL_SetHint(SDL_HINT_EVENT_LOGGING, "2");
/* Support for multiple keyboards requires raw keyboard events on Windows */
SDL_SetHint(SDL_HINT_WINDOWS_RAW_KEYBOARD, "1");
/* Initialize test framework */
state = SDLTest_CommonCreateState(argv, SDL_INIT_VIDEO);
if (!state) {
@@ -521,6 +519,7 @@ int main(int argc, char *argv[])
SDLTest_CommonQuit(state);
return 1;
}
i += consumed;
}
if (!SDLTest_CommonInit(state)) {
@@ -534,12 +533,12 @@ int main(int argc, char *argv[])
SDL_Texture *cursor_arrow = CreateTexture(arrow, renderer);
SDL_Texture *cursor_cross = CreateTexture(cross, renderer);
SDL_SetProperty(SDL_GetRendererProperties(renderer), PROP_ARROW_CURSOR_TEXTURE, cursor_arrow);
SDL_SetProperty(SDL_GetRendererProperties(renderer), PROP_CROSS_CURSOR_TEXTURE, cursor_cross);
}
SDL_SetPointerProperty(SDL_GetRendererProperties(renderer), PROP_ARROW_CURSOR_TEXTURE, cursor_arrow);
SDL_SetPointerProperty(SDL_GetRendererProperties(renderer), PROP_CROSS_CURSOR_TEXTURE, cursor_cross);
/* We only get mouse motion for distinct devices when relative mode is enabled */
SDL_SetRelativeMouseMode(SDL_TRUE);
/* We only get mouse motion for distinct devices when relative mode is enabled */
SDL_SetWindowRelativeMouseMode(state->windows[i], true);
}
/* Main render loop */
done = 0;