* @param y2 The Y coordinate of the end point of the curve relative to the current point.
*/
vkvg_public
-void vkvg_rel_quadratic_to (VkvgContext ctx, float x1, float y1, float x2, float y2);/**
+void vkvg_rel_quadratic_to (VkvgContext ctx, float x1, float y1, float x2, float y2);
+/**
* @brief Add an axis aligned rectangle subpath to the current path.
*
* Adds a closed sub-path rectangle of the given size to the current path at position (x, y).
*/
vkvg_public
vkvg_status_t vkvg_rectangle(VkvgContext ctx, float x, float y, float w, float h);
+/**
+* @brief Add an axis aligned rectangle with rounded corners to the current path.
+*
+* Adds a closed sub-path rectangle of the given size to the current path at position (x, y).
+* @param ctx The vkvg context pointer.
+* @param x The x coordinate of the top left corner of the rectangle to emit.
+* @param y The y coordinate of the top left corner of the rectangle to emit.
+* @param w The width in pixel of the rectangle to draw.
+* @param h The height in pixel of the rectangle to draw.
+* @param radius The radius of the corners.
+* @return VKVG_STATUS_SUCCESS or VKVG_STATUS_INVALID_RECT if width or height is equal to 0.
+*/
+vkvg_public
+vkvg_status_t vkvg_rounded_rectangle (VkvgContext ctx, float x, float y, float w, float h, float radius);
/**
* @brief Stroke command
*
_finish_path(ctx);
return VKVG_STATUS_SUCCESS;
}
+vkvg_status_t vkvg_rounded_rectangle (VkvgContext ctx, float x, float y, float w, float h, float radius){
+ if (ctx->status)
+ return ctx->status;
+ _finish_path (ctx);
+
+ if (w <= 0 || h <= 0)
+ return VKVG_STATUS_INVALID_RECT;
+
+ if ((radius > w / 2.0f) || (radius > h / 2.0f))
+ radius = fmin (w / 2.0f, h / 2.0f);
+
+ vkvg_move_to(ctx, x, y + radius);
+ vkvg_arc(ctx, x + radius, y + radius, radius, (float)M_PI, (float)-M_PI_2);
+ vkvg_line_to(ctx, x + w - radius, y);
+ vkvg_arc(ctx, x + w - radius, y + radius, radius, (float)-M_PI_2, 0);
+ vkvg_line_to(ctx, x + w, y + h - radius);
+ vkvg_arc(ctx, x + w - radius, y + h - radius, radius, 0, (float)M_PI_2);
+ vkvg_line_to(ctx, x + radius, y + h);
+ vkvg_arc(ctx, x + radius, y + h - radius, radius, (float)M_PI_2, (float)M_PI);
+ vkvg_line_to(ctx, x, y + radius);
+ vkvg_close_path(ctx);
+
+ return VKVG_STATUS_SUCCESS;
+}
+
static const VkClearAttachment clearStencil = {VK_IMAGE_ASPECT_STENCIL_BIT, 1, {{{0}}}};
static const VkClearAttachment clearColorAttach = {VK_IMAGE_ASPECT_COLOR_BIT, 0, {{{0}}}};