From 566b327f09e47c81396213ebad2e318c699a1a61 Mon Sep 17 00:00:00 2001 From: Mira Grudzinska Date: Thu, 30 May 2024 21:13:34 +0200 Subject: [PATCH] capi: bindings for strokeTrim Example Capi.cpp modyfied. --- examples/Capi.cpp | 5 +++++ src/bindings/capi/thorvg_capi.h | 31 +++++++++++++++++++++++++++++++ src/bindings/capi/tvgCapi.cpp | 15 +++++++++++++++ 3 files changed, 51 insertions(+) diff --git a/examples/Capi.cpp b/examples/Capi.cpp index e4721260..dfa37b16 100644 --- a/examples/Capi.cpp +++ b/examples/Capi.cpp @@ -154,6 +154,11 @@ void testCapi() tvg_shape_append_arc(scene_shape1, 175.0f, 600.0f, 150.0f, -45.0f, 90.0f, 1); tvg_shape_append_arc(scene_shape1, 175.0f, 600.0f, 150.0f, 225.0f, -90.0f, 1); tvg_shape_set_fill_color(scene_shape1, 0, 0, 255, 150); + tvg_shape_set_stroke_color(scene_shape1, 255, 255, 255, 155); + tvg_shape_set_stroke_width(scene_shape1, 10.0f); + tvg_shape_set_stroke_cap(scene_shape1, Tvg_Stroke_Cap::TVG_STROKE_CAP_ROUND); + tvg_shape_set_stroke_join(scene_shape1, Tvg_Stroke_Join::TVG_STROKE_JOIN_ROUND); + tvg_shape_set_stroke_trim(scene_shape1, 0.25f, 0.75f, true); //Set an arc with a dashed stroke Tvg_Paint* scene_shape2 = tvg_paint_duplicate(scene_shape1); diff --git a/src/bindings/capi/thorvg_capi.h b/src/bindings/capi/thorvg_capi.h index 3833fe9b..09225141 100644 --- a/src/bindings/capi/thorvg_capi.h +++ b/src/bindings/capi/thorvg_capi.h @@ -1532,6 +1532,37 @@ TVG_API Tvg_Result tvg_shape_set_stroke_miterlimit(Tvg_Paint* paint, float miter TVG_API Tvg_Result tvg_shape_get_stroke_miterlimit(const Tvg_Paint* paint, float* miterlimit); +/*! +* \brief Sets the trim of the stroke along the defined path segment, allowing control over which part of the stroke is visible. (Experimental API) +* +* The values of the arguments @p begin, @p end, and @p offset are in the range of 0.0 to 1.0, representing the beginning of the path and the end, respectively. +* +* \param[in] begin Specifies the start of the segment to display along the path. +* \param[in] end Specifies the end of the segment to display along the path. +* \param[in] simultaneous Determines how to trim multiple paths within a single shape. If set to @c true (default), trimming is applied simultaneously to all paths; +* Otherwise, all paths are treated as a single entity with a combined length equal to the sum of their individual lengths and are trimmed as such. +* +* \return Tvg_Result enumeration. +* \retval TVG_RESULT_SUCCESS Succeed. +* \retval TVG_RESULT_INVALID_ARGUMENT An invalid Tvg_Paint pointer. +*/ +TVG_API Tvg_Result tvg_shape_set_stroke_trim(Tvg_Paint* paint, float begin, float end, bool simultaneous); + + +/*! +* \brief Gets the trim of the stroke along the defined path segment. (Experimental API) +* +* \param[out] begin The starting point of the segment to display along the path. +* \param[out] end Specifies the end of the segment to display along the path. +* \param[out] simultaneous Determines how to trim multiple paths within a shape. +* +* \return Tvg_Result enumeration. +* \retval TVG_RESULT_SUCCESS Succeed. +* \retval TVG_RESULT_INVALID_ARGUMENT An invalid Tvg_Paint pointer. +*/ +TVG_API Tvg_Result tvg_shape_get_stroke_trim(Tvg_Paint* paint, float* begin, float* end, bool* simultaneous); + + /*! * \brief Sets the shape's solid color. * diff --git a/src/bindings/capi/tvgCapi.cpp b/src/bindings/capi/tvgCapi.cpp index 0d49f74b..aaf3b0c7 100644 --- a/src/bindings/capi/tvgCapi.cpp +++ b/src/bindings/capi/tvgCapi.cpp @@ -461,6 +461,21 @@ TVG_API Tvg_Result tvg_shape_get_stroke_miterlimit(const Tvg_Paint* paint, float } +TVG_API Tvg_Result tvg_shape_set_stroke_trim(Tvg_Paint* paint, float begin, float end, bool simultaneous) +{ + if (!paint) return TVG_RESULT_INVALID_ARGUMENT; + return (Tvg_Result) reinterpret_cast(paint)->strokeTrim(begin, end, simultaneous); +} + + +TVG_API Tvg_Result tvg_shape_get_stroke_trim(Tvg_Paint* paint, float* begin, float* end, bool* simultaneous) +{ + if (!paint) return TVG_RESULT_INVALID_ARGUMENT; + if (simultaneous) *simultaneous = reinterpret_cast(paint)->strokeTrim(begin, end); + return TVG_RESULT_SUCCESS; +} + + TVG_API Tvg_Result tvg_shape_set_fill_color(Tvg_Paint* paint, uint8_t r, uint8_t g, uint8_t b, uint8_t a) { if (!paint) return TVG_RESULT_INVALID_ARGUMENT;