mirror of
https://github.com/raysan5/raylib.git
synced 2026-11-27 18:11:48 -05:00
Compare commits
11 Commits
fa14dc7792
...
master
| Author | SHA1 | Date | |
|---|---|---|---|
| e045e8fa1f | |||
| aefcca3505 | |||
| 8054413f53 | |||
| 0a63f1252f | |||
| 99b0707988 | |||
| 40b9da5e54 | |||
| 1f64f34cc0 | |||
| 7aeef57754 | |||
| 7cbadefd06 | |||
| 9fcb245f28 | |||
| dd8e7491e2 |
@ -77,7 +77,7 @@ if (dataPtr != NULL)
|
|||||||
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.**
|
**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.**
|
||||||
|
|
||||||
|
|||||||
@ -32,6 +32,7 @@ int main(void)
|
|||||||
const int screenWidth = 800;
|
const int screenWidth = 800;
|
||||||
const int screenHeight = 450;
|
const int screenHeight = 450;
|
||||||
|
|
||||||
|
// Remove FLAG_WINDOW_HIGHDPI to compare with automatic DPI scaling disabled
|
||||||
SetConfigFlags(FLAG_WINDOW_HIGHDPI | FLAG_WINDOW_RESIZABLE);
|
SetConfigFlags(FLAG_WINDOW_HIGHDPI | FLAG_WINDOW_RESIZABLE);
|
||||||
InitWindow(screenWidth, screenHeight, "raylib [core] example - highdpi demo");
|
InitWindow(screenWidth, screenHeight, "raylib [core] example - highdpi demo");
|
||||||
SetWindowMinSize(450, 450);
|
SetWindowMinSize(450, 450);
|
||||||
@ -45,7 +46,6 @@ int main(void)
|
|||||||
int pixelGridLabelY = pixelGridBottom + 30;
|
int pixelGridLabelY = pixelGridBottom + 30;
|
||||||
int pixelGridDescY = pixelGridLabelY + 30;
|
int pixelGridDescY = pixelGridLabelY + 30;
|
||||||
int cellSize = 50;
|
int cellSize = 50;
|
||||||
float cellSizePx = (float)cellSize;
|
|
||||||
|
|
||||||
SetTargetFPS(60); // Set our game to run at 60 frames-per-second
|
SetTargetFPS(60); // Set our game to run at 60 frames-per-second
|
||||||
//--------------------------------------------------------------------------------------
|
//--------------------------------------------------------------------------------------
|
||||||
@ -64,7 +64,11 @@ int main(void)
|
|||||||
|
|
||||||
int currentMonitor = GetCurrentMonitor();
|
int currentMonitor = GetCurrentMonitor();
|
||||||
Vector2 dpiScale = GetWindowScaleDPI();
|
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
|
// Draw
|
||||||
@ -90,12 +94,12 @@ int main(void)
|
|||||||
odd = true;
|
odd = true;
|
||||||
const int minTextSpace = 30;
|
const int minTextSpace = 30;
|
||||||
int lastTextX = -minTextSpace;
|
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);
|
int x = (int)(i*renderToLogicalX);
|
||||||
if (odd) DrawRectangle(x, pixelGridTop, (int)cellSizePx, pixelGridBottom - pixelGridTop, CLITERAL(Color){ 0, 121, 241, 100 });
|
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)
|
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?";
|
const char *text = "Can you see this?";
|
||||||
Vector2 size = MeasureTextEx(GetFontDefault(), text, 20, 3);
|
Vector2 size = MeasureTextEx(GetFontDefault(), text, 20, 3);
|
||||||
|
|||||||
14
src/config.h
14
src/config.h
@ -72,10 +72,6 @@
|
|||||||
// Include pseudo-random numbers generator (rprand.h), based on Xoshiro128** and SplitMix64
|
// Include pseudo-random numbers generator (rprand.h), based on Xoshiro128** and SplitMix64
|
||||||
#define SUPPORT_RPRAND_GENERATOR 1
|
#define SUPPORT_RPRAND_GENERATOR 1
|
||||||
#endif
|
#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
|
#ifndef SUPPORT_SSH_KEYBOARD_RPI
|
||||||
// Reconfigure standard input to receive key inputs, works with SSH connection
|
// Reconfigure standard input to receive key inputs, works with SSH connection
|
||||||
#define SUPPORT_SSH_KEYBOARD_RPI 1
|
#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
|
// Enabling this flag allows manual control of the frame processes, use at your own risk
|
||||||
#define SUPPORT_CUSTOM_FRAME_CONTROL 0 // Disabled by default
|
#define SUPPORT_CUSTOM_FRAME_CONTROL 0 // Disabled by default
|
||||||
#endif
|
#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
|
// rcore: Configuration values
|
||||||
// NOTE: Below values are already defined inside [rcore.c] so there is no need to be
|
// NOTE: Below values are already defined inside [rcore.c] so there is no need to be
|
||||||
|
|||||||
2
src/external/rlsw.h
vendored
2
src/external/rlsw.h
vendored
@ -685,6 +685,7 @@ SWAPI void swSwapColorBuffers(void); // Swap software renderer color/back buffer
|
|||||||
SWAPI void swEnable(SWstate state);
|
SWAPI void swEnable(SWstate state);
|
||||||
SWAPI void swDisable(SWstate state);
|
SWAPI void swDisable(SWstate state);
|
||||||
|
|
||||||
|
SWAPI void swGetIntegerv(SWget name, int *v);
|
||||||
SWAPI void swGetFloatv(SWget name, float *v);
|
SWAPI void swGetFloatv(SWget name, float *v);
|
||||||
SWAPI const char *swGetString(SWget name);
|
SWAPI const char *swGetString(SWget name);
|
||||||
SWAPI SWerrcode swGetError(void);
|
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 swGenTextures(int count, uint32_t *textures);
|
||||||
SWAPI void swDeleteTextures(int count, uint32_t *textures);
|
SWAPI void swDeleteTextures(int count, uint32_t *textures);
|
||||||
SWAPI void swBindTexture(uint32_t id);
|
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 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 swTexSubImage2D(GLint x, GLint y, GLsizei width, GLsizei height, GLenum format, GLenum type, const void *pixels);
|
||||||
SWAPI void swTexParameteri(int param, int value);
|
SWAPI void swTexParameteri(int param, int value);
|
||||||
|
|||||||
@ -19,7 +19,6 @@
|
|||||||
*
|
*
|
||||||
* DEPENDENCIES:
|
* DEPENDENCIES:
|
||||||
* - Android NDK: Provides C API to access Android functionality
|
* - Android NDK: Provides C API to access Android functionality
|
||||||
* - gestures: Gestures system for touch-ready devices (or simulated from mouse inputs)
|
|
||||||
*
|
*
|
||||||
*
|
*
|
||||||
* LICENSE: zlib/libpng
|
* LICENSE: zlib/libpng
|
||||||
@ -721,7 +720,7 @@ Image GetClipboardImage(void)
|
|||||||
{
|
{
|
||||||
Image image = { 0 };
|
Image image = { 0 };
|
||||||
|
|
||||||
TRACELOG(LOG_WARNING, "GetClipboardImage() not implemented on target platform");
|
TRACELOG(LOG_WARNING, "Clipboard image retrieving not implemented");
|
||||||
|
|
||||||
return image;
|
return image;
|
||||||
}
|
}
|
||||||
@ -861,12 +860,6 @@ const char *GetKeyName(int key)
|
|||||||
// Register all input events
|
// Register all input events
|
||||||
void PollInputEvents(void)
|
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
|
// Reset keys/chars pressed registered
|
||||||
CORE.Input.Keyboard.keyPressedQueueCount = 0;
|
CORE.Input.Keyboard.keyPressedQueueCount = 0;
|
||||||
CORE.Input.Keyboard.charPressedQueueCount = 0;
|
CORE.Input.Keyboard.charPressedQueueCount = 0;
|
||||||
@ -891,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];
|
for (int i = 0; i < MAX_TOUCH_POINTS; i++) CORE.Input.Touch.previousTouchState[i] = CORE.Input.Touch.currentTouchState[i];
|
||||||
|
|
||||||
// Reset touch positions
|
// 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
|
// Register previous keys states
|
||||||
// NOTE: Android supports up to 260 keys
|
// NOTE: Android supports up to 260 keys
|
||||||
@ -1472,7 +1465,7 @@ static int32_t AndroidInputCallback(struct android_app *app, AInputEvent *event)
|
|||||||
// Register touch points position
|
// Register touch points position
|
||||||
touchRaw.position[i] = (Vector2){ AMotionEvent_getX(event, i), AMotionEvent_getY(event, i) };
|
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 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;
|
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;
|
touchRaw.position[i].x = touchRaw.position[i].x*widthRatio - (float)CORE.Window.renderOffset.x/2;
|
||||||
@ -1575,7 +1568,7 @@ static int32_t AndroidInputCallback(struct android_app *app, AInputEvent *event)
|
|||||||
if (hover) continue;
|
if (hover) continue;
|
||||||
|
|
||||||
CORE.Input.Touch.pointId[CORE.Input.Touch.pointCount] = touchRaw.pointId[i];
|
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++;
|
CORE.Input.Touch.pointCount++;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -1587,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
|
// 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;
|
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
|
// 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 };
|
CORE.Input.Mouse.currentWheelMove = (Vector2){ 0.0f, 0.0f };
|
||||||
|
|
||||||
return 0;
|
return 0;
|
||||||
|
|||||||
@ -22,7 +22,6 @@
|
|||||||
*
|
*
|
||||||
* DEPENDENCIES:
|
* DEPENDENCIES:
|
||||||
* - rglfw: Manage graphic device, OpenGL context and inputs (Windows, Linux, OSX/macOS, FreeBSD...)
|
* - 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
|
* LICENSE: zlib/libpng
|
||||||
@ -1080,7 +1079,7 @@ void SetClipboardText(const char *text)
|
|||||||
}
|
}
|
||||||
|
|
||||||
// Get clipboard text content
|
// 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)
|
const char *GetClipboardText(void)
|
||||||
{
|
{
|
||||||
return glfwGetClipboardString(platform.handle);
|
return glfwGetClipboardString(platform.handle);
|
||||||
@ -1108,7 +1107,11 @@ Image GetClipboardImage(void)
|
|||||||
{
|
{
|
||||||
Image image = { 0 };
|
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
|
||||||
|
|
||||||
#if defined(_WIN32)
|
#if defined(_WIN32)
|
||||||
unsigned int dataSize = 0;
|
unsigned int dataSize = 0;
|
||||||
void *bmpData = NULL;
|
void *bmpData = NULL;
|
||||||
@ -1163,11 +1166,8 @@ Image GetClipboardImage(void)
|
|||||||
XFree(data);
|
XFree(data);
|
||||||
}
|
}
|
||||||
#else
|
#else
|
||||||
TRACELOG(LOG_WARNING, "GetClipboardImage() not implemented on target platform");
|
TRACELOG(LOG_WARNING, "Clipboard image not implemented on target platform");
|
||||||
#endif
|
#endif
|
||||||
#else
|
|
||||||
TRACELOG(LOG_WARNING, "Clipboard image: SUPPORT_CLIPBOARD_IMAGE requires SUPPORT_MODULE_RTEXTURES to work properly");
|
|
||||||
#endif // SUPPORT_CLIPBOARD_IMAGE
|
|
||||||
|
|
||||||
return image;
|
return image;
|
||||||
}
|
}
|
||||||
@ -1316,21 +1316,14 @@ const char *GetKeyName(int key)
|
|||||||
// Register all input events
|
// Register all input events
|
||||||
void PollInputEvents(void)
|
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
|
// Reset keys/chars pressed registered
|
||||||
CORE.Input.Keyboard.keyPressedQueueCount = 0;
|
CORE.Input.Keyboard.keyPressedQueueCount = 0;
|
||||||
CORE.Input.Keyboard.charPressedQueueCount = 0;
|
CORE.Input.Keyboard.charPressedQueueCount = 0;
|
||||||
|
|
||||||
// Reset last gamepad button/axis registered state
|
// Reset last gamepad button/axis registered state
|
||||||
CORE.Input.Gamepad.lastButtonPressed = GAMEPAD_BUTTON_UNKNOWN;
|
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
|
// Register previous keys states
|
||||||
for (int i = 0; i < MAX_KEYBOARD_KEYS; i++)
|
for (int i = 0; i < MAX_KEYBOARD_KEYS; i++)
|
||||||
@ -1352,15 +1345,20 @@ void PollInputEvents(void)
|
|||||||
// Register previous touch states
|
// Register previous touch states
|
||||||
for (int i = 0; i < MAX_TOUCH_POINTS; i++) CORE.Input.Touch.previousTouchState[i] = CORE.Input.Touch.currentTouchState[i];
|
for (int i = 0; i < MAX_TOUCH_POINTS; i++) CORE.Input.Touch.previousTouchState[i] = CORE.Input.Touch.currentTouchState[i];
|
||||||
|
|
||||||
// Reset touch positions
|
// Register previous touch positions and reset
|
||||||
//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.previousPosition[i] = CORE.Input.Touch.currentPosition[i];
|
||||||
|
CORE.Input.Touch.currentPosition[i] = (Vector2){ 0, 0 };
|
||||||
|
}
|
||||||
|
|
||||||
// Map touch position to mouse position for convenience
|
// Map touch position to mouse position for convenience
|
||||||
// WARNING: If the target desktop device supports touch screen, this behaviour should be reviewed!
|
// WARNING: If the target desktop device supports touch screen, this behaviour should be reviewed!
|
||||||
// TODO: GLFW does not support multi-touch input yet
|
// TODO: GLFW does not support multi-touch input yet
|
||||||
// REF: https://www.codeproject.com/Articles/668404/Programming-for-Multi-Touch
|
// 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
|
// 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
|
// Check if gamepads are ready
|
||||||
// NOTE: Doing it here in case of disconnection
|
// NOTE: Doing it here in case of disconnection
|
||||||
@ -1464,7 +1462,7 @@ void PollInputEvents(void)
|
|||||||
glfwWaitEvents(); // Wait for in input events before continue (drawing is paused)
|
glfwWaitEvents(); // Wait for in input events before continue (drawing is paused)
|
||||||
CORE.Time.previous = GetTime();
|
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);
|
CORE.Window.shouldClose = glfwWindowShouldClose(platform.handle);
|
||||||
|
|
||||||
@ -2179,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)
|
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,
|
// 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)
|
// but future releases may add more actions (i.e. GLFW_REPEAT)
|
||||||
CORE.Input.Mouse.currentButtonState[button] = action;
|
CORE.Input.Mouse.currentButtonState[button] = action;
|
||||||
CORE.Input.Touch.currentTouchState[button] = action;
|
|
||||||
|
|
||||||
#if SUPPORT_GESTURES_SYSTEM && SUPPORT_MOUSE_GESTURES
|
// Processing mouse events as touches, using button id as touch id
|
||||||
// Process mouse events as touches to be able to use mouse-gestures
|
if (action == GLFW_PRESS)
|
||||||
GestureEvent gestureEvent = { 0 };
|
{
|
||||||
|
CORE.Input.Touch.pointCount = 1;
|
||||||
// Register touch actions
|
CORE.Input.Touch.pointId[button] = button;
|
||||||
if ((CORE.Input.Mouse.currentButtonState[button] == 1) && (CORE.Input.Mouse.previousButtonState[button] == 0)) gestureEvent.touchAction = TOUCH_ACTION_DOWN;
|
CORE.Input.Touch.currentTouchState[button] = 1; // ACTION: DOWN
|
||||||
else if ((CORE.Input.Mouse.currentButtonState[button] == 0) && (CORE.Input.Mouse.previousButtonState[button] == 1)) gestureEvent.touchAction = TOUCH_ACTION_UP;
|
CORE.Input.Touch.currentPosition[button] = GetMousePosition();
|
||||||
|
}
|
||||||
// NOTE: TOUCH_ACTION_MOVE event is registered in MouseCursorPosCallback()
|
else if (action == GLFW_RELEASE)
|
||||||
|
{
|
||||||
// Assign a pointer ID
|
// Point count and id should be reseted at some point
|
||||||
gestureEvent.pointId[0] = 0;
|
CORE.Input.Touch.currentTouchState[button] = 0; // ACTION: UP
|
||||||
|
CORE.Input.Touch.currentPosition[button] = GetMousePosition();
|
||||||
// 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
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// GLFW3: Cursor position callback, runs on mouse movement
|
// GLFW3: Cursor position callback, runs on mouse movement
|
||||||
@ -2220,30 +2205,11 @@ static void MouseCursorPosCallback(GLFWwindow *window, double x, double y)
|
|||||||
{
|
{
|
||||||
CORE.Input.Mouse.currentPosition.x = (float)x;
|
CORE.Input.Mouse.currentPosition.x = (float)x;
|
||||||
CORE.Input.Mouse.currentPosition.y = (float)y;
|
CORE.Input.Mouse.currentPosition.y = (float)y;
|
||||||
CORE.Input.Touch.position[0] = CORE.Input.Mouse.currentPosition;
|
|
||||||
|
|
||||||
#if SUPPORT_GESTURES_SYSTEM && SUPPORT_MOUSE_GESTURES
|
// Register current touch position and movement action
|
||||||
// Process mouse events as touches to be able to use mouse-gestures
|
CORE.Input.Touch.currentPosition[0] = CORE.Input.Mouse.currentPosition;
|
||||||
GestureEvent gestureEvent = { 0 };
|
if (Vector2Distance(CORE.Input.Touch.currentPosition[0], CORE.Input.Touch.previousPosition[0]) > 3.0f)
|
||||||
|
CORE.Input.Touch.currentTouchState[0] = 2; // ACTION: MOVE
|
||||||
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: Mouse wheel scroll callback, runs on mouse wheel changes
|
// GLFW3: Mouse wheel scroll callback, runs on mouse wheel changes
|
||||||
@ -2253,18 +2219,12 @@ static void MouseScrollCallback(GLFWwindow *window, double xoffset, double yoffs
|
|||||||
CORE.Input.Mouse.currentWheelMove.y += (float)yoffset;
|
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)
|
static void CursorEnterCallback(GLFWwindow *window, int entered)
|
||||||
{
|
{
|
||||||
if (entered)
|
if (entered) CORE.Input.Mouse.cursorOnScreen = true;
|
||||||
{
|
else CORE.Input.Mouse.cursorOnScreen = false;
|
||||||
// NOTE: Mouse position updated by MouseCursorPosCallback()
|
|
||||||
CORE.Input.Mouse.cursorOnScreen = true;
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
CORE.Input.Mouse.cursorOnScreen = false;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// GLFW3: Joystick connected/disconnected callback
|
// GLFW3: Joystick connected/disconnected callback
|
||||||
|
|||||||
@ -21,7 +21,6 @@
|
|||||||
*
|
*
|
||||||
* DEPENDENCIES:
|
* DEPENDENCIES:
|
||||||
* - RGFW.h (main library): Windowing and inputs management
|
* - RGFW.h (main library): Windowing and inputs management
|
||||||
* - gestures: Gestures system for touch-ready devices (or simulated from mouse inputs)
|
|
||||||
*
|
*
|
||||||
*
|
*
|
||||||
* LICENSE: zlib/libpng
|
* LICENSE: zlib/libpng
|
||||||
@ -168,6 +167,17 @@ extern "C" {
|
|||||||
#undef Size
|
#undef Size
|
||||||
#endif
|
#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>
|
#include <stdbool.h>
|
||||||
|
|
||||||
//----------------------------------------------------------------------------------
|
//----------------------------------------------------------------------------------
|
||||||
@ -685,7 +695,7 @@ static void RGFW_cb_mouserawmotionfunc(const RGFW_event *e)
|
|||||||
CORE.Input.Mouse.currentPosition.y += mouseY;
|
CORE.Input.Mouse.currentPosition.y += mouseY;
|
||||||
|
|
||||||
// simulate touch with the mouse
|
// 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);
|
RemapMouseToTouch(2);
|
||||||
}
|
}
|
||||||
static void RGFW_cb_mousemotionfunc(const RGFW_event *e)
|
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;
|
CORE.Input.Mouse.currentPosition.y = mouseY;
|
||||||
|
|
||||||
// simulate touch with the mouse
|
// 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);
|
RemapMouseToTouch(2);
|
||||||
}
|
}
|
||||||
static void RGFW_cb_keyfunc(const RGFW_keyEvent* e)
|
static void RGFW_cb_keyfunc(const RGFW_keyEvent* e)
|
||||||
@ -1307,26 +1317,17 @@ const char *GetClipboardText(void)
|
|||||||
return RGFW_readClipboard(NULL);
|
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
|
// Get clipboard image
|
||||||
Image GetClipboardImage(void)
|
Image GetClipboardImage(void)
|
||||||
{
|
{
|
||||||
Image image = { 0 };
|
Image image = { 0 };
|
||||||
|
|
||||||
#if SUPPORT_CLIPBOARD_IMAGE && SUPPORT_MODULE_RTEXTURES
|
#if !SUPPORT_MODULE_RTEXTURES
|
||||||
#if defined(_WIN32
|
TRACELOG(LOG_WARNING, "Clipboard image requires SUPPORT_MODULE_RTEXTURES to work");
|
||||||
|
return image;
|
||||||
|
#endif
|
||||||
|
|
||||||
|
#if defined(_WIN32)
|
||||||
unsigned int dataSize = 0;
|
unsigned int dataSize = 0;
|
||||||
void *fileData = NULL;
|
void *fileData = NULL;
|
||||||
|
|
||||||
@ -1386,11 +1387,8 @@ Image GetClipboardImage(void)
|
|||||||
XDestroyWindow(dpy, win);
|
XDestroyWindow(dpy, win);
|
||||||
XCloseDisplay(dpy);
|
XCloseDisplay(dpy);
|
||||||
#else
|
#else
|
||||||
TRACELOG(LOG_WARNING, "Clipboard image: PLATFORM_DESKTOP_RGFW doesn't implement GetClipboardImage() for this OS");
|
TRACELOG(LOG_WARNING, "Clipboard image not implemented on target platform");
|
||||||
#endif // _WIN32
|
#endif
|
||||||
#else
|
|
||||||
TRACELOG(LOG_WARNING, "Clipboard image: SUPPORT_CLIPBOARD_IMAGE requires SUPPORT_MODULE_RTEXTURES to work properly");
|
|
||||||
#endif // SUPPORT_CLIPBOARD_IMAGE
|
|
||||||
|
|
||||||
return image;
|
return image;
|
||||||
}
|
}
|
||||||
@ -1553,12 +1551,6 @@ const char *GetKeyName(int key)
|
|||||||
// Register all input events
|
// Register all input events
|
||||||
void PollInputEvents(void)
|
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
|
// Reset keys/chars pressed registered
|
||||||
CORE.Input.Keyboard.keyPressedQueueCount = 0;
|
CORE.Input.Keyboard.keyPressedQueueCount = 0;
|
||||||
CORE.Input.Keyboard.charPressedQueueCount = 0;
|
CORE.Input.Keyboard.charPressedQueueCount = 0;
|
||||||
@ -1587,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];
|
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
|
// 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
|
// Register previous keys states
|
||||||
// NOTE: Android supports up to 260 keys
|
// NOTE: Android supports up to 260 keys
|
||||||
@ -2042,31 +2034,25 @@ static KeyboardKey ConvertScancodeToKey(u32 keycode)
|
|||||||
// NOTE: 0-TOUCH_ACTION_UP, 1-TOUCH_ACTION_DOWN, 2-TOUCH_ACTION_MOVE
|
// NOTE: 0-TOUCH_ACTION_UP, 1-TOUCH_ACTION_DOWN, 2-TOUCH_ACTION_MOVE
|
||||||
void RemapMouseToTouch(int touchAction)
|
void RemapMouseToTouch(int touchAction)
|
||||||
{
|
{
|
||||||
#if SUPPORT_GESTURES_SYSTEM
|
#if SUPPORT_GESTURES_SYSTEM
|
||||||
if (touchAction < 0) return;
|
if (touchAction < 0) return;
|
||||||
|
|
||||||
GestureEvent gestureEvent = { 0 };
|
GestureEvent gestureEvent = { 0 };
|
||||||
|
|
||||||
// Register touch actions
|
|
||||||
gestureEvent.touchAction = touchAction;
|
gestureEvent.touchAction = touchAction;
|
||||||
|
|
||||||
// Assign a pointer ID
|
|
||||||
gestureEvent.pointId[0] = 0;
|
gestureEvent.pointId[0] = 0;
|
||||||
|
|
||||||
// Register touch points count
|
|
||||||
gestureEvent.pointCount = 1;
|
gestureEvent.pointCount = 1;
|
||||||
|
|
||||||
// Register touch points position, only one point registered
|
// 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();
|
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].x /= (float)GetScreenWidth();
|
||||||
gestureEvent.position[0].y /= (float)GetScreenHeight();
|
gestureEvent.position[0].y /= (float)GetScreenHeight();
|
||||||
|
|
||||||
// Gesture data is sent to gestures-system for processing
|
// Gesture data is sent to gestures-system for processing
|
||||||
ProcessGestureEvent(gestureEvent);
|
ProcessGestureEvent(gestureEvent);
|
||||||
#endif
|
#endif
|
||||||
}
|
}
|
||||||
|
|
||||||
// Helper functions for Time
|
// Helper functions for Time
|
||||||
|
|||||||
@ -21,7 +21,6 @@
|
|||||||
*
|
*
|
||||||
* DEPENDENCIES:
|
* DEPENDENCIES:
|
||||||
* - SDL 2 or SDL 3 (main library): Windowing and inputs management
|
* - 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
|
* LICENSE: zlib/libpng
|
||||||
@ -1215,22 +1214,22 @@ Image GetClipboardImage(void)
|
|||||||
{
|
{
|
||||||
Image image = { 0 };
|
Image image = { 0 };
|
||||||
|
|
||||||
#if SUPPORT_CLIPBOARD_IMAGE
|
|
||||||
#if !SUPPORT_MODULE_RTEXTURES
|
#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;
|
return image;
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
// It's nice to have support Bitmap on Linux as well, but not as necessary as Windows
|
// It's nice to have support Bitmap on Linux as well, but not as necessary as Windows
|
||||||
#if !SUPPORT_FILEFORMAT_BMP && defined(_WIN32)
|
#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;
|
return image;
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
// From what I've tested applications on Wayland saves images on clipboard as PNG
|
// From what I've tested applications on Wayland saves images on clipboard as PNG
|
||||||
#if (!SUPPORT_FILEFORMAT_PNG || !SUPPORT_FILEFORMAT_JPG) && !defined(_WIN32)
|
#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
|
#endif
|
||||||
|
|
||||||
// Let's hope compiler put these arrays in static memory
|
// Let's hope compiler put these arrays in static memory
|
||||||
const char *imageFormats[] = {
|
const char *imageFormats[] = {
|
||||||
"image/bmp",
|
"image/bmp",
|
||||||
@ -1238,6 +1237,7 @@ Image GetClipboardImage(void)
|
|||||||
"image/jpg",
|
"image/jpg",
|
||||||
"image/tiff",
|
"image/tiff",
|
||||||
};
|
};
|
||||||
|
|
||||||
const char *imageExtensions[] = {
|
const char *imageExtensions[] = {
|
||||||
".bmp",
|
".bmp",
|
||||||
".png",
|
".png",
|
||||||
@ -1259,14 +1259,13 @@ Image GetClipboardImage(void)
|
|||||||
|
|
||||||
if (IsImageValid(image))
|
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;
|
return image;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!IsImageValid(image)) TRACELOG(LOG_WARNING, "Clipboard: Couldn't get clipboard data. ERROR: %s", SDL_GetError());
|
if (!IsImageValid(image)) TRACELOG(LOG_WARNING, "Clipboard image data can not be retrieved, ERROR: %s", SDL_GetError());
|
||||||
#endif // SUPPORT_CLIPBOARD_IMAGE
|
|
||||||
|
|
||||||
return image;
|
return image;
|
||||||
}
|
}
|
||||||
@ -1425,12 +1424,6 @@ const char *GetKeyName(int key)
|
|||||||
// Register all input events
|
// Register all input events
|
||||||
void PollInputEvents(void)
|
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
|
// Reset keys/chars pressed registered
|
||||||
CORE.Input.Keyboard.keyPressedQueueCount = 0;
|
CORE.Input.Keyboard.keyPressedQueueCount = 0;
|
||||||
CORE.Input.Keyboard.charPressedQueueCount = 0;
|
CORE.Input.Keyboard.charPressedQueueCount = 0;
|
||||||
@ -1465,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];
|
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
|
// 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
|
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
|
bool realTouch = false; // Flag to differentiate real touch gestures from mouse ones
|
||||||
@ -1750,7 +1743,7 @@ void PollInputEvents(void)
|
|||||||
CORE.Input.Mouse.currentPosition.y = (float)event.motion.y;
|
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;
|
touchAction = 2;
|
||||||
} break;
|
} break;
|
||||||
|
|
||||||
@ -1965,36 +1958,6 @@ void PollInputEvents(void)
|
|||||||
} break;
|
} break;
|
||||||
default: 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
|
|
||||||
}
|
}
|
||||||
//-----------------------------------------------------------------------------
|
//-----------------------------------------------------------------------------
|
||||||
}
|
}
|
||||||
@ -2191,7 +2154,7 @@ int InitPlatform(void)
|
|||||||
|
|
||||||
// Disable mouse events being interpreted as touch events
|
// Disable mouse events being interpreted as touch events
|
||||||
// NOTE: This is wanted because there are SDL_FINGER* events available which provide unique data
|
// 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_SetHint(SDL_HINT_TOUCH_MOUSE_EVENTS, "0");
|
||||||
|
|
||||||
SDL_EventState(SDL_DROPFILE, SDL_ENABLE);
|
SDL_EventState(SDL_DROPFILE, SDL_ENABLE);
|
||||||
@ -2298,8 +2261,8 @@ static void UpdateTouchPointsSDL(SDL_TouchFingerEvent event)
|
|||||||
{
|
{
|
||||||
SDL_Finger *finger = fingers[i];
|
SDL_Finger *finger = fingers[i];
|
||||||
CORE.Input.Touch.pointId[i] = finger->id;
|
CORE.Input.Touch.pointId[i] = finger->id;
|
||||||
CORE.Input.Touch.position[i].x = finger->x*CORE.Window.screen.width;
|
CORE.Input.Touch.currentPosition[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].y = finger->y*CORE.Window.screen.height;
|
||||||
CORE.Input.Touch.currentTouchState[i] = 1;
|
CORE.Input.Touch.currentTouchState[i] = 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -2313,8 +2276,8 @@ static void UpdateTouchPointsSDL(SDL_TouchFingerEvent event)
|
|||||||
{
|
{
|
||||||
SDL_Finger *finger = SDL_GetTouchFinger(event.touchId, i);
|
SDL_Finger *finger = SDL_GetTouchFinger(event.touchId, i);
|
||||||
CORE.Input.Touch.pointId[i] = (int)finger->id;
|
CORE.Input.Touch.pointId[i] = (int)finger->id;
|
||||||
CORE.Input.Touch.position[i].x = finger->x*CORE.Window.screen.width;
|
CORE.Input.Touch.currentPosition[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].y = finger->y*CORE.Window.screen.height;
|
||||||
CORE.Input.Touch.currentTouchState[i] = 1;
|
CORE.Input.Touch.currentTouchState[i] = 1;
|
||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
|
|||||||
@ -91,18 +91,28 @@ typedef enum MONITOR_DPI_TYPE {
|
|||||||
#include <GL/gl.h>
|
#include <GL/gl.h>
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
#if SUPPORT_CLIPBOARD_IMAGE && SUPPORT_MODULE_RTEXTURES
|
#define WIN32_CLIPBOARD_IMPLEMENTATION
|
||||||
#define WIN32_CLIPBOARD_IMPLEMENTATION
|
#define WINUSER_ALREADY_INCLUDED
|
||||||
#define WINUSER_ALREADY_INCLUDED
|
#define WINBASE_ALREADY_INCLUDED
|
||||||
#define WINBASE_ALREADY_INCLUDED
|
#define WINGDI_ALREADY_INCLUDED
|
||||||
#define WINGDI_ALREADY_INCLUDED
|
#include "../external/win32_clipboard.h"
|
||||||
#include "../external/win32_clipboard.h"
|
|
||||||
#endif
|
|
||||||
|
|
||||||
//----------------------------------------------------------------------------------
|
//----------------------------------------------------------------------------------
|
||||||
// Types and Structures Definition
|
// 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,
|
// 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)
|
// the backend must keep the client area this size (after DPI scaling is applied)
|
||||||
// when the window isn't fullscreen/maximized/minimized
|
// when the window isn't fullscreen/maximized/minimized
|
||||||
@ -127,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
|
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;
|
LARGE_INTEGER timerFrequency;
|
||||||
|
|
||||||
char *clipboardText;
|
char *clipboardText;
|
||||||
@ -291,14 +306,6 @@ typedef struct {
|
|||||||
DWORD clear;
|
DWORD clear;
|
||||||
} FlagsOp;
|
} FlagsOp;
|
||||||
|
|
||||||
// Monitor info type
|
|
||||||
typedef struct {
|
|
||||||
HMONITOR needle;
|
|
||||||
int index;
|
|
||||||
int matchIndex;
|
|
||||||
RECT rect;
|
|
||||||
} MonitorInfo;
|
|
||||||
|
|
||||||
//----------------------------------------------------------------------------------
|
//----------------------------------------------------------------------------------
|
||||||
// Global Const Variables Definition
|
// Global Const Variables Definition
|
||||||
//----------------------------------------------------------------------------------
|
//----------------------------------------------------------------------------------
|
||||||
@ -468,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
|
// GetDpiForWindow with a fallback for older versions of Windows
|
||||||
static UINT GetDpiForWindowCompat(HWND hwnd)
|
static UINT GetDpiForWindowCompat(HWND hwnd)
|
||||||
{
|
{
|
||||||
@ -888,37 +912,6 @@ static HICON ConvertImageToWindowsIcon(Image image)
|
|||||||
return result;
|
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
|
// Get style changed required operations flags
|
||||||
// NOTE: Required for deferred operations
|
// NOTE: Required for deferred operations
|
||||||
static void GetStyleChangeFlagOps(DWORD coreWindowFlags, STYLESTRUCT *style, FlagsOp *deferredFlags)
|
static void GetStyleChangeFlagOps(DWORD coreWindowFlags, STYLESTRUCT *style, FlagsOp *deferredFlags)
|
||||||
@ -1165,22 +1158,55 @@ void SetWindowPosition(int x, int y)
|
|||||||
{
|
{
|
||||||
if (platform.hwnd != NULL)
|
if (platform.hwnd != NULL)
|
||||||
{
|
{
|
||||||
RECT rect = { 0 };
|
RECT rect = { x, y, x, y };
|
||||||
if (GetWindowRect(platform.hwnd, &rect))
|
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);
|
||||||
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);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// Set monitor for the current window
|
// Place window on a given monitor
|
||||||
void SetWindowMonitor(int 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)
|
// Set window minimum dimensions (FLAG_WINDOW_RESIZABLE)
|
||||||
@ -1244,87 +1270,190 @@ void *GetWindowHandle(void)
|
|||||||
return (void *)platform.hwnd;
|
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 GetMonitorCount(void)
|
||||||
{
|
{
|
||||||
int count = 0;
|
return platform.monitorCount;
|
||||||
|
|
||||||
int result = EnumDisplayMonitors(NULL, NULL, CountMonitorsProc, (LPARAM)&count);
|
|
||||||
if (result == 0) TRACELOG(LOG_ERROR, "%s failed, error=%lu", "EnumDisplayMonitors", GetLastError());
|
|
||||||
|
|
||||||
return count;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// Get current monitor where window is placed
|
// Get current monitor where window is placed
|
||||||
int GetCurrentMonitor(void)
|
int GetCurrentMonitor(void)
|
||||||
{
|
{
|
||||||
HMONITOR monitor = MonitorFromWindow(platform.hwnd, MONITOR_DEFAULTTOPRIMARY);
|
return platform.currentMonitor;
|
||||||
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;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// Get selected monitor position
|
// Get selected monitor position
|
||||||
Vector2 GetMonitorPosition(int monitor)
|
Vector2 GetMonitorPosition(int monitor)
|
||||||
{
|
{
|
||||||
TRACELOG(LOG_WARNING, "GetMonitorPosition not implemented");
|
Vector2 position = { 0 };
|
||||||
return (Vector2){ 0, 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)
|
// Get selected monitor width (currently used by monitor)
|
||||||
int GetMonitorWidth(int monitor)
|
int GetMonitorWidth(int monitor)
|
||||||
{
|
{
|
||||||
//TRACELOG(LOG_WARNING, "GetMonitorWidth not implemented");
|
int width = 0;
|
||||||
return 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)
|
// Get selected monitor height (currently used by monitor)
|
||||||
int GetMonitorHeight(int monitor)
|
int GetMonitorHeight(int monitor)
|
||||||
{
|
{
|
||||||
//TRACELOG(LOG_WARNING, "GetMonitorHeight not implemented");
|
int height = 0;
|
||||||
return 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
|
// Get selected monitor physical width in millimetres
|
||||||
int GetMonitorPhysicalWidth(int monitor)
|
int GetMonitorPhysicalWidth(int monitor)
|
||||||
{
|
{
|
||||||
TRACELOG(LOG_WARNING, "GetMonitorPhysicalWidth not implemented");
|
int physicalWidth = 0;
|
||||||
return 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
|
// Get selected monitor physical height in millimetres
|
||||||
int GetMonitorPhysicalHeight(int monitor)
|
int GetMonitorPhysicalHeight(int monitor)
|
||||||
{
|
{
|
||||||
TRACELOG(LOG_WARNING, "GetMonitorPhysicalHeight not implemented");
|
int physicalHeight = 0;
|
||||||
return 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
|
// Get selected monitor refresh rate
|
||||||
int GetMonitorRefreshRate(int monitor)
|
int GetMonitorRefreshRate(int monitor)
|
||||||
{
|
{
|
||||||
TRACELOG(LOG_WARNING, "GetMonitorRefreshRate not implemented");
|
int refreshRate = 0;
|
||||||
return 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
|
// Get the human-readable, UTF-8 encoded name of the selected monitor
|
||||||
const char *GetMonitorName(int monitor)
|
const char *GetMonitorName(int monitor)
|
||||||
{
|
{
|
||||||
TRACELOG(LOG_WARNING, "GetMonitorName not implemented");
|
const char *name = NULL;
|
||||||
return 0;
|
|
||||||
|
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
|
// Get window position XY on monitor
|
||||||
Vector2 GetWindowPosition(void)
|
Vector2 GetWindowPosition(void)
|
||||||
{
|
{
|
||||||
//TRACELOG(LOG_WARNING, "GetWindowPosition not implemented");
|
return (Vector2){ (float)CORE.Window.position.x, (float)CORE.Window.position.y };
|
||||||
return (Vector2){ 0, 0 };
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// Get window scale DPI factor for current monitor
|
// Get window scale DPI factor for current monitor
|
||||||
@ -1485,7 +1614,11 @@ Image GetClipboardImage(void)
|
|||||||
{
|
{
|
||||||
Image image = { 0 };
|
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;
|
unsigned int dataSize = 0;
|
||||||
void *fileData = NULL;
|
void *fileData = NULL;
|
||||||
int width = 0;
|
int width = 0;
|
||||||
@ -1496,12 +1629,10 @@ Image GetClipboardImage(void)
|
|||||||
if (fileData == NULL) TRACELOG(LOG_WARNING, "Clipboard image: Couldn't get clipboard data.");
|
if (fileData == NULL) TRACELOG(LOG_WARNING, "Clipboard image: Couldn't get clipboard data.");
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
|
// TODO: Support additional image file-formats
|
||||||
image = LoadImageFromMemory(".bmp", (const unsigned char*)fileData, (int)dataSize);
|
image = LoadImageFromMemory(".bmp", (const unsigned char*)fileData, (int)dataSize);
|
||||||
RL_FREE(fileData);
|
RL_FREE(fileData);
|
||||||
}
|
}
|
||||||
#else
|
|
||||||
TRACELOG(LOG_WARNING, "Clipboard image: SUPPORT_CLIPBOARD_IMAGE requires SUPPORT_MODULE_RTEXTURES to work properly");
|
|
||||||
#endif
|
|
||||||
|
|
||||||
return image;
|
return image;
|
||||||
}
|
}
|
||||||
@ -1724,7 +1855,7 @@ void PollInputEvents(void)
|
|||||||
// Reset touch positions
|
// Reset touch positions
|
||||||
// TODO: It resets on target platform the mouse position and not filled again until a move-event,
|
// 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!
|
// 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));
|
memcpy(CORE.Input.Keyboard.previousKeyState, CORE.Input.Keyboard.currentKeyState, sizeof(CORE.Input.Keyboard.previousKeyState));
|
||||||
|
|
||||||
@ -2013,24 +2144,6 @@ int InitPlatform(void)
|
|||||||
result = (int)RegisterClassExW(&windowClass);
|
result = (int)RegisterClassExW(&windowClass);
|
||||||
if (result == 0) TRACELOG(LOG_ERROR, "WIN32: Failed to register window class [ERROR: %lu]", GetLastError());
|
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
|
// Create window
|
||||||
// NOTE: Title string needs to be converted to WCHAR
|
// NOTE: Title string needs to be converted to WCHAR
|
||||||
WCHAR *titleWide = NULL;
|
WCHAR *titleWide = NULL;
|
||||||
@ -2083,7 +2196,19 @@ int InitPlatform(void)
|
|||||||
int windowWidth = rect.right - rect.left;
|
int windowWidth = rect.right - rect.left;
|
||||||
int windowHeight = rect.bottom - rect.top;
|
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 monitorInfo = { 0 };
|
||||||
monitorInfo.cbSize = sizeof(monitorInfo);
|
monitorInfo.cbSize = sizeof(monitorInfo);
|
||||||
if (GetMonitorInfoW(currentMonitor, &monitorInfo))
|
if (GetMonitorInfoW(currentMonitor, &monitorInfo))
|
||||||
@ -2103,6 +2228,7 @@ int InitPlatform(void)
|
|||||||
SetWindowPos(platform.hwnd, NULL, x, y, windowWidth, windowHeight, SWP_NOZORDER | SWP_NOACTIVATE);
|
SetWindowPos(platform.hwnd, NULL, x, y, windowWidth, windowHeight, SWP_NOZORDER | SWP_NOACTIVATE);
|
||||||
}
|
}
|
||||||
else TRACELOG(LOG_WARNING, "DISPLAY: Unable to retrieve information about monitor");
|
else TRACELOG(LOG_WARNING, "DISPLAY: Unable to retrieve information about monitor");
|
||||||
|
}
|
||||||
|
|
||||||
if ((platform.desiredFlags & FLAG_WINDOW_HIDDEN) == 0)
|
if ((platform.desiredFlags & FLAG_WINDOW_HIDDEN) == 0)
|
||||||
{
|
{
|
||||||
@ -2207,6 +2333,18 @@ void ClosePlatform(void)
|
|||||||
shcore = NULL;
|
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
|
#if SUPPORT_WINMM_HIGHRES_TIMER && !SUPPORT_BUSY_WAIT_LOOP
|
||||||
timeEndPeriod(1); // Restore time period
|
timeEndPeriod(1); // Restore time period
|
||||||
#endif
|
#endif
|
||||||
@ -2301,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,
|
// in response to WM_WINDOWPOSCHANGED but looks like when a window is created,
|
||||||
// this message can be obtained without getting WM_WINDOWPOSCHANGED
|
// this message can be obtained without getting WM_WINDOWPOSCHANGED
|
||||||
HandleWindowResize(hwnd, &platform.appScreenWidth, &platform.appScreenHeight);
|
HandleWindowResize(hwnd, &platform.appScreenWidth, &platform.appScreenHeight);
|
||||||
|
platform.currentMonitor = GetMonitorIndexFromHWND(hwnd);
|
||||||
result = 0; // If an application processes WM_SIZE message, it should return zero
|
result = 0; // If an application processes WM_SIZE message, it should return zero
|
||||||
} break;
|
} break;
|
||||||
case WM_GETMINMAXINFO:
|
case WM_GETMINMAXINFO:
|
||||||
@ -2403,13 +2542,19 @@ static LRESULT CALLBACK WndProc(HWND hwnd, UINT msg, WPARAM wparam, LPARAM lpara
|
|||||||
default: break;
|
default: break;
|
||||||
}
|
}
|
||||||
} 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:
|
case WM_WINDOWPOSCHANGED:
|
||||||
{
|
{
|
||||||
WINDOWPOS *pos = (WINDOWPOS*)lparam;
|
WINDOWPOS *pos = (WINDOWPOS*)lparam;
|
||||||
if (!(pos->flags & SWP_NOSIZE)) HandleWindowResize(hwnd, &platform.appScreenWidth, &platform.appScreenHeight);
|
if (!(pos->flags & SWP_NOSIZE)) HandleWindowResize(hwnd, &platform.appScreenWidth, &platform.appScreenHeight);
|
||||||
|
|
||||||
DefWindowProc(hwnd, msg, wparam, lparam);
|
DefWindowProcW(hwnd, msg, wparam, lparam);
|
||||||
} break;
|
} break;
|
||||||
case WM_GETDPISCALEDSIZE:
|
case WM_GETDPISCALEDSIZE:
|
||||||
{
|
{
|
||||||
@ -2478,6 +2623,26 @@ static LRESULT CALLBACK WndProc(HWND hwnd, UINT msg, WPARAM wparam, LPARAM lpara
|
|||||||
HandleWindowResize(hwnd, &platform.appScreenWidth, &platform.appScreenHeight);
|
HandleWindowResize(hwnd, &platform.appScreenWidth, &platform.appScreenHeight);
|
||||||
|
|
||||||
} break;
|
} 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:
|
case WM_SETCURSOR:
|
||||||
{
|
{
|
||||||
// Called when mouse moves, enters/leaves window...
|
// Called when mouse moves, enters/leaves window...
|
||||||
@ -2487,7 +2652,7 @@ static LRESULT CALLBACK WndProc(HWND hwnd, UINT msg, WPARAM wparam, LPARAM lpara
|
|||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
result = DefWindowProc(hwnd, msg, wparam, lparam);
|
result = DefWindowProcW(hwnd, msg, wparam, lparam);
|
||||||
} break;
|
} break;
|
||||||
case WM_PAINT:
|
case WM_PAINT:
|
||||||
{
|
{
|
||||||
@ -2513,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.x = (float)GET_X_LPARAM(lparam);
|
||||||
CORE.Input.Mouse.currentPosition.y = (float)GET_Y_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;
|
} break;
|
||||||
case WM_SYSKEYDOWN:
|
case WM_SYSKEYDOWN:
|
||||||
|
|||||||
@ -21,7 +21,6 @@
|
|||||||
*
|
*
|
||||||
* DEPENDENCIES:
|
* DEPENDENCIES:
|
||||||
* - DRM and GLM: System libraries for display initialization and configuration
|
* - 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
|
* LICENSE: zlib/libpng
|
||||||
@ -570,7 +569,7 @@ Image GetClipboardImage(void)
|
|||||||
{
|
{
|
||||||
Image image = { 0 };
|
Image image = { 0 };
|
||||||
|
|
||||||
TRACELOG(LOG_WARNING, "GetClipboardImage() not implemented on target platform");
|
TRACELOG(LOG_WARNING, "Clipboard image retrieving not implemented");
|
||||||
|
|
||||||
return image;
|
return image;
|
||||||
}
|
}
|
||||||
@ -1088,12 +1087,6 @@ const char *GetKeyName(int key)
|
|||||||
// Register all input events
|
// Register all input events
|
||||||
void PollInputEvents(void)
|
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
|
// Reset keys/chars pressed registered
|
||||||
CORE.Input.Keyboard.keyPressedQueueCount = 0;
|
CORE.Input.Keyboard.keyPressedQueueCount = 0;
|
||||||
CORE.Input.Keyboard.charPressedQueueCount = 0;
|
CORE.Input.Keyboard.charPressedQueueCount = 0;
|
||||||
@ -1145,7 +1138,7 @@ void PollInputEvents(void)
|
|||||||
|
|
||||||
// Map touch position to mouse position for convenience
|
// Map touch position to mouse position for convenience
|
||||||
// NOTE: For DRM touchscreen devices, this mapping is disabled to avoid false touch detection
|
// 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
|
// Handle the mouse/touch/gestures events
|
||||||
PollMouseEvents();
|
PollMouseEvents();
|
||||||
@ -1956,8 +1949,8 @@ static void InitEvdevInput(void)
|
|||||||
// Reset variables
|
// Reset variables
|
||||||
for (int i = 0; i < MAX_TOUCH_POINTS; i++)
|
for (int i = 0; i < MAX_TOUCH_POINTS; i++)
|
||||||
{
|
{
|
||||||
CORE.Input.Touch.position[i].x = -1;
|
CORE.Input.Touch.currentPosition[i].x = -1;
|
||||||
CORE.Input.Touch.position[i].y = -1;
|
CORE.Input.Touch.currentPosition[i].y = -1;
|
||||||
platform.touchActive[i] = false;
|
platform.touchActive[i] = false;
|
||||||
platform.touchPosition[i].x = -1;
|
platform.touchPosition[i].x = -1;
|
||||||
platform.touchPosition[i].y = -1;
|
platform.touchPosition[i].y = -1;
|
||||||
@ -2337,7 +2330,7 @@ static void PollMouseEvents(void)
|
|||||||
if (fd == -1) return;
|
if (fd == -1) return;
|
||||||
|
|
||||||
struct input_event event = { 0 };
|
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
|
static bool isMultitouch = false; // Detect if device supports MT events
|
||||||
|
|
||||||
// Try to read data from the mouse/touch/gesture and only continue if successful
|
// Try to read data from the mouse/touch/gesture and only continue if successful
|
||||||
@ -2356,7 +2349,7 @@ static void PollMouseEvents(void)
|
|||||||
else CORE.Input.Mouse.currentPosition.x += event.value;
|
else CORE.Input.Mouse.currentPosition.x += event.value;
|
||||||
|
|
||||||
// NOTE: For DRM touchscreen, do not simulate touch from mouse movement
|
// 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
|
touchAction = 2; // TOUCH_ACTION_MOVE
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -2370,7 +2363,7 @@ static void PollMouseEvents(void)
|
|||||||
else CORE.Input.Mouse.currentPosition.y += event.value;
|
else CORE.Input.Mouse.currentPosition.y += event.value;
|
||||||
|
|
||||||
// NOTE: For DRM touchscreen, do not simulate touch from mouse movement
|
// 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
|
touchAction = 2; // TOUCH_ACTION_MOVE
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -2575,7 +2568,7 @@ static void PollMouseEvents(void)
|
|||||||
{
|
{
|
||||||
if (platform.touchActive[i])
|
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];
|
CORE.Input.Touch.pointId[k] = platform.touchId[i];
|
||||||
k++;
|
k++;
|
||||||
}
|
}
|
||||||
@ -2586,8 +2579,8 @@ static void PollMouseEvents(void)
|
|||||||
// Clear remaining slots
|
// Clear remaining slots
|
||||||
for (int i = k; i < MAX_TOUCH_POINTS; i++)
|
for (int i = k; i < MAX_TOUCH_POINTS; i++)
|
||||||
{
|
{
|
||||||
CORE.Input.Touch.position[i].x = -1;
|
CORE.Input.Touch.currentPosition[i].x = -1;
|
||||||
CORE.Input.Touch.position[i].y = -1;
|
CORE.Input.Touch.currentPosition[i].y = -1;
|
||||||
CORE.Input.Touch.pointId[i] = -1;
|
CORE.Input.Touch.pointId[i] = -1;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -2601,7 +2594,7 @@ static void PollMouseEvents(void)
|
|||||||
for (int i = 0; i < MAX_TOUCH_POINTS; i++)
|
for (int i = 0; i < MAX_TOUCH_POINTS; i++)
|
||||||
{
|
{
|
||||||
gestureEvent.pointId[i] = i;
|
gestureEvent.pointId[i] = i;
|
||||||
gestureEvent.position[i] = CORE.Input.Touch.position[i];
|
gestureEvent.position[i] = CORE.Input.Touch.currentPosition[i];
|
||||||
}
|
}
|
||||||
|
|
||||||
ProcessGestureEvent(gestureEvent);
|
ProcessGestureEvent(gestureEvent);
|
||||||
|
|||||||
@ -19,7 +19,6 @@
|
|||||||
*
|
*
|
||||||
* DEPENDENCIES:
|
* DEPENDENCIES:
|
||||||
* - rlsw: Software renderer
|
* - rlsw: Software renderer
|
||||||
* - gestures: Gestures system for touch-ready devices (or simulated from mouse inputs)
|
|
||||||
*
|
*
|
||||||
*
|
*
|
||||||
* LICENSE: zlib/libpng
|
* LICENSE: zlib/libpng
|
||||||
@ -323,7 +322,7 @@ Image GetClipboardImage(void)
|
|||||||
{
|
{
|
||||||
Image image = { 0 };
|
Image image = { 0 };
|
||||||
|
|
||||||
TRACELOG(LOG_WARNING, "GetClipboardImage() not implemented on target platform");
|
TRACELOG(LOG_WARNING, "Clipboard image retrieving not implemented");
|
||||||
|
|
||||||
return image;
|
return image;
|
||||||
}
|
}
|
||||||
@ -448,12 +447,6 @@ const char *GetKeyName(int key)
|
|||||||
// Register all input events
|
// Register all input events
|
||||||
void PollInputEvents(void)
|
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
|
// Reset keys/chars pressed registered
|
||||||
CORE.Input.Keyboard.keyPressedQueueCount = 0;
|
CORE.Input.Keyboard.keyPressedQueueCount = 0;
|
||||||
CORE.Input.Keyboard.charPressedQueueCount = 0;
|
CORE.Input.Keyboard.charPressedQueueCount = 0;
|
||||||
@ -471,7 +464,7 @@ void PollInputEvents(void)
|
|||||||
// Reset touch positions
|
// Reset touch positions
|
||||||
// TODO: It resets on target platform the mouse position and not filled again until a move-event,
|
// 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!
|
// 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
|
// Register previous keys states
|
||||||
// NOTE: Android supports up to 260 keys
|
// NOTE: Android supports up to 260 keys
|
||||||
|
|||||||
@ -22,7 +22,6 @@
|
|||||||
*
|
*
|
||||||
* DEPENDENCIES:
|
* DEPENDENCIES:
|
||||||
* - <platform-specific SDK dependency>
|
* - <platform-specific SDK dependency>
|
||||||
* - gestures: Gestures system for touch-ready devices (or simulated from mouse inputs)
|
|
||||||
*
|
*
|
||||||
*
|
*
|
||||||
* LICENSE: zlib/libpng
|
* LICENSE: zlib/libpng
|
||||||
@ -302,7 +301,7 @@ Image GetClipboardImage(void)
|
|||||||
{
|
{
|
||||||
Image image = { 0 };
|
Image image = { 0 };
|
||||||
|
|
||||||
TRACELOG(LOG_WARNING, "GetClipboardImage() not implemented on target platform");
|
TRACELOG(LOG_WARNING, "Clipboard image retrieving not implemented");
|
||||||
|
|
||||||
return image;
|
return image;
|
||||||
}
|
}
|
||||||
@ -423,12 +422,6 @@ const char *GetKeyName(int key)
|
|||||||
// Register all input events
|
// Register all input events
|
||||||
void PollInputEvents(void)
|
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
|
// Reset keys/chars pressed registered
|
||||||
CORE.Input.Keyboard.keyPressedQueueCount = 0;
|
CORE.Input.Keyboard.keyPressedQueueCount = 0;
|
||||||
CORE.Input.Keyboard.charPressedQueueCount = 0;
|
CORE.Input.Keyboard.charPressedQueueCount = 0;
|
||||||
@ -446,7 +439,7 @@ void PollInputEvents(void)
|
|||||||
// Reset touch positions
|
// Reset touch positions
|
||||||
// TODO: It resets on target platform the mouse position and not filled again until a move-event,
|
// 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!
|
// 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
|
// Register previous keys states
|
||||||
// NOTE: Android supports up to 260 keys
|
// NOTE: Android supports up to 260 keys
|
||||||
|
|||||||
@ -17,8 +17,8 @@
|
|||||||
* Custom flag for rcore on target platform -not used-
|
* Custom flag for rcore on target platform -not used-
|
||||||
*
|
*
|
||||||
* DEPENDENCIES:
|
* DEPENDENCIES:
|
||||||
* - emscripten: Allow interaction between browser API and C
|
* - Emscripten SDK: Allow interaction between browser API and C
|
||||||
* - gestures: Gestures system for touch-ready devices (or simulated from mouse inputs)
|
* - libglfw.js: GLFW implementation over Emscripten SDK
|
||||||
*
|
*
|
||||||
*
|
*
|
||||||
* LICENSE: zlib/libpng
|
* LICENSE: zlib/libpng
|
||||||
@ -901,11 +901,16 @@ bool SetClipboardImage(Image image)
|
|||||||
Image GetClipboardImage(void)
|
Image GetClipboardImage(void)
|
||||||
{
|
{
|
||||||
Image image = { 0 };
|
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();
|
RequestClipboardData();
|
||||||
|
|
||||||
|
int width = 0;
|
||||||
|
int height = 0;
|
||||||
unsigned char *data = GetLastPastedImage(&width, &height);
|
unsigned char *data = GetLastPastedImage(&width, &height);
|
||||||
|
|
||||||
if (data != NULL)
|
if (data != NULL)
|
||||||
@ -1094,12 +1099,6 @@ const char *GetKeyName(int key)
|
|||||||
// Register all input events
|
// Register all input events
|
||||||
void PollInputEvents(void)
|
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
|
// Reset keys/chars pressed registered
|
||||||
CORE.Input.Keyboard.keyPressedQueueCount = 0;
|
CORE.Input.Keyboard.keyPressedQueueCount = 0;
|
||||||
CORE.Input.Keyboard.charPressedQueueCount = 0;
|
CORE.Input.Keyboard.charPressedQueueCount = 0;
|
||||||
@ -1133,7 +1132,7 @@ void PollInputEvents(void)
|
|||||||
// Reset touch positions
|
// Reset touch positions
|
||||||
// TODO: It resets on target platform the mouse position and not filled again until a move-event,
|
// 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!
|
// 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
|
// Gamepad support using emscripten API
|
||||||
// NOTE: GLFW3 joystick functionality not available in web
|
// NOTE: GLFW3 joystick functionality not available in web
|
||||||
@ -1676,35 +1675,6 @@ static void MouseButtonCallback(GLFWwindow *window, int button, int action, int
|
|||||||
// but future releases may add more actions (i.e. GLFW_REPEAT)
|
// but future releases may add more actions (i.e. GLFW_REPEAT)
|
||||||
CORE.Input.Mouse.currentButtonState[button] = action;
|
CORE.Input.Mouse.currentButtonState[button] = action;
|
||||||
CORE.Input.Touch.currentTouchState[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
|
// GLFW3: Called on mouse move
|
||||||
@ -1715,31 +1685,8 @@ static void MouseMoveCallback(GLFWwindow *window, double x, double y)
|
|||||||
{
|
{
|
||||||
CORE.Input.Mouse.currentPosition.x = (float)x;
|
CORE.Input.Mouse.currentPosition.x = (float)x;
|
||||||
CORE.Input.Mouse.currentPosition.y = (float)y;
|
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
|
// GLFW3: Called on mouse wheel scrolling
|
||||||
@ -1844,11 +1791,11 @@ static EM_BOOL EmscriptenTouchCallback(int eventType, const EmscriptenTouchEvent
|
|||||||
CORE.Input.Touch.pointId[i] = touchEvent->touches[i].identifier;
|
CORE.Input.Touch.pointId[i] = touchEvent->touches[i].identifier;
|
||||||
|
|
||||||
// Register touch points position
|
// 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
|
// 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.currentPosition[i].x *= ((float)GetScreenWidth()/(float)canvasWidth);
|
||||||
CORE.Input.Touch.position[i].y *= ((float)GetScreenHeight()/(float)canvasHeight);
|
CORE.Input.Touch.currentPosition[i].y *= ((float)GetScreenHeight()/(float)canvasHeight);
|
||||||
|
|
||||||
if (eventType == EMSCRIPTEN_EVENT_TOUCHSTART) CORE.Input.Touch.currentTouchState[i] = 1;
|
if (eventType == EMSCRIPTEN_EVENT_TOUCHSTART) CORE.Input.Touch.currentTouchState[i] = 1;
|
||||||
else if (eventType == EMSCRIPTEN_EVENT_TOUCHEND) CORE.Input.Touch.currentTouchState[i] = 0;
|
else if (eventType == EMSCRIPTEN_EVENT_TOUCHEND) CORE.Input.Touch.currentTouchState[i] = 0;
|
||||||
@ -1857,34 +1804,10 @@ static EM_BOOL EmscriptenTouchCallback(int eventType, const EmscriptenTouchEvent
|
|||||||
// Update mouse position when single touch detected
|
// Update mouse position when single touch detected
|
||||||
if (CORE.Input.Touch.pointCount == 1)
|
if (CORE.Input.Touch.pointCount == 1)
|
||||||
{
|
{
|
||||||
CORE.Input.Mouse.currentPosition.x = CORE.Input.Touch.position[0].x;
|
CORE.Input.Mouse.currentPosition.x = CORE.Input.Touch.currentPosition[0].x;
|
||||||
CORE.Input.Mouse.currentPosition.y = CORE.Input.Touch.position[0].y;
|
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)
|
if (eventType == EMSCRIPTEN_EVENT_TOUCHEND)
|
||||||
{
|
{
|
||||||
// Identify the EMSCRIPTEN_EVENT_TOUCHEND and remove it from the list
|
// Identify the EMSCRIPTEN_EVENT_TOUCHEND and remove it from the list
|
||||||
@ -1896,7 +1819,7 @@ static EM_BOOL EmscriptenTouchCallback(int eventType, const EmscriptenTouchEvent
|
|||||||
for (int j = i; j < CORE.Input.Touch.pointCount - 1; j++)
|
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.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
|
// Decrease touch points count to remove the last one
|
||||||
CORE.Input.Touch.pointCount--;
|
CORE.Input.Touch.pointCount--;
|
||||||
|
|||||||
@ -16,8 +16,7 @@
|
|||||||
* Custom flag for rcore on target platform -not used-
|
* Custom flag for rcore on target platform -not used-
|
||||||
*
|
*
|
||||||
* DEPENDENCIES:
|
* DEPENDENCIES:
|
||||||
* - emscripten: Allow interaction between browser API and C
|
* - Emscripten SDK: Allow interaction between browser API and C
|
||||||
* - gestures: Gestures system for touch-ready devices (or simulated from mouse inputs)
|
|
||||||
*
|
*
|
||||||
*
|
*
|
||||||
* LICENSE: zlib/libpng
|
* LICENSE: zlib/libpng
|
||||||
@ -864,12 +863,15 @@ EM_ASYNC_JS(void, RequestClipboardData, (void), {
|
|||||||
EM_JS(char *, GetLastPastedText, (void), {
|
EM_JS(char *, GetLastPastedText, (void), {
|
||||||
var str = window._lastClipboardString || "";
|
var str = window._lastClipboardString || "";
|
||||||
var length = lengthBytesUTF8(str) + 1;
|
var length = lengthBytesUTF8(str) + 1;
|
||||||
|
|
||||||
if (length > 1)
|
if (length > 1)
|
||||||
{
|
{
|
||||||
var ptr = _malloc(length);
|
var ptr = _malloc(length);
|
||||||
stringToUTF8(str, ptr, length);
|
stringToUTF8(str, ptr, length);
|
||||||
|
|
||||||
return ptr;
|
return ptr;
|
||||||
}
|
}
|
||||||
|
|
||||||
return 0;
|
return 0;
|
||||||
});
|
});
|
||||||
|
|
||||||
@ -921,10 +923,16 @@ bool SetClipboardImage(Image image)
|
|||||||
Image GetClipboardImage(void)
|
Image GetClipboardImage(void)
|
||||||
{
|
{
|
||||||
Image image = { 0 };
|
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();
|
RequestClipboardData();
|
||||||
|
|
||||||
|
int width = 0;
|
||||||
|
int height = 0;
|
||||||
unsigned char *data = GetLastPastedImage(&width, &height);
|
unsigned char *data = GetLastPastedImage(&width, &height);
|
||||||
|
|
||||||
if (data != NULL)
|
if (data != NULL)
|
||||||
@ -1111,12 +1119,6 @@ const char *GetKeyName(int key)
|
|||||||
// Register all input events
|
// Register all input events
|
||||||
void PollInputEvents(void)
|
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
|
// Reset keys/chars pressed registered
|
||||||
CORE.Input.Keyboard.keyPressedQueueCount = 0;
|
CORE.Input.Keyboard.keyPressedQueueCount = 0;
|
||||||
CORE.Input.Keyboard.charPressedQueueCount = 0;
|
CORE.Input.Keyboard.charPressedQueueCount = 0;
|
||||||
@ -1150,7 +1152,7 @@ void PollInputEvents(void)
|
|||||||
// Reset touch positions
|
// Reset touch positions
|
||||||
// TODO: It resets on target platform the mouse position and not filled again until a move-event,
|
// 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!
|
// 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
|
// Get number of gamepads connected
|
||||||
int numGamepads = 0;
|
int numGamepads = 0;
|
||||||
@ -1627,34 +1629,6 @@ static EM_BOOL EmscriptenMouseCallback(int eventType, const EmscriptenMouseEvent
|
|||||||
default: break;
|
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
|
// Don't prevent default to allow focusing on canvas
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
@ -1683,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.x = normalizedX*(float)CORE.Window.screen.width;
|
||||||
CORE.Input.Mouse.currentPosition.y = normalizedY*(float)CORE.Window.screen.height;
|
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
|
return 1; // The event was consumed by the callback handler
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -1785,11 +1736,11 @@ static EM_BOOL EmscriptenTouchCallback(int eventType, const EmscriptenTouchEvent
|
|||||||
CORE.Input.Touch.pointId[i] = touchEvent->touches[i].identifier;
|
CORE.Input.Touch.pointId[i] = touchEvent->touches[i].identifier;
|
||||||
|
|
||||||
// Register touch points position
|
// 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
|
// 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.currentPosition[i].x *= ((float)GetScreenWidth()/(float)canvasWidth);
|
||||||
CORE.Input.Touch.position[i].y *= ((float)GetScreenHeight()/(float)canvasHeight);
|
CORE.Input.Touch.currentPosition[i].y *= ((float)GetScreenHeight()/(float)canvasHeight);
|
||||||
|
|
||||||
if (eventType == EMSCRIPTEN_EVENT_TOUCHSTART) CORE.Input.Touch.currentTouchState[i] = 1;
|
if (eventType == EMSCRIPTEN_EVENT_TOUCHSTART) CORE.Input.Touch.currentTouchState[i] = 1;
|
||||||
else if (eventType == EMSCRIPTEN_EVENT_TOUCHEND) CORE.Input.Touch.currentTouchState[i] = 0;
|
else if (eventType == EMSCRIPTEN_EVENT_TOUCHEND) CORE.Input.Touch.currentTouchState[i] = 0;
|
||||||
@ -1798,34 +1749,10 @@ static EM_BOOL EmscriptenTouchCallback(int eventType, const EmscriptenTouchEvent
|
|||||||
// Update mouse position if a single touch is detected
|
// Update mouse position if a single touch is detected
|
||||||
if (CORE.Input.Touch.pointCount == 1)
|
if (CORE.Input.Touch.pointCount == 1)
|
||||||
{
|
{
|
||||||
CORE.Input.Mouse.currentPosition.x = CORE.Input.Touch.position[0].x;
|
CORE.Input.Mouse.currentPosition.x = CORE.Input.Touch.currentPosition[0].x;
|
||||||
CORE.Input.Mouse.currentPosition.y = CORE.Input.Touch.position[0].y;
|
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)
|
if (eventType == EMSCRIPTEN_EVENT_TOUCHEND)
|
||||||
{
|
{
|
||||||
// Identify the EMSCRIPTEN_EVENT_TOUCHEND and remove it from the list
|
// Identify the EMSCRIPTEN_EVENT_TOUCHEND and remove it from the list
|
||||||
@ -1837,8 +1764,9 @@ static EM_BOOL EmscriptenTouchCallback(int eventType, const EmscriptenTouchEvent
|
|||||||
for (int j = i; j < CORE.Input.Touch.pointCount - 1; j++)
|
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.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
|
// Decrease touch points count to remove the last one
|
||||||
CORE.Input.Touch.pointCount--;
|
CORE.Input.Touch.pointCount--;
|
||||||
break;
|
break;
|
||||||
|
|||||||
104
src/rcore.c
104
src/rcore.c
@ -42,9 +42,6 @@
|
|||||||
* #define SUPPORT_GESTURES_SYSTEM 1
|
* #define SUPPORT_GESTURES_SYSTEM 1
|
||||||
* Gestures module is included (rgestures.h) to support gestures detection: tap, hold, swipe, drag
|
* 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
|
* #define SUPPORT_BUSY_WAIT_LOOP 1
|
||||||
* Use busy wait loop for timing sync, if not defined, a high-resolution timer is setup and used
|
* 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)
|
char **dropFilepaths; // Store dropped files paths pointers (provided by GLFW)
|
||||||
unsigned int dropFileCount; // Count dropped files strings
|
unsigned int dropFileCount; // Count dropped files strings
|
||||||
|
|
||||||
} Window;
|
} Window;
|
||||||
struct {
|
struct {
|
||||||
const char *basePath; // Base path for data storage
|
const char *basePath; // Base path for data storage
|
||||||
|
|
||||||
} Storage;
|
} Storage;
|
||||||
struct {
|
struct {
|
||||||
struct {
|
struct {
|
||||||
@ -343,7 +338,6 @@ typedef struct CoreData {
|
|||||||
|
|
||||||
int charPressedQueue[MAX_CHAR_PRESSED_QUEUE]; // Input characters queue (unicode)
|
int charPressedQueue[MAX_CHAR_PRESSED_QUEUE]; // Input characters queue (unicode)
|
||||||
int charPressedQueueCount; // Input characters queue count
|
int charPressedQueueCount; // Input characters queue count
|
||||||
|
|
||||||
} Keyboard;
|
} Keyboard;
|
||||||
struct {
|
struct {
|
||||||
Vector2 offset; // Mouse offset
|
Vector2 offset; // Mouse offset
|
||||||
@ -361,16 +355,14 @@ typedef struct CoreData {
|
|||||||
char previousButtonState[MAX_MOUSE_BUTTONS]; // Registers previous mouse button state
|
char previousButtonState[MAX_MOUSE_BUTTONS]; // Registers previous mouse button state
|
||||||
Vector2 currentWheelMove; // Registers current mouse wheel variation
|
Vector2 currentWheelMove; // Registers current mouse wheel variation
|
||||||
Vector2 previousWheelMove; // Registers previous mouse wheel variation
|
Vector2 previousWheelMove; // Registers previous mouse wheel variation
|
||||||
|
|
||||||
} Mouse;
|
} Mouse;
|
||||||
struct {
|
struct Touch {
|
||||||
int pointCount; // Number of touch points active
|
int pointCount; // Number of touch points active
|
||||||
int pointId[MAX_TOUCH_POINTS]; // Point identifiers
|
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
|
Vector2 previousPosition[MAX_TOUCH_POINTS]; // Previous touch position on screen
|
||||||
char currentTouchState[MAX_TOUCH_POINTS]; // Registers current 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
|
char previousTouchState[MAX_TOUCH_POINTS]; // Registers previous touch state: 0-UP, 1-DOWN, 2-MOVE, 3-CANCEL
|
||||||
|
|
||||||
} Touch;
|
} Touch;
|
||||||
struct {
|
struct {
|
||||||
int lastButtonPressed; // Register last gamepad button pressed
|
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 currentButtonState[MAX_GAMEPADS][MAX_GAMEPAD_BUTTONS]; // Current gamepad buttons state
|
||||||
char previousButtonState[MAX_GAMEPADS][MAX_GAMEPAD_BUTTONS]; // Previous gamepad buttons state
|
char previousButtonState[MAX_GAMEPADS][MAX_GAMEPAD_BUTTONS]; // Previous gamepad buttons state
|
||||||
float axisState[MAX_GAMEPADS][MAX_GAMEPAD_AXES]; // Gamepad axes state
|
float axisState[MAX_GAMEPADS][MAX_GAMEPAD_AXES]; // Gamepad axes state
|
||||||
|
|
||||||
} Gamepad;
|
} Gamepad;
|
||||||
|
|
||||||
} Input;
|
} Input;
|
||||||
struct {
|
struct {
|
||||||
double current; // Current time measure (seconds)
|
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)
|
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 long long base; // Base time measure for hi-res timer (ticks or nanoseconds)
|
||||||
unsigned int frameCounter; // Frame counter (frames)
|
unsigned int frameCounter; // Frame counter (frames)
|
||||||
|
|
||||||
} Time;
|
} Time;
|
||||||
} CoreData;
|
} CoreData;
|
||||||
|
|
||||||
@ -579,6 +568,13 @@ const char *TextFormat(const char *text, ...); // Formatting of text with variab
|
|||||||
//Vector2 GetMonitorPosition(int monitor)
|
//Vector2 GetMonitorPosition(int monitor)
|
||||||
//const char *GetMonitorName(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)
|
//void SetClipboardText(const char *text)
|
||||||
//const char *GetClipboardText(void)
|
//const char *GetClipboardText(void)
|
||||||
//bool SetClipboardImage(Image image)
|
//bool SetClipboardImage(Image image)
|
||||||
@ -863,7 +859,7 @@ bool IsCursorOnScreen(void)
|
|||||||
void ClearBackground(Color color)
|
void ClearBackground(Color color)
|
||||||
{
|
{
|
||||||
rlClearColor(color.r, color.g, color.b, color.a); // Set clear 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
|
// Begin canvas (framebuffer) drawing
|
||||||
@ -914,9 +910,57 @@ void EndDrawing(void)
|
|||||||
CORE.Time.frame += waitTime; // Total frame time: update + draw + wait
|
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
|
#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 SUPPORT_SCREEN_CAPTURE
|
||||||
if (IsKeyPressed(KEY_F12))
|
if (IsKeyPressed(KEY_F12))
|
||||||
{
|
{
|
||||||
@ -2694,9 +2738,7 @@ const char *GetApplicationDirectory(void)
|
|||||||
appDir[0] = '.';
|
appDir[0] = '.';
|
||||||
appDir[1] = '\\';
|
appDir[1] = '\\';
|
||||||
}
|
}
|
||||||
|
|
||||||
#elif defined(__linux__)
|
#elif defined(__linux__)
|
||||||
|
|
||||||
unsigned int size = sizeof(appDir);
|
unsigned int size = sizeof(appDir);
|
||||||
ssize_t len = readlink("/proc/self/exe", appDir, size);
|
ssize_t len = readlink("/proc/self/exe", appDir, size);
|
||||||
|
|
||||||
@ -2716,9 +2758,7 @@ const char *GetApplicationDirectory(void)
|
|||||||
appDir[0] = '.';
|
appDir[0] = '.';
|
||||||
appDir[1] = '/';
|
appDir[1] = '/';
|
||||||
}
|
}
|
||||||
|
|
||||||
#elif defined(__APPLE__)
|
#elif defined(__APPLE__)
|
||||||
|
|
||||||
uint32_t size = sizeof(appDir);
|
uint32_t size = sizeof(appDir);
|
||||||
|
|
||||||
if (_NSGetExecutablePath(appDir, &size) == 0)
|
if (_NSGetExecutablePath(appDir, &size) == 0)
|
||||||
@ -2738,9 +2778,7 @@ const char *GetApplicationDirectory(void)
|
|||||||
appDir[0] = '.';
|
appDir[0] = '.';
|
||||||
appDir[1] = '/';
|
appDir[1] = '/';
|
||||||
}
|
}
|
||||||
|
|
||||||
#elif defined(__FreeBSD__)
|
#elif defined(__FreeBSD__)
|
||||||
|
|
||||||
size_t size = sizeof(appDir);
|
size_t size = sizeof(appDir);
|
||||||
int mib[4] = {CTL_KERN, KERN_PROC, KERN_PROC_PATHNAME, -1};
|
int mib[4] = {CTL_KERN, KERN_PROC, KERN_PROC_PATHNAME, -1};
|
||||||
|
|
||||||
@ -2761,9 +2799,7 @@ const char *GetApplicationDirectory(void)
|
|||||||
appDir[0] = '.';
|
appDir[0] = '.';
|
||||||
appDir[1] = '/';
|
appDir[1] = '/';
|
||||||
}
|
}
|
||||||
|
|
||||||
#elif defined(__wasm__)
|
#elif defined(__wasm__)
|
||||||
|
|
||||||
appDir[0] = '/';
|
appDir[0] = '/';
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
@ -3855,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_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
|
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.currentPosition[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]].y = (float)event.params[2];
|
||||||
} break;
|
} break;
|
||||||
case INPUT_GAMEPAD_CONNECT: CORE.Input.Gamepad.ready[event.params[0]] = true; break; // param[0]: gamepad
|
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
|
case INPUT_GAMEPAD_DISCONNECT: CORE.Input.Gamepad.ready[event.params[0]] = false; break; // param[0]: gamepad
|
||||||
@ -4274,14 +4310,14 @@ Vector2 GetMouseWheelMoveV(void)
|
|||||||
// Get touch position X for touch point 0 (relative to screen size)
|
// Get touch position X for touch point 0 (relative to screen size)
|
||||||
int GetTouchX(void)
|
int GetTouchX(void)
|
||||||
{
|
{
|
||||||
int touchX = (int)CORE.Input.Touch.position[0].x;
|
int touchX = (int)CORE.Input.Touch.currentPosition[0].x;
|
||||||
return touchX;
|
return touchX;
|
||||||
}
|
}
|
||||||
|
|
||||||
// Get touch position Y for touch point 0 (relative to screen size)
|
// Get touch position Y for touch point 0 (relative to screen size)
|
||||||
int GetTouchY(void)
|
int GetTouchY(void)
|
||||||
{
|
{
|
||||||
int touchY = (int)CORE.Input.Touch.position[0].y;
|
int touchY = (int)CORE.Input.Touch.currentPosition[0].y;
|
||||||
return touchY;
|
return touchY;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -4290,7 +4326,7 @@ Vector2 GetTouchPosition(int index)
|
|||||||
{
|
{
|
||||||
Vector2 position = { -1.0f, -1.0f };
|
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);
|
else TRACELOG(LOG_WARNING, "INPUT: Required touch point out of range (Max touch points: %i)", MAX_TOUCH_POINTS);
|
||||||
|
|
||||||
return position;
|
return position;
|
||||||
@ -4567,14 +4603,14 @@ static void RecordAutomationEvent(void)
|
|||||||
if (currentEventList->count == currentEventList->capacity) return; // Security check
|
if (currentEventList->count == currentEventList->capacity) return; // Security check
|
||||||
|
|
||||||
// Event type: INPUT_TOUCH_POSITION
|
// Event type: INPUT_TOUCH_POSITION
|
||||||
if (((int)CORE.Input.Touch.position[id].x != (int)CORE.Input.Touch.previousPosition[id].x) ||
|
if (((int)CORE.Input.Touch.currentPosition[id].x != (int)CORE.Input.Touch.previousPosition[id].x) ||
|
||||||
((int)CORE.Input.Touch.position[id].y != (int)CORE.Input.Touch.previousPosition[id].y))
|
((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].frame = CORE.Time.frameCounter;
|
||||||
currentEventList->events[currentEventList->count].type = INPUT_TOUCH_POSITION;
|
currentEventList->events[currentEventList->count].type = INPUT_TOUCH_POSITION;
|
||||||
currentEventList->events[currentEventList->count].params[0] = id;
|
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[1] = (int)CORE.Input.Touch.currentPosition[id].x;
|
||||||
currentEventList->events[currentEventList->count].params[2] = (int)CORE.Input.Touch.position[id].y;
|
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]);
|
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++;
|
currentEventList->count++;
|
||||||
|
|||||||
@ -123,7 +123,7 @@ extern "C" { // Prevents name mangling of functions
|
|||||||
#endif
|
#endif
|
||||||
|
|
||||||
void ProcessGestureEvent(GestureEvent event); // Process gesture event and translate it into gestures
|
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)
|
#if defined(RGESTURES_STANDALONE)
|
||||||
void SetGesturesEnabled(unsigned int flags); // Enable a set of gestures using flags
|
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
|
// Defines and Macros
|
||||||
//----------------------------------------------------------------------------------
|
//----------------------------------------------------------------------------------
|
||||||
#define FORCE_TO_SWIPE 0.2f // Swipe force, measured in normalized screen units/time
|
#define MIN_TAP_TIME 0.3f // Tap minimum time (DOWN-UP), measured in seconds
|
||||||
#define MINIMUM_DRAG 0.015f // Drag minimum force, measured in normalized screen units (0.0f to 1.0f)
|
#define MIN_HOLD_TIME 0.6f // Hold minimum time, measured in seconds
|
||||||
#define DRAG_TIMEOUT 0.3f // Drag minimum time for web, 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 MINIMUM_PINCH 0.005f // Pinch minimum force, measured in normalized screen units (0.0f to 1.0f)
|
#define MIN_DRAG_TIME 0.3f // Drag minimum time, measured in seconds
|
||||||
#define TAP_TIMEOUT 0.3f // Tap 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 PINCH_TIMEOUT 0.3f // Pinch minimum time, measured in seconds
|
#define MIN_SWIPE_FORCE 0.2f // Swipe force, measured in normalized screen units/time
|
||||||
#define DOUBLETAP_RANGE 0.03f // DoubleTap range, measured in normalized screen units (0.0f to 1.0f)
|
#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
|
// Types and Structures Definition
|
||||||
@ -265,10 +266,11 @@ bool IsGestureDetected(unsigned int gesture)
|
|||||||
}
|
}
|
||||||
|
|
||||||
// Process gesture event and translate it into gestures
|
// 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)
|
void ProcessGestureEvent(GestureEvent event)
|
||||||
{
|
{
|
||||||
// Reset required variables
|
// Reset required variables
|
||||||
GESTURES.Touch.pointCount = event.pointCount; // Required on UpdateGestures()
|
GESTURES.Touch.pointCount = event.pointCount;
|
||||||
|
|
||||||
if (GESTURES.Touch.pointCount == 1) // One touch point
|
if (GESTURES.Touch.pointCount == 1) // One touch point
|
||||||
{
|
{
|
||||||
@ -277,7 +279,9 @@ void ProcessGestureEvent(GestureEvent event)
|
|||||||
GESTURES.Touch.tapCounter++; // Tap counter
|
GESTURES.Touch.tapCounter++; // Tap counter
|
||||||
|
|
||||||
// Detect GESTURE_DOUBLE_TAP
|
// 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.current = GESTURE_DOUBLETAP;
|
||||||
GESTURES.Touch.tapCounter = 0;
|
GESTURES.Touch.tapCounter = 0;
|
||||||
@ -300,15 +304,14 @@ void ProcessGestureEvent(GestureEvent event)
|
|||||||
}
|
}
|
||||||
else if (event.touchAction == TOUCH_ACTION_UP)
|
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
|
GESTURES.Touch.upPosition = event.position[0];
|
||||||
if (GESTURES.current == GESTURE_DRAG || GESTURES.current == GESTURE_HOLD) GESTURES.Touch.upPosition = event.position[0];
|
|
||||||
|
|
||||||
// NOTE: GESTURES.Drag.intensity is dependent on the resolution of the screen
|
// NOTE: GESTURES.Drag.intensity is dependent on the resolution of the screen
|
||||||
GESTURES.Drag.distance = rgVector2Distance(GESTURES.Touch.downPositionA, GESTURES.Touch.upPosition);
|
GESTURES.Drag.distance = rgVector2Distance(GESTURES.Touch.downPositionA, GESTURES.Touch.upPosition);
|
||||||
GESTURES.Drag.intensity = GESTURES.Drag.distance/(float)((rgGetCurrentTime() - GESTURES.Swipe.startTime));
|
GESTURES.Drag.intensity = GESTURES.Drag.distance/(float)((rgGetCurrentTime() - GESTURES.Swipe.startTime));
|
||||||
|
|
||||||
// Detect GESTURE_SWIPE
|
// 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
|
// NOTE: Angle should be inverted in Y
|
||||||
GESTURES.Drag.angle = 360.0f - rgVector2Angle(GESTURES.Touch.downPositionA, GESTURES.Touch.upPosition);
|
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];
|
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
|
// Detect GESTURE_DRAG
|
||||||
if ((rgGetCurrentTime() - GESTURES.Touch.eventTime) > DRAG_TIMEOUT)
|
if ((rgGetCurrentTime() - GESTURES.Touch.eventTime) > MIN_DRAG_TIME)
|
||||||
{
|
{
|
||||||
GESTURES.Touch.eventTime = rgGetCurrentTime();
|
GESTURES.Touch.eventTime = rgGetCurrentTime();
|
||||||
GESTURES.current = GESTURE_DRAG;
|
GESTURES.current = GESTURE_DRAG;
|
||||||
@ -363,13 +362,11 @@ void ProcessGestureEvent(GestureEvent event)
|
|||||||
GESTURES.Touch.previousPositionA = GESTURES.Touch.downPositionA;
|
GESTURES.Touch.previousPositionA = GESTURES.Touch.downPositionA;
|
||||||
GESTURES.Touch.previousPositionB = GESTURES.Touch.downPositionB;
|
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.x = GESTURES.Touch.downPositionB.x - GESTURES.Touch.downPositionA.x;
|
||||||
GESTURES.Pinch.vector.y = GESTURES.Touch.downPositionB.y - GESTURES.Touch.downPositionA.y;
|
GESTURES.Pinch.vector.y = GESTURES.Touch.downPositionB.y - GESTURES.Touch.downPositionA.y;
|
||||||
|
|
||||||
GESTURES.current = GESTURE_HOLD;
|
//GESTURES.current = GESTURE_HOLD;
|
||||||
GESTURES.Hold.timeDuration = rgGetCurrentTime();
|
//GESTURES.Hold.timeDuration = rgGetCurrentTime();
|
||||||
}
|
}
|
||||||
else if (event.touchAction == TOUCH_ACTION_MOVE)
|
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.x = GESTURES.Touch.moveDownPositionB.x - GESTURES.Touch.moveDownPositionA.x;
|
||||||
GESTURES.Pinch.vector.y = GESTURES.Touch.moveDownPositionB.y - GESTURES.Touch.moveDownPositionA.y;
|
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_PINCH_OUT;
|
||||||
}
|
}
|
||||||
else
|
//else
|
||||||
{
|
//{
|
||||||
GESTURES.current = GESTURE_HOLD;
|
// GESTURES.current = GESTURE_HOLD;
|
||||||
GESTURES.Hold.timeDuration = rgGetCurrentTime();
|
// GESTURES.Hold.timeDuration = rgGetCurrentTime();
|
||||||
}
|
//}
|
||||||
|
|
||||||
// NOTE: Angle should be inverted in Y
|
// NOTE: Angle should be inverted in Y
|
||||||
GESTURES.Pinch.angle = 360.0f - rgVector2Angle(GESTURES.Touch.moveDownPositionA, GESTURES.Touch.moveDownPositionB);
|
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)
|
// Update gestures detected (must be called every frame)
|
||||||
void UpdateGestures(void)
|
void UpdateGestures(void)
|
||||||
{
|
{
|
||||||
// NOTE: Gestures are processed through system callbacks on touch events
|
// NOTE: Gestures are processed through system callbacks on touch events
|
||||||
|
|
||||||
// Detect GESTURE_HOLD
|
// 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.current = GESTURE_HOLD;
|
||||||
GESTURES.Hold.timeDuration = rgGetCurrentTime();
|
GESTURES.Hold.timeDuration = (rgGetCurrentTime() - GESTURES.Touch.eventTime);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// Detect GESTURE_NONE
|
// 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;
|
GESTURES.current = GESTURE_NONE;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
*/
|
||||||
|
|
||||||
// Get latest detected gesture
|
// Get latest detected gesture
|
||||||
int GetGestureDetected(void)
|
int GetGestureDetected(void)
|
||||||
|
|||||||
@ -1079,7 +1079,6 @@ typedef struct rlglData {
|
|||||||
|
|
||||||
int framebufferWidth; // Current framebuffer width
|
int framebufferWidth; // Current framebuffer width
|
||||||
int framebufferHeight; // Current framebuffer height
|
int framebufferHeight; // Current framebuffer height
|
||||||
|
|
||||||
} State; // Renderer state
|
} State; // Renderer state
|
||||||
struct {
|
struct {
|
||||||
bool vao; // VAO support (OpenGL ES2 could not support VAO extension) (GL_ARB_vertex_array_object)
|
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)
|
float maxAnisotropyLevel; // Maximum anisotropy level supported (minimum is 2.0f)
|
||||||
int maxDepthBits; // Maximum bits for depth component
|
int maxDepthBits; // Maximum bits for depth component
|
||||||
|
|
||||||
} ExtSupported; // Extensions supported flags
|
} ExtSupported; // Extensions supported flags
|
||||||
} rlglData;
|
} rlglData;
|
||||||
|
|
||||||
|
|||||||
@ -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);
|
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);
|
UnloadFileData(fileData);
|
||||||
|
|
||||||
return animations;
|
return animations;
|
||||||
|
|||||||
@ -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;
|
for (count = 0; (temp = strstr(insertPoint, search)); count++) insertPoint = temp + searchLen;
|
||||||
|
|
||||||
// Allocate returning string and point temp to it
|
// 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));
|
temp = result = (char *)RL_CALLOC(tempLen, sizeof(char));
|
||||||
|
|
||||||
// First time through the loop, all the variable are set correctly from here on,
|
// 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]);
|
int textLength = TextLength(textList[i]);
|
||||||
|
|
||||||
// Make sure joined text could fit inside MAX_TEXT_BUFFER_LENGTH
|
// 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);
|
memcpy(textPtr, textList[i], textLength);
|
||||||
totalLength += textLength;
|
totalLength += textLength;
|
||||||
|
|||||||
Reference in New Issue
Block a user