bindings/capi: Added gradient getter

Co-authored-by: Michal Maciola <m.maciola@samsung.com>
This commit is contained in:
mmaciola 2020-09-23 08:09:08 +02:00 committed by GitHub
parent ce69dcd416
commit 145bafbec8
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
3 changed files with 50 additions and 2 deletions

View file

@ -159,9 +159,13 @@ TVG_EXPORT Tvg_Result tvg_shape_get_gradient(const Tvg_Paint* paint, Tvg_Gradien
TVG_EXPORT Tvg_Gradient* tvg_linear_gradient_new();
TVG_EXPORT Tvg_Gradient* tvg_radial_gradient_new();
TVG_EXPORT Tvg_Result tvg_linear_gradient_set(Tvg_Gradient* grad, float x1, float y1, float x2, float y2);
TVG_EXPORT Tvg_Result tvg_linear_gradient_get(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_radial_gradient_get(Tvg_Gradient* grad, float* cx, float* cy, float* radius);
TVG_EXPORT Tvg_Result tvg_gradient_set_color_stops(Tvg_Gradient* grad, const Tvg_Color_Stop* color_stop, uint32_t cnt);
TVG_EXPORT Tvg_Result tvg_gradient_set_spread(Tvg_Gradient* grad, const Tvg_Stroke_Fill);
TVG_EXPORT Tvg_Result tvg_gradient_get_color_stops(Tvg_Gradient* grad, const Tvg_Color_Stop** color_stop, uint32_t* cnt);
TVG_EXPORT Tvg_Result tvg_gradient_set_spread(Tvg_Gradient* grad, const Tvg_Stroke_Fill spread);
TVG_EXPORT Tvg_Result tvg_gradient_get_spread(Tvg_Gradient* grad, Tvg_Stroke_Fill* spread);
TVG_EXPORT Tvg_Result tvg_gradient_del(Tvg_Gradient* grad);

View file

@ -417,24 +417,50 @@ TVG_EXPORT Tvg_Result tvg_linear_gradient_set(Tvg_Gradient* grad, float x1, floa
return (Tvg_Result) reinterpret_cast<LinearGradient*>(grad)->linear(x1, y1, x2, y2);
}
TVG_EXPORT Tvg_Result tvg_linear_gradient_get(Tvg_Gradient* grad, float* x1, float* y1, float* x2, float* y2)
{
if (!grad) return TVG_RESULT_INVALID_ARGUMENT;
return (Tvg_Result) reinterpret_cast<LinearGradient*>(grad)->linear(x1, y1, x2, y2);
}
TVG_EXPORT Tvg_Result tvg_radial_gradient_set(Tvg_Gradient* grad, float cx, float cy, float radius)
{
if (!grad) return TVG_RESULT_INVALID_ARGUMENT;
return (Tvg_Result) reinterpret_cast<RadialGradient*>(grad)->radial(cx, cy, radius);
}
TVG_EXPORT Tvg_Result tvg_radial_gradient_get(Tvg_Gradient* grad, float* cx, float* cy, float* radius)
{
if (!grad) return TVG_RESULT_INVALID_ARGUMENT;
return (Tvg_Result) reinterpret_cast<RadialGradient*>(grad)->radial(cx, cy, radius);
}
TVG_EXPORT Tvg_Result tvg_gradient_set_color_stops(Tvg_Gradient* grad, const Tvg_Color_Stop* color_stop, uint32_t cnt)
{
if (!grad) return TVG_RESULT_INVALID_ARGUMENT;
return (Tvg_Result) reinterpret_cast<Fill*>(grad)->colorStops(reinterpret_cast<const Fill::ColorStop*>(color_stop), cnt);
}
TVG_EXPORT Tvg_Result tvg_gradient_get_color_stops(Tvg_Gradient* grad, const Tvg_Color_Stop** color_stop, uint32_t* cnt)
{
if (!grad) return TVG_RESULT_INVALID_ARGUMENT;
*cnt = reinterpret_cast<Fill*>(grad)->colorStops(reinterpret_cast<const Fill::ColorStop**>(color_stop));
return TVG_RESULT_SUCCESS;
}
TVG_EXPORT Tvg_Result tvg_gradient_set_spread(Tvg_Gradient* grad, const Tvg_Stroke_Fill spread)
{
if (!grad) return TVG_RESULT_INVALID_ARGUMENT;
return (Tvg_Result) reinterpret_cast<Fill*>(grad)->spread((FillSpread)spread);
}
TVG_EXPORT Tvg_Result tvg_gradient_get_spread(Tvg_Gradient* grad, Tvg_Stroke_Fill* spread)
{
if (!grad) return TVG_RESULT_INVALID_ARGUMENT;
*spread = (Tvg_Stroke_Fill) reinterpret_cast<Fill*>(grad)->spread();
return TVG_RESULT_SUCCESS;
}
#ifdef __cplusplus
}

View file

@ -135,7 +135,25 @@ void testCapi()
for(uint32_t i = 0; i < ptsCnt; ++i) {
printf("(%.2lf, %.2lf)\n", pts[i].x, pts[i].y);
}
float x1, y1, x2, y2, radius;
tvg_linear_gradient_get(grad, &x1, &y1, &x2, &y2);
printf("Gradient linear get: %f/%f/%f/%f\n", x1, y1, x2, y2);
tvg_radial_gradient_get(grad6, &x1, &y1, &radius);
printf("Gradient radial get: %f/%f, %f\n", x1, y1, radius);
uint32_t cnt;
const Tvg_Color_Stop* color_stops_get;
tvg_gradient_get_color_stops(grad5, &color_stops_get, &cnt);
printf("Gradient stops get:\n");
for(uint32_t i = 0; i < cnt; i++) {
printf("\t[%d] offset: %f, rgb: %d/%d/%d, alpha: %d\n", i, color_stops_get[i].offset, color_stops_get[i].r, color_stops_get[i].g, color_stops_get[i].b, color_stops_get[i].a);
}
Tvg_Stroke_Fill spread;
tvg_gradient_get_spread(grad, &spread);
printf("Gradient spread: %d\n", (int)spread);
//Origin paint for duplicated
Tvg_Paint* org = tvg_shape_new();
tvg_shape_append_rect(org, 550, 10, 100, 100, 0, 0);