Skip to content

Commit 12b055b

Browse files
[Input] Fix Touch input on SDL3 Render Window;
1 parent ba7dba2 commit 12b055b

1 file changed

Lines changed: 51 additions & 14 deletions

File tree

Engine/Staple.Core/Rendering/Windowing/Impls/SDL3RenderWindow.cs

Lines changed: 51 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
using SDL;
22
using System;
33
using System.Collections.Generic;
4+
using System.Numerics;
45
using System.Runtime.InteropServices;
56
using System.Text;
67

@@ -448,36 +449,72 @@ public void PollEvents()
448449
case SDL_EventType.SDL_EVENT_MOUSE_BUTTON_DOWN:
449450
case SDL_EventType.SDL_EVENT_MOUSE_BUTTON_UP:
450451

451-
AppEventQueue.instance.Add(AppEvent.Mouse(_event.button.button switch
452+
if (Platform.IsDesktopPlatform)
452453
{
453-
1 => AppEventMouseButton.Left,
454-
2 => AppEventMouseButton.Middle,
455-
3 => AppEventMouseButton.Right,
456-
4 => AppEventMouseButton.Button1,
457-
5 => AppEventMouseButton.Button2,
458-
_ => 0,
459-
},
454+
AppEventQueue.instance.Add(AppEvent.Mouse(_event.button.button switch
455+
{
456+
1 => AppEventMouseButton.Left,
457+
2 => AppEventMouseButton.Middle,
458+
3 => AppEventMouseButton.Right,
459+
4 => AppEventMouseButton.Button1,
460+
5 => AppEventMouseButton.Button2,
461+
_ => 0,
462+
},
460463
_event.button.down ? AppEventInputState.Press : AppEventInputState.Release,
461464
GetModifiers(SDL3.SDL_GetModState())));
465+
}
462466

463467
break;
464468

465469
case SDL_EventType.SDL_EVENT_MOUSE_MOTION:
466470

467-
if (SDL3.SDL_GetWindowRelativeMouseMode(window))
471+
if(Platform.IsDesktopPlatform)
472+
{
473+
if (SDL3.SDL_GetWindowRelativeMouseMode(window))
474+
{
475+
Input.CursorPosCallback(_event.motion.xrel, _event.motion.yrel);
476+
}
477+
else
478+
{
479+
Input.CursorPosCallback(_event.motion.x, _event.motion.y);
480+
}
481+
}
482+
483+
break;
484+
485+
case SDL_EventType.SDL_EVENT_MOUSE_WHEEL:
486+
487+
if (Platform.IsDesktopPlatform)
468488
{
469-
Input.CursorPosCallback(_event.motion.xrel, _event.motion.yrel);
489+
Input.MouseScrollCallback(_event.wheel.x, _event.wheel.y);
470490
}
471-
else
491+
492+
break;
493+
494+
case SDL_EventType.SDL_EVENT_FINGER_CANCELED:
495+
case SDL_EventType.SDL_EVENT_FINGER_DOWN:
496+
case SDL_EventType.SDL_EVENT_FINGER_UP:
497+
472498
{
473-
Input.CursorPosCallback(_event.motion.x, _event.motion.y);
499+
var size = Size;
500+
501+
AppEventQueue.instance.Add(AppEvent.Touch((int)_event.tfinger.fingerID,
502+
new Vector2((int)(_event.tfinger.x * size.X), (int)(_event.tfinger.y * size.Y)),
503+
(SDL_EventType)_event.type == SDL_EventType.SDL_EVENT_FINGER_DOWN ?
504+
AppEventInputState.Press : AppEventInputState.Release));
474505
}
475506

476507
break;
477508

478-
case SDL_EventType.SDL_EVENT_MOUSE_WHEEL:
509+
case SDL_EventType.SDL_EVENT_FINGER_MOTION:
479510

480-
Input.MouseScrollCallback(_event.wheel.x, _event.wheel.y);
511+
{
512+
var size = Size;
513+
514+
AppEventQueue.instance.Add(AppEvent.Touch((int)_event.tfinger.fingerID,
515+
new Vector2((int)(_event.tfinger.x * size.X), (int)(_event.tfinger.y * size.Y)),
516+
AppEventInputState.Repeat));
517+
}
481518

482519
break;
483520

0 commit comments

Comments
 (0)