83
|
1 |
/*
|
|
2 |
* Copyright (c) 2008 Nokia Corporation and/or its subsidiary(-ies).
|
|
3 |
* All rights reserved.
|
|
4 |
* This component and the accompanying materials are made available
|
|
5 |
* under the terms of "Eclipse Public License v1.0"
|
|
6 |
* which accompanies this distribution, and is available
|
|
7 |
* at the URL "http://www.eclipse.org/legal/epl-v10.html".
|
|
8 |
*
|
|
9 |
* Initial Contributors:
|
|
10 |
* Nokia Corporation - initial contribution.
|
|
11 |
*
|
|
12 |
* Contributors:
|
|
13 |
*
|
|
14 |
* Description: Gesture and physics helper declaration
|
|
15 |
*
|
|
16 |
*/
|
|
17 |
|
|
18 |
#include "tseventcontroler.h"
|
|
19 |
#include "tsphysicsengine.h"
|
|
20 |
|
|
21 |
// -----------------------------------------------------------------------------
|
|
22 |
// NewLC
|
|
23 |
// -----------------------------------------------------------------------------
|
|
24 |
//
|
|
25 |
CTsEventControler* CTsEventControler::NewLC(
|
|
26 |
MTsEventControlerObserver& aObserver,
|
|
27 |
CCoeControl& aEventSrc)
|
|
28 |
{
|
|
29 |
CTsEventControler* self =
|
|
30 |
new(ELeave)CTsEventControler(aObserver);
|
|
31 |
CleanupStack::PushL(self);
|
|
32 |
self->ConstructL(aEventSrc);
|
|
33 |
return self;
|
|
34 |
}
|
|
35 |
|
|
36 |
// -----------------------------------------------------------------------------
|
|
37 |
// NewL
|
|
38 |
// -----------------------------------------------------------------------------
|
|
39 |
//
|
|
40 |
CTsEventControler* CTsEventControler::NewL(
|
|
41 |
MTsEventControlerObserver& aObserver,
|
|
42 |
CCoeControl& aEventSrc)
|
|
43 |
{
|
|
44 |
CTsEventControler* self =
|
|
45 |
CTsEventControler::NewLC(aObserver, aEventSrc);
|
|
46 |
CleanupStack::Pop(self);
|
|
47 |
return self;
|
|
48 |
}
|
|
49 |
|
|
50 |
// -----------------------------------------------------------------------------
|
|
51 |
// ~CTsPointerHandler
|
|
52 |
// -----------------------------------------------------------------------------
|
|
53 |
//
|
|
54 |
CTsEventControler::~CTsEventControler()
|
|
55 |
{
|
|
56 |
delete iGestureHelper;
|
|
57 |
delete iPhysicsHelper;
|
|
58 |
}
|
|
59 |
|
|
60 |
// -----------------------------------------------------------------------------
|
|
61 |
// CTsPointerHandler
|
|
62 |
// -----------------------------------------------------------------------------
|
|
63 |
//
|
|
64 |
CTsEventControler::CTsEventControler(
|
|
65 |
MTsEventControlerObserver& aObserver)
|
|
66 |
:
|
|
67 |
CBase(),
|
|
68 |
iObserver(aObserver),
|
|
69 |
iHandleEvents(ETrue),
|
|
70 |
iHandleDragEvents(ETrue)
|
|
71 |
{
|
|
72 |
}
|
|
73 |
|
|
74 |
// -----------------------------------------------------------------------------
|
|
75 |
// ConstructL
|
|
76 |
// -----------------------------------------------------------------------------
|
|
77 |
//
|
|
78 |
void CTsEventControler::ConstructL(CCoeControl& aEventSrc)
|
|
79 |
{
|
|
80 |
iGestureHelper =
|
|
81 |
AknTouchGestureFw::CAknTouchGestureFw::NewL(*this, aEventSrc);
|
|
82 |
iGestureHelper->SetGestureInterestL(EAknTouchGestureFwAll);
|
|
83 |
iPhysicsHelper = CTsPhysicsEngine::NewL(*this, aEventSrc);
|
|
84 |
}
|
|
85 |
|
|
86 |
// -----------------------------------------------------------------------------
|
|
87 |
// HandleTouchGestureL
|
|
88 |
// -----------------------------------------------------------------------------
|
|
89 |
//
|
|
90 |
void CTsEventControler::HandleTouchGestureL(
|
|
91 |
AknTouchGestureFw::MAknTouchGestureFwEvent& aEvent)
|
|
92 |
{
|
|
93 |
if ( iHandleEvents )
|
|
94 |
{
|
|
95 |
if (AknTouchGestureFwEventDrag(aEvent))
|
|
96 |
{
|
|
97 |
HandleDragEventL(*AknTouchGestureFwEventDrag(aEvent));
|
|
98 |
}
|
|
99 |
else if (AknTouchGestureFwEventTap(aEvent))
|
|
100 |
{
|
|
101 |
HandleTapEventL(*AknTouchGestureFwEventTap(aEvent));
|
|
102 |
}
|
|
103 |
//ignore flick and pinch events
|
|
104 |
}
|
|
105 |
}
|
|
106 |
|
|
107 |
// -----------------------------------------------------------------------------
|
|
108 |
// HandleTapEventL
|
|
109 |
// -----------------------------------------------------------------------------
|
|
110 |
//
|
|
111 |
void CTsEventControler::HandleTapEventL(
|
|
112 |
MAknTouchGestureFwTapEvent& aEvent)
|
|
113 |
{
|
|
114 |
if(EAknTouchGestureFwLongTap == aEvent.Type())
|
|
115 |
{
|
|
116 |
if( IsPhysicsRunning() )
|
|
117 |
{
|
|
118 |
iPhysicsHelper->Stop();
|
|
119 |
}
|
|
120 |
iObserver.LongTapL(aEvent.Position());
|
|
121 |
}
|
|
122 |
else if(EAknTouchGestureFwTap == aEvent.Type())
|
|
123 |
{
|
|
124 |
if( IsPhysicsRunning() )
|
|
125 |
{
|
|
126 |
iPhysicsHelper->Stop();
|
|
127 |
}
|
|
128 |
else
|
|
129 |
{
|
|
130 |
iObserver.TapL(aEvent.Position());
|
|
131 |
}
|
|
132 |
}
|
|
133 |
}
|
|
134 |
|
|
135 |
// -----------------------------------------------------------------------------
|
|
136 |
// HandleDragEventL
|
|
137 |
// -----------------------------------------------------------------------------
|
|
138 |
//
|
|
139 |
void CTsEventControler::HandleDragEventL(
|
|
140 |
MAknTouchGestureFwDragEvent& aEvent)
|
|
141 |
{
|
|
142 |
if ( iHandleDragEvents )
|
|
143 |
{
|
|
144 |
iObserver.DragL(aEvent);
|
|
145 |
if ( iHandleEvents && iHandleDragEvents )
|
|
146 |
{
|
|
147 |
iPhysicsHelper->HandleDragEvent(aEvent);
|
|
148 |
}
|
|
149 |
}
|
|
150 |
}
|
|
151 |
|
|
152 |
// -----------------------------------------------------------------------------
|
|
153 |
// PhysicEmulationEnded
|
|
154 |
// -----------------------------------------------------------------------------
|
|
155 |
//
|
|
156 |
void CTsEventControler::ViewPositionChanged(const TPoint& aNewPosition,
|
|
157 |
TBool aDrawNow,
|
|
158 |
TUint /*aFlags*/)
|
|
159 |
{
|
|
160 |
iObserver.MoveOffset(aNewPosition, aDrawNow);
|
|
161 |
}
|
|
162 |
|
|
163 |
// -----------------------------------------------------------------------------
|
|
164 |
// PhysicEmulationEnded
|
|
165 |
// -----------------------------------------------------------------------------
|
|
166 |
//
|
|
167 |
void CTsEventControler::PhysicEmulationEnded()
|
|
168 |
{
|
|
169 |
iObserver.Stop();
|
|
170 |
}
|
|
171 |
|
|
172 |
// -----------------------------------------------------------------------------
|
|
173 |
// ViewPosition
|
|
174 |
// -----------------------------------------------------------------------------
|
|
175 |
//
|
|
176 |
TPoint CTsEventControler::ViewPosition() const
|
|
177 |
{
|
|
178 |
return iObserver.ViewPos();
|
|
179 |
}
|
|
180 |
|
|
181 |
// -----------------------------------------------------------------------------
|
|
182 |
// Animate
|
|
183 |
// -----------------------------------------------------------------------------
|
|
184 |
//
|
|
185 |
void CTsEventControler::Animate(const TPoint& aPoint)
|
|
186 |
{
|
|
187 |
iPhysicsHelper->AnimateToTarget(aPoint);
|
|
188 |
}
|
|
189 |
|
|
190 |
// -----------------------------------------------------------------------------
|
|
191 |
// ReInitPhysicL
|
|
192 |
// -----------------------------------------------------------------------------
|
|
193 |
//
|
|
194 |
void CTsEventControler::ReInitPhysicsL(const TSize& aWorldSize,
|
|
195 |
const TSize& aViewSize, TBool aLandscape)
|
|
196 |
{
|
|
197 |
iPhysicsHelper->ReInitPhysicsL( aWorldSize, aViewSize, aLandscape);
|
|
198 |
}
|
|
199 |
|
|
200 |
// -----------------------------------------------------------------------------
|
|
201 |
// IsPhysicsRunning
|
|
202 |
// -----------------------------------------------------------------------------
|
|
203 |
//
|
|
204 |
TBool CTsEventControler::IsPhysicsRunning()
|
|
205 |
{
|
|
206 |
return iPhysicsHelper->IsRunning();
|
|
207 |
}
|
|
208 |
|
|
209 |
// -----------------------------------------------------------------------------
|
|
210 |
// StopAnimation
|
|
211 |
// -----------------------------------------------------------------------------
|
|
212 |
//
|
|
213 |
void CTsEventControler::StopAnimation()
|
|
214 |
{
|
|
215 |
iPhysicsHelper->Stop();
|
|
216 |
}
|
|
217 |
|
|
218 |
|
|
219 |
// -----------------------------------------------------------------------------
|
|
220 |
// EnableEventHandling
|
|
221 |
// -----------------------------------------------------------------------------
|
|
222 |
//
|
|
223 |
void CTsEventControler::EnableEventHandling( TBool aEnable )
|
|
224 |
{
|
|
225 |
iHandleEvents = aEnable;
|
|
226 |
if ( !aEnable && IsPhysicsRunning() )
|
|
227 |
{
|
|
228 |
iPhysicsHelper->Stop();
|
|
229 |
}
|
|
230 |
}
|
|
231 |
|
|
232 |
|
|
233 |
// -----------------------------------------------------------------------------
|
|
234 |
// EnableDragEventHandling
|
|
235 |
// -----------------------------------------------------------------------------
|
|
236 |
//
|
|
237 |
void CTsEventControler::EnableDragEventHandling( TBool aEnable )
|
|
238 |
{
|
|
239 |
iHandleDragEvents = aEnable;
|
|
240 |
if ( !aEnable && IsPhysicsRunning() )
|
|
241 |
{
|
|
242 |
iPhysicsHelper->Stop();
|
|
243 |
}
|
|
244 |
}
|
|
245 |
|
|
246 |
// end of file
|