[dali_2.3.23] Merge branch 'devel/master'
[platform/core/uifw/dali-core.git] / dali / integration-api / events / point.h
1 #ifndef DALI_INTEGRATION_POINT_H
2 #define DALI_INTEGRATION_POINT_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/devel-api/events/touch-point.h>
23 #include <dali/public-api/events/device.h>
24 #include <dali/public-api/events/mouse-button.h>
25 #include <dali/public-api/events/point-state.h>
26 #include <dali/public-api/math/degree.h>
27 #include <dali/public-api/math/vector2.h>
28
29 namespace Dali
30 {
31 namespace Integration
32 {
33 /**
34  * @brief A Point represents a point on the screen that is currently being touched or where touch has stopped.
35  */
36 struct DALI_CORE_API Point
37 {
38   /**
39    * @brief Default Constructor
40    */
41   Point();
42
43   /**
44    * @brief Constructor which creates a Point instance from a TouchPoint.
45    * @param[in]  touchPoint  The touch-point to copy from.
46    */
47   explicit Point(const TouchPoint& touchPoint);
48
49   /**
50    * @brief Destructor
51    */
52   ~Point();
53
54   /**
55    * @brief Set the Unique Device ID.
56    *
57    * Each touch point has a unique device ID which specifies the touch device for that point.
58    *
59    * @param[in]  deviceId  The Unique Device ID.
60    */
61   void SetDeviceId(int32_t deviceId);
62
63   /**
64    * @brief Set the state of the point.
65    * @param[in]  state  The state of the point.
66    */
67   void SetState(PointState::Type state);
68
69   /**
70    * @brief Set the screen position of the point from the top-left of the screen.
71    * @param[in]  screenPosition  The screen position of the point from the top-left of the screen.
72    */
73   void SetScreenPosition(const Vector2& screenPosition);
74
75   /**
76    * @brief Set the radius of the press point.
77    *
78    * This is the average of both the horizontal and vertical radii of the press point.
79    * @param[in]  radius  The average of both the horizontal and vertical radii.
80    */
81   void SetRadius(float radius);
82
83   /**
84    * @brief Set the radius of the press point as an ellipse.
85    * @param[in]  radius         The average of both the horizontal and vertical radii.
86    * @param[in]  ellipseRadius  The horizontal and vertical radii of the press point (different if an ellipse).
87    */
88   void SetRadius(float radius, Vector2 ellipseRadius);
89
90   /**
91    * @brief Sets the touch pressure.
92    *
93    * The pressure range starts at 0.0f.
94    * Normal pressure is defined as 1.0f.
95    * A value between 0.0f and 1.0f means light pressure has been applied.
96    * A value greater than 1.0f means more pressure than normal has been applied.
97    *
98    * @param[in]  pressure  The touch pressure.
99    */
100   void SetPressure(float pressure);
101
102   /**
103    * @brief Sets the angle of the press point relative to the Y-Axis.
104    * @param[in]  angle  The angle of the press point relative to the Y-Axis.
105    */
106   void SetAngle(Degree angle);
107
108   /**
109    * @brief Sets the class of the device for the event
110    * @param[in] deviceClass The class of the device.
111    */
112   void SetDeviceClass(Device::Class::Type deviceClass);
113
114   /**
115    * @brief Sets the subclass of the device for the event
116    * @param[in] deviceSubclass The subclass of the device.
117    */
118   void SetDeviceSubclass(Device::Subclass::Type deviceSubclass);
119
120   /**
121    * @brief Retrieve the Unique Device ID of the point.
122    * @return The Unique Device ID of the point.
123    */
124   int GetDeviceId() const;
125
126   /**
127    * @brief Retrieve the state of the point.
128    * @return The state of the point.
129    */
130   PointState::Type GetState() const;
131
132   /**
133    * @brief Retrieve the screen position from the top-left of the screen.
134    * @return The screen position from the top-left of the screen.
135    */
136   const Vector2& GetScreenPosition() const;
137
138   /**
139    * @brief Retrieve the radius of the press point.
140    * @return The radius of the press point.
141    * @see SetRadius(float)
142    * @see SetRadius(float,Vector2)
143    */
144   float GetRadius() const;
145
146   /**
147    * @brief Retrieve BOTH the horizontal and the vertical radii of the press point.
148    * @return The radius of the press point.
149    * @see SetRadius(float)
150    * @see SetRadius(float,Vector2)
151    */
152   const Vector2& GetEllipseRadius() const;
153
154   /**
155    * @brief Retrieves the touch pressure.
156    *
157    * @return The touch pressure.
158    * @see SetPressure()
159    */
160   float GetPressure() const;
161
162   /**
163    * @brief Retrieve the angle of the press point relative to the Y-Axis.
164    * @return The angle of the press point.
165    */
166   Degree GetAngle() const;
167
168   /**
169    * @brief Retrieve the class of the device for the event.
170    * @return The class of the device
171    */
172   Device::Class::Type GetDeviceClass() const;
173
174   /**
175    * @brief Retrieve the subclass of the device for the event.
176    * @return The subclass of the device
177    */
178   Device::Subclass::Type GetDeviceSubclass() const;
179
180   /**
181    * @brief Get Mouse Button value. (ex: right/left button)
182    * @return The mouse button value.
183    */
184   MouseButton::Type GetMouseButton() const;
185
186   /**
187    * @brief Set Mouse Button value. (ex: right/left button)
188    */
189   void SetMouseButton(MouseButton::Type button);
190
191 public: // Not intended for Integration API developers
192   /**
193    * @brief Sets the hit actor under this point.
194    * @param[in]  hitActor  The hit actor.
195    */
196   DALI_INTERNAL void SetHitActor(Actor hitActor);
197
198   /**
199    * @brief Set the co-ordinates relative to the top-left of the hit-actor.
200    * @param[in]  localPosition  The local position.
201    * @note The top-left of an actor is (0.0, 0.0, 0.5).
202    */
203   DALI_INTERNAL void SetLocalPosition(const Vector2& localPosition);
204
205   /**
206    * @brief Retrieve the Hit Actor.
207    * @return The hit actor.
208    */
209   DALI_INTERNAL Actor GetHitActor() const;
210
211   /**
212    * @brief Retrieve the local position relative to the top-left of the hit-actor.
213    * @return The local position.
214    * @note The top-left of an actor is (0.0, 0.0, 0.5).
215    */
216   DALI_INTERNAL const Vector2& GetLocalPosition() const;
217
218   /**
219    * @brief Retrieve the touch point equivalent of this point for old API.
220    * @return The touch point equivalent.
221    */
222   DALI_INTERNAL const TouchPoint& GetTouchPoint() const;
223
224 private:
225   TouchPoint             mTouchPoint;    ///< Stores screen position, device Id, local & screen positions and the hit-actor. @see TouchPoint
226   Vector2                mEllipseRadius; ///< Radius of both the horizontal and vertical radius (useful if an ellipse).
227   Degree                 mAngle;         ///< The angle of the press point, relative to the Y-Axis.
228   Device::Class::Type    mDeviceClass;
229   Device::Subclass::Type mDeviceSubclass;
230   float                  mPressure;    ///< The touch pressure.
231   float                  mRadius;      ///< Radius of the press point, an average of the ellipse radius.
232   MouseButton::Type      mMouseButton; /// < mouse button value.
233 };
234
235 } // namespace Integration
236
237 } // namespace Dali
238
239 #endif // DALI_INTEGRATION_POINT_H