Beispiel #1
0
        unsafe void PointerMap(StateEvent *data, InputDevice device)
        {
            switch (device)
            {
            case Mouse mouse:
                MouseState *mouseState = (MouseState *)data->state;
                mouseState->position = Map(mouseState->position, inputRegion, outputRegion);
                break;

            case Touchscreen touch:
                // todo(kazuki): multi touch is not supported yet.
                TouchState *touchState = (TouchState *)data->state;
                touchState->position = Map(touchState->position, inputRegion, outputRegion);
                break;
            }
        }
        /// <summary>
        /// Checks an Input Event for any significant changes that would be considered user activity.
        /// </summary>
        /// <param name="inputEvent">The input event being checked for changes</param>
        /// <param name="device">The input device being checked against </param>
        /// <param name="offset">The offset into the device that the event is placed</param>
        /// <param name="sizeInbytes">The size of the event in bytes</param>
        /// <returns>True if any changes exist in the event once the device has been filtered through for noise and non-significant changes.  False otherwise.</returns>
        public unsafe bool HasValidData(InputDevice device, InputEventPtr inputEvent, uint offset, uint sizeInbytes)
        {
            if (elements.Length == 0)
            {
                return(true);
            }

            if ((offset + sizeInbytes) * 8 > device.stateBlock.sizeInBits)
            {
                return(false);
            }

            bool result = false;

            IntPtr noiseFilterPtr = InputStateBuffers.s_NoiseFilterBuffer;

            if (noiseFilterPtr != IntPtr.Zero)
            {
                IntPtr ptrToEventState = IntPtr.Zero;
                if (inputEvent.IsA <StateEvent>())
                {
                    StateEvent *stateEvent = StateEvent.From(inputEvent);
                    ptrToEventState = stateEvent->state;
                }
                else if (inputEvent.IsA <DeltaStateEvent>())
                {
                    DeltaStateEvent *stateEvent = DeltaStateEvent.From(inputEvent);
                    ptrToEventState = stateEvent->deltaState;
                }

                if (ptrToEventState != IntPtr.Zero)
                {
                    result = BitmaskHelpers.CheckForMaskedValues(ptrToEventState, noiseFilterPtr, offset, sizeInbytes * 8);
                    for (int i = 0; i < elements.Length && !result; i++)
                    {
                        result = elements[i].HasValidData(inputEvent, device);
                    }
                }
            }

            return(result);
        }