Revert "[Tizen] Not execute the remove callback"
[platform/core/uifw/dali-core.git] / dali / internal / event / events / touch-event-impl.h
1 #ifndef DALI_INTERNAL_TOUCH_EVENT_H
2 #define DALI_INTERNAL_TOUCH_EVENT_H
3
4 /*
5  * Copyright (c) 2021 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 // INTERNAL INCLUDES
22 #include <dali/integration-api/events/point.h>
23 #include <dali/public-api/common/vector-wrapper.h>
24 #include <dali/public-api/events/point-state.h>
25 #include <dali/public-api/events/touch-event.h>
26 #include <dali/public-api/object/base-object.h>
27
28 namespace Dali
29 {
30 class Actor;
31 struct Vector2;
32
33 namespace Internal
34 {
35 class TouchEvent;
36 using TouchEventPtr = IntrusivePtr<TouchEvent>;
37
38 /**
39  * @copydoc Dali::TouchEvent
40  */
41 class TouchEvent : public BaseObject
42 {
43 public:
44   // Construction & Destruction
45
46   /**
47    * @brief Default constructor
48    */
49   TouchEvent() = default;
50
51   /**
52    * @brief Constructor
53    * @param[in]  time  The time the event occurred
54    */
55   TouchEvent(unsigned long time)
56   : mTime(time)
57   {
58   }
59
60   /**
61    * @brief Clones the TouchEvent object.
62    *
63    * Required because base class copy constructor is not implemented.
64    * @param[in]  other  The TouchEvent to clone from.
65    * @return A new TouchEvent object which has the same touch point data.
66    */
67   static TouchEventPtr Clone(const TouchEvent& other);
68
69   TouchEvent(const TouchEvent& other) = delete;            ///< Deleted copy constructor.
70   TouchEvent(TouchEvent&& other)      = delete;            ///< Deleted move constructor.
71   TouchEvent& operator=(const TouchEvent& other) = delete; ///< Deleted copy assignment operator.
72   TouchEvent& operator=(TouchEvent&& other) = delete;      ///< Deleted move assignment operator.
73
74   // Getters
75
76   /**
77    * @copydoc Dali::TouchEvent::GetTime()
78    */
79   inline unsigned long GetTime() const
80   {
81     return mTime;
82   }
83
84   /**
85    * @copydoc Dali::TouchEvent::GetPointCount()
86    */
87   inline std::size_t GetPointCount() const
88   {
89     return mPoints.size();
90   }
91
92   /**
93    * @copydoc Dali::TouchEvent::GetDeviceId()
94    */
95   int32_t GetDeviceId(std::size_t point) const;
96
97   /**
98    * @copydoc Dali::TouchEvent::GetGetState()
99    */
100   PointState::Type GetState(std::size_t point) const;
101
102   /**
103    * @copydoc Dali::TouchEvent::GetHitActor()
104    */
105   Dali::Actor GetHitActor(std::size_t point) const;
106
107   /**
108    * @copydoc Dali::TouchEvent::GetLocalPosition()
109    */
110   const Vector2& GetLocalPosition(std::size_t point) const;
111
112   /**
113    * @copydoc Dali::TouchEvent::GetScreenPosition()
114    */
115   const Vector2& GetScreenPosition(std::size_t point) const;
116
117   /**
118    * @copydoc Dali::TouchEvent::GetRadius()
119    */
120   float GetRadius(std::size_t point) const;
121
122   /**
123    * @copydoc Dali::TouchEvent::GetEllipseRadius()
124    */
125   const Vector2& GetEllipseRadius(std::size_t point) const;
126
127   /**
128    * @copydoc Dali::TouchEvent::GetPressure()
129    */
130   float GetPressure(std::size_t point) const;
131
132   /**
133    * @copydoc Dali::TouchEvent::GetAngle()
134    */
135   Degree GetAngle(std::size_t point) const;
136
137   /**
138    * @brief Returns a const reference to a point at the index requested.
139    *
140    * The first point in the set is always the primary point (i.e. the first point touched in a multi-touch event).
141    *
142    * @param[in]  point  The index of the required Point.
143    * @return A const reference to the Point at the position requested
144    * @note point should be less than the value returned by GetPointCount(). Will assert if out of range.
145    */
146   const Integration::Point& GetPoint(std::size_t point) const;
147
148   /**
149    * @brief Returns a reference to a point at the index requested.
150    *
151    * The first point in the set is always the primary point (i.e. the first point touched in a multi-touch event).
152    *
153    * @param[in]  point  The index of the required Point.
154    * @return A reference to the Point at the position requested
155    * @note point should be less than the value returned by GetPointCount(). Will assert if out of range.
156    */
157   Integration::Point& GetPoint(std::size_t point);
158
159   /**
160    * @brief Get the device class the mouse/touch event originated from
161    *
162    * @return The device class
163    */
164   Device::Class::Type GetDeviceClass(std::size_t point) const;
165
166   /**
167    * @brief Get the device subclass the mouse/touch event originated from
168    *
169    * @return The device subclass
170    */
171   Device::Subclass::Type GetDeviceSubclass(std::size_t point) const;
172
173   /**
174    * @brief Get mouse's button value (ex: right/left button)
175    *
176    * @return The value of mouse button
177    */
178   MouseButton::Type GetMouseButton(std::size_t point) const;
179
180   // Setters
181
182   /**
183    * @brief Adds a point to this touch event handler.
184    * @param[in]  point  The point to add to the touch event handler.
185    */
186   void AddPoint(const Integration::Point& point);
187
188 private:
189   /**
190    * @brief Virtual Destructor
191    *
192    * A reference counted object may only be deleted by calling Unreference()
193    */
194   ~TouchEvent() override = default;
195
196 private:
197   std::vector<Integration::Point> mPoints;   ///< Container of the points for this touch event.
198   unsigned long                   mTime{0u}; ///< The time (in ms) that the touch event occurred.
199 };
200
201 } // namespace Internal
202
203 // Helpers for public-api forwarding methods
204
205 inline Internal::TouchEvent& GetImplementation(Dali::TouchEvent& touchEvent)
206 {
207   DALI_ASSERT_ALWAYS(touchEvent && "Touch Event handle is empty");
208
209   BaseObject& object = touchEvent.GetBaseObject();
210
211   return static_cast<Internal::TouchEvent&>(object);
212 }
213
214 inline const Internal::TouchEvent& GetImplementation(const Dali::TouchEvent& touchEvent)
215 {
216   DALI_ASSERT_ALWAYS(touchEvent && "Touch Event handle is empty");
217
218   const BaseObject& object = touchEvent.GetBaseObject();
219
220   return static_cast<const Internal::TouchEvent&>(object);
221 }
222
223 } // namespace Dali
224
225 #endif // DALI_INTERNAL_TOUCH_EVENT_H