mirror of
https://github.com/raysan5/raylib.git
synced 2026-01-11 14:08:48 +01:00
Compare commits
4 Commits
8f8346048c
...
2b48cf6793
| Author | SHA1 | Date | |
|---|---|---|---|
| 2b48cf6793 | |||
| 1c6f683161 | |||
| 00f42e4199 | |||
| 58d414bcf8 |
@ -105,7 +105,7 @@
|
||||
#define MAX_GAMEPAD_AXES 8 // Maximum number of axes supported (per gamepad)
|
||||
#define MAX_GAMEPAD_BUTTONS 32 // Maximum number of buttons supported (per gamepad)
|
||||
#define MAX_GAMEPAD_VIBRATION_TIME 2.0f // Maximum vibration time in seconds
|
||||
#define MAX_TOUCH_POINTS 8 // Maximum number of touch points supported
|
||||
#define MAX_TOUCH_POINTS 10 // Maximum number of touch points supported
|
||||
#define MAX_KEY_PRESSED_QUEUE 16 // Maximum number of keys in the key input queue
|
||||
#define MAX_CHAR_PRESSED_QUEUE 16 // Maximum number of characters in the char input queue
|
||||
|
||||
|
||||
@ -1336,30 +1336,17 @@ static int32_t AndroidInputCallback(struct android_app *app, AInputEvent *event)
|
||||
}
|
||||
}
|
||||
|
||||
if ((flags == AMOTION_EVENT_ACTION_POINTER_UP) || (flags == AMOTION_EVENT_ACTION_UP) || (flags == AMOTION_EVENT_ACTION_HOVER_EXIT))
|
||||
{
|
||||
// One of the touchpoints is released, remove it from touch point arrays
|
||||
if (flags == AMOTION_EVENT_ACTION_HOVER_EXIT)
|
||||
{
|
||||
// If the touchPoint is hover, remove it from hoverPoints
|
||||
for (int i = 0; i < MAX_TOUCH_POINTS; i++)
|
||||
{
|
||||
if (touchRaw.hoverPoints[i] == touchRaw.pointId[pointerIndex])
|
||||
{
|
||||
touchRaw.hoverPoints[i] = -1;
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
for (int i = pointerIndex; (i < touchRaw.pointCount - 1) && (i < MAX_TOUCH_POINTS - 1); i++)
|
||||
{
|
||||
touchRaw.pointId[i] = touchRaw.pointId[i+1];
|
||||
touchRaw.position[i] = touchRaw.position[i+1];
|
||||
}
|
||||
touchRaw.pointCount--;
|
||||
}
|
||||
#if defined(SUPPORT_GESTURES_SYSTEM)
|
||||
GestureEvent gestureEvent = { 0 };
|
||||
|
||||
gestureEvent.pointCount = 0;
|
||||
|
||||
// Register touch actions
|
||||
if (flags == AMOTION_EVENT_ACTION_DOWN) gestureEvent.touchAction = TOUCH_ACTION_DOWN;
|
||||
else if (flags == AMOTION_EVENT_ACTION_UP) gestureEvent.touchAction = TOUCH_ACTION_UP;
|
||||
else if (flags == AMOTION_EVENT_ACTION_MOVE) gestureEvent.touchAction = TOUCH_ACTION_MOVE;
|
||||
else if (flags == AMOTION_EVENT_ACTION_CANCEL) gestureEvent.touchAction = TOUCH_ACTION_CANCEL;
|
||||
|
||||
int pointCount = 0;
|
||||
for (int i = 0; (i < touchRaw.pointCount) && (i < MAX_TOUCH_POINTS); i++)
|
||||
{
|
||||
// If the touchPoint is hover, Ignore it
|
||||
@ -1375,35 +1362,62 @@ static int32_t AndroidInputCallback(struct android_app *app, AInputEvent *event)
|
||||
}
|
||||
if (hover) continue;
|
||||
|
||||
CORE.Input.Touch.pointId[pointCount] = touchRaw.pointId[i];
|
||||
CORE.Input.Touch.position[pointCount] = touchRaw.position[i];
|
||||
pointCount++;
|
||||
}
|
||||
CORE.Input.Touch.pointCount = pointCount;
|
||||
|
||||
#if defined(SUPPORT_GESTURES_SYSTEM)
|
||||
GestureEvent gestureEvent = { 0 };
|
||||
|
||||
gestureEvent.pointCount = CORE.Input.Touch.pointCount;
|
||||
|
||||
// Register touch actions
|
||||
if (flags == AMOTION_EVENT_ACTION_DOWN) gestureEvent.touchAction = TOUCH_ACTION_DOWN;
|
||||
else if (flags == AMOTION_EVENT_ACTION_UP) gestureEvent.touchAction = TOUCH_ACTION_UP;
|
||||
else if (flags == AMOTION_EVENT_ACTION_MOVE) gestureEvent.touchAction = TOUCH_ACTION_MOVE;
|
||||
else if (flags == AMOTION_EVENT_ACTION_CANCEL) 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];
|
||||
gestureEvent.position[i].x /= (float)GetScreenWidth();
|
||||
gestureEvent.position[i].y /= (float)GetScreenHeight();
|
||||
gestureEvent.pointId[gestureEvent.pointCount] = touchRaw.pointId[i];
|
||||
gestureEvent.position[gestureEvent.pointCount] = touchRaw.position[i];
|
||||
gestureEvent.position[gestureEvent.pointCount].x /= (float)GetScreenWidth();
|
||||
gestureEvent.position[gestureEvent.pointCount].y /= (float)GetScreenHeight();
|
||||
gestureEvent.pointCount++;
|
||||
}
|
||||
|
||||
// Gesture data is sent to gestures system for processing
|
||||
ProcessGestureEvent(gestureEvent);
|
||||
#endif
|
||||
|
||||
if (flags == AMOTION_EVENT_ACTION_HOVER_EXIT)
|
||||
{
|
||||
// Hover exited. So, remove it from hoverPoints
|
||||
for (int i = 0; i < MAX_TOUCH_POINTS; i++)
|
||||
{
|
||||
if (touchRaw.hoverPoints[i] == touchRaw.pointId[pointerIndex])
|
||||
{
|
||||
touchRaw.hoverPoints[i] = -1;
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if ((flags == AMOTION_EVENT_ACTION_POINTER_UP) || (flags == AMOTION_EVENT_ACTION_UP))
|
||||
{
|
||||
// One of the touchpoints is released, remove it from touch point arrays
|
||||
for (int i = pointerIndex; (i < touchRaw.pointCount - 1) && (i < MAX_TOUCH_POINTS - 1); i++)
|
||||
{
|
||||
touchRaw.pointId[i] = touchRaw.pointId[i+1];
|
||||
touchRaw.position[i] = touchRaw.position[i+1];
|
||||
}
|
||||
touchRaw.pointCount--;
|
||||
}
|
||||
|
||||
CORE.Input.Touch.pointCount = 0;
|
||||
for (int i = 0; (i < touchRaw.pointCount) && (i < MAX_TOUCH_POINTS); i++)
|
||||
{
|
||||
// If the touchPoint is hover, Ignore it
|
||||
bool hover = false;
|
||||
for (int j = 0; j < MAX_TOUCH_POINTS; j++)
|
||||
{
|
||||
// Check if the touchPoint is in hoverPointers
|
||||
if (touchRaw.hoverPoints[j] == touchRaw.pointId[i])
|
||||
{
|
||||
hover = true;
|
||||
break;
|
||||
}
|
||||
}
|
||||
if (hover) continue;
|
||||
|
||||
CORE.Input.Touch.pointId[CORE.Input.Touch.pointCount] = touchRaw.pointId[i];
|
||||
CORE.Input.Touch.position[CORE.Input.Touch.pointCount] = touchRaw.position[i];
|
||||
CORE.Input.Touch.pointCount++;
|
||||
}
|
||||
|
||||
// When all touchpoints are tapped and released really quickly, this event is generated
|
||||
if (flags == AMOTION_EVENT_ACTION_CANCEL) CORE.Input.Touch.pointCount = 0;
|
||||
|
||||
|
||||
@ -1565,13 +1565,18 @@ int InitPlatform(void)
|
||||
CORE.Window.previousScreen.height = 450;
|
||||
CORE.Window.previousPosition.x = CORE.Window.display.width/2 - 800/2;
|
||||
CORE.Window.previousPosition.y = CORE.Window.display.height/2 - 450/2;
|
||||
|
||||
// Set screen width/height to the display width/height
|
||||
if (CORE.Window.screen.width == 0) CORE.Window.screen.width = CORE.Window.display.width;
|
||||
if (CORE.Window.screen.height == 0) CORE.Window.screen.height = CORE.Window.display.height;
|
||||
}
|
||||
else
|
||||
{
|
||||
CORE.Window.previousScreen = CORE.Window.screen;
|
||||
CORE.Window.screen = CORE.Window.display;
|
||||
}
|
||||
|
||||
// Set screen width/height to the display width/height
|
||||
if (CORE.Window.screen.width == 0) CORE.Window.screen.width = CORE.Window.display.width;
|
||||
if (CORE.Window.screen.height == 0) CORE.Window.screen.height = CORE.Window.display.height;
|
||||
|
||||
platform.handle = glfwCreateWindow(CORE.Window.display.width, CORE.Window.display.height, (CORE.Window.title != 0)? CORE.Window.title : " ", monitor, NULL);
|
||||
platform.handle = glfwCreateWindow(CORE.Window.screen.width, CORE.Window.screen.height, (CORE.Window.title != 0)? CORE.Window.title : " ", monitor, NULL);
|
||||
if (!platform.handle)
|
||||
{
|
||||
glfwTerminate();
|
||||
@ -1630,13 +1635,13 @@ int InitPlatform(void)
|
||||
|
||||
glfwMakeContextCurrent(platform.handle);
|
||||
result = glfwGetError(NULL);
|
||||
if ((result != GLFW_NO_WINDOW_CONTEXT) && (result != GLFW_PLATFORM_ERROR)) CORE.Window.ready = true; // Checking context activation
|
||||
|
||||
// Check context activation
|
||||
if ((result != GLFW_NO_WINDOW_CONTEXT) && (result != GLFW_PLATFORM_ERROR))
|
||||
if (CORE.Window.ready)
|
||||
{
|
||||
CORE.Window.ready = true;
|
||||
// Setup additional windows configs and register required window size info
|
||||
|
||||
glfwSwapInterval(0); // No V-Sync by default
|
||||
glfwSwapInterval(0); // No V-Sync by default
|
||||
|
||||
// Try to enable GPU V-Sync, so frames are limited to screen refresh rate (60Hz -> 60 FPS)
|
||||
// NOTE: V-Sync can be enabled by graphic driver configuration, it doesn't need
|
||||
@ -1677,25 +1682,13 @@ int InitPlatform(void)
|
||||
TRACELOG(LOG_INFO, " > Screen size: %i x %i", CORE.Window.screen.width, CORE.Window.screen.height);
|
||||
TRACELOG(LOG_INFO, " > Render size: %i x %i", CORE.Window.render.width, CORE.Window.render.height);
|
||||
TRACELOG(LOG_INFO, " > Viewport offsets: %i, %i", CORE.Window.renderOffset.x, CORE.Window.renderOffset.y);
|
||||
}
|
||||
else
|
||||
{
|
||||
TRACELOG(LOG_FATAL, "PLATFORM: Failed to initialize graphics device");
|
||||
return -1;
|
||||
}
|
||||
|
||||
if (FLAG_IS_SET(CORE.Window.flags, FLAG_WINDOW_MINIMIZED)) MinimizeWindow();
|
||||
|
||||
// If graphic device is no properly initialized, we end program
|
||||
if (!CORE.Window.ready) { TRACELOG(LOG_FATAL, "PLATFORM: Failed to initialize graphic device"); return -1; }
|
||||
else
|
||||
{
|
||||
// Try to center window on screen but avoiding window-bar outside of screen
|
||||
int monitorCount = 0;
|
||||
int monitorIndex = GetCurrentMonitor();
|
||||
GLFWmonitor **monitors = glfwGetMonitors(&monitorCount);
|
||||
GLFWmonitor *monitor = monitors[monitorIndex];
|
||||
|
||||
// Try to center window on screen but avoiding window-bar outside of screen
|
||||
int monitorX = 0;
|
||||
int monitorY = 0;
|
||||
int monitorWidth = 0;
|
||||
@ -1704,15 +1697,19 @@ int InitPlatform(void)
|
||||
|
||||
// TODO: Here CORE.Window.render.width/height should be used instead of
|
||||
// CORE.Window.screen.width/height to center the window correctly when the high dpi flag is enabled
|
||||
int posX = monitorX + (monitorWidth - (int)CORE.Window.render.width)/2;
|
||||
int posY = monitorY + (monitorHeight - (int)CORE.Window.render.height)/2;
|
||||
if (posX < monitorX) posX = monitorX;
|
||||
if (posY < monitorY) posY = monitorY;
|
||||
SetWindowPosition(posX, posY);
|
||||
CORE.Window.position.x = monitorX + (monitorWidth - (int)CORE.Window.screen.width)/2;
|
||||
CORE.Window.position.y = monitorY + (monitorHeight - (int)CORE.Window.screen.height)/2;
|
||||
//if (CORE.Window.position.x < monitorX) CORE.Window.position.x = monitorX;
|
||||
//if (CORE.Window.position.y < monitorY) CORE.Window.position.y = monitorY;
|
||||
|
||||
// Update CORE.Window.position here so it is correct from the start
|
||||
CORE.Window.position.x = posX;
|
||||
CORE.Window.position.y = posY;
|
||||
SetWindowPosition(CORE.Window.position.x, CORE.Window.position.y);
|
||||
|
||||
if (FLAG_IS_SET(CORE.Window.flags, FLAG_WINDOW_MINIMIZED)) MinimizeWindow();
|
||||
}
|
||||
else
|
||||
{
|
||||
TRACELOG(LOG_FATAL, "PLATFORM: Failed to initialize graphics device");
|
||||
return -1;
|
||||
}
|
||||
|
||||
// Apply window flags requested previous to initialization
|
||||
|
||||
@ -135,8 +135,12 @@ typedef struct {
|
||||
char currentButtonStateEvdev[MAX_MOUSE_BUTTONS]; // Holds the new mouse state for the next polling event to grab
|
||||
bool cursorRelative; // Relative cursor mode
|
||||
int mouseFd; // File descriptor for the evdev mouse/touch/gestures
|
||||
bool mouseIsTouch; // Check if the current mouse device is actually a touchscreen
|
||||
Rectangle absRange; // Range of values for absolute pointing devices (touchscreens)
|
||||
int touchSlot; // Hold the touch slot number of the currently being sent multitouch block
|
||||
bool touchActive[MAX_TOUCH_POINTS]; // Track which touch points are currently active
|
||||
Vector2 touchPosition[MAX_TOUCH_POINTS]; // Track touch positions for each slot
|
||||
int touchId[MAX_TOUCH_POINTS]; // Track touch IDs for each slot
|
||||
|
||||
// Gamepad data
|
||||
int gamepadStreamFd[MAX_GAMEPADS]; // Gamepad device file descriptor
|
||||
@ -1115,9 +1119,6 @@ void PollInputEvents(void)
|
||||
// Register previous touch states
|
||||
for (int i = 0; i < MAX_TOUCH_POINTS; i++) CORE.Input.Touch.previousTouchState[i] = CORE.Input.Touch.currentTouchState[i];
|
||||
|
||||
// Reset touch positions to invalid state
|
||||
for (int i = 0; i < MAX_TOUCH_POINTS; i++) CORE.Input.Touch.position[i] = (Vector2){ -1, -1 };
|
||||
|
||||
// Map touch position to mouse position for convenience
|
||||
// NOTE: For DRM touchscreen devices, this mapping is disabled to avoid false touch detection
|
||||
// CORE.Input.Touch.position[0] = CORE.Input.Mouse.currentPosition;
|
||||
@ -1565,7 +1566,11 @@ int InitPlatform(void)
|
||||
if (FLAG_IS_SET(CORE.Window.flags, FLAG_WINDOW_MINIMIZED)) MinimizeWindow();
|
||||
|
||||
// If graphic device is no properly initialized, we end program
|
||||
if (!CORE.Window.ready) { TRACELOG(LOG_FATAL, "PLATFORM: Failed to initialize graphic device"); return -1; }
|
||||
if (!CORE.Window.ready)
|
||||
{
|
||||
TRACELOG(LOG_FATAL, "PLATFORM: Failed to initialize graphic device");
|
||||
return -1;
|
||||
}
|
||||
else SetWindowPosition(GetMonitorWidth(GetCurrentMonitor())/2 - CORE.Window.screen.width/2, GetMonitorHeight(GetCurrentMonitor())/2 - CORE.Window.screen.height/2);
|
||||
|
||||
// Set some default window flags
|
||||
@ -1883,8 +1888,15 @@ static void InitEvdevInput(void)
|
||||
{
|
||||
CORE.Input.Touch.position[i].x = -1;
|
||||
CORE.Input.Touch.position[i].y = -1;
|
||||
platform.touchActive[i] = false;
|
||||
platform.touchPosition[i].x = -1;
|
||||
platform.touchPosition[i].y = -1;
|
||||
platform.touchId[i] = -1;
|
||||
}
|
||||
|
||||
// Initialize touch slot
|
||||
platform.touchSlot = 0;
|
||||
|
||||
// Reset keyboard key state
|
||||
for (int i = 0; i < MAX_KEYBOARD_KEYS; i++)
|
||||
{
|
||||
@ -2047,17 +2059,49 @@ static void ConfigureEvdevDevice(char *device)
|
||||
const char *deviceKindStr = "unknown";
|
||||
if (isMouse || isTouch)
|
||||
{
|
||||
deviceKindStr = "mouse";
|
||||
if (platform.mouseFd != -1) close(platform.mouseFd);
|
||||
platform.mouseFd = fd;
|
||||
bool prioritize = false;
|
||||
|
||||
if (absAxisCount > 0)
|
||||
// Priority logic: touchscreens override Mice
|
||||
// 1. No device set yet? Take it
|
||||
if (platform.mouseFd == -1) prioritize = true;
|
||||
// 2. Current is mouse, new is touch? Upgrade to touch
|
||||
else if (isTouch && !platform.mouseIsTouch) prioritize = true;
|
||||
// 3. Current is touch, new is touch? Use the new one (last one found wins, standard behavior)
|
||||
else if (isTouch && platform.mouseIsTouch) prioritize = true;
|
||||
// 4. Current is mouse, new is mouse? Use the new one
|
||||
else if (!isTouch && !platform.mouseIsTouch) prioritize = true;
|
||||
// 5. Current is touch, new is mouse? Ignore the mouse, keep the touchscreen
|
||||
else prioritize = false;
|
||||
|
||||
if (prioritize)
|
||||
{
|
||||
platform.absRange.x = absinfo[ABS_X].info.minimum;
|
||||
platform.absRange.width = absinfo[ABS_X].info.maximum - absinfo[ABS_X].info.minimum;
|
||||
deviceKindStr = isTouch? "touchscreen" : "mouse";
|
||||
|
||||
platform.absRange.y = absinfo[ABS_Y].info.minimum;
|
||||
platform.absRange.height = absinfo[ABS_Y].info.maximum - absinfo[ABS_Y].info.minimum;
|
||||
if (platform.mouseFd != -1)
|
||||
{
|
||||
TRACELOG(LOG_INFO, "INPUT: Overwriting previous input device with new %s", deviceKindStr);
|
||||
close(platform.mouseFd);
|
||||
}
|
||||
|
||||
platform.mouseFd = fd;
|
||||
platform.mouseIsTouch = isTouch;
|
||||
|
||||
if (absAxisCount > 0)
|
||||
{
|
||||
platform.absRange.x = absinfo[ABS_X].info.minimum;
|
||||
platform.absRange.width = absinfo[ABS_X].info.maximum - absinfo[ABS_X].info.minimum;
|
||||
|
||||
platform.absRange.y = absinfo[ABS_Y].info.minimum;
|
||||
platform.absRange.height = absinfo[ABS_Y].info.maximum - absinfo[ABS_Y].info.minimum;
|
||||
}
|
||||
|
||||
TRACELOG(LOG_INFO, "INPUT: Initialized input device %s as %s", device, deviceKindStr);
|
||||
}
|
||||
else
|
||||
{
|
||||
TRACELOG(LOG_INFO, "INPUT: Ignoring device %s (keeping higher priority %s device)", device, platform.mouseIsTouch ? "touchscreen" : "mouse");
|
||||
close(fd);
|
||||
return;
|
||||
}
|
||||
}
|
||||
else if (isGamepad && !isMouse && !isKeyboard && (platform.gamepadCount < MAX_GAMEPADS))
|
||||
@ -2128,18 +2172,15 @@ static void PollKeyboardEvents(void)
|
||||
// If the event was a key, we know a working keyboard is connected, so disable the SSH keyboard
|
||||
platform.eventKeyboardMode = true;
|
||||
#endif
|
||||
|
||||
// Keyboard keys appear for codes 1 to 255, ignore everthing else
|
||||
if ((event.code >= 1) && (event.code <= 255))
|
||||
{
|
||||
|
||||
// Lookup the scancode in the keymap to get a keycode
|
||||
keycode = linuxToRaylibMap[event.code];
|
||||
|
||||
// Make sure we got a valid keycode
|
||||
if ((keycode > 0) && (keycode < MAX_KEYBOARD_KEYS))
|
||||
{
|
||||
|
||||
// WARNING: https://www.kernel.org/doc/Documentation/input/input.txt
|
||||
// Event interface: 'value' is the value the event carries. Either a relative change for EV_REL,
|
||||
// absolute new value for EV_ABS (joysticks ...), or 0 for EV_KEY for release, 1 for keypress and 2 for autorepeat
|
||||
@ -2188,16 +2229,15 @@ static void PollGamepadEvents(void)
|
||||
{
|
||||
if (event.code < KEYMAP_SIZE)
|
||||
{
|
||||
short keycodeRaylib = linuxToRaylibMap[event.code];
|
||||
short keycode = linuxToRaylibMap[event.code]; // raylib keycode
|
||||
|
||||
TRACELOG(LOG_DEBUG, "INPUT: Gamepad %2i: KEY_%s Keycode(linux): %4i Keycode(raylib): %4i", i, (event.value == 0)? "UP" : "DOWN", event.code, keycodeRaylib);
|
||||
TRACELOG(LOG_DEBUG, "INPUT: Gamepad %2i: KEY_%s Keycode(linux): %4i Keycode(raylib): %4i", i, (event.value == 0)? "UP" : "DOWN", event.code, keycode);
|
||||
|
||||
if ((keycodeRaylib != 0) && (keycodeRaylib < MAX_GAMEPAD_BUTTONS))
|
||||
if ((keycode != 0) && (keycode < MAX_GAMEPAD_BUTTONS))
|
||||
{
|
||||
// 1 - button pressed, 0 - button released
|
||||
CORE.Input.Gamepad.currentButtonState[i][keycodeRaylib] = event.value;
|
||||
|
||||
CORE.Input.Gamepad.lastButtonPressed = (event.value == 1)? keycodeRaylib : GAMEPAD_BUTTON_UNKNOWN;
|
||||
CORE.Input.Gamepad.currentButtonState[i][keycode] = event.value;
|
||||
CORE.Input.Gamepad.lastButtonPressed = (event.value == 1)? keycode : GAMEPAD_BUTTON_UNKNOWN;
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -2231,6 +2271,7 @@ static void PollMouseEvents(void)
|
||||
|
||||
struct input_event event = { 0 };
|
||||
int touchAction = -1; // 0-TOUCH_ACTION_UP, 1-TOUCH_ACTION_DOWN, 2-TOUCH_ACTION_MOVE
|
||||
static bool isMultitouch = false; // Detect if device supports MT events
|
||||
|
||||
// Try to read data from the mouse/touch/gesture and only continue if successful
|
||||
while (read(fd, &event, sizeof(event)) == (int)sizeof(event))
|
||||
@ -2276,39 +2317,102 @@ static void PollMouseEvents(void)
|
||||
if (event.code == ABS_X)
|
||||
{
|
||||
CORE.Input.Mouse.currentPosition.x = (event.value - platform.absRange.x)*CORE.Window.screen.width/platform.absRange.width; // Scale according to absRange
|
||||
CORE.Input.Touch.position[0].x = (event.value - platform.absRange.x)*CORE.Window.screen.width/platform.absRange.width; // Scale according to absRange
|
||||
|
||||
touchAction = 2; // TOUCH_ACTION_MOVE
|
||||
// Update single touch position only if it's active and no MT events are being used
|
||||
if (platform.touchActive[0] && !isMultitouch)
|
||||
{
|
||||
platform.touchPosition[0].x = (event.value - platform.absRange.x)*CORE.Window.screen.width/platform.absRange.width;
|
||||
if (touchAction == -1) touchAction = 2; // TOUCH_ACTION_MOVE
|
||||
}
|
||||
}
|
||||
|
||||
if (event.code == ABS_Y)
|
||||
{
|
||||
CORE.Input.Mouse.currentPosition.y = (event.value - platform.absRange.y)*CORE.Window.screen.height/platform.absRange.height; // Scale according to absRange
|
||||
CORE.Input.Touch.position[0].y = (event.value - platform.absRange.y)*CORE.Window.screen.height/platform.absRange.height; // Scale according to absRange
|
||||
|
||||
touchAction = 2; // TOUCH_ACTION_MOVE
|
||||
// Update single touch position only if it's active and no MT events are being used
|
||||
if (platform.touchActive[0] && !isMultitouch)
|
||||
{
|
||||
platform.touchPosition[0].y = (event.value - platform.absRange.y)*CORE.Window.screen.height/platform.absRange.height;
|
||||
if (touchAction == -1) touchAction = 2; // TOUCH_ACTION_MOVE
|
||||
}
|
||||
}
|
||||
|
||||
// Multitouch movement
|
||||
if (event.code == ABS_MT_SLOT) platform.touchSlot = event.value; // Remember the slot number for the folowing events
|
||||
if (event.code == ABS_MT_SLOT)
|
||||
{
|
||||
platform.touchSlot = event.value;
|
||||
isMultitouch = true;
|
||||
}
|
||||
|
||||
if (event.code == ABS_MT_POSITION_X)
|
||||
{
|
||||
if (platform.touchSlot < MAX_TOUCH_POINTS) CORE.Input.Touch.position[platform.touchSlot].x = (event.value - platform.absRange.x)*CORE.Window.screen.width/platform.absRange.width; // Scale according to absRange
|
||||
isMultitouch = true;
|
||||
if (platform.touchSlot < MAX_TOUCH_POINTS)
|
||||
{
|
||||
platform.touchPosition[platform.touchSlot].x = (event.value - platform.absRange.x)*CORE.Window.screen.width/platform.absRange.width;
|
||||
|
||||
// If this slot is active, it's a move. If not, we are just updating the buffer for when it becomes active.
|
||||
// Only set to MOVE if we haven't already detected a DOWN or UP event this frame
|
||||
if (platform.touchActive[platform.touchSlot] && touchAction == -1) touchAction = 2; // TOUCH_ACTION_MOVE
|
||||
}
|
||||
}
|
||||
|
||||
if (event.code == ABS_MT_POSITION_Y)
|
||||
{
|
||||
if (platform.touchSlot < MAX_TOUCH_POINTS) CORE.Input.Touch.position[platform.touchSlot].y = (event.value - platform.absRange.y)*CORE.Window.screen.height/platform.absRange.height; // Scale according to absRange
|
||||
if (platform.touchSlot < MAX_TOUCH_POINTS)
|
||||
{
|
||||
platform.touchPosition[platform.touchSlot].y = (event.value - platform.absRange.y)*CORE.Window.screen.height/platform.absRange.height;
|
||||
|
||||
// If this slot is active, it's a move. If not, we are just updating the buffer for when it becomes active.
|
||||
// Only set to MOVE if we haven't already detected a DOWN or UP event this frame
|
||||
if (platform.touchActive[platform.touchSlot] && touchAction == -1) touchAction = 2; // TOUCH_ACTION_MOVE
|
||||
}
|
||||
}
|
||||
|
||||
if (event.code == ABS_MT_TRACKING_ID)
|
||||
{
|
||||
if ((event.value < 0) && (platform.touchSlot < MAX_TOUCH_POINTS))
|
||||
if (platform.touchSlot < MAX_TOUCH_POINTS)
|
||||
{
|
||||
// Touch has ended for this point
|
||||
CORE.Input.Touch.position[platform.touchSlot].x = -1;
|
||||
CORE.Input.Touch.position[platform.touchSlot].y = -1;
|
||||
if (event.value >= 0)
|
||||
{
|
||||
|
||||
platform.touchActive[platform.touchSlot] = true;
|
||||
platform.touchId[platform.touchSlot] = event.value; // Use Tracking ID for unique IDs
|
||||
|
||||
touchAction = 1; // TOUCH_ACTION_DOWN
|
||||
}
|
||||
else
|
||||
{
|
||||
// Touch has ended for this point
|
||||
platform.touchActive[platform.touchSlot] = false;
|
||||
platform.touchPosition[platform.touchSlot].x = -1;
|
||||
platform.touchPosition[platform.touchSlot].y = -1;
|
||||
platform.touchId[platform.touchSlot] = -1;
|
||||
|
||||
// Force UP action if we haven't already set a DOWN action
|
||||
// (DOWN takes priority over UP if both happen in one frame, though rare)
|
||||
if (touchAction != 1) touchAction = 0; // TOUCH_ACTION_UP
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// Handle ABS_MT_PRESSURE (0x3a) if available, as some devices use it for lift-off
|
||||
#ifndef ABS_MT_PRESSURE
|
||||
#define ABS_MT_PRESSURE 0x3a
|
||||
#endif
|
||||
if (event.code == ABS_MT_PRESSURE)
|
||||
{
|
||||
if (platform.touchSlot < MAX_TOUCH_POINTS)
|
||||
{
|
||||
if (event.value <= 0) // Pressure 0 means lift
|
||||
{
|
||||
platform.touchActive[platform.touchSlot] = false;
|
||||
platform.touchPosition[platform.touchSlot].x = -1;
|
||||
platform.touchPosition[platform.touchSlot].y = -1;
|
||||
platform.touchId[platform.touchSlot] = -1;
|
||||
if (touchAction != 1) touchAction = 0; // TOUCH_ACTION_UP
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@ -2320,16 +2424,15 @@ static void PollMouseEvents(void)
|
||||
if (!event.value && previousMouseLeftButtonState)
|
||||
{
|
||||
platform.currentButtonStateEvdev[MOUSE_BUTTON_LEFT] = 0;
|
||||
touchAction = 0; // TOUCH_ACTION_UP
|
||||
if (touchAction != 1) touchAction = 0; // TOUCH_ACTION_UP
|
||||
}
|
||||
|
||||
if (event.value && !previousMouseLeftButtonState)
|
||||
{
|
||||
platform.currentButtonStateEvdev[MOUSE_BUTTON_LEFT] = 1;
|
||||
touchAction = 1; // TOUCH_ACTION_DOWN
|
||||
touchAction = 1; // TOUCH_ACTION_DOWN
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
// Button parsing
|
||||
@ -2340,8 +2443,43 @@ static void PollMouseEvents(void)
|
||||
{
|
||||
platform.currentButtonStateEvdev[MOUSE_BUTTON_LEFT] = event.value;
|
||||
|
||||
if (event.value > 0) touchAction = 1; // TOUCH_ACTION_DOWN
|
||||
else touchAction = 0; // TOUCH_ACTION_UP
|
||||
if (event.value > 0)
|
||||
{
|
||||
bool activateSlot0 = false;
|
||||
|
||||
if (event.code == BTN_LEFT) activateSlot0 = true; // Mouse click always activates
|
||||
else if (event.code == BTN_TOUCH)
|
||||
{
|
||||
bool anyActive = false;
|
||||
for (int i = 0; i < MAX_TOUCH_POINTS; i++)
|
||||
{
|
||||
if (platform.touchActive[i]) { anyActive = true; break; }
|
||||
}
|
||||
|
||||
if (!anyActive) activateSlot0 = true;
|
||||
}
|
||||
|
||||
if (activateSlot0)
|
||||
{
|
||||
platform.touchActive[0] = true;
|
||||
platform.touchId[0] = 0;
|
||||
}
|
||||
|
||||
touchAction = 1; // TOUCH_ACTION_DOWN
|
||||
}
|
||||
else
|
||||
{
|
||||
// Only clear touch 0 for actual mouse clicks (BTN_LEFT)
|
||||
if (event.code == BTN_LEFT)
|
||||
{
|
||||
platform.touchActive[0] = false;
|
||||
platform.touchPosition[0].x = -1;
|
||||
platform.touchPosition[0].y = -1;
|
||||
}
|
||||
else if (event.code == BTN_TOUCH) platform.touchSlot = 0; // Reset slot index to 0
|
||||
|
||||
touchAction = 0; // TOUCH_ACTION_UP
|
||||
}
|
||||
}
|
||||
|
||||
if (event.code == BTN_RIGHT) platform.currentButtonStateEvdev[MOUSE_BUTTON_RIGHT] = event.value;
|
||||
@ -2356,24 +2494,40 @@ static void PollMouseEvents(void)
|
||||
if (!CORE.Input.Mouse.cursorLocked)
|
||||
{
|
||||
if (CORE.Input.Mouse.currentPosition.x < 0) CORE.Input.Mouse.currentPosition.x = 0;
|
||||
if (CORE.Input.Mouse.currentPosition.x > CORE.Window.screen.width/CORE.Input.Mouse.scale.x) CORE.Input.Mouse.currentPosition.x = CORE.Window.screen.width/CORE.Input.Mouse.scale.x;
|
||||
if (CORE.Input.Mouse.currentPosition.x > CORE.Window.screen.width/CORE.Input.Mouse.scale.x)
|
||||
CORE.Input.Mouse.currentPosition.x = CORE.Window.screen.width/CORE.Input.Mouse.scale.x;
|
||||
|
||||
if (CORE.Input.Mouse.currentPosition.y < 0) CORE.Input.Mouse.currentPosition.y = 0;
|
||||
if (CORE.Input.Mouse.currentPosition.y > CORE.Window.screen.height/CORE.Input.Mouse.scale.y) CORE.Input.Mouse.currentPosition.y = CORE.Window.screen.height/CORE.Input.Mouse.scale.y;
|
||||
if (CORE.Input.Mouse.currentPosition.y > CORE.Window.screen.height/CORE.Input.Mouse.scale.y)
|
||||
CORE.Input.Mouse.currentPosition.y = CORE.Window.screen.height/CORE.Input.Mouse.scale.y;
|
||||
}
|
||||
|
||||
// Update touch point count
|
||||
CORE.Input.Touch.pointCount = 0;
|
||||
// Repack active touches into CORE.Input.Touch
|
||||
int k = 0;
|
||||
for (int i = 0; i < MAX_TOUCH_POINTS; i++)
|
||||
{
|
||||
if (CORE.Input.Touch.position[i].x >= 0) CORE.Input.Touch.pointCount++;
|
||||
if (platform.touchActive[i])
|
||||
{
|
||||
CORE.Input.Touch.position[k] = platform.touchPosition[i];
|
||||
CORE.Input.Touch.pointId[k] = platform.touchId[i];
|
||||
k++;
|
||||
}
|
||||
}
|
||||
|
||||
CORE.Input.Touch.pointCount = k;
|
||||
|
||||
// Clear remaining slots
|
||||
for (int i = k; i < MAX_TOUCH_POINTS; i++)
|
||||
{
|
||||
CORE.Input.Touch.position[i].x = -1;
|
||||
CORE.Input.Touch.position[i].y = -1;
|
||||
CORE.Input.Touch.pointId[i] = -1;
|
||||
}
|
||||
|
||||
#if defined(SUPPORT_GESTURES_SYSTEM)
|
||||
if (touchAction > -1)
|
||||
{
|
||||
GestureEvent gestureEvent = { 0 };
|
||||
|
||||
gestureEvent.touchAction = touchAction;
|
||||
gestureEvent.pointCount = CORE.Input.Touch.pointCount;
|
||||
|
||||
@ -2384,7 +2538,6 @@ static void PollMouseEvents(void)
|
||||
}
|
||||
|
||||
ProcessGestureEvent(gestureEvent);
|
||||
|
||||
touchAction = -1;
|
||||
}
|
||||
#endif
|
||||
|
||||
Reference in New Issue
Block a user