Merge branch 'devel/master' into tizen
[platform/core/uifw/dali-core.git] / dali / internal / event / events / rotation-gesture / rotation-gesture-recognizer.h
1 #ifndef DALI_INTERNAL_EVENT_ROTATION_GESTURE_RECOGNIZER_H
2 #define DALI_INTERNAL_EVENT_ROTATION_GESTURE_RECOGNIZER_H
3
4 /*
5  * Copyright (c) 2019 Samsung Electronics Co., Ltd.
6  *
7  * Licensed under the Apache License, Version 2.0 (the "License");
8  * you may not use this file except in compliance with the License.
9  * You may obtain a copy of the License at
10  *
11  * http://www.apache.org/licenses/LICENSE-2.0
12  *
13  * Unless required by applicable law or agreed to in writing, software
14  * distributed under the License is distributed on an "AS IS" BASIS,
15  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
16  * See the License for the specific language governing permissions and
17  * limitations under the License.
18  *
19  */
20
21 // EXTERNAL INCLUDES
22 #include <dali/public-api/common/vector-wrapper.h>
23
24 // INTERNAL INCLUDES
25 #include <dali/internal/event/events/gesture-recognizer.h>
26 #include <dali/internal/event/events/rotation-gesture/rotation-gesture-event.h>
27
28 namespace Dali
29 {
30
31 namespace Integration
32 {
33 struct TouchEvent;
34 }
35
36 namespace Internal
37 {
38
39 /**
40  * When given a set of touch events, this detector attempts to determine if a rotation gesture has taken place.
41  */
42 class RotationGestureRecognizer : public GestureRecognizer
43 {
44 public:
45
46   using Observer = RecognizerObserver< RotationGestureEvent >;
47
48   /**
49    * Constructor
50    * @param[in] observer   The observer to send gesture too when it's detected
51    */
52   RotationGestureRecognizer( Observer& observer );
53
54   /**
55    * Virtual destructor.
56    */
57   virtual ~RotationGestureRecognizer() = default;
58
59 public:
60
61   /**
62    * @copydoc Dali::Internal::GestureDetector::SendEvent(const Integration::TouchEvent&)
63    */
64   virtual void SendEvent( const Integration::TouchEvent& event );
65
66   /**
67    * @copydoc Dali::Internal::GestureDetector::Update(const Integration::GestureRequest&)
68    */
69   virtual void Update( const GestureRequest& request ) { /* Nothing to do */ }
70
71 private:
72
73   /**
74    * Emits the rotation gesture event to the core.
75    * @param[in]  state         The state of the rotation (whether it's starting, continuing or finished).
76    * @param[in]  currentEvent  The latest touch event.
77    */
78   void SendRotation( Gesture::State state, const Integration::TouchEvent& currentEvent );
79
80 private:
81
82   // Reference to the gesture processor for this recognizer
83   Observer& mObserver;
84
85   /**
86    * Internal state machine.
87    */
88   enum State
89   {
90     Clear,    ///< No gesture detected.
91     Possible, ///< The current touch event data suggests that a gesture is possible.
92     Started,  ///< A gesture has been detected.
93   };
94
95   State mState; ///< The current state of the detector.
96   std::vector< Integration::TouchEvent > mTouchEvents; ///< The touch events since initial touch down.
97
98   float mStartingAngle; ///< The angle between the two touch points when the rotation is first detected.
99 };
100
101 } // namespace Internal
102
103 } // namespace Dali
104
105 #endif // DALI_INTERNAL_EVENT_ROTATION_GESTURE_RECOGNIZER_H