void Contact::sendEventToListeners(CursorEventPtr pCursorEvent) { switch (pCursorEvent->getType()) { case Event::CURSOR_DOWN: break; case Event::CURSOR_MOTION: notifySubscribers("CURSOR_MOTION", pCursorEvent); break; case Event::CURSOR_UP: notifySubscribers("CURSOR_UP", pCursorEvent); removeSubscribers(); break; default: AVG_ASSERT_MSG(false, pCursorEvent->typeStr().c_str()); } m_bSendingEvents = true; AVG_ASSERT(pCursorEvent->getContact() == shared_from_this()); EventPtr pEvent = boost::dynamic_pointer_cast<Event>(pCursorEvent); m_bCurListenerIsDead = false; for (map<int, Listener>::iterator it = m_ListenerMap.begin(); it != m_ListenerMap.end();) { Listener listener = it->second; m_CurListenerID = it->first; m_bCurListenerIsDead = false; switch (pCursorEvent->getType()) { case Event::CURSOR_MOTION: if (listener.m_pMotionCallback != Py_None) { py::call<void>(listener.m_pMotionCallback, pEvent); } break; case Event::CURSOR_UP: if (listener.m_pUpCallback != Py_None) { py::call<void>(listener.m_pUpCallback, pEvent); } break; default: AVG_ASSERT(false); } map<int, Listener>::iterator lastIt = it; ++it; if (m_bCurListenerIsDead) { m_ListenerMap.erase(lastIt); m_bCurListenerIsDead = false; } } m_bSendingEvents = false; }
void TestHelper::processTouchStatus(CursorEventPtr pEvent) { map<int, TouchStatusPtr>::iterator it = m_Touches.find(pEvent->getCursorID()); switch (pEvent->getType()) { case Event::CURSOR_DOWN: { AVG_ASSERT(it == m_Touches.end()); TouchStatusPtr pTouchStatus(new TouchStatus(pEvent)); m_Touches[pEvent->getCursorID()] = pTouchStatus; } break; case Event::CURSOR_MOTION: case Event::CURSOR_UP: { if (it == m_Touches.end()) { cerr << "borked: " << pEvent->getCursorID() << ", " << pEvent->typeStr() << endl; } AVG_ASSERT(it != m_Touches.end()); TouchStatusPtr pTouchStatus = (*it).second; pTouchStatus->pushEvent(pEvent); } break; default: AVG_ASSERT(false); break; } }
// From InputDevice std::vector<EventPtr> TestHelper::pollEvents() { vector<EventPtr> events = m_Events; map<int, TouchStatusPtr>::iterator it; for (it = m_Touches.begin(); it != m_Touches.end(); ) { TouchStatusPtr pTouchStatus = it->second; CursorEventPtr pEvent = pTouchStatus->pollEvent(); if (pEvent) { events.push_back(pEvent); if (pEvent->getType() == Event::CURSOR_UP) { m_Touches.erase(it++); } else { ++it; } } else { ++it; } } m_Events.clear(); return events; }
vector<EventPtr> MultitouchInputDevice::pollEvents() { lock_guard lock(*m_pMutex); vector<EventPtr> events; vector<TouchStatusPtr>::iterator it; // cerr << "--------poll---------" << endl; for (it = m_Touches.begin(); it != m_Touches.end(); ) { // cerr << (*it)->getID() << " "; CursorEventPtr pEvent = (*it)->pollEvent(); if (pEvent) { events.push_back(pEvent); if (pEvent->getType() == Event::CURSOR_UP) { it = m_Touches.erase(it); } else { ++it; } } else { ++it; } } // cerr << endl; return events; }