forked from Green-Sky/tomato
Merge commit '852f2a6343518919e5ca8d3c1bbcab9f493e3cd8'
This commit is contained in:
142
external/sdl/SDL/test/testcustomcursor.c
vendored
142
external/sdl/SDL/test/testcustomcursor.c
vendored
@ -1,5 +1,5 @@
|
||||
/*
|
||||
Copyright (C) 1997-2023 Sam Lantinga <slouken@libsdl.org>
|
||||
Copyright (C) 1997-2024 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
|
||||
@ -65,6 +65,50 @@ static const char *arrow[] = {
|
||||
"0,0"
|
||||
};
|
||||
|
||||
static const char *cross[] = {
|
||||
/* width height num_colors chars_per_pixel */
|
||||
" 32 32 3 1",
|
||||
/* colors */
|
||||
"o c #000000",
|
||||
". c #ffffff",
|
||||
" c None",
|
||||
/* pixels */
|
||||
/* pixels */
|
||||
" ",
|
||||
" ",
|
||||
" ",
|
||||
" ",
|
||||
" oo ",
|
||||
" oo ",
|
||||
" oo ",
|
||||
" oo ",
|
||||
" oo ",
|
||||
" oo ",
|
||||
" oo ",
|
||||
" oo ",
|
||||
" oo ",
|
||||
" oo ",
|
||||
" oo ",
|
||||
" oooooooooooooooooooooooo ",
|
||||
" oooooooooooooooooooooooo ",
|
||||
" oo ",
|
||||
" oo ",
|
||||
" oo ",
|
||||
" oo ",
|
||||
" oo ",
|
||||
" oo ",
|
||||
" oo ",
|
||||
" oo ",
|
||||
" oo ",
|
||||
" oo ",
|
||||
" oo ",
|
||||
" ",
|
||||
" ",
|
||||
" ",
|
||||
" ",
|
||||
"0,0"
|
||||
};
|
||||
|
||||
static SDL_Cursor *
|
||||
init_color_cursor(const char *file)
|
||||
{
|
||||
@ -72,7 +116,12 @@ init_color_cursor(const char *file)
|
||||
SDL_Surface *surface = SDL_LoadBMP(file);
|
||||
if (surface) {
|
||||
if (surface->format->palette) {
|
||||
SDL_SetSurfaceColorKey(surface, 1, *(Uint8 *)surface->pixels);
|
||||
const Uint8 bpp = surface->format->BitsPerPixel;
|
||||
const Uint8 mask = (1 << bpp) - 1;
|
||||
if (SDL_PIXELORDER(surface->format->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->BitsPerPixel) {
|
||||
case 15:
|
||||
@ -122,6 +171,9 @@ init_system_cursor(const char *image[])
|
||||
case '.':
|
||||
mask[i] |= 0x01;
|
||||
break;
|
||||
case 'o':
|
||||
data[i] |= 0x01;
|
||||
break;
|
||||
case ' ':
|
||||
break;
|
||||
}
|
||||
@ -133,8 +185,8 @@ init_system_cursor(const char *image[])
|
||||
|
||||
static SDLTest_CommonState *state;
|
||||
static int done;
|
||||
static SDL_Cursor *cursors[1 + SDL_NUM_SYSTEM_CURSORS];
|
||||
static SDL_SystemCursor cursor_types[1 + SDL_NUM_SYSTEM_CURSORS];
|
||||
static SDL_Cursor *cursors[3 + SDL_NUM_SYSTEM_CURSORS];
|
||||
static SDL_SystemCursor cursor_types[3 + SDL_NUM_SYSTEM_CURSORS];
|
||||
static int num_cursors;
|
||||
static int current_cursor;
|
||||
static SDL_bool show_cursor;
|
||||
@ -210,6 +262,30 @@ static void loop(void)
|
||||
case SDL_SYSTEM_CURSOR_HAND:
|
||||
SDL_Log("Hand");
|
||||
break;
|
||||
case SDL_SYSTEM_CURSOR_WINDOW_TOPLEFT:
|
||||
SDL_Log("Window resize top-left");
|
||||
break;
|
||||
case SDL_SYSTEM_CURSOR_WINDOW_TOP:
|
||||
SDL_Log("Window resize top");
|
||||
break;
|
||||
case SDL_SYSTEM_CURSOR_WINDOW_TOPRIGHT:
|
||||
SDL_Log("Window resize top-right");
|
||||
break;
|
||||
case SDL_SYSTEM_CURSOR_WINDOW_RIGHT:
|
||||
SDL_Log("Window resize right");
|
||||
break;
|
||||
case SDL_SYSTEM_CURSOR_WINDOW_BOTTOMRIGHT:
|
||||
SDL_Log("Window resize bottom-right");
|
||||
break;
|
||||
case SDL_SYSTEM_CURSOR_WINDOW_BOTTOM:
|
||||
SDL_Log("Window resize bottom");
|
||||
break;
|
||||
case SDL_SYSTEM_CURSOR_WINDOW_BOTTOMLEFT:
|
||||
SDL_Log("Window resize bottom-left");
|
||||
break;
|
||||
case SDL_SYSTEM_CURSOR_WINDOW_LEFT:
|
||||
SDL_Log("Window resize left");
|
||||
break;
|
||||
default:
|
||||
SDL_Log("UNKNOWN CURSOR TYPE, FIX THIS PROGRAM.");
|
||||
break;
|
||||
@ -228,7 +304,29 @@ static void loop(void)
|
||||
|
||||
for (i = 0; i < state->num_windows; ++i) {
|
||||
SDL_Renderer *renderer = state->renderers[i];
|
||||
SDL_RenderClear(renderer);
|
||||
SDL_FRect rect;
|
||||
int x, y, row;
|
||||
int window_w = 0, window_h = 0;
|
||||
|
||||
SDL_GetWindowSize(state->windows[i], &window_w, &window_h);
|
||||
rect.w = 128.0f;
|
||||
rect.h = 128.0f;
|
||||
for (y = 0, row = 0; y < window_h; y += (int)rect.h, ++row) {
|
||||
SDL_bool black = ((row % 2) == 0) ? SDL_TRUE : SDL_FALSE;
|
||||
for (x = 0; x < window_w; x += (int)rect.w) {
|
||||
rect.x = (float)x;
|
||||
rect.y = (float)y;
|
||||
|
||||
if (black) {
|
||||
SDL_SetRenderDrawColor(renderer, 0x00, 0x00, 0x00, 0xFF);
|
||||
} else {
|
||||
SDL_SetRenderDrawColor(renderer, 0xFF, 0xFF, 0xFF, 0xFF);
|
||||
}
|
||||
SDL_RenderFillRect(renderer, &rect);
|
||||
|
||||
black = !black;
|
||||
}
|
||||
}
|
||||
SDL_RenderPresent(renderer);
|
||||
}
|
||||
#ifdef __EMSCRIPTEN__
|
||||
@ -242,13 +340,14 @@ int main(int argc, char *argv[])
|
||||
{
|
||||
int i;
|
||||
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 == NULL) {
|
||||
if (!state) {
|
||||
return 1;
|
||||
}
|
||||
for (i = 1; i < argc;) {
|
||||
@ -270,23 +369,10 @@ int main(int argc, char *argv[])
|
||||
quit(2);
|
||||
}
|
||||
|
||||
for (i = 0; i < state->num_windows; ++i) {
|
||||
SDL_Renderer *renderer = state->renderers[i];
|
||||
SDL_SetRenderDrawColor(renderer, 0xA0, 0xA0, 0xA0, 0xFF);
|
||||
SDL_RenderClear(renderer);
|
||||
}
|
||||
|
||||
num_cursors = 0;
|
||||
|
||||
if (color_cursor) {
|
||||
SDL_Cursor *cursor = init_color_cursor(color_cursor);
|
||||
if (cursor) {
|
||||
cursors[num_cursors] = cursor;
|
||||
cursor_types[num_cursors] = (SDL_SystemCursor)-1;
|
||||
num_cursors++;
|
||||
}
|
||||
} else {
|
||||
SDL_Cursor *cursor = init_system_cursor(arrow);
|
||||
cursor = init_color_cursor(color_cursor);
|
||||
if (cursor) {
|
||||
cursors[num_cursors] = cursor;
|
||||
cursor_types[num_cursors] = (SDL_SystemCursor)-1;
|
||||
@ -294,8 +380,22 @@ int main(int argc, char *argv[])
|
||||
}
|
||||
}
|
||||
|
||||
cursor = init_system_cursor(arrow);
|
||||
if (cursor) {
|
||||
cursors[num_cursors] = cursor;
|
||||
cursor_types[num_cursors] = (SDL_SystemCursor)-1;
|
||||
num_cursors++;
|
||||
}
|
||||
|
||||
cursor = init_system_cursor(cross);
|
||||
if (cursor) {
|
||||
cursors[num_cursors] = cursor;
|
||||
cursor_types[num_cursors] = (SDL_SystemCursor)-1;
|
||||
num_cursors++;
|
||||
}
|
||||
|
||||
for (i = 0; i < SDL_NUM_SYSTEM_CURSORS; ++i) {
|
||||
SDL_Cursor *cursor = SDL_CreateSystemCursor((SDL_SystemCursor)i);
|
||||
cursor = SDL_CreateSystemCursor((SDL_SystemCursor)i);
|
||||
if (cursor) {
|
||||
cursors[num_cursors] = cursor;
|
||||
cursor_types[num_cursors] = i;
|
||||
|
Reference in New Issue
Block a user