Merge "CanvasRenderer: Add Gradient, LinearGradient, RadialGradient classes" into...
[platform/core/uifw/dali-adaptor.git] / dali / devel-api / adaptor-framework / canvas-renderer-shape.h
1 #ifndef DALI_CANVAS_RENDERER_SHAPE_H
2 #define DALI_CANVAS_RENDERER_SHAPE_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 // EXTERNAL INCLUDES
22 #include <dali/public-api/object/base-handle.h>
23
24 // INTERNAL INCLUDES
25 #include <dali/devel-api/adaptor-framework/canvas-renderer-drawable.h>
26 #include <dali/devel-api/adaptor-framework/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 public:
109   /**
110    * @brief Append the given rectangle with rounded corner to the path.
111    * The roundedCorner arguments specify the radii of the ellipses defining the
112    * corners of the rounded rectangle.
113    *
114    * roundedCorner are specified in terms of width and height respectively.
115    *
116    * If roundedCorner's values are 0, then it will draw a rectangle without rounded corner.
117    *
118    * @param[in] rect size of the rectangle.
119    * @param[in] roundedCorner The radius of the rounded corner and should be in range [ 0 to w/2 ]
120    * @return Returns True when it's successful. False otherwise.
121    */
122   bool AddRect(Rect<float> rect, Vector2 roundedCorner);
123
124   /**
125    * @brief Append a circle with given center and x,y-axis radius.
126    * @param[in] center X and Y co-ordinate of the center of the circle.
127    * @param[in] radius X and Y co-ordinate of radius of the circle.
128    * @return Returns True when it's successful. False otherwise.
129    */
130   bool AddCircle(Vector2 center, Vector2 radius);
131
132   /**
133    * @brief Append the arcs .
134    * @param[in] center X and Y co-ordinate of the center of the arc.
135    * @param[in] radius Radius of the arc.
136    * @param[in] startAngle Start angle (in degrees) where the arc begins.
137    * @param[in] sweep The Angle measures how long the arc will be drawn.
138    * @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.
139    * @return Returns True when it's successful. False otherwise.
140    */
141   bool AddArc(Vector2 center, float radius, float startAngle, float sweep, bool pie);
142
143   /**
144    * @brief Add a point that sets the given point as the current point,
145    * implicitly starting a new subpath and closing the previous one.
146    * @param[in] point X and Y co-ordinate of the current point.
147    * @return Returns True when it's successful. False otherwise.
148    */
149   bool AddMoveTo(Vector2 point);
150
151   /**
152    * @brief Adds a straight line from the current position to the given end point.
153    * After the line is drawn, the current position is updated to be at the
154    * end point of the line.
155    * If no current position present, it draws a line to itself, basically * a point.
156    * @param[in] line X and Y co-ordinate of end point of the line.
157    * @return Returns True when it's successful. False otherwise.
158    */
159   bool AddLineTo(Vector2 line);
160
161   /**
162    * @brief Adds a cubic Bezier curve between the current position and the
163    * given end point (lineEndPoint) using the control points specified by
164    * (controlPoint1), and (controlPoint2). After the path is drawn,
165    * the current position is updated to be at the end point of the path.
166    * @param[in] controlPoint1 X and Y co-ordinate of 1st control point.
167    * @param[in] controlPoint2 X and Y co-ordinate of 2nd control point.
168    * @param[in] endPoint X and Y co-ordinate of end point of the line.
169    * @return Returns True when it's successful. False otherwise.
170    */
171   bool AddCubicTo(Vector2 controlPoint1, Vector2 controlPoint2, Vector2 endPoint);
172
173   /**
174    * @brief Closes the current subpath by drawing a line to the beginning of the
175    * subpath, automatically starting a new path. The current point of the
176    * new path is (0, 0).
177    * If the subpath does not contain any points, this function does nothing.
178    * @return Returns True when it's successful. False otherwise.
179    */
180   bool Close();
181
182   /**
183    * @brief Reset the added path(rect, circle, path, etc...) information.
184    * Color and Stroke information are keeped.
185    * @return Returns True when it's successful. False otherwise.
186    */
187   bool ResetPath();
188
189   /**
190    * @brief Set the color to use for filling the path.
191    * @param[in] color The color value.
192    * @return Returns True when it's successful. False otherwise.
193    */
194   bool SetFillColor(Vector4 color);
195
196   /**
197    * @brief Get the color to use for filling the path.
198    * @return Returns The color value.
199    */
200   Vector4 GetFillColor() const;
201
202   /**
203    * @brief Set the gradient to use for filling the path.
204    * @param[in] gradient The gradient object.
205    * @return Returns True when it's successful. False otherwise.
206    */
207   bool SetFillGradient(CanvasRenderer::Gradient& gradient);
208
209   /**
210    * @brief Get the gradient to use for filling the path.
211    * @return Returns The gradient object.
212    */
213   CanvasRenderer::Gradient GetFillGradient() const;
214
215   /**
216    * @brief Set the fill rule.
217    * @param[in] rule The current fill rule of the shape.
218    * @return Returns True when it's successful. False otherwise.
219    */
220   bool SetFillRule(CanvasRenderer::Shape::FillRule rule);
221
222   /**
223    * @brief Get the fill rule.
224    * @return Returns the current fill rule of the shape.
225    */
226   CanvasRenderer::Shape::FillRule GetFillRule() const;
227
228   /**
229    * @brief Set the stroke width to use for stroking the path.
230    * @param[in] width Stroke width to be used.
231    * @return Returns True when it's successful. False otherwise.
232    */
233   bool SetStrokeWidth(float width);
234
235   /**
236    * @brief Get the stroke width to use for stroking the path.
237    * @return Returns stroke width to be used.
238    */
239   float GetStrokeWidth() const;
240
241   /**
242    * @brief Set the color to use for stroking the path.
243    * @param[in] color The stroking color.
244    * @return Returns True when it's successful. False otherwise.
245    */
246   bool SetStrokeColor(Vector4 color);
247
248   /**
249    * @brief Get the color to use for stroking the path.
250    * @return Returns the stroking color.
251    */
252   Vector4 GetStrokeColor() const;
253
254   /**
255    * @brief Set the gradient to use for stroking the path.
256    * @param[in] gradient The gradient object.
257    * @return Returns True when it's successful. False otherwise.
258    */
259   bool SetStrokeGradient(CanvasRenderer::Gradient& gradient);
260
261   /**
262    * @brief Get the gradient to use for stroking the path.
263    * @return Returns The gradient object.
264    */
265   CanvasRenderer::Gradient GetStrokeGradient() const;
266
267   /**
268    * @brief Sets the stroke dash pattern. The dash pattern is specified dash pattern.
269    * @param[in] dashPattern Lenght and a gap list.
270    * @return Returns True when it's successful. False otherwise.
271    */
272   bool SetStrokeDash(const Dali::Vector<float>& dashPattern);
273
274   /**
275    * @brief Gets the stroke dash pattern.
276    * @return Returns the stroke dash pattern. The dash pattern is specified dash pattern.
277    */
278   Dali::Vector<float> GetStrokeDash() const;
279
280   /**
281    * @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.
282    * @param[in] cap Cap style to use.
283    * @return Returns True when it's successful. False otherwise.
284    */
285   bool SetStrokeCap(CanvasRenderer::Shape::StrokeCap cap);
286
287   /**
288    * @brief Get the cap style to use for stroking the path.
289    * @return Returns the cap style.
290    */
291   CanvasRenderer::Shape::StrokeCap GetStrokeCap() const;
292
293   /**
294    * @brief Set the join style to use for stroking the path.
295    * The join style will be used for joining the two line segment while stroking the path.
296    * @param[in] join Join style to use.
297    * @return Returns True when it's successful. False otherwise.
298    */
299   bool SetStrokeJoin(CanvasRenderer::Shape::StrokeJoin join);
300
301   /**
302    * @brief Get the join style to use for stroking the path.
303    * @return Returns join style to use.
304    */
305   CanvasRenderer::Shape::StrokeJoin GetStrokeJoin() const;
306
307 public: // Not intended for application developers
308   /// @cond internal
309   /**
310    * @brief The constructor.
311    * @note  Not intended for application developers.
312    *
313    * @param[in] pointer A pointer to a newly allocated CanvasRenderer::Shape
314    */
315   explicit DALI_INTERNAL Shape(Internal::Adaptor::Shape* impl);
316   /// @endcond
317 };
318
319 /**
320  * @}
321  */
322 } // namespace Dali
323
324 #endif // DALI_CANVAS_RENDERER_SHAPE_H