bindings/capi: Added path getters + test in testCapi.c

This commit is contained in:
Piotr Kalota 2020-09-15 14:06:05 +02:00 committed by Hermet Park
parent 64c958cd2c
commit 7d08f202a8
3 changed files with 41 additions and 7 deletions

View file

@ -135,6 +135,8 @@ TVG_EXPORT Tvg_Result tvg_shape_append_rect(Tvg_Paint* paint, float x, float y,
TVG_EXPORT Tvg_Result tvg_shape_append_circle(Tvg_Paint* paint, float cx, float cy, float rx, float ry);
TVG_EXPORT Tvg_Result tvg_shape_append_arc(Tvg_Paint* paint, float cx, float cy, float radius, float startAngle, float sweep, uint8_t pie);
TVG_EXPORT Tvg_Result tvg_shape_append_path(Tvg_Paint* paint, const Tvg_Path_Command* cmds, uint32_t cmdCnt, const Tvg_Point* pts, uint32_t ptsCnt);
TVG_EXPORT Tvg_Result tvg_shape_get_path_coords(const Tvg_Paint* paint, const Tvg_Point** pts, uint32_t* cnt);
TVG_EXPORT Tvg_Result tvg_shape_get_path_commands(const Tvg_Paint* paint, const Tvg_Path_Command** cmds, uint32_t* cnt);
TVG_EXPORT Tvg_Result tvg_shape_set_stroke_width(Tvg_Paint* paint, float width);
TVG_EXPORT Tvg_Result tvg_shape_get_stroke_width(Tvg_Paint* paint, float* width);
TVG_EXPORT Tvg_Result tvg_shape_set_stroke_color(Tvg_Paint* paint, uint8_t r, uint8_t g, uint8_t b, uint8_t a);

View file

@ -254,6 +254,23 @@ TVG_EXPORT Tvg_Result tvg_shape_append_path(Tvg_Paint* paint, const Tvg_Path_Com
return (Tvg_Result) reinterpret_cast<Shape*>(paint)->appendPath((PathCommand*)cmds, cmdCnt, (Point*)pts, ptsCnt);
}
TVG_EXPORT Tvg_Result tvg_shape_get_path_coords(const Tvg_Paint* paint, const Tvg_Point** pts, uint32_t* cnt)
{
if (!paint) return TVG_RESULT_INVALID_ARGUMENT;
auto ret = reinterpret_cast<const Shape*>(paint)->pathCoords((const Point**)pts);
if (cnt) *cnt = ret;
return TVG_RESULT_SUCCESS;
}
TVG_EXPORT Tvg_Result tvg_shape_get_path_commands(const Tvg_Paint* paint, const Tvg_Path_Command** cmds, uint32_t* cnt)
{
if (!paint) return TVG_RESULT_INVALID_ARGUMENT;
auto ret = reinterpret_cast<const Shape*>(paint)->pathCommands((const PathCommand**)cmds);
if (cnt) *cnt = ret;
return TVG_RESULT_SUCCESS;
}
TVG_EXPORT Tvg_Result tvg_shape_set_stroke_width(Tvg_Paint* paint, float width)
{

View file

@ -71,10 +71,10 @@ void testCapi()
tvg_gradient_color_stops(grad1, color_stops1, 3);
tvg_gradient_color_stops(grad2, color_stops2, 2);
tvg_gradient_color_stops(grad3, color_stops3, 2);
tvg_shape_linear_gradient_set(shape, grad);
tvg_shape_radial_gradient_set(shape1, grad1);
tvg_shape_linear_gradient_set(shape2, grad2);
tvg_shape_linear_gradient_set(shape3, grad3);
tvg_shape_set_linear_gradient(shape, grad);
tvg_shape_set_radial_gradient(shape1, grad1);
tvg_shape_set_linear_gradient(shape2, grad2);
tvg_shape_set_linear_gradient(shape3, grad3);
tvg_canvas_push(canvas, shape);
tvg_canvas_push(canvas, shape1);
@ -91,7 +91,7 @@ void testCapi()
{.offset=1, .r=0, .g=255, .b=0, .a=255},
};
tvg_gradient_color_stops(grad4, color_stops4, 2);
tvg_shape_linear_gradient_set(shape4, grad4);
tvg_shape_set_linear_gradient(shape4, grad4);
Tvg_Gradient* grad5 = tvg_linear_gradient_new();
tvg_linear_gradient_set(grad5, 700, 700, 800, 800);
@ -101,7 +101,7 @@ void testCapi()
{.offset=1, .r=0, .g=255, .b=255, .a=255},
};
tvg_gradient_color_stops(grad5, color_stops5, 2);
tvg_shape_linear_gradient_set(shape4, grad5);
tvg_shape_set_linear_gradient(shape4, grad5);
tvg_canvas_push(canvas, shape4);
Tvg_Gradient* grad6 = tvg_radial_gradient_new();
@ -112,13 +112,28 @@ void testCapi()
{.offset=1, .r=125, .g=0, .b=125, .a=255},
};
tvg_gradient_color_stops(grad6, color_stops6, 2);
tvg_shape_radial_gradient_set(shape1, grad6);
tvg_shape_set_radial_gradient(shape1, grad6);
tvg_canvas_update(canvas);
tvg_shape_set_stroke_width(shape,3);
tvg_shape_set_stroke_color(shape, 125, 0, 125, 255);
tvg_canvas_update_paint(canvas, shape);
const Tvg_Path_Command* cmds;
uint32_t cmdCnt;
const Tvg_Point* pts;
uint32_t ptsCnt;
tvg_shape_get_path_commands(shape, &cmds, &cmdCnt);
printf("---- First Shape Commands(%u) ----\n", cmdCnt);
for(int i=0; i<cmdCnt; ++i)
printf("%d\n", cmds[i]);
tvg_shape_get_path_coords(shape, &pts, &ptsCnt);
printf("---- First Shape Points(%u) ----\n", ptsCnt);
for(int i=0; i<ptsCnt; ++i)
printf("(%.2lf, %.2lf)\n", pts[i].x, pts[i].y);
tvg_canvas_draw(canvas);
tvg_canvas_sync(canvas);