1 #ifndef DALI_CANVAS_RENDERER_SHAPE_H
2 #define DALI_CANVAS_RENDERER_SHAPE_H
5 * Copyright (c) 2021 Samsung Electronics Co., Ltd.
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
11 * http://www.apache.org/licenses/LICENSE-2.0
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.
22 #include <dali/public-api/object/base-handle.h>
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>
32 * @addtogroup dali_adaptor_framework
36 namespace Internal DALI_INTERNAL
42 } // namespace Adaptor
43 } // namespace DALI_INTERNAL
46 * @brief Shape is a command list for drawing one shape groups
47 * It has own path data & properties for sync/asynchronous drawing
49 class DALI_ADAPTOR_API CanvasRenderer::Shape : public CanvasRenderer::Drawable
53 * @brief Creates an initialized handle to a new CanvasRenderer::Shape.
55 * @return A handle to a newly allocated Shape
61 * @brief Creates an empty handle.
62 * Use CanvasRenderer::Shape::New() to create an initialized object.
72 * @brief This copy constructor is required for (smart) pointer semantics.
74 * @param[in] handle A reference to the copied handle
76 Shape(const Shape& handle) = default;
80 * @brief Enumeration for The cap style to be used for stroking the path.
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.
90 * @brief Enumeration for The join style to be used for stroking the path.
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.
100 * @brief Enumeration for The fill rule of shape.
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.
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).
112 enum class PathCommandType
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.
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.
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.
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.
138 * roundedCorner are specified in terms of width and height respectively.
140 * If roundedCorner's values are 0, then it will draw a rectangle without rounded corner.
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.
146 bool AddRect(Rect<float> rect, Vector2 roundedCorner);
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.
154 bool AddCircle(Vector2 center, Vector2 radius);
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.
165 bool AddArc(Vector2 center, float radius, float startAngle, float sweep, bool pie);
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.
173 bool AddMoveTo(Vector2 point);
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.
183 bool AddLineTo(Vector2 line);
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.
195 bool AddCubicTo(Vector2 controlPoint1, Vector2 controlPoint2, Vector2 endPoint);
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.
205 bool AddPath(PathCommands& pathCommand);
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.
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.
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.
228 bool SetFillColor(Vector4 color);
231 * @brief Get the color to use for filling the path.
232 * @return Returns The color value.
234 Vector4 GetFillColor() const;
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.
241 bool SetFillGradient(CanvasRenderer::Gradient& gradient);
244 * @brief Get the gradient to use for filling the path.
245 * @return Returns The gradient object.
247 CanvasRenderer::Gradient GetFillGradient() const;
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.
254 bool SetFillRule(CanvasRenderer::Shape::FillRule rule);
257 * @brief Get the fill rule.
258 * @return Returns the current fill rule of the shape.
260 CanvasRenderer::Shape::FillRule GetFillRule() const;
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.
267 bool SetStrokeWidth(float width);
270 * @brief Get the stroke width to use for stroking the path.
271 * @return Returns stroke width to be used.
273 float GetStrokeWidth() const;
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.
280 bool SetStrokeColor(Vector4 color);
283 * @brief Get the color to use for stroking the path.
284 * @return Returns the stroking color.
286 Vector4 GetStrokeColor() const;
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.
293 bool SetStrokeGradient(CanvasRenderer::Gradient& gradient);
296 * @brief Get the gradient to use for stroking the path.
297 * @return Returns The gradient object.
299 CanvasRenderer::Gradient GetStrokeGradient() const;
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.
306 bool SetStrokeDash(const Dali::Vector<float>& dashPattern);
309 * @brief Gets the stroke dash pattern.
310 * @return Returns the stroke dash pattern. The dash pattern is specified dash pattern.
312 Dali::Vector<float> GetStrokeDash() const;
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.
319 bool SetStrokeCap(CanvasRenderer::Shape::StrokeCap cap);
322 * @brief Get the cap style to use for stroking the path.
323 * @return Returns the cap style.
325 CanvasRenderer::Shape::StrokeCap GetStrokeCap() const;
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.
333 bool SetStrokeJoin(CanvasRenderer::Shape::StrokeJoin join);
336 * @brief Get the join style to use for stroking the path.
337 * @return Returns join style to use.
339 CanvasRenderer::Shape::StrokeJoin GetStrokeJoin() const;
341 public: // Not intended for application developers
344 * @brief The constructor.
345 * @note Not intended for application developers.
347 * @param[in] pointer A pointer to a newly allocated CanvasRenderer::Shape
349 explicit DALI_INTERNAL Shape(Internal::Adaptor::Shape* impl);
358 #endif // DALI_CANVAS_RENDERER_SHAPE_H