16 Commits

Author SHA1 Message Date
Ray
e045e8fa1f REDESIGNED: Gestures system, process touch/mouse actions after being polled
Gestures system has been redesigned to avoid duplicate code calls on all platform backends, now platforms can just store `CORE.Input.Touch` state and information is processed on `rcore` main loop (`EndDrawing()`) after `PollInputEvents()`.

`rgestures` module was created on 2014 and it has barely been updated along the years, it has many problems. Current gestures detection mechanisms try to detect gestures only on touch-events detection (touch/mouse UP-DOWN-MOVE). A new (future) design could consider detection running per-frame.
2026-11-27 20:44:45 +01:00
Ray
aefcca3505 Reverted changes TextReplace() and TextReplaceAlloc()
After further review thy are considering a very limit case where the resulting strings are longer than INT_MAX, that only can happen if user passes that kind of limit. `MAX_TEXT_BUFFER_LENGTH` is  more than enough.
2026-11-27 19:35:53 +01:00
8054413f53 [examples] Use render width for high-DPI pixel grid (#6447)
Co-authored-by: yex743055-sudo <318559365+yex743055-sudo@users.noreply.github.com>
2026-11-27 19:21:52 +01:00
0a63f1252f Fix for integer overflow (#6452) (#6453)
* Fix for integer overflow (#6452)

* Change to avoid using (long long) and check for overflow before usage
2026-11-27 19:20:10 +01:00
99b0707988 [rtext] Fix TextJoin dropping the last string at the buffer limit (#6454) 2026-11-27 12:41:26 +01:00
Ray
40b9da5e54 Update CONVENTIONS.md 2026-11-26 23:04:32 +01:00
1f64f34cc0 [rcore][win32] Implement monitor query functions (#6450)
* [rcore][win32] Implement monitor query functions

* Update monitor name in RefreshMonitorsProc instead of lazily allocating it
2026-11-26 22:36:47 +01:00
7aeef57754 [rlsw] Add missing function declarations (#6451) 2026-11-25 20:00:43 +01:00
Ray
7cbadefd06 Remove some spacing on module data 2026-11-24 21:09:37 +01:00
Ray
9fcb245f28 Clipboard image enabled by default 2026-11-24 21:09:03 +01:00
dd8e7491e2 [rmodels] Fix memory leak in LoadModelAnimations() (#6449) 2026-11-24 15:14:10 +01:00
fa14dc7792 [Examples] Updated text_animations shaking delta generation (#6448) 2026-11-24 12:08:39 +01:00
88b10152e9 rlparser: update raylib_api.* by CI 2026-11-24 11:07:33 +00:00
Ray
867376c6cb ADDED: SetClipboardImage() -WIP- 2026-11-24 12:07:10 +01:00
Ray
b7011ad4d4 Update Makefile.Android 2026-11-24 12:01:18 +01:00
b4a4f9d360 [rtextures] Round instead of truncate in ColorFromHSV() (#6445) 2026-11-24 10:23:09 +01:00
28 changed files with 1384 additions and 1281 deletions

View File

@ -77,7 +77,7 @@ if (dataPtr != NULL)
dataPtr = NULL;
}
```
- Memory allocation return value checks: no checks are done, the probabilities of allocators failing are very low and it would add a great amount of checking code, if a finer control is needed for allocators, macors can be overriden by custom implementations.
- Memory allocation return value checks: no checks are done, the probabilities of allocators failing are very low and it would add a great amount of checking code, if a finer control is needed for allocators, macros are provided to be overriden with custom implementations.
**If proposing new functions, please try to use a clear naming for function-name and functions-parameters, in case of doubt, open an issue for discussion.**

View File

@ -26,15 +26,16 @@ PLATFORM ?= PLATFORM_ANDROID
RAYLIB_PATH ?= ..\..
# Define Android architecture (armeabi-v7a, arm64-v8a, x86, x86-64) and API version
# Starting in 2019 using ARM64 is mandatory for published apps,
# Starting on August 2020, minimum required target API is Android 10 (API level 29)
# NOTE: Starting in 2019 using ARM64 is mandatory for published apps
# NOTE: Starting on August 2020, minimum required target API is Android 10 (API level 29)
# NOTE: Android 13 (API level 33), released on August 2022 should be a safe bet
ANDROID_ARCH ?= ARM64
ANDROID_API_VERSION = 29
ANDROID_API_VERSION = 33
# Android required path variables
# NOTE: Starting with Android NDK r21, no more toolchain generation is required, NDK is the toolchain on itself
ifeq ($(OS),Windows_NT)
ANDROID_NDK = C:/android-ndk
ANDROID_NDK = C:/android-ndk-r30
ANDROID_TOOLCHAIN = $(ANDROID_NDK)/toolchains/llvm/prebuilt/windows-x86_64
else
ANDROID_NDK ?= /usr/lib/android/ndk
@ -55,10 +56,10 @@ ifeq ($(ANDROID_ARCH),x86_64)
endif
# Required path variables
# NOTE: JAVA_HOME must be set to JDK (using OpenJDK 13)
JAVA_HOME ?= C:/open-jdk
# NOTE: JAVA_HOME must be set to JDK (using OpenJDK 27.0.1.1)
JAVA_HOME ?= C:/open-jdk-27.0.1.1
ANDROID_HOME ?= C:/android-sdk
ANDROID_BUILD_TOOLS ?= $(ANDROID_HOME)/build-tools/29.0.3
ANDROID_BUILD_TOOLS ?= $(ANDROID_HOME)/build-tools/36.0.0
ANDROID_PLATFORM_TOOLS = $(ANDROID_HOME)/platform-tools
# Android project configuration variables
@ -137,7 +138,9 @@ CFLAGS += -ffunction-sections -funwind-tables -fstack-protector-strong -fPIC
# Compiler options for the linker
CFLAGS += -Wall -Wa,--noexecstack -Wformat -Werror=format-security -no-canonical-prefixes
# Preprocessor macro definitions
CFLAGS += -DANDROID -DPLATFORM_ANDROID -D__ANDROID_API__=$(ANDROID_API_VERSION)
CFLAGS += -DANDROID -DPLATFORM_ANDROID
# NOTE: API level is already implicit on compiler call, no need for redefinition
#-D__ANDROID_API__=$(ANDROID_API_VERSION)
# Paths containing required header files
INCLUDE_PATHS = -I. -I$(RAYLIB_PATH)/src -I$(NATIVE_APP_GLUE_PATH)

View File

@ -32,6 +32,7 @@ int main(void)
const int screenWidth = 800;
const int screenHeight = 450;
// Remove FLAG_WINDOW_HIGHDPI to compare with automatic DPI scaling disabled
SetConfigFlags(FLAG_WINDOW_HIGHDPI | FLAG_WINDOW_RESIZABLE);
InitWindow(screenWidth, screenHeight, "raylib [core] example - highdpi demo");
SetWindowMinSize(450, 450);
@ -45,7 +46,6 @@ int main(void)
int pixelGridLabelY = pixelGridBottom + 30;
int pixelGridDescY = pixelGridLabelY + 30;
int cellSize = 50;
float cellSizePx = (float)cellSize;
SetTargetFPS(60); // Set our game to run at 60 frames-per-second
//--------------------------------------------------------------------------------------
@ -64,7 +64,11 @@ int main(void)
int currentMonitor = GetCurrentMonitor();
Vector2 dpiScale = GetWindowScaleDPI();
cellSizePx = ((float)cellSize)/dpiScale.x;
int renderWidth = GetRenderWidth();
// The monitor DPI scale can differ from the actual render scale when HiDPI is disabled
float renderToLogicalX = (renderWidth > 0)? ((float)GetScreenWidth())/renderWidth : 1.0f;
int pixelCellWidth = (int)(cellSize*renderToLogicalX);
//----------------------------------------------------------------------------------
// Draw
@ -90,12 +94,12 @@ int main(void)
odd = true;
const int minTextSpace = 30;
int lastTextX = -minTextSpace;
for (int i = cellSize; i < GetRenderWidth(); i += cellSize, odd = !odd)
for (int i = cellSize; i < renderWidth; i += cellSize, odd = !odd)
{
int x = (int)(((float)i)/dpiScale.x);
if (odd) DrawRectangle(x, pixelGridTop, (int)cellSizePx, pixelGridBottom - pixelGridTop, CLITERAL(Color){ 0, 121, 241, 100 });
int x = (int)(i*renderToLogicalX);
if (odd) DrawRectangle(x, pixelGridTop, pixelCellWidth, pixelGridBottom - pixelGridTop, CLITERAL(Color){ 0, 121, 241, 100 });
DrawLine(x, pixelGridTop, (int)(((float)i)/dpiScale.x), pixelGridLabelY - 10, GRAY);
DrawLine(x, pixelGridTop, x, pixelGridLabelY - 10, GRAY);
if ((x - lastTextX) >= minTextSpace)
{
@ -104,7 +108,7 @@ int main(void)
}
}
DrawTextCenter(TextFormat("Window is %d \"physical pixels\" wide", GetRenderWidth()), windowCenter, pixelGridDescY, 20, BLUE);
DrawTextCenter(TextFormat("Window is %d \"physical pixels\" wide", renderWidth), windowCenter, pixelGridDescY, 20, BLUE);
const char *text = "Can you see this?";
Vector2 size = MeasureTextEx(GetFontDefault(), text, 20, 3);

View File

@ -52,6 +52,7 @@ int main(void)
int frameCount = 0;
Vector2 glyphPosition[MAX_TEXT_LENGTH] = { 0 };
Vector2 glyphDelta[MAX_TEXT_LENGTH] = { 0 };
unsigned char glyphAlpha[MAX_TEXT_LENGTH] = { 0 };
SetTargetFPS(60);
@ -66,8 +67,8 @@ int main(void)
if (IsKeyPressed(KEY_S)) text.delta = Clamp(text.delta - 2.0f, 10.0f, 60.0f);
else if (IsKeyPressed(KEY_W)) text.delta = Clamp(text.delta + 2.0f, 10.0f, 60.0f);
if (IsKeyPressed(KEY_A)) text.duration = (int) Clamp((float) text.duration - 5.0f, 20.0f, 120.0f);
else if (IsKeyPressed(KEY_D)) text.duration = (int) Clamp((float) text.duration + 5.0f, 20.0f, 120.0f);
if (IsKeyPressed(KEY_A)) text.duration = (int) Clamp((float) text.duration - 5.0f, 10.0f, 120.0f);
else if (IsKeyPressed(KEY_D)) text.duration = (int) Clamp((float) text.duration + 5.0f, 10.0f, 120.0f);
if (IsKeyPressed(KEY_Z)) text.offset = Clamp(text.offset - 1.0f, 0.0f, 15.0f);
else if (IsKeyPressed(KEY_X)) text.offset = Clamp(text.offset + 1.0f, 0.0f, 15.0f);
if (IsKeyPressed(KEY_Q)) currentAnimation = currentAnimation? currentAnimation - 1 : animationsSize - 1;
@ -107,18 +108,21 @@ int main(void)
for (unsigned int i = 0; i < TextLength(text.str); i++)
{
float time = (int) (frameCount + i*text.offset)%(int)text.duration;
float deltaX = (float) GetRandomValue(-text.delta/10, text.delta/10);
float deltaY = (float) GetRandomValue(-text.delta/10, text.delta/10);
if (time <= 1.0f) // Actives once every `text.duration` frames
{
glyphDelta[i].x = (float) GetRandomValue(-text.delta/10, text.delta/10);
glyphDelta[i].y = (float) GetRandomValue(-text.delta/10, text.delta/10);
}
if (time < (text.duration/2))
{
glyphPosition[i].x = EaseLinearNone(time, glyphPosition[i].x, deltaX, text.duration/2);
glyphPosition[i].y = EaseLinearNone(time, text.position.y, deltaY, text.duration/2);
glyphPosition[i].x = EaseLinearNone(time, glyphPosition[i].x, glyphDelta[i].x, text.duration/2);
glyphPosition[i].y = EaseLinearNone(time, text.position.y, glyphDelta[i].y, text.duration/2);
}
else
{
glyphPosition[i].x = EaseLinearNone(time - text.duration/2, glyphPosition[i].x + deltaX, -deltaX, text.duration/2);
glyphPosition[i].y = EaseLinearNone(time - text.duration/2, text.position.y + deltaY, -deltaY, text.duration/2);
glyphPosition[i].x = EaseLinearNone(time - text.duration/2, glyphPosition[i].x + glyphDelta[i].x, -glyphDelta[i].x, text.duration/2);
glyphPosition[i].y = EaseLinearNone(time - text.duration/2, text.position.y + glyphDelta[i].y, -glyphDelta[i].y, text.duration/2);
}
}
} break;

View File

@ -72,10 +72,6 @@
// Include pseudo-random numbers generator (rprand.h), based on Xoshiro128** and SplitMix64
#define SUPPORT_RPRAND_GENERATOR 1
#endif
#ifndef SUPPORT_MOUSE_GESTURES
// Mouse gestures are directly mapped like touches and processed by the gestures system
#define SUPPORT_MOUSE_GESTURES 1
#endif
#ifndef SUPPORT_SSH_KEYBOARD_RPI
// Reconfigure standard input to receive key inputs, works with SSH connection
#define SUPPORT_SSH_KEYBOARD_RPI 1
@ -113,16 +109,6 @@
// Enabling this flag allows manual control of the frame processes, use at your own risk
#define SUPPORT_CUSTOM_FRAME_CONTROL 0 // Disabled by default
#endif
#ifndef SUPPORT_CLIPBOARD_IMAGE
// Support for clipboard image loading
// NOTE: Only working on SDL3, GLFW (Windows) and RGFW (Windows)
// WARNING: It requires support for some additional flags:
// - SUPPORT_MODULE_RTEXTURES
// - SUPPORT_FILEFORMAT_BMP (Windows clipboard)
// - SUPPORT_FILEFORMAT_PNG (Wayland clipboard)
// - SUPPORT_FILEFORMAT_JPG
#define SUPPORT_CLIPBOARD_IMAGE 1
#endif
// rcore: Configuration values
// NOTE: Below values are already defined inside [rcore.c] so there is no need to be

2
src/external/rlsw.h vendored
View File

@ -685,6 +685,7 @@ SWAPI void swSwapColorBuffers(void); // Swap software renderer color/back buffer
SWAPI void swEnable(SWstate state);
SWAPI void swDisable(SWstate state);
SWAPI void swGetIntegerv(SWget name, int *v);
SWAPI void swGetFloatv(SWget name, float *v);
SWAPI const char *swGetString(SWget name);
SWAPI SWerrcode swGetError(void);
@ -746,6 +747,7 @@ SWAPI void swDrawElements(SWdraw mode, int count, int type, const void *indices)
SWAPI void swGenTextures(int count, uint32_t *textures);
SWAPI void swDeleteTextures(int count, uint32_t *textures);
SWAPI void swBindTexture(uint32_t id);
SWAPI void swTexStorage2D(int width, int height, SWinternalformat format);
SWAPI void swTexImage2D(int width, int height, SWformat format, SWtype type, const void *data);
SWAPI void swTexSubImage2D(GLint x, GLint y, GLsizei width, GLsizei height, GLenum format, GLenum type, const void *pixels);
SWAPI void swTexParameteri(int param, int value);

View File

@ -19,7 +19,6 @@
*
* DEPENDENCIES:
* - Android NDK: Provides C API to access Android functionality
* - gestures: Gestures system for touch-ready devices (or simulated from mouse inputs)
*
*
* LICENSE: zlib/libpng
@ -706,12 +705,22 @@ const char *GetClipboardText(void)
return buffer;
}
// Set clipboard image content
bool SetClipboardImage(Image image)
{
bool result = false;
TRACELOG(LOG_WARNING, "SetClipboardImage() not implemented on target platform");
return result;
}
// Get clipboard image
Image GetClipboardImage(void)
{
Image image = { 0 };
TRACELOG(LOG_WARNING, "GetClipboardImage() not implemented on target platform");
TRACELOG(LOG_WARNING, "Clipboard image retrieving not implemented");
return image;
}
@ -851,12 +860,6 @@ const char *GetKeyName(int key)
// Register all input events
void PollInputEvents(void)
{
#if SUPPORT_GESTURES_SYSTEM
// NOTE: Gestures update must be called every frame to reset gestures correctly
// because ProcessGestureEvent() is called on an event, not every frame
UpdateGestures();
#endif
// Reset keys/chars pressed registered
CORE.Input.Keyboard.keyPressedQueueCount = 0;
CORE.Input.Keyboard.charPressedQueueCount = 0;
@ -881,7 +884,7 @@ void PollInputEvents(void)
for (int i = 0; i < MAX_TOUCH_POINTS; i++) CORE.Input.Touch.previousTouchState[i] = CORE.Input.Touch.currentTouchState[i];
// Reset touch positions
//for (int i = 0; i < MAX_TOUCH_POINTS; i++) CORE.Input.Touch.position[i] = (Vector2){ 0, 0 };
//for (int i = 0; i < MAX_TOUCH_POINTS; i++) CORE.Input.Touch.currentPosition[i] = (Vector2){ 0, 0 };
// Register previous keys states
// NOTE: Android supports up to 260 keys
@ -1462,7 +1465,7 @@ static int32_t AndroidInputCallback(struct android_app *app, AInputEvent *event)
// Register touch points position
touchRaw.position[i] = (Vector2){ AMotionEvent_getX(event, i), AMotionEvent_getY(event, i) };
// Normalize CORE.Input.Touch.position[i] for CORE.Window.screen.width and CORE.Window.screen.height
// Normalize CORE.Input.Touch.currentPosition[i] for CORE.Window.screen.width and CORE.Window.screen.height
float widthRatio = (float)(CORE.Window.screen.width + CORE.Window.renderOffset.x)/(float)CORE.Window.display.width;
float heightRatio = (float)(CORE.Window.screen.height + CORE.Window.renderOffset.y)/(float)CORE.Window.display.height;
touchRaw.position[i].x = touchRaw.position[i].x*widthRatio - (float)CORE.Window.renderOffset.x/2;
@ -1565,7 +1568,7 @@ static int32_t AndroidInputCallback(struct android_app *app, AInputEvent *event)
if (hover) continue;
CORE.Input.Touch.pointId[CORE.Input.Touch.pointCount] = touchRaw.pointId[i];
CORE.Input.Touch.position[CORE.Input.Touch.pointCount] = touchRaw.position[i];
CORE.Input.Touch.currentPosition[CORE.Input.Touch.pointCount] = touchRaw.position[i];
CORE.Input.Touch.pointCount++;
}
@ -1577,10 +1580,10 @@ static int32_t AndroidInputCallback(struct android_app *app, AInputEvent *event)
// Stores the previous position of touch[0] only while it's active to calculate the delta
if (flags == AMOTION_EVENT_ACTION_MOVE) CORE.Input.Mouse.previousPosition = CORE.Input.Mouse.currentPosition;
else CORE.Input.Mouse.previousPosition = CORE.Input.Touch.position[0];
else CORE.Input.Mouse.previousPosition = CORE.Input.Touch.currentPosition[0];
// Map touch[0] as mouse input for convenience
CORE.Input.Mouse.currentPosition = CORE.Input.Touch.position[0];
CORE.Input.Mouse.currentPosition = CORE.Input.Touch.currentPosition[0];
CORE.Input.Mouse.currentWheelMove = (Vector2){ 0.0f, 0.0f };
return 0;

View File

@ -22,7 +22,6 @@
*
* DEPENDENCIES:
* - rglfw: Manage graphic device, OpenGL context and inputs (Windows, Linux, OSX/macOS, FreeBSD...)
* - gestures: Gestures system for touch-ready devices (or simulated from mouse inputs)
*
*
* LICENSE: zlib/libpng
@ -59,6 +58,7 @@
typedef struct HWND__ *HWND;
#endif
#define WIN32_CLIPBOARD_IMPLEMENTATION
#include "../external/win32_clipboard.h" // Clipboard image copy-paste
#define GLFW_EXPOSE_NATIVE_WIN32
@ -796,8 +796,7 @@ void *GetWindowHandle(void)
#if defined(_WIN32)
handle = glfwGetWin32Window(platform.handle); // Type: HWND
#endif
#if defined(__linux__)
#elif defined(__linux__)
#if defined(_GLFW_WAYLAND)
#if defined(_GLFW_X11)
int platformID = glfwGetPlatform();
@ -818,8 +817,7 @@ void *GetWindowHandle(void)
platform.windowHandleX11 = glfwGetX11Window(platform.handle);
handle = &platform.windowHandleX11;
#endif
#endif
#if defined(__APPLE__)
#elif defined(__APPLE__)
handle = (void *)glfwGetCocoaWindow(platform.handle); // Type: NSWindow*
#endif
@ -1081,20 +1079,40 @@ void SetClipboardText(const char *text)
}
// Get clipboard text content
// NOTE: returned string is allocated and freed by GLFW
// NOTE: Returned string is allocated and freed by GLFW
const char *GetClipboardText(void)
{
return glfwGetClipboardString(platform.handle);
}
// Set clipboard image content
bool SetClipboardImage(Image image)
{
bool result = false;
#if defined(_WIN32)
#elif defined(__linux__)
#elif defined(__APPLE__)
#endif
return result;
}
// Get clipboard image
Image GetClipboardImage(void)
{
Image image = { 0 };
#if SUPPORT_CLIPBOARD_IMAGE && SUPPORT_MODULE_RTEXTURES
#if defined(_WIN32)
#if !SUPPORT_MODULE_RTEXTURES
TRACELOG(LOG_WARNING, "Clipboard image requires SUPPORT_MODULE_RTEXTURES to work");
return image;
#endif
#if defined(_WIN32)
unsigned int dataSize = 0;
void *bmpData = NULL;
int width = 0;
@ -1106,13 +1124,10 @@ Image GetClipboardImage(void)
else
{
image = LoadImageFromMemory(".bmp", (const unsigned char *)bmpData, (int)dataSize);
RL_FREE(bmpData);
}
#elif defined(__linux__) && defined(_GLFW_X11)
// REF: https://github.com/ColleagueRiley/Clipboard-Copy-Paste/blob/main/x11.c
// REF: https://github.com/ColleagueRiley/Clipboard-Copy-Paste/blob/main/x11.
static Atom clipboard = 0;
static Atom targetType = 0;
static Atom property = 0;
@ -1150,13 +1165,9 @@ Image GetClipboardImage(void)
image = LoadImageFromMemory(".png", data, (int)nitems);
XFree(data);
}
#else
TRACELOG(LOG_WARNING, "GetClipboardImage() not implemented on target platform");
#endif // _WIN32
#else
TRACELOG(LOG_WARNING, "Clipboard image: SUPPORT_CLIPBOARD_IMAGE requires SUPPORT_MODULE_RTEXTURES to work properly");
#endif // SUPPORT_CLIPBOARD_IMAGE
TRACELOG(LOG_WARNING, "Clipboard image not implemented on target platform");
#endif
return image;
}
@ -1245,11 +1256,9 @@ void OpenURL(const char *url)
char *cmd = (char *)RL_CALLOC(strlen(url) + 16, sizeof(char));
#if defined(_WIN32)
sprintf(cmd, "explorer \"%s\"", url);
#endif
#if defined(__linux__) || defined(__FreeBSD__) || defined(__OpenBSD__)
#elif defined(__linux__) || defined(__FreeBSD__) || defined(__OpenBSD__)
sprintf(cmd, "xdg-open '%s'", url); // Alternatives: firefox, x-www-browser
#endif
#if defined(__APPLE__)
#elif defined(__APPLE__)
sprintf(cmd, "open '%s'", url);
#endif
int result = system(cmd);
@ -1307,21 +1316,14 @@ const char *GetKeyName(int key)
// Register all input events
void PollInputEvents(void)
{
#if SUPPORT_GESTURES_SYSTEM
// NOTE: Gestures update must be called every frame to reset gestures correctly
// because ProcessGestureEvent() is called on an event, not every frame
UpdateGestures();
#endif
// Reset keys/chars pressed registered
CORE.Input.Keyboard.keyPressedQueueCount = 0;
CORE.Input.Keyboard.charPressedQueueCount = 0;
// Reset last gamepad button/axis registered state
CORE.Input.Gamepad.lastButtonPressed = GAMEPAD_BUTTON_UNKNOWN;
//CORE.Input.Gamepad.axisCount = 0;
// Keyboard/Mouse input polling (automatically managed by GLFW3 through callback)
// NOTE: Keyboard/Mouse input polling (automatically managed by GLFW3 through callback)
// Register previous keys states
for (int i = 0; i < MAX_KEYBOARD_KEYS; i++)
@ -1343,15 +1345,20 @@ void PollInputEvents(void)
// Register previous touch states
for (int i = 0; i < MAX_TOUCH_POINTS; i++) CORE.Input.Touch.previousTouchState[i] = CORE.Input.Touch.currentTouchState[i];
// Reset touch positions
//for (int i = 0; i < MAX_TOUCH_POINTS; i++) CORE.Input.Touch.position[i] = (Vector2){ 0, 0 };
// Register previous touch positions and reset
for (int i = 0; i < MAX_TOUCH_POINTS; i++)
{
CORE.Input.Touch.previousPosition[i] = CORE.Input.Touch.currentPosition[i];
CORE.Input.Touch.currentPosition[i] = (Vector2){ 0, 0 };
}
// Map touch position to mouse position for convenience
// WARNING: If the target desktop device supports touch screen, this behaviour should be reviewed!
// TODO: GLFW does not support multi-touch input yet
// REF: https://www.codeproject.com/Articles/668404/Programming-for-Multi-Touch
// REF: https://docs.microsoft.com/en-us/windows/win32/wintouch/getting-started-with-multi-touch-messages
CORE.Input.Touch.position[0] = CORE.Input.Mouse.currentPosition;
CORE.Input.Touch.currentPosition[0] = GetMousePosition();
CORE.Input.Touch.previousPosition[0] = CORE.Input.Mouse.currentPosition;
// Check if gamepads are ready
// NOTE: Doing it here in case of disconnection
@ -1455,7 +1462,7 @@ void PollInputEvents(void)
glfwWaitEvents(); // Wait for in input events before continue (drawing is paused)
CORE.Time.previous = GetTime();
}
else glfwPollEvents(); // Poll input events: keyboard/mouse/window events (callbacks) -> Update keys state
else glfwPollEvents(); // Poll input events: keyboard/mouse/window events (callbacks)
CORE.Window.shouldClose = glfwWindowShouldClose(platform.handle);
@ -2170,40 +2177,27 @@ static void CharCallback(GLFWwindow *window, unsigned int codepoint)
}
}
// GLFW3: Mouse button callback, runs on mouse button pressed
// GLFW3: Mouse button callback, runs on mouse button pressed and released
static void MouseButtonCallback(GLFWwindow *window, int button, int action, int mods)
{
// WARNING: GLFW could only return GLFW_PRESS (1) or GLFW_RELEASE (0) for now,
// but future releases may add more actions (i.e. GLFW_REPEAT)
CORE.Input.Mouse.currentButtonState[button] = action;
CORE.Input.Touch.currentTouchState[button] = action;
#if SUPPORT_GESTURES_SYSTEM && SUPPORT_MOUSE_GESTURES
// Process mouse events as touches to be able to use mouse-gestures
GestureEvent gestureEvent = { 0 };
// Register touch actions
if ((CORE.Input.Mouse.currentButtonState[button] == 1) && (CORE.Input.Mouse.previousButtonState[button] == 0)) gestureEvent.touchAction = TOUCH_ACTION_DOWN;
else if ((CORE.Input.Mouse.currentButtonState[button] == 0) && (CORE.Input.Mouse.previousButtonState[button] == 1)) gestureEvent.touchAction = TOUCH_ACTION_UP;
// NOTE: TOUCH_ACTION_MOVE event is registered in MouseCursorPosCallback()
// Assign a pointer ID
gestureEvent.pointId[0] = 0;
// Register touch points count
gestureEvent.pointCount = 1;
// Register touch points position, only one point registered
gestureEvent.position[0] = GetMousePosition();
// Normalize gestureEvent.position[0] for CORE.Window.screen.width and CORE.Window.screen.height
gestureEvent.position[0].x /= (float)GetScreenWidth();
gestureEvent.position[0].y /= (float)GetScreenHeight();
// Gesture data is sent to gestures-system for processing
ProcessGestureEvent(gestureEvent);
#endif
// Processing mouse events as touches, using button id as touch id
if (action == GLFW_PRESS)
{
CORE.Input.Touch.pointCount = 1;
CORE.Input.Touch.pointId[button] = button;
CORE.Input.Touch.currentTouchState[button] = 1; // ACTION: DOWN
CORE.Input.Touch.currentPosition[button] = GetMousePosition();
}
else if (action == GLFW_RELEASE)
{
// Point count and id should be reseted at some point
CORE.Input.Touch.currentTouchState[button] = 0; // ACTION: UP
CORE.Input.Touch.currentPosition[button] = GetMousePosition();
}
}
// GLFW3: Cursor position callback, runs on mouse movement
@ -2211,30 +2205,11 @@ static void MouseCursorPosCallback(GLFWwindow *window, double x, double y)
{
CORE.Input.Mouse.currentPosition.x = (float)x;
CORE.Input.Mouse.currentPosition.y = (float)y;
CORE.Input.Touch.position[0] = CORE.Input.Mouse.currentPosition;
#if SUPPORT_GESTURES_SYSTEM && SUPPORT_MOUSE_GESTURES
// Process mouse events as touches to be able to use mouse-gestures
GestureEvent gestureEvent = { 0 };
gestureEvent.touchAction = TOUCH_ACTION_MOVE;
// Assign a pointer ID
gestureEvent.pointId[0] = 0;
// Register touch points count
gestureEvent.pointCount = 1;
// Register touch points position, only one point registered
gestureEvent.position[0] = CORE.Input.Touch.position[0];
// Normalize gestureEvent.position[0] for CORE.Window.screen.width and CORE.Window.screen.height
gestureEvent.position[0].x /= (float)GetScreenWidth();
gestureEvent.position[0].y /= (float)GetScreenHeight();
// Gesture data is sent to gestures-system for processing
ProcessGestureEvent(gestureEvent);
#endif
// Register current touch position and movement action
CORE.Input.Touch.currentPosition[0] = CORE.Input.Mouse.currentPosition;
if (Vector2Distance(CORE.Input.Touch.currentPosition[0], CORE.Input.Touch.previousPosition[0]) > 3.0f)
CORE.Input.Touch.currentTouchState[0] = 2; // ACTION: MOVE
}
// GLFW3: Mouse wheel scroll callback, runs on mouse wheel changes
@ -2244,18 +2219,12 @@ static void MouseScrollCallback(GLFWwindow *window, double xoffset, double yoffs
CORE.Input.Mouse.currentWheelMove.y += (float)yoffset;
}
// GLFW3: Cursor ennter callback, when cursor enters the window
// GLFW3: Cursor enter callback, when cursor enters the window
// NOTE: Mouse position updated by MouseCursorPosCallback()
static void CursorEnterCallback(GLFWwindow *window, int entered)
{
if (entered)
{
// NOTE: Mouse position updated by MouseCursorPosCallback()
CORE.Input.Mouse.cursorOnScreen = true;
}
else
{
CORE.Input.Mouse.cursorOnScreen = false;
}
if (entered) CORE.Input.Mouse.cursorOnScreen = true;
else CORE.Input.Mouse.cursorOnScreen = false;
}
// GLFW3: Joystick connected/disconnected callback
@ -2277,8 +2246,4 @@ static void JoystickCallback(int jid, int event)
}
}
#ifdef _WIN32
# define WIN32_CLIPBOARD_IMPLEMENTATION
# include "../external/win32_clipboard.h"
#endif
// EOF

View File

@ -21,7 +21,6 @@
*
* DEPENDENCIES:
* - RGFW.h (main library): Windowing and inputs management
* - gestures: Gestures system for touch-ready devices (or simulated from mouse inputs)
*
*
* LICENSE: zlib/libpng
@ -168,6 +167,17 @@ extern "C" {
#undef Size
#endif
#if defined(_WIN32)
#define WIN32_CLIPBOARD_IMPLEMENTATION
#define WINUSER_ALREADY_INCLUDED
#define WINBASE_ALREADY_INCLUDED
#define WINGDI_ALREADY_INCLUDED
#include "../external/win32_clipboard.h"
#elif defined(__linux__) && defined(DRGFW_X11)
#include <X11/Xlib.h>
#include <X11/Xatom.h>
#endif
#include <stdbool.h>
//----------------------------------------------------------------------------------
@ -685,7 +695,7 @@ static void RGFW_cb_mouserawmotionfunc(const RGFW_event *e)
CORE.Input.Mouse.currentPosition.y += mouseY;
// simulate touch with the mouse
CORE.Input.Touch.position[0] = CORE.Input.Mouse.currentPosition;
CORE.Input.Touch.currentPosition[0] = CORE.Input.Mouse.currentPosition;
RemapMouseToTouch(2);
}
static void RGFW_cb_mousemotionfunc(const RGFW_event *e)
@ -713,7 +723,7 @@ static void RGFW_cb_mousemotionfunc(const RGFW_event *e)
CORE.Input.Mouse.currentPosition.y = mouseY;
// simulate touch with the mouse
CORE.Input.Touch.position[0] = CORE.Input.Mouse.currentPosition;
CORE.Input.Touch.currentPosition[0] = CORE.Input.Mouse.currentPosition;
RemapMouseToTouch(2);
}
static void RGFW_cb_keyfunc(const RGFW_keyEvent* e)
@ -1307,27 +1317,17 @@ const char *GetClipboardText(void)
return RGFW_readClipboard(NULL);
}
#if SUPPORT_CLIPBOARD_IMAGE
#if defined(_WIN32)
#define WIN32_CLIPBOARD_IMPLEMENTATION
#define WINUSER_ALREADY_INCLUDED
#define WINBASE_ALREADY_INCLUDED
#define WINGDI_ALREADY_INCLUDED
#include "../external/win32_clipboard.h"
#elif defined(__linux__) && defined(DRGFW_X11)
#include <X11/Xlib.h>
#include <X11/Xatom.h>
#endif
#endif
// Get clipboard image
Image GetClipboardImage(void)
{
Image image = { 0 };
#if SUPPORT_CLIPBOARD_IMAGE && SUPPORT_MODULE_RTEXTURES
#if defined(_WIN32)
#if !SUPPORT_MODULE_RTEXTURES
TRACELOG(LOG_WARNING, "Clipboard image requires SUPPORT_MODULE_RTEXTURES to work");
return image;
#endif
#if defined(_WIN32)
unsigned int dataSize = 0;
void *fileData = NULL;
@ -1339,12 +1339,9 @@ Image GetClipboardImage(void)
else
{
image = LoadImageFromMemory(".bmp", (const unsigned char *)fileData, (int)dataSize);
RL_FREE(fileData);
}
#elif defined(__linux__) && defined(DRGFW_X11)
// REF: https://github.com/ColleagueRiley/Clipboard-Copy-Paste/blob/main/x11.c
Display *dpy = XOpenDisplay(NULL);
if (!dpy) return image;
@ -1390,11 +1387,8 @@ Image GetClipboardImage(void)
XDestroyWindow(dpy, win);
XCloseDisplay(dpy);
#else
TRACELOG(LOG_WARNING, "Clipboard image: PLATFORM_DESKTOP_RGFW doesn't implement GetClipboardImage() for this OS");
#endif // _WIN32
#else
TRACELOG(LOG_WARNING, "Clipboard image: SUPPORT_CLIPBOARD_IMAGE requires SUPPORT_MODULE_RTEXTURES to work properly");
#endif // SUPPORT_CLIPBOARD_IMAGE
TRACELOG(LOG_WARNING, "Clipboard image not implemented on target platform");
#endif
return image;
}
@ -1557,12 +1551,6 @@ const char *GetKeyName(int key)
// Register all input events
void PollInputEvents(void)
{
#if SUPPORT_GESTURES_SYSTEM
// NOTE: Gestures update must be called every frame to reset gestures correctly
// because ProcessGestureEvent() is called on an event, not every frame
UpdateGestures();
#endif
// Reset keys/chars pressed registered
CORE.Input.Keyboard.keyPressedQueueCount = 0;
CORE.Input.Keyboard.charPressedQueueCount = 0;
@ -1591,7 +1579,7 @@ void PollInputEvents(void)
for (int i = 0; i < MAX_TOUCH_POINTS; i++) CORE.Input.Touch.previousTouchState[i] = CORE.Input.Touch.currentTouchState[i];
// Map touch position to mouse position for convenience
CORE.Input.Touch.position[0] = CORE.Input.Mouse.currentPosition;
CORE.Input.Touch.currentPosition[0] = CORE.Input.Mouse.currentPosition;
// Register previous keys states
// NOTE: Android supports up to 260 keys
@ -2042,35 +2030,29 @@ static KeyboardKey ConvertScancodeToKey(u32 keycode)
return (KeyboardKey)RGFW_keyConvertTable[keycode];
}
// assign mouse to touches
// 0-TOUCH_ACTION_UP, 1-TOUCH_ACTION_DOWN, 2-TOUCH_ACTION_MOVE
// Assign mouse input events to touches
// NOTE: 0-TOUCH_ACTION_UP, 1-TOUCH_ACTION_DOWN, 2-TOUCH_ACTION_MOVE
void RemapMouseToTouch(int touchAction)
{
#if SUPPORT_GESTURES_SYSTEM
#if SUPPORT_GESTURES_SYSTEM
if (touchAction < 0) return;
GestureEvent gestureEvent = { 0 };
// Register touch actions
gestureEvent.touchAction = touchAction;
// Assign a pointer ID
gestureEvent.pointId[0] = 0;
// Register touch points count
gestureEvent.pointCount = 1;
// Register touch points position, only one point registered
if (touchAction == 2 /*|| realTouch*/) gestureEvent.position[0] = CORE.Input.Touch.position[0];
if ((touchAction == 2) /*|| realTouch*/) gestureEvent.position[0] = CORE.Input.Touch.currentPosition[0];
else gestureEvent.position[0] = GetMousePosition();
// Normalize gestureEvent.position[0] for CORE.Window.screen.width and CORE.Window.screen.height
// Normalize gesture event position to [0.0f..1.0f]
gestureEvent.position[0].x /= (float)GetScreenWidth();
gestureEvent.position[0].y /= (float)GetScreenHeight();
// Gesture data is sent to gestures-system for processing
ProcessGestureEvent(gestureEvent);
#endif
#endif
}
// Helper functions for Time

View File

@ -21,7 +21,6 @@
*
* DEPENDENCIES:
* - SDL 2 or SDL 3 (main library): Windowing and inputs management
* - gestures: Gestures system for touch-ready devices (or simulated from mouse inputs)
*
*
* LICENSE: zlib/libpng
@ -1200,27 +1199,37 @@ const char *GetClipboardText(void)
return buffer;
}
// Set clipboard image content
bool SetClipboardImage(Image image)
{
bool result = false;
// TODO: bool SDL_SetClipboardData(SDL_ClipboardDataCallback callback, SDL_ClipboardCleanupCallback cleanup, void *userdata, const char *const *mime_types, size_t num_mime_types);
return result;
}
// Get clipboard image
Image GetClipboardImage(void)
{
Image image = { 0 };
#if SUPPORT_CLIPBOARD_IMAGE
#if !SUPPORT_MODULE_RTEXTURES
TRACELOG(LOG_WARNING, "Enabling SUPPORT_CLIPBOARD_IMAGE requires SUPPORT_MODULE_RTEXTURES to work properly");
TRACELOG(LOG_WARNING, "Clipboard image requires SUPPORT_MODULE_RTEXTURES to work");
return image;
#endif
// It's nice to have support Bitmap on Linux as well, but not as necessary as Windows
#if !SUPPORT_FILEFORMAT_BMP && defined(_WIN32)
TRACELOG(LOG_WARNING, "WARNING: Enabling SUPPORT_CLIPBOARD_IMAGE requires SUPPORT_FILEFORMAT_BMP, specially on Windows");
TRACELOG(LOG_WARNING, "Clipboard image requires SUPPORT_FILEFORMAT_BMP on Windows");
return image;
#endif
// From what I've tested applications on Wayland saves images on clipboard as PNG
#if (!SUPPORT_FILEFORMAT_PNG || !SUPPORT_FILEFORMAT_JPG) && !defined(_WIN32)
TRACELOG(LOG_WARNING, "WARNING: Getting image from the clipboard might not work without SUPPORT_FILEFORMAT_PNG or SUPPORT_FILEFORMAT_JPG");
TRACELOG(LOG_WARNING, "Clipboard image might require SUPPORT_FILEFORMAT_PNG or SUPPORT_FILEFORMAT_JPG");
#endif
// Let's hope compiler put these arrays in static memory
const char *imageFormats[] = {
"image/bmp",
@ -1228,6 +1237,7 @@ Image GetClipboardImage(void)
"image/jpg",
"image/tiff",
};
const char *imageExtensions[] = {
".bmp",
".png",
@ -1245,19 +1255,17 @@ Image GetClipboardImage(void)
if (fileData)
{
image = LoadImageFromMemory(imageExtensions[i], fileData, (int)dataSize);
SDL_free(fileData);
if (IsImageValid(image))
{
TRACELOG(LOG_INFO, "Clipboard: Got image from clipboard successfully: %s", imageExtensions[i]);
TRACELOG(LOG_INFO, "Clipboard image retrieved successfully (%s image data)", imageExtensions[i]);
return image;
}
}
}
if (!IsImageValid(image)) TRACELOG(LOG_WARNING, "Clipboard: Couldn't get clipboard data. ERROR: %s", SDL_GetError());
#endif // SUPPORT_CLIPBOARD_IMAGE
if (!IsImageValid(image)) TRACELOG(LOG_WARNING, "Clipboard image data can not be retrieved, ERROR: %s", SDL_GetError());
return image;
}
@ -1416,12 +1424,6 @@ const char *GetKeyName(int key)
// Register all input events
void PollInputEvents(void)
{
#if SUPPORT_GESTURES_SYSTEM
// NOTE: Gestures update must be called every frame to reset gestures correctly
// because ProcessGestureEvent() is called on an event, not every frame
UpdateGestures();
#endif
// Reset keys/chars pressed registered
CORE.Input.Keyboard.keyPressedQueueCount = 0;
CORE.Input.Keyboard.charPressedQueueCount = 0;
@ -1456,7 +1458,7 @@ void PollInputEvents(void)
for (int i = 0; i < MAX_TOUCH_POINTS; i++) CORE.Input.Touch.previousTouchState[i] = CORE.Input.Touch.currentTouchState[i];
// Map touch position to mouse position for convenience
if (CORE.Input.Touch.pointCount == 0) CORE.Input.Touch.position[0] = CORE.Input.Mouse.currentPosition;
if (CORE.Input.Touch.pointCount == 0) CORE.Input.Touch.currentPosition[0] = CORE.Input.Mouse.currentPosition;
int touchAction = -1; // 0-TOUCH_ACTION_UP, 1-TOUCH_ACTION_DOWN, 2-TOUCH_ACTION_MOVE
bool realTouch = false; // Flag to differentiate real touch gestures from mouse ones
@ -1741,7 +1743,7 @@ void PollInputEvents(void)
CORE.Input.Mouse.currentPosition.y = (float)event.motion.y;
}
CORE.Input.Touch.position[0] = CORE.Input.Mouse.currentPosition;
CORE.Input.Touch.currentPosition[0] = CORE.Input.Mouse.currentPosition;
touchAction = 2;
} break;
@ -1956,36 +1958,6 @@ void PollInputEvents(void)
} break;
default: break;
}
#if SUPPORT_GESTURES_SYSTEM
if (touchAction > -1)
{
// Process mouse events as touches to be able to use mouse-gestures
GestureEvent gestureEvent = { 0 };
// Register touch actions
gestureEvent.touchAction = touchAction;
// Assign a pointer ID
gestureEvent.pointId[0] = 0;
// Register touch points count
gestureEvent.pointCount = 1;
// Register touch points position, only one point registered
if (touchAction == 2 || realTouch) gestureEvent.position[0] = CORE.Input.Touch.position[0];
else gestureEvent.position[0] = GetMousePosition();
// Normalize gestureEvent.position[0] for CORE.Window.screen.width and CORE.Window.screen.height
gestureEvent.position[0].x /= (float)GetScreenWidth();
gestureEvent.position[0].y /= (float)GetScreenHeight();
// Gesture data is sent to gestures-system for processing
ProcessGestureEvent(gestureEvent);
touchAction = -1;
}
#endif
}
//-----------------------------------------------------------------------------
}
@ -2182,7 +2154,7 @@ int InitPlatform(void)
// Disable mouse events being interpreted as touch events
// NOTE: This is wanted because there are SDL_FINGER* events available which provide unique data
// Due to the way PollInputEvents() and rgestures.h are currently implemented, setting this won't break SUPPORT_MOUSE_GESTURES
SDL_SetHint(SDL_HINT_TOUCH_MOUSE_EVENTS, "0");
SDL_EventState(SDL_DROPFILE, SDL_ENABLE);
@ -2289,8 +2261,8 @@ static void UpdateTouchPointsSDL(SDL_TouchFingerEvent event)
{
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.currentPosition[i].x = finger->x*CORE.Window.screen.width;
CORE.Input.Touch.currentPosition[i].y = finger->y*CORE.Window.screen.height;
CORE.Input.Touch.currentTouchState[i] = 1;
}
@ -2304,8 +2276,8 @@ static void UpdateTouchPointsSDL(SDL_TouchFingerEvent event)
{
SDL_Finger *finger = SDL_GetTouchFinger(event.touchId, i);
CORE.Input.Touch.pointId[i] = (int)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.currentPosition[i].x = finger->x*CORE.Window.screen.width;
CORE.Input.Touch.currentPosition[i].y = finger->y*CORE.Window.screen.height;
CORE.Input.Touch.currentTouchState[i] = 1;
}
#endif

View File

@ -91,10 +91,28 @@ typedef enum MONITOR_DPI_TYPE {
#include <GL/gl.h>
#endif
#define WIN32_CLIPBOARD_IMPLEMENTATION
#define WINUSER_ALREADY_INCLUDED
#define WINBASE_ALREADY_INCLUDED
#define WINGDI_ALREADY_INCLUDED
#include "../external/win32_clipboard.h"
//----------------------------------------------------------------------------------
// Types and Structures Definition
//----------------------------------------------------------------------------------
typedef struct {
HMONITOR handle; // Win32 monitor handle
char *name; // Human-readable UTF-8 name
int x; // Virtual desktop X position
int y; // Virtual desktop Y position
int width; // Current mode width (pixels)
int height; // Current mode height (pixels)
int physicalWidth; // Physical width (mm)
int physicalHeight; // Physical height (mm)
int refreshRate; // Current mode refresh rate (Hz)
} Win32Monitor;
// NOTE: appScreenSize is the last screen size requested by the app,
// the backend must keep the client area this size (after DPI scaling is applied)
// when the window isn't fullscreen/maximized/minimized
@ -119,6 +137,11 @@ typedef struct {
bool perMonitorDPIAwareV2; // Flag to check DPI-awareness level. This is used mainly to distinguish between per-monitor DPI awareness v1 and v2
Win32Monitor *monitors;
int monitorCount;
int monitorCapacity;
int currentMonitor;
LARGE_INTEGER timerFrequency;
char *clipboardText;
@ -283,14 +306,6 @@ typedef struct {
DWORD clear;
} FlagsOp;
// Monitor info type
typedef struct {
HMONITOR needle;
int index;
int matchIndex;
RECT rect;
} MonitorInfo;
//----------------------------------------------------------------------------------
// Global Const Variables Definition
//----------------------------------------------------------------------------------
@ -460,6 +475,23 @@ static void LoadWin32FunctionPointers(void)
}
}
static int GetMonitorIndexFromHWND(HWND hwnd)
{
HMONITOR handle = MonitorFromWindow(hwnd, MONITOR_DEFAULTTONEAREST);
int result = 0;
for (int i = 0; i < platform.monitorCount; i++)
{
if (platform.monitors[i].handle == handle)
{
result = i;
break;
}
}
return result;
}
// GetDpiForWindow with a fallback for older versions of Windows
static UINT GetDpiForWindowCompat(HWND hwnd)
{
@ -880,37 +912,6 @@ static HICON ConvertImageToWindowsIcon(Image image)
return result;
}
// Count monitors process
// NOTE: Required by GetMonitorCount()
static BOOL CALLBACK CountMonitorsProc(HMONITOR handle, HDC hdc, LPRECT rect, LPARAM lparam)
{
int *count = (int *)lparam;
*count += 1;
// Always return TRUE to continue the loop, otherwise, the caller
// can't distinguish between stopping the loop and an error
return TRUE;
}
// Find monitor process
// NOTE: Required by GetCurrentMonitor()
static BOOL CALLBACK FindMonitorProc(HMONITOR handle, HDC hdc, LPRECT rect, LPARAM lparam)
{
MonitorInfo *monitor = (MonitorInfo *)lparam;
if (handle == monitor->needle)
{
monitor->matchIndex = monitor->index;
monitor->rect = *rect;
}
monitor->index += 1;
// Always return TRUE to continue the loop, otherwise, the caller
// can't distinguish between stopping the loop and an error
return TRUE;
}
// Get style changed required operations flags
// NOTE: Required for deferred operations
static void GetStyleChangeFlagOps(DWORD coreWindowFlags, STYLESTRUCT *style, FlagsOp *deferredFlags)
@ -1157,22 +1158,55 @@ void SetWindowPosition(int x, int y)
{
if (platform.hwnd != NULL)
{
RECT rect = { 0 };
if (GetWindowRect(platform.hwnd, &rect))
{
int width = rect.right - rect.left;
int height = rect.bottom - rect.top;
// Move the window to the new position (keeping size and z-order)
SetWindowPos(platform.hwnd, NULL, x, y, width, height, SWP_NOZORDER | SWP_NOACTIVATE);
}
RECT rect = { x, y, x, y };
AdjustWindowRectExForDpiCompat(&rect, MakeWindowStyle(CORE.Window.flags), FALSE, WINDOW_STYLE_EX, GetDpiForWindowCompat(platform.hwnd));
SetWindowPos(platform.hwnd, NULL, rect.left, rect.top, 0, 0, SWP_NOZORDER | SWP_NOACTIVATE | SWP_NOSIZE);
}
}
// Set monitor for the current window
// Place window on a given monitor
void SetWindowMonitor(int monitor)
{
TRACELOG(LOG_WARNING, "SetWindowMonitor not implemented");
if ((monitor >= 0) && (monitor < platform.monitorCount))
{
MONITORINFO info = { 0 };
info.cbSize = sizeof(info);
HMONITOR monitorHandle = platform.monitors[monitor].handle;
if (GetMonitorInfoW(monitorHandle, &info))
{
RECT windowRect = { 0 };
GetWindowRect(platform.hwnd, &windowRect);
int windowWidth = windowRect.right - windowRect.left;
int windowHeight = windowRect.bottom - windowRect.top;
RECT rcWork = info.rcWork;
int x = rcWork.left + ((rcWork.right - rcWork.left) - windowWidth)/2;
int y = rcWork.top + ((rcWork.bottom - rcWork.top) - windowHeight)/2;
// Keep title bar on-screen if window is larger than the target monitor's work area
if (x < rcWork.left) x = rcWork.left;
if (y < rcWork.top) y = rcWork.top;
SetWindowPos(platform.hwnd, NULL, x, y, 0, 0, SWP_NOZORDER | SWP_NOACTIVATE | SWP_NOSIZE);
GetWindowRect(platform.hwnd, &windowRect);
int newWidth = windowRect.right - windowRect.left;
int newHeight = windowRect.bottom - windowRect.top;
// The window size can change due to the WM_DPICHANGED event. The window has to be re-centered if this happens
if ((newWidth != windowWidth) || (newHeight != windowHeight))
{
x = rcWork.left + ((rcWork.right - rcWork.left) - newWidth)/2;
y = rcWork.top + ((rcWork.bottom - rcWork.top) - newHeight)/2;
if (x < rcWork.left) x = rcWork.left;
if (y < rcWork.top) y = rcWork.top;
SetWindowPos(platform.hwnd, NULL, x, y, 0, 0, SWP_NOZORDER | SWP_NOACTIVATE | SWP_NOSIZE);
}
}
else TRACELOG(LOG_WARNING, "WIN32: Failed to get monitor info [ERROR: %lu]", GetLastError());
}
else TRACELOG(LOG_WARNING, "WIN32: Failed to find monitor with index %d", monitor);
}
// Set window minimum dimensions (FLAG_WINDOW_RESIZABLE)
@ -1236,87 +1270,190 @@ void *GetWindowHandle(void)
return (void *)platform.hwnd;
}
// Update all monitor info in PlatformData. This function is called via EnumDisplayMonitors
static BOOL CALLBACK RefreshMonitorsProc(HMONITOR handle, HDC hdc, LPRECT rect, LPARAM lparam)
{
MONITORINFOEXW info = { 0 };
info.cbSize = sizeof(info);
if (!GetMonitorInfoW(handle, (MONITORINFO *)&info)) return TRUE;
if (platform.monitorCount == platform.monitorCapacity)
{
platform.monitorCapacity += 1;
platform.monitors = (Win32Monitor *)RL_REALLOC(platform.monitors, platform.monitorCapacity*sizeof(Win32Monitor));
}
bool isPrimary = ((info.dwFlags & MONITORINFOF_PRIMARY) != 0);
// The primary monitor should always be at the first index
if (isPrimary && (platform.monitorCount > 0)) memmove(platform.monitors + 1, platform.monitors, sizeof(Win32Monitor)*platform.monitorCount);
Win32Monitor *monitor = &platform.monitors[(isPrimary)? 0 : platform.monitorCount];
*monitor = (Win32Monitor){ 0 };
monitor->handle = handle;
DEVMODEW dm = { 0 };
dm.dmSize = sizeof(dm);
if (EnumDisplaySettingsExW(info.szDevice, ENUM_CURRENT_SETTINGS, &dm, EDS_ROTATEDMODE))
{
monitor->x = (int)dm.dmPosition.x;
monitor->y = (int)dm.dmPosition.y;
monitor->width = (int)dm.dmPelsWidth;
monitor->height = (int)dm.dmPelsHeight;
monitor->refreshRate = (int)dm.dmDisplayFrequency;
}
const WCHAR *monitorNameW = info.szDevice;
DISPLAY_DEVICEW display = { 0 };
for (DWORD displayIndex = 0; ; displayIndex++)
{
display = (DISPLAY_DEVICEW){ 0 };
display.cb = sizeof(display);
if (!EnumDisplayDevicesW(info.szDevice, displayIndex, &display, 0)) break;
if ((display.StateFlags & DISPLAY_DEVICE_ACTIVE) != 0)
{
// Take name from first active display and break out of loop
monitorNameW = display.DeviceString;
break;
}
}
int nameSize = WideCharToMultiByte(CP_UTF8, 0, monitorNameW, -1, NULL, 0, NULL, NULL);
if (nameSize > 0)
{
monitor->name = (char *)RL_CALLOC(nameSize, sizeof(char));
WideCharToMultiByte(CP_UTF8, 0, monitorNameW, -1, monitor->name, nameSize, NULL, NULL);
}
HDC dc = CreateDCW(L"DISPLAY", info.szDevice, NULL, NULL);
if (dc)
{
// Checking these functions as a proxy for Windows version
if ((pSetProcessDpiAwarenessContext != NULL) || (pGetDpiForMonitor != NULL))
{
// Windows 8.1+, HORZSIZE/VERTSIZE report physical size in millimeters
monitor->physicalWidth = GetDeviceCaps(dc, HORZSIZE);
monitor->physicalHeight = GetDeviceCaps(dc, VERTSIZE);
}
else
{
// Older Windows fallback: use system DPI
int dpiX = GetDeviceCaps(dc, LOGPIXELSX);
int dpiY = GetDeviceCaps(dc, LOGPIXELSY);
// Divide native display resolution by DPI to get physical size in inches
// Multiply by 25.4 to convert from inches to millimeters
if (dpiX > 0) monitor->physicalWidth = (int)(dm.dmPelsWidth*25.4f/dpiX);
if (dpiY > 0) monitor->physicalHeight = (int)(dm.dmPelsHeight*25.4f/dpiY);
}
DeleteDC(dc);
}
platform.monitorCount += 1;
// Return TRUE to continue iterating
return TRUE;
}
int GetMonitorCount(void)
{
int count = 0;
int result = EnumDisplayMonitors(NULL, NULL, CountMonitorsProc, (LPARAM)&count);
if (result == 0) TRACELOG(LOG_ERROR, "%s failed, error=%lu", "EnumDisplayMonitors", GetLastError());
return count;
return platform.monitorCount;
}
// Get current monitor where window is placed
int GetCurrentMonitor(void)
{
HMONITOR monitor = MonitorFromWindow(platform.hwnd, MONITOR_DEFAULTTOPRIMARY);
if (!monitor) TRACELOG(LOG_ERROR, "%s failed, error=%lu", "MonitorFromWindow", GetLastError());
MonitorInfo info = { 0 };
info.needle = monitor;
info.index = 0;
info.matchIndex = -1;
int result = EnumDisplayMonitors(NULL, NULL, FindMonitorProc, (LPARAM)&info);
if (result == 0) TRACELOG(LOG_ERROR, "%s failed, error=%lu", "EnumDisplayMonitors", GetLastError());
return info.matchIndex;
return platform.currentMonitor;
}
// Get selected monitor position
Vector2 GetMonitorPosition(int monitor)
{
TRACELOG(LOG_WARNING, "GetMonitorPosition not implemented");
return (Vector2){ 0, 0 };
Vector2 position = { 0 };
if ((monitor >= 0) && (monitor < platform.monitorCount))
{
position.x = (float)platform.monitors[monitor].x;
position.y = (float)platform.monitors[monitor].y;
}
else TRACELOG(LOG_WARNING, "WIN32: Failed to find monitor with index %d", monitor);
return position;
}
// Get selected monitor width (currently used by monitor)
int GetMonitorWidth(int monitor)
{
//TRACELOG(LOG_WARNING, "GetMonitorWidth not implemented");
return 0;
int width = 0;
if ((monitor >= 0) && (monitor < platform.monitorCount)) width = platform.monitors[monitor].width;
else TRACELOG(LOG_WARNING, "WIN32: Failed to find monitor with index %d", monitor);
return width;
}
// Get selected monitor height (currently used by monitor)
int GetMonitorHeight(int monitor)
{
//TRACELOG(LOG_WARNING, "GetMonitorHeight not implemented");
return 0;
int height = 0;
if ((monitor >= 0) && (monitor < platform.monitorCount)) height = platform.monitors[monitor].height;
else TRACELOG(LOG_WARNING, "WIN32: Failed to find monitor with index %d", monitor);
return height;
}
// Get selected monitor physical width in millimetres
int GetMonitorPhysicalWidth(int monitor)
{
TRACELOG(LOG_WARNING, "GetMonitorPhysicalWidth not implemented");
return 0;
int physicalWidth = 0;
if ((monitor >= 0) && (monitor < platform.monitorCount)) physicalWidth = platform.monitors[monitor].physicalWidth;
else TRACELOG(LOG_WARNING, "WIN32: Failed to find monitor with index %d", monitor);
return physicalWidth;
}
// Get selected monitor physical height in millimetres
int GetMonitorPhysicalHeight(int monitor)
{
TRACELOG(LOG_WARNING, "GetMonitorPhysicalHeight not implemented");
return 0;
int physicalHeight = 0;
if ((monitor >= 0) && (monitor < platform.monitorCount)) physicalHeight = platform.monitors[monitor].physicalHeight;
else TRACELOG(LOG_WARNING, "WIN32: Failed to find monitor with index %d", monitor);
return physicalHeight;
}
// Get selected monitor refresh rate
int GetMonitorRefreshRate(int monitor)
{
TRACELOG(LOG_WARNING, "GetMonitorRefreshRate not implemented");
return 0;
int refreshRate = 0;
if ((monitor >= 0) && (monitor < platform.monitorCount)) refreshRate = platform.monitors[monitor].refreshRate;
else TRACELOG(LOG_WARNING, "WIN32: Failed to find monitor with index %d", monitor);
return refreshRate;
}
// Get the human-readable, UTF-8 encoded name of the selected monitor
const char *GetMonitorName(int monitor)
{
TRACELOG(LOG_WARNING, "GetMonitorName not implemented");
return 0;
const char *name = NULL;
if ((monitor >= 0) && (monitor < platform.monitorCount)) name = platform.monitors[monitor].name;
else TRACELOG(LOG_WARNING, "WIN32: Failed to find monitor with index %d", monitor);
return name;
}
// Get window position XY on monitor
Vector2 GetWindowPosition(void)
{
//TRACELOG(LOG_WARNING, "GetWindowPosition not implemented");
return (Vector2){ 0, 0 };
return (Vector2){ (float)CORE.Window.position.x, (float)CORE.Window.position.y };
}
// Get window scale DPI factor for current monitor
@ -1417,20 +1554,71 @@ const char *GetClipboardText(void)
return platform.clipboardText;
}
#if SUPPORT_CLIPBOARD_IMAGE && SUPPORT_MODULE_RTEXTURES
#define WIN32_CLIPBOARD_IMPLEMENTATION
#define WINUSER_ALREADY_INCLUDED
#define WINBASE_ALREADY_INCLUDED
#define WINGDI_ALREADY_INCLUDED
#include "../external/win32_clipboard.h"
#endif
// Set clipboard image content
bool SetClipboardImage(Image image)
{
bool result = false;
BOOL opened = OpenClipboard(NULL);
if (opened)
{
EmptyClipboard();
Image imCopy = { 0 };
bool useCopy = false;
if (image.format != PIXELFORMAT_UNCOMPRESSED_R8G8B8A8)
{
// Make sure data is RGBA 32bit
imCopy = ImageCopy(image);
ImageFormat(&imCopy, PIXELFORMAT_UNCOMPRESSED_R8G8B8A8);
useCopy = true;
}
// Calculate bitmap information size.
BITMAPINFOHEADER header = { 0 };
header.biSize = sizeof(BITMAPINFOHEADER);
header.biWidth = image.width;
header.biHeight = -image.height; // Top-down bitmap
header.biPlanes = 1;
header.biBitCount = 32;
header.biCompression = BI_RGB;
header.biSizeImage = image.width*image.height*4;
SIZE_T size = sizeof(header) + header.biSizeImage;
HGLOBAL memory = GlobalAlloc(GMEM_MOVEABLE, size);
if (memory)
{
BYTE *data = (BYTE *)GlobalLock(memory);
memcpy(data, &header, sizeof(header));
memcpy(data + sizeof(header), useCopy? imCopy.data : image.data, header.biSizeImage);
GlobalUnlock(memory);
HANDLE clipset = SetClipboardData(CF_DIB, memory);
if (clipset == NULL) GlobalFree(memory);
}
if (useCopy) UnloadImage(imCopy);
CloseClipboard();
}
return result;
}
// Get clipboard image
Image GetClipboardImage(void)
{
Image image = { 0 };
#if SUPPORT_CLIPBOARD_IMAGE && SUPPORT_MODULE_RTEXTURES
#if !SUPPORT_MODULE_RTEXTURES
TRACELOG(LOG_WARNING, "Clipboard image requires SUPPORT_MODULE_RTEXTURES to work");
return image;
#endif
unsigned int dataSize = 0;
void *fileData = NULL;
int width = 0;
@ -1441,12 +1629,10 @@ Image GetClipboardImage(void)
if (fileData == NULL) TRACELOG(LOG_WARNING, "Clipboard image: Couldn't get clipboard data.");
else
{
// TODO: Support additional image file-formats
image = LoadImageFromMemory(".bmp", (const unsigned char*)fileData, (int)dataSize);
RL_FREE(fileData);
}
#else
TRACELOG(LOG_WARNING, "Clipboard image: SUPPORT_CLIPBOARD_IMAGE requires SUPPORT_MODULE_RTEXTURES to work properly");
#endif // SUPPORT_CLIPBOARD_IMAGE
return image;
}
@ -1669,7 +1855,7 @@ void PollInputEvents(void)
// Reset touch positions
// TODO: It resets on target platform the mouse position and not filled again until a move-event,
// so, if mouse is not moved it returns a (0, 0) position... this behaviour should be reviewed!
//for (int i = 0; i < MAX_TOUCH_POINTS; i++) CORE.Input.Touch.position[i] = (Vector2){ 0, 0 };
//for (int i = 0; i < MAX_TOUCH_POINTS; i++) CORE.Input.Touch.currentPosition[i] = (Vector2){ 0, 0 };
memcpy(CORE.Input.Keyboard.previousKeyState, CORE.Input.Keyboard.currentKeyState, sizeof(CORE.Input.Keyboard.previousKeyState));
@ -1777,7 +1963,11 @@ HGLRC InitOpenGL(HWND hwnd, HDC hdc)
HGLRC tempContext = wglCreateContext(dummyHDC);
//if (!tempContext) { TRACELOG(LOG_ERROR, "%s failed, error=%lu", "wglCreateContext", GetLastError()); return -1; }
BOOL result = wglMakeCurrent(dummyHDC, tempContext);
//if (!result) { TRACELOG(LOG_ERROR, "%s failed, error=%lu", "wglMakeCurrent", GetLastError()); return -1; }
if (!result)
{
TRACELOG(LOG_ERROR, "GL: Context failed to be set as current, error code: %lu", GetLastError());
return NULL;
}
// Load WGL extension entry points
wglCreateContextAttribsARB = (PFNWGLCREATECONTEXTATTRIBSARBPROC)wglGetProcAddress("wglCreateContextAttribsARB");
@ -1954,24 +2144,6 @@ int InitPlatform(void)
result = (int)RegisterClassExW(&windowClass);
if (result == 0) TRACELOG(LOG_ERROR, "WIN32: Failed to register window class [ERROR: %lu]", GetLastError());
// Get primary monitor info
POINT primaryTopLeft = { 0 };
HMONITOR monitor = MonitorFromPoint(primaryTopLeft, MONITOR_DEFAULTTOPRIMARY);
if (monitor != NULL)
{
MONITORINFO info = { 0 };
info.cbSize = sizeof(info);
result = (int)GetMonitorInfoW(monitor, &info);
if (result == 0) TRACELOG(LOG_WARNING, "WIN32: DISPLAY: Failed to get monitor info [ERROR: %u]", GetLastError());
else
{
CORE.Window.display.width = info.rcMonitor.right - info.rcMonitor.left;
CORE.Window.display.height = info.rcMonitor.bottom - info.rcMonitor.top;
}
}
else TRACELOG(LOG_WARNING, "WIN32: DISPLAY: Failed to get primary monitor from point [ERROR: %u]", GetLastError());
// Create window
// NOTE: Title string needs to be converted to WCHAR
WCHAR *titleWide = NULL;
@ -2024,7 +2196,19 @@ int InitPlatform(void)
int windowWidth = rect.right - rect.left;
int windowHeight = rect.bottom - rect.top;
HMONITOR currentMonitor = MonitorFromWindow(platform.hwnd, MONITOR_DEFAULTTONEAREST);
// Set initial monitor array capacity. This array only grows with RL_REALLOC
platform.monitorCapacity = 1;
platform.monitors = (Win32Monitor *)RL_CALLOC(platform.monitorCapacity, sizeof(Win32Monitor));
platform.monitorCount = 0;
EnumDisplayMonitors(NULL, NULL, RefreshMonitorsProc, 0);
platform.currentMonitor = GetMonitorIndexFromHWND(platform.hwnd);
if (platform.monitorCount > 0)
{
// This is only used for logging on desktop backends
CORE.Window.display.width = platform.monitors[platform.currentMonitor].width;
CORE.Window.display.height = platform.monitors[platform.currentMonitor].height;
HMONITOR currentMonitor = platform.monitors[platform.currentMonitor].handle;
MONITORINFO monitorInfo = { 0 };
monitorInfo.cbSize = sizeof(monitorInfo);
if (GetMonitorInfoW(currentMonitor, &monitorInfo))
@ -2044,6 +2228,7 @@ int InitPlatform(void)
SetWindowPos(platform.hwnd, NULL, x, y, windowWidth, windowHeight, SWP_NOZORDER | SWP_NOACTIVATE);
}
else TRACELOG(LOG_WARNING, "DISPLAY: Unable to retrieve information about monitor");
}
if ((platform.desiredFlags & FLAG_WINDOW_HIDDEN) == 0)
{
@ -2148,6 +2333,18 @@ void ClosePlatform(void)
shcore = NULL;
}
if (platform.monitors != NULL)
{
for (int i = 0; i < platform.monitorCount; i++)
{
if (platform.monitors[i].name != NULL) RL_FREE(platform.monitors[i].name);
}
RL_FREE(platform.monitors);
}
platform = (PlatformData){ 0 };
#if SUPPORT_WINMM_HIGHRES_TIMER && !SUPPORT_BUSY_WAIT_LOOP
timeEndPeriod(1); // Restore time period
#endif
@ -2242,6 +2439,7 @@ static LRESULT CALLBACK WndProc(HWND hwnd, UINT msg, WPARAM wparam, LPARAM lpara
// in response to WM_WINDOWPOSCHANGED but looks like when a window is created,
// this message can be obtained without getting WM_WINDOWPOSCHANGED
HandleWindowResize(hwnd, &platform.appScreenWidth, &platform.appScreenHeight);
platform.currentMonitor = GetMonitorIndexFromHWND(hwnd);
result = 0; // If an application processes WM_SIZE message, it should return zero
} break;
case WM_GETMINMAXINFO:
@ -2344,13 +2542,19 @@ static LRESULT CALLBACK WndProc(HWND hwnd, UINT msg, WPARAM wparam, LPARAM lpara
default: break;
}
} break;
//case WM_MOVE: break;
case WM_MOVE:
{
CORE.Window.position.x = (int)(short)LOWORD(lparam);
CORE.Window.position.y = (int)(short)HIWORD(lparam);
platform.currentMonitor = GetMonitorIndexFromHWND(hwnd);
result = DefWindowProcW(hwnd, msg, wparam, lparam);
} break;
case WM_WINDOWPOSCHANGED:
{
WINDOWPOS *pos = (WINDOWPOS*)lparam;
if (!(pos->flags & SWP_NOSIZE)) HandleWindowResize(hwnd, &platform.appScreenWidth, &platform.appScreenHeight);
DefWindowProc(hwnd, msg, wparam, lparam);
DefWindowProcW(hwnd, msg, wparam, lparam);
} break;
case WM_GETDPISCALEDSIZE:
{
@ -2419,6 +2623,26 @@ static LRESULT CALLBACK WndProc(HWND hwnd, UINT msg, WPARAM wparam, LPARAM lpara
HandleWindowResize(hwnd, &platform.appScreenWidth, &platform.appScreenHeight);
} break;
case WM_DISPLAYCHANGE:
{
for (int i = 0; i < platform.monitorCount; i++)
{
if (platform.monitors[i].name != NULL) RL_FREE(platform.monitors[i].name);
platform.monitors[i].name = NULL;
}
platform.monitorCount = 0;
EnumDisplayMonitors(NULL, NULL, RefreshMonitorsProc, 0);
platform.currentMonitor = GetMonitorIndexFromHWND(platform.hwnd);
POINT position = { 0, 0 };
if (ClientToScreen(hwnd, &position))
{
CORE.Window.position.x = (int)position.x;
CORE.Window.position.y = (int)position.y;
}
result = DefWindowProcW(hwnd, msg, wparam, lparam);
} break;
case WM_SETCURSOR:
{
// Called when mouse moves, enters/leaves window...
@ -2428,7 +2652,7 @@ static LRESULT CALLBACK WndProc(HWND hwnd, UINT msg, WPARAM wparam, LPARAM lpara
return 0;
}
result = DefWindowProc(hwnd, msg, wparam, lparam);
result = DefWindowProcW(hwnd, msg, wparam, lparam);
} break;
case WM_PAINT:
{
@ -2454,7 +2678,7 @@ static LRESULT CALLBACK WndProc(HWND hwnd, UINT msg, WPARAM wparam, LPARAM lpara
{
CORE.Input.Mouse.currentPosition.x = (float)GET_X_LPARAM(lparam);
CORE.Input.Mouse.currentPosition.y = (float)GET_Y_LPARAM(lparam);
CORE.Input.Touch.position[0] = CORE.Input.Mouse.currentPosition;
CORE.Input.Touch.currentPosition[0] = CORE.Input.Mouse.currentPosition;
}
} break;
case WM_SYSKEYDOWN:

View File

@ -21,7 +21,6 @@
*
* DEPENDENCIES:
* - DRM and GLM: System libraries for display initialization and configuration
* - gestures: Gestures system for touch-ready devices (or simulated from mouse inputs)
*
*
* LICENSE: zlib/libpng
@ -555,12 +554,22 @@ const char *GetClipboardText(void)
return NULL;
}
// Set clipboard image content
bool SetClipboardImage(Image image)
{
bool result = false;
TRACELOG(LOG_WARNING, "SetClipboardImage() not implemented on target platform");
return result;
}
// Get clipboard image
Image GetClipboardImage(void)
{
Image image = { 0 };
TRACELOG(LOG_WARNING, "GetClipboardImage() not implemented on target platform");
TRACELOG(LOG_WARNING, "Clipboard image retrieving not implemented");
return image;
}
@ -1078,12 +1087,6 @@ const char *GetKeyName(int key)
// Register all input events
void PollInputEvents(void)
{
#if SUPPORT_GESTURES_SYSTEM
// NOTE: Gestures update must be called every frame to reset gestures correctly
// because ProcessGestureEvent() is called on an event, not every frame
UpdateGestures();
#endif
// Reset keys/chars pressed registered
CORE.Input.Keyboard.keyPressedQueueCount = 0;
CORE.Input.Keyboard.charPressedQueueCount = 0;
@ -1135,7 +1138,7 @@ void PollInputEvents(void)
// Map touch position to mouse position for convenience
// NOTE: For DRM touchscreen devices, this mapping is disabled to avoid false touch detection
// CORE.Input.Touch.position[0] = CORE.Input.Mouse.currentPosition;
// CORE.Input.Touch.currentPosition[0] = CORE.Input.Mouse.currentPosition;
// Handle the mouse/touch/gestures events
PollMouseEvents();
@ -1946,8 +1949,8 @@ static void InitEvdevInput(void)
// Reset variables
for (int i = 0; i < MAX_TOUCH_POINTS; i++)
{
CORE.Input.Touch.position[i].x = -1;
CORE.Input.Touch.position[i].y = -1;
CORE.Input.Touch.currentPosition[i].x = -1;
CORE.Input.Touch.currentPosition[i].y = -1;
platform.touchActive[i] = false;
platform.touchPosition[i].x = -1;
platform.touchPosition[i].y = -1;
@ -2327,7 +2330,7 @@ static void PollMouseEvents(void)
if (fd == -1) return;
struct input_event event = { 0 };
int touchAction = -1; // 0-TOUCH_ACTION_UP, 1-TOUCH_ACTION_DOWN, 2-TOUCH_ACTION_MOVE
int touchAction = -1; // Actions: 0-TOUCH_ACTION_UP, 1-TOUCH_ACTION_DOWN, 2-TOUCH_ACTION_MOVE
static bool isMultitouch = false; // Detect if device supports MT events
// Try to read data from the mouse/touch/gesture and only continue if successful
@ -2346,7 +2349,7 @@ static void PollMouseEvents(void)
else CORE.Input.Mouse.currentPosition.x += event.value;
// NOTE: For DRM touchscreen, do not simulate touch from mouse movement
// CORE.Input.Touch.position[0].x = CORE.Input.Mouse.currentPosition.x;
// CORE.Input.Touch.currentPosition[0].x = CORE.Input.Mouse.currentPosition.x;
touchAction = 2; // TOUCH_ACTION_MOVE
}
@ -2360,7 +2363,7 @@ static void PollMouseEvents(void)
else CORE.Input.Mouse.currentPosition.y += event.value;
// NOTE: For DRM touchscreen, do not simulate touch from mouse movement
// CORE.Input.Touch.position[0].y = CORE.Input.Mouse.currentPosition.y;
// CORE.Input.Touch.currentPosition[0].y = CORE.Input.Mouse.currentPosition.y;
touchAction = 2; // TOUCH_ACTION_MOVE
}
@ -2565,7 +2568,7 @@ static void PollMouseEvents(void)
{
if (platform.touchActive[i])
{
CORE.Input.Touch.position[k] = platform.touchPosition[i];
CORE.Input.Touch.currentPosition[k] = platform.touchPosition[i];
CORE.Input.Touch.pointId[k] = platform.touchId[i];
k++;
}
@ -2576,8 +2579,8 @@ static void PollMouseEvents(void)
// Clear remaining slots
for (int i = k; i < MAX_TOUCH_POINTS; i++)
{
CORE.Input.Touch.position[i].x = -1;
CORE.Input.Touch.position[i].y = -1;
CORE.Input.Touch.currentPosition[i].x = -1;
CORE.Input.Touch.currentPosition[i].y = -1;
CORE.Input.Touch.pointId[i] = -1;
}
@ -2591,7 +2594,7 @@ static void PollMouseEvents(void)
for (int i = 0; i < MAX_TOUCH_POINTS; i++)
{
gestureEvent.pointId[i] = i;
gestureEvent.position[i] = CORE.Input.Touch.position[i];
gestureEvent.position[i] = CORE.Input.Touch.currentPosition[i];
}
ProcessGestureEvent(gestureEvent);

View File

@ -19,7 +19,6 @@
*
* DEPENDENCIES:
* - rlsw: Software renderer
* - gestures: Gestures system for touch-ready devices (or simulated from mouse inputs)
*
*
* LICENSE: zlib/libpng
@ -308,12 +307,22 @@ const char *GetClipboardText(void)
return NULL;
}
// Set clipboard image content
bool SetClipboardImage(Image image)
{
bool result = false;
TRACELOG(LOG_WARNING, "SetClipboardImage() not implemented on target platform");
return result;
}
// Get clipboard image
Image GetClipboardImage(void)
{
Image image = { 0 };
TRACELOG(LOG_WARNING, "GetClipboardImage() not implemented on target platform");
TRACELOG(LOG_WARNING, "Clipboard image retrieving not implemented");
return image;
}
@ -438,12 +447,6 @@ const char *GetKeyName(int key)
// Register all input events
void PollInputEvents(void)
{
#if SUPPORT_GESTURES_SYSTEM
// NOTE: Gestures update must be called every frame to reset gestures correctly
// because ProcessGestureEvent() is called on an event, not every frame
UpdateGestures();
#endif
// Reset keys/chars pressed registered
CORE.Input.Keyboard.keyPressedQueueCount = 0;
CORE.Input.Keyboard.charPressedQueueCount = 0;
@ -461,7 +464,7 @@ void PollInputEvents(void)
// Reset touch positions
// TODO: It resets on target platform the mouse position and not filled again until a move-event,
// so, if mouse is not moved it returns a (0, 0) position... this behaviour should be reviewed!
//for (int i = 0; i < MAX_TOUCH_POINTS; i++) CORE.Input.Touch.position[i] = (Vector2){ 0, 0 };
//for (int i = 0; i < MAX_TOUCH_POINTS; i++) CORE.Input.Touch.currentPosition[i] = (Vector2){ 0, 0 };
// Register previous keys states
// NOTE: Android supports up to 260 keys

View File

@ -22,7 +22,6 @@
*
* DEPENDENCIES:
* - <platform-specific SDK dependency>
* - gestures: Gestures system for touch-ready devices (or simulated from mouse inputs)
*
*
* LICENSE: zlib/libpng
@ -287,12 +286,22 @@ const char *GetClipboardText(void)
return NULL;
}
// Set clipboard image content
bool SetClipboardImage(Image image)
{
bool result = false;
TRACELOG(LOG_WARNING, "SetClipboardImage() not implemented on target platform");
return result;
}
// Get clipboard image
Image GetClipboardImage(void)
{
Image image = { 0 };
TRACELOG(LOG_WARNING, "GetClipboardImage() not implemented on target platform");
TRACELOG(LOG_WARNING, "Clipboard image retrieving not implemented");
return image;
}
@ -413,12 +422,6 @@ const char *GetKeyName(int key)
// Register all input events
void PollInputEvents(void)
{
#if SUPPORT_GESTURES_SYSTEM
// NOTE: Gestures update must be called every frame to reset gestures correctly
// because ProcessGestureEvent() is called on an event, not every frame
UpdateGestures();
#endif
// Reset keys/chars pressed registered
CORE.Input.Keyboard.keyPressedQueueCount = 0;
CORE.Input.Keyboard.charPressedQueueCount = 0;
@ -436,7 +439,7 @@ void PollInputEvents(void)
// Reset touch positions
// TODO: It resets on target platform the mouse position and not filled again until a move-event,
// so, if mouse is not moved it returns a (0, 0) position... this behaviour should be reviewed!
//for (int i = 0; i < MAX_TOUCH_POINTS; i++) CORE.Input.Touch.position[i] = (Vector2){ 0, 0 };
//for (int i = 0; i < MAX_TOUCH_POINTS; i++) CORE.Input.Touch.currentPosition[i] = (Vector2){ 0, 0 };
// Register previous keys states
// NOTE: Android supports up to 260 keys

View File

@ -17,8 +17,8 @@
* Custom flag for rcore on target platform -not used-
*
* DEPENDENCIES:
* - emscripten: Allow interaction between browser API and C
* - gestures: Gestures system for touch-ready devices (or simulated from mouse inputs)
* - Emscripten SDK: Allow interaction between browser API and C
* - libglfw.js: GLFW implementation over Emscripten SDK
*
*
* LICENSE: zlib/libpng
@ -883,17 +883,34 @@ EM_JS(unsigned char *, GetLastPastedImage, (int *width, int *height), {
const char *GetClipboardText(void)
{
RequestClipboardData();
return GetLastPastedText();
}
// Set clipboard image content
bool SetClipboardImage(Image image)
{
bool result = false;
TRACELOG(LOG_WARNING, "SetClipboardImage() not implemented on target platform");
return result;
}
// Get clipboard image
Image GetClipboardImage(void)
{
Image image = { 0 };
int width = 0;
int height = 0;
#if !SUPPORT_MODULE_RTEXTURES
TRACELOG(LOG_WARNING, "Clipboard image requires SUPPORT_MODULE_RTEXTURES to work");
return image;
#endif
RequestClipboardData();
int width = 0;
int height = 0;
unsigned char *data = GetLastPastedImage(&width, &height);
if (data != NULL)
@ -1082,12 +1099,6 @@ const char *GetKeyName(int key)
// Register all input events
void PollInputEvents(void)
{
#if SUPPORT_GESTURES_SYSTEM
// NOTE: Gestures update must be called every frame to reset gestures correctly
// because ProcessGestureEvent() is called on an event, not every frame
UpdateGestures();
#endif
// Reset keys/chars pressed registered
CORE.Input.Keyboard.keyPressedQueueCount = 0;
CORE.Input.Keyboard.charPressedQueueCount = 0;
@ -1121,7 +1132,7 @@ void PollInputEvents(void)
// Reset touch positions
// TODO: It resets on target platform the mouse position and not filled again until a move-event,
// so, if mouse is not moved it returns a (0, 0) position... this behaviour should be reviewed!
//for (int i = 0; i < MAX_TOUCH_POINTS; i++) CORE.Input.Touch.position[i] = (Vector2){ 0, 0 };
//for (int i = 0; i < MAX_TOUCH_POINTS; i++) CORE.Input.Touch.currentPosition[i] = (Vector2){ 0, 0 };
// Gamepad support using emscripten API
// NOTE: GLFW3 joystick functionality not available in web
@ -1664,35 +1675,6 @@ static void MouseButtonCallback(GLFWwindow *window, int button, int action, int
// but future releases may add more actions (i.e. GLFW_REPEAT)
CORE.Input.Mouse.currentButtonState[button] = action;
CORE.Input.Touch.currentTouchState[button] = action;
#if SUPPORT_GESTURES_SYSTEM && SUPPORT_MOUSE_GESTURES
// Process mouse events as touches to be able to use mouse-gestures
GestureEvent gestureEvent = { 0 };
// Register touch actions
if ((CORE.Input.Mouse.currentButtonState[button] == 1) && (CORE.Input.Mouse.previousButtonState[button] == 0)) gestureEvent.touchAction = TOUCH_ACTION_DOWN;
else if ((CORE.Input.Mouse.currentButtonState[button] == 0) && (CORE.Input.Mouse.previousButtonState[button] == 1)) gestureEvent.touchAction = TOUCH_ACTION_UP;
// NOTE: TOUCH_ACTION_MOVE event is registered in MouseMoveCallback()
// Assign a pointer ID
gestureEvent.pointId[0] = 0;
// Register touch points count
gestureEvent.pointCount = 1;
// Register touch points position, only one point registered
gestureEvent.position[0] = GetMousePosition();
// Normalize gestureEvent.position[0] for CORE.Window.screen.width and CORE.Window.screen.height
gestureEvent.position[0].x /= (float)GetScreenWidth();
gestureEvent.position[0].y /= (float)GetScreenHeight();
// Gesture data is sent to gestures-system for processing
// Prevent calling ProcessGestureEvent() when Emscripten is present and there's a touch gesture, so EmscriptenTouchCallback() can handle it itself
if (GetMouseX() != 0 || GetMouseY() != 0) ProcessGestureEvent(gestureEvent);
#endif
}
// GLFW3: Called on mouse move
@ -1703,31 +1685,8 @@ static void MouseMoveCallback(GLFWwindow *window, double x, double y)
{
CORE.Input.Mouse.currentPosition.x = (float)x;
CORE.Input.Mouse.currentPosition.y = (float)y;
CORE.Input.Touch.position[0] = CORE.Input.Mouse.currentPosition;
CORE.Input.Touch.currentPosition[0] = CORE.Input.Mouse.currentPosition;
}
#if SUPPORT_GESTURES_SYSTEM && SUPPORT_MOUSE_GESTURES
// Process mouse events as touches to be able to use mouse-gestures
GestureEvent gestureEvent = { 0 };
gestureEvent.touchAction = TOUCH_ACTION_MOVE;
// Assign a pointer ID
gestureEvent.pointId[0] = 0;
// Register touch points count
gestureEvent.pointCount = 1;
// Register touch points position, only one point registered
gestureEvent.position[0] = CORE.Input.Touch.position[0];
// Normalize gestureEvent.position[0] for CORE.Window.screen.width and CORE.Window.screen.height
gestureEvent.position[0].x /= (float)GetScreenWidth();
gestureEvent.position[0].y /= (float)GetScreenHeight();
// Gesture data is sent to gestures-system for processing
ProcessGestureEvent(gestureEvent);
#endif
}
// GLFW3: Called on mouse wheel scrolling
@ -1832,11 +1791,11 @@ static EM_BOOL EmscriptenTouchCallback(int eventType, const EmscriptenTouchEvent
CORE.Input.Touch.pointId[i] = touchEvent->touches[i].identifier;
// Register touch points position
CORE.Input.Touch.position[i] = (Vector2){touchEvent->touches[i].targetX, touchEvent->touches[i].targetY};
CORE.Input.Touch.currentPosition[i] = (Vector2){touchEvent->touches[i].targetX, touchEvent->touches[i].targetY};
// Normalize gestureEvent.position[x] for CORE.Window.screen.width and CORE.Window.screen.height
CORE.Input.Touch.position[i].x *= ((float)GetScreenWidth()/(float)canvasWidth);
CORE.Input.Touch.position[i].y *= ((float)GetScreenHeight()/(float)canvasHeight);
CORE.Input.Touch.currentPosition[i].x *= ((float)GetScreenWidth()/(float)canvasWidth);
CORE.Input.Touch.currentPosition[i].y *= ((float)GetScreenHeight()/(float)canvasHeight);
if (eventType == EMSCRIPTEN_EVENT_TOUCHSTART) CORE.Input.Touch.currentTouchState[i] = 1;
else if (eventType == EMSCRIPTEN_EVENT_TOUCHEND) CORE.Input.Touch.currentTouchState[i] = 0;
@ -1845,34 +1804,10 @@ static EM_BOOL EmscriptenTouchCallback(int eventType, const EmscriptenTouchEvent
// Update mouse position when single touch detected
if (CORE.Input.Touch.pointCount == 1)
{
CORE.Input.Mouse.currentPosition.x = CORE.Input.Touch.position[0].x;
CORE.Input.Mouse.currentPosition.y = CORE.Input.Touch.position[0].y;
CORE.Input.Mouse.currentPosition.x = CORE.Input.Touch.currentPosition[0].x;
CORE.Input.Mouse.currentPosition.y = CORE.Input.Touch.currentPosition[0].y;
}
#if SUPPORT_GESTURES_SYSTEM
GestureEvent gestureEvent = { 0 };
gestureEvent.pointCount = CORE.Input.Touch.pointCount;
// Register touch actions
if (eventType == EMSCRIPTEN_EVENT_TOUCHSTART) gestureEvent.touchAction = TOUCH_ACTION_DOWN;
else if (eventType == EMSCRIPTEN_EVENT_TOUCHEND) gestureEvent.touchAction = TOUCH_ACTION_UP;
else if (eventType == EMSCRIPTEN_EVENT_TOUCHMOVE) gestureEvent.touchAction = TOUCH_ACTION_MOVE;
else if (eventType == EMSCRIPTEN_EVENT_TOUCHCANCEL) gestureEvent.touchAction = TOUCH_ACTION_CANCEL;
for (int i = 0; (i < gestureEvent.pointCount) && (i < MAX_TOUCH_POINTS); i++)
{
gestureEvent.pointId[i] = CORE.Input.Touch.pointId[i];
gestureEvent.position[i] = CORE.Input.Touch.position[i];
// Normalize gestureEvent.position[i]
gestureEvent.position[i].x /= (float)GetScreenWidth();
gestureEvent.position[i].y /= (float)GetScreenHeight();
}
// Gesture data is sent to gestures system for processing
ProcessGestureEvent(gestureEvent);
#endif
if (eventType == EMSCRIPTEN_EVENT_TOUCHEND)
{
// Identify the EMSCRIPTEN_EVENT_TOUCHEND and remove it from the list
@ -1884,7 +1819,7 @@ static EM_BOOL EmscriptenTouchCallback(int eventType, const EmscriptenTouchEvent
for (int j = i; j < CORE.Input.Touch.pointCount - 1; j++)
{
CORE.Input.Touch.pointId[j] = CORE.Input.Touch.pointId[j + 1];
CORE.Input.Touch.position[j] = CORE.Input.Touch.position[j + 1];
CORE.Input.Touch.currentPosition[j] = CORE.Input.Touch.currentPosition[j + 1];
}
// Decrease touch points count to remove the last one
CORE.Input.Touch.pointCount--;

View File

@ -16,8 +16,7 @@
* Custom flag for rcore on target platform -not used-
*
* DEPENDENCIES:
* - emscripten: Allow interaction between browser API and C
* - gestures: Gestures system for touch-ready devices (or simulated from mouse inputs)
* - Emscripten SDK: Allow interaction between browser API and C
*
*
* LICENSE: zlib/libpng
@ -864,12 +863,15 @@ EM_ASYNC_JS(void, RequestClipboardData, (void), {
EM_JS(char *, GetLastPastedText, (void), {
var str = window._lastClipboardString || "";
var length = lengthBytesUTF8(str) + 1;
if (length > 1)
{
var ptr = _malloc(length);
stringToUTF8(str, ptr, length);
return ptr;
}
return 0;
});
@ -907,14 +909,30 @@ const char *GetClipboardText(void)
return GetLastPastedText();
}
// Set clipboard image content
bool SetClipboardImage(Image image)
{
bool result = false;
TRACELOG(LOG_WARNING, "SetClipboardImage() not implemented on target platform");
return result;
}
// Get clipboard image
Image GetClipboardImage(void)
{
Image image = { 0 };
int width = 0;
int height = 0;
#if !SUPPORT_MODULE_RTEXTURES
TRACELOG(LOG_WARNING, "Clipboard image requires SUPPORT_MODULE_RTEXTURES to work");
return image;
#endif
RequestClipboardData();
int width = 0;
int height = 0;
unsigned char *data = GetLastPastedImage(&width, &height);
if (data != NULL)
@ -1101,12 +1119,6 @@ const char *GetKeyName(int key)
// Register all input events
void PollInputEvents(void)
{
#if SUPPORT_GESTURES_SYSTEM
// NOTE: Gestures update must be called every frame to reset gestures correctly
// because ProcessGestureEvent() is called on an event, not every frame
UpdateGestures();
#endif
// Reset keys/chars pressed registered
CORE.Input.Keyboard.keyPressedQueueCount = 0;
CORE.Input.Keyboard.charPressedQueueCount = 0;
@ -1140,7 +1152,7 @@ void PollInputEvents(void)
// Reset touch positions
// TODO: It resets on target platform the mouse position and not filled again until a move-event,
// so, if mouse is not moved it returns a (0, 0) position... this behaviour should be reviewed!
//for (int i = 0; i < MAX_TOUCH_POINTS; i++) CORE.Input.Touch.position[i] = (Vector2){ 0, 0 };
//for (int i = 0; i < MAX_TOUCH_POINTS; i++) CORE.Input.Touch.currentPosition[i] = (Vector2){ 0, 0 };
// Get number of gamepads connected
int numGamepads = 0;
@ -1617,34 +1629,6 @@ static EM_BOOL EmscriptenMouseCallback(int eventType, const EmscriptenMouseEvent
default: break;
}
#if SUPPORT_GESTURES_SYSTEM && SUPPORT_MOUSE_GESTURES
// Process mouse events as touches to be able to use mouse-gestures
GestureEvent gestureEvent = { 0 };
// Register touch actions
if ((CORE.Input.Mouse.currentButtonState[MOUSE_BUTTON_LEFT] == 1) && (CORE.Input.Mouse.previousButtonState[MOUSE_BUTTON_LEFT] == 0)) gestureEvent.touchAction = TOUCH_ACTION_DOWN;
else if ((CORE.Input.Mouse.currentButtonState[MOUSE_BUTTON_LEFT] == 0) && (CORE.Input.Mouse.previousButtonState[MOUSE_BUTTON_LEFT] == 1)) gestureEvent.touchAction = TOUCH_ACTION_UP;
// NOTE: TOUCH_ACTION_MOVE event is registered in MouseMoveCallback()
// Assign a pointer ID
gestureEvent.pointId[0] = 0;
// Register touch points count
gestureEvent.pointCount = 1;
// Register touch points position, only one point registered
gestureEvent.position[0] = GetMousePosition();
// Normalize gestureEvent.position[0] for CORE.Window.screen.width and CORE.Window.screen.height
gestureEvent.position[0].x /= (float)GetScreenWidth();
gestureEvent.position[0].y /= (float)GetScreenHeight();
// Gesture data is sent to gestures-system for processing
// Prevent calling ProcessGestureEvent() when Emscripten is present and there's a touch gesture, so EmscriptenTouchCallback() can handle it itself
if (GetMouseX() != 0 || GetMouseY() != 0) ProcessGestureEvent(gestureEvent);
#endif
// Don't prevent default to allow focusing on canvas
return 0;
}
@ -1673,32 +1657,9 @@ static EM_BOOL EmscriptenMouseMoveCallback(int eventType, const EmscriptenMouseE
CORE.Input.Mouse.currentPosition.x = normalizedX*(float)CORE.Window.screen.width;
CORE.Input.Mouse.currentPosition.y = normalizedY*(float)CORE.Window.screen.height;
CORE.Input.Touch.position[0] = CORE.Input.Mouse.currentPosition;
CORE.Input.Touch.currentPosition[0] = CORE.Input.Mouse.currentPosition;
}
#if SUPPORT_GESTURES_SYSTEM && SUPPORT_MOUSE_GESTURES
// Process mouse events as touches to be able to use mouse-gestures
GestureEvent gestureEvent = { 0 };
gestureEvent.touchAction = TOUCH_ACTION_MOVE;
// Assign a pointer ID
gestureEvent.pointId[0] = 0;
// Register touch points count
gestureEvent.pointCount = 1;
// Register touch points position, only one point registered
gestureEvent.position[0] = CORE.Input.Touch.position[0];
// Normalize gestureEvent.position[0] for CORE.Window.screen.width and CORE.Window.screen.height
gestureEvent.position[0].x /= (float)GetScreenWidth();
gestureEvent.position[0].y /= (float)GetScreenHeight();
// Gesture data is sent to gestures-system for processing
ProcessGestureEvent(gestureEvent);
#endif
return 1; // The event was consumed by the callback handler
}
@ -1775,11 +1736,11 @@ static EM_BOOL EmscriptenTouchCallback(int eventType, const EmscriptenTouchEvent
CORE.Input.Touch.pointId[i] = touchEvent->touches[i].identifier;
// Register touch points position
CORE.Input.Touch.position[i] = (Vector2){touchEvent->touches[i].targetX, touchEvent->touches[i].targetY};
CORE.Input.Touch.currentPosition[i] = (Vector2){touchEvent->touches[i].targetX, touchEvent->touches[i].targetY};
// Normalize gestureEvent.position[x] for CORE.Window.screen.width and CORE.Window.screen.height
CORE.Input.Touch.position[i].x *= ((float)GetScreenWidth()/(float)canvasWidth);
CORE.Input.Touch.position[i].y *= ((float)GetScreenHeight()/(float)canvasHeight);
CORE.Input.Touch.currentPosition[i].x *= ((float)GetScreenWidth()/(float)canvasWidth);
CORE.Input.Touch.currentPosition[i].y *= ((float)GetScreenHeight()/(float)canvasHeight);
if (eventType == EMSCRIPTEN_EVENT_TOUCHSTART) CORE.Input.Touch.currentTouchState[i] = 1;
else if (eventType == EMSCRIPTEN_EVENT_TOUCHEND) CORE.Input.Touch.currentTouchState[i] = 0;
@ -1788,34 +1749,10 @@ static EM_BOOL EmscriptenTouchCallback(int eventType, const EmscriptenTouchEvent
// Update mouse position if a single touch is detected
if (CORE.Input.Touch.pointCount == 1)
{
CORE.Input.Mouse.currentPosition.x = CORE.Input.Touch.position[0].x;
CORE.Input.Mouse.currentPosition.y = CORE.Input.Touch.position[0].y;
CORE.Input.Mouse.currentPosition.x = CORE.Input.Touch.currentPosition[0].x;
CORE.Input.Mouse.currentPosition.y = CORE.Input.Touch.currentPosition[0].y;
}
#if SUPPORT_GESTURES_SYSTEM
GestureEvent gestureEvent = { 0 };
gestureEvent.pointCount = CORE.Input.Touch.pointCount;
// Register touch actions
if (eventType == EMSCRIPTEN_EVENT_TOUCHSTART) gestureEvent.touchAction = TOUCH_ACTION_DOWN;
else if (eventType == EMSCRIPTEN_EVENT_TOUCHEND) gestureEvent.touchAction = TOUCH_ACTION_UP;
else if (eventType == EMSCRIPTEN_EVENT_TOUCHMOVE) gestureEvent.touchAction = TOUCH_ACTION_MOVE;
else if (eventType == EMSCRIPTEN_EVENT_TOUCHCANCEL) gestureEvent.touchAction = TOUCH_ACTION_CANCEL;
for (int i = 0; (i < gestureEvent.pointCount) && (i < MAX_TOUCH_POINTS); i++)
{
gestureEvent.pointId[i] = CORE.Input.Touch.pointId[i];
gestureEvent.position[i] = CORE.Input.Touch.position[i];
// Normalize gestureEvent.position[i]
gestureEvent.position[i].x /= (float)GetScreenWidth();
gestureEvent.position[i].y /= (float)GetScreenHeight();
}
// Gesture data is sent to gestures system for processing
ProcessGestureEvent(gestureEvent);
#endif
if (eventType == EMSCRIPTEN_EVENT_TOUCHEND)
{
// Identify the EMSCRIPTEN_EVENT_TOUCHEND and remove it from the list
@ -1827,8 +1764,9 @@ static EM_BOOL EmscriptenTouchCallback(int eventType, const EmscriptenTouchEvent
for (int j = i; j < CORE.Input.Touch.pointCount - 1; j++)
{
CORE.Input.Touch.pointId[j] = CORE.Input.Touch.pointId[j + 1];
CORE.Input.Touch.position[j] = CORE.Input.Touch.position[j + 1];
CORE.Input.Touch.currentPosition[j] = CORE.Input.Touch.currentPosition[j + 1];
}
// Decrease touch points count to remove the last one
CORE.Input.Touch.pointCount--;
break;

View File

@ -1031,6 +1031,7 @@ RLAPI Vector2 GetWindowScaleDPI(void); // Get window
RLAPI const char *GetMonitorName(int monitor); // Get the human-readable, UTF-8 encoded name of the specified monitor
RLAPI void SetClipboardText(const char *text); // Set clipboard text content
RLAPI const char *GetClipboardText(void); // Get clipboard text content
RLAPI bool SetClipboardImage(Image image); // Set clipboard image content
RLAPI Image GetClipboardImage(void); // Get clipboard image content
RLAPI void EnableEventWaiting(void); // Enable waiting for events on EndDrawing(), no automatic event polling
RLAPI void DisableEventWaiting(void); // Disable waiting for events on EndDrawing(), automatic events polling

View File

@ -42,9 +42,6 @@
* #define SUPPORT_GESTURES_SYSTEM 1
* Gestures module is included (rgestures.h) to support gestures detection: tap, hold, swipe, drag
*
* #define SUPPORT_MOUSE_GESTURES 1
* Mouse gestures are directly mapped like touches and processed by gestures system
*
* #define SUPPORT_BUSY_WAIT_LOOP 1
* Use busy wait loop for timing sync, if not defined, a high-resolution timer is setup and used
*
@ -322,11 +319,9 @@ typedef struct CoreData {
char **dropFilepaths; // Store dropped files paths pointers (provided by GLFW)
unsigned int dropFileCount; // Count dropped files strings
} Window;
struct {
const char *basePath; // Base path for data storage
} Storage;
struct {
struct {
@ -343,7 +338,6 @@ typedef struct CoreData {
int charPressedQueue[MAX_CHAR_PRESSED_QUEUE]; // Input characters queue (unicode)
int charPressedQueueCount; // Input characters queue count
} Keyboard;
struct {
Vector2 offset; // Mouse offset
@ -361,16 +355,14 @@ typedef struct CoreData {
char previousButtonState[MAX_MOUSE_BUTTONS]; // Registers previous mouse button state
Vector2 currentWheelMove; // Registers current mouse wheel variation
Vector2 previousWheelMove; // Registers previous mouse wheel variation
} Mouse;
struct {
struct Touch {
int pointCount; // Number of touch points active
int pointId[MAX_TOUCH_POINTS]; // Point identifiers
Vector2 position[MAX_TOUCH_POINTS]; // Touch position on screen
Vector2 currentPosition[MAX_TOUCH_POINTS]; // Touch position on screen
Vector2 previousPosition[MAX_TOUCH_POINTS]; // Previous touch position on screen
char currentTouchState[MAX_TOUCH_POINTS]; // Registers current touch state
char previousTouchState[MAX_TOUCH_POINTS]; // Registers previous touch state
char currentTouchState[MAX_TOUCH_POINTS]; // Registers current touch state: 0-UP, 1-DOWN, 2-MOVE, 3-CANCEL
char previousTouchState[MAX_TOUCH_POINTS]; // Registers previous touch state: 0-UP, 1-DOWN, 2-MOVE, 3-CANCEL
} Touch;
struct {
int lastButtonPressed; // Register last gamepad button pressed
@ -380,9 +372,7 @@ typedef struct CoreData {
char currentButtonState[MAX_GAMEPADS][MAX_GAMEPAD_BUTTONS]; // Current gamepad buttons state
char previousButtonState[MAX_GAMEPADS][MAX_GAMEPAD_BUTTONS]; // Previous gamepad buttons state
float axisState[MAX_GAMEPADS][MAX_GAMEPAD_AXES]; // Gamepad axes state
} Gamepad;
} Input;
struct {
double current; // Current time measure (seconds)
@ -393,7 +383,6 @@ typedef struct CoreData {
double target; // Desired time for one frame, if 0 not applied (seconds)
unsigned long long base; // Base time measure for hi-res timer (ticks or nanoseconds)
unsigned int frameCounter; // Frame counter (frames)
} Time;
} CoreData;
@ -524,7 +513,7 @@ const char *TextFormat(const char *text, ...); // Formatting of text with variab
#include "platforms/rcore_desktop_glfw.c"
#elif defined(PLATFORM_DESKTOP_SDL)
#include "platforms/rcore_desktop_sdl.c"
#elif (defined(PLATFORM_DESKTOP_RGFW) || defined(PLATFORM_WEB_RGFW))
#elif defined(PLATFORM_DESKTOP_RGFW) || defined(PLATFORM_WEB_RGFW)
#include "platforms/rcore_desktop_rgfw.c"
#elif defined(PLATFORM_DESKTOP_WIN32)
#include "platforms/rcore_desktop_win32.c"
@ -579,8 +568,17 @@ const char *TextFormat(const char *text, ...); // Formatting of text with variab
//Vector2 GetMonitorPosition(int monitor)
//const char *GetMonitorName(int monitor)
// Clipboard interaction support
// NOTE: Only working on SDL3, GLFW (Windows) and RGFW (Windows)
// WARNING: It requires support for some additional flags:
// - SUPPORT_MODULE_RTEXTURES
// - SUPPORT_FILEFORMAT_BMP (Windows clipboard)
// - SUPPORT_FILEFORMAT_PNG (Wayland clipboard)
// - SUPPORT_FILEFORMAT_JPG
//void SetClipboardText(const char *text)
//const char *GetClipboardText(void)
//bool SetClipboardImage(Image image)
//Image GetClipboardImage(void)
//void ShowCursor(void)
//void HideCursor(void)
@ -861,7 +859,7 @@ bool IsCursorOnScreen(void)
void ClearBackground(Color color)
{
rlClearColor(color.r, color.g, color.b, color.a); // Set clear color
rlClearScreenBuffers(); // Clear current framebuffers
rlClearScreenBuffers(); // Clear screen framebuffers (color and depth)
}
// Begin canvas (framebuffer) drawing
@ -912,9 +910,57 @@ void EndDrawing(void)
CORE.Time.frame += waitTime; // Total frame time: update + draw + wait
}
PollInputEvents(); // Poll user events (before next frame update)
#if SUPPORT_GESTURES_SYSTEM
// NOTE: Gestures update must be called every frame to reset gestures correctly
// because ProcessGestureEvent() is called on an event, not every frame
//UpdateGestures();
#endif
PollInputEvents(); // Poll user events (before next frame update)
#if SUPPORT_GESTURES_SYSTEM
// If a previous swipe gesture was detected, just reset it
if ((GESTURES.current == GESTURE_SWIPE_RIGHT) ||
(GESTURES.current == GESTURE_SWIPE_UP) ||
(GESTURES.current == GESTURE_SWIPE_LEFT) ||
(GESTURES.current == GESTURE_SWIPE_DOWN))
{
GESTURES.current = GESTURE_NONE;
}
else if (((GESTURES.current == GESTURE_TAP) || (GESTURES.current == GESTURE_DOUBLETAP)) &&
(GESTURES.current != GESTURE_DRAG) && (GESTURES.Touch.pointCount == 1))
{
double currentTime = rgGetCurrentTime();
if ((currentTime - GESTURES.Touch.eventTime) > MIN_HOLD_TIME)
{
GESTURES.current = GESTURE_HOLD;
GESTURES.Hold.timeDuration = (currentTime - GESTURES.Touch.eventTime);
}
}
// Process gestures event: touch state changes
// NOTE: Touch move action (position change) is considered on move event (with threshold)
// WARNING: Only considering one touch point (id = 0), mouse on desktop platforms
if (CORE.Input.Touch.currentTouchState[0] != CORE.Input.Touch.previousTouchState[0])
{
// Register a new event with current touch data
GestureEvent gestureEvent = { 0 };
gestureEvent.pointCount = 1; // Register touch points count
gestureEvent.pointId[0] = 0; // Assign a pointer ID
gestureEvent.position[0] = CORE.Input.Touch.currentPosition[0];
gestureEvent.touchAction = CORE.Input.Touch.currentTouchState[0];
// Normalize gesture event position [0.0f..1.0f]
gestureEvent.position[0].x /= (float)GetScreenWidth();
gestureEvent.position[0].y /= (float)GetScreenHeight();
// Gesture data is sent to gestures-system for processing
ProcessGestureEvent(gestureEvent);
}
#endif
#endif // !SUPPORT_CUSTOM_FRAME_CONTROL
#if SUPPORT_SCREEN_CAPTURE
if (IsKeyPressed(KEY_F12))
{
@ -1675,8 +1721,7 @@ void WaitTime(double seconds)
// System halt functions
#if defined(_WIN32)
Sleep((unsigned long)(sleepSeconds*1000.0));
#endif
#if defined(__linux__) || defined(__FreeBSD__) || defined(__OpenBSD__) || defined(__EMSCRIPTEN__)
#elif defined(__linux__) || defined(__FreeBSD__) || defined(__OpenBSD__) || defined(__EMSCRIPTEN__)
struct timespec req = { 0 };
time_t sec = sleepSeconds;
long nsec = (sleepSeconds - sec)*1000000000L;
@ -1685,8 +1730,7 @@ void WaitTime(double seconds)
// NOTE: Use nanosleep() on Unix platforms... usleep() it's deprecated
while (nanosleep(&req, &req) == -1) continue;
#endif
#if defined(__APPLE__)
#elif defined(__APPLE__)
usleep(sleepSeconds*1000000.0);
#endif
@ -2424,6 +2468,7 @@ bool IsFileExtension(const char *fileName, const char *ext)
bool IsFileHidden(const char *filePath)
{
bool result = false;
#if defined(_WIN32)
unsigned long attribs = GetFileAttributesA(filePath);
@ -2435,6 +2480,7 @@ bool IsFileHidden(const char *filePath)
if ((basePath[0] == '.') && (strcmp(basePath, ".") != 0) && (strcmp(basePath, "..") != 0)) result = true;
#endif
return result;
}
@ -2692,9 +2738,7 @@ const char *GetApplicationDirectory(void)
appDir[0] = '.';
appDir[1] = '\\';
}
#elif defined(__linux__)
unsigned int size = sizeof(appDir);
ssize_t len = readlink("/proc/self/exe", appDir, size);
@ -2714,9 +2758,7 @@ const char *GetApplicationDirectory(void)
appDir[0] = '.';
appDir[1] = '/';
}
#elif defined(__APPLE__)
uint32_t size = sizeof(appDir);
if (_NSGetExecutablePath(appDir, &size) == 0)
@ -2736,9 +2778,7 @@ const char *GetApplicationDirectory(void)
appDir[0] = '.';
appDir[1] = '/';
}
#elif defined(__FreeBSD__)
size_t size = sizeof(appDir);
int mib[4] = {CTL_KERN, KERN_PROC, KERN_PROC_PATHNAME, -1};
@ -2759,9 +2799,7 @@ const char *GetApplicationDirectory(void)
appDir[0] = '.';
appDir[1] = '/';
}
#elif defined(__wasm__)
appDir[0] = '/';
#endif
@ -3853,8 +3891,8 @@ void PlayAutomationEvent(AutomationEvent event)
case INPUT_TOUCH_DOWN: CORE.Input.Touch.currentTouchState[event.params[0]] = true; break; // param[0]: id
case INPUT_TOUCH_POSITION: // param[0]: id, param[1]: x, param[2]: y
{
CORE.Input.Touch.position[event.params[0]].x = (float)event.params[1];
CORE.Input.Touch.position[event.params[0]].y = (float)event.params[2];
CORE.Input.Touch.currentPosition[event.params[0]].x = (float)event.params[1];
CORE.Input.Touch.currentPosition[event.params[0]].y = (float)event.params[2];
} break;
case INPUT_GAMEPAD_CONNECT: CORE.Input.Gamepad.ready[event.params[0]] = true; break; // param[0]: gamepad
case INPUT_GAMEPAD_DISCONNECT: CORE.Input.Gamepad.ready[event.params[0]] = false; break; // param[0]: gamepad
@ -4272,14 +4310,14 @@ Vector2 GetMouseWheelMoveV(void)
// Get touch position X for touch point 0 (relative to screen size)
int GetTouchX(void)
{
int touchX = (int)CORE.Input.Touch.position[0].x;
int touchX = (int)CORE.Input.Touch.currentPosition[0].x;
return touchX;
}
// Get touch position Y for touch point 0 (relative to screen size)
int GetTouchY(void)
{
int touchY = (int)CORE.Input.Touch.position[0].y;
int touchY = (int)CORE.Input.Touch.currentPosition[0].y;
return touchY;
}
@ -4288,7 +4326,7 @@ Vector2 GetTouchPosition(int index)
{
Vector2 position = { -1.0f, -1.0f };
if (index < MAX_TOUCH_POINTS) position = CORE.Input.Touch.position[index];
if (index < MAX_TOUCH_POINTS) position = CORE.Input.Touch.currentPosition[index];
else TRACELOG(LOG_WARNING, "INPUT: Required touch point out of range (Max touch points: %i)", MAX_TOUCH_POINTS);
return position;
@ -4565,14 +4603,14 @@ static void RecordAutomationEvent(void)
if (currentEventList->count == currentEventList->capacity) return; // Security check
// Event type: INPUT_TOUCH_POSITION
if (((int)CORE.Input.Touch.position[id].x != (int)CORE.Input.Touch.previousPosition[id].x) ||
((int)CORE.Input.Touch.position[id].y != (int)CORE.Input.Touch.previousPosition[id].y))
if (((int)CORE.Input.Touch.currentPosition[id].x != (int)CORE.Input.Touch.previousPosition[id].x) ||
((int)CORE.Input.Touch.currentPosition[id].y != (int)CORE.Input.Touch.previousPosition[id].y))
{
currentEventList->events[currentEventList->count].frame = CORE.Time.frameCounter;
currentEventList->events[currentEventList->count].type = INPUT_TOUCH_POSITION;
currentEventList->events[currentEventList->count].params[0] = id;
currentEventList->events[currentEventList->count].params[1] = (int)CORE.Input.Touch.position[id].x;
currentEventList->events[currentEventList->count].params[2] = (int)CORE.Input.Touch.position[id].y;
currentEventList->events[currentEventList->count].params[1] = (int)CORE.Input.Touch.currentPosition[id].x;
currentEventList->events[currentEventList->count].params[2] = (int)CORE.Input.Touch.currentPosition[id].y;
TRACELOG(LOG_INFO, "AUTOMATION: Frame: %i | Event type: INPUT_TOUCH_POSITION | Event parameters: %i, %i, %i", currentEventList->events[currentEventList->count].frame, currentEventList->events[currentEventList->count].params[0], currentEventList->events[currentEventList->count].params[1], currentEventList->events[currentEventList->count].params[2]);
currentEventList->count++;

View File

@ -123,7 +123,7 @@ extern "C" { // Prevents name mangling of functions
#endif
void ProcessGestureEvent(GestureEvent event); // Process gesture event and translate it into gestures
void UpdateGestures(void); // Update gestures detected (must be called every frame)
//void UpdateGestures(void); // Update gestures detected (must be called every frame)
#if defined(RGESTURES_STANDALONE)
void SetGesturesEnabled(unsigned int flags); // Enable a set of gestures using flags
@ -181,13 +181,14 @@ float GetGesturePinchAngle(void); // Get gesture pinch ang
//----------------------------------------------------------------------------------
// Defines and Macros
//----------------------------------------------------------------------------------
#define FORCE_TO_SWIPE 0.2f // Swipe force, measured in normalized screen units/time
#define MINIMUM_DRAG 0.015f // Drag minimum force, measured in normalized screen units (0.0f to 1.0f)
#define DRAG_TIMEOUT 0.3f // Drag minimum time for web, measured in seconds
#define MINIMUM_PINCH 0.005f // Pinch minimum force, measured in normalized screen units (0.0f to 1.0f)
#define TAP_TIMEOUT 0.3f // Tap minimum time, measured in seconds
#define PINCH_TIMEOUT 0.3f // Pinch minimum time, measured in seconds
#define DOUBLETAP_RANGE 0.03f // DoubleTap range, measured in normalized screen units (0.0f to 1.0f)
#define MIN_TAP_TIME 0.3f // Tap minimum time (DOWN-UP), measured in seconds
#define MIN_HOLD_TIME 0.6f // Hold minimum time, measured in seconds
#define MAX_DOUBLETAP_RANGE 0.03f // DoubleTap maximum range between first and second tap, measured in normalized screen units (0.0f to 1.0f)
#define MIN_DRAG_TIME 0.3f // Drag minimum time, measured in seconds
#define MIN_DRAG_DISTANCE 0.015f // Drag minimum distance, measured in normalized screen units (0.0f to 1.0f)
#define MIN_SWIPE_FORCE 0.2f // Swipe force, measured in normalized screen units/time
#define MIN_PINCH_TIME 0.3f // Pinch minimum time, measured in seconds
#define MIN_PINCH_DISTANCE 0.005f // Pinch minimum distance, measured in normalized screen units (0.0f to 1.0f)
//----------------------------------------------------------------------------------
// Types and Structures Definition
@ -265,10 +266,11 @@ bool IsGestureDetected(unsigned int gesture)
}
// Process gesture event and translate it into gestures
// TODO: Tap gesture is detected on DOWN action but should be detected on UP action
void ProcessGestureEvent(GestureEvent event)
{
// Reset required variables
GESTURES.Touch.pointCount = event.pointCount; // Required on UpdateGestures()
GESTURES.Touch.pointCount = event.pointCount;
if (GESTURES.Touch.pointCount == 1) // One touch point
{
@ -277,7 +279,9 @@ void ProcessGestureEvent(GestureEvent event)
GESTURES.Touch.tapCounter++; // Tap counter
// Detect GESTURE_DOUBLE_TAP
if ((GESTURES.current == GESTURE_NONE) && (GESTURES.Touch.tapCounter >= 2) && ((rgGetCurrentTime() - GESTURES.Touch.eventTime) < TAP_TIMEOUT) && (rgVector2Distance(GESTURES.Touch.downPositionA, event.position[0]) < DOUBLETAP_RANGE))
if ((GESTURES.current == GESTURE_NONE) && (GESTURES.Touch.tapCounter >= 2) &&
((rgGetCurrentTime() - GESTURES.Touch.eventTime) < MIN_TAP_TIME) &&
(rgVector2Distance(GESTURES.Touch.downPositionA, event.position[0]) < MAX_DOUBLETAP_RANGE))
{
GESTURES.current = GESTURE_DOUBLETAP;
GESTURES.Touch.tapCounter = 0;
@ -300,15 +304,14 @@ void ProcessGestureEvent(GestureEvent event)
}
else if (event.touchAction == TOUCH_ACTION_UP)
{
// A swipe can happen while the current gesture is drag, but (especially for web) also hold, so set upPosition for both cases
if (GESTURES.current == GESTURE_DRAG || GESTURES.current == GESTURE_HOLD) GESTURES.Touch.upPosition = event.position[0];
GESTURES.Touch.upPosition = event.position[0];
// NOTE: GESTURES.Drag.intensity is dependent on the resolution of the screen
GESTURES.Drag.distance = rgVector2Distance(GESTURES.Touch.downPositionA, GESTURES.Touch.upPosition);
GESTURES.Drag.intensity = GESTURES.Drag.distance/(float)((rgGetCurrentTime() - GESTURES.Swipe.startTime));
// Detect GESTURE_SWIPE
if ((GESTURES.Drag.intensity > FORCE_TO_SWIPE) && (GESTURES.current != GESTURE_DRAG))
if ((GESTURES.Drag.intensity > MIN_SWIPE_FORCE) && (GESTURES.current != GESTURE_DRAG))
{
// NOTE: Angle should be inverted in Y
GESTURES.Drag.angle = 360.0f - rgVector2Angle(GESTURES.Touch.downPositionA, GESTURES.Touch.upPosition);
@ -335,14 +338,10 @@ void ProcessGestureEvent(GestureEvent event)
{
GESTURES.Touch.moveDownPositionA = event.position[0];
if (GESTURES.current == GESTURE_HOLD)
if ((GESTURES.current == GESTURE_TAP) || (GESTURES.current == GESTURE_HOLD))
{
if (GESTURES.Hold.resetRequired) GESTURES.Touch.downPositionA = event.position[0];
GESTURES.Hold.resetRequired = false;
// Detect GESTURE_DRAG
if ((rgGetCurrentTime() - GESTURES.Touch.eventTime) > DRAG_TIMEOUT)
if ((rgGetCurrentTime() - GESTURES.Touch.eventTime) > MIN_DRAG_TIME)
{
GESTURES.Touch.eventTime = rgGetCurrentTime();
GESTURES.current = GESTURE_DRAG;
@ -363,13 +362,11 @@ void ProcessGestureEvent(GestureEvent event)
GESTURES.Touch.previousPositionA = GESTURES.Touch.downPositionA;
GESTURES.Touch.previousPositionB = GESTURES.Touch.downPositionB;
//GESTURES.Pinch.distance = rgVector2Distance(GESTURES.Touch.downPositionA, GESTURES.Touch.downPositionB);
GESTURES.Pinch.vector.x = GESTURES.Touch.downPositionB.x - GESTURES.Touch.downPositionA.x;
GESTURES.Pinch.vector.y = GESTURES.Touch.downPositionB.y - GESTURES.Touch.downPositionA.y;
GESTURES.current = GESTURE_HOLD;
GESTURES.Hold.timeDuration = rgGetCurrentTime();
//GESTURES.current = GESTURE_HOLD;
//GESTURES.Hold.timeDuration = rgGetCurrentTime();
}
else if (event.touchAction == TOUCH_ACTION_MOVE)
{
@ -381,16 +378,16 @@ void ProcessGestureEvent(GestureEvent event)
GESTURES.Pinch.vector.x = GESTURES.Touch.moveDownPositionB.x - GESTURES.Touch.moveDownPositionA.x;
GESTURES.Pinch.vector.y = GESTURES.Touch.moveDownPositionB.y - GESTURES.Touch.moveDownPositionA.y;
if ((rgVector2Distance(GESTURES.Touch.previousPositionA, GESTURES.Touch.moveDownPositionA) >= MINIMUM_PINCH) || (rgVector2Distance(GESTURES.Touch.previousPositionB, GESTURES.Touch.moveDownPositionB) >= MINIMUM_PINCH))
if ((rgVector2Distance(GESTURES.Touch.previousPositionA, GESTURES.Touch.moveDownPositionA) >= MIN_PINCH_DISTANCE) || (rgVector2Distance(GESTURES.Touch.previousPositionB, GESTURES.Touch.moveDownPositionB) >= MIN_PINCH_DISTANCE))
{
if ( rgVector2Distance(GESTURES.Touch.previousPositionA, GESTURES.Touch.previousPositionB) > rgVector2Distance(GESTURES.Touch.moveDownPositionA, GESTURES.Touch.moveDownPositionB) ) GESTURES.current = GESTURE_PINCH_IN;
if (rgVector2Distance(GESTURES.Touch.previousPositionA, GESTURES.Touch.previousPositionB) > rgVector2Distance(GESTURES.Touch.moveDownPositionA, GESTURES.Touch.moveDownPositionB) ) GESTURES.current = GESTURE_PINCH_IN;
else GESTURES.current = GESTURE_PINCH_OUT;
}
else
{
GESTURES.current = GESTURE_HOLD;
GESTURES.Hold.timeDuration = rgGetCurrentTime();
}
//else
//{
// GESTURES.current = GESTURE_HOLD;
// GESTURES.Hold.timeDuration = rgGetCurrentTime();
//}
// NOTE: Angle should be inverted in Y
GESTURES.Pinch.angle = 360.0f - rgVector2Angle(GESTURES.Touch.moveDownPositionA, GESTURES.Touch.moveDownPositionB);
@ -411,24 +408,33 @@ void ProcessGestureEvent(GestureEvent event)
}
}
/*
// Update gestures detected (must be called every frame)
void UpdateGestures(void)
{
// NOTE: Gestures are processed through system callbacks on touch events
// Detect GESTURE_HOLD
if (((GESTURES.current == GESTURE_TAP) || (GESTURES.current == GESTURE_DOUBLETAP)) && (GESTURES.Touch.pointCount < 2))
if (((GESTURES.current == GESTURE_TAP) || (GESTURES.current == GESTURE_DOUBLETAP)) &&
(GESTURES.Touch.pointCount < 2))
{
if ((rgGetCurrentTime() - GESTURES.Touch.eventTime) > MIN_HOLD_TIME)
{
GESTURES.current = GESTURE_HOLD;
GESTURES.Hold.timeDuration = rgGetCurrentTime();
GESTURES.Hold.timeDuration = (rgGetCurrentTime() - GESTURES.Touch.eventTime);
}
}
// Detect GESTURE_NONE
if ((GESTURES.current == GESTURE_SWIPE_RIGHT) || (GESTURES.current == GESTURE_SWIPE_UP) || (GESTURES.current == GESTURE_SWIPE_LEFT) || (GESTURES.current == GESTURE_SWIPE_DOWN))
if ((GESTURES.current == GESTURE_SWIPE_RIGHT) ||
(GESTURES.current == GESTURE_SWIPE_UP) ||
(GESTURES.current == GESTURE_SWIPE_LEFT) ||
(GESTURES.current == GESTURE_SWIPE_DOWN))
{
GESTURES.current = GESTURE_NONE;
}
}
*/
// Get latest detected gesture
int GetGestureDetected(void)

View File

@ -1079,7 +1079,6 @@ typedef struct rlglData {
int framebufferWidth; // Current framebuffer width
int framebufferHeight; // Current framebuffer height
} State; // Renderer state
struct {
bool vao; // VAO support (OpenGL ES2 could not support VAO extension) (GL_ARB_vertex_array_object)
@ -1101,7 +1100,6 @@ typedef struct rlglData {
float maxAnisotropyLevel; // Maximum anisotropy level supported (minimum is 2.0f)
int maxDepthBits; // Maximum bits for depth component
} ExtSupported; // Extensions supported flags
} rlglData;

View File

@ -6808,10 +6808,9 @@ static ModelAnimation *LoadModelAnimationsGLTF(const char *fileName, int *animCo
{
TRACELOG(LOG_WARNING, "MODEL: [%s] Expected one unique skin to load animation data from, but found %i", fileName, data->skins_count);
}
cgltf_free(data);
}
cgltf_free(data);
UnloadFileData(fileData);
return animations;

View File

@ -1925,7 +1925,8 @@ char *TextReplaceAlloc(const char *text, const char *search, const char *replace
for (count = 0; (temp = strstr(insertPoint, search)); count++) insertPoint = temp + searchLen;
// Allocate returning string and point temp to it
int tempLen = textLen + (replaceLen - searchLen)*count + 1;
int tempLen = textLen + count*(replaceLen - searchLen) + 1;
temp = result = (char *)RL_CALLOC(tempLen, sizeof(char));
// First time through the loop, all the variable are set correctly from here on,
@ -2101,7 +2102,7 @@ char *TextJoin(char **textList, int count, const char *delimiter)
int textLength = TextLength(textList[i]);
// Make sure joined text could fit inside MAX_TEXT_BUFFER_LENGTH
if ((totalLength + textLength + delimiterLen) < MAX_TEXT_BUFFER_LENGTH)
if ((totalLength + textLength + ((i < (count - 1))? delimiterLen : 0)) < MAX_TEXT_BUFFER_LENGTH)
{
memcpy(textPtr, textList[i], textLength);
totalLength += textLength;

View File

@ -5331,7 +5331,7 @@ Color ColorFromHSV(float hue, float saturation, float value)
k = (t < k)? t : k;
k = (k < 1)? k : 1;
k = (k > 0)? k : 0;
color.r = (unsigned char)((value - value*saturation*k)*255.0f);
color.r = (unsigned char)((value - value*saturation*k)*255.0f + 0.5f);
// Green channel
k = fmodf((3.0f + hue/60.0f), 6);
@ -5339,7 +5339,7 @@ Color ColorFromHSV(float hue, float saturation, float value)
k = (t < k)? t : k;
k = (k < 1)? k : 1;
k = (k > 0)? k : 0;
color.g = (unsigned char)((value - value*saturation*k)*255.0f);
color.g = (unsigned char)((value - value*saturation*k)*255.0f + 0.5f);
// Blue channel
k = fmodf((1.0f + hue/60.0f), 6);
@ -5347,7 +5347,7 @@ Color ColorFromHSV(float hue, float saturation, float value)
k = (t < k)? t : k;
k = (k < 1)? k : 1;
k = (k > 0)? k : 0;
color.b = (unsigned char)((value - value*saturation*k)*255.0f);
color.b = (unsigned char)((value - value*saturation*k)*255.0f + 0.5f);
return color;
}

View File

@ -3550,6 +3550,17 @@
"description": "Get clipboard text content",
"returnType": "const char *"
},
{
"name": "SetClipboardImage",
"description": "Set clipboard image content",
"returnType": "bool",
"params": [
{
"type": "Image",
"name": "image"
}
]
},
{
"name": "GetClipboardImage",
"description": "Get clipboard image content",

View File

@ -3427,6 +3427,14 @@ return {
description = "Get clipboard text content",
returnType = "const char *"
},
{
name = "SetClipboardImage",
description = "Set clipboard image content",
returnType = "bool",
params = {
{type = "Image", name = "image"}
}
},
{
name = "GetClipboardImage",
description = "Get clipboard image content",

View File

@ -2453,6 +2453,12 @@
(description "Get clipboard text content")
(return-type "const char *"))
((name "SetClipboardImage")
(description "Set clipboard image content")
(return-type "bool")
(params
((type "Image") (name "image"))))
((name "GetClipboardImage")
(description "Get clipboard image content")
(return-type "Image"))

File diff suppressed because it is too large Load Diff

View File

@ -681,7 +681,7 @@
<Param type="unsigned int" name="frames" desc="" />
</Callback>
</Callbacks>
<Functions count="619">
<Functions count="620">
<Function name="InitWindow" retType="void" paramCount="3" desc="Initialize window and OpenGL context">
<Param type="int" name="width" desc="" />
<Param type="int" name="height" desc="" />
@ -802,6 +802,9 @@
</Function>
<Function name="GetClipboardText" retType="const char *" paramCount="0" desc="Get clipboard text content">
</Function>
<Function name="SetClipboardImage" retType="bool" paramCount="1" desc="Set clipboard image content">
<Param type="Image" name="image" desc="" />
</Function>
<Function name="GetClipboardImage" retType="Image" paramCount="0" desc="Get clipboard image content">
</Function>
<Function name="EnableEventWaiting" retType="void" paramCount="0" desc="Enable waiting for events on EndDrawing(), no automatic event polling">