2 // Open Service Platform
3 // Copyright (c) 2012-2013 Samsung Electronics Co., Ltd.
5 // Licensed under the Flora License, Version 1.1 (the License);
6 // you may not use this file except in compliance with the License.
7 // You may obtain a copy of the License at
9 // http://floralicense.org/license/
11 // Unless required by applicable law or agreed to in writing, software
12 // distributed under the License is distributed on an "AS IS" BASIS,
13 // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14 // See the License for the specific language governing permissions and
15 // limitations under the License.
18 * @file FUi_TouchPinchGestureDetector.cpp
19 * @brief This is the implementation file for %_TouchPinchGestureDetector class
22 * This file contains the implementation of %_TouchPinchGestureDetector class.
27 #include <FBaseColIEnumeratorT.h>
28 #include <FUiITouchPinchGestureEventListener.h>
29 #include "FUi_TouchPinchGestureDetector.h"
30 #include "FUi_ITouchPinchGestureEventListener.h"
31 #include "FUi_TouchManager.h"
32 #include "FUi_TouchPinchGestureDetectorImpl.h"
35 using namespace Tizen::Graphics;
36 using namespace Tizen::Base::Collection;
37 using namespace Tizen::Base::Runtime;
41 const int DEFAULT_TOUCH_COUNT = 2;
42 const int POLLING_PINCH = 16;
43 const int PINCH_THRESHOLD = 10;
46 namespace Tizen { namespace Ui
48 _TouchPinchGestureDetector::_TouchPinchGestureDetector(void)
49 : __MinimumPoint(0, 0)
50 , __MaximumPoint(0, 0)
51 , __centerPosition(0, 0)
53 , __threshold(PINCH_THRESHOLD)
56 result r = GetLastResult();
57 SysTryReturnVoidResult(NID_UI, r == E_SUCCESS, r, GetErrorMessage(r));
59 __pTimer = new (std::nothrow)Timer;
60 SysTryReturnVoidResult(NID_UI, __pTimer, E_OUT_OF_MEMORY, "[E_OUT_OF_MEMORY] Memory allocation failed.");
62 r = __pTimer->Construct(*this);
63 SysTryCatch(NID_UI, r == E_SUCCESS, , r, "[%s] Propagating.", GetErrorMessage(r));
65 SetDetectorType(_TOUCH_GESTURE_DETECTOR_TYPE_PINCH);
73 _TouchPinchGestureDetector::~_TouchPinchGestureDetector(void)
80 _TouchPinchGestureDetector::OnTouchPressed(const _Control& source, const _TouchInfo& touchinfo)
82 //SysLog(NID_UI, "pressId = %d, pressX = %d, pressY = %d", touchinfo.GetPointId(), touchinfo.GetCurrentPosition().x, touchinfo.GetCurrentPosition().y);
84 if (MeasureArea() > __threshold)
86 SetGestureStart(true);
87 SetDetectorState(_TOUCH_GESTURE_DETECTOR_STATE_STARTED);
89 _Control* pControl = GetControl();
90 if (pControl && !pControl->IsMultiTouchEnabled())
92 pControl->SetMultiTouchEnabled(true);
100 _TouchPinchGestureDetector::OnTouchMoved(const _Control& source, const _TouchInfo& touchinfo)
102 _TouchGestureDetectorState state = GetDetectorState();
103 //SysLog(NID_UI, "moveId = %d, moveX = %d, moveY = %d", touchinfo.GetPointId(), touchinfo.GetCurrentPosition().x, touchinfo.GetCurrentPosition().y);
105 if (state == _TOUCH_GESTURE_DETECTOR_STATE_STARTED || state == _TOUCH_GESTURE_DETECTOR_STATE_SUCCESS_AND_WAIT
106 || state == _TOUCH_GESTURE_DETECTOR_STATE_CHANGED)
108 //SysLog(NID_UI, "enter state ok");
109 if (MeasureArea() > __threshold)
111 SetDetectorState(_TOUCH_GESTURE_DETECTOR_STATE_CHANGED);
119 _TouchPinchGestureDetector::OnTimerExpired(Timer& timer)
121 SetDetectorStateChanged();
123 __pTimer->Start(POLLING_PINCH);
127 _TouchPinchGestureDetector::SetDetectorStateChanged(void)
129 _TouchGestureDetectorState state = GetDetectorState();
131 if ( state == _TOUCH_GESTURE_DETECTOR_STATE_CHANGED )
133 SetDetectorState(_TOUCH_GESTURE_DETECTOR_STATE_CHANGED);
138 _TouchPinchGestureDetector::OnTouchReleased(const _Control& source, const _TouchInfo& touchinfo)
140 //SysLog(NID_UI, "releaseId = %d, releaseX = %d, releaseY = %d", touchinfo.GetPointId(), touchinfo.GetCurrentPosition().x, touchinfo.GetCurrentPosition().y);
142 if (MeasureArea() > __threshold)
149 _TouchGestureDetectorState state = GetDetectorState();
151 if (IsGestureStarted())
153 SetGestureStart(false);
154 if (state == _TOUCH_GESTURE_DETECTOR_STATE_STARTED || state == _TOUCH_GESTURE_DETECTOR_STATE_CHANGED || state == _TOUCH_GESTURE_DETECTOR_STATE_SUCCESS_AND_WAIT)
156 SetDetectorState(_TOUCH_GESTURE_DETECTOR_STATE_FINISHED);
164 _TouchPinchGestureDetector::OnTouchCanceled(const _Control& source, const _TouchInfo& touchinfo)
167 __centerPosition.x = 0;
168 __centerPosition.y = 0;
170 __MinimumPoint.x = 0;
171 __MinimumPoint.y = 0;
172 __MaximumPoint.x = 0;
173 __MaximumPoint.y = 0;
179 _TouchPinchGestureDetector::GetCenterPoint(void) const
181 return Point(__centerPosition.x, __centerPosition.y);
185 _TouchPinchGestureDetector::GetCenterPointF(void) const
187 return __centerPosition;
191 _TouchPinchGestureDetector::GetScale(void) const
197 _TouchPinchGestureDetector::GetScaleF(void) const
203 _TouchPinchGestureDetector::MeasureArea(void)
205 _TouchManager* pTouchManager = _TouchManager::GetInstance();
206 SysTryReturn(NID_UI, pTouchManager != null, null, E_SYSTEM, "[E_SYSTEM] _TouchManager does not exist.");
208 IListT<_FingerInfo*>* pFingerInfoList = pTouchManager->GetMultiFingerInfoListN();
209 SysTryReturn(NID_UI, pFingerInfoList, null, E_OUT_OF_MEMORY, "[E_OUT_OF_MEMORY] Memory allocation failed.");
211 //SysLog(NID_UI, "GetCount = %d, minX = %d, minY = %d, maxX = %d, maxY = %d", pFingerInfoList->GetCount(), __MinimumPoint.x, __MinimumPoint.y, __MaximumPoint.x, __MaximumPoint.y);
213 bool initialized = false;
215 __MinimumPoint.x = 0;
216 __MinimumPoint.y = 0;
217 __MaximumPoint.x = 0;
218 __MaximumPoint.y = 0;
220 for (int i = 0; i < pFingerInfoList->GetCount(); i++)
222 _FingerInfo* pFingerInfo = null;
223 pFingerInfoList->GetAt(i, pFingerInfo);
225 if (pFingerInfo == null || pFingerInfo->GetPointId() == INVALID_POINT_ID ||
226 pFingerInfo->GetStatus() == _TOUCH_RELEASED || pFingerInfo->GetStatus() == _TOUCH_CANCELED)
231 //SysLog(NID_UI, "pointId = %d, x = %d, y = %d", pFingerInfo->GetPointId(), pFingerInfo->GetPoint().x, pFingerInfo->GetPoint().y);
233 Tizen::Graphics::FloatPoint point = pFingerInfo->GetPoint();
237 if (__MinimumPoint.x > point.x)
239 __MinimumPoint.x = point.x;
241 if (__MinimumPoint.y > point.y)
243 __MinimumPoint.y = point.y;
245 if (__MaximumPoint.x < point.x)
247 __MaximumPoint.x = point.x;
249 if (__MaximumPoint.y < point.y)
251 __MaximumPoint.y = point.y;
256 __MinimumPoint.x = point.x;
257 __MinimumPoint.y = point.y;
258 __MaximumPoint.x = point.x;
259 __MaximumPoint.y = point.y;
265 delete pFingerInfoList;
266 pFingerInfoList = null;
268 __centerPosition.x = (__MinimumPoint.x+__MaximumPoint.x)/2;
269 __centerPosition.y = (__MinimumPoint.y+__MaximumPoint.y)/2;
271 __scale = int(sqrt(pow(abs(__MaximumPoint.x-__MinimumPoint.x), 2) + pow(abs(__MaximumPoint.y-__MinimumPoint.y), 2)));
274 //SysLog(NID_UI, "centerX = %d, centerY = %d, area = %d", __centerPosition.x, __centerPosition.y, __scale);