REVIEWED: Code formatting to follow raylib conventions

This commit is contained in:
Ray 2024-07-09 09:21:57 +02:00
parent 98662b6a4a
commit fa03246d0e

View file

@ -53,7 +53,7 @@
void ShowCursor(void); void ShowCursor(void);
void CloseWindow(void); void CloseWindow(void);
#ifdef __linux__ #if defined(__linux__)
#define _INPUT_EVENT_CODES_H #define _INPUT_EVENT_CODES_H
#endif #endif
@ -71,19 +71,17 @@ void CloseWindow(void);
#define _APISETSTRING_ #define _APISETSTRING_
#endif #endif
#ifdef __APPLE__ #if defined(__APPLE__)
#define Point NSPOINT #define Point NSPOINT
#define Size NSSIZE #define Size NSSIZE
#endif #endif
#ifdef _MSC_VER #if defined(_MSC_VER)
__declspec(dllimport) int __stdcall MultiByteToWideChar(unsigned int CodePage, unsigned long dwFlags, const char *lpMultiByteStr, int cbMultiByte, wchar_t *lpWideCharStr, int cchWideChar); __declspec(dllimport) int __stdcall MultiByteToWideChar(unsigned int CodePage, unsigned long dwFlags, const char *lpMultiByteStr, int cbMultiByte, wchar_t *lpWideCharStr, int cchWideChar);
#endif #endif
#include "../external/RGFW.h" #include "../external/RGFW.h"
#if defined(__WIN32) || defined(__WIN64) #if defined(__WIN32) || defined(__WIN64)
#undef DrawText #undef DrawText
#undef ShowCursor #undef ShowCursor
@ -91,12 +89,13 @@ __declspec(dllimport) int __stdcall MultiByteToWideChar(unsigned int CodePage,
#undef Rectangle #undef Rectangle
#endif #endif
#ifdef __APPLE__ #if defined(__APPLE__)
#undef Point #undef Point
#undef Size #undef Size
#endif #endif
#include <stdbool.h> #include <stdbool.h>
#include <string.h> // Required for: strcmp()
//---------------------------------------------------------------------------------- //----------------------------------------------------------------------------------
// Types and Structures Definition // Types and Structures Definition
@ -112,6 +111,8 @@ extern CoreData CORE; // Global CORE state context
static PlatformData platform = { NULL }; // Platform specific static PlatformData platform = { NULL }; // Platform specific
static bool RGFW_disableCursor = false;
static const unsigned short keyMappingRGFW[] = { static const unsigned short keyMappingRGFW[] = {
[RGFW_KEY_NULL] = KEY_NULL, [RGFW_KEY_NULL] = KEY_NULL,
[RGFW_Quote] = KEY_APOSTROPHE, [RGFW_Quote] = KEY_APOSTROPHE,
@ -250,7 +251,8 @@ void ToggleFullscreen(void)
// Toggle borderless windowed mode // Toggle borderless windowed mode
void ToggleBorderlessWindowed(void) void ToggleBorderlessWindowed(void)
{ {
if (platform.window != NULL) { if (platform.window != NULL)
{
RGFW_window_setBorder(platform.window, CORE.Window.flags & FLAG_WINDOW_UNDECORATED); RGFW_window_setBorder(platform.window, CORE.Window.flags & FLAG_WINDOW_UNDECORATED);
} }
} }
@ -569,8 +571,7 @@ int GetCurrentMonitor(void)
for (int i = 0; i < 6; i++) for (int i = 0; i < 6; i++)
{ {
if ((mons[i].rect.x == mon.rect.x) && (mons[i].rect.y == mon.rect.y)) if ((mons[i].rect.x == mon.rect.x) && (mons[i].rect.y == mon.rect.y)) return i;
return i;
} }
return 0; return 0;
@ -672,8 +673,6 @@ void HideCursor(void)
CORE.Input.Mouse.cursorHidden = true; CORE.Input.Mouse.cursorHidden = true;
} }
bool RGFW_disableCursor = false;
// Enables cursor (unlock cursor) // Enables cursor (unlock cursor)
void EnableCursor(void) void EnableCursor(void)
{ {
@ -690,6 +689,7 @@ void EnableCursor(void)
void DisableCursor(void) void DisableCursor(void)
{ {
RGFW_disableCursor = true; RGFW_disableCursor = true;
// Set cursor position in the middle // Set cursor position in the middle
SetMousePosition(CORE.Window.screen.width/2, CORE.Window.screen.height/2); SetMousePosition(CORE.Window.screen.width/2, CORE.Window.screen.height/2);
@ -727,7 +727,7 @@ void OpenURL(const char *url)
if (strchr(url, '\'') != NULL) TRACELOG(LOG_WARNING, "SYSTEM: Provided URL could be potentially malicious, avoid [\'] character"); if (strchr(url, '\'') != NULL) TRACELOG(LOG_WARNING, "SYSTEM: Provided URL could be potentially malicious, avoid [\'] character");
else else
{ {
// TODO: // TODO: Open URL implementation
} }
} }
@ -758,14 +758,10 @@ void SetMouseCursor(int cursor)
static KeyboardKey ConvertScancodeToKey(u32 keycode); static KeyboardKey ConvertScancodeToKey(u32 keycode);
/* // TODO: Review function to avoid duplicate with RSGL
TODO, try to make this better (RSGL uses this method too :I ) char RSGL_keystrToChar(const char *str)
sourced from RSGL obviously -> ColleagueRiley {
*/ if (str[1] == 0) return str[0];
char RSGL_keystrToChar(const char* str) {
if (str[1] == 0)
return str[0];
static const char *map[] = { static const char *map[] = {
"asciitilde", "`", "asciitilde", "`",
@ -806,10 +802,10 @@ char RSGL_keystrToChar(const char* str) {
"enter", "\n", "enter", "\n",
}; };
u8 i = 0; for (unsigned char i = 0; i < (sizeof(map)/sizeof(char *)); i += 2)
for (i = 0; i < (sizeof(map) / sizeof(char*)); i += 2) {
if (strcmp(map[i], str) == 0) if (strcmp(map[i], str) == 0) return *map[i + 1];
return *map[i + 1]; }
return '\0'; return '\0';
} }
@ -866,22 +862,22 @@ void PollInputEvents(void)
} }
// Register previous mouse states // Register previous mouse states
for (int i = 0; i < MAX_MOUSE_BUTTONS; i++) for (int i = 0; i < MAX_MOUSE_BUTTONS; i++) CORE.Input.Mouse.previousButtonState[i] = CORE.Input.Mouse.currentButtonState[i];
CORE.Input.Mouse.previousButtonState[i] = CORE.Input.Mouse.currentButtonState[i];
// Poll input events for current platform // Poll input events for current platform
//----------------------------------------------------------------------------- //-----------------------------------------------------------------------------
CORE.Window.resizedLastFrame = false; CORE.Window.resizedLastFrame = false;
#define RGFW_HOLD_MOUSE (1L<<2) #define RGFW_HOLD_MOUSE (1L<<2)
#if defined(RGFW_X11) //|| defined(RGFW_MACOS) #if defined(RGFW_X11) //|| defined(RGFW_MACOS)
if (platform.window->src.winArgs & RGFW_HOLD_MOUSE) if (platform.window->src.winArgs & RGFW_HOLD_MOUSE)
{ {
CORE.Input.Mouse.previousPosition = (Vector2){ 0.0f, 0.0f }; CORE.Input.Mouse.previousPosition = (Vector2){ 0.0f, 0.0f };
CORE.Input.Mouse.currentPosition = (Vector2){ 0.0f, 0.0f }; CORE.Input.Mouse.currentPosition = (Vector2){ 0.0f, 0.0f };
} }
else { else
{
CORE.Input.Mouse.previousPosition = CORE.Input.Mouse.currentPosition; CORE.Input.Mouse.previousPosition = CORE.Input.Mouse.currentPosition;
} }
#endif #endif
@ -1163,6 +1159,7 @@ void PollInputEvents(void)
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->joystick][button] = pressed; CORE.Input.Gamepad.currentButtonState[event->joystick][button] = pressed;
if (pressed) CORE.Input.Gamepad.lastButtonPressed = button; if (pressed) CORE.Input.Gamepad.lastButtonPressed = button;
else if (CORE.Input.Gamepad.lastButtonPressed == button) CORE.Input.Gamepad.lastButtonPressed = 0; else if (CORE.Input.Gamepad.lastButtonPressed == button) CORE.Input.Gamepad.lastButtonPressed = 0;
} }
@ -1254,8 +1251,7 @@ int InitPlatform(void)
platform.window = RGFW_createWindow(CORE.Window.title, RGFW_RECT(0, 0, CORE.Window.screen.width, CORE.Window.screen.height), flags); platform.window = RGFW_createWindow(CORE.Window.title, RGFW_RECT(0, 0, CORE.Window.screen.width, CORE.Window.screen.height), flags);
if (CORE.Window.flags & FLAG_VSYNC_HINT) if (CORE.Window.flags & FLAG_VSYNC_HINT) RGFW_window_swapInterval(platform.window, 1);
RGFW_window_swapInterval(platform.window, 1);
RGFW_window_makeCurrent(platform.window); RGFW_window_makeCurrent(platform.window);