2
// libavg - Media Playback Engine.
3
// Copyright (C) 2003-2011 Ulrich von Zadow
5
// This library is free software; you can redistribute it and/or
6
// modify it under the terms of the GNU Lesser General Public
7
// License as published by the Free Software Foundation; either
8
// version 2 of the License, or (at your option) any later version.
10
// This library is distributed in the hope that it will be useful,
11
// but WITHOUT ANY WARRANTY; without even the implied warranty of
12
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13
// Lesser General Public License for more details.
15
// You should have received a copy of the GNU Lesser General Public
16
// License along with this library; if not, write to the Free Software
17
// Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
19
// Current versions can be found at www.libavg.de
21
// Original author of this file is igor@c-base.org
24
#include "MultitouchInputDevice.h"
25
#include "TouchEvent.h"
28
#include "TouchStatus.h"
30
#include "../base/Logger.h"
31
#include "../base/ObjectCounter.h"
32
#include "../base/Exception.h"
38
MultitouchInputDevice::MultitouchInputDevice()
39
: IInputDevice(EXTRACT_INPUTDEVICE_CLASSNAME(MultitouchInputDevice))
43
MultitouchInputDevice::~MultitouchInputDevice()
47
void MultitouchInputDevice::start()
49
m_WindowSize = Player::get()->getRootNode()->getSize();
50
m_pMutex = MutexPtr(new boost::mutex);
53
vector<EventPtr> MultitouchInputDevice::pollEvents()
55
boost::mutex::scoped_lock lock(*m_pMutex);
57
vector<EventPtr> events;
58
vector<TouchStatusPtr>::iterator it;
59
// cerr << "--------poll---------" << endl;
60
for (it = m_Touches.begin(); it != m_Touches.end(); ) {
61
// cerr << it->first << " ";
62
CursorEventPtr pEvent = (*it)->pollEvent();
64
events.push_back(pEvent);
65
if (pEvent->getType() == Event::CURSORUP) {
66
it = m_Touches.erase(it);
78
const DPoint& MultitouchInputDevice::getWindowSize() const
83
int MultitouchInputDevice::getNumTouches() const
85
return m_TouchIDMap.size();
88
TouchStatusPtr MultitouchInputDevice::getTouchStatus(int id)
90
map<int, TouchStatusPtr>::iterator it = m_TouchIDMap.find(id);
91
if (it == m_TouchIDMap.end()) {
92
return TouchStatusPtr();
98
void MultitouchInputDevice::addTouchStatus(int id, TouchEventPtr pInitialEvent)
100
TouchStatusPtr pTouchStatus(new TouchStatus(pInitialEvent));
101
m_TouchIDMap[id] = pTouchStatus;
102
m_Touches.push_back(pTouchStatus);
105
void MultitouchInputDevice::removeTouchStatus(int id)
107
unsigned numRemoved = m_TouchIDMap.erase(id);
108
AVG_ASSERT(numRemoved == 1);
111
void MultitouchInputDevice::getDeadIDs(const set<int>& liveIDs, set<int>& deadIDs)
113
map<int, TouchStatusPtr>::iterator it;
114
for (it = m_TouchIDMap.begin(); it != m_TouchIDMap.end(); ++it) {
116
set<int>::const_iterator foundIt = liveIDs.find(id);
117
if (foundIt == liveIDs.end()) {
123
boost::mutex& MultitouchInputDevice::getMutex()