Example #1
0
        public override void TouchMoved(CCTouch touch, CCEvent pEvent)
        {
            if (!Visible)
            {
                return;
            }

            if (m_pTouches.Contains(touch))
            {
                if (m_pTouches.Count == 1 && m_bDragging)
                {
                    // scrolling

                    m_bTouchMoved = true;
                    CCPoint frameOriginal = Parent.ConvertToWorldSpace(Position);
                    var frame = new CCRect(frameOriginal.X, frameOriginal.Y, m_tViewSize.Width, m_tViewSize.Height);
                    CCPoint newPoint = ConvertTouchToNodeSpace(m_pTouches[0]);
                    CCPoint moveDistance = CCPointExtension.Subtract(newPoint, m_tTouchPoint);
                    m_tTouchPoint = newPoint;

                    if (frame.ContainsPoint(ConvertToWorldSpace(newPoint)))
                    {
                        switch (m_eDirection)
                        {
                            case CCScrollViewDirection.Vertical:
                                moveDistance = new CCPoint(0.0f, moveDistance.Y);
                                break;
                            case CCScrollViewDirection.Horizontal:
                                moveDistance = new CCPoint(moveDistance.X, 0.0f);
                                break;
                        }

                        m_pContainer.Position = CCPointExtension.Add(m_pContainer.Position, moveDistance);

                        CCPoint maxInset = m_fMaxInset;
                        CCPoint minInset = m_fMinInset;

                        //check to see if offset lies within the inset bounds
                        float newX = Math.Min(m_pContainer.Position.X, maxInset.X);
                        newX = Math.Max(newX, minInset.X);
                        float newY = Math.Min(m_pContainer.Position.Y, maxInset.Y);
                        newY = Math.Max(newY, minInset.Y);

                        m_tScrollDistance = CCPointExtension.Subtract(moveDistance,
                                                                    new CCPoint(newX - m_pContainer.Position.X, newY - m_pContainer.Position.Y));
                        SetContentOffset(new CCPoint(newX, newY), false);
                    }
                }
                else if (m_pTouches.Count == 2 && !m_bDragging)
                {
                    float len = CCPointExtension.Distance(m_pContainer.ConvertTouchToNodeSpace(m_pTouches[0]),
                                                             m_pContainer.ConvertTouchToNodeSpace(m_pTouches[1]));
                    ZoomScale = ZoomScale * len / m_fTouchLength;
                }
            }
        }
Example #2
0
        /** override functions */
        // optional
        public override bool TouchBegan(CCTouch pTouch, CCEvent pEvent)
        {
            if (!Visible)
            {
                return false;
            }

            CCPoint frameOriginal = Parent.ConvertToWorldSpace(Position);
            var frame = new CCRect(frameOriginal.X, frameOriginal.Y, m_tViewSize.Width, m_tViewSize.Height);

            //dispatcher does not know about clipping. reject touches outside visible bounds.
            if (m_pTouches.Count > 2 ||
                m_bTouchMoved ||
                !frame.ContainsPoint(m_pContainer.ConvertToWorldSpace(m_pContainer.ConvertTouchToNodeSpace(pTouch))))
            {
                return false;
            }

            if (!m_pTouches.Contains(pTouch))
            {
                m_pTouches.Add(pTouch);
            }

            if (m_pTouches.Count == 1)
            {
                // scrolling
                m_tTouchPoint = ConvertTouchToNodeSpace(pTouch);
                m_bTouchMoved = false;
                m_bDragging = true; //dragging started
                m_tScrollDistance = new CCPoint(0.0f, 0.0f);
                m_fTouchLength = 0.0f;
            }
            else if (m_pTouches.Count == 2)
            {
                m_tTouchPoint = CCPointExtension.Midpoint(ConvertTouchToNodeSpace(m_pTouches[0]),
                                                             ConvertTouchToNodeSpace(m_pTouches[1]));
                m_fTouchLength = CCPointExtension.Distance(m_pContainer.ConvertTouchToNodeSpace(m_pTouches[0]),
                                                              m_pContainer.ConvertTouchToNodeSpace(m_pTouches[1]));
                m_bDragging = false;
            }
            return true;
        }