void Game2DStage::touchHandler(JniMethodInfo nativeTouchCallbackMInfo, std::string type, std::vector<cocos2d::Touch *> &touches){ jstring jType = nativeTouchCallbackMInfo.env->NewStringUTF(type.c_str()); int len = touches.size()*2; jfloat buf[len]; jfloatArray arr = nativeTouchCallbackMInfo.env->NewFloatArray(len); Touch *t = NULL; Point p; int index = 0; for (auto it = touches.begin(); it!=touches.end(); it++) { t = (Touch*)(*it); p = t->getLocation(); buf[index] = p.x;index++; buf[index] = p.y;index++; } nativeTouchCallbackMInfo.env->SetFloatArrayRegion(arr, 0, len, buf); nativeTouchCallbackMInfo.env->CallStaticVoidMethod(nativeTouchCallbackMInfo.classID, nativeTouchCallbackMInfo.methodID,jType,arr); nativeTouchCallbackMInfo.env->DeleteLocalRef(jType); nativeTouchCallbackMInfo.env->DeleteLocalRef(arr); }
void QTELayer::onTouchesMoved(const std::vector<Touch*>& touches, Event *unused_event) { if(!enableFight) return; Touch *touch = touches.at(0); Vec2 delta = touch->getDelta(); Vec2 lastPos = touch->getPreviousLocation(); Vec2 pos = touch->getLocation(); float dx = pos.x - startTouchPosition.x; float dy = pos.y - startTouchPosition.y; float dist = sqrtf(dx*dx+dy*dy); streak->setPosition(pos); //刀的判断 dist = pos.distanceSquared(startTouchPosition); if (dist > 50) { //hit test monster bool hit = qteMonster->hittestPoint(pos); if (hit) { hitQteMonster(); } } }
Touch::Touch(const Touch &t) : QObject(t.parent()) { fixedMiddle = t.fixedMiddle; setContours(t.getCvContour()); found = t.isFound(); id = t.getId(); }
void PlaySceneOne::onTouchMoved(Touch* touches, Event* event) { log("touchMMMMMMMMMOOVVEDDD执行了---------------------------------------------"); // 获取当前触摸的目标 Touch* touch = static_cast<Touch*>(touches); Point locationInNodelocal = touch->getLocation(); //log("GameObjHero::onTouchBegan::rx=%0.2f, ry=%0.2f, rw=%0.2f, rh=%0.2f, lx=%0.2f, ly=%0.2f", rect.origin.x, rect.origin.y, rect.size.width, rect.size.height, locationInNode.x, locationInNode.y); //左侧手势 if (ControlrectMove.containsPoint(locationInNodelocal)) { float adsxL = locationInNodelocal.x - proposL.x; float adsyL = locationInNodelocal.y - proposL.y; hero->locationInNode = locationInNodelocal; if (adsxL <= -50 && hero->state != 1) { //减少手抖的影响且主角不在空中 proposL = locationInNodelocal; // 设置运动状态:左移 hero->setState(3); log("MMMMMMMMMOOOOOOOOVVVVEEEEE1"); } else if (adsxL >= 50 && hero->state != 1) { proposL = locationInNodelocal; // 设置运动状态:右移 hero->setState(4); log("MMMMMMMMMOOOOOOOOVVVVEEEEE2"); } } //右上手势 else if (ControlrectShot.containsPoint(locationInNodelocal)) { log("shotmoved"); proposM = locationInNodelocal;////////////////////////; hero->archAngle = locationInNodelocal; hero->rotateArrow(hero->archAngle); hero->setState(7); } }
void BadaAppForm::OnTouchPressed(const Control& source, const Point& currentPosition, const TouchEventInfo& touchInfo) { Touch touch; _touchCount = touch.GetPointCount(); if (_touchCount > 1) { int index = getShortcutIndex(); _shortcutIndex = (index == -1 ? 0 : index + 1); _shortcutTimer = g_system->getMillis(); switch (_shortcutIndex) { case SHORTCUT_F5: g_system->displayMessageOnOSD(_("Game Menu")); break; case SHORTCUT_ESCAPE: g_system->displayMessageOnOSD(_("Escape")); break; default: g_system->displayMessageOnOSD(_("Swap Buttons")); _shortcutIndex = SHORTCUT_SWAP_MOUSE; } } else if (getShortcutIndex() == -1) { pushEvent(_buttonState == LeftButton ? Common::EVENT_LBUTTONDOWN : Common::EVENT_RBUTTONDOWN, currentPosition); } }
void CocosDenshionTest::ccTouchesMoved(Set *pTouches, Event *pEvent) { Touch* touch = (Touch*)pTouches->anyObject(); Point touchLocation = touch->getLocation(); float nMoveY = touchLocation.y - _beginPos.y; Point curPos = _itmeMenu->getPosition(); Point nextPos = ccp(curPos.x, curPos.y + nMoveY); if (nextPos.y < 0.0f) { _itmeMenu->setPosition(PointZero); return; } if (nextPos.y > ((_testCount + 1)* LINE_SPACE - VisibleRect::getVisibleRect().size.height)) { _itmeMenu->setPosition(ccp(0, ((_testCount + 1)* LINE_SPACE - VisibleRect::getVisibleRect().size.height))); return; } _itmeMenu->setPosition(nextPos); _beginPos = touchLocation; }
// check if the touch was on one of the flipper buttons void PinballRUBELayer::onTouchesBegan(const std::vector<Touch *> &touches, cocos2d::Event *event) { // Calling the superclass handles the mouse joint dragging for the launcher, // but it also allows the user to grab the ball, and zoom and pan the scene. // For a real application you would want to implement a better method here. // RUBELayer::onTouchesBegan(touches, event); for (auto it = touches.begin(); it != touches.end(); ++it) { Touch* touch = (Touch*)*it; Point screenPos = touch->getLocationInView(); b2Vec2 worldPos = screenToWorld(screenPos); CCLOG("Touch began at x: %f y: %f", screenPos.x, screenPos.y); // Make a small box around the touched point to query for overlapping fixtures b2AABB aabb; b2Vec2 d(0.001f, 0.001f); aabb.lowerBound = worldPos - d; aabb.upperBound = worldPos + d; // Query the world for overlapping fixtures (the TouchDownQueryCallback simply // looks for any fixture that contains the touched point) TouchDownQueryCallback callback(worldPos); m_world->QueryAABB(&callback, aabb); // if the touched fixture was one of the flipper buttons, set that touch as // the current touch for that button if (callback.m_fixture == m_leftFlipperButtonFixture) m_leftFlipperTouch = touch; if (callback.m_fixture == m_rightFlipperButtonFixture) m_rightFlipperTouch = touch; } }
void SelectStage::onTouchesEnded(const vector<Touch *> & touches, Event * event) { vector<Touch *>::const_iterator it = touches.begin(); while (it != touches.end()) { Touch * touch = (Touch *) (* it); if (touch) { Point tap = touch->getLocation(); Rect select; Scene * gameScene; select = _stageSun->getBoundingBox(); if (select.containsPoint(tap)) { gameScene = TransitionFlipY::create(0.5f,GameLayer::scene(),TransitionScene::Orientation::RIGHT_OVER); Director::getInstance()->replaceScene(gameScene); } else if (!select.containsPoint(tap) && _stageSea->getBoundingBox().containsPoint(tap)) { // gameScene = TransitionFlipY::create(0.5f, GameLayer::scene(), TransitionScene::Orientation::RIGHT_OVER); // Director::getInstance()->replaceScene(gameScene); } else { } } it++; } }
void MainThread::run() { serial.blocking = true; serial.baud = 115200; serial.echo = true; if (serial.open() != Uart0::kOK) Board::reboot(); Touch touch; bool touchOk = touch.setup(); if (!touchOk) { serial << "Error during touch sensor setup." << Uart0::endl; } while (1) { if (touch.checkSensor()) { serial << "Touch sensor ok." << Uart0::endl; } else { serial << "Touch sensor error." << Uart0::endl; } sleep_ms(500); } }
void CWidgetWindow::onTouchesCancelled(const std::vector<Touch*>&touches, Event *unused_event) { for(unsigned int i=0;i<touches.size(); i++) { Touch* pTouch = touches.at(i); map<int, __ccMULTITOUCHTARGET>::iterator mitr = m_mMultiTouchKeeper.find(pTouch->getID()); if( mitr != m_mMultiTouchKeeper.end() ) { if( mitr->second.pWidget ) { if( mitr->second.pWidget->isTouchInterrupted() ) { if( mitr->second.pLongClickedWidgetObject ) { executeTouchCancelledAfterLongClickHandler(mitr->second.pLongClickedWidgetObject, pTouch, mitr->second.fTouchedDuration); } } else { mitr->second.pWidget->interruptTouchCascade(pTouch, mitr->second.fTouchedDuration); } } m_mMultiTouchKeeper.erase(mitr); } } }
void LHScenePhysicsTransformationsDemo::onTouchesBegan(const std::vector<Touch*>& touches, Event* event) { if(touches.size() < 1){ return; } Touch* touch = touches[0]; Point location = touch->getLocation(); __Array* allPhysicalChildren = this->getGameWorldNode()->getChildrenOfType<Node*>(); for(int i = 0; i < allPhysicalChildren->count(); ++i) { Node* node = (Node*)allPhysicalChildren->getObjectAtIndex(i); if(node && node->getBoundingBox().containsPoint(location)) { // node->removeFromParent();//this will remove the node together with its physical body (if any) CCLOG("SETTING NODE %p TO LOCATION %f %f", node, location.x, location.y); node->setPosition(location); node->setRotation(LHUtils::LHRandomFloat(0, 360)); node->setScaleX(LHUtils::LHRandomFloat(0.2, 1.5f)); node->setScaleY(LHUtils::LHRandomFloat(0.2, 1.5f)); return; } } //dont forget to call super LHScene::onTouchesBegan(touches, event); }
result CCEGLView::OnInitializing(void) { result r = E_SUCCESS; AddTouchEventListener(*this); Touch touch; touch.SetMultipointEnabled(*this, true); m_pKeypad = new Keypad(); m_pKeypad->Construct(KEYPAD_STYLE_NORMAL, KEYPAD_MODE_ALPHA); m_pKeypad->AddTextEventListener(*this); Rectangle rc = GetBounds(); if ((rc.width == 480 && rc.height == 720) || (rc.width == 720 && rc.height == 480)) { m_bNotHVGA = false; m_sSizeInPixel.width = rc.width / 1.5f; m_sSizeInPixel.height = rc.height / 1.5f; } else { m_bNotHVGA = true; m_sSizeInPixel.width = rc.width; m_sSizeInPixel.height = rc.height; } // calculate the factor and the rect of viewport m_fScreenScaleFactor = MIN((float)m_sSizeInPixel.width / m_sSizeInPoint.width, (float)m_sSizeInPixel.height / m_sSizeInPoint.height); //CCLOG("rc.width = %d, rc.height = %d, m_fScreenScaleFactor = %f", rc.width, rc.height, m_fScreenScaleFactor); resize(m_sSizeInPoint.width, m_sSizeInPoint.height); return r; }
// Override this to find the body that was touched and remove it. void DestroyBodyLayer::onTouchesBegan(const std::vector<Touch*>& touches, Event *unused_event) { Touch *touch = (Touch*)touches[0]; Point screenPos = touch->getLocationInView(); b2Vec2 worldPos = screenToWorld(screenPos); // Make a small box around the touched point to query for overlapping fixtures b2AABB aabb; b2Vec2 d(0.001f, 0.001f); aabb.lowerBound = worldPos - d; aabb.upperBound = worldPos + d; // Query the world for overlapping fixtures (the TouchDownQueryCallback simply // looks for any fixture that contains the touched point) TouchDownQueryCallback callback(worldPos); m_world->QueryAABB(&callback, aabb); // Check if we found something, and it was a dynamic body (could also destroy static // bodies but we want to keep the pinch-zoom and pan from the superclass, and it's // hard not to touch the ground body in this scene) if (callback.m_fixture && callback.m_fixture->GetBody()->GetType() == b2_dynamicBody) { b2Body* touchedBody = callback.m_fixture->GetBody(); removeBodyFromWorld(touchedBody); } }
void BLevelMenu::ccTouchesMoved(Set *pTouches, Event *pEvent) { Touch* touch = (Touch*)pTouches->anyObject(); Point touchLocation = touch->getLocation(); float nMoveY = touchLocation.y - beginPos.y; Point curPos = itemMenu->getPosition(); Point nextPos = Point(curPos.x, curPos.y + nMoveY); if (nextPos.y < 0.0f) { itemMenu->setPosition(Point::ZERO); return; } if (nextPos.y > ((levelCount + 1)* LINE_SPACE - visRect.size.height)) { itemMenu->setPosition(Point(0, ((levelCount + 1)* LINE_SPACE - visRect.size.height))); return; } itemMenu->setPosition(nextPos); beginPos = touchLocation; s_tCurPos = nextPos; }
void GLView::handleTouchesOfEndOrCancel(EventTouch::EventCode eventCode, int num, intptr_t ids[], float xs[], float ys[]) { intptr_t id = 0; float x = 0.0f; float y = 0.0f; EventTouch touchEvent; for (int i = 0; i < num; ++i) { id = ids[i]; x = xs[i]; y = ys[i]; auto iter = g_touchIdReorderMap.find(id); if (iter == g_touchIdReorderMap.end()) { CCLOG("if the index doesn't exist, it is an error"); continue; } /* Add to the set to send to the director */ Touch* touch = g_touches[iter->second]; if (touch) { CCLOGINFO("Ending touches with id: %d, x=%f, y=%f", id, x, y); touch->setTouchInfo(iter->second, (x - _viewPortRect.origin.x) / _scaleX, (y - _viewPortRect.origin.y) / _scaleY); touchEvent._touches.push_back(touch); g_touches[iter->second] = nullptr; removeUsedIndexBit(iter->second); g_touchIdReorderMap.erase(id); } else { CCLOG("Ending touches with id: %ld error", static_cast<long>(id)); return; } } if (touchEvent._touches.size() == 0) { CCLOG("touchesEnded or touchesCancel: size = 0"); return; } touchEvent._eventCode = eventCode; auto dispatcher = Director::getInstance()->getEventDispatcher(); dispatcher->dispatchEvent(&touchEvent); for (auto& touch : touchEvent._touches) { // release the touch object. touch->release(); } }
void PluginView::handleTouchEvent(TouchEvent* event) { if (!m_window->isAcceptingEvent(kTouch_ANPEventFlag)) return; if (!m_window->inFullScreen() && m_parentFrame->document()->focusedNode() != m_element) return; ANPEvent evt; SkANP::InitEvent(&evt, kMultiTouch_ANPEventType); const AtomicString& type = event->type(); if (eventNames().touchstartEvent == type) evt.data.multiTouch.action = kDown_ANPTouchAction; else if (eventNames().touchendEvent == type) evt.data.multiTouch.action = kUp_ANPTouchAction; else if (eventNames().touchmoveEvent == type) evt.data.multiTouch.action = kMove_ANPTouchAction; else if (eventNames().touchcancelEvent == type) evt.data.multiTouch.action = kCancel_ANPTouchAction; else if (eventNames().touchlongpressEvent == type) evt.data.multiTouch.action = kLongPress_ANPTouchAction; else if (eventNames().touchdoubletapEvent == type) evt.data.multiTouch.action = kDoubleTap_ANPTouchAction; else return; // set the id and timestamp evt.data.multiTouch.id = 0; // TODO evt.data.multiTouch.timestamp = 0; // TODO // In the event of a touchend (up) or touchcancel event, we must ask the changedTouch for the // co-ordinates as there is no touch in touches anymore. TouchList* touches = (evt.data.multiTouch.action == kUp_ANPTouchAction || evt.data.multiTouch.action == kCancel_ANPTouchAction) ? event->changedTouches() : event->touches(); // set each touchPoint int pointerCount = touches->length(); evt.data.multiTouch.pointerCount = pointerCount; evt.data.multiTouch.touchPoint = new TouchPoint[pointerCount]; for (int x = 0; x < evt.data.multiTouch.pointerCount; x++) { Touch* touch = touches->item(x); // Convert to coordinates that are relative to the plugin. IntPoint localPos = roundedIntPoint(m_element->renderer()->absoluteToLocal(IntPoint(touch->pageX(), touch->pageY()))); evt.data.multiTouch.touchPoint[x].id = touch->identifier(); evt.data.multiTouch.touchPoint[x].x = localPos.x(); evt.data.multiTouch.touchPoint[x].y = localPos.y(); evt.data.multiTouch.touchPoint[x].pressure = 1; // TODO evt.data.multiTouch.touchPoint[x].size = 1; // TODO } if (m_window->sendEvent(evt)) event->preventDefault(); // cleanup the touch points we allocated delete[] evt.data.multiTouch.touchPoint; }
void MotionStreakTest2::ccTouchesMoved(Set* touches, Event* event) { Touch* touch = static_cast<Touch*>( touches->anyObject() ); Point touchLocation = touch->getLocation(); streak->setPosition( touchLocation ); }
JSValue jsTouchIdentifier(ExecState* exec, JSValue slotBase, const Identifier&) { JSTouch* castedThis = static_cast<JSTouch*>(asObject(slotBase)); UNUSED_PARAM(exec); Touch* imp = static_cast<Touch*>(castedThis->impl()); JSValue result = jsNumber(imp->identifier()); return result; }
JSValue jsTouchTarget(ExecState* exec, JSValue slotBase, const Identifier&) { JSTouch* castedThis = static_cast<JSTouch*>(asObject(slotBase)); UNUSED_PARAM(exec); Touch* imp = static_cast<Touch*>(castedThis->impl()); JSValue result = toJS(exec, castedThis->globalObject(), WTF::getPtr(imp->target())); return result; }
void GameLayer::onTouchesMoved(const std::vector<Touch*>& touches, Event * event) { if(_gameOver || _is_character_moving) return; Touch* touch = touches[0]; Vec2 location = touch->getLocation(); }
void HoleDemo::onTouchesBegan(const std::vector<Touch*>& touches, Event* event) { Touch *touch = (Touch *)touches[0]; Vec2 point = _outerClipper->convertToNodeSpace(Director::getInstance()->convertToGL(touch->getLocationInView())); auto rect = Rect(0, 0, _outerClipper->getContentSize().width, _outerClipper->getContentSize().height); if (!rect.containsPoint(point)) return; this->pokeHoleAtPoint(point); }
int LuaEngine::handleTouchesEvent(void* data) { if (NULL == data) return 0; TouchesScriptData* touchesScriptData = static_cast<TouchesScriptData*>(data); if (NULL == touchesScriptData->nativeObject || NULL == touchesScriptData->touches) return 0; int handler = ScriptHandlerMgr::getInstance()->getObjectHandler((void*)touchesScriptData->nativeObject, ScriptHandlerMgr::kTouchesHandler); if (0 == handler) return 0; switch (touchesScriptData->actionType) { case CCTOUCHBEGAN: _stack->pushString("began"); break; case CCTOUCHMOVED: _stack->pushString("moved"); break; case CCTOUCHENDED: _stack->pushString("ended"); break; case CCTOUCHCANCELLED: _stack->pushString("cancelled"); break; default: return 0; } Director* pDirector = Director::getInstance(); lua_State *L = _stack->getLuaState(); int ret = 0; lua_newtable(L); int i = 1; for (SetIterator it = touchesScriptData->touches->begin(); it != touchesScriptData->touches->end(); ++it) { Touch* pTouch = static_cast<Touch*>(*it); Point pt = pDirector->convertToGL(pTouch->getLocationInView()); lua_pushnumber(L, pt.x); lua_rawseti(L, -2, i++); lua_pushnumber(L, pt.y); lua_rawseti(L, -2, i++); lua_pushinteger(L, pTouch->getID()); lua_rawseti(L, -2, i++); } ret = _stack->executeFunctionByHandler(handler, 2); _stack->clean(); return ret; }
void ScrollViewDemo::onTouchesBegan(const std::vector<Touch*>& touches, Event *event) { Touch *touch = touches[0]; auto clipper = this->getChildByTag(kTagClipperNode); Vec2 point = clipper->convertToNodeSpace(Director::getInstance()->convertToGL(touch->getLocationInView())); auto rect = Rect(0, 0, clipper->getContentSize().width, clipper->getContentSize().height); _scrolling = rect.containsPoint(point); _lastPoint = point; }
void CCEGLView::onTouchEvent(const Control& source, TouchStatus status) { IList *pList = null; do { CC_BREAK_IF(!m_pDelegate); int i = 0; Touch touch; pList = touch.GetTouchInfoListN(source); CC_BREAK_IF(pList == NULL); int pointerNumber = pList->GetCount(); CC_BREAK_IF(pointerNumber <= 0); int id[30] = {0}; float x[30] = {0}; float y[30] = {0}; for (i = 0; i < pointerNumber; i++) { TouchInfo *pTouchInfo = static_cast<TouchInfo *>(pList->GetAt(i)); id[i] = (int)pTouchInfo->id; float tmpX = (float)pTouchInfo->position.x; float tmpY = (float)pTouchInfo->position.y; if (!m_bNotHVGA) { x[i] = tmpX * 2 / 3; y[i] = tmpY * 2 / 3; } else { x[i] = tmpX; y[i] = tmpY; } } if (TOUCH_PRESSED == status) { onTouchesBegin(id, x, y, pointerNumber); } else if (TOUCH_MOVED == status) { onTouchesMove(id, x, y, pointerNumber); } else if (TOUCH_RELEASED == status) { onTouchesEnd(id, x, y, pointerNumber); } } while (0); if (pList != null) { pList->RemoveAll(true); delete pList; } }
void Joystick::onTouchesMoved(const std::vector<Touch *> &touches, Event *event) { if (_isPressed) { Touch *touch = touches[0]; Vec2 touchPoint = touch->getLocation(); this->updateVelocity(touchPoint); } }
Touch * RenderingEngine::GetTouchForSystemTouch(const void *pSystemTouch) const { for (int touchIndex = 0; touchIndex < m_touches->size(); touchIndex++) { Touch *touch = m_touches->at(touchIndex); if (touch->GetSystemTouch() == pSystemTouch) { return touch; } } return nullptr; }
EventRelatedNodeResolver(Touch& touch, TouchEventContext::TouchListType touchListType) : m_relatedNode(*touch.target()->toNode()) , m_relatedNodeTreeScope(m_relatedNode.treeScope()) , m_relatedNodeInCurrentTreeScope(nullptr) , m_currentTreeScope(nullptr) , m_touch(&touch) , m_touchListType(touchListType) { ASSERT(touch.target()->toNode()); }
static Touch* findTouchWithIdentifier(TouchList& list, unsigned identifier) { unsigned length = list.length(); for (unsigned i = 0; i < length; ++i) { Touch* touch = list.item(i); if (touch->identifier() == identifier) return touch; } return nullptr; }
void ScrollViewDemo::onTouchesMoved(const std::vector<Touch*>& touches, Event *event) { if (!_scrolling) return; Touch *touch = touches[0]; auto clipper = this->getChildByTag(kTagClipperNode); auto point = clipper->convertToNodeSpace(Director::getInstance()->convertToGL(touch->getLocationInView())); Vec2 diff = point - _lastPoint; auto content = clipper->getChildByTag(kTagContentNode); content->setPosition(content->getPosition() + diff); _lastPoint = point; }
void Joystick::onTouchesBegan(const std::vector<Touch*>& touches, Event *event) { Touch* touch = touches[0]; Vec2 touchPoint = touch->getLocation(); if (isPointInCircle(touchPoint, kCenter, JOYSTICK_RADIUS)) { isPressed = true; this->updateVelocity(touchPoint); } }