Update for SDL3 coding style (#6717)

I updated .clang-format and ran clang-format 14 over the src and test directories to standardize the code base.

In general I let clang-format have it's way, and added markup to prevent formatting of code that would break or be completely unreadable if formatted.

The script I ran for the src directory is added as build-scripts/clang-format-src.sh

This fixes:
#6592
#6593
#6594

(cherry picked from commit 5750bcb174)
This commit is contained in:
Sam Lantinga 2022-11-30 12:51:59 -08:00
parent 5c4bc807f7
commit b8d85c6939
764 changed files with 50598 additions and 54407 deletions

View file

@ -22,59 +22,58 @@
/* Stolen from the mailing list */
/* Creates a new mouse cursor from an XPM */
/* XPM */
static const char *arrow[] = {
/* width height num_colors chars_per_pixel */
" 32 32 3 1",
/* colors */
"X c #000000",
". c #ffffff",
" c None",
/* pixels */
"X ",
"XX ",
"X.X ",
"X..X ",
"X...X ",
"X....X ",
"X.....X ",
"X......X ",
"X.......X ",
"X........X ",
"X.....XXXXX ",
"X..X..X ",
"X.X X..X ",
"XX X..X ",
"X X..X ",
" X..X ",
" X..X ",
" X..X ",
" XX ",
" ",
" ",
" ",
" ",
" ",
" ",
" ",
" ",
" ",
" ",
" ",
" ",
" ",
"0,0"
};
/* width height num_colors chars_per_pixel */
" 32 32 3 1",
/* colors */
"X c #000000",
". c #ffffff",
" c None",
/* pixels */
"X ",
"XX ",
"X.X ",
"X..X ",
"X...X ",
"X....X ",
"X.....X ",
"X......X ",
"X.......X ",
"X........X ",
"X.....XXXXX ",
"X..X..X ",
"X.X X..X ",
"XX X..X ",
"X X..X ",
" X..X ",
" X..X ",
" X..X ",
" XX ",
" ",
" ",
" ",
" ",
" ",
" ",
" ",
" ",
" ",
" ",
" ",
" ",
" ",
"0,0"
};
static SDL_Cursor*
static SDL_Cursor *
init_color_cursor(const char *file)
{
SDL_Cursor *cursor = NULL;
SDL_Surface *surface = SDL_LoadBMP(file);
if (surface) {
if (surface->format->palette) {
SDL_SetColorKey(surface, 1, *(Uint8 *) surface->pixels);
SDL_SetColorKey(surface, 1, *(Uint8 *)surface->pixels);
} else {
switch (surface->format->BitsPerPixel) {
case 15:
@ -97,45 +96,45 @@ init_color_cursor(const char *file)
return cursor;
}
static SDL_Cursor*
static SDL_Cursor *
init_system_cursor(const char *image[])
{
int i, row, col;
Uint8 data[4*32];
Uint8 mask[4*32];
int hot_x, hot_y;
int i, row, col;
Uint8 data[4 * 32];
Uint8 mask[4 * 32];
int hot_x, hot_y;
i = -1;
for (row=0; row<32; ++row) {
for (col=0; col<32; ++col) {
if (col % 8) {
data[i] <<= 1;
mask[i] <<= 1;
} else {
++i;
data[i] = mask[i] = 0;
}
switch (image[4+row][col]) {
case 'X':
data[i] |= 0x01;
mask[i] |= 0x01;
break;
case '.':
mask[i] |= 0x01;
break;
case ' ':
break;
}
i = -1;
for (row = 0; row < 32; ++row) {
for (col = 0; col < 32; ++col) {
if (col % 8) {
data[i] <<= 1;
mask[i] <<= 1;
} else {
++i;
data[i] = mask[i] = 0;
}
switch (image[4 + row][col]) {
case 'X':
data[i] |= 0x01;
mask[i] |= 0x01;
break;
case '.':
mask[i] |= 0x01;
break;
case ' ':
break;
}
}
}
}
SDL_sscanf(image[4+row], "%d,%d", &hot_x, &hot_y);
return SDL_CreateCursor(data, mask, 32, 32, hot_x, hot_y);
SDL_sscanf(image[4 + row], "%d,%d", &hot_x, &hot_y);
return SDL_CreateCursor(data, mask, 32, 32, hot_x, hot_y);
}
static SDLTest_CommonState *state;
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[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;
@ -148,8 +147,7 @@ quit(int rc)
exit(rc);
}
void
loop()
void loop()
{
int i;
SDL_Event event;
@ -170,20 +168,48 @@ loop()
SDL_SetCursor(cursors[current_cursor]);
switch ((int)cursor_types[current_cursor]) {
case (SDL_SystemCursor)-1: SDL_Log("Custom cursor"); break;
case SDL_SYSTEM_CURSOR_ARROW: SDL_Log("Arrow"); break;
case SDL_SYSTEM_CURSOR_IBEAM: SDL_Log("I-beam"); break;
case SDL_SYSTEM_CURSOR_WAIT: SDL_Log("Wait"); break;
case SDL_SYSTEM_CURSOR_CROSSHAIR: SDL_Log("Crosshair"); break;
case SDL_SYSTEM_CURSOR_WAITARROW: SDL_Log("Small wait cursor (or Wait if not available)"); break;
case SDL_SYSTEM_CURSOR_SIZENWSE: SDL_Log("Double arrow pointing northwest and southeast"); break;
case SDL_SYSTEM_CURSOR_SIZENESW: SDL_Log("Double arrow pointing northeast and southwest"); break;
case SDL_SYSTEM_CURSOR_SIZEWE: SDL_Log("Double arrow pointing west and east"); break;
case SDL_SYSTEM_CURSOR_SIZENS: 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"); break;
case SDL_SYSTEM_CURSOR_NO: SDL_Log("Slashed circle or crossbones"); break;
case SDL_SYSTEM_CURSOR_HAND: SDL_Log("Hand"); break;
default: SDL_Log("UNKNOWN CURSOR TYPE, FIX THIS PROGRAM."); break;
case (SDL_SystemCursor)-1:
SDL_Log("Custom cursor");
break;
case SDL_SYSTEM_CURSOR_ARROW:
SDL_Log("Arrow");
break;
case SDL_SYSTEM_CURSOR_IBEAM:
SDL_Log("I-beam");
break;
case SDL_SYSTEM_CURSOR_WAIT:
SDL_Log("Wait");
break;
case SDL_SYSTEM_CURSOR_CROSSHAIR:
SDL_Log("Crosshair");
break;
case SDL_SYSTEM_CURSOR_WAITARROW:
SDL_Log("Small wait cursor (or Wait if not available)");
break;
case SDL_SYSTEM_CURSOR_SIZENWSE:
SDL_Log("Double arrow pointing northwest and southeast");
break;
case SDL_SYSTEM_CURSOR_SIZENESW:
SDL_Log("Double arrow pointing northeast and southwest");
break;
case SDL_SYSTEM_CURSOR_SIZEWE:
SDL_Log("Double arrow pointing west and east");
break;
case SDL_SYSTEM_CURSOR_SIZENS:
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");
break;
case SDL_SYSTEM_CURSOR_NO:
SDL_Log("Slashed circle or crossbones");
break;
case SDL_SYSTEM_CURSOR_HAND:
SDL_Log("Hand");
break;
default:
SDL_Log("UNKNOWN CURSOR TYPE, FIX THIS PROGRAM.");
break;
}
} else {
@ -192,7 +218,7 @@ loop()
}
}
}
for (i = 0; i < state->num_windows; ++i) {
SDL_Renderer *renderer = state->renderers[i];
SDL_RenderClear(renderer);
@ -205,8 +231,7 @@ loop()
#endif
}
int
main(int argc, char *argv[])
int main(int argc, char *argv[])
{
int i;
const char *color_cursor = NULL;