mirror of
https://github.com/raysan5/raylib.git
synced 2026-01-29 02:09:17 -05:00
REVIEWED: Platform code formatting and organization
This commit is contained in:
@ -130,27 +130,29 @@ void ClosePlatform(void); // Close platform
|
|||||||
static void ErrorCallback(int error, const char *description); // GLFW3 Error Callback, runs on GLFW3 error
|
static void ErrorCallback(int error, const char *description); // GLFW3 Error Callback, runs on GLFW3 error
|
||||||
|
|
||||||
// Window callbacks events
|
// Window callbacks events
|
||||||
static void WindowSizeCallback(GLFWwindow *window, int width, int height); // GLFW3 WindowSize Callback, runs when window is resized
|
static void WindowSizeCallback(GLFWwindow *window, int width, int height); // GLFW3 WindowSize Callback, runs when window is resized
|
||||||
static void WindowPosCallback(GLFWwindow* window, int x, int y); // GLFW3 WindowPos Callback, runs when window is moved
|
static void WindowPosCallback(GLFWwindow* window, int x, int y); // GLFW3 WindowPos Callback, runs when window is moved
|
||||||
static void WindowIconifyCallback(GLFWwindow *window, int iconified); // GLFW3 WindowIconify Callback, runs when window is minimized/restored
|
static void WindowIconifyCallback(GLFWwindow *window, int iconified); // GLFW3 WindowIconify Callback, runs when window is minimized/restored
|
||||||
static void WindowMaximizeCallback(GLFWwindow* window, int maximized); // GLFW3 Window Maximize Callback, runs when window is maximized
|
static void WindowMaximizeCallback(GLFWwindow* window, int maximized); // GLFW3 Window Maximize Callback, runs when window is maximized
|
||||||
static void WindowFocusCallback(GLFWwindow *window, int focused); // GLFW3 WindowFocus Callback, runs when window get/lose focus
|
static void WindowFocusCallback(GLFWwindow *window, int focused); // GLFW3 WindowFocus Callback, runs when window get/lose focus
|
||||||
static void WindowDropCallback(GLFWwindow *window, int count, const char **paths); // GLFW3 Window Drop Callback, runs when drop files into window
|
static void WindowDropCallback(GLFWwindow *window, int count, const char **paths); // GLFW3 Window Drop Callback, runs when drop files into window
|
||||||
static void WindowContentScaleCallback(GLFWwindow *window, float scalex, float scaley); // GLFW3 Window Content Scale Callback, runs when window changes scale
|
static void WindowContentScaleCallback(GLFWwindow *window, float scalex, float scaley); // GLFW3 Window Content Scale Callback, runs when window changes scale
|
||||||
|
|
||||||
// Input callbacks events
|
// Input callbacks events
|
||||||
static void KeyCallback(GLFWwindow *window, int key, int scancode, int action, int mods); // GLFW3 Keyboard Callback, runs on key pressed
|
static void KeyCallback(GLFWwindow *window, int key, int scancode, int action, int mods); // GLFW3 Keyboard Callback, runs on key pressed
|
||||||
static void CharCallback(GLFWwindow *window, unsigned int codepoint); // GLFW3 Char Callback, runs on key pressed (get codepoint value)
|
static void CharCallback(GLFWwindow *window, unsigned int codepoint); // GLFW3 Char Callback, runs on key pressed (get codepoint value)
|
||||||
static void MouseButtonCallback(GLFWwindow *window, int button, int action, int mods); // GLFW3 Mouse Button Callback, runs on mouse button pressed
|
static void MouseButtonCallback(GLFWwindow *window, int button, int action, int mods); // GLFW3 Mouse Button Callback, runs on mouse button pressed
|
||||||
static void MouseCursorPosCallback(GLFWwindow *window, double x, double y); // GLFW3 Cursor Position Callback, runs on mouse move
|
static void MouseCursorPosCallback(GLFWwindow *window, double x, double y); // GLFW3 Cursor Position Callback, runs on mouse move
|
||||||
static void MouseScrollCallback(GLFWwindow *window, double xoffset, double yoffset); // GLFW3 Scrolling Callback, runs on mouse wheel
|
static void MouseScrollCallback(GLFWwindow *window, double xoffset, double yoffset); // GLFW3 Scrolling Callback, runs on mouse wheel
|
||||||
static void CursorEnterCallback(GLFWwindow *window, int enter); // GLFW3 Cursor Enter Callback, cursor enters client area
|
static void CursorEnterCallback(GLFWwindow *window, int enter); // GLFW3 Cursor Enter Callback, cursor enters client area
|
||||||
static void JoystickCallback(int jid, int event); // GLFW3 Joystick Connected/Disconnected Callback
|
static void JoystickCallback(int jid, int event); // GLFW3 Joystick Connected/Disconnected Callback
|
||||||
|
|
||||||
// Wrappers used by glfwInitAllocator
|
// Memory allocator wrappers [used by glfwInitAllocator()]
|
||||||
static void *AllocateWrapper(size_t size, void *user); // GLFW3 GLFWallocatefun, wrapps around RL_CALLOC macro
|
static void *AllocateWrapper(size_t size, void *user); // GLFW3 GLFWallocatefun, wrapps around RL_CALLOC macro
|
||||||
static void *ReallocateWrapper(void *block, size_t size, void *user); // GLFW3 GLFWreallocatefun, wrapps around RL_REALLOC macro
|
static void *ReallocateWrapper(void *block, size_t size, void *user); // GLFW3 GLFWreallocatefun, wrapps around RL_REALLOC macro
|
||||||
static void DeallocateWrapper(void *block, void *user); // GLFW3 GLFWdeallocatefun, wraps around RL_FREE macro
|
static void DeallocateWrapper(void *block, void *user); // GLFW3 GLFWdeallocatefun, wraps around RL_FREE macro
|
||||||
|
|
||||||
|
static void SetDimensionsFromMonitor(GLFWmonitor *monitor); // Set screen dimensions from monitor/display dimensions
|
||||||
|
|
||||||
//----------------------------------------------------------------------------------
|
//----------------------------------------------------------------------------------
|
||||||
// Module Functions Declaration
|
// Module Functions Declaration
|
||||||
@ -435,7 +437,7 @@ void SetWindowState(unsigned int flags)
|
|||||||
// State change: FLAG_INTERLACED_HINT
|
// State change: FLAG_INTERLACED_HINT
|
||||||
if (((CORE.Window.flags & FLAG_INTERLACED_HINT) != (flags & FLAG_INTERLACED_HINT)) && ((flags & FLAG_INTERLACED_HINT) > 0))
|
if (((CORE.Window.flags & FLAG_INTERLACED_HINT) != (flags & FLAG_INTERLACED_HINT)) && ((flags & FLAG_INTERLACED_HINT) > 0))
|
||||||
{
|
{
|
||||||
TRACELOG(LOG_WARNING, "RPI: Interlaced mode can only be configured before window initialization");
|
TRACELOG(LOG_WARNING, "WINDOW: Interlaced mode can only be configured before window initialization");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -993,7 +995,7 @@ 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)
|
||||||
{
|
{
|
||||||
Vector2 scale = {0};
|
Vector2 scale = { 0 };
|
||||||
glfwGetWindowContentScale(platform.handle, &scale.x, &scale.y);
|
glfwGetWindowContentScale(platform.handle, &scale.x, &scale.y);
|
||||||
return scale;
|
return scale;
|
||||||
}
|
}
|
||||||
@ -1321,20 +1323,6 @@ void PollInputEvents(void)
|
|||||||
//----------------------------------------------------------------------------------
|
//----------------------------------------------------------------------------------
|
||||||
// Module Internal Functions Definition
|
// Module Internal Functions Definition
|
||||||
//----------------------------------------------------------------------------------
|
//----------------------------------------------------------------------------------
|
||||||
|
|
||||||
static void SetDimensionsFromMonitor(GLFWmonitor *monitor)
|
|
||||||
{
|
|
||||||
const GLFWvidmode *mode = glfwGetVideoMode(monitor);
|
|
||||||
|
|
||||||
// Default display resolution to that of the current mode
|
|
||||||
CORE.Window.display.width = mode->width;
|
|
||||||
CORE.Window.display.height = mode->height;
|
|
||||||
|
|
||||||
// Set screen width/height to the display width/height if they are 0
|
|
||||||
if (CORE.Window.screen.width == 0) CORE.Window.screen.width = CORE.Window.display.width;
|
|
||||||
if (CORE.Window.screen.height == 0) CORE.Window.screen.height = CORE.Window.display.height;
|
|
||||||
}
|
|
||||||
|
|
||||||
// Function wrappers around RL_*alloc macros, used by glfwInitAllocator() inside of InitPlatform()
|
// Function wrappers around RL_*alloc macros, used by glfwInitAllocator() inside of InitPlatform()
|
||||||
// We need to provide these because GLFWallocator expects function pointers with specific signatures
|
// We need to provide these because GLFWallocator expects function pointers with specific signatures
|
||||||
// Similar wrappers exist in utils.c but we cannot reuse them here due to declaration mismatch
|
// Similar wrappers exist in utils.c but we cannot reuse them here due to declaration mismatch
|
||||||
@ -1929,8 +1917,6 @@ static void KeyCallback(GLFWwindow *window, int key, int scancode, int action, i
|
|||||||
// GLFW3 Char Callback, get unicode codepoint value
|
// GLFW3 Char Callback, get unicode codepoint value
|
||||||
static void CharCallback(GLFWwindow *window, unsigned int codepoint)
|
static void CharCallback(GLFWwindow *window, unsigned int codepoint)
|
||||||
{
|
{
|
||||||
//TRACELOG(LOG_DEBUG, "Char Callback: Codepoint: %i", codepoint);
|
|
||||||
|
|
||||||
// NOTE: Registers any key down considering OS keyboard layout but
|
// NOTE: Registers any key down considering OS keyboard layout but
|
||||||
// does not detect action events, those should be managed by user...
|
// does not detect action events, those should be managed by user...
|
||||||
// Ref: https://github.com/glfw/glfw/issues/668#issuecomment-166794907
|
// Ref: https://github.com/glfw/glfw/issues/668#issuecomment-166794907
|
||||||
@ -2041,6 +2027,20 @@ static void JoystickCallback(int jid, int event)
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Set screen dimensions from monitor/display dimensions
|
||||||
|
static void SetDimensionsFromMonitor(GLFWmonitor *monitor)
|
||||||
|
{
|
||||||
|
const GLFWvidmode *mode = glfwGetVideoMode(monitor);
|
||||||
|
|
||||||
|
// Default display resolution to that of the current mode
|
||||||
|
CORE.Window.display.width = mode->width;
|
||||||
|
CORE.Window.display.height = mode->height;
|
||||||
|
|
||||||
|
// Set screen width/height to the display width/height if they are 0
|
||||||
|
if (CORE.Window.screen.width == 0) CORE.Window.screen.width = CORE.Window.display.width;
|
||||||
|
if (CORE.Window.screen.height == 0) CORE.Window.screen.height = CORE.Window.display.height;
|
||||||
|
}
|
||||||
|
|
||||||
#ifdef _WIN32
|
#ifdef _WIN32
|
||||||
# define WIN32_CLIPBOARD_IMPLEMENTATION
|
# define WIN32_CLIPBOARD_IMPLEMENTATION
|
||||||
# include "../external/win32_clipboard.h"
|
# include "../external/win32_clipboard.h"
|
||||||
|
|||||||
@ -240,12 +240,34 @@ static const unsigned short keyMappingRGFW[] = {
|
|||||||
[RGFW_scrollLock] = KEY_SCROLL_LOCK,
|
[RGFW_scrollLock] = KEY_SCROLL_LOCK,
|
||||||
};
|
};
|
||||||
|
|
||||||
|
static int RGFW_gpConvTable[18] = {
|
||||||
|
[RGFW_gamepadY] = GAMEPAD_BUTTON_RIGHT_FACE_UP,
|
||||||
|
[RGFW_gamepadB] = GAMEPAD_BUTTON_RIGHT_FACE_RIGHT,
|
||||||
|
[RGFW_gamepadA] = GAMEPAD_BUTTON_RIGHT_FACE_DOWN,
|
||||||
|
[RGFW_gamepadX] = GAMEPAD_BUTTON_RIGHT_FACE_LEFT,
|
||||||
|
[RGFW_gamepadL1] = GAMEPAD_BUTTON_LEFT_TRIGGER_1,
|
||||||
|
[RGFW_gamepadR1] = GAMEPAD_BUTTON_RIGHT_TRIGGER_1,
|
||||||
|
[RGFW_gamepadL2] = GAMEPAD_BUTTON_LEFT_TRIGGER_2,
|
||||||
|
[RGFW_gamepadR2] = GAMEPAD_BUTTON_RIGHT_TRIGGER_2,
|
||||||
|
[RGFW_gamepadSelect] = GAMEPAD_BUTTON_MIDDLE_LEFT,
|
||||||
|
[RGFW_gamepadHome] = GAMEPAD_BUTTON_MIDDLE,
|
||||||
|
[RGFW_gamepadStart] = GAMEPAD_BUTTON_MIDDLE_RIGHT,
|
||||||
|
[RGFW_gamepadUp] = GAMEPAD_BUTTON_LEFT_FACE_UP,
|
||||||
|
[RGFW_gamepadRight] = GAMEPAD_BUTTON_LEFT_FACE_RIGHT,
|
||||||
|
[RGFW_gamepadDown] = GAMEPAD_BUTTON_LEFT_FACE_DOWN,
|
||||||
|
[RGFW_gamepadLeft] = GAMEPAD_BUTTON_LEFT_FACE_LEFT,
|
||||||
|
[RGFW_gamepadL3] = GAMEPAD_BUTTON_LEFT_THUMB,
|
||||||
|
[RGFW_gamepadR3] = GAMEPAD_BUTTON_RIGHT_THUMB,
|
||||||
|
};
|
||||||
|
|
||||||
//----------------------------------------------------------------------------------
|
//----------------------------------------------------------------------------------
|
||||||
// Module Internal Functions Declaration
|
// Module Internal Functions Declaration
|
||||||
//----------------------------------------------------------------------------------
|
//----------------------------------------------------------------------------------
|
||||||
int InitPlatform(void); // Initialize platform (graphics, inputs and more)
|
int InitPlatform(void); // Initialize platform (graphics, inputs and more)
|
||||||
bool InitGraphicsDevice(void); // Initialize graphics device
|
bool InitGraphicsDevice(void); // Initialize graphics device
|
||||||
|
|
||||||
|
static KeyboardKey ConvertScancodeToKey(u32 keycode);
|
||||||
|
|
||||||
//----------------------------------------------------------------------------------
|
//----------------------------------------------------------------------------------
|
||||||
// Module Functions Declaration
|
// Module Functions Declaration
|
||||||
//----------------------------------------------------------------------------------
|
//----------------------------------------------------------------------------------
|
||||||
@ -897,28 +919,6 @@ const char *GetKeyName(int key)
|
|||||||
return "";
|
return "";
|
||||||
}
|
}
|
||||||
|
|
||||||
static KeyboardKey ConvertScancodeToKey(u32 keycode);
|
|
||||||
|
|
||||||
int RGFW_gpConvTable[18] = {
|
|
||||||
[RGFW_gamepadY] = GAMEPAD_BUTTON_RIGHT_FACE_UP,
|
|
||||||
[RGFW_gamepadB] = GAMEPAD_BUTTON_RIGHT_FACE_RIGHT,
|
|
||||||
[RGFW_gamepadA] = GAMEPAD_BUTTON_RIGHT_FACE_DOWN,
|
|
||||||
[RGFW_gamepadX] = GAMEPAD_BUTTON_RIGHT_FACE_LEFT,
|
|
||||||
[RGFW_gamepadL1] = GAMEPAD_BUTTON_LEFT_TRIGGER_1,
|
|
||||||
[RGFW_gamepadR1] = GAMEPAD_BUTTON_RIGHT_TRIGGER_1,
|
|
||||||
[RGFW_gamepadL2] = GAMEPAD_BUTTON_LEFT_TRIGGER_2,
|
|
||||||
[RGFW_gamepadR2] = GAMEPAD_BUTTON_RIGHT_TRIGGER_2,
|
|
||||||
[RGFW_gamepadSelect] = GAMEPAD_BUTTON_MIDDLE_LEFT,
|
|
||||||
[RGFW_gamepadHome] = GAMEPAD_BUTTON_MIDDLE,
|
|
||||||
[RGFW_gamepadStart] = GAMEPAD_BUTTON_MIDDLE_RIGHT,
|
|
||||||
[RGFW_gamepadUp] = GAMEPAD_BUTTON_LEFT_FACE_UP,
|
|
||||||
[RGFW_gamepadRight] = GAMEPAD_BUTTON_LEFT_FACE_RIGHT,
|
|
||||||
[RGFW_gamepadDown] = GAMEPAD_BUTTON_LEFT_FACE_DOWN,
|
|
||||||
[RGFW_gamepadLeft] = GAMEPAD_BUTTON_LEFT_FACE_LEFT,
|
|
||||||
[RGFW_gamepadL3] = GAMEPAD_BUTTON_LEFT_THUMB,
|
|
||||||
[RGFW_gamepadR3] = GAMEPAD_BUTTON_RIGHT_THUMB,
|
|
||||||
};
|
|
||||||
|
|
||||||
// Register all input events
|
// Register all input events
|
||||||
void PollInputEvents(void)
|
void PollInputEvents(void)
|
||||||
{
|
{
|
||||||
|
|||||||
@ -90,6 +90,8 @@
|
|||||||
#endif
|
#endif
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
#define SCANCODE_MAPPED_NUM 232
|
||||||
|
|
||||||
//----------------------------------------------------------------------------------
|
//----------------------------------------------------------------------------------
|
||||||
// Types and Structures Definition
|
// Types and Structures Definition
|
||||||
//----------------------------------------------------------------------------------
|
//----------------------------------------------------------------------------------
|
||||||
@ -110,10 +112,6 @@ extern CoreData CORE; // Global CORE state context
|
|||||||
|
|
||||||
static PlatformData platform = { 0 }; // Platform specific data
|
static PlatformData platform = { 0 }; // Platform specific data
|
||||||
|
|
||||||
//----------------------------------------------------------------------------------
|
|
||||||
// Global Variables Definition
|
|
||||||
//----------------------------------------------------------------------------------
|
|
||||||
#define SCANCODE_MAPPED_NUM 232
|
|
||||||
static const KeyboardKey mapScancodeToKey[SCANCODE_MAPPED_NUM] = {
|
static const KeyboardKey mapScancodeToKey[SCANCODE_MAPPED_NUM] = {
|
||||||
KEY_NULL, // SDL_SCANCODE_UNKNOWN
|
KEY_NULL, // SDL_SCANCODE_UNKNOWN
|
||||||
0,
|
0,
|
||||||
@ -321,7 +319,7 @@ Uint8 SDL_EventState(Uint32 type, int state)
|
|||||||
{
|
{
|
||||||
case SDL_DISABLE: SDL_SetEventEnabled(type, false); break;
|
case SDL_DISABLE: SDL_SetEventEnabled(type, false); break;
|
||||||
case SDL_ENABLE: SDL_SetEventEnabled(type, true); break;
|
case SDL_ENABLE: SDL_SetEventEnabled(type, true); break;
|
||||||
default: TRACELOG(LOG_WARNING, "Event sate: unknow type");
|
default: TRACELOG(LOG_WARNING, "SDL: Event state of unknow type");
|
||||||
}
|
}
|
||||||
|
|
||||||
return stateBefore;
|
return stateBefore;
|
||||||
@ -329,10 +327,10 @@ Uint8 SDL_EventState(Uint32 type, int state)
|
|||||||
|
|
||||||
void SDL_GetCurrentDisplayMode_Adapter(SDL_DisplayID displayID, SDL_DisplayMode* mode)
|
void SDL_GetCurrentDisplayMode_Adapter(SDL_DisplayID displayID, SDL_DisplayMode* mode)
|
||||||
{
|
{
|
||||||
const SDL_DisplayMode* currMode = SDL_GetCurrentDisplayMode(displayID);
|
const SDL_DisplayMode *currentMode = SDL_GetCurrentDisplayMode(displayID);
|
||||||
|
|
||||||
if (currMode == NULL) TRACELOG(LOG_WARNING, "No current display mode");
|
if (currentMode == NULL) TRACELOG(LOG_WARNING, "SDL: No possible to get current display mode");
|
||||||
else *mode = *currMode;
|
else *mode = *currentMode;
|
||||||
}
|
}
|
||||||
|
|
||||||
// SDL3 Migration: Renamed
|
// SDL3 Migration: Renamed
|
||||||
@ -423,7 +421,7 @@ int SDL_GetNumTouchFingers(SDL_TouchID touchID)
|
|||||||
// SDL_GetClipboardData function is available since SDL 3.1.3. (e.g. SDL3)
|
// SDL_GetClipboardData function is available since SDL 3.1.3. (e.g. SDL3)
|
||||||
void *SDL_GetClipboardData(const char *mime_type, size_t *size)
|
void *SDL_GetClipboardData(const char *mime_type, size_t *size)
|
||||||
{
|
{
|
||||||
TRACELOG(LOG_WARNING, "Getting clipboard data that is not text is only available in SDL3");
|
TRACELOG(LOG_WARNING, "SDL: Getting clipboard data that is not text not available in SDL2");
|
||||||
|
|
||||||
// We could possibly implement it ourselves in this case for some easier platforms
|
// We could possibly implement it ourselves in this case for some easier platforms
|
||||||
return NULL;
|
return NULL;
|
||||||
@ -438,8 +436,8 @@ int InitPlatform(void); // Initialize platf
|
|||||||
void ClosePlatform(void); // Close platform
|
void ClosePlatform(void); // Close platform
|
||||||
|
|
||||||
static KeyboardKey ConvertScancodeToKey(SDL_Scancode sdlScancode); // Help convert SDL scancodes to raylib key
|
static KeyboardKey ConvertScancodeToKey(SDL_Scancode sdlScancode); // Help convert SDL scancodes to raylib key
|
||||||
|
|
||||||
static int GetCodepointNextSDL(const char *text, int *codepointSize); // Get next codepoint in a byte sequence and bytes processed
|
static int GetCodepointNextSDL(const char *text, int *codepointSize); // Get next codepoint in a byte sequence and bytes processed
|
||||||
|
static void UpdateTouchPointsSDL(SDL_TouchFingerEvent event); // Update CORE input touch point info from SDL touch data
|
||||||
|
|
||||||
//----------------------------------------------------------------------------------
|
//----------------------------------------------------------------------------------
|
||||||
// Module Functions Declaration
|
// Module Functions Declaration
|
||||||
@ -1307,41 +1305,6 @@ const char *GetKeyName(int key)
|
|||||||
return SDL_GetKeyName(key);
|
return SDL_GetKeyName(key);
|
||||||
}
|
}
|
||||||
|
|
||||||
static void UpdateTouchPointsSDL(SDL_TouchFingerEvent event)
|
|
||||||
{
|
|
||||||
#if defined(USING_VERSION_SDL3) // SDL3
|
|
||||||
int count = 0;
|
|
||||||
SDL_Finger **fingers = SDL_GetTouchFingers(event.touchID, &count);
|
|
||||||
CORE.Input.Touch.pointCount = count;
|
|
||||||
|
|
||||||
for (int i = 0; i < CORE.Input.Touch.pointCount; i++)
|
|
||||||
{
|
|
||||||
SDL_Finger *finger = fingers[i];
|
|
||||||
CORE.Input.Touch.pointId[i] = finger->id;
|
|
||||||
CORE.Input.Touch.position[i].x = finger->x*CORE.Window.screen.width;
|
|
||||||
CORE.Input.Touch.position[i].y = finger->y*CORE.Window.screen.height;
|
|
||||||
CORE.Input.Touch.currentTouchState[i] = 1;
|
|
||||||
}
|
|
||||||
|
|
||||||
SDL_free(fingers);
|
|
||||||
|
|
||||||
#else // SDL2
|
|
||||||
|
|
||||||
CORE.Input.Touch.pointCount = SDL_GetNumTouchFingers(event.touchId);
|
|
||||||
|
|
||||||
for (int i = 0; i < CORE.Input.Touch.pointCount; i++)
|
|
||||||
{
|
|
||||||
SDL_Finger *finger = SDL_GetTouchFinger(event.touchId, i);
|
|
||||||
CORE.Input.Touch.pointId[i] = finger->id;
|
|
||||||
CORE.Input.Touch.position[i].x = finger->x*CORE.Window.screen.width;
|
|
||||||
CORE.Input.Touch.position[i].y = finger->y*CORE.Window.screen.height;
|
|
||||||
CORE.Input.Touch.currentTouchState[i] = 1;
|
|
||||||
}
|
|
||||||
#endif
|
|
||||||
|
|
||||||
for (int i = CORE.Input.Touch.pointCount; i < MAX_TOUCH_POINTS; i++) CORE.Input.Touch.currentTouchState[i] = 0;
|
|
||||||
}
|
|
||||||
|
|
||||||
// Register all input events
|
// Register all input events
|
||||||
void PollInputEvents(void)
|
void PollInputEvents(void)
|
||||||
{
|
{
|
||||||
@ -1399,15 +1362,9 @@ void PollInputEvents(void)
|
|||||||
|
|
||||||
// Poll input events for current platform
|
// Poll input events for current platform
|
||||||
//-----------------------------------------------------------------------------
|
//-----------------------------------------------------------------------------
|
||||||
/*
|
|
||||||
// WARNING: Indexes into this array are obtained by using SDL_Scancode values, not SDL_Keycode values
|
// WARNING: Indexes into this array are obtained by using SDL_Scancode values, not SDL_Keycode values
|
||||||
const Uint8 *keys = SDL_GetKeyboardState(NULL);
|
//const Uint8 *keys = SDL_GetKeyboardState(NULL);
|
||||||
for (int i = 0; i < 256; ++i)
|
//for (int i = 0; i < 256; ++i) CORE.Input.Keyboard.currentKeyState[i] = keys[i];
|
||||||
{
|
|
||||||
CORE.Input.Keyboard.currentKeyState[i] = keys[i];
|
|
||||||
//if (keys[i]) TRACELOG(LOG_WARNING, "Pressed key: %i", i);
|
|
||||||
}
|
|
||||||
*/
|
|
||||||
|
|
||||||
CORE.Window.resizedLastFrame = false;
|
CORE.Window.resizedLastFrame = false;
|
||||||
|
|
||||||
@ -2174,3 +2131,39 @@ static int GetCodepointNextSDL(const char *text, int *codepointSize)
|
|||||||
|
|
||||||
return codepoint;
|
return codepoint;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Update CORE input touch point info from SDL touch data
|
||||||
|
static void UpdateTouchPointsSDL(SDL_TouchFingerEvent event)
|
||||||
|
{
|
||||||
|
#if defined(USING_VERSION_SDL3) // SDL3
|
||||||
|
int count = 0;
|
||||||
|
SDL_Finger **fingers = SDL_GetTouchFingers(event.touchID, &count);
|
||||||
|
CORE.Input.Touch.pointCount = count;
|
||||||
|
|
||||||
|
for (int i = 0; i < CORE.Input.Touch.pointCount; i++)
|
||||||
|
{
|
||||||
|
SDL_Finger *finger = fingers[i];
|
||||||
|
CORE.Input.Touch.pointId[i] = finger->id;
|
||||||
|
CORE.Input.Touch.position[i].x = finger->x*CORE.Window.screen.width;
|
||||||
|
CORE.Input.Touch.position[i].y = finger->y*CORE.Window.screen.height;
|
||||||
|
CORE.Input.Touch.currentTouchState[i] = 1;
|
||||||
|
}
|
||||||
|
|
||||||
|
SDL_free(fingers);
|
||||||
|
|
||||||
|
#else // SDL2
|
||||||
|
|
||||||
|
CORE.Input.Touch.pointCount = SDL_GetNumTouchFingers(event.touchId);
|
||||||
|
|
||||||
|
for (int i = 0; i < CORE.Input.Touch.pointCount; i++)
|
||||||
|
{
|
||||||
|
SDL_Finger *finger = SDL_GetTouchFinger(event.touchId, i);
|
||||||
|
CORE.Input.Touch.pointId[i] = finger->id;
|
||||||
|
CORE.Input.Touch.position[i].x = finger->x*CORE.Window.screen.width;
|
||||||
|
CORE.Input.Touch.position[i].y = finger->y*CORE.Window.screen.height;
|
||||||
|
CORE.Input.Touch.currentTouchState[i] = 1;
|
||||||
|
}
|
||||||
|
#endif
|
||||||
|
|
||||||
|
for (int i = CORE.Input.Touch.pointCount; i < MAX_TOUCH_POINTS; i++) CORE.Input.Touch.currentTouchState[i] = 0;
|
||||||
|
}
|
||||||
|
|||||||
@ -245,6 +245,7 @@ static void RestoreKeyboard(void); // Restore keyboard system
|
|||||||
static void ProcessKeyboard(void); // Process keyboard events
|
static void ProcessKeyboard(void); // Process keyboard events
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
// Input management functions
|
||||||
static void InitEvdevInput(void); // Initialize evdev inputs
|
static void InitEvdevInput(void); // Initialize evdev inputs
|
||||||
static void ConfigureEvdevDevice(char *device); // Identifies a input device and configures it for use if appropriate
|
static void ConfigureEvdevDevice(char *device); // Identifies a input device and configures it for use if appropriate
|
||||||
static void PollKeyboardEvents(void); // Process evdev keyboard events
|
static void PollKeyboardEvents(void); // Process evdev keyboard events
|
||||||
@ -703,7 +704,7 @@ void SwapScreenBuffer()
|
|||||||
if (!crtcSet || !platform.gbmSurface) return;
|
if (!crtcSet || !platform.gbmSurface) return;
|
||||||
|
|
||||||
static int loopCnt = 0;
|
static int loopCnt = 0;
|
||||||
static int errCnt[5] = {0};
|
static int errCnt[5] = { 0 };
|
||||||
loopCnt++;
|
loopCnt++;
|
||||||
|
|
||||||
// Call this only, if pendingFlip is not set
|
// Call this only, if pendingFlip is not set
|
||||||
|
|||||||
@ -1722,8 +1722,7 @@ static EM_BOOL EmscriptenTouchCallback(int eventType, const EmscriptenTouchEvent
|
|||||||
}
|
}
|
||||||
|
|
||||||
#if defined(SUPPORT_GESTURES_SYSTEM)
|
#if defined(SUPPORT_GESTURES_SYSTEM)
|
||||||
GestureEvent gestureEvent = {0};
|
GestureEvent gestureEvent = { 0 };
|
||||||
|
|
||||||
gestureEvent.pointCount = CORE.Input.Touch.pointCount;
|
gestureEvent.pointCount = CORE.Input.Touch.pointCount;
|
||||||
|
|
||||||
// Register touch actions
|
// Register touch actions
|
||||||
@ -1852,7 +1851,7 @@ static EM_BOOL EmscriptenVisibilityChangeCallback(int eventType, const Emscripte
|
|||||||
//-------------------------------------------------------------------------------------------------------
|
//-------------------------------------------------------------------------------------------------------
|
||||||
|
|
||||||
// JS: Get the canvas id provided by the module configuration
|
// JS: Get the canvas id provided by the module configuration
|
||||||
EM_JS(char*, GetCanvasIdJs, (), {
|
EM_JS(char *, GetCanvasIdJs, (), {
|
||||||
var canvasId = "#" + Module.canvas.id;
|
var canvasId = "#" + Module.canvas.id;
|
||||||
var lengthBytes = lengthBytesUTF8(canvasId) + 1;
|
var lengthBytes = lengthBytesUTF8(canvasId) + 1;
|
||||||
var stringOnWasmHeap = _malloc(lengthBytes);
|
var stringOnWasmHeap = _malloc(lengthBytes);
|
||||||
|
|||||||
Reference in New Issue
Block a user