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.
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.
114 * roundedCorner are specified in terms of width and height respectively.
116 * If roundedCorner's values are 0, then it will draw a rectangle without rounded corner.
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.
122 bool AddRect(Rect<float> rect, Vector2 roundedCorner);
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.
130 bool AddCircle(Vector2 center, Vector2 radius);
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.
141 bool AddArc(Vector2 center, float radius, float startAngle, float sweep, bool pie);
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.
149 bool AddMoveTo(Vector2 point);
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.
159 bool AddLineTo(Vector2 line);
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.
171 bool AddCubicTo(Vector2 controlPoint1, Vector2 controlPoint2, Vector2 endPoint);
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.
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.
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.
194 bool SetFillColor(Vector4 color);
197 * @brief Get the color to use for filling the path.
198 * @return Returns The color value.
200 Vector4 GetFillColor() const;
203 * @brief Set the fill rule.
204 * @param[in] rule The current fill rule of the shape.
205 * @return Returns True when it's successful. False otherwise.
207 bool SetFillRule(CanvasRenderer::Shape::FillRule rule);
210 * @brief Get the fill rule.
211 * @return Returns the current fill rule of the shape.
213 CanvasRenderer::Shape::FillRule GetFillRule() const;
216 * @brief Set the stroke width to use for stroking the path.
217 * @param[in] width Stroke width to be used.
218 * @return Returns True when it's successful. False otherwise.
220 bool SetStrokeWidth(float width);
223 * @brief Get the stroke width to use for stroking the path.
224 * @return Returns stroke width to be used.
226 float GetStrokeWidth() const;
229 * @brief Set the color to use for stroking the path.
230 * @param[in] color The stroking color.
231 * @return Returns True when it's successful. False otherwise.
233 bool SetStrokeColor(Vector4 color);
236 * @brief Get the color to use for stroking the path.
237 * @return Returns the stroking color.
239 Vector4 GetStrokeColor() const;
242 * @brief Sets the stroke dash pattern. The dash pattern is specified dash pattern.
243 * @param[in] dashPattern Lenght and a gap list.
244 * @return Returns True when it's successful. False otherwise.
246 bool SetStrokeDash(const Dali::Vector<float>& dashPattern);
249 * @brief Gets the stroke dash pattern.
250 * @return Returns the stroke dash pattern. The dash pattern is specified dash pattern.
252 Dali::Vector<float> GetStrokeDash() const;
255 * @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.
256 * @param[in] cap Cap style to use.
257 * @return Returns True when it's successful. False otherwise.
259 bool SetStrokeCap(CanvasRenderer::Shape::StrokeCap cap);
262 * @brief Get the cap style to use for stroking the path.
263 * @return Returns the cap style.
265 CanvasRenderer::Shape::StrokeCap GetStrokeCap() const;
268 * @brief Set the join style to use for stroking the path.
269 * The join style will be used for joining the two line segment while stroking the path.
270 * @param[in] join Join style to use.
271 * @return Returns True when it's successful. False otherwise.
273 bool SetStrokeJoin(CanvasRenderer::Shape::StrokeJoin join);
276 * @brief Get the join style to use for stroking the path.
277 * @return Returns join style to use.
279 CanvasRenderer::Shape::StrokeJoin GetStrokeJoin() const;
281 public: // Not intended for application developers
284 * @brief The constructor.
285 * @note Not intended for application developers.
287 * @param[in] pointer A pointer to a newly allocated CanvasRenderer::Shape
289 explicit DALI_INTERNAL Shape(Internal::Adaptor::Shape* impl);
298 #endif // DALI_CANVAS_RENDERER_SHAPE_H