mirror of
https://github.com/thorvg/thorvg.git
synced 2025-07-25 07:39:02 +00:00
capi: correct interfaces.
put missing const parameter and correct set/get naming. attention, these two apis are changed! tvg_gradient_color_stops() => tvg_gradient_set_color_stops() tvg_gradient_spread() = tvg_gradient_set_spread()
This commit is contained in:
parent
7d08f202a8
commit
7a27ca3613
3 changed files with 45 additions and 41 deletions
|
@ -138,31 +138,31 @@ TVG_EXPORT Tvg_Result tvg_shape_append_path(Tvg_Paint* paint, const Tvg_Path_Com
|
|||
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_get_stroke_width(const 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);
|
||||
TVG_EXPORT Tvg_Result tvg_shape_get_stroke_color(Tvg_Paint* paint, uint8_t* r, uint8_t* g, uint8_t* b, uint8_t* a);
|
||||
TVG_EXPORT Tvg_Result tvg_shape_get_stroke_color(const Tvg_Paint* paint, uint8_t* r, uint8_t* g, uint8_t* b, uint8_t* a);
|
||||
TVG_EXPORT Tvg_Result tvg_shape_set_stroke_dash(Tvg_Paint* paint, const float* dashPattern, uint32_t cnt);
|
||||
TVG_EXPORT Tvg_Result tvg_shape_get_stroke_dash(Tvg_Paint* paint, const float** dashPattern, uint32_t* cnt);
|
||||
TVG_EXPORT Tvg_Result tvg_shape_get_stroke_dash(const Tvg_Paint* paint, const float** dashPattern, uint32_t* cnt);
|
||||
TVG_EXPORT Tvg_Result tvg_shape_set_stroke_cap(Tvg_Paint* paint, Tvg_Stroke_Cap cap);
|
||||
TVG_EXPORT Tvg_Result tvg_shape_get_stroke_cap(Tvg_Paint* paint, Tvg_Stroke_Cap* cap);
|
||||
TVG_EXPORT Tvg_Result tvg_shape_get_stroke_cap(const Tvg_Paint* paint, Tvg_Stroke_Cap* cap);
|
||||
TVG_EXPORT Tvg_Result tvg_shape_set_stroke_join(Tvg_Paint* paint, Tvg_Stroke_Join join);
|
||||
TVG_EXPORT Tvg_Result tvg_shape_get_stroke_join(Tvg_Paint* paint, Tvg_Stroke_Join* join);
|
||||
TVG_EXPORT Tvg_Result tvg_shape_get_stroke_join(const Tvg_Paint* paint, Tvg_Stroke_Join* join);
|
||||
TVG_EXPORT Tvg_Result tvg_shape_set_fill_color(Tvg_Paint* paint, uint8_t r, uint8_t g, uint8_t b, uint8_t a);
|
||||
TVG_EXPORT Tvg_Result tvg_shape_get_fill_color(Tvg_Paint* paint, uint8_t* r, uint8_t* g, uint8_t* b, uint8_t* a);
|
||||
TVG_EXPORT Tvg_Result tvg_shape_get_fill_color(const Tvg_Paint* paint, uint8_t* r, uint8_t* g, uint8_t* b, uint8_t* a);
|
||||
TVG_EXPORT Tvg_Result tvg_shape_set_linear_gradient(Tvg_Paint* paint, Tvg_Gradient* grad);
|
||||
TVG_EXPORT Tvg_Result tvg_shape_set_radial_gradient(Tvg_Paint* paint, Tvg_Gradient* grad);
|
||||
TVG_EXPORT Tvg_Result tvg_shape_get_gradient(Tvg_Paint* paint, Tvg_Gradient** grad);
|
||||
TVG_EXPORT Tvg_Result tvg_shape_get_gradient(const 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);
|
||||
TVG_EXPORT Tvg_Result tvg_gradient_spread(Tvg_Gradient* grad, const Tvg_Stroke_Fill);
|
||||
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_del(Tvg_Gradient* grad);
|
||||
|
||||
|
||||
/************************************************************************/
|
||||
|
@ -170,7 +170,7 @@ TVG_EXPORT Tvg_Result tvg_gradient_spread(Tvg_Gradient* grad, const Tvg_Stroke_F
|
|||
/************************************************************************/
|
||||
TVG_EXPORT Tvg_Paint* tvg_picture_new();
|
||||
TVG_EXPORT Tvg_Result tvg_picture_load(Tvg_Paint* paint, const char* path);
|
||||
TVG_EXPORT Tvg_Result tvg_picture_get_viewbox(Tvg_Paint* paint, float* x, float* y, float* w, float* h);
|
||||
TVG_EXPORT Tvg_Result tvg_picture_get_viewbox(const Tvg_Paint* paint, float* x, float* y, float* w, float* h);
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
|
|
|
@ -26,6 +26,8 @@
|
|||
using namespace std;
|
||||
using namespace tvg;
|
||||
|
||||
#define CCP(A) const_cast<Tvg_Paint*>(A) //Const-Cast-Paint
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
|
@ -279,10 +281,10 @@ 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_get_stroke_width(const Tvg_Paint* paint, float* width)
|
||||
{
|
||||
if (!paint || !width) return TVG_RESULT_INVALID_ARGUMENT;
|
||||
*width = reinterpret_cast<Shape*>(paint)->strokeWidth();
|
||||
*width = reinterpret_cast<Shape*>(CCP(paint))->strokeWidth();
|
||||
return TVG_RESULT_SUCCESS;
|
||||
}
|
||||
|
||||
|
@ -294,10 +296,10 @@ TVG_EXPORT Tvg_Result tvg_shape_set_stroke_color(Tvg_Paint* paint, uint8_t r, ui
|
|||
}
|
||||
|
||||
|
||||
TVG_EXPORT Tvg_Result tvg_shape_get_stroke_color(Tvg_Paint* paint, uint8_t* r, uint8_t* g, uint8_t* b, uint8_t* a)
|
||||
TVG_EXPORT Tvg_Result tvg_shape_get_stroke_color(const Tvg_Paint* paint, uint8_t* r, uint8_t* g, uint8_t* b, uint8_t* a)
|
||||
{
|
||||
if (!paint) return TVG_RESULT_INVALID_ARGUMENT;
|
||||
return (Tvg_Result) reinterpret_cast<Shape*>(paint)->strokeColor(r, g, b, a);
|
||||
return (Tvg_Result) reinterpret_cast<Shape*>(CCP(paint))->strokeColor(r, g, b, a);
|
||||
}
|
||||
|
||||
|
||||
|
@ -308,10 +310,10 @@ TVG_EXPORT Tvg_Result tvg_shape_set_stroke_dash(Tvg_Paint* paint, const float* d
|
|||
}
|
||||
|
||||
|
||||
TVG_EXPORT Tvg_Result tvg_shape_get_stroke_dash(Tvg_Paint* paint, const float** dashPattern, uint32_t* cnt)
|
||||
TVG_EXPORT Tvg_Result tvg_shape_get_stroke_dash(const Tvg_Paint* paint, const float** dashPattern, uint32_t* cnt)
|
||||
{
|
||||
if (!paint || !cnt || !dashPattern) return TVG_RESULT_INVALID_ARGUMENT;
|
||||
*cnt = reinterpret_cast<Shape*>(paint)->strokeDash(dashPattern);
|
||||
*cnt = reinterpret_cast<Shape*>(CCP(paint))->strokeDash(dashPattern);
|
||||
return TVG_RESULT_SUCCESS;
|
||||
}
|
||||
|
||||
|
@ -323,10 +325,10 @@ TVG_EXPORT Tvg_Result tvg_shape_set_stroke_cap(Tvg_Paint* paint, Tvg_Stroke_Cap
|
|||
}
|
||||
|
||||
|
||||
TVG_EXPORT Tvg_Result tvg_shape_get_stroke_cap(Tvg_Paint* paint, Tvg_Stroke_Cap* cap)
|
||||
TVG_EXPORT Tvg_Result tvg_shape_get_stroke_cap(const Tvg_Paint* paint, Tvg_Stroke_Cap* cap)
|
||||
{
|
||||
if (!paint || !cap) return TVG_RESULT_INVALID_ARGUMENT;
|
||||
*cap = (Tvg_Stroke_Cap) reinterpret_cast<Shape*>(paint)->strokeCap();
|
||||
*cap = (Tvg_Stroke_Cap) reinterpret_cast<Shape*>(CCP(paint))->strokeCap();
|
||||
return TVG_RESULT_SUCCESS;
|
||||
}
|
||||
|
||||
|
@ -337,10 +339,10 @@ TVG_EXPORT Tvg_Result tvg_shape_set_stroke_join(Tvg_Paint* paint, Tvg_Stroke_Joi
|
|||
}
|
||||
|
||||
|
||||
TVG_EXPORT Tvg_Result tvg_shape_get_stroke_join(Tvg_Paint* paint, Tvg_Stroke_Join* join)
|
||||
TVG_EXPORT Tvg_Result tvg_shape_get_stroke_join(const Tvg_Paint* paint, Tvg_Stroke_Join* join)
|
||||
{
|
||||
if (!paint || !join) return TVG_RESULT_INVALID_ARGUMENT;
|
||||
*join = (Tvg_Stroke_Join) reinterpret_cast<Shape*>(paint)->strokeJoin();
|
||||
*join = (Tvg_Stroke_Join) reinterpret_cast<Shape*>(CCP(paint))->strokeJoin();
|
||||
return TVG_RESULT_SUCCESS;
|
||||
}
|
||||
|
||||
|
@ -352,10 +354,10 @@ TVG_EXPORT Tvg_Result tvg_shape_set_fill_color(Tvg_Paint* paint, uint8_t r, uint
|
|||
}
|
||||
|
||||
|
||||
TVG_EXPORT Tvg_Result tvg_shape_get_fill_color(Tvg_Paint* paint, uint8_t* r, uint8_t* g, uint8_t* b, uint8_t* a)
|
||||
TVG_EXPORT Tvg_Result tvg_shape_get_fill_color(const Tvg_Paint* paint, uint8_t* r, uint8_t* g, uint8_t* b, uint8_t* a)
|
||||
{
|
||||
if (!paint) return TVG_RESULT_INVALID_ARGUMENT;
|
||||
return (Tvg_Result) reinterpret_cast<Shape*>(paint)->fill(r, g, b, a);
|
||||
return (Tvg_Result) reinterpret_cast<Shape*>(CCP(paint))->fill(r, g, b, a);
|
||||
}
|
||||
|
||||
|
||||
|
@ -373,10 +375,10 @@ TVG_EXPORT Tvg_Result tvg_shape_set_radial_gradient(Tvg_Paint* paint, Tvg_Gradie
|
|||
}
|
||||
|
||||
|
||||
TVG_EXPORT Tvg_Result tvg_shape_get_gradient(Tvg_Paint* paint, Tvg_Gradient** gradient)
|
||||
TVG_EXPORT Tvg_Result tvg_shape_get_gradient(const Tvg_Paint* paint, Tvg_Gradient** gradient)
|
||||
{
|
||||
if (!paint || !gradient) return TVG_RESULT_INVALID_ARGUMENT;
|
||||
*gradient = (Tvg_Gradient*)(reinterpret_cast<Shape*>(paint)->fill());
|
||||
*gradient = (Tvg_Gradient*)(reinterpret_cast<Shape*>(CCP(paint))->fill());
|
||||
return TVG_RESULT_SUCCESS;
|
||||
}
|
||||
|
||||
|
@ -398,10 +400,10 @@ TVG_EXPORT Tvg_Result tvg_picture_load(Tvg_Paint* paint, const char* path)
|
|||
}
|
||||
|
||||
|
||||
TVG_EXPORT Tvg_Result tvg_picture_get_viewbox(Tvg_Paint* paint, float* x, float* y, float* w, float* h)
|
||||
TVG_EXPORT Tvg_Result tvg_picture_get_viewbox(const Tvg_Paint* paint, float* x, float* y, float* w, float* h)
|
||||
{
|
||||
if (!paint) return TVG_RESULT_INVALID_ARGUMENT;
|
||||
return (Tvg_Result) reinterpret_cast<Picture*>(paint)->viewbox(x, y, w, h);
|
||||
return (Tvg_Result) reinterpret_cast<Picture*>(CCP(paint))->viewbox(x, y, w, h);
|
||||
}
|
||||
|
||||
|
||||
|
@ -438,13 +440,13 @@ TVG_EXPORT Tvg_Result tvg_radial_gradient_set(Tvg_Gradient* grad, float cx, floa
|
|||
return (Tvg_Result) reinterpret_cast<RadialGradient*>(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)
|
||||
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_spread(Tvg_Gradient* grad, const Tvg_Stroke_Fill spread)
|
||||
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);
|
||||
|
|
|
@ -53,7 +53,7 @@ void testCapi()
|
|||
{.offset=1, .r=255, .g=0, .b=0, .a=255},
|
||||
};
|
||||
|
||||
tvg_gradient_spread(grad2, TVG_STROKE_FILL_REPEAT);
|
||||
tvg_gradient_set_spread(grad2, TVG_STROKE_FILL_REPEAT);
|
||||
|
||||
Tvg_Paint* shape3 = tvg_shape_new();
|
||||
tvg_shape_append_rect(shape3, 0, 400, 400, 800, 20, 20);
|
||||
|
@ -65,12 +65,12 @@ void testCapi()
|
|||
{.offset=1, .r=0, .g=255, .b=0, .a=255},
|
||||
};
|
||||
|
||||
tvg_gradient_spread(grad3, TVG_STROKE_FILL_REFLECT);
|
||||
tvg_gradient_set_spread(grad3, TVG_STROKE_FILL_REFLECT);
|
||||
|
||||
tvg_gradient_color_stops(grad, color_stops, 4);
|
||||
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_gradient_set_color_stops(grad, color_stops, 4);
|
||||
tvg_gradient_set_color_stops(grad1, color_stops1, 3);
|
||||
tvg_gradient_set_color_stops(grad2, color_stops2, 2);
|
||||
tvg_gradient_set_color_stops(grad3, color_stops3, 2);
|
||||
tvg_shape_set_linear_gradient(shape, grad);
|
||||
tvg_shape_set_radial_gradient(shape1, grad1);
|
||||
tvg_shape_set_linear_gradient(shape2, grad2);
|
||||
|
@ -90,7 +90,7 @@ void testCapi()
|
|||
{.offset=0.0, .r=0, .g=0, .b=0, .a=255},
|
||||
{.offset=1, .r=0, .g=255, .b=0, .a=255},
|
||||
};
|
||||
tvg_gradient_color_stops(grad4, color_stops4, 2);
|
||||
tvg_gradient_set_color_stops(grad4, color_stops4, 2);
|
||||
tvg_shape_set_linear_gradient(shape4, grad4);
|
||||
|
||||
Tvg_Gradient* grad5 = tvg_linear_gradient_new();
|
||||
|
@ -100,7 +100,7 @@ void testCapi()
|
|||
{.offset=0.0, .r=0, .g=0, .b=255, .a=255},
|
||||
{.offset=1, .r=0, .g=255, .b=255, .a=255},
|
||||
};
|
||||
tvg_gradient_color_stops(grad5, color_stops5, 2);
|
||||
tvg_gradient_set_color_stops(grad5, color_stops5, 2);
|
||||
tvg_shape_set_linear_gradient(shape4, grad5);
|
||||
tvg_canvas_push(canvas, shape4);
|
||||
|
||||
|
@ -111,7 +111,7 @@ void testCapi()
|
|||
{.offset=0.0, .r=0, .g=125, .b=0, .a=255},
|
||||
{.offset=1, .r=125, .g=0, .b=125, .a=255},
|
||||
};
|
||||
tvg_gradient_color_stops(grad6, color_stops6, 2);
|
||||
tvg_gradient_set_color_stops(grad6, color_stops6, 2);
|
||||
tvg_shape_set_radial_gradient(shape1, grad6);
|
||||
tvg_canvas_update(canvas);
|
||||
|
||||
|
@ -126,14 +126,16 @@ void testCapi()
|
|||
|
||||
tvg_shape_get_path_commands(shape, &cmds, &cmdCnt);
|
||||
printf("---- First Shape Commands(%u) ----\n", cmdCnt);
|
||||
for(int i=0; i<cmdCnt; ++i)
|
||||
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)
|
||||
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);
|
||||
|
||||
|
|
Loading…
Add table
Reference in a new issue