Ejemplo n.º 1
0
void CCEGLViewProtocol::handleTouchesBegin(int num, int ids[], float xs[], float ys[])
{
    for (int i = 0; i < num; ++i)
    {
        int id = ids[i];
        float x = xs[i];
        float y = ys[i];

        std::map<int,int>::iterator pIndex = s_TouchesIntergerDict.find(id);
        int nUnusedIndex = 0;

        // it is a new touch
        if (pIndex == s_TouchesIntergerDict.end())
        {
            nUnusedIndex = getUnUsedIndex();

            // The touches is more than MAX_TOUCHES ?
            if (nUnusedIndex == -1) {
                CCLOG("The touches is more than MAX_TOUCHES, nUnusedIndex = %d", nUnusedIndex);
                continue;
            }

            s_TouchesIntergerDict[id] = nUnusedIndex;

            CCEvent touchEvent;
            touchEvent.Type = CCEvent::TouchBegan;
            touchEvent.Touch.TouchId = nUnusedIndex;
            touchEvent.Touch.X = (x - m_obViewPortRect.origin.x) / m_fScaleX;// * scaleFactor;
            touchEvent.Touch.Y = (y - m_obViewPortRect.origin.y) / m_fScaleY;// * scaleFactor;

            CCDirector::sharedDirector()->pushEvent(touchEvent);
        }
    }
}
Ejemplo n.º 2
0
void CCEGLViewProtocol::handleTouchesBegin(int num, int ids[], float xs[],
										   float ys[])
{
	CCSet set;
	for (int i = 0; i < num; ++i)
	{
		int id = ids[i];
		float x = xs[i];
		float y = ys[i];

		CCInteger* pIndex = (CCInteger*) s_TouchesIntergerDict.objectForKey(id);
		int nUnusedIndex = 0;

		// it is a new touch
		if (pIndex == NULL)
		{
			nUnusedIndex = getUnUsedIndex();

			// The touches is more than MAX_TOUCHES ?
			if (nUnusedIndex == -1)
			{
				CCLOG("The touches is more than MAX_TOUCHES, nUnusedIndex = %d",
					nUnusedIndex);
				continue;
			}

			CCTouch* pTouch = s_pTouches[nUnusedIndex] = new CCTouch();
			if (m_bIsRetinaEnabled)
			{
				// on iOS, though retina is enabled, the value got from os is also 
				// relative to its original size
				pTouch->setTouchInfo(nUnusedIndex,
					(x - m_obViewPortRect.origin.x),
					(y - m_obViewPortRect.origin.y));
			}
			else
			{
				pTouch->setTouchInfo(nUnusedIndex,
					(x - m_obViewPortRect.origin.x) / m_fScaleX,
					(y - m_obViewPortRect.origin.y) / m_fScaleY);
			}

			//CCLOG("x = %f y = %f", pTouch->getLocationInView().x, pTouch->getLocationInView().y);

			CCInteger* pInterObj = new CCInteger(nUnusedIndex);
			s_TouchesIntergerDict.setObject(pInterObj, id);
			set.addObject(pTouch);
			pInterObj->release();
		}
	}

	if (set.count() == 0)
	{
		CCLOG("touchesBegan: count = 0");
		return;
	}

	m_pDelegate->touchesBegan(&set, NULL);
}
Ejemplo n.º 3
0
void CCEGLViewProtocol::handleTouchesBegin(int num, int ids[], float xs[], float ys[])
{
    CCSet set;
    for (int i = 0; i < num; ++i)
    {
        int id = ids[i];
        float x = xs[i];
        float y = ys[i];

        CCInteger* pIndex = (CCInteger*)s_TouchesIntergerDict.objectForKey(id);
        int nUnusedIndex = 0;

        // it is a new touch
        if (pIndex == NULL)
        {
            nUnusedIndex = getUnUsedIndex();

            // The touches is more than MAX_TOUCHES ?
            if (nUnusedIndex == -1) {
                CCLOG("The touches is more than MAX_TOUCHES, nUnusedIndex = %d", nUnusedIndex);
                continue;
            }

            CCTouch* pTouch = s_pTouches[nUnusedIndex] = new CCTouch();
			pTouch->setTouchInfo(nUnusedIndex, (x - m_obViewPortRect.origin.x) / m_fScaleX, 
                                     (y - m_obViewPortRect.origin.y) / m_fScaleY);
            
            //CCLOG("x = %f y = %f", pTouch->getLocationInView().x, pTouch->getLocationInView().y);
            
            CCInteger* pInterObj = new CCInteger(nUnusedIndex);
            s_TouchesIntergerDict.setObject(pInterObj, id);
            set.addObject(pTouch);
            pInterObj->release();
        }
    }

    if (set.count() == 0)
    {
        CCLOG("touchesBegan: count = 0");
        return;
    }

    CCEvent event;
    CCSet *allTouches= new CCSet;
    allTouches->autorelease();
    getCurrentSetOfTouches(*allTouches);
    event.setAllTouches(allTouches);
    m_pDelegate->touchesBegan(&set, &event);
}
Ejemplo n.º 4
0
void EGLViewProtocol::handleTouchesBegin(int num, int ids[], float xs[], float ys[])
{
    int id = 0;
    float x = 0.0f;
    float y = 0.0f;
    int unusedIndex = 0;
    EventTouch touchEvent;
    
    for (int i = 0; i < num; ++i)
    {
        id = ids[i];
        x = xs[i];
        y = ys[i];

        auto iter = g_touchIdReorderMap.find(id);
        unusedIndex = 0;

        // it is a new touch
        if (iter == g_touchIdReorderMap.end())
        {
            unusedIndex = getUnUsedIndex();

            // The touches is more than MAX_TOUCHES ?
            if (unusedIndex == -1) {
                CCLOG("The touches is more than MAX_TOUCHES, unusedIndex = %d", unusedIndex);
                continue;
            }

            Touch* touch = g_touches[unusedIndex] = new Touch();
			touch->setTouchInfo(unusedIndex, (x - _viewPortRect.origin.x) / _scaleX,
                                     (y - _viewPortRect.origin.y) / _scaleY);
            
            CCLOGINFO("x = %f y = %f", pTouch->getLocationInView().x, pTouch->getLocationInView().y);
            
            g_touchIdReorderMap.insert(std::make_pair(id, unusedIndex));
            touchEvent._touches.push_back(touch);
        }
    }

    if (touchEvent._touches.size() == 0)
    {
        CCLOG("touchesBegan: size = 0");
        return;
    }
    
    touchEvent._eventCode = EventTouch::EventCode::BEGAN;
    auto dispatcher = Director::getInstance()->getEventDispatcher();
    dispatcher->dispatchEvent(&touchEvent);
}
Ejemplo n.º 5
0
void EGLViewProtocol::handleTouchesBegin(int num, int ids[], float xs[], float ys[])
{
    Set set;
    for (int i = 0; i < num; ++i)
    {
        int id = ids[i];
        float x = xs[i];
        float y = ys[i];

        Integer* pIndex = (Integer*)s_TouchesIntergerDict.objectForKey(id);
        int nUnusedIndex = 0;

        // it is a new touch
        if (pIndex == NULL)
        {
            nUnusedIndex = getUnUsedIndex();

            // The touches is more than MAX_TOUCHES ?
            if (nUnusedIndex == -1) {
                CCLOG("The touches is more than MAX_TOUCHES, nUnusedIndex = %d", nUnusedIndex);
                continue;
            }

            Touch* pTouch = s_pTouches[nUnusedIndex] = new Touch();
			pTouch->setTouchInfo(nUnusedIndex, (x - _viewPortRect.origin.x) / _scaleX, 
                                     (y - _viewPortRect.origin.y) / _scaleY);
            
            //CCLOG("x = %f y = %f", pTouch->getLocationInView().x, pTouch->getLocationInView().y);
            
            Integer* pInterObj = new Integer(nUnusedIndex);
            s_TouchesIntergerDict.setObject(pInterObj, id);
            set.addObject(pTouch);
            pInterObj->release();
        }
    }

    if (set.count() == 0)
    {
        CCLOG("touchesBegan: count = 0");
        return;
    }

    _delegate->touchesBegan(&set, NULL);
}
Ejemplo n.º 6
0
void CCEGLViewProtocol::handleTouchesBegin(int num, int ids[], float xs[], float ys[])
{
    CCSet set;
    for (int i = 0; i < num; ++i)
    {
        int id = ids[i];
        float x = xs[i];
        float y = ys[i];

        int nUnusedIndex = 0;

        // it is a new touch
        if (s_TouchesIntergerDict.find(id) == s_TouchesIntergerDict.end())
        {
            nUnusedIndex = getUnUsedIndex();

            // The touches is more than MAX_TOUCHES ?
            if (nUnusedIndex == -1)
            {
                CCLOG("The touches is more than MAX_TOUCHES, nUnusedIndex = %d", nUnusedIndex);
                continue;
            }

            CATouch* pTouch = s_pTouches[nUnusedIndex] = new CATouch();
            pTouch->setTouchInfo(nUnusedIndex,
                                 (x - m_obViewPortRect.origin.x) / m_fScaleX,
                                 (y - m_obViewPortRect.origin.y) / m_fScaleY);


            s_TouchesIntergerDict.insert(std::make_pair(id, nUnusedIndex));
            set.addObject(pTouch);
        }
    }

    if (set.count() == 0)
    {
        CCLOG("touchesBegan: count = 0");
        return;
    }

    m_pDelegate->touchesBegan(&set, NULL);
}
Ejemplo n.º 7
0
bool TouchPool::handleTouch(TouchTrigger::TouchAction action,int num,intptr_t ids[],float xs[],float ys[])
{
    intptr_t id = 0;
    float x = 0.0f;
    float y = 0.0f;
    int unusedIndex = 0;
    TouchTrigger touchTrigger;

    for(int i=0;i<num;i++)
    {
        id = ids[i];
        x = xs[i];
        y = ys[i];


        auto iter = _touchIdReorderMap.find(id);

        // it is a new touch
        if (iter == _touchIdReorderMap.end())
        {
             if(action != TouchTrigger::TouchAction::DOWN)
             {
                 FKLOG("if the index doesn't exist, it is an error");
                 continue;
             }

            FKLOG("id = %ld",(long int) id);
            unusedIndex = getUnUsedIndex();

             // The touches is more than MAX_TOUCHES ?
             if (unusedIndex == -1) {
                   FKLOG("The touches is more than MAX_TOUCHES, unusedIndex = %d", unusedIndex);
                   continue;
             }

             Touch* touch = _touches[unusedIndex] = new (std::nothrow) Touch();
             touch->setTouchInfo(unusedIndex, x, y);

             FKLOG("x = %f y = %f", touch->getLocationInView().x, touch->getLocationInView().y);

             _touchIdReorderMap.insert(std::make_pair(id, unusedIndex));
             touchTrigger._touches.push_back(touch);

         }
        else
        {
            FKLOG("unusedindex = %d", iter->second);
            FKLOG("other x = %f y = %f", x, y);
            Touch* touch = _touches[iter->second];
            if (touch)
            {
                  touch->setTouchInfo(iter->second, x, y);

                  touchTrigger._touches.push_back(touch);

                  if(action == TouchTrigger::TouchAction::UP || action == TouchTrigger::TouchAction::CANCEL)
                  {
                      _touches[iter->second] = nullptr;
                      removeUsedIndexBit(iter->second);

                      _touchIdReorderMap.erase(id);

                  }
            }
            else
            {
                // It is error, should return.
                FKLOG("Moving touches with id: %ld error", (long int)id);
                return false;
            }

        }

    }

    if (touchTrigger._touches.size() == 0)
    {
         FKLOG("touches: size = 0");
         return false;
    }

    touchTrigger.setAction(action);
    
    bool result = dispatchTouch(&touchTrigger);
	
    if(action == TouchTrigger::TouchAction::UP || action == TouchTrigger::TouchAction::CANCEL)
    {
        for (auto& touch : touchTrigger._touches)
        {
            // release the touch object.
            touch->release();
        }
    }
    return result;
}