HitTest() protected method

protected HitTest ( ) : DisplayObject
return DisplayObject
Esempio n. 1
0
        public override DisplayObject HitTest(Vector2 localPoint, bool forTouch)
        {
            if (_skipRendering)
            {
                return(null);
            }

            if (forTouch && (!visible || !touchable || optimizeNotTouchable))
            {
                return(null);
            }

            if (_clipRect != null && !((Rect)_clipRect).Contains(localPoint))
            {
                return(null);
            }
            else
            {
                int           count  = _children.Count;
                DisplayObject target = null;
                for (int i = count - 1; i >= 0; --i)                 // front to back!
                {
                    DisplayObject child = _children[i];

                    Vector2 v = TransformPoint(localPoint, child);
                    target = child.HitTest(v, forTouch);

                    if (target != null)
                    {
                        break;
                    }
                }

                if (target == null && _hitArea != null)
                {
                    if (((Rect)_hitArea).Contains(localPoint))
                    {
                        target = this;
                    }
                }

                return(target);
            }
        }
Esempio n. 2
0
        override protected internal DisplayObject HitTest(bool forTouch)
        {
            if (!visible || (forTouch && (!touchable || _optimizeNotTouchable)))
            {
                return(null);
            }

            Vector2 localPoint      = new Vector2();
            Vector3 savedWorldPoint = HitTestContext.worldPoint;
            Vector3 savedDirection  = HitTestContext.direction;

            if (hitArea != null)
            {
                if (!hitArea.HitTest(this, ref localPoint))
                {
                    HitTestContext.worldPoint = savedWorldPoint;
                    HitTestContext.direction  = savedDirection;
                    return(null);
                }
            }
            else
            {
                localPoint = GetHitTestLocalPoint();
                if (_clipRect != null && !((Rect)_clipRect).Contains(localPoint))
                {
                    HitTestContext.worldPoint = savedWorldPoint;
                    HitTestContext.direction  = savedDirection;
                    return(null);
                }
            }

            if (_mask != null && _mask.HitTest(false) == null)
            {
                return(null);
            }

            DisplayObject target = null;

            if (touchChildren)
            {
                int count = _children.Count;
                for (int i = count - 1; i >= 0; --i)                 // front to back!
                {
                    DisplayObject child = _children[i];
                    if (child == _mask)
                    {
                        continue;
                    }

                    target = child.HitTest(forTouch);
                    if (target != null)
                    {
                        break;
                    }
                }
            }

            if (target == null && opaque && _contentRect.Contains(localPoint))
            {
                target = this;
            }

            HitTestContext.worldPoint = savedWorldPoint;
            HitTestContext.direction  = savedDirection;

            return(target);
        }