[dali_1.4.20] Merge branch 'devel/master'
[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/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 class 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    * Called when it gets a touch event.  The gesture recognizer should
61    * evaluate this event along with previously received events to determine
62    * whether the gesture they require has taken place.
63    * @param[in]  event  The latest touch event.
64    */
65   virtual void SendEvent(const Integration::TouchEvent& event) = 0;
66
67   /**
68    * Called when Core updates the gesture's detection requirements.
69    * @param[in]  request  The updated detection requirements.
70    */
71   virtual void Update(const GestureRequest& request) = 0;
72
73   /**
74    * Returns the type of gesture detector.
75    * @return Type of gesture detector.
76    */
77   Gesture::Type GetType() const { return mType; }
78
79   void SendEvent(Scene& scene, const Integration::TouchEvent& event)
80   {
81     mScene = &scene;
82     SendEvent(event);
83   }
84
85 protected:
86
87   /**
88    * Protected Constructor.  Should only be able to create derived class objects.
89    * @param[in]  screenSize    The size of the screen.
90    * @param[in]  detectorType  The type of gesture detector.
91    */
92   GestureRecognizer( Vector2 screenSize, Gesture::Type detectorType )
93   : mScreenSize(screenSize),
94     mType(detectorType),
95     mScene(nullptr)
96   {
97   }
98
99   /**
100    * Virtual destructor.
101    */
102   virtual ~GestureRecognizer() {}
103
104 protected:
105   Vector2 mScreenSize;
106   Gesture::Type mType;
107   Scene* mScene;
108 };
109
110 typedef IntrusivePtr<GestureRecognizer> GestureRecognizerPtr;
111
112 } // namespace Internal
113
114 } // namespace Dali
115
116 #endif // DALI_INTERNAL_GESTURE_RECOGNIZER_H