REVIEWED: Formating to follow raylib conventions

This commit is contained in:
Ray 2025-03-10 17:08:18 +01:00
parent bd8e59f18d
commit 7f8bf2233c

View file

@ -128,7 +128,7 @@ typedef struct {
//---------------------------------------------------------------------------------- //----------------------------------------------------------------------------------
extern CoreData CORE; // Global CORE state context extern CoreData CORE; // Global CORE state context
static PlatformData platform = { NULL }; // Platform specific static PlatformData platform = { 0 }; // Platform specific
static bool RGFW_disableCursor = false; static bool RGFW_disableCursor = false;
@ -315,7 +315,9 @@ void ToggleBorderlessWindowed(void)
RGFW_monitor mon = RGFW_window_getMonitor(platform.window); RGFW_monitor mon = RGFW_window_getMonitor(platform.window);
RGFW_window_resize(platform.window, mon.mode.area); RGFW_window_resize(platform.window, mon.mode.area);
} else { }
else
{
RGFW_window_setBorder(platform.window, 1); RGFW_window_setBorder(platform.window, 1);
CORE.Window.position = CORE.Window.previousPosition; CORE.Window.position = CORE.Window.previousPosition;
@ -340,8 +342,7 @@ void MinimizeWindow(void)
// Set window state: not minimized/maximized // Set window state: not minimized/maximized
void RestoreWindow(void) void RestoreWindow(void)
{ {
if (!(CORE.Window.flags & FLAG_WINDOW_UNFOCUSED)) if (!(CORE.Window.flags & FLAG_WINDOW_UNFOCUSED)) RGFW_window_focus(platform.window);
RGFW_window_focus(platform.window);
RGFW_window_restore(platform.window); RGFW_window_restore(platform.window);
} }
@ -357,8 +358,7 @@ void SetWindowState(unsigned int flags)
} }
if (flags & FLAG_FULLSCREEN_MODE) if (flags & FLAG_FULLSCREEN_MODE)
{ {
if (!CORE.Window.fullscreen) if (!CORE.Window.fullscreen) ToggleFullscreen();
ToggleFullscreen();
} }
if (flags & FLAG_WINDOW_RESIZABLE) if (flags & FLAG_WINDOW_RESIZABLE)
{ {
@ -432,8 +432,7 @@ void ClearWindowState(unsigned int flags)
} }
if (flags & FLAG_FULLSCREEN_MODE) if (flags & FLAG_FULLSCREEN_MODE)
{ {
if (CORE.Window.fullscreen) if (CORE.Window.fullscreen) ToggleFullscreen();
ToggleFullscreen();
} }
if (flags & FLAG_WINDOW_RESIZABLE) if (flags & FLAG_WINDOW_RESIZABLE)
{ {
@ -446,21 +445,20 @@ void ClearWindowState(unsigned int flags)
} }
if (flags & FLAG_WINDOW_HIDDEN) if (flags & FLAG_WINDOW_HIDDEN)
{ {
if (!(CORE.Window.flags & FLAG_WINDOW_UNFOCUSED)) if (!(CORE.Window.flags & FLAG_WINDOW_UNFOCUSED)) RGFW_window_focus(platform.window);
RGFW_window_focus(platform.window);
RGFW_window_show(platform.window); RGFW_window_show(platform.window);
} }
if (flags & FLAG_WINDOW_MINIMIZED) if (flags & FLAG_WINDOW_MINIMIZED)
{ {
if (!(CORE.Window.flags & FLAG_WINDOW_UNFOCUSED)) if (!(CORE.Window.flags & FLAG_WINDOW_UNFOCUSED)) RGFW_window_focus(platform.window);
RGFW_window_focus(platform.window);
RGFW_window_restore(platform.window); RGFW_window_restore(platform.window);
} }
if (flags & FLAG_WINDOW_MAXIMIZED) if (flags & FLAG_WINDOW_MAXIMIZED)
{ {
if (!(CORE.Window.flags & FLAG_WINDOW_UNFOCUSED)) if (!(CORE.Window.flags & FLAG_WINDOW_UNFOCUSED)) RGFW_window_focus(platform.window);
RGFW_window_focus(platform.window);
RGFW_window_restore(platform.window); RGFW_window_restore(platform.window);
} }
if (flags & FLAG_WINDOW_UNFOCUSED) if (flags & FLAG_WINDOW_UNFOCUSED)
@ -490,8 +488,7 @@ void ClearWindowState(unsigned int flags)
} }
if (flags & FLAG_BORDERLESS_WINDOWED_MODE) if (flags & FLAG_BORDERLESS_WINDOWED_MODE)
{ {
if (CORE.Window.fullscreen) if (CORE.Window.fullscreen) ToggleBorderlessWindowed();
ToggleBorderlessWindowed();
} }
if (flags & FLAG_MSAA_4X_HINT) if (flags & FLAG_MSAA_4X_HINT)
{ {
@ -505,7 +502,8 @@ void ClearWindowState(unsigned int flags)
int RGFW_formatToChannels(int format) int RGFW_formatToChannels(int format)
{ {
switch (format) { switch (format)
{
case PIXELFORMAT_UNCOMPRESSED_GRAYSCALE: case PIXELFORMAT_UNCOMPRESSED_GRAYSCALE:
case PIXELFORMAT_UNCOMPRESSED_R16: // 16 bpp (1 channel - half float) case PIXELFORMAT_UNCOMPRESSED_R16: // 16 bpp (1 channel - half float)
case PIXELFORMAT_UNCOMPRESSED_R32: // 32 bpp (1 channel - float) case PIXELFORMAT_UNCOMPRESSED_R32: // 32 bpp (1 channel - float)
@ -547,32 +545,29 @@ void SetWindowIcon(Image image)
// Set icon for window // Set icon for window
void SetWindowIcons(Image *images, int count) void SetWindowIcons(Image *images, int count)
{ {
if ((images == NULL) || (count <= 0)) if ((images == NULL) || (count <= 0))
{ {
RGFW_window_setIcon(platform.window, NULL, RGFW_AREA(0, 0), 0); RGFW_window_setIcon(platform.window, NULL, RGFW_AREA(0, 0), 0);
} { }
Image* bigIcon = NULL; else
Image* smallIcon = NULL; {
Image *bigIcon = NULL;
Image *smallIcon = NULL;
for (size_t i = 0; i < count; i++) { for (int i = 0; i < count; i++)
if (bigIcon == NULL || (images[i].width > bigIcon->width && images[i].height > bigIcon->height)) {
bigIcon = &images[i]; if ((bigIcon == NULL) || ((images[i].width > bigIcon->width) && (images[i].height > bigIcon->height))) bigIcon = &images[i];
if (smallIcon == NULL || (images[i].width < smallIcon->width && images[i].height > smallIcon->height)) if ((smallIcon == NULL) || ((images[i].width < smallIcon->width) && (images[i].height > smallIcon->height))) smallIcon = &images[i];
smallIcon = &images[i];
} }
if (smallIcon != NULL) if (smallIcon != NULL) RGFW_window_setIconEx(platform.window, smallIcon->data, RGFW_AREA(smallIcon->width, smallIcon->height), RGFW_formatToChannels(smallIcon->format), RGFW_iconWindow);
RGFW_window_setIconEx(platform.window, smallIcon->data, RGFW_AREA(smallIcon->width, smallIcon->height), RGFW_formatToChannels(smallIcon->format), RGFW_iconWindow); if (bigIcon != NULL) RGFW_window_setIconEx(platform.window, bigIcon->data, RGFW_AREA(bigIcon->width, bigIcon->height), RGFW_formatToChannels(bigIcon->format), RGFW_iconTaskbar);
if (bigIcon != NULL)
RGFW_window_setIconEx(platform.window, bigIcon->data, RGFW_AREA(bigIcon->width, bigIcon->height), RGFW_formatToChannels(bigIcon->format), RGFW_iconTaskbar);
} }
} }
// Set title for window // Set title for window
void SetWindowTitle(const char *title) void SetWindowTitle(const char *title)
{ {
RGFW_window_setName(platform.window, (char *)title); RGFW_window_setName(platform.window, (char *)title);
CORE.Window.title = title; CORE.Window.title = title;
} }
@ -661,7 +656,8 @@ int GetMonitorCount(void)
int GetCurrentMonitor(void) int GetCurrentMonitor(void)
{ {
RGFW_monitor *mons = RGFW_getMonitors(); RGFW_monitor *mons = RGFW_getMonitors();
RGFW_monitor mon; RGFW_monitor mon = { 0 };
if (platform.window) mon = RGFW_window_getMonitor(platform.window); if (platform.window) mon = RGFW_window_getMonitor(platform.window);
else mon = RGFW_getPrimaryMonitor(); else mon = RGFW_getPrimaryMonitor();
@ -739,11 +735,12 @@ Vector2 GetWindowPosition(void)
// Get window scale DPI factor for current monitor // Get window scale DPI factor for current monitor
Vector2 GetWindowScaleDPI(void) Vector2 GetWindowScaleDPI(void)
{ {
RGFW_monitor monitor; RGFW_monitor monitor = { 0 };
if (platform.window) monitor = RGFW_window_getMonitor(platform.window); if (platform.window) monitor = RGFW_window_getMonitor(platform.window);
else monitor = RGFW_getPrimaryMonitor(); else monitor = RGFW_getPrimaryMonitor();
return (Vector2){monitor.scaleX, monitor.scaleX}; return (Vector2){ monitor.scaleX, monitor.scaleX };
} }
// Set clipboard text content // Set clipboard text content
@ -759,7 +756,6 @@ const char *GetClipboardText(void)
return RGFW_readClipboard(NULL); return RGFW_readClipboard(NULL);
} }
#if defined(SUPPORT_CLIPBOARD_IMAGE) #if defined(SUPPORT_CLIPBOARD_IMAGE)
#if defined(_WIN32) #if defined(_WIN32)
#define WIN32_CLIPBOARD_IMPLEMENTATION #define WIN32_CLIPBOARD_IMPLEMENTATION
@ -893,6 +889,7 @@ void SetMouseCursor(int cursor)
const char *GetKeyName(int key) const char *GetKeyName(int key)
{ {
TRACELOG(LOG_WARNING, "GetKeyName() unsupported on target platform"); TRACELOG(LOG_WARNING, "GetKeyName() unsupported on target platform");
return ""; return "";
} }
@ -1043,17 +1040,20 @@ void PollInputEvents(void)
CORE.Window.resizedLastFrame = true; CORE.Window.resizedLastFrame = true;
} break; } break;
case RGFW_windowMaximized: case RGFW_windowMaximized:
{
CORE.Window.flags |= FLAG_WINDOW_MAXIMIZED; // The window was maximized CORE.Window.flags |= FLAG_WINDOW_MAXIMIZED; // The window was maximized
break; } break;
case RGFW_windowMinimized: case RGFW_windowMinimized:
{
CORE.Window.flags |= FLAG_WINDOW_MINIMIZED; // The window was iconified CORE.Window.flags |= FLAG_WINDOW_MINIMIZED; // The window was iconified
break; } break;
case RGFW_windowRestored: case RGFW_windowRestored:
{
if (RGFW_window_isMaximized(platform.window)) if (RGFW_window_isMaximized(platform.window))
CORE.Window.flags &= ~FLAG_WINDOW_MAXIMIZED; // The window was restored CORE.Window.flags &= ~FLAG_WINDOW_MAXIMIZED; // The window was restored
if (RGFW_window_isMinimized(platform.window)) if (RGFW_window_isMinimized(platform.window))
CORE.Window.flags &= ~FLAG_WINDOW_MINIMIZED; // The window was restored CORE.Window.flags &= ~FLAG_WINDOW_MINIMIZED; // The window was restored
break; } break;
case RGFW_windowMoved: case RGFW_windowMoved:
{ {
CORE.Window.position.x = platform.window->r.x; CORE.Window.position.x = platform.window->r.x;
@ -1104,7 +1104,8 @@ void PollInputEvents(void)
{ {
CORE.Input.Mouse.currentWheelMove.y = event->scroll; CORE.Input.Mouse.currentWheelMove.y = event->scroll;
break; break;
} else CORE.Input.Mouse.currentWheelMove.y = 0; }
else CORE.Input.Mouse.currentWheelMove.y = 0;
int btn = event->button; int btn = event->button;
if (btn == RGFW_mouseLeft) btn = 1; if (btn == RGFW_mouseLeft) btn = 1;
@ -1122,7 +1123,8 @@ void PollInputEvents(void)
{ {
CORE.Input.Mouse.currentWheelMove.y = event->scroll; CORE.Input.Mouse.currentWheelMove.y = event->scroll;
break; break;
} else CORE.Input.Mouse.currentWheelMove.y = 0; }
else CORE.Input.Mouse.currentWheelMove.y = 0;
int btn = event->button; int btn = event->button;
if (btn == RGFW_mouseLeft) btn = 1; if (btn == RGFW_mouseLeft) btn = 1;
@ -1152,16 +1154,18 @@ void PollInputEvents(void)
touchAction = 2; touchAction = 2;
} break; } break;
case RGFW_gamepadConnected: case RGFW_gamepadConnected:
{
CORE.Input.Gamepad.ready[platform.window->event.gamepad] = true; CORE.Input.Gamepad.ready[platform.window->event.gamepad] = true;
CORE.Input.Gamepad.axisCount[platform.window->event.gamepad] = platform.window->event.axisesCount; CORE.Input.Gamepad.axisCount[platform.window->event.gamepad] = platform.window->event.axisesCount;
CORE.Input.Gamepad.axisState[platform.window->event.gamepad][GAMEPAD_AXIS_LEFT_TRIGGER] = -1.0f; CORE.Input.Gamepad.axisState[platform.window->event.gamepad][GAMEPAD_AXIS_LEFT_TRIGGER] = -1.0f;
CORE.Input.Gamepad.axisState[platform.window->event.gamepad][GAMEPAD_AXIS_RIGHT_TRIGGER] = -1.0f; CORE.Input.Gamepad.axisState[platform.window->event.gamepad][GAMEPAD_AXIS_RIGHT_TRIGGER] = -1.0f;
strcpy(CORE.Input.Gamepad.name[platform.window->event.gamepad], RGFW_getGamepadName(platform.window, platform.window->event.gamepad)); strcpy(CORE.Input.Gamepad.name[platform.window->event.gamepad], RGFW_getGamepadName(platform.window, platform.window->event.gamepad));
break; } break;
case RGFW_gamepadDisconnected: case RGFW_gamepadDisconnected:
{
CORE.Input.Gamepad.ready[platform.window->event.gamepad] = false; CORE.Input.Gamepad.ready[platform.window->event.gamepad] = false;
break; } break;
case RGFW_gamepadButtonPressed: case RGFW_gamepadButtonPressed:
{ {
int button = RGFW_gpConvTable[event->button]; int button = RGFW_gpConvTable[event->button];
@ -1182,8 +1186,8 @@ void PollInputEvents(void)
case RGFW_gamepadAxisMove: case RGFW_gamepadAxisMove:
{ {
int axis = -1; int axis = -1;
float value = 0; float value = 0;
switch(event->whichAxis) switch(event->whichAxis)
{ {
case 0: case 0:
@ -1200,6 +1204,7 @@ void PollInputEvents(void)
case 3: case 3:
{ {
if (axis == -1) axis = GAMEPAD_AXIS_RIGHT_TRIGGER; if (axis == -1) axis = GAMEPAD_AXIS_RIGHT_TRIGGER;
int button = (axis == GAMEPAD_AXIS_LEFT_TRIGGER)? GAMEPAD_BUTTON_LEFT_TRIGGER_2 : GAMEPAD_BUTTON_RIGHT_TRIGGER_2; int button = (axis == GAMEPAD_AXIS_LEFT_TRIGGER)? GAMEPAD_BUTTON_LEFT_TRIGGER_2 : GAMEPAD_BUTTON_RIGHT_TRIGGER_2;
int pressed = (value > 0.1f); int pressed = (value > 0.1f);
CORE.Input.Gamepad.currentButtonState[event->gamepad][button] = pressed; CORE.Input.Gamepad.currentButtonState[event->gamepad][button] = pressed;
@ -1276,7 +1281,6 @@ int InitPlatform(void)
if ((CORE.Window.flags & FLAG_WINDOW_HIDDEN) > 0) flags |= RGFW_windowHide; if ((CORE.Window.flags & FLAG_WINDOW_HIDDEN) > 0) flags |= RGFW_windowHide;
if ((CORE.Window.flags & FLAG_WINDOW_MAXIMIZED) > 0) flags |= RGFW_windowMaximize; if ((CORE.Window.flags & FLAG_WINDOW_MAXIMIZED) > 0) flags |= RGFW_windowMaximize;
// NOTE: Some OpenGL context attributes must be set before window creation // NOTE: Some OpenGL context attributes must be set before window creation
// Check selection OpenGL version // Check selection OpenGL version
if (rlGetVersion() == RL_OPENGL_21) if (rlGetVersion() == RL_OPENGL_21)
@ -1365,10 +1369,8 @@ int InitPlatform(void)
//---------------------------------------------------------------------------- //----------------------------------------------------------------------------
#if defined(RGFW_WAYLAND) #if defined(RGFW_WAYLAND)
if (RGFW_useWaylandBool) if (RGFW_useWaylandBool) TRACELOG(LOG_INFO, "PLATFORM: DESKTOP (RGFW - Wayland): Initialized successfully");
TRACELOG(LOG_INFO, "PLATFORM: DESKTOP (RGFW - Wayland): Initialized successfully"); else TRACELOG(LOG_INFO, "PLATFORM: DESKTOP (RGFW - X11 (fallback)): Initialized successfully");
else
TRACELOG(LOG_INFO, "PLATFORM: DESKTOP (RGFW - X11 (fallback)): Initialized successfully");
#elif defined(RGFW_X11) #elif defined(RGFW_X11)
#if defined(__APPLE__) #if defined(__APPLE__)
TRACELOG(LOG_INFO, "PLATFORM: DESKTOP (RGFW - X11 (MacOS)): Initialized successfully"); TRACELOG(LOG_INFO, "PLATFORM: DESKTOP (RGFW - X11 (MacOS)): Initialized successfully");