给cocos2dx增加windows右键事件

给cocos2dx增加windows右键事件,第1张

概述给quick-cocos2d-x增加windows下模拟器右键,步骤如下 1.修改LRESULT CCEGLView::WindowProc(UINT message, WPARAM wParam, LPARAM lParam),增加右键按下和抬起事件,大体参照左键的抬起和按下,具体代码如下所示: case WM_RBUTTONDOWN: #if(_MSC_VER >= 1600) /

给quick-cocos2d-x增加windows下模拟器右键,步骤如下

1.修改LRESulT CCEGLVIEw::WindowProc(UINT message,WParaM wParam,LParaM lParam),增加右键按下和抬起事件,大体参照左键的抬起和按下,具体代码如下所示:

case WM_RbuttonDOWN:		#if(_MSC_VER >= 1600)			// Don't process message generated by windows touch			if (m_bSupporttouch && (s_pfgetMessageExtraInfoFunction() & MOUSEEVENTF_FROMtouch) == MOUSEEVENTF_FROMtouch) break;		#endif /* #if(_MSC_VER >= 1600) */		if (m_pDelegate && MK_Rbutton == wParam)		{			POINT point = {(short)LOWORD(lParam),(short)HIWORD(lParam)};			CCPoint pt(point.x,point.y);			pt.x /= m_fFrameZoomFactor;			pt.y /= m_fFrameZoomFactor;			CCPoint tmp = ccp(pt.x,m_obScreenSize.height - pt.y);			if (m_obVIEwPortRect.equals(CCRectZero) || m_obVIEwPortRect.containsPoint(tmp))			{				m_bCaptured = true;				SetCapture(m_hWnd);				int ID = 0;				handleR@R_301_5033@Begin(1,&ID,&pt.x,&pt.y);			}		}        break;
2.修改CCEGLVIEwProtocol,添加右键的handle,代码如下
voID CCEGLVIEwProtocol::handleR@R_301_5033@Begin(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_@R_301_5033@IntergerDict.objectForKey(ID);        int nUnusedindex = 0;        // it is a new touch        if (pIndex == NulL)        {            nUnusedindex = getUnUsedindex();            // The @R_301_5033@ is more than MAX_@R_301_5033@ ?            if (nUnusedindex == -1) {                cclOG("The @R_301_5033@ is more than MAX_@R_301_5033@,nUnusedindex = %d",nUnusedindex);                continue;            }            CCtouch* ptouch = s_p@R_301_5033@[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_@R_301_5033@IntergerDict.setobject(pInterObj,ID);            set.addobject(ptouch);            pInterObj->release();        }    }    if (set.count() == 0)    {        cclOG("@R_301_5033@Began: count = 0");        return;    }    m_pDelegate->@R_301_5033@RBegan(&set,NulL);}
3.cctouchdispatcher中添加分发事件,代码如下
voID CCtouchdispatcher::@R_301_5033@RBegan(CCSet *@R_301_5033@,CCEvent *pEvent){    if (m_bdispatchEvents)    {        this->@R_301_5033@(@R_301_5033@,pEvent,CCRtouchBEGAN);    }}
4.修改cctouchdispatcher的touch,添加右键
 if (uIndex == CCtouchBEGAN)                {                    bClaimed = pHandler->getDelegate()->cctouchBegan(ptouch,pEvent);                    if (bClaimed)                    {                        pHandler->getClaimed@R_301_5033@()->addobject(ptouch);                    }				} else if(uIndex == CCRtouchBEGAN){					bClaimed = pHandler->getDelegate()->ccRtouchBegan(ptouch,pEvent);                    if (bClaimed)                    {                        pHandler->getClaimed@R_301_5033@()->addobject(ptouch);                    }				}else                if (pHandler->getClaimed@R_301_5033@()->containsObject(ptouch))                {                    // moved ended canceled                    bClaimed = true;                    switch (sHelper.m_type)                    {                    case CCtouchmoveD:                        pHandler->getDelegate()->cctouchmoved(ptouch,pEvent);                        break;                    case CCtouchendED:                        pHandler->getDelegate()->cctouchended(ptouch,pEvent);                        pHandler->getClaimed@R_301_5033@()->removeObject(ptouch);                        break;                    case CCtouchCANCELLED:                        pHandler->getDelegate()->cctouchCancelled(ptouch,pEvent);                        pHandler->getClaimed@R_301_5033@()->removeObject(ptouch);                        break;					case CCRtouchendED:						pHandler->getDelegate()->ccRtouchended(ptouch,pEvent);                        pHandler->getClaimed@R_301_5033@()->removeObject(ptouch);						break;                    }                }
5.修改添加CCtouchDelegate右键事件:
virtual int ccRtouchBegan(CCtouch *ptouch,CCEvent *pEvent) {		CC_UNUSED_ParaM(ptouch); CC_UNUSED_ParaM(pEvent); return 0;};virtual voID ccRtouchended(CCtouch *ptouch,CCEvent *pEvent) {CC_UNUSED_ParaM(ptouch); CC_UNUSED_ParaM(pEvent);}

6,.为ccnode添加右键事件
int CCNode::ccRtouchBegan(CCtouch *ptouch,CCEvent *pEvent){  if (kScriptTypeNone != m_eScriptType)  {    return excuteScripttouchHandler(CCRtouchBEGAN,ptouch);  }  CC_UNUSED_ParaM(ptouch);  CC_UNUSED_ParaM(pEvent);  CCAssert(false,"Layer#cctouchBegan overrIDe me");<span >	</span>printf("the kCCtouchBegan is %d\n\n",kCCtouchBegan);  return kCCtouchBegan;}
7.千万别忘了在ccScene中重写右键事件,因为ccScene的作用是分发触摸。
int CCScene::ccRtouchBegan(CCtouch *ptouch,CCEvent *pEvent){	   // remove all touch targets    m_touchTargets->removeAllObjects();    // check touch targets    const CCPoint p = ptouch->getLocation();    CCObject *node;    CCNode *touchNode = NulL;    CCNode *checkVisibleNode = NulL;    bool visible = true;    sortAlltouchableNodes(m_touchableNodes);    CCARRAY_FOREACH(m_touchableNodes,node)    {        checkVisibleNode = touchNode = dynamic_cast<CCNode*>(node);        // check node is visible        visible = true;        do        {            visible = visible && checkVisibleNode->isVisible();            checkVisibleNode = checkVisibleNode->getParent();        } while (checkVisibleNode && visible);        if (!visible) continue;        const CCRect boundingBox = touchNode->getCascadeBoundingBox();        if (touchNode->isRunning() && boundingBox.containsPoint(p))        {            touchNode->retain();            int ret = touchNode->ccRtouchBegan(ptouch,pEvent);            if (ret == kCCtouchBegan || ret == kCCtouchBeganNoSwallows)            {                m_touchTargets->addobject(touchNode);                if (ret == kCCtouchBegan)                {                    touchNode->release();                    break;                }            }            touchNode->release();        }    }    sortAlltouchableNodes(m_touchTargets);    return kCCtouchBegan;}
8.添加传递给lua的事件
int ccluaEngine::executeNodetouchEvent(CCNode* pNode,int eventType,CCtouch *ptouch){    CCtouchScriptHandlerEntry* pScriptHandlerEntry = pNode->getScripttouchHandlerEntry();	if (!pScriptHandlerEntry){ 		return 0;	}    int nHandler = pScriptHandlerEntry->getHandler();	if (!nHandler){ 		return 0;	}    switch (eventType)    {        case CCtouchBEGAN:            m_stack->pushString("began");            break;        case CCtouchmoveD:            m_stack->pushString("moved");            break;        case CCtouchendED:            m_stack->pushString("ended");            break;        case CCtouchCANCELLED:            m_stack->pushString("cancelled");            break;		case CCRtouchBEGAN:			m_stack->pushString("rbegan");			break;		 case CCRtouchendED:            m_stack->pushString("rended");			break;        default:            return 0;    }    const CCPoint pt = CCDirector::sharedDirector()->convertToGL(ptouch->getLocationInVIEw());    const CCPoint prev = CCDirector::sharedDirector()->convertToGL(ptouch->getPrevIoUsLocationInVIEw());    m_stack->pushfloat(pt.x);    m_stack->pushfloat(pt.y);    m_stack->pushfloat(prev.x);    m_stack->pushfloat(prev.y);    int ret = m_stack->executeFunctionByHandler(nHandler,5);    m_stack->clean();    return ret;}
总结

以上是内存溢出为你收集整理的给cocos2dx增加windows右键事件全部内容,希望文章能够帮你解决给cocos2dx增加windows右键事件所遇到的程序开发问题。

如果觉得内存溢出网站内容还不错,欢迎将内存溢出网站推荐给程序员好友。

欢迎分享,转载请注明来源:内存溢出

原文地址: http://outofmemory.cn/web/1058923.html

(0)
打赏 微信扫一扫 微信扫一扫 支付宝扫一扫 支付宝扫一扫
上一篇 2022-05-25
下一篇 2022-05-25

发表评论

登录后才能评论

评论列表(0条)

保存