void TUIOInputDevice::processTangibleSet(ReceivedMessageArgumentStream& args) { osc::int32 tuioID; osc::int32 classID; float xpos, ypos; float angle; float xspeed, yspeed; float angleSpeed; float accel; float angleAccel; args >> tuioID >> classID >> xpos >> ypos >> angle >> xspeed >> yspeed >> angleSpeed >> accel >> angleAccel; glm::vec2 pos(xpos, ypos); glm::vec2 speed(xspeed, yspeed); TouchStatusPtr pTouchStatus = getTouchStatus(tuioID); IntPoint screenPos = getScreenPos(pos); TangibleEventPtr pEvent; if (!pTouchStatus) { // Down pEvent = TangibleEventPtr(new TangibleEvent(getNextContactID(), classID, Event::CURSOR_DOWN, screenPos, speed, angle)); addTouchStatus((long)tuioID, pEvent); } else { // Move pEvent = TangibleEventPtr(new TangibleEvent(0, classID, Event::CURSOR_MOTION, screenPos, speed, angle)); pTouchStatus->pushEvent(pEvent); } setEventSpeed(pEvent, speed); }
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; } }
void TestHelper::fakeTouchEvent(int id, Event::Type eventType, Event::Source source, const glm::vec2& pos, const glm::vec2& speed) { checkEventType(eventType); // The id is modified to avoid collisions with real touch events. TouchEventPtr pEvent(new TouchEvent(id+std::numeric_limits<int>::max()/2, eventType, IntPoint(pos), source, speed)); map<int, TouchStatusPtr>::iterator it = m_Touches.find(pEvent->getCursorID()); switch (pEvent->getType()) { case Event::CURSORDOWN: { AVG_ASSERT(it == m_Touches.end()); TouchStatusPtr pTouchStatus(new TouchStatus(pEvent)); m_Touches[pEvent->getCursorID()] = pTouchStatus; } break; case Event::CURSORMOTION: case Event::CURSORUP: { 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; } }
void XInputMTInputDevice::handleXIEvent(const XEvent& xEvent) { m_SDLLockFunc(); XGenericEventCookie* pCookie = (XGenericEventCookie*)&xEvent.xcookie; if (pCookie->type == GenericEvent && pCookie->extension == m_XIOpcode) { XIDeviceEvent* pDevEvent = (XIDeviceEvent*)(pCookie->data); IntPoint pos(pDevEvent->event_x, pDevEvent->event_y); int xid = pDevEvent->detail; switch (pCookie->evtype) { case XI_TouchBegin: { // cerr << "TouchBegin " << xid << ", " << pos << endl; m_LastID++; TouchEventPtr pEvent = createEvent(m_LastID, Event::CURSOR_DOWN, pos); addTouchStatus(xid, pEvent); } break; case XI_TouchUpdate: { // cerr << "TouchUpdate " << xid << ", " << pos << endl; TouchEventPtr pEvent = createEvent(0, Event::CURSOR_MOTION, pos); TouchStatusPtr pTouchStatus = getTouchStatus(xid); AVG_ASSERT(pTouchStatus); pTouchStatus->pushEvent(pEvent); } break; case XI_TouchEnd: { // cerr << "TouchEnd " << xid << ", " << pos << endl; TouchStatusPtr pTouchStatus = getTouchStatus(xid); AVG_ASSERT(pTouchStatus); TouchEventPtr pEvent = createEvent(0, Event::CURSOR_UP, pos); pTouchStatus->pushEvent(pEvent); } break; default: ; // cerr << "Unhandled XInput event, type: " // << cookieTypeToName(pCookie->evtype) << endl; } } else { // cerr << "Unhandled X11 Event: " << xEvent.type << endl; } XFreeEventData(s_pDisplay, pCookie); m_SDLUnlockFunc(); }
void TUIOInputDevice::processAlive(ReceivedMessageArgumentStream& args, Event::Source source) { std::set<int> liveTUIOIDs; int32 tuioID; while (!args.Eos()) { args >> tuioID; liveTUIOIDs.insert(tuioID); } // Create up events for all ids not in live list. set<int> deadTUIOIDs; getDeadIDs(liveTUIOIDs, deadTUIOIDs, source); set<int>::iterator it; for (it = deadTUIOIDs.begin(); it != deadTUIOIDs.end(); ++it) { int id = *it; TouchStatusPtr pTouchStatus = getTouchStatus(id); CursorEventPtr pOldEvent = pTouchStatus->getLastEvent(); CursorEventPtr pUpEvent = pOldEvent->cloneAs(Event::CURSOR_UP); pTouchStatus->pushEvent(pUpEvent); removeTouchStatus(id); } }
void AppleTrackpadInputDevice::onData(int device, Finger* pFingers, int numFingers, float timestamp, int frame) { boost::mutex::scoped_lock lock(getMutex()); for (int i = 0; i < numFingers; i++) { Finger* pFinger = &pFingers[i]; TouchStatusPtr pTouchStatus = getTouchStatus(pFinger->identifier); if (!pTouchStatus) { m_LastID++; TouchEventPtr pEvent = createEvent(m_LastID, pFinger, Event::CURSORDOWN); addTouchStatus(pFinger->identifier, pEvent); } else { Event::Type eventType; if (pFinger->state == 7) { eventType = Event::CURSORUP; removeTouchStatus(pFinger->identifier); } else { eventType = Event::CURSORMOTION; } TouchEventPtr pEvent = createEvent(0, pFinger, eventType); pTouchStatus->pushEvent(pEvent); } } }