update SDL3 from 3.2.20 to 3.4.2
This commit is contained in:
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
Copyright (C) 1997-2025 Sam Lantinga <slouken@libsdl.org>
|
||||
Copyright (C) 1997-2026 Sam Lantinga <slouken@libsdl.org>
|
||||
|
||||
This software is provided 'as-is', without any express or implied
|
||||
warranty. In no event will the authors be held liable for any damages
|
||||
@@ -106,12 +106,12 @@ static const char *cross[] = {
|
||||
" ",
|
||||
" ",
|
||||
" ",
|
||||
"0,0"
|
||||
"16,16"
|
||||
};
|
||||
|
||||
static SDL_Surface *load_image_file(const char *file)
|
||||
{
|
||||
SDL_Surface *surface = SDL_LoadBMP(file);
|
||||
SDL_Surface *surface = SDL_LoadSurface(file);
|
||||
if (surface) {
|
||||
if (SDL_GetSurfacePalette(surface)) {
|
||||
const Uint8 bpp = SDL_BITSPERPIXEL(surface->format);
|
||||
@@ -168,14 +168,36 @@ static SDL_Surface *load_image(const char *file)
|
||||
return surface;
|
||||
}
|
||||
|
||||
static SDL_Cursor *init_color_cursor(const char *file)
|
||||
static SDL_Cursor *init_color_cursor(char **files, int num_frames)
|
||||
{
|
||||
SDL_Cursor *cursor = NULL;
|
||||
SDL_Surface *surface = load_image(file);
|
||||
if (surface) {
|
||||
cursor = SDL_CreateColorCursor(surface, 0, 0);
|
||||
SDL_DestroySurface(surface);
|
||||
SDL_CursorFrameInfo *frames = (SDL_CursorFrameInfo *)SDL_calloc(num_frames, sizeof(SDL_CursorFrameInfo));
|
||||
int i;
|
||||
|
||||
for (i = 0; i < num_frames; i++) {
|
||||
SDL_Surface *img = load_image(files[i]);
|
||||
if (!img) {
|
||||
SDL_LogWarn(SDL_LOG_CATEGORY_TEST, "Failed to load %s", files[i]);
|
||||
goto cleanup;
|
||||
}
|
||||
frames[i].surface = img;
|
||||
if (i > 0) {
|
||||
frames[i].duration = 150;
|
||||
}
|
||||
}
|
||||
|
||||
if (num_frames == 1) {
|
||||
cursor = SDL_CreateColorCursor(frames[0].surface, 0, 0);
|
||||
} else {
|
||||
cursor = SDL_CreateAnimatedCursor(frames, num_frames, 0, 0);
|
||||
}
|
||||
|
||||
cleanup:
|
||||
for (i = 0; i < num_frames; ++i) {
|
||||
SDL_DestroySurface(frames[i].surface);
|
||||
}
|
||||
SDL_free(frames);
|
||||
|
||||
return cursor;
|
||||
}
|
||||
|
||||
@@ -217,10 +239,83 @@ static SDL_Cursor *init_system_cursor(const char *image[])
|
||||
return SDL_CreateCursor(data, mask, 32, 32, hot_x, hot_y);
|
||||
}
|
||||
|
||||
static SDL_Cursor *init_animated_cursor(const char *image[], bool oneshot)
|
||||
{
|
||||
int row, col;
|
||||
SDL_Surface *surface, *invsurface;
|
||||
Uint32 *pixels, *invpixels;
|
||||
SDL_CursorFrameInfo frames[6];
|
||||
int hot_x = 0;
|
||||
int hot_y = 0;
|
||||
|
||||
surface = SDL_CreateSurface(32, 32, SDL_PIXELFORMAT_ARGB8888);
|
||||
if (!surface) {
|
||||
return NULL;
|
||||
}
|
||||
|
||||
invsurface = SDL_CreateSurface(32, 32, SDL_PIXELFORMAT_ARGB8888);
|
||||
if (!invsurface) {
|
||||
SDL_DestroySurface(surface);
|
||||
return NULL;
|
||||
}
|
||||
|
||||
for (row = 4; row < 36; ++row) {
|
||||
pixels = (Uint32 *)((Uint8 *)surface->pixels + ((row - 4) * surface->pitch));
|
||||
invpixels = (Uint32 *)((Uint8 *)invsurface->pixels + ((row - 4) * surface->pitch));
|
||||
for (col = 0; col < 32; ++col) {
|
||||
switch (image[row][col]) {
|
||||
case 'X':
|
||||
pixels[col] = 0xFFFFFFFF;
|
||||
invpixels[col] = 0xFF000000;
|
||||
break;
|
||||
case '.':
|
||||
pixels[col] = 0xFF000000;
|
||||
invpixels[col] = 0xFFFFFFFF;
|
||||
break;
|
||||
case ' ':
|
||||
pixels[col] = 0;
|
||||
invpixels[col] = 0;
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
int frame_count = 2;
|
||||
|
||||
frames[0].surface = surface;
|
||||
frames[0].duration = 100;
|
||||
|
||||
frames[1].surface = invsurface;
|
||||
frames[1].duration = 100;
|
||||
|
||||
if (oneshot) {
|
||||
frames[2].surface = surface;
|
||||
frames[2].duration = 200;
|
||||
|
||||
frames[3].surface = invsurface;
|
||||
frames[3].duration = 300;
|
||||
|
||||
frames[4].surface = surface;
|
||||
frames[4].duration = 400;
|
||||
|
||||
frames[5].surface = invsurface;
|
||||
frames[5].duration = 0;
|
||||
|
||||
frame_count = 6;
|
||||
}
|
||||
|
||||
SDL_Cursor *cursor = SDL_CreateAnimatedCursor(frames, frame_count, hot_x, hot_y);
|
||||
|
||||
SDL_DestroySurface(surface);
|
||||
SDL_DestroySurface(invsurface);
|
||||
|
||||
return cursor;
|
||||
}
|
||||
|
||||
static SDLTest_CommonState *state;
|
||||
static int done;
|
||||
static SDL_Cursor *cursors[3 + SDL_SYSTEM_CURSOR_COUNT];
|
||||
static SDL_SystemCursor cursor_types[3 + SDL_SYSTEM_CURSOR_COUNT];
|
||||
static SDL_Cursor *cursors[5 + SDL_SYSTEM_CURSOR_COUNT];
|
||||
static SDL_SystemCursor cursor_types[5 + SDL_SYSTEM_CURSOR_COUNT];
|
||||
static int num_cursors;
|
||||
static int current_cursor;
|
||||
static bool show_cursor;
|
||||
@@ -257,6 +352,12 @@ static void loop(void)
|
||||
SDL_SetCursor(cursors[current_cursor]);
|
||||
|
||||
switch ((int)cursor_types[current_cursor]) {
|
||||
case (SDL_SystemCursor)-3:
|
||||
SDL_Log("Animated custom cursor (one-shot)");
|
||||
break;
|
||||
case (SDL_SystemCursor)-2:
|
||||
SDL_Log("Animated custom cursor");
|
||||
break;
|
||||
case (SDL_SystemCursor)-1:
|
||||
SDL_Log("Custom cursor");
|
||||
break;
|
||||
@@ -374,7 +475,8 @@ static void loop(void)
|
||||
int main(int argc, char *argv[])
|
||||
{
|
||||
int i;
|
||||
const char *color_cursor = NULL;
|
||||
char **frames = NULL;
|
||||
int num_frames = -1;
|
||||
SDL_Cursor *cursor;
|
||||
|
||||
/* Initialize test framework */
|
||||
@@ -388,11 +490,18 @@ int main(int argc, char *argv[])
|
||||
|
||||
consumed = SDLTest_CommonArg(state, i);
|
||||
if (consumed == 0) {
|
||||
color_cursor = argv[i];
|
||||
break;
|
||||
if (SDL_strcmp(argv[i], "--frames") == 0 && frames == NULL) {
|
||||
num_frames = 0;
|
||||
while (i + 1 + num_frames < argc && argv[i + 1 + num_frames][0] != '-') {
|
||||
num_frames += 1;
|
||||
}
|
||||
frames = &argv[i + 1];
|
||||
consumed = num_frames + 1;
|
||||
}
|
||||
}
|
||||
if (consumed < 0) {
|
||||
SDLTest_CommonLogUsage(state, argv[0], NULL);
|
||||
if (consumed <= 0) {
|
||||
static const char *options[] = { "[--frames frame0.bmp [frame1.bmp [frame2.bmp ...]]]", NULL};
|
||||
SDLTest_CommonLogUsage(state, argv[0], options);
|
||||
quit(1);
|
||||
}
|
||||
i += consumed;
|
||||
@@ -404,8 +513,9 @@ int main(int argc, char *argv[])
|
||||
|
||||
num_cursors = 0;
|
||||
|
||||
if (color_cursor) {
|
||||
SDL_Surface *icon = load_image(color_cursor);
|
||||
if (num_frames > 0) {
|
||||
/* Only load the first file in the list for the icon. */
|
||||
SDL_Surface *icon = load_image(frames[0]);
|
||||
if (icon) {
|
||||
for (i = 0; i < state->num_windows; ++i) {
|
||||
SDL_SetWindowIcon(state->windows[i], icon);
|
||||
@@ -413,7 +523,7 @@ int main(int argc, char *argv[])
|
||||
SDL_DestroySurface(icon);
|
||||
}
|
||||
|
||||
cursor = init_color_cursor(color_cursor);
|
||||
cursor = init_color_cursor(frames, num_frames);
|
||||
if (cursor) {
|
||||
cursors[num_cursors] = cursor;
|
||||
cursor_types[num_cursors] = (SDL_SystemCursor)-1;
|
||||
@@ -435,6 +545,20 @@ int main(int argc, char *argv[])
|
||||
num_cursors++;
|
||||
}
|
||||
|
||||
cursor = init_animated_cursor(arrow, false);
|
||||
if (cursor) {
|
||||
cursors[num_cursors] = cursor;
|
||||
cursor_types[num_cursors] = (SDL_SystemCursor)-2;
|
||||
num_cursors++;
|
||||
}
|
||||
|
||||
cursor = init_animated_cursor(arrow, true);
|
||||
if (cursor) {
|
||||
cursors[num_cursors] = cursor;
|
||||
cursor_types[num_cursors] = (SDL_SystemCursor)-3;
|
||||
num_cursors++;
|
||||
}
|
||||
|
||||
for (i = 0; i < SDL_SYSTEM_CURSOR_COUNT; ++i) {
|
||||
cursor = SDL_CreateSystemCursor((SDL_SystemCursor)i);
|
||||
if (cursor) {
|
||||
|
||||
Reference in New Issue
Block a user