| using System.Runtime.InteropServices; |
| using UnityEngine.InputSystem.Controls; |
| using UnityEngine.InputSystem.Layouts; |
| using UnityEngine.InputSystem.LowLevel; |
| using UnityEngine.InputSystem.Utilities; |
|
|
| |
|
|
| namespace UnityEngine.InputSystem.LowLevel |
| { |
| |
| |
| |
| |
| [StructLayout(LayoutKind.Explicit, Size = 30)] |
| public struct MouseState : IInputStateTypeInfo |
| { |
| |
| |
| |
| |
| |
| public static FourCC Format => new FourCC('M', 'O', 'U', 'S'); |
|
|
| |
| |
| |
| |
| |
| [InputControl(usage = "Point", dontReset = true)] |
| [FieldOffset(0)] |
| public Vector2 position; |
|
|
| |
| |
| |
| |
| |
| [InputControl(usage = "Secondary2DMotion", layout = "Delta")] |
| [FieldOffset(8)] |
| public Vector2 delta; |
|
|
| |
| |
| |
| |
| |
| |
| [InputControl(displayName = "Scroll", layout = "Delta")] |
| [InputControl(name = "scroll/x", aliases = new[] { "horizontal" }, usage = "ScrollHorizontal", displayName = "Left/Right")] |
| [InputControl(name = "scroll/y", aliases = new[] { "vertical" }, usage = "ScrollVertical", displayName = "Up/Down", shortDisplayName = "Wheel")] |
| [FieldOffset(16)] |
| public Vector2 scroll; |
|
|
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| [InputControl(name = "press", useStateFrom = "leftButton", synthetic = true, usages = new string[0])] |
| [InputControl(name = "leftButton", layout = "Button", bit = (int)MouseButton.Left, usage = "PrimaryAction", displayName = "Left Button", shortDisplayName = "LMB")] |
| [InputControl(name = "rightButton", layout = "Button", bit = (int)MouseButton.Right, usage = "SecondaryAction", displayName = "Right Button", shortDisplayName = "RMB")] |
| [InputControl(name = "middleButton", layout = "Button", bit = (int)MouseButton.Middle, displayName = "Middle Button", shortDisplayName = "MMB")] |
| [InputControl(name = "forwardButton", layout = "Button", bit = (int)MouseButton.Forward, usage = "Forward", displayName = "Forward")] |
| [InputControl(name = "backButton", layout = "Button", bit = (int)MouseButton.Back, usage = "Back", displayName = "Back")] |
| [FieldOffset(24)] |
| |
| |
| |
| |
| |
| [InputControl(name = "pressure", layout = "Axis", usage = "Pressure", offset = InputStateBlock.AutomaticOffset, format = "FLT", sizeInBits = 32)] |
| [InputControl(name = "radius", layout = "Vector2", usage = "Radius", offset = InputStateBlock.AutomaticOffset, format = "VEC2", sizeInBits = 64)] |
| [InputControl(name = "pointerId", layout = "Digital", format = "BIT", sizeInBits = 1, offset = InputStateBlock.AutomaticOffset)] |
| public ushort buttons; |
|
|
| |
| |
| |
| [InputControl(name = "displayIndex", layout = "Integer", displayName = "Display Index")] |
| [FieldOffset(26)] |
| public ushort displayIndex; |
|
|
| |
| |
| |
| |
| |
| [InputControl(name = "clickCount", layout = "Integer", displayName = "Click Count", synthetic = true)] |
| [FieldOffset(28)] |
| public ushort clickCount; |
|
|
| |
| |
| |
| |
| |
| |
| |
| public MouseState WithButton(MouseButton button, bool state = true) |
| { |
| Debug.Assert((int)button < 16, $"Expected button < 16, so we fit into the 16 bit wide bitmask"); |
| var bit = 1U << (int)button; |
| if (state) |
| buttons |= (ushort)bit; |
| else |
| buttons &= (ushort)~bit; |
| return this; |
| } |
|
|
| |
| |
| |
| |
| public FourCC format => Format; |
| } |
|
|
| |
| |
| |
| public enum MouseButton |
| { |
| |
| |
| |
| |
| Left, |
|
|
| |
| |
| |
| |
| Right, |
|
|
| |
| |
| |
| |
| Middle, |
|
|
| |
| |
| |
| |
| Forward, |
|
|
| |
| |
| |
| |
| Back |
| } |
| } |
|
|
| namespace UnityEngine.InputSystem |
| { |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| [InputControlLayout(stateType = typeof(MouseState), isGenericTypeOfDevice = true)] |
| public class Mouse : Pointer, IInputStateCallbackReceiver |
| { |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| public DeltaControl scroll { get; protected set; } |
|
|
| |
| |
| |
| |
| public ButtonControl leftButton { get; protected set; } |
|
|
| |
| |
| |
| |
| public ButtonControl middleButton { get; protected set; } |
|
|
| |
| |
| |
| |
| public ButtonControl rightButton { get; protected set; } |
|
|
| |
| |
| |
| |
| |
| |
| |
| public ButtonControl backButton { get; protected set; } |
|
|
| |
| |
| |
| |
| |
| |
| |
| public ButtonControl forwardButton { get; protected set; } |
|
|
| |
| |
| |
| |
| |
| public IntegerControl clickCount { get; protected set; } |
|
|
| |
| |
| |
| |
| |
| public new static Mouse current { get; private set; } |
|
|
| |
| |
| |
| public override void MakeCurrent() |
| { |
| base.MakeCurrent(); |
| current = this; |
| } |
|
|
| |
| |
| |
| protected override void OnAdded() |
| { |
| base.OnAdded(); |
|
|
| if (native && s_PlatformMouseDevice == null) |
| s_PlatformMouseDevice = this; |
| } |
|
|
| |
| |
| |
| protected override void OnRemoved() |
| { |
| base.OnRemoved(); |
| if (current == this) |
| current = null; |
| } |
|
|
| internal static Mouse s_PlatformMouseDevice; |
|
|
| |
| |
| |
| |
| |
| |
| |
| |
| |
| public void WarpCursorPosition(Vector2 position) |
| { |
| var command = WarpMousePositionCommand.Create(position); |
| ExecuteCommand(ref command); |
| } |
|
|
| |
| protected override void FinishSetup() |
| { |
| scroll = GetChildControl<DeltaControl>("scroll"); |
| leftButton = GetChildControl<ButtonControl>("leftButton"); |
| middleButton = GetChildControl<ButtonControl>("middleButton"); |
| rightButton = GetChildControl<ButtonControl>("rightButton"); |
| forwardButton = GetChildControl<ButtonControl>("forwardButton"); |
| backButton = GetChildControl<ButtonControl>("backButton"); |
| displayIndex = GetChildControl<IntegerControl>("displayIndex"); |
| clickCount = GetChildControl<IntegerControl>("clickCount"); |
| base.FinishSetup(); |
| } |
|
|
| |
| |
| |
| protected new void OnNextUpdate() |
| { |
| base.OnNextUpdate(); |
| InputState.Change(scroll, Vector2.zero); |
| } |
|
|
| |
| |
| |
| |
| protected new unsafe void OnStateEvent(InputEventPtr eventPtr) |
| { |
| scroll.AccumulateValueInEvent(currentStatePtr, eventPtr); |
| base.OnStateEvent(eventPtr); |
| } |
|
|
| void IInputStateCallbackReceiver.OnNextUpdate() |
| { |
| OnNextUpdate(); |
| } |
|
|
| void IInputStateCallbackReceiver.OnStateEvent(InputEventPtr eventPtr) |
| { |
| OnStateEvent(eventPtr); |
| } |
| } |
| } |
|
|