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