2
// libavg - Media Playback Engine.
3
// Copyright (C) 2003-2008 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
22
#include "EventStream.h"
23
#include "TouchEvent.h"
25
#include "../base/Logger.h"
26
#include "../base/ObjectCounter.h"
27
#include "../base/Exception.h"
31
const int MAXMISSINGFRAMES=1;
37
int EventStream::s_LastLabel = 0;
39
EventStream::EventStream(BlobPtr pFirstBlob, long long time)
42
ObjectCounter::get()->incRef(&typeid(*this));
45
m_Pos = m_pBlob->getCenter();
48
m_State = DOWN_PENDING;
54
EventStream::~EventStream()
56
ObjectCounter::get()->decRef(&typeid(*this));
59
void EventStream::blobChanged(BlobPtr pNewBlob, long long time, bool bEventOnMove)
64
DPoint c = pNewBlob->getCenter();
67
bPosChanged = (calcDist(c, m_Pos) > 1);
73
//finger touch has not been polled yet. update position
76
m_State = MOTION_PENDING;
79
//fingerdown delivered, change to motion states
81
m_State = MOTION_PENDING;
83
m_State = MOTION_DELIVERED;
87
case MOTION_DELIVERED:
89
m_State = MOTION_PENDING;
106
void EventStream::blobGone()
110
m_State = UP_DELIVERED;
118
if (m_VanishCounter >= MAXMISSINGFRAMES) {
119
m_State = UP_PENDING;
125
EventPtr EventStream::pollevent(DeDistortPtr pDeDistort, const DRect& displayROI,
126
CursorEvent::Source source, bool bEventOnMove)
129
DPoint BlobOffset = pDeDistort->getActiveBlobArea(displayROI).tl;
130
DPoint pt = m_pBlob->getCenter()+BlobOffset;
131
DPoint screenpos = pDeDistort->transformBlobToScreen(pt);
132
IntPoint pos(int(screenpos.x+0.5), int(screenpos.y+0.5));
133
DPoint oldPos = pDeDistort->transformBlobToScreen(m_OldPos + BlobOffset);
134
DPoint newPos = pDeDistort->transformBlobToScreen(m_Pos + BlobOffset);
135
DPoint speed = getSpeed(oldPos, newPos);
136
DPoint firstDoubleScreenPos = pDeDistort->transformBlobToScreen(
137
m_FirstPos+BlobOffset);
138
IntPoint firstScreenPos(int(firstDoubleScreenPos.x+0.5),
139
int(firstDoubleScreenPos.y+0.5));
142
m_State = DOWN_DELIVERED;
143
return EventPtr(new TouchEvent(m_ID, Event::CURSORDOWN,
144
m_pBlob, pos, source, speed, firstScreenPos));
146
m_State = MOTION_DELIVERED;
147
return EventPtr(new TouchEvent(m_ID, Event::CURSORMOTION,
148
m_pBlob, pos, source, speed, firstScreenPos));
150
m_State = UP_DELIVERED;
151
return EventPtr(new TouchEvent(m_ID, Event::CURSORUP,
152
m_pBlob, pos, source, speed, firstScreenPos));
154
case MOTION_DELIVERED:
156
return EventPtr(new TouchEvent(m_ID, Event::CURSORMOTION,
157
m_pBlob, pos, source, speed, firstScreenPos));
168
bool EventStream::isGone()
170
return (m_State == UP_DELIVERED);
173
void EventStream::setStale() {
177
bool EventStream::isStale() {
181
string EventStream::stateToString(StreamState State)
185
return "DOWN_PENDING";
187
return "DOWN_DELIVERED";
189
return "MOTION_PENDING";
190
case MOTION_DELIVERED:
191
return "MOTION_DELIVERED";
197
return "UP_DELIVERED";
199
return "Broken state";
203
void EventStream::dump()
205
cerr << " " << m_ID << ": " << stateToString(m_State) << ", stale: "
207
if (m_State == VANISHED) {
208
cerr << " VanishCounter: " << m_VanishCounter << endl;
212
DPoint EventStream::getSpeed (const DPoint& oldPos, const DPoint& newPos)
214
if (m_OldTime==0 || m_Time == m_OldTime) {
217
double timeDiff = double(m_OldTime-m_Time);
218
return (oldPos-newPos)/timeDiff;