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