From: Mateusz Palkowski Date: Fri, 31 Jul 2020 09:34:49 +0000 (+0200) Subject: capi: Added C wrappers for gradient func X-Git-Tag: accepted/tizen/unified/20200806.062539~7 X-Git-Url: http://review.tizen.org/git/?a=commitdiff_plain;h=7b9c7de1e5eca8e9fe300e17407ada28dc117802;p=platform%2Fcore%2Fgraphics%2Ftizenvg.git capi: Added C wrappers for gradient func Change-Id: If41dab9b06f6cec2831ea1361f30b50a193e99c4 --- diff --git a/inc/thorvg_capi.h b/inc/thorvg_capi.h index 9fa4d59..037730f 100644 --- a/inc/thorvg_capi.h +++ b/inc/thorvg_capi.h @@ -35,6 +35,7 @@ extern "C" { typedef struct _Tvg_Canvas Tvg_Canvas; typedef struct _Tvg_Paint Tvg_Paint; +typedef struct _Tvg_Gradient Tvg_Gradient; #define TVG_ENGINE_SW (1 << 1) #define TVG_ENGINE_GL (1 << 2) @@ -93,6 +94,11 @@ typedef struct float e31, e32, e33; } Tvg_Matrix; +typedef struct +{ + float offset; + uint8_t r, g, b, a; +} Tvg_Color_Stop; /************************************************************************/ /* Engine API */ @@ -144,6 +150,20 @@ TVG_EXPORT Tvg_Result tvg_shape_scale(Tvg_Paint* paint, float factor); TVG_EXPORT Tvg_Result tvg_shape_rotate(Tvg_Paint* paint, float degree); TVG_EXPORT Tvg_Result tvg_shape_translate(Tvg_Paint* paint, float x, float y); TVG_EXPORT Tvg_Result tvg_shape_transform(Tvg_Paint* paint, const Tvg_Matrix* m); +TVG_EXPORT Tvg_Result tvg_shape_linear_gradient_set(Tvg_Paint* paint, Tvg_Gradient *grad); +TVG_EXPORT Tvg_Result tvg_shape_radial_gradient_set(Tvg_Paint* paint, Tvg_Gradient *grad); + + +/************************************************************************/ +/* Gradient API */ +/************************************************************************/ +TVG_EXPORT Tvg_Gradient* tvg_linear_gradient_new(); +TVG_EXPORT Tvg_Gradient* tvg_radial_gradient_new(); +TVG_EXPORT Tvg_Result tvg_gradient_del(Tvg_Gradient* grad); +TVG_EXPORT Tvg_Result tvg_linear_gradient_set(Tvg_Gradient* grad, float x1, float y1, float x2, float y2); +TVG_EXPORT Tvg_Result tvg_radial_gradient_set(Tvg_Gradient* grad, float cx, float cy, float radius); +TVG_EXPORT Tvg_Result tvg_gradient_color_stops(Tvg_Gradient* grad, const Tvg_Color_Stop* color_stop, uint32_t cnt); + #ifdef __cplusplus } diff --git a/src/bindings/capi/tvgCapi.cpp b/src/bindings/capi/tvgCapi.cpp index 9ceb113..5df6b5a 100644 --- a/src/bindings/capi/tvgCapi.cpp +++ b/src/bindings/capi/tvgCapi.cpp @@ -35,6 +35,11 @@ struct _Tvg_Paint //Dummy for Direct Casting }; +struct _Tvg_Gradient +{ + //Dummy for Direct Casting +}; + /************************************************************************/ /* Engine API */ @@ -246,6 +251,52 @@ TVG_EXPORT Tvg_Result tvg_shape_transform(Tvg_Paint* paint, const Tvg_Matrix* m) return (Tvg_Result) reinterpret_cast(paint)->transform(*(reinterpret_cast(m))); } +TVG_EXPORT Tvg_Result tvg_shape_linear_gradient_set(Tvg_Paint* paint, Tvg_Gradient *grad) +{ + return (Tvg_Result) reinterpret_cast(paint)->fill(unique_ptr((LinearGradient*)(grad))); +} + +TVG_EXPORT Tvg_Result tvg_shape_radial_gradient_set(Tvg_Paint* paint, Tvg_Gradient *grad) +{ + return (Tvg_Result) reinterpret_cast(paint)->fill(unique_ptr((RadialGradient*)(grad))); +} + + +/************************************************************************/ +/* Gradient API */ +/************************************************************************/ +TVG_EXPORT Tvg_Gradient* tvg_linear_gradient_new() +{ + return (Tvg_Gradient*)LinearGradient::gen().release(); +} + +TVG_EXPORT Tvg_Gradient* tvg_radial_gradient_new() +{ + return (Tvg_Gradient*)RadialGradient::gen().release(); + +} + +TVG_EXPORT Tvg_Result tvg_gradient_del(Tvg_Gradient* grad) +{ + delete(grad); + return TVG_RESULT_SUCCESS; +} + +TVG_EXPORT Tvg_Result tvg_linear_gradient_set(Tvg_Gradient* grad, float x1, float y1, float x2, float y2) +{ + return (Tvg_Result) reinterpret_cast(grad)->linear(x1, y1, x2, y2); +} + +TVG_EXPORT Tvg_Result tvg_radial_gradient_set(Tvg_Gradient* grad, float cx, float cy, float radius) +{ + return (Tvg_Result) reinterpret_cast(grad)->radial(cx, cy, radius); +} + +TVG_EXPORT Tvg_Result tvg_gradient_color_stops(Tvg_Gradient* grad, const Tvg_Color_Stop* color_stop, uint32_t cnt) +{ + return (Tvg_Result) reinterpret_cast(grad)->colorStops(reinterpret_cast(color_stop), cnt); +} + #ifdef __cplusplus } #endif \ No newline at end of file diff --git a/test/testCapi.c b/test/testCapi.c index 6a46e97..3a307ab 100644 --- a/test/testCapi.c +++ b/test/testCapi.c @@ -20,11 +20,36 @@ void testCapi() Tvg_Paint* shape = tvg_shape_new(); tvg_shape_append_rect(shape, 0, 0, 200, 200, 0, 0); + tvg_shape_append_circle(shape, 200, 200, 100, 100); tvg_shape_append_rect(shape, 100, 100, 300, 300, 100, 100); - tvg_shape_append_circle(shape, 400, 400, 100, 100); - tvg_shape_append_circle(shape, 400, 500, 170, 100); - tvg_shape_fill_color(shape, 255, 255, 0, 255); + Tvg_Gradient* grad = tvg_linear_gradient_new(); + tvg_linear_gradient_set(grad, 0, 0, 300, 300); + Tvg_Color_Stop color_stops[4] = + { + {.offset=0.0, .r=0, .g=0, .b=0, .a=255}, + {.offset=0.25, .r=255, .g=0, .b=0, .a=255}, + {.offset=0.5, .r=0, .g=255, .b=0, .a=255}, + {.offset=1.0, .r=0, .g=0, .b=255, .a=255} + }; + + Tvg_Paint *shape1 = tvg_shape_new(); + tvg_shape_append_rect(shape1, 500, 500, 100, 100, 30, 30); + Tvg_Gradient* grad1 = tvg_radial_gradient_new(); + tvg_radial_gradient_set(grad1, 550, 550, 50); + Tvg_Color_Stop color_stops1[3] = + { + {.offset=0.0, .r=0, .g=0, .b=0, .a=255}, + {.offset=0.6, .r=255, .g=0, .b=0, .a=255}, + {.offset=1.0, .r=0, .g=255, .b=255, .a=255} + }; + + tvg_gradient_color_stops(grad, color_stops, 4); + tvg_gradient_color_stops(grad1, color_stops1, 3); + tvg_shape_linear_gradient_set(shape, grad); + tvg_shape_radial_gradient_set(shape1, grad1); + tvg_canvas_push(canvas, shape); + tvg_canvas_push(canvas, shape1); tvg_canvas_draw(canvas); tvg_canvas_sync(canvas);