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