mirror of
https://github.com/love2d/megasource.git
synced 2026-08-17 19:24:09 +02:00
update SDL3 to latest commit
This commit is contained in:
@@ -109,21 +109,19 @@ static const char *cross[] = {
|
||||
"0,0"
|
||||
};
|
||||
|
||||
static SDL_Cursor *
|
||||
init_color_cursor(const char *file)
|
||||
static SDL_Surface *load_image_file(const char *file)
|
||||
{
|
||||
SDL_Cursor *cursor = NULL;
|
||||
SDL_Surface *surface = SDL_LoadBMP(file);
|
||||
if (surface) {
|
||||
if (surface->format->palette) {
|
||||
const Uint8 bpp = surface->format->bits_per_pixel;
|
||||
if (SDL_GetSurfacePalette(surface)) {
|
||||
const Uint8 bpp = SDL_BITSPERPIXEL(surface->format);
|
||||
const Uint8 mask = (1 << bpp) - 1;
|
||||
if (SDL_PIXELORDER(surface->format->format) == SDL_BITMAPORDER_4321)
|
||||
if (SDL_PIXELORDER(surface->format) == SDL_BITMAPORDER_4321)
|
||||
SDL_SetSurfaceColorKey(surface, 1, (*(Uint8 *)surface->pixels) & mask);
|
||||
else
|
||||
SDL_SetSurfaceColorKey(surface, 1, ((*(Uint8 *)surface->pixels) >> (8 - bpp)) & mask);
|
||||
} else {
|
||||
switch (surface->format->bits_per_pixel) {
|
||||
switch (SDL_BITSPERPIXEL(surface->format)) {
|
||||
case 15:
|
||||
SDL_SetSurfaceColorKey(surface, 1, (*(Uint16 *)surface->pixels) & 0x00007FFF);
|
||||
break;
|
||||
@@ -138,14 +136,50 @@ init_color_cursor(const char *file)
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
return surface;
|
||||
}
|
||||
|
||||
static SDL_Surface *load_image(const char *file)
|
||||
{
|
||||
SDL_Surface *surface = load_image_file(file);
|
||||
if (surface) {
|
||||
/* Add a 2x version of this image, if available */
|
||||
SDL_Surface *surface2x = NULL;
|
||||
const char *ext = SDL_strrchr(file, '.');
|
||||
size_t len = SDL_strlen(file) + 2 + 1;
|
||||
char *file2x = (char *)SDL_malloc(len);
|
||||
if (file2x) {
|
||||
SDL_strlcpy(file2x, file, len);
|
||||
if (ext) {
|
||||
SDL_memcpy(file2x + (ext - file), "2x", 3);
|
||||
SDL_strlcat(file2x, ext, len);
|
||||
} else {
|
||||
SDL_strlcat(file2x, "2x", len);
|
||||
}
|
||||
surface2x = load_image_file(file2x);
|
||||
SDL_free(file2x);
|
||||
}
|
||||
if (surface2x) {
|
||||
SDL_AddSurfaceAlternateImage(surface, surface2x);
|
||||
SDL_DestroySurface(surface2x);
|
||||
}
|
||||
}
|
||||
return surface;
|
||||
}
|
||||
|
||||
static SDL_Cursor *init_color_cursor(const char *file)
|
||||
{
|
||||
SDL_Cursor *cursor = NULL;
|
||||
SDL_Surface *surface = load_image(file);
|
||||
if (surface) {
|
||||
cursor = SDL_CreateColorCursor(surface, 0, 0);
|
||||
SDL_DestroySurface(surface);
|
||||
}
|
||||
return cursor;
|
||||
}
|
||||
|
||||
static SDL_Cursor *
|
||||
init_system_cursor(const char *image[])
|
||||
static SDL_Cursor *init_system_cursor(const char *image[])
|
||||
{
|
||||
int i, row, col;
|
||||
Uint8 data[4 * 32];
|
||||
@@ -185,11 +219,11 @@ 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;
|
||||
static bool show_cursor;
|
||||
|
||||
/* Call this instead of exit(), so we can clean up SDL: atexit() is evil. */
|
||||
static void
|
||||
@@ -226,11 +260,11 @@ static void loop(void)
|
||||
case (SDL_SystemCursor)-1:
|
||||
SDL_Log("Custom cursor");
|
||||
break;
|
||||
case SDL_SYSTEM_CURSOR_ARROW:
|
||||
SDL_Log("Arrow");
|
||||
case SDL_SYSTEM_CURSOR_DEFAULT:
|
||||
SDL_Log("Default");
|
||||
break;
|
||||
case SDL_SYSTEM_CURSOR_IBEAM:
|
||||
SDL_Log("I-beam");
|
||||
case SDL_SYSTEM_CURSOR_TEXT:
|
||||
SDL_Log("Text");
|
||||
break;
|
||||
case SDL_SYSTEM_CURSOR_WAIT:
|
||||
SDL_Log("Wait");
|
||||
@@ -238,52 +272,52 @@ static void loop(void)
|
||||
case SDL_SYSTEM_CURSOR_CROSSHAIR:
|
||||
SDL_Log("Crosshair");
|
||||
break;
|
||||
case SDL_SYSTEM_CURSOR_WAITARROW:
|
||||
SDL_Log("Small wait cursor (or Wait if not available)");
|
||||
case SDL_SYSTEM_CURSOR_PROGRESS:
|
||||
SDL_Log("Progress: Small wait cursor (or Wait if not available)");
|
||||
break;
|
||||
case SDL_SYSTEM_CURSOR_SIZENWSE:
|
||||
case SDL_SYSTEM_CURSOR_NWSE_RESIZE:
|
||||
SDL_Log("Double arrow pointing northwest and southeast");
|
||||
break;
|
||||
case SDL_SYSTEM_CURSOR_SIZENESW:
|
||||
case SDL_SYSTEM_CURSOR_NESW_RESIZE:
|
||||
SDL_Log("Double arrow pointing northeast and southwest");
|
||||
break;
|
||||
case SDL_SYSTEM_CURSOR_SIZEWE:
|
||||
case SDL_SYSTEM_CURSOR_EW_RESIZE:
|
||||
SDL_Log("Double arrow pointing west and east");
|
||||
break;
|
||||
case SDL_SYSTEM_CURSOR_SIZENS:
|
||||
case SDL_SYSTEM_CURSOR_NS_RESIZE:
|
||||
SDL_Log("Double arrow pointing north and south");
|
||||
break;
|
||||
case SDL_SYSTEM_CURSOR_SIZEALL:
|
||||
SDL_Log("Four pointed arrow pointing north, south, east, and west");
|
||||
case SDL_SYSTEM_CURSOR_MOVE:
|
||||
SDL_Log("Move: Four pointed arrow pointing north, south, east, and west");
|
||||
break;
|
||||
case SDL_SYSTEM_CURSOR_NO:
|
||||
SDL_Log("Slashed circle or crossbones");
|
||||
case SDL_SYSTEM_CURSOR_NOT_ALLOWED:
|
||||
SDL_Log("Not Allowed: Slashed circle or crossbones");
|
||||
break;
|
||||
case SDL_SYSTEM_CURSOR_HAND:
|
||||
SDL_Log("Hand");
|
||||
case SDL_SYSTEM_CURSOR_POINTER:
|
||||
SDL_Log("Pointer: Hand");
|
||||
break;
|
||||
case SDL_SYSTEM_CURSOR_WINDOW_TOPLEFT:
|
||||
case SDL_SYSTEM_CURSOR_NW_RESIZE:
|
||||
SDL_Log("Window resize top-left");
|
||||
break;
|
||||
case SDL_SYSTEM_CURSOR_WINDOW_TOP:
|
||||
case SDL_SYSTEM_CURSOR_N_RESIZE:
|
||||
SDL_Log("Window resize top");
|
||||
break;
|
||||
case SDL_SYSTEM_CURSOR_WINDOW_TOPRIGHT:
|
||||
case SDL_SYSTEM_CURSOR_NE_RESIZE:
|
||||
SDL_Log("Window resize top-right");
|
||||
break;
|
||||
case SDL_SYSTEM_CURSOR_WINDOW_RIGHT:
|
||||
case SDL_SYSTEM_CURSOR_E_RESIZE:
|
||||
SDL_Log("Window resize right");
|
||||
break;
|
||||
case SDL_SYSTEM_CURSOR_WINDOW_BOTTOMRIGHT:
|
||||
case SDL_SYSTEM_CURSOR_SE_RESIZE:
|
||||
SDL_Log("Window resize bottom-right");
|
||||
break;
|
||||
case SDL_SYSTEM_CURSOR_WINDOW_BOTTOM:
|
||||
case SDL_SYSTEM_CURSOR_S_RESIZE:
|
||||
SDL_Log("Window resize bottom");
|
||||
break;
|
||||
case SDL_SYSTEM_CURSOR_WINDOW_BOTTOMLEFT:
|
||||
case SDL_SYSTEM_CURSOR_SW_RESIZE:
|
||||
SDL_Log("Window resize bottom-left");
|
||||
break;
|
||||
case SDL_SYSTEM_CURSOR_WINDOW_LEFT:
|
||||
case SDL_SYSTEM_CURSOR_W_RESIZE:
|
||||
SDL_Log("Window resize left");
|
||||
break;
|
||||
default:
|
||||
@@ -307,12 +341,13 @@ static void loop(void)
|
||||
SDL_FRect rect;
|
||||
int x, y, row;
|
||||
int window_w = 0, window_h = 0;
|
||||
const float scale = SDL_GetWindowPixelDensity(state->windows[i]);
|
||||
|
||||
SDL_GetWindowSize(state->windows[i], &window_w, &window_h);
|
||||
rect.w = 128.0f;
|
||||
rect.h = 128.0f;
|
||||
SDL_GetWindowSizeInPixels(state->windows[i], &window_w, &window_h);
|
||||
rect.w = 128.0f * scale;
|
||||
rect.h = 128.0f * scale;
|
||||
for (y = 0, row = 0; y < window_h; y += (int)rect.h, ++row) {
|
||||
SDL_bool black = ((row % 2) == 0) ? SDL_TRUE : SDL_FALSE;
|
||||
bool black = ((row % 2) == 0) ? true : false;
|
||||
for (x = 0; x < window_w; x += (int)rect.w) {
|
||||
rect.x = (float)x;
|
||||
rect.y = (float)y;
|
||||
@@ -342,14 +377,12 @@ int main(int argc, char *argv[])
|
||||
const char *color_cursor = NULL;
|
||||
SDL_Cursor *cursor;
|
||||
|
||||
/* Enable standard application logging */
|
||||
SDL_LogSetPriority(SDL_LOG_CATEGORY_APPLICATION, SDL_LOG_PRIORITY_INFO);
|
||||
|
||||
/* Initialize test framework */
|
||||
state = SDLTest_CommonCreateState(argv, SDL_INIT_VIDEO);
|
||||
if (!state) {
|
||||
return 1;
|
||||
}
|
||||
|
||||
for (i = 1; i < argc;) {
|
||||
int consumed;
|
||||
|
||||
@@ -372,6 +405,14 @@ int main(int argc, char *argv[])
|
||||
num_cursors = 0;
|
||||
|
||||
if (color_cursor) {
|
||||
SDL_Surface *icon = load_image(color_cursor);
|
||||
if (icon) {
|
||||
for (i = 0; i < state->num_windows; ++i) {
|
||||
SDL_SetWindowIcon(state->windows[i], icon);
|
||||
}
|
||||
SDL_DestroySurface(icon);
|
||||
}
|
||||
|
||||
cursor = init_color_cursor(color_cursor);
|
||||
if (cursor) {
|
||||
cursors[num_cursors] = cursor;
|
||||
@@ -394,7 +435,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;
|
||||
|
||||
Reference in New Issue
Block a user