@@ -20,6 +20,8 @@ public static void SetPlayWidget( SceneRenderingWidget widget )
2020
2121 widget . Focused += WidgetFocused ;
2222 widget . Blurred += WidgetBlurred ;
23+ widget . MouseTracking = true ;
24+ widget . MouseMove += OnPlayWidgetMouseMove ;
2325
2426 NativeEngine . InputSystem . RegisterWindowWithSDL ( widget . _widget . winId ( ) ) ;
2527 g_pEngineServiceMgr . SetEngineState ( widget . _widget . winId ( ) , widget . SwapChain ) ;
@@ -40,6 +42,8 @@ public static void ClearPlayMode()
4042
4143 _inPlay . Focused -= WidgetFocused ;
4244 _inPlay . Blurred -= WidgetBlurred ;
45+ _inPlay . MouseMove -= OnPlayWidgetMouseMove ;
46+ _inPlay . MouseTracking = false ;
4347
4448 NativeEngine . InputSystem . UnregisterWindowFromSDL ( _inPlay . _widget . winId ( ) ) ;
4549
@@ -68,22 +72,15 @@ private static void WidgetBlurred( FocusChangeReason reason )
6872 NativeEngine . InputSystem . OnEditorGameFocusChange ( _inPlay . _widget . winId ( ) , false ) ;
6973 }
7074
71- internal static void Tick ( )
75+ private static void OnPlayWidgetMouseMove ( Vector2 local )
7276 {
73- // Keep game mouse position updated while the play widget is unfocused.
74- var playWidget = _inPlay ;
75- if ( playWidget is null || playWidget . IsFocused )
76- return ;
77-
78- var local = playWidget . FromScreen ( Application . CursorPosition ) ;
79-
80- // Don't snap to borders if cursor isn't over the widget.
81- if ( local . x < 0 || local . y < 0 || local . x >= playWidget . Size . x || local . y >= playWidget . Size . y )
77+ // SDL handles position when the widget is focused; only fill in the gap when unfocused.
78+ if ( _inPlay is null || _inPlay . IsFocused )
8279 return ;
8380
8481 var pos = new Vector2 ( ( int ) local . x , ( int ) local . y ) ;
8582 var delta = pos - InputRouter . MouseCursorPosition ;
8683
87- InputRouter . ApplyAbsoluteMousePosition ( pos , delta ) ;
84+ InputRouter . OnMousePositionChange ( pos . x , pos . y , delta . x , delta . y ) ;
8885 }
8986}
0 commit comments