f76326dd43a1894ea68d3f5821f997d31872d00e
[platform/core/uifw/dali-core.git] / dali / internal / event / events / gesture-recognizer.h
1 #ifndef DALI_INTERNAL_GESTURE_RECOGNIZER_H
2 #define DALI_INTERNAL_GESTURE_RECOGNIZER_H
3
4 /*
5  * Copyright (c) 2020 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 #include <dali/public-api/events/gesture.h>
24 #include <dali/public-api/math/vector2.h>
25 #include <dali/public-api/object/ref-object.h>
26 #include <dali/internal/event/events/gesture-event.h>
27
28 namespace Dali
29 {
30
31 namespace Integration
32 {
33 struct TouchEvent;
34 }
35
36 namespace Internal
37 {
38 struct GestureRequest;
39 class Scene;
40
41 template< typename T>
42 class RecognizerObserver
43 {
44 public:
45   virtual void Process( Scene& scene, const T& event ) = 0;
46
47   virtual ~RecognizerObserver(){};
48 };
49
50
51 /**
52  * Abstract Base class for all adaptor gesture detectors.
53  *
54  * @note this may be replaced by gesture events sent directly from X.
55  */
56 class GestureRecognizer : public RefObject
57 {
58 public:
59
60   /**
61    * Called when it gets a touch event.  The gesture recognizer should
62    * evaluate this event along with previously received events to determine
63    * whether the gesture they require has taken place.
64    * @param[in]  event  The latest touch event.
65    */
66   virtual void SendEvent(const Integration::TouchEvent& event) = 0;
67
68   /**
69    * Called when Core updates the gesture's detection requirements.
70    * @param[in]  request  The updated detection requirements.
71    */
72   virtual void Update(const GestureRequest& request) = 0;
73
74   /**
75    * Returns the type of gesture detector.
76    * @return Type of gesture detector.
77    */
78   GestureType::Value GetType() const { return mType; }
79
80   /**
81    * Called when we get a touch event.
82    * @param[in]  scene  The scene the touch event has occurred on
83    * @param[in]  event  The latest touch event
84    */
85   void SendEvent( Scene& scene, const Integration::TouchEvent& event )
86   {
87     mScene = &scene;
88     SendEvent( event );
89   }
90
91 protected:
92
93   /**
94    * Protected Constructor. Should only be able to create derived class objects.
95    * @param[in]  screenSize    The size of the screen.
96    * @param[in]  detectorType  The type of gesture detector.
97    */
98   GestureRecognizer( Vector2 screenSize, GestureType::Value detectorType )
99   : mScreenSize( screenSize ),
100     mType( detectorType ),
101     mScene( nullptr )
102   {
103   }
104
105   /**
106    * Protected Constructor. Should only be able to create derived class objects.
107    *
108    * Use this constructor with the screen size is not used in the dereived class.
109    * @param[in]  detectorType  The type of gesture detector.
110    */
111   GestureRecognizer( GestureType::Value detectorType )
112   : GestureRecognizer( Vector2::ZERO, detectorType )
113   {
114   }
115
116   /**
117    * Virtual destructor.
118    */
119   virtual ~GestureRecognizer() {}
120
121 protected:
122   Vector2 mScreenSize;
123   GestureType::Value mType;
124   Scene* mScene;
125 };
126
127 typedef IntrusivePtr<GestureRecognizer> GestureRecognizerPtr;
128
129 } // namespace Internal
130
131 } // namespace Dali
132
133 #endif // DALI_INTERNAL_GESTURE_RECOGNIZER_H