mirror of
https://github.com/libsdl-org/SDL.git
synced 2025-10-14 22:05:59 +00:00
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:
@@ -31,16 +31,16 @@
|
||||
#include "../../core/android/SDL_android.h"
|
||||
|
||||
/* See Android's MotionEvent class for constants */
|
||||
#define ACTION_DOWN 0
|
||||
#define ACTION_UP 1
|
||||
#define ACTION_MOVE 2
|
||||
#define ACTION_DOWN 0
|
||||
#define ACTION_UP 1
|
||||
#define ACTION_MOVE 2
|
||||
#define ACTION_HOVER_MOVE 7
|
||||
#define ACTION_SCROLL 8
|
||||
#define BUTTON_PRIMARY 1
|
||||
#define BUTTON_SECONDARY 2
|
||||
#define BUTTON_TERTIARY 4
|
||||
#define BUTTON_BACK 8
|
||||
#define BUTTON_FORWARD 16
|
||||
#define ACTION_SCROLL 8
|
||||
#define BUTTON_PRIMARY 1
|
||||
#define BUTTON_SECONDARY 2
|
||||
#define BUTTON_TERTIARY 4
|
||||
#define BUTTON_BACK 8
|
||||
#define BUTTON_FORWARD 16
|
||||
|
||||
typedef struct
|
||||
{
|
||||
@@ -55,8 +55,7 @@ static int last_state;
|
||||
/* Blank cursor */
|
||||
static SDL_Cursor *empty_cursor;
|
||||
|
||||
static SDL_Cursor *
|
||||
Android_WrapCursor(int custom_cursor, int system_cursor)
|
||||
static SDL_Cursor *Android_WrapCursor(int custom_cursor, int system_cursor)
|
||||
{
|
||||
SDL_Cursor *cursor;
|
||||
|
||||
@@ -79,14 +78,12 @@ Android_WrapCursor(int custom_cursor, int system_cursor)
|
||||
return cursor;
|
||||
}
|
||||
|
||||
static SDL_Cursor *
|
||||
Android_CreateDefaultCursor()
|
||||
static SDL_Cursor *Android_CreateDefaultCursor()
|
||||
{
|
||||
return Android_WrapCursor(0, SDL_SYSTEM_CURSOR_ARROW);
|
||||
}
|
||||
|
||||
static SDL_Cursor *
|
||||
Android_CreateCursor(SDL_Surface * surface, int hot_x, int hot_y)
|
||||
static SDL_Cursor *Android_CreateCursor(SDL_Surface *surface, int hot_x, int hot_y)
|
||||
{
|
||||
int custom_cursor;
|
||||
SDL_Surface *converted;
|
||||
@@ -104,16 +101,14 @@ Android_CreateCursor(SDL_Surface * surface, int hot_x, int hot_y)
|
||||
return Android_WrapCursor(custom_cursor, 0);
|
||||
}
|
||||
|
||||
static SDL_Cursor *
|
||||
Android_CreateSystemCursor(SDL_SystemCursor id)
|
||||
static SDL_Cursor *Android_CreateSystemCursor(SDL_SystemCursor id)
|
||||
{
|
||||
return Android_WrapCursor(0, id);
|
||||
}
|
||||
|
||||
static void
|
||||
Android_FreeCursor(SDL_Cursor * cursor)
|
||||
static void Android_FreeCursor(SDL_Cursor *cursor)
|
||||
{
|
||||
SDL_AndroidCursorData *data = (SDL_AndroidCursorData*) cursor->driverdata;
|
||||
SDL_AndroidCursorData *data = (SDL_AndroidCursorData *)cursor->driverdata;
|
||||
if (data->custom_cursor != 0) {
|
||||
Android_JNI_DestroyCustomCursor(data->custom_cursor);
|
||||
}
|
||||
@@ -121,8 +116,7 @@ Android_FreeCursor(SDL_Cursor * cursor)
|
||||
SDL_free(cursor);
|
||||
}
|
||||
|
||||
static SDL_Cursor *
|
||||
Android_CreateEmptyCursor()
|
||||
static SDL_Cursor *Android_CreateEmptyCursor()
|
||||
{
|
||||
if (empty_cursor == NULL) {
|
||||
SDL_Surface *empty_surface = SDL_CreateRGBSurfaceWithFormat(0, 1, 1, 32, SDL_PIXELFORMAT_ARGB8888);
|
||||
@@ -135,8 +129,7 @@ Android_CreateEmptyCursor()
|
||||
return empty_cursor;
|
||||
}
|
||||
|
||||
static void
|
||||
Android_DestroyEmptyCursor()
|
||||
static void Android_DestroyEmptyCursor()
|
||||
{
|
||||
if (empty_cursor) {
|
||||
Android_FreeCursor(empty_cursor);
|
||||
@@ -144,8 +137,7 @@ Android_DestroyEmptyCursor()
|
||||
}
|
||||
}
|
||||
|
||||
static int
|
||||
Android_ShowCursor(SDL_Cursor *cursor)
|
||||
static int Android_ShowCursor(SDL_Cursor *cursor)
|
||||
{
|
||||
if (cursor == NULL) {
|
||||
cursor = Android_CreateEmptyCursor();
|
||||
@@ -168,8 +160,7 @@ Android_ShowCursor(SDL_Cursor *cursor)
|
||||
}
|
||||
}
|
||||
|
||||
static int
|
||||
Android_SetRelativeMouseMode(SDL_bool enabled)
|
||||
static int Android_SetRelativeMouseMode(SDL_bool enabled)
|
||||
{
|
||||
if (!Android_JNI_SupportsRelativeMouse()) {
|
||||
return SDL_Unsupported();
|
||||
@@ -182,8 +173,7 @@ Android_SetRelativeMouseMode(SDL_bool enabled)
|
||||
return 0;
|
||||
}
|
||||
|
||||
void
|
||||
Android_InitMouse(void)
|
||||
void Android_InitMouse(void)
|
||||
{
|
||||
SDL_Mouse *mouse = SDL_GetMouse();
|
||||
|
||||
@@ -198,15 +188,13 @@ Android_InitMouse(void)
|
||||
last_state = 0;
|
||||
}
|
||||
|
||||
void
|
||||
Android_QuitMouse(void)
|
||||
void Android_QuitMouse(void)
|
||||
{
|
||||
Android_DestroyEmptyCursor();
|
||||
}
|
||||
|
||||
/* Translate Android mouse button state to SDL mouse button */
|
||||
static Uint8
|
||||
TranslateButton(int state)
|
||||
static Uint8 TranslateButton(int state)
|
||||
{
|
||||
if (state & BUTTON_PRIMARY) {
|
||||
return SDL_BUTTON_LEFT;
|
||||
@@ -223,8 +211,7 @@ TranslateButton(int state)
|
||||
}
|
||||
}
|
||||
|
||||
void
|
||||
Android_OnMouse(SDL_Window *window, int state, int action, float x, float y, SDL_bool relative)
|
||||
void Android_OnMouse(SDL_Window *window, int state, int action, float x, float y, SDL_bool relative)
|
||||
{
|
||||
int changes;
|
||||
Uint8 button;
|
||||
@@ -233,38 +220,37 @@ Android_OnMouse(SDL_Window *window, int state, int action, float x, float y, SDL
|
||||
return;
|
||||
}
|
||||
|
||||
switch(action) {
|
||||
case ACTION_DOWN:
|
||||
changes = state & ~last_state;
|
||||
button = TranslateButton(changes);
|
||||
last_state = state;
|
||||
SDL_SendMouseMotion(window, 0, relative, (int)x, (int)y);
|
||||
SDL_SendMouseButton(window, 0, SDL_PRESSED, button);
|
||||
break;
|
||||
switch (action) {
|
||||
case ACTION_DOWN:
|
||||
changes = state & ~last_state;
|
||||
button = TranslateButton(changes);
|
||||
last_state = state;
|
||||
SDL_SendMouseMotion(window, 0, relative, (int)x, (int)y);
|
||||
SDL_SendMouseButton(window, 0, SDL_PRESSED, button);
|
||||
break;
|
||||
|
||||
case ACTION_UP:
|
||||
changes = last_state & ~state;
|
||||
button = TranslateButton(changes);
|
||||
last_state = state;
|
||||
SDL_SendMouseMotion(window, 0, relative, (int)x, (int)y);
|
||||
SDL_SendMouseButton(window, 0, SDL_RELEASED, button);
|
||||
break;
|
||||
case ACTION_UP:
|
||||
changes = last_state & ~state;
|
||||
button = TranslateButton(changes);
|
||||
last_state = state;
|
||||
SDL_SendMouseMotion(window, 0, relative, (int)x, (int)y);
|
||||
SDL_SendMouseButton(window, 0, SDL_RELEASED, button);
|
||||
break;
|
||||
|
||||
case ACTION_MOVE:
|
||||
case ACTION_HOVER_MOVE:
|
||||
SDL_SendMouseMotion(window, 0, relative, (int)x, (int)y);
|
||||
break;
|
||||
case ACTION_MOVE:
|
||||
case ACTION_HOVER_MOVE:
|
||||
SDL_SendMouseMotion(window, 0, relative, (int)x, (int)y);
|
||||
break;
|
||||
|
||||
case ACTION_SCROLL:
|
||||
SDL_SendMouseWheel(window, 0, x, y, SDL_MOUSEWHEEL_NORMAL);
|
||||
break;
|
||||
case ACTION_SCROLL:
|
||||
SDL_SendMouseWheel(window, 0, x, y, SDL_MOUSEWHEEL_NORMAL);
|
||||
break;
|
||||
|
||||
default:
|
||||
break;
|
||||
default:
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
#endif /* SDL_VIDEO_DRIVER_ANDROID */
|
||||
|
||||
/* vi: set ts=4 sw=4 expandtab: */
|
||||
|
||||
|
Reference in New Issue
Block a user