Esempio n. 1
0
void ScrollView::interceptTouchEvent(Widget::TouchEventType event, Widget *sender,Touch* touch)
{
    if(!_touchEnabled)
    {
        Layout::interceptTouchEvent(event, sender, touch);
        return;
    }
    if(_direction == Direction::NONE)
        return;

    Vec2 touchPoint = touch->getLocation();
    switch (event)
    {
        case TouchEventType::BEGAN:
        {
            _isInterceptTouch = true;
            _touchBeganPosition = touch->getLocation();
            handlePressLogic(touch);
        }
        break;
        case TouchEventType::MOVED:
        {
            _touchMovePosition = touch->getLocation();
            // calculates move offset in points
            float offsetInInch = 0;
            switch (_direction)
            {
                case Direction::HORIZONTAL:
                    offsetInInch = convertDistanceFromPointToInch(Vec2(fabs(sender->getTouchBeganPosition().x - touchPoint.x), 0));
                    break;
                case Direction::VERTICAL:
                    offsetInInch = convertDistanceFromPointToInch(Vec2(0, fabs(sender->getTouchBeganPosition().y - touchPoint.y)));
                    break;
                case Direction::BOTH:
                    offsetInInch = convertDistanceFromPointToInch(sender->getTouchBeganPosition() - touchPoint);
                    break;
                default:
                    break;
            }
            if (offsetInInch > _childFocusCancelOffsetInInch)
            {
                sender->setHighlighted(false);
                handleMoveLogic(touch);
            }
        }
        break;

        case TouchEventType::CANCELED:
        case TouchEventType::ENDED:
        {
            _touchEndPosition = touch->getLocation();
            handleReleaseLogic(touch);
            if (sender->isSwallowTouches())
            {
                _isInterceptTouch = false;
            }
        }
        break;
    }
}
Esempio n. 2
0
void HFViewport::onTouchesMoved(const std::vector<Touch*>& pTouches, Event *pEvent)
{
    if (notMove) {
        return;
    }
    CC_ASSERT(this->m_TargetNode);
    if( m_TargetNode == NULL )
        return;
    
    vector<CCTouch*> tmpTouches;
    auto tmpIt = pTouches.begin();
    while (tmpIt != pTouches.end()) {
        auto tmpTouch = dynamic_cast<CCTouch*>(*tmpIt);
        if (mFingerMap.find(tmpTouch->getID()) != mFingerMap.end()) {
            tmpTouches.push_back(tmpTouch);
        }
        ++tmpIt;
    }
    switch(tmpTouches.size())
    {
        case 1:
        {
            CCTouch* ptouch = *tmpTouches.begin();
            if (!m_bTouchMoved && !moveableCheck(ptouch)) {
                return;
            }
            
            CC_BREAK_IF(this->mTouchMode != TouchMode_Scroll);
            
            if (!mForceStopScroll && mMovable) {
                CCPoint newPoint, moveDistance;
                stepScroll(ptouch);
                m_tTouchTime = getNowTime();
                newPoint     = this->convertTouchToNodeSpace(ptouch);
                moveDistance = ccpSub(newPoint, m_tTouchPoint);
                
                if (!mIsProcessingScroll) {
                    m_tTouchPoint = CCPointZero;
                }
                
                float dis = 0.0f;
                dis = sqrtf(moveDistance.x*moveDistance.x + moveDistance.y*moveDistance.y);
                
                if (fabs(convertDistanceFromPointToInch(dis)) < MOVE_INCH )
                {
                    //CCLOG("Invalid movement, distance = [%f, %f], disInch = %f", moveDistance.x, moveDistance.y);
                    return;
                }
                if (!m_bTouchMoved)
                {
                    moveDistance = CCPointZero;
                }
                m_tTouchPoint = newPoint;
                m_bTouchMoved = true;
                m_tScrollDistance = moveDistance;
                
            }
        }
            break;
        case 2:
            CC_BREAK_IF(this->mTouchMode != TouchMode_Zoom);
            do
            {
                CCTouch* objTouch1 = *tmpTouches.begin();
                CCTouch* objTouch2 = tmpTouches.back();
                stepZoom(objTouch1->getLocation(), objTouch2->getLocation());
            }
            while(0);
            break;
        default:
            CCLOG("move:Touch not support with %d fingers", pTouches.size());
            mFingerMap.clear();
    }
}
Esempio n. 3
0
void ScrollView::onTouchMoved(Touch* touch, Event* event)
{
    if (!this->isVisible())
    {
        return;
    }

    if (std::find(_touches.begin(), _touches.end(), touch) != _touches.end())
    {
        if (_touches.size() == 1 && _dragging)
        { // scrolling
            Vec2 moveDistance, newPoint;
            Rect  frame;
            float newX, newY;
            
            frame = getViewRect();

            newPoint     = this->convertTouchToNodeSpace(_touches[0]);
            moveDistance = newPoint - _touchPoint;
            
            float dis = 0.0f;
            if (_direction == Direction::VERTICAL)
            {
                dis = moveDistance.y;
                float pos = _container->getPosition().y;
                if (!(minContainerOffset().y <= pos && pos <= maxContainerOffset().y)) {
                    moveDistance.y *= BOUNCE_BACK_FACTOR;
                }
            }
            else if (_direction == Direction::HORIZONTAL)
            {
                dis = moveDistance.x;
                float pos = _container->getPosition().x;
                if (!(minContainerOffset().x <= pos && pos <= maxContainerOffset().x)) {
                    moveDistance.x *= BOUNCE_BACK_FACTOR;
                }
            }
            else
            {
                dis = sqrtf(moveDistance.x*moveDistance.x + moveDistance.y*moveDistance.y);
                
                float pos = _container->getPosition().y;
                if (!(minContainerOffset().y <= pos && pos <= maxContainerOffset().y)) {
                    moveDistance.y *= BOUNCE_BACK_FACTOR;
                }
                
                pos = _container->getPosition().x;
                if (!(minContainerOffset().x <= pos && pos <= maxContainerOffset().x)) {
                    moveDistance.x *= BOUNCE_BACK_FACTOR;
                }
            }

            if (!_touchMoved && fabs(convertDistanceFromPointToInch(dis)) < MOVE_INCH )
            {
                //CCLOG("Invalid movement, distance = [%f, %f], disInch = %f", moveDistance.x, moveDistance.y);
                return;
            }
            
            if (!_touchMoved)
            {
                moveDistance = Vec2::ZERO;
            }
            
            _touchPoint = newPoint;
            _touchMoved = true;
            
            if (_dragging)
            {
                switch (_direction)
                {
                    case Direction::VERTICAL:
                        moveDistance = Vec2(0.0f, moveDistance.y);
                        break;
                    case Direction::HORIZONTAL:
                        moveDistance = Vec2(moveDistance.x, 0.0f);
                        break;
                    default:
                        break;
                }

                newX     = _container->getPosition().x + moveDistance.x;
                newY     = _container->getPosition().y + moveDistance.y;

                _scrollDistance = moveDistance;
                this->setContentOffset(Vec2(newX, newY));
            }
        }
        else if (_touches.size() == 2 && !_dragging)
        {
            const float len = _container->convertTouchToNodeSpace(_touches[0]).getDistance(
                                            _container->convertTouchToNodeSpace(_touches[1]));
            this->setZoomScale(this->getZoomScale()*len/_touchLength);
        }
    }
}
Esempio n. 4
0
void LotteryRotateView::onTouchMoved(CCTouch* touch, CCEvent* event)
{
    if (!this->isVisible())
    {
        return;
    }
    if (m_rotating)
    {
        return;
    }
    if (!m_enabled) {
        return;
    }
    
    if (m_pTouches->containsObject(touch))
    {
        if (m_pTouches->count() == 1 && m_bDragging)
        {
            // scrolling
            CCPoint moveDistance;
            CCPoint lastPoint = touch->getPreviousLocation();
            CCPoint nowPoint = touch->getLocation();
            lastPoint = m_pContainer->convertToNodeSpace(lastPoint);
            nowPoint = m_pContainer->convertToNodeSpace(nowPoint);
            CCPoint lastLine = ccpSub(lastPoint, ccp(0, 0));
            CCPoint nowLine = ccpSub(nowPoint, ccp(0, 0));
            
            CCPoint startPoint = m_pContainer->convertToNodeSpace(touch->getStartLocation());
            float angle = CC_RADIANS_TO_DEGREES(ccpSub(nowPoint, startPoint).getAngle());
            CCLOG("angle:%f", angle);
            if (abs(angle) >= 60 && abs(angle) <= 120)
            {
                return;
            }
            
            moveDistance = ccpSub(nowPoint, m_tTouchPoint);
            if (!m_bTouchMoved)
            {
                moveDistance = CCPointZero;
            }
            
            m_tTouchPoint = nowPoint;
            m_bTouchMoved = true;
            float dis = 0.0f;
            dis = sqrtf(moveDistance.x*moveDistance.x + moveDistance.y*moveDistance.y);

            float inch = convertDistanceFromPointToInch(dis);
            if (!m_bTouchMoved && fabs(inch) < MOVE_INCH )
            {
                CCLOG("Invalid movement, distance = [%f, %f], disInch = %f", moveDistance.x, moveDistance.y, inch);
                m_pTouches->removeObject(touch);
                return;
            }
            m_lastTouchMoveTime = clock() / 1000;
            
            float angleGap = nowLine.getAngle(lastLine);
//            CCLOG("angleGap:%f", angleGap);
            setRotationAngle(-angleGap);
            
            m_tScrollAngel = CC_RADIANS_TO_DEGREES(-angleGap);
            
            if (m_tScrollAngel>=-360 && m_tScrollAngel<=-180) {
                m_tScrollAngel = m_tScrollAngel + 360;
            }
            else if (m_tScrollAngel<=360 && m_tScrollAngel>=180) {
                m_tScrollAngel = 360 - m_tScrollAngel;
            }
            
            this->setContentOffsetForMove();
        }
    }
}