Esempio n. 1
0
        void ProcessFingerPress(HitTestEvent hitInfo, bool isNewTouch, int cacheIndex,
                                out Entity down, out Entity clicked)
        {
            down    = Entity.Null;
            clicked = Entity.Null;

            if (isNewTouch)
            {
                // account for touch events that are within a single frame
                if (hitInfo.Touch.phase == TouchState.Ended)
                {
                    clicked = hitInfo.e;
                }
                else
                {
                    // ok to mutate array, since we are adding to the end.
                    cachedTouches.Add(new TouchInfo
                    {
                        touch = hitInfo.Touch,
                        e     = hitInfo.e,
                        eligibleForClickOrPressState = true,
                        inputDown = true
                    });

                    down = hitInfo.e;
                }
            }
            else
            {
                var cachedTouchInfo = cachedTouches[cacheIndex];
                if (cachedTouchInfo.eligibleForClickOrPressState)
                {
                    // validate that finger hasn't left box
                    // if it has, current touch is no longer eligible for triggering clicked / pressed state
                    if (hitInfo.e != cachedTouchInfo.e)
                    {
                        cachedTouchInfo.eligibleForClickOrPressState = false;
                        cachedTouches[cacheIndex] = cachedTouchInfo;
                        return;
                    }

                    // haven't left original box, continue pressed state or trigger a click
                    if (hitInfo.Touch.phase == TouchState.Ended)
                    {
                        clicked = hitInfo.e;
                    }
                    else
                    {
                        down = hitInfo.e;
                    }
                }
            }
        }
Esempio n. 2
0
        void ProcessFirstMouse(HitTestEvent hitInfo, out Entity down)
        {
            cachedTouches.Add(new TouchInfo
            {
                touch = hitInfo.Touch,
                e     = hitInfo.e,
                eligibleForClickOrPressState = true,
                inputDown = (hitInfo.InputDown > 0)
            });

            down = hitInfo.Down ? hitInfo.e : Entity.Null;
        }
Esempio n. 3
0
        void ProcessMouseInput(HitTestEvent hitInfo, int cacheIndex,
                               out Entity down, out Entity clicked, out Entity hover)
        {
            down    = Entity.Null;
            clicked = Entity.Null;
            hover   = Entity.Null;

            if (hitInfo.Up)
            {
                hover = hitInfo.e;
            }

            if (cacheIndex < 0)
            {
                ProcessFirstMouse(hitInfo, out down);
                return;
            }

            var cachedInfo = cachedTouches[cacheIndex];

            if (cachedInfo.eligibleForClickOrPressState)
            {
                if (hitInfo.Up)
                {
                    if (hitInfo.e == cachedInfo.e && cachedInfo.inputDown)
                    {
                        clicked = hitInfo.e;
                    }
                }
                else if (hitInfo.Down)
                {
                    if (hitInfo.e != cachedInfo.e && cachedInfo.inputDown)
                    {
                        cachedInfo.eligibleForClickOrPressState = false;
                        cachedTouches[cacheIndex] = cachedInfo;
                        return;
                    }

                    cachedInfo.e = hitInfo.e;
                    down         = hitInfo.e;
                }
            }

            if (hitInfo.Up)
            {
                cachedInfo.eligibleForClickOrPressState = true;
            }

            cachedInfo.inputDown      = (hitInfo.InputDown > 0);
            cachedTouches[cacheIndex] = cachedInfo;
        }
Esempio n. 4
0
        /**
         * Checks to see the if the entity has been pressed and the finger or mouse that clicked it is still
         * down. For example, if a user presses a button then drags their finger out of the button transform,
         * this will remain true for the button entity until the finger or mouse is released.
         */
        internal bool IsPressOnSelectedEntityActive(Entity e, out HitTestEvent outEvent)
        {
            foreach (var cachedEvent in cachedTouches)
            {
                if (e == cachedEvent.e && HitsContainsFingerId(cachedEvent.touch.fingerId, out var index))
                {
                    outEvent = hitTestEvents[index];
                    return(true);
                }
            }

            outEvent = default;
            return(false);
        }