(Canvas Renderer) Moved Devel Headers into sub-folder to improve SAM score
[platform/core/uifw/dali-adaptor.git] / dali / devel-api / adaptor-framework / canvas-renderer / canvas-renderer-shape.h
1 #ifndef DALI_CANVAS_RENDERER_SHAPE_H
2 #define DALI_CANVAS_RENDERER_SHAPE_H
3
4 /*
5  * Copyright (c) 2022 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/object/base-handle.h>
23
24 // INTERNAL INCLUDES
25 #include <dali/devel-api/adaptor-framework/canvas-renderer/canvas-renderer-drawable.h>
26 #include <dali/devel-api/adaptor-framework/canvas-renderer/canvas-renderer.h>
27 #include <dali/public-api/dali-adaptor-common.h>
28
29 namespace Dali
30 {
31 /**
32  * @addtogroup dali_adaptor_framework
33  * @{
34  */
35
36 namespace Internal DALI_INTERNAL
37 {
38 namespace Adaptor
39 {
40 class CanvasRenderer;
41 class Shape;
42 } // namespace Adaptor
43 } // namespace DALI_INTERNAL
44
45 /**
46  * @brief Shape is a command list for drawing one shape groups
47  * It has own path data & properties for sync/asynchronous drawing
48  */
49 class DALI_ADAPTOR_API CanvasRenderer::Shape : public CanvasRenderer::Drawable
50 {
51 public:
52   /**
53    * @brief Creates an initialized handle to a new CanvasRenderer::Shape.
54    *
55    * @return A handle to a newly allocated Shape
56    */
57   static Shape New();
58
59 public:
60   /**
61    * @brief Creates an empty handle.
62    * Use CanvasRenderer::Shape::New() to create an initialized object.
63    */
64   Shape();
65
66   /**
67    * @brief Destructor.
68    */
69   ~Shape();
70
71   /**
72    * @brief This copy constructor is required for (smart) pointer semantics.
73    *
74    * @param[in] handle A reference to the copied handle
75    */
76   Shape(const Shape& handle) = default;
77
78 public:
79   /**
80    * @brief Enumeration for The cap style to be used for stroking the path.
81    */
82   enum class StrokeCap
83   {
84     SQUARE = 0, ///< The end of lines is rendered as a square around the last point.
85     ROUND,      ///< The end of lines is rendered as a half-circle around the last point.
86     BUTT        ///< The end of lines is rendered as a full stop on the last point itself.
87   };
88
89   /**
90    * @brief Enumeration for The join style to be used for stroking the path.
91    */
92   enum class StrokeJoin
93   {
94     BEVEL = 0, ///< Used to render beveled line joins. The outer corner of the joined lines is filled by enclosing the triangular region of the corner with a straight line between the outer corners of each stroke.
95     ROUND,     ///< Used to render rounded line joins. Circular arcs are used to join two lines smoothly.
96     MITER      ///< Used to render mitered line joins. The intersection of the strokes is clipped at a line perpendicular to the bisector of the angle between the strokes, at the distance from the intersection of the segments equal to the product of the miter limit value and the border radius.  This prevents long spikes being created.
97   };
98
99   /**
100    * @brief Enumeration for The fill rule of shape.
101    */
102   enum class FillRule
103   {
104     WINDING = 0, ///< Draw a horizontal line from the point to a location outside the shape. Determine whether the direction of the line at each intersection point is up or down. The winding number is determined by summing the direction of each intersection. If the number is non zero, the point is inside the shape.
105     EVEN_ODD     ///< Draw a horizontal line from the point to a location outside the shape, and count the number of intersections. If the number of intersections is an odd number, the point is inside the shape.
106   };
107
108   /**
109    * @brief Enumeration specifying the values of the path commands.
110    * Not to be confused with the path commands from the svg path element (like M, L, Q, H and many others).
111    */
112   enum class PathCommandType
113   {
114     CLOSE = 0, ///< Ends the current sub-path and connects it with its initial point. This command doesn't expect any points.
115     MOVE_TO,   ///< Sets a new initial point of the sub-path and a new current point. This command expects 1 point: the starting position.
116     LINE_TO,   ///< Draws a line from the current point to the given point and sets a new value of the current point. This command expects 1 point: the end-position of the line.
117     CUBIC_TO   ///< Draws a cubic Bezier curve from the current point to the given point using two given control points and sets a new value of the current point. This command expects 3 points: the 1st control-point, the 2nd control-point, the end-point of the curve.
118   };
119
120   /**
121    * @brief Structure that contains information about a list of path commands.
122    * For each command from the mCommands array, an appropriate number of points in mPoints array should be specified.
123    */
124   struct PathCommands
125   {
126     PathCommandType* mCommands;     ///< Set of each PathComand.
127     uint32_t         mCommandCount; ///< The number of command array.
128     float*           mPoints;       ///< Set of each Point
129     uint32_t         mPointCount;   ///< The number of point array.
130   };
131
132 public:
133   /**
134    * @brief Append the given rectangle with rounded corner to the path.
135    * The roundedCorner arguments specify the radii of the ellipses defining the
136    * corners of the rounded rectangle.
137    *
138    * roundedCorner are specified in terms of width and height respectively.
139    *
140    * If roundedCorner's values are 0, then it will draw a rectangle without rounded corner.
141    *
142    * @param[in] rect size of the rectangle.
143    * @param[in] roundedCorner The radius of the rounded corner and should be in range [ 0 to w/2 ]
144    * @return Returns True when it's successful. False otherwise.
145    */
146   bool AddRect(Rect<float> rect, Vector2 roundedCorner);
147
148   /**
149    * @brief Append a circle with given center and x,y-axis radius.
150    * @param[in] center X and Y co-ordinate of the center of the circle.
151    * @param[in] radius X and Y co-ordinate of radius of the circle.
152    * @return Returns True when it's successful. False otherwise.
153    */
154   bool AddCircle(Vector2 center, Vector2 radius);
155
156   /**
157    * @brief Append the arcs .
158    * @param[in] center X and Y co-ordinate of the center of the arc.
159    * @param[in] radius Radius of the arc.
160    * @param[in] startAngle Start angle (in degrees) where the arc begins.
161    * @param[in] sweep The Angle measures how long the arc will be drawn.
162    * @param[in] pie If True, the area is created by connecting start angle point and sweep angle point of the drawn arc. If false, it doesn't.
163    * @return Returns True when it's successful. False otherwise.
164    */
165   bool AddArc(Vector2 center, float radius, float startAngle, float sweep, bool pie);
166
167   /**
168    * @brief Add a point that sets the given point as the current point,
169    * implicitly starting a new subpath and closing the previous one.
170    * @param[in] point X and Y co-ordinate of the current point.
171    * @return Returns True when it's successful. False otherwise.
172    */
173   bool AddMoveTo(Vector2 point);
174
175   /**
176    * @brief Adds a straight line from the current position to the given end point.
177    * After the line is drawn, the current position is updated to be at the
178    * end point of the line.
179    * If no current position present, it draws a line to itself, basically * a point.
180    * @param[in] line X and Y co-ordinate of end point of the line.
181    * @return Returns True when it's successful. False otherwise.
182    */
183   bool AddLineTo(Vector2 line);
184
185   /**
186    * @brief Adds a cubic Bezier curve between the current position and the
187    * given end point (lineEndPoint) using the control points specified by
188    * (controlPoint1), and (controlPoint2). After the path is drawn,
189    * the current position is updated to be at the end point of the path.
190    * @param[in] controlPoint1 X and Y co-ordinate of 1st control point.
191    * @param[in] controlPoint2 X and Y co-ordinate of 2nd control point.
192    * @param[in] endPoint X and Y co-ordinate of end point of the line.
193    * @return Returns True when it's successful. False otherwise.
194    */
195   bool AddCubicTo(Vector2 controlPoint1, Vector2 controlPoint2, Vector2 endPoint);
196
197   /**
198    * @brief Appends a given sub-path to the path.
199    * The current point value is set to the last point from the sub-path.
200    * @param[in] pathCommand The command object that contain sub-path information. (This command information is copied internally.)
201    * @return Returns True when it's successful. False otherwise.
202    * @note The interface is designed for optimal path setting if the caller has a completed path commands already.
203    *
204    */
205   bool AddPath(PathCommands& pathCommand);
206
207   /**
208    * @brief Closes the current subpath by drawing a line to the beginning of the
209    * subpath, automatically starting a new path. The current point of the
210    * new path is (0, 0).
211    * If the subpath does not contain any points, this function does nothing.
212    * @return Returns True when it's successful. False otherwise.
213    */
214   bool Close();
215
216   /**
217    * @brief Reset the added path(rect, circle, path, etc...) information.
218    * Color and Stroke information are keeped.
219    * @return Returns True when it's successful. False otherwise.
220    */
221   bool ResetPath();
222
223   /**
224    * @brief Set the color to use for filling the path.
225    * @param[in] color The color value.
226    * @return Returns True when it's successful. False otherwise.
227    */
228   bool SetFillColor(Vector4 color);
229
230   /**
231    * @brief Get the color to use for filling the path.
232    * @return Returns The color value.
233    */
234   Vector4 GetFillColor() const;
235
236   /**
237    * @brief Set the gradient to use for filling the path.
238    * @param[in] gradient The gradient object.
239    * @return Returns True when it's successful. False otherwise.
240    */
241   bool SetFillGradient(CanvasRenderer::Gradient& gradient);
242
243   /**
244    * @brief Get the gradient to use for filling the path.
245    * @return Returns The gradient object.
246    */
247   CanvasRenderer::Gradient GetFillGradient() const;
248
249   /**
250    * @brief Set the fill rule.
251    * @param[in] rule The current fill rule of the shape.
252    * @return Returns True when it's successful. False otherwise.
253    */
254   bool SetFillRule(CanvasRenderer::Shape::FillRule rule);
255
256   /**
257    * @brief Get the fill rule.
258    * @return Returns the current fill rule of the shape.
259    */
260   CanvasRenderer::Shape::FillRule GetFillRule() const;
261
262   /**
263    * @brief Set the stroke width to use for stroking the path.
264    * @param[in] width Stroke width to be used.
265    * @return Returns True when it's successful. False otherwise.
266    */
267   bool SetStrokeWidth(float width);
268
269   /**
270    * @brief Get the stroke width to use for stroking the path.
271    * @return Returns stroke width to be used.
272    */
273   float GetStrokeWidth() const;
274
275   /**
276    * @brief Set the color to use for stroking the path.
277    * @param[in] color The stroking color.
278    * @return Returns True when it's successful. False otherwise.
279    */
280   bool SetStrokeColor(Vector4 color);
281
282   /**
283    * @brief Get the color to use for stroking the path.
284    * @return Returns the stroking color.
285    */
286   Vector4 GetStrokeColor() const;
287
288   /**
289    * @brief Set the gradient to use for stroking the path.
290    * @param[in] gradient The gradient object.
291    * @return Returns True when it's successful. False otherwise.
292    */
293   bool SetStrokeGradient(CanvasRenderer::Gradient& gradient);
294
295   /**
296    * @brief Get the gradient to use for stroking the path.
297    * @return Returns The gradient object.
298    */
299   CanvasRenderer::Gradient GetStrokeGradient() const;
300
301   /**
302    * @brief Sets the stroke dash pattern. The dash pattern is specified dash pattern.
303    * @param[in] dashPattern Lenght and a gap list.
304    * @return Returns True when it's successful. False otherwise.
305    */
306   bool SetStrokeDash(const Dali::Vector<float>& dashPattern);
307
308   /**
309    * @brief Gets the stroke dash pattern.
310    * @return Returns the stroke dash pattern. The dash pattern is specified dash pattern.
311    */
312   Dali::Vector<float> GetStrokeDash() const;
313
314   /**
315    * @brief Set the cap style to use for stroking the path. The cap will be used for capping the end point of a open subpath.
316    * @param[in] cap Cap style to use.
317    * @return Returns True when it's successful. False otherwise.
318    */
319   bool SetStrokeCap(CanvasRenderer::Shape::StrokeCap cap);
320
321   /**
322    * @brief Get the cap style to use for stroking the path.
323    * @return Returns the cap style.
324    */
325   CanvasRenderer::Shape::StrokeCap GetStrokeCap() const;
326
327   /**
328    * @brief Set the join style to use for stroking the path.
329    * The join style will be used for joining the two line segment while stroking the path.
330    * @param[in] join Join style to use.
331    * @return Returns True when it's successful. False otherwise.
332    */
333   bool SetStrokeJoin(CanvasRenderer::Shape::StrokeJoin join);
334
335   /**
336    * @brief Get the join style to use for stroking the path.
337    * @return Returns join style to use.
338    */
339   CanvasRenderer::Shape::StrokeJoin GetStrokeJoin() const;
340
341 public: // Not intended for application developers
342   /// @cond internal
343   /**
344    * @brief The constructor.
345    * @note  Not intended for application developers.
346    *
347    * @param[in] pointer A pointer to a newly allocated CanvasRenderer::Shape
348    */
349   explicit DALI_INTERNAL Shape(Internal::Adaptor::Shape* impl);
350   /// @endcond
351 };
352
353 /**
354  * @}
355  */
356 } // namespace Dali
357
358 #endif // DALI_CANVAS_RENDERER_SHAPE_H