2 // Copyright (c) 2014 Samsung Electronics Co., Ltd.
4 // Licensed under the Flora License, Version 1.0 (the License);
5 // you may not use this file except in compliance with the License.
6 // You may obtain a copy of the License at
8 // http://floralicense.org/license/
10 // Unless required by applicable law or agreed to in writing, software
11 // distributed under the License is distributed on an AS IS BASIS,
12 // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 // See the License for the specific language governing permissions and
14 // limitations under the License.
18 #include <dali/internal/update/gestures/scene-graph-pan-gesture.h>
23 #include <dali/internal/update/gestures/pan-gesture-profiling.h>
37 const unsigned int ARRAY_SIZE( 4u );
39 const unsigned int UPDATES_BETWEEN_PRINT( 120u );
40 unsigned int UPDATE_COUNT( 0u );
42 } // unnamed namespace
44 PanGesture* PanGesture::New()
46 return new PanGesture();
49 PanGesture::~PanGesture()
54 void PanGesture::AddGesture( const Dali::PanGesture& gesture )
56 mGestures[ mWritePosition ] = gesture;
58 // Update our write position (so now this new value can be read)
59 // Note: we want to overwrite oldest gesture information even if it hasn't been read.
61 mWritePosition %= ARRAY_SIZE;
64 void PanGesture::UpdateProperties( unsigned int lastVSyncTime, unsigned int nextVSyncTime )
66 unsigned int time( 0u );
67 bool justStarted ( false );
68 bool justFinished ( false );
70 // If our read position is not same as write position, then there
71 // must be new values on circular buffer to read.
72 while(mReadPosition != mWritePosition)
74 const PanInfo& currentGesture = mGestures[mReadPosition];
78 mProfiling->mRawData.push_back( PanGestureProfiling::Position( currentGesture.time, currentGesture.screen.position ) );
81 if ( currentGesture.time > time )
83 justStarted |= (currentGesture.state == Gesture::Started);
84 justFinished |= (currentGesture.state == Gesture::Finished || currentGesture.state == Gesture::Cancelled);
86 // use position values direct from gesture.
87 mLatestGesture.screen.position = currentGesture.screen.position;
88 mLatestGesture.local.position = currentGesture.local.position;
90 // change displacement to be relative to initial touch, instead of relative to last touch-frame.
91 if(currentGesture.state == Gesture::Started)
93 mLatestGesture.screen.displacement = currentGesture.screen.displacement;
94 mLatestGesture.local.displacement = currentGesture.local.displacement;
98 mLatestGesture.screen.displacement += currentGesture.screen.displacement;
99 mLatestGesture.local.displacement += currentGesture.local.displacement;
102 time = currentGesture.time;
106 mReadPosition %= ARRAY_SIZE;
109 mInGesture |= justStarted;
113 PanInfo gesture(mLatestGesture);
117 mProfiling->mLatestData.push_back( PanGestureProfiling::Position( lastVSyncTime, gesture.screen.position ) );
120 if( !justStarted ) // only use previous frame if this is the continuing.
122 // If previous gesture exists, then produce position as 50/50 interpolated blend of these two points.
123 gesture.screen.position += mPreviousGesture.screen.position;
124 gesture.local.position += mPreviousGesture.local.position;
125 gesture.screen.position *= 0.5f;
126 gesture.local.position *= 0.5f;
127 // make current displacement relative to previous update-frame now.
128 gesture.screen.displacement -= mPreviousGesture.screen.displacement;
129 gesture.local.displacement -= mPreviousGesture.local.displacement;
134 mProfiling->mAveragedData.push_back( PanGestureProfiling::Position( lastVSyncTime, gesture.screen.position ) );
137 mPreviousGesture = mLatestGesture;
139 mScreenPosition.Set( gesture.screen.position );
140 mScreenDisplacement.Set( gesture.screen.displacement );
141 mLocalPosition.Set( gesture.local.position );
142 mLocalDisplacement.Set( gesture.local.displacement );
145 mInGesture &= ~justFinished;
148 UPDATE_COUNT++ >= UPDATES_BETWEEN_PRINT )
150 mProfiling->PrintData();
151 mProfiling->ClearData();
156 const GesturePropertyVector2& PanGesture::GetScreenPositionProperty() const
158 return mScreenPosition;
161 const GesturePropertyVector2& PanGesture::GetScreenDisplacementProperty() const
163 return mScreenDisplacement;
166 const GesturePropertyVector2& PanGesture::GetLocalPositionProperty() const
168 return mLocalPosition;
171 const GesturePropertyVector2& PanGesture::GetLocalDisplacementProperty() const
173 return mLocalDisplacement;
176 void PanGesture::EnableProfiling()
180 mProfiling = new PanGestureProfiling();
184 void PanGesture::ResetDefaultProperties( BufferIndex updateBufferIndex )
186 mScreenPosition.Reset();
187 mScreenDisplacement.Reset();
188 mLocalPosition.Reset();
189 mLocalDisplacement.Reset();
192 PanGesture::PanGesture()
201 } // namespace SceneGraph
203 } // namespace Internal