~ubuntu-branches/ubuntu/trusty/libavg/trusty-proposed

« back to all changes in this revision

Viewing changes to src/player/MultitouchInputDevice.cpp

  • Committer: Package Import Robot
  • Author(s): OXullo Intersecans
  • Date: 2011-12-06 22:44:56 UTC
  • mfrom: (1.1.6)
  • Revision ID: package-import@ubuntu.com-20111206224456-qc7250z3ya1vi8s9
Tags: 1.7.0-0ubuntu1
* New upstream release (LP: #899183)
* Remove patches 0002-libav-0.7.patch, 0003-fglrx-segfault-on-startup.patch
  now merged to upstream
* Remove unnecessary .la files
* Update debian/watch file
* Fix debian/copyright dep-5 compliancy
* Update standards to version 3.9.2
* Add man pages for avg_checktouch, avg_checkvsync, avg_showsvg
* Minor debian/rules enhancement
* Add librsvg2-dev, libgdk-pixbuf2.0-dev to Build-Depends
* Proper transition to dh_python2

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
//
 
2
//  libavg - Media Playback Engine. 
 
3
//  Copyright (C) 2003-2011 Ulrich von Zadow
 
4
//
 
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.
 
9
//
 
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.
 
14
//
 
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
 
18
//
 
19
//  Current versions can be found at www.libavg.de
 
20
//
 
21
//  Original author of this file is igor@c-base.org
 
22
//
 
23
 
 
24
#include "MultitouchInputDevice.h"
 
25
#include "TouchEvent.h"
 
26
#include "Player.h"
 
27
#include "AVGNode.h"
 
28
#include "TouchStatus.h"
 
29
 
 
30
#include "../base/Logger.h"
 
31
#include "../base/ObjectCounter.h"
 
32
#include "../base/Exception.h"
 
33
 
 
34
using namespace std;
 
35
 
 
36
namespace avg {
 
37
 
 
38
MultitouchInputDevice::MultitouchInputDevice()
 
39
    : IInputDevice(EXTRACT_INPUTDEVICE_CLASSNAME(MultitouchInputDevice))
 
40
{
 
41
}
 
42
 
 
43
MultitouchInputDevice::~MultitouchInputDevice()
 
44
{
 
45
}
 
46
 
 
47
void MultitouchInputDevice::start()
 
48
{
 
49
    m_WindowSize = Player::get()->getRootNode()->getSize();
 
50
    m_pMutex = MutexPtr(new boost::mutex);
 
51
}
 
52
 
 
53
vector<EventPtr> MultitouchInputDevice::pollEvents()
 
54
{
 
55
    boost::mutex::scoped_lock lock(*m_pMutex);
 
56
 
 
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();
 
63
        if (pEvent) {
 
64
            events.push_back(pEvent);
 
65
            if (pEvent->getType() == Event::CURSORUP) {
 
66
                it = m_Touches.erase(it);
 
67
            } else {
 
68
                ++it;
 
69
            }
 
70
        } else {
 
71
            ++it;
 
72
        }
 
73
    }
 
74
//    cerr << endl;
 
75
    return events;
 
76
}
 
77
 
 
78
const DPoint& MultitouchInputDevice::getWindowSize() const
 
79
{
 
80
    return m_WindowSize;
 
81
}
 
82
 
 
83
int MultitouchInputDevice::getNumTouches() const
 
84
{
 
85
    return m_TouchIDMap.size();
 
86
}
 
87
 
 
88
TouchStatusPtr MultitouchInputDevice::getTouchStatus(int id)
 
89
{
 
90
    map<int, TouchStatusPtr>::iterator it = m_TouchIDMap.find(id);
 
91
    if (it == m_TouchIDMap.end()) {
 
92
        return TouchStatusPtr();
 
93
    } else {
 
94
        return it->second;
 
95
    }
 
96
}
 
97
 
 
98
void MultitouchInputDevice::addTouchStatus(int id, TouchEventPtr pInitialEvent)
 
99
{
 
100
    TouchStatusPtr pTouchStatus(new TouchStatus(pInitialEvent));
 
101
    m_TouchIDMap[id] = pTouchStatus;
 
102
    m_Touches.push_back(pTouchStatus);
 
103
}
 
104
 
 
105
void MultitouchInputDevice::removeTouchStatus(int id)
 
106
{
 
107
    unsigned numRemoved = m_TouchIDMap.erase(id);
 
108
    AVG_ASSERT(numRemoved == 1);
 
109
}
 
110
 
 
111
void MultitouchInputDevice::getDeadIDs(const set<int>& liveIDs, set<int>& deadIDs)
 
112
{
 
113
    map<int, TouchStatusPtr>::iterator it;
 
114
    for (it = m_TouchIDMap.begin(); it != m_TouchIDMap.end(); ++it) {
 
115
        int id = it->first;
 
116
        set<int>::const_iterator foundIt = liveIDs.find(id);
 
117
        if (foundIt == liveIDs.end()) {
 
118
            deadIDs.insert(id);
 
119
        }
 
120
    }
 
121
}
 
122
 
 
123
boost::mutex& MultitouchInputDevice::getMutex()
 
124
{
 
125
    return *m_pMutex;
 
126
}
 
127
 
 
128
}