16 public struct MouseButtonInfo {
28 public static ConcurrentQueue<MouseButtonInfo> m_cachedMouseButtonEvents = [];
30 static Vector2 m_queuedMouseMovement;
32 static float m_queuedMouseWheelMovement;
34 static bool m_pointerCaptureRequested;
36 internal static Point2 m_currentMousePosition;
37 internal static Vector2 m_queuedMouseMovement;
38 internal static float m_queuedMouseWheelMovement;
39 static bool m_pointerCaptureRequested;
65 public static event Action<MouseButtonEvent>
MouseDown;
67 public static event Action<MouseButtonEvent>
MouseUp;
70#if !MOBILE && !BROWSER
71 m_mouse.Position =
new System.Numerics.Vector2(x, y);
77 if (Build.VERSION.SdkInt >= (BuildVersionCodes)26) {
78 Window.m_surface.SetOnCapturedPointerListener(
new OnCapturedPointerListener());
94 if (m_pointerCaptureRequested) {
95 m_pointerCaptureRequested =
false;
96 if (Build.VERSION.SdkInt >= (BuildVersionCodes)26) {
97 Window.m_surface?.ReleasePointerCapture();
105 if (!m_pointerCaptureRequested) {
106 m_pointerCaptureRequested =
true;
107 if (Build.VERSION.SdkInt >= (BuildVersionCodes)26) {
108 Window.m_surface?.RequestPointerCapture();
119 m_queuedMouseWheelMovement = 0f;
120 while (!m_cachedMouseButtonEvents.IsEmpty) {
121 if (m_cachedMouseButtonEvents.TryDequeue(out MouseButtonInfo buttonInfo)) {
122 if (buttonInfo.Press) {
137 if (m_pointerCaptureRequested) {
138 m_pointerCaptureRequested =
false;
145 if (!m_pointerCaptureRequested) {
146 m_pointerCaptureRequested =
true;
160 m_queuedMouseWheelMovement = 0f;
166 m_mouse.Cursor.CursorMode = CursorMode.Normal;
171 m_mouse.Cursor.CursorMode = CursorMode.Raw;
177 || position.
X >= windowSize.
X
179 || position.
Y >= windowSize.
Y) {
180 position =
new Point2(windowSize.
X / 2, windowSize.
Y / 2);
192 public static void EnqueueMouseButtonEvent(
MouseButton button,
bool press,
Point2 position) => m_cachedMouseButtonEvents.Enqueue(
new MouseButtonInfo(button, press, position));
195 internal static void HandleMotionEvent(MotionEvent e) {
197 case MotionEventActions.Move: {
198 for (
int num = e.HistorySize - 1; num >= 0; num--) {
199 m_queuedMouseMovement +=
new Vector2(e.GetHistoricalX(num), e.GetHistoricalY(num));
205 case MotionEventActions.ButtonPress:
207 case MotionEventActions.ButtonRelease:
209 case MotionEventActions.PointerIdShift: {
210 for (
int num2 = e.HistorySize - 1; num2 >= 0; num2--) {
211 m_queuedMouseWheelMovement +=
MathUtils.
Sign(e.GetHistoricalAxisValue(Axis.Vscroll, num2));
213 m_queuedMouseWheelMovement += MathUtils.Sign(e.GetAxisValue(Axis.Vscroll));
220 MotionEventButtonState.Primary =>
MouseButton.Left,
221 MotionEventButtonState.Secondary =>
MouseButton.Right,
222 MotionEventButtonState.Tertiary =>
MouseButton.Middle,
224 MotionEventButtonState.Forward =>
MouseButton.Ext2,
225 _ => MouseButton.Left
229 CursorType.Arrow => PointerIconType.Arrow,
230 CursorType.IBeam => PointerIconType.Text,
231 CursorType.Crosshair => PointerIconType.Crosshair,
232 CursorType.Hand => PointerIconType.Hand,
233 CursorType.HResize => PointerIconType.HorizontalDoubleArrow,
234 CursorType.VResize => PointerIconType.VerticalDoubleArrow,
235 CursorType.NwseResize => PointerIconType.TopLeftDiagonalDoubleArrow,
236 CursorType.NeswResize => PointerIconType.TopRightDiagonalDoubleArrow,
237 CursorType.ResizeAll => PointerIconType.AllScroll,
238 CursorType.NotAllowed => PointerIconType.NoDrop,
239 CursorType.Grab => PointerIconType.Grab,
240 CursorType.Grabbing => PointerIconType.Grabbing,
241 _ => PointerIconType.Default
244 public class OnCapturedPointerListener : Java.Lang.Object, View.IOnCapturedPointerListener {
245 public bool OnCapturedPointer(View view, MotionEvent e) {
249 if ((e.Source & InputSourceType.MouseRelative) == InputSourceType.MouseRelative) {
250 HandleMotionEvent(e);
255#elif !IOS && !BROWSER
259 System.Numerics.Vector2 position = mouse.Position;
267 System.Numerics.Vector2 position = mouse.Position;
284 Silk.NET.Input.MouseButton.Left =>
MouseButton.Left,
285 Silk.NET.Input.MouseButton.Right =>
MouseButton.Right,
286 Silk.NET.Input.MouseButton.Middle =>
MouseButton.Middle,
287 Silk.NET.Input.MouseButton.Button4 =>
MouseButton.Ext1,
288 Silk.NET.Input.MouseButton.Button5 =>
MouseButton.Ext2,
305 _ => StandardCursor.Default
348#if !MOBILE && !BROWSER
349 m_mouse.Cursor.CursorMode =
Window.IsActive ? CursorMode.Raw : CursorMode.Normal;
352 m_mouse.Cursor.CursorMode = CursorMode.Normal;
412 if (Build.VERSION.SdkInt >= (BuildVersionCodes)24) {
415#elif !IOS && !BROWSER