capi: Added doxygen comments and doxygen config file.
[platform/core/graphics/tizenvg.git] / inc / thorvg_capi.h
1 /*!
2 * \file thorvg_capi.h
3 * \brief Function provides C bindings for thorvg library.
4 * Please refer to src/examples/Capi.cpp to find thorvg_capi examples.
5 *
6 * thorvg_capi module provides a set of functionality that allows to
7 * implement thorvg C client with following funcionalities
8 * - Drawing primitive paints: Line, Arc, Curve, Path, Shapes, Polygons
9 * - Filling: Solid, Linear, Radial Gradient
10 * - Scene Graph & Affine Transformation (translation, rotation, scale ...)
11 * - Stroking: Width, Join, Cap, Dash
12 * - Composition: Blending, Masking, Path Clipping, etc
13 * - Pictures: SVG, Bitmap
14 */
15
16 #ifndef __THORVG_CAPI_H__
17 #define __THORVG_CAPI_H__
18
19 /*! Importation of librairies*/
20 #include <stdbool.h>
21
22 #ifdef TVG_EXPORT
23     #undef TVG_EXPORT
24 #endif
25
26 #ifdef TVG_BUILD
27     #define TVG_EXPORT __attribute__ ((visibility ("default")))
28 #else
29     #define TVG_EXPORT
30 #endif
31
32
33 #ifdef __cplusplus
34 extern "C" {
35 #endif
36
37 typedef struct _Tvg_Canvas Tvg_Canvas;
38 typedef struct _Tvg_Paint Tvg_Paint;
39 typedef struct _Tvg_Gradient Tvg_Gradient;
40
41 /*!
42 * \def TVG_ENGINE_SW
43 * Software raster engine type.
44 */
45 #define TVG_ENGINE_SW (1 << 1)
46 /*!
47 * \def TVG_ENGINE_GL
48 * GL raster engine type.
49 */
50 #define TVG_ENGINE_GL (1 << 2)
51
52 /*!
53 * \def TVG_COLORSPACE_ABGR8888
54 * Colorspace used to fill buffer.
55 */
56 #define TVG_COLORSPACE_ABGR8888 0
57 /*!
58 * \def TVG_COLORSPACE_ARGB8888
59 * Colorspace used to fill buffer.
60 */
61 #define TVG_COLORSPACE_ARGB8888 1
62
63 typedef enum {
64     TVG_RESULT_SUCCESS = 0,
65     TVG_RESULT_INVALID_ARGUMENT,
66     TVG_RESULT_INSUFFICIENT_CONDITION,
67     TVG_RESULT_FAILED_ALLOCATION,
68     TVG_RESULT_MEMORY_CORRUPTION,
69     TVG_RESULT_NOT_SUPPORTED,
70     TVG_RESULT_UNKNOWN
71 } Tvg_Result;
72
73
74 typedef enum {
75     TVG_PATH_COMMAND_CLOSE = 0,
76     TVG_PATH_COMMAND_MOVE_TO,
77     TVG_PATH_COMMAND_LINE_TO,
78     TVG_PATH_COMMAND_CUBIC_TO
79 } Tvg_Path_Command;
80
81
82 typedef enum {
83     TVG_STROKE_CAP_SQUARE = 0,
84     TVG_STROKE_CAP_ROUND,
85     TVG_STROKE_CAP_BUTT
86 } Tvg_Stroke_Cap;
87
88
89 typedef enum {
90     TVG_STROKE_JOIN_BEVEL = 0,
91     TVG_STROKE_JOIN_ROUND,
92     TVG_STROKE_JOIN_MITER
93 } Tvg_Stroke_Join;
94
95
96 typedef enum {
97     TVG_STROKE_FILL_PAD = 0,
98     TVG_STROKE_FILL_REFLECT,
99     TVG_STROKE_FILL_REPEAT
100 } Tvg_Stroke_Fill;
101
102
103 typedef enum {
104     TVG_FILL_RULE_WINDING = 0,
105     TVG_FILL_RULE_EVEN_ODD
106 } Tvg_Fill_Rule;
107
108 typedef struct
109 {
110     float x, y;
111 } Tvg_Point;
112
113
114 typedef struct
115 {
116     float e11, e12, e13;
117     float e21, e22, e23;
118     float e31, e32, e33;
119 } Tvg_Matrix;
120
121
122 typedef struct
123 {
124     float offset;
125     uint8_t r, g, b, a;
126 } Tvg_Color_Stop;
127
128
129 /************************************************************************/
130 /* Engine API                                                           */
131 /************************************************************************/
132 /*!
133 * \fn Tvg_Result tvg_engine_init(unsigned engine_method, unsigned threads)
134 * \brief The funciton initialises thorvg library. It must be called before the
135 * other functions at the beggining of thorvg client.
136 * \code
137 * tvg_engine_init(TVG_ENGINE_SW, 0); //Initialize software renderer and use 1 thread
138 * \endcode
139 * \param[in] engine_method renderer type
140 *   - TVG_ENGINE_SW: software renderer
141 *   - TVG_ENGINE_GL: opengl renderer (not supported yet)
142 * \param[in] threads number of threads used to perform rendering. If threads = 0, only one
143 * thread will be used for renderer
144 * \return Tvg_Result return values:
145 *   - TVG_RESULT_SUCCESS: if ok.
146 *   - TVG_RESULT_INSUFFICENT_CONDITION: multiple init calls.
147 *   - TVG_RESULT_INVALID_ARGUMENT: not known engine_method.
148 *   - TVG_RESULT_NOT_SUPPORTED: not supported engine_method.
149 *   - TVG_RESULT_UNKOWN: internal error.
150 */
151 TVG_EXPORT Tvg_Result tvg_engine_init(unsigned engine_method, unsigned threads);
152
153
154 /*!
155 * \fn TVG_EXPORT Tvg_Result tvg_engine_term(unsigned engine_method)
156 * \brief The funciton termiates renderer tasks. Used for cleanup.
157 * It should be called in case of termination of the thorvg library with same
158 * renderer types as it was passed in tvg_engine_init()
159 * \code
160 * tvg_engine_init(TVG_ENGINE_SW, 0);
161 * //define canvas and shapes, update shapes, general rendering calls
162 * tvg_engine_term(TVG_ENGINE_SW);
163 * \endcode
164 * \param engine_method renderer type
165 *   - TVG_ENGINE_SW: software renderer
166 *   - TVG_ENGINE_GL: opengl renderer (not supported yet)
167 * \return Tvg_Result return values:
168 *   - TVG_RESULT_SUCCESS: if ok.
169 *   - TVG_RESULT_INSUFFICENT_CONDITION: multiple terminate calls.
170 *   - TVG_RESULT_INVALID_ARGUMENT: not known engine_method.
171 *   - TVG_RESULT_NOT_SUPPORTED: not supported engine_method.
172 *   - TVG_RESULT_UNKOWN: internal error.
173 */
174 TVG_EXPORT Tvg_Result tvg_engine_term(unsigned engine_method);
175
176
177 /************************************************************************/
178 /* SwCanvas API                                                         */
179 /************************************************************************/
180 /*!
181 * \fn TVG_EXPORT Tvg_Canvas* tvg_swcanvas_create()
182 * \brief The function creates a canvas, i.e. an object used for drawing shapes,
183 * scenes (Tvg_Paint objects)
184 * \code
185 * Tvg_Canvas *canvas = NULL;
186 *
187 * tvg_engine_init(TVG_ENGINE_SW, 4);
188 * canvas = tvg_swcavnas_create();
189 *
190 * //setup canvas buffer
191 * uint32_t *buffer = NULL;
192 * buffer = (uint32_t*) malloc(sizeof(uint32_t) * 100 * 100);
193 * if (!buffer) return;
194 *
195 * tvg_swcanvas_set_target(canvas, buffer, 100, 100, 100, TVG_COLORSPACE_ARGB8888);
196 *
197 * //add paints to canvas and setup them before draw calls
198 *
199 * tvg_canvas_destroy(canvas);
200 * tvg_engine_term(TVG_ENGINE_SW);
201 * \endcode
202 * \return Tvg_Canvas pointer to the canvas object, or NULL if something went wrong
203 */
204
205
206 TVG_EXPORT Tvg_Canvas* tvg_swcanvas_create();
207 /*!
208 * \fn TVG_EXPORT Tvg_Result tvg_swcanvas_set_target(Tvg_Canvas* canvas, uint32_t* buffer, uint32_t stride, uint32_t w, uint32_t h, uint32_t cs)
209 * \brief The function sets memory buffer used by renderer and define colorspace used for renderering. For optimisation reasons, the library
210 * does not allocate memory for the output buffer on its own. Buffer is used to integrate thorvg with external libraries. Please refer to examples/Capi.cpp
211 * where thorvg is integrated with the EFL lib.
212 * \param[in] canvas The pointer to Tvg_Canvas object.
213 * \param[in] buffer The uint32_t pointer to allocated memory.
214 * \param[in] stride The buffer stride - in most cases width.
215 * \param[in] w The buffer width
216 * \param[in] h The buffer height
217 * \param[in] cs The buffer colorspace, defines position of color in raw pixel data.
218 * - TVG_COLORSPACE_ABGR8888
219 * - TVG_COLORSPACE_ARGB8888
220 * \return Tvg_Result return values:
221 * - TVG_RESULT_SUCCESS: if ok.
222 * - TVG_RESULT_MEMORY_CORRUPTION: A canvas is not valid.
223 * - TVG_RESULT_INVALID_ARGUMENTS: invalid buffer, stride = 0, w or h = 0
224 */
225 TVG_EXPORT Tvg_Result tvg_swcanvas_set_target(Tvg_Canvas* canvas, uint32_t* buffer, uint32_t stride, uint32_t w, uint32_t h, uint32_t cs);
226
227
228 /************************************************************************/
229 /* Common Canvas API                                                    */
230 /************************************************************************/
231 /*!
232 * \fn TVG_EXPORT Tvg_Result tvg_canvas_destroy(Tvg_Canvas* canvas)
233 * \brief The function clears canvas internal data (e.g all paints stored by canvas)
234 * and destroy canvas object. There is no need to call tvg_paint_del API manually for
235 * each paint. This function releases stored paints data. If there is a need to destroy
236 * paint manually in thorvg client runtime tvg_canvas_clear(canvas, false) API should be
237 * called, but in that case all shapes should be deleted by thorvg client.
238 * \code
239 * static Tvg_Canvas *canvas = NULL;
240 * static uint32_t *buffer = NULL;
241 *
242 * static void _init() {
243 *   canvas = tvg_swcavnas_create();
244 *   buffer = (uint32_t*) malloc(sizeof(uint32_t) * 100 * 100);
245 *   tvg_swcanvas_set_target(canvas, buffer, 100, 100, 100, TVG_COLORSPACE_ARGB8888);
246 * }
247 *
248 * //a task called from main function in a loop
249 * static void _job(const int cmd) {
250 *   switch (cmd) {
251 *     case CMD_EXIT: return 0;
252 *     case CMD_ADD_RECT:
253 *       //define valid rectangle shape
254 *       tvg_canvas_push(canvas, rect);
255 *       break;
256 *     case CMD_DEL_RECT:
257 *       tvg_shape_del(rect);
258 *       //now to safely delete Tvg_Canvas, tvg_canvas_clear() API have to be used.
259 *       break;
260 *     default:
261 *       break;
262 *   }
263 * }
264 *
265 * int main(int argc, char **argv) {
266 *   int cmd = 0;
267 *   int stop = 1;
268 *
269 *   tvg_engine_init(TVG_ENGINE_SW, 4);
270 *
271 *   while (stop) {
272 *      //wait for command e.g. from console
273 *      stop = _job(cmd);
274 *   }
275 *   tvg_canvas_clear(canvas, false);
276 *   tvg_canvas_destroy(canvas);
277 *   tvg_engine_term(TVG_ENGINE_SW);
278 *   return 0;
279 * }
280 *
281 *
282 * tvg_canvas_destroy(canvas);
283 * tvg_engine_term()
284 * \endcode
285 * \param[in] canvas Tvg_Canvas pointer
286 * \return Tvg_Result return values:
287 * - TVG_RESULT_SUCCESS: if ok.
288 * - TVG_RESULT_INVALID_ARGUMENT: if canvas is a NULL pointer.
289 */
290 TVG_EXPORT Tvg_Result tvg_canvas_destroy(Tvg_Canvas* canvas);
291
292
293 /*!
294 * \fn TVG_EXPORT Tvg_Result tvg_canvas_push(Tvg_Canvas* canvas, Tvg_Paint* paint)
295 * \brief The function inserts paint object in the canvas.
296 * \param[in] canvas Tvg_Canvas pointer
297 * \param[in] paint Tvg_Paint pointer
298 * \return Tvg_Result return values:
299 * - TVG_RESULT_SUCCESS: if ok.
300 * - TVG_RESULT_INVALID_PARAMETERS: if canvas or if paint are NULL pointers.
301 * - TVG_RESULT_MEMORY_CORRUPTION: if paint is not a valid Tvg_Paint object.
302 */
303 TVG_EXPORT Tvg_Result tvg_canvas_push(Tvg_Canvas* canvas, Tvg_Paint* paint);
304
305
306 /*!
307 * \fn TVG_EXPORT Tvg_Result tvg_canvas_reserve(Tvg_Canvas* canvas, uint32_t n)
308 * \brief The function reserves a memory for objects. It might be used to reduce
309 * reallocations in any cases when number of Tvg_Paints stored in canvas is known
310 * or it can be estimated.
311 * \code
312 * Tvg_Canvas *canvas = NULL;
313 *
314 * tvg_engine_init(TVG_ENGINE_SW, 4);
315 * canvas = tvg_swcavnas_create();
316 *
317 * uint32_t *buffer = NULL;
318 * buffer = (uint32_t*) malloc(sizeof(uint32_t) * 100 * 100);
319 * if (!buffer) return;
320 *
321 * tvg_swcanvas_set_target(canvas, buffer, 100, 100, 100, TVG_COLORSPACE_ARGB8888);
322 * tvg_canvas_reserve(canvas, 100); //reserve array for 100 paints in canvas.
323 *
324 * tvg_canvas_destroy(canvas);
325 * tvg_engine_term()
326 * \endcode
327 * \param[in] canvas Tvg_Canvas pointer.
328 * \param[in] n uint32_t reserved space.
329 * \return Tvg_Result return values:
330 * - TVG_RESULT_SUCCESS: if ok.
331 * - TVG_RESULT_INVALID_PARAMETERS: if canvas is invalid.
332 */
333 TVG_EXPORT Tvg_Result tvg_canvas_reserve(Tvg_Canvas* canvas, uint32_t n);
334
335
336 /*!
337 * \fn TVG_EXPORT Tvg_Result tvg_canvas_clear(Tvg_Canvas* canvas, bool free)
338 * \brief The function clears a Tvg_Canvas from pushed paints. If free is set to true,
339 * Tvg_Paints stored in canvas also will be released. If free is set to false,
340 * all paints should be released manually to avoid memory leaks.
341 * \param canvas Tvg_Canvas pointer.
342 * \param free boolean, if equals true, function release all paints stored in given canvas.
343 * \return
344 * - TVG_RESULT_SUCCESS: if ok.
345 * - TVG_RESULT_INVALID_PARAMETERS: if canvas is invalid
346 */
347 TVG_EXPORT Tvg_Result tvg_canvas_clear(Tvg_Canvas* canvas, bool free);
348
349
350 /*!
351 * \fn TVG_EXPORT Tvg_Result tvg_canvas_update(Tvg_Canvas* canvas)
352 * \brief The function update all paints in given canvas. Should be called before draw to
353 * prepare shapes for rendering.
354 * \code
355 * //A frame drawing example. Thread safety and events implementation is skipped to show only thorvg code.
356 *
357 * static Tvg_Canvas *canvas = NULL;
358 * static Tvg_Paint *rect = NULL;
359 *
360 * int _frame_render(void) {
361 *   tvg_canvas_update(canvas);
362 *   tvg_canvas_draw(canvas);
363 *   tvg_canvas_sync(canvas);
364 * }
365 *
366 * //event handler from your code or third party library
367 * void _event_handler(event *event_data) {
368 *   if (!event_data) return NULL;
369 *     switch(event_data.type) {
370 *       case EVENT_RECT_ADD:
371 *         if (!rect) {
372 *           tvg_shape_append_rect(shape, 10, 10, 50, 50, 0, 0);
373 *           tvg_shape_set_stroke_width(shape, 1.0f);
374 *           tvg_shape_set_stroke_color(shape, 255, 0, 0, 255);
375 *           tvg_canvas_push(canvas, shape);
376 *         }
377 *         break;
378 *       case EVENT_RECT_MOVE:
379 *         if (rect) tvg_paint_translate(rect, 10.0, 10.0);
380 *           break;
381 *         default:
382 *           break;
383 *   }
384 * }
385 *
386 * int main(int argc, char **argv) {
387 *   //example handler from your code or third party lib
388 *   event_handler_add(handler, _event_handler);
389 *
390 *   //create frame rendering process which calls _frame_render() function.
391 *   app_loop_begin(_frame_render);
392 *   app_loop_finish();
393 *   cleanup();
394 * }
395 * \endcode
396 * \param[in] canvas Tvg_Canvas pointer
397 * \return Tvg_Result return value
398 * - TVG_RESULT_SUCCESS: if ok.
399 * - TVG_RESULT_INVALID_PARAMETERS: if canvas is invalid]
400 */
401 TVG_EXPORT Tvg_Result tvg_canvas_update(Tvg_Canvas* canvas);
402
403
404 /*!
405 * \fn TVG_EXPORT Tvg_Result tvg_canvas_update_paint(Tvg_Canvas* canvas, Tvg_Paint* paint)
406 * \brief The funciton updates shape before rendering. If a client application using the
407 * thorvg library does not update the entire canvas (tvg_canvas_update()) in the frame
408 * rendering process, Tvg_Paints previosly added to the canvas should be updated manually
409 * using this function.
410 * \param[in] canvas Tvg_Canvas pointer
411 * \param[in] paint Tvg_Paint pointer to update
412 * \return Tvg_Result return value
413 * - TVG_RESULT_SUCCESS: if ok.
414 * - TVG_RESULT_INVALID_PARAMETERS: if canvas is invalid
415 */
416 TVG_EXPORT Tvg_Result tvg_canvas_update_paint(Tvg_Canvas* canvas, Tvg_Paint* paint);
417
418
419 /*!
420 * \fn TVG_EXPORT Tvg_Result tvg_canvas_draw(Tvg_Canvas* canvas)
421 * \brief The function start rendering process. All shapes from the given canvas will be rasterized
422 * to the buffer.
423 * \param[in] canvas
424 * \return Tvg_Result return value
425 * - TVG_RESULT_SUCCESS: if ok.
426 * - TVG_RESULT_INSUFFICIENT_CONDITION: interna rendering errors.
427 * - TVG_RESULT_INVALID_PARAMETERS: if canvas is invalid.
428 */
429 TVG_EXPORT Tvg_Result tvg_canvas_draw(Tvg_Canvas* canvas);
430
431
432 /*!
433 * \fn TVG_EXPORT Tvg_Result tvg_canvas_sync(Tvg_Canvas* canvas)
434 * \brief The function finalize rendering process. It should be called after tvg_canvas_draw(canvas).
435 * \param[in] canvas
436 * \return Tvg_Result return value
437 * - TVG_RESULT_SUCCESS: if ok.
438 * - TVG_RESULT_INVALID_PARAMETERS: if canvas is invalids.
439 */
440 TVG_EXPORT Tvg_Result tvg_canvas_sync(Tvg_Canvas* canvas);
441
442 /************************************************************************/
443 /* Paint API                                                            */
444 /************************************************************************/
445 /*!
446 * \fn TVG_EXPORT Tvg_Result tvg_paint_del(Tvg_Paint* paint)
447 * \brief The function releases given paint object. The tvg_canvas_clear(canvas, true) or tvg_canvas_del(canvas)
448 * releases previously pushed paints internally. If this function is used, tvg_canvas_clear(canvas, false) should
449 * be used to avoid unexpected behaviours.
450 * \code
451 * //example of cleanup function
452 * Tvg_Paint *rect = NULL; //rectangle shape added in other function
453 *
454 * //rectangle delete API
455 * int rectangle_delete(void) {
456 *   if (rect) tvg_paint_del(rect);
457 *   rect = NULL;
458 * }
459 *
460 * int cleanup(void) {
461 *   tvg_canvas_clear(canvas, false);
462 *   tvg_canvas_del(canvas);
463 *   canvas = NULL;
464 * }
465 * \endcode
466 * \param[in] paint Tvg_Paint pointer
467 * \return Tvg_Result return value
468 * - TVG_RESULT_SUCCESS: if ok.
469 * - TVG_RESULT_INVALID_PARAMETERS: if paint is invalid
470 */
471 TVG_EXPORT Tvg_Result tvg_paint_del(Tvg_Paint* paint);
472
473
474 /*!
475 * \fn TVG_EXPORT Tvg_Result tvg_paint_scale(Tvg_Paint* paint, float factor)
476 * \brief The function scales given paint using given factor.
477 * \param[in] paint Tvg_Paint pointer
478 * \param[in] factor double scale factor
479 * \return Tvg_Result return value
480 * - TVG_RESULT_SUCCESS: if ok.
481 * - TVG_RESULT_INSUFFICENT_CONDITION: if invalid factor is used.
482 * - TVG_RESULT_INVALID_PARAMETERS: if paint is invalid
483 */
484 TVG_EXPORT Tvg_Result tvg_paint_scale(Tvg_Paint* paint, float factor);
485
486
487 /*!
488 * \fn TVG_EXPORT Tvg_Result tvg_paint_rotate(Tvg_Paint* paint, float degree)
489 * \brief The function rotates the givent paint by the given degree.
490 * \param[in] paint Tvg_Paint pointer
491 * \param[in] degree double rotation degree
492 * \return Tvg_Result return value
493 * - TVG_RESULT_SUCCESS: if ok.
494 * - TVG_RESULT_INSUFFICENT_CONDITION: if invalid degree is used.
495 * - TVG_RESULT_INVALID_PARAMETERS: if paint is invalid.
496 */
497 TVG_EXPORT Tvg_Result tvg_paint_rotate(Tvg_Paint* paint, float degree);
498
499
500 /*!
501 * \fn TVG_EXPORT Tvg_Result tvg_paint_translate(Tvg_Paint* paint, float x, float y)
502 * \brief The function moves the given paint in the X,Y coordinate system.
503 * \param[in] paint Tvg_Paint pointer
504 * \param[in] x float x shift
505 * \param[in] y float y shift
506 * \return Tvg_Result return value
507 * - TVG_RESULT_SUCCESS: if ok.
508 * - TVG_RESULT_INVALID_PARAMETERS: if paint is invalid
509 */
510 TVG_EXPORT Tvg_Result tvg_paint_translate(Tvg_Paint* paint, float x, float y);
511
512
513 /*!
514 * \fn TVG_EXPORT Tvg_Result tvg_paint_transform(Tvg_Paint* paint, const Tvg_Matrix* m)
515 * \brief The function transforms given paint using transformation matrix. It could
516 * be used to move, rotate in 2d coordinates system and rotate in 3d coordinates system
517 * \param[in] paint Tvg_Paint pointer
518 * \param[in] m Tvg_Matrix pointer
519 * \return Tvg_Result return value
520 * - TVG_RESULT_SUCCESS: if ok.
521 * - TVG_RESULT_INVALID_PARAMETERS: if paint or m is invalid
522 */
523 TVG_EXPORT Tvg_Result tvg_paint_transform(Tvg_Paint* paint, const Tvg_Matrix* m);
524
525
526 /*!
527 * \fn TVG_EXPORT Tvg_Result tvg_paint_set_opacity(Tvg_Paint* paint, uint8_t opacity)
528 * \brief The function sets opacity of paint. It could be used in Tvg_Scene to implement
529 * translucent layers of shapes.
530 * \param[in] paint Tvg_Paint pointer
531 * \param[in] opacity uint8_t opacity value
532 * \return Tvg_Result return value
533 * - TVG_RESULT_SUCCESS: if ok.
534 * - TVG_RESULT_INVALID_PARAMETERS: if paint is invalid
535 */
536 TVG_EXPORT Tvg_Result tvg_paint_set_opacity(Tvg_Paint* paint, uint8_t opacity);
537
538
539 /*!
540 * \fn TVG_EXPORT Tvg_Result tvg_paint_get_opacity(Tvg_Paint* paint, uint8_t* opacity)
541 * \brief The function gets opacity of given paint
542 * \param[in] paint Tvg_Paint pointer
543 * \param[out] opacity uint8_t pointer to store opacity
544 * \return Tvg_Result return value
545 * - TVG_RESULT_SUCCESS: if ok.
546 * - TVG_RESULT_INVALID_PARAMETERS: if canvas is invalid
547 */
548 TVG_EXPORT Tvg_Result tvg_paint_get_opacity(Tvg_Paint* paint, uint8_t* opacity);
549
550
551 /*!
552 * \fn TVG_EXPORT Tvg_Paint* tvg_paint_duplicate(Tvg_Paint* paint)
553 * \brief The function duplicates given paint. Returns newly allocated paint with the
554 * same properties (stroke, color, path). It could be used to duplicate scenes too.
555 * \param[in] paint Tvg_Paint pointer
556 * \return Tvg_Paint pointer to duplicatede paint
557 */
558 TVG_EXPORT Tvg_Paint* tvg_paint_duplicate(Tvg_Paint* paint);
559
560
561 /*!
562 * \fn TVG_EXPORT Tvg_Result tvg_paint_get_bounds(const Tvg_Paint* paint, float* x, float* y, float* w, float* h)
563 * \brief The function returns paint path bounds.
564 * \param[in] paint Tvg_Paint pointer
565 * \param[out] x float x position
566 * \param[out] y float y position
567 * \param[out] w float paint width
568 * \param[out] h float paint height
569 * \return Tvg_Result return value
570 * - TVG_RESULT_SUCCESS: if ok.
571 * - TVG_RESULT_INVALID_PARAMETERS: if paint is invalid
572 */
573 TVG_EXPORT Tvg_Result tvg_paint_get_bounds(const Tvg_Paint* paint, float* x, float* y, float* w, float* h);
574
575 /************************************************************************/
576 /* Shape API                                                            */
577 /************************************************************************/
578 /*!
579 * \fn TVG_EXPORT Tvg_Paint* tvg_shape_new()
580 * \brief The function creates a new shape
581 * \return Tvg_Paint pointer or NULL if something went wrong
582 */
583 TVG_EXPORT Tvg_Paint* tvg_shape_new();
584
585
586 /*!
587 * \fn TVG_EXPORT Tvg_Result tvg_shape_reset(Tvg_Paint* paint)
588 * \brief The function resets shape properties like path, stroke properties, fill color
589 * \param[in] paint Tvg_Paint pointer
590 * \return Tvg_Result return value
591 * - TVG_RESULT_SUCCESS: if ok.
592 * - TVG_RESULT_INVALID_PARAMETERS: if paint is invalid
593 */
594 TVG_EXPORT Tvg_Result tvg_shape_reset(Tvg_Paint* paint);
595
596
597 /*!
598 * \fn TVG_EXPORT Tvg_Result tvg_shape_move_to(Tvg_Paint* paint, float x, float y)
599 * \brief The funciton moves the current point to the given point.
600 * \param[in] paint Tvg_paint pointer
601 * \param[in] x move x coordinate
602 * \param[in] y move y coordinate
603 * \return Tvg_Result return value
604 * - TVG_RESULT_SUCCESS: if ok.
605 * - TVG_RESULT_INVALID_PARAMETERS: if paint is invalid
606 */
607 TVG_EXPORT Tvg_Result tvg_shape_move_to(Tvg_Paint* paint, float x, float y);
608
609
610 /*!
611 * \fn TVG_EXPORT Tvg_Result tvg_shape_line_to(Tvg_Paint* paint, float x, float y)
612 * \brief The funciton adds straight line from the current point to the given point.
613 * \param[in] paint Tvg_Paint pointer
614 * \param[in] x line end x position
615 * \param[in] y line end y position
616 * \return Tvg_Result return value
617 * - TVG_RESULT_SUCCESS: if ok.
618 * - TVG_RESULT_INVALID_PARAMETERS: if paint is invalid
619 */
620 TVG_EXPORT Tvg_Result tvg_shape_line_to(Tvg_Paint* paint, float x, float y);
621
622
623 /*!
624 * \fn TVG_EXPORT Tvg_Result tvg_shape_cubic_to(Tvg_Paint* paint, float cx1, float cy1, float cx2, float cy2, float x, float y)
625 * \brief The function adds a cubic Bezier curve between the current point and given end point (x, y) specified by control
626 points (cx1, cy1) and (cx2, cy2).
627 * \param[in] paint Tvg_Paint pointer
628 * \param[in] cx1 First control point x coordinate
629 * \param[in] cy1 First control point y coordinate
630 * \param[in] cx2 Second control point x coordinate
631 * \param[in] cy2 Second control point y coordinate
632 * \param[in] x Line end x coordinate
633 * \param[in] y Line end y coordinate
634 * \return Tvg_Result return value
635 * - TVG_RESULT_SUCCESS: if ok.
636 * - TVG_RESULT_INVALID_PARAMETERS: if paint is invalid
637 */
638 TVG_EXPORT Tvg_Result tvg_shape_cubic_to(Tvg_Paint* paint, float cx1, float cy1, float cx2, float cy2, float x, float y);
639
640
641 /*!
642 * \fn TVG_EXPORT Tvg_Result tvg_shape_close(Tvg_Paint* paint)
643 * \brief The function closes current path by drawing line to the start position of it.
644 * \param[in] paint
645 * \return Tvg_Result return value
646 * - TVG_RESULT_SUCCESS: if ok.
647 * - TVG_RESULT_INVALID_PARAMETERS: if paint is invalid
648 */
649 TVG_EXPORT Tvg_Result tvg_shape_close(Tvg_Paint* paint);
650 /*!
651 * \fn TVG_EXPORT Tvg_Result tvg_shape_append_rect(Tvg_Paint* paint, float x, float y, float w, float h, float rx, float ry)
652 * \brief The function appends rectangle in start position specified by x and y parameters, size spiecified by w and h parameters
653 * and rounded rectangles specified by rx, ry parameteres
654 * \param[in] paint Tvg_Paint pointer
655 * \param[in] x start x position
656 * \param[in] y start y position
657 * \param[in] w rectangle width
658 * \param[in] h rectangle height
659 * \param[in] rx rectangle corner x radius
660 * \param[in] ry rectangle corner y radius
661 * \return Tvg_Result return value
662 * - TVG_RESULT_SUCCESS: if ok.
663 * - TVG_RESULT_INVALID_PARAMETERS: if paint is invalid
664 */
665 TVG_EXPORT Tvg_Result tvg_shape_append_rect(Tvg_Paint* paint, float x, float y, float w, float h, float rx, float ry);
666
667
668 /*!
669 * \fn TVG_EXPORT Tvg_Result tvg_shape_append_circle(Tvg_Paint* paint, float cx, float cy, float rx, float ry)
670 * \brief The function appends circle with center in (cx, cy) point, x radius (rx) and y radius (ry)
671 * \param[in] paint Tvg_Paint pointer
672 * \param[in] cx circle x center
673 * \param[in] cy circle y center
674 * \param[in] rx circle x radius
675 * \param[in] ry circle y radius
676 * \return Tvg_Result return value
677 * - TVG_RESULT_SUCCESS: if ok.
678 * - TVG_RESULT_INVALID_PARAMETERS: if paint is invalid
679 */
680 TVG_EXPORT Tvg_Result tvg_shape_append_circle(Tvg_Paint* paint, float cx, float cy, float rx, float ry);
681
682
683 /*!
684 * \fn TVG_EXPORT Tvg_Result tvg_shape_append_arc(Tvg_Paint* paint, float cx, float cy, float radius, float startAngle, float sweep, uint8_t pie)
685 * \brief The function append an arc to the shape with center in (cx, cy) position. Arc radius is set by radius parameter. Start position of an
686 * arcus is defined by startAngle variable. Arcus lenght is set by sweep parameter. To draw closed arcus pie parameter should be set to true.
687 * \param[in] paint Tvg_Paint pointer
688 * \param[in] cx arcus x center
689 * \param[in] cy arcus y center
690 * \param[in] radius radius of an arc
691 * \param[in] startAngle start angle of an arc in degrees
692 * \param[in] sweep lenght of an arc in degrees
693 * \param[in] pie arcus close parameter
694 * \return Tvg_Result return value
695 * - TVG_RESULT_SUCCESS: if ok.
696 * - TVG_RESULT_INVALID_PARAMETERS: if paint is invalid
697 */
698 TVG_EXPORT Tvg_Result tvg_shape_append_arc(Tvg_Paint* paint, float cx, float cy, float radius, float startAngle, float sweep, uint8_t pie);
699
700
701 /*!
702 * \fn 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)
703 * \brief The function append path specified by path commands and path points
704 * \param[in] paint Tvg_Paint pointer
705 * \param[in] cmds array of path commands
706 * \param[in] cmdCnt lenght of commands array
707 * \param[in] pts array of command points
708 * \param[in] ptsCnt lenght of command points array
709 * \return Tvg_Result return value
710 * - TVG_RESULT_SUCCESS: if ok.
711 * - TVG_RESULT_INVALID_PARAMETERS: if paint is invalid
712 */
713 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);
714
715
716 /*!
717 * \fn TVG_EXPORT Tvg_Result tvg_shape_get_path_coords(const Tvg_Paint* paint, const Tvg_Point** pts, uint32_t* cnt)
718 * \brief The function get path coordinates to the Tvg_Point array. Array length is specified by cnt output parameter.
719 * The function does not allocate any data, it operates on internal memory. There is no need to free pts array.
720 * \code
721 * Tvg_Shape *shape = tvg_shape_new();
722 * Tvg_Point *coords = NULL;
723 * uint32_t len = 0;
724 *
725 * tvg_shape_append_circle(shape, 10, 10, 50, 50);
726 * tvg_shape_get_path_coords(shape, (const Tvg_Point**)&coords, &coords_len);
727 * //thorvg aproximates circle by four Bezier lines. In example above cmds array will store their coordinates
728 * \endcode
729 * \param[in] paint Tvg_Paint pointer
730 * \param[out] pts points output array
731 * \param[out] cnt points array length
732 * \return Tvg_Result return value
733 * - TVG_RESULT_SUCCESS: if ok.
734 * - TVG_RESULT_INVALID_PARAMETERS: if paint is invalid
735 */
736 TVG_EXPORT Tvg_Result tvg_shape_get_path_coords(const Tvg_Paint* paint, const Tvg_Point** pts, uint32_t* cnt);
737
738
739 /*!
740 * \fn TVG_EXPORT Tvg_Result tvg_shape_get_path_commands(const Tvg_Paint* paint, const Tvg_Path_Command** cmds, uint32_t* cnt)
741 * \brief The function gets path commands to commands array. Array length is specified by cnt output parameter.
742 * The function does not allocate any data. There is no need to cmds array.
743 * \code
744 * Tvg_Shape *shape = tvg_shape_new();
745 * Tvg_Point *coords = NULL;
746 * uint32_t len = 0;
747 *
748 * tvg_shape_append_circle(shape, 10, 10, 50, 50);
749 * tvg_shape_get_path_commands(shape, (const Tvg_Path_Command**)&cmds, &len);
750 * //thorvg aproximates circle by four Bezier lines. In example above cmds array will store their coordinates
751 * \endcode
752 * \param[in] paint Tvg_Paint pointer
753 * \param[out] cmds commands output array
754 * \param[out] cnt commands array length
755 * \return Tvg_Result return value
756 * - TVG_RESULT_SUCCESS: if ok.
757 * - TVG_RESULT_INVALID_PARAMETERS: if paint is invalid
758 */
759 TVG_EXPORT Tvg_Result tvg_shape_get_path_commands(const Tvg_Paint* paint, const Tvg_Path_Command** cmds, uint32_t* cnt);
760
761
762 /*!
763 * \fn TVG_EXPORT Tvg_Result tvg_shape_set_stroke_width(Tvg_Paint* paint, float width)
764 * \brief The function sets shape's stroke width.
765 * \param[in] paint Tvg_Paint pointer
766 * \param[in] width stroke width parameter
767 * \return Tvg_Result return value
768 * - TVG_RESULT_SUCCESS: if ok.
769 * - TVG_RESULT_INVALID_PARAMETERS: if paint is invalid
770 */
771 TVG_EXPORT Tvg_Result tvg_shape_set_stroke_width(Tvg_Paint* paint, float width);
772
773
774 /*!
775 * \fn TVG_EXPORT Tvg_Result tvg_shape_get_stroke_width(const Tvg_Paint* paint, float* width)
776 * \brief The function gets shape's stroke width
777 * \param[in] paint Tvg_Paint pointer
778 * \param[out] width stroke width
779 * \return Tvg_Result return value
780 * - TVG_RESULT_SUCCESS: if ok.
781 * - TVG_RESULT_INVALID_PARAMETERS: if paint is invalid
782 */
783 TVG_EXPORT Tvg_Result tvg_shape_get_stroke_width(const Tvg_Paint* paint, float* width);
784
785
786 /*!
787 * \fn TVG_EXPORT Tvg_Result tvg_shape_set_stroke_color(Tvg_Paint* paint, uint8_t r, uint8_t g, uint8_t b, uint8_t a)
788 * \brief The function sets shape's stroke color.
789 * \param[in] paint Tvg_Paint pointer
790 * \param[in] r red value
791 * \param[in] g green value
792 * \param[in] b blue value
793 * \param[in] a opacity value
794 * \return Tvg_Result return value
795 * - TVG_RESULT_SUCCESS: if ok.
796 * - TVG_RESULT_INVALID_PARAMETERS: if paint is invalid
797 */
798 TVG_EXPORT Tvg_Result tvg_shape_set_stroke_color(Tvg_Paint* paint, uint8_t r, uint8_t g, uint8_t b, uint8_t a);
799
800
801 /*!
802 * \fn 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)
803 * \brief The function gets shape's stroke color
804 * \param[in] paint Tvg_Paint pointer
805 * \param[out] r red value
806 * \param[out] g green value
807 * \param[out] b blue value
808 * \param[out] a opacity value
809 * \return Tvg_Result return value
810 * - TVG_RESULT_SUCCESS: if ok.
811 * - TVG_RESULT_INVALID_PARAMETERS: if paint is invalid
812 */
813 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);
814
815
816 /*!
817 * \fn TVG_EXPORT Tvg_Result tvg_shape_set_stroke_dash(Tvg_Paint* paint, const float* dashPattern, uint32_t cnt)
818 * \brief The function sets shape's stroke dash mode. Dash pattern is an array of floats with size which have to be
819 * divisible by 2. Position with index not divisible by 2 defines length of line. Positions divisible by 2 defines
820 * length of gap
821 * \code
822 * //dash pattern examples
823 * float dashPattern[2] = {20, 10};  // -- - -- - -- -
824 * float dashPattern[2] = {40, 20};  // ----  ----  ----
825 * float dashPattern[4] = {10, 20, 30, 40} // -  ---
826 * \endcode
827 * \param[in] paint Tvg_Paint pointer
828 * \param[in] dashPattern array of floats descibing pattern [(line, gap)]
829 * \param[in] cnt size of an array
830 * \return Tvg_Result return value
831 * - TVG_RESULT_SUCCESS: if ok.
832 * - TVG_RESULT_INVALID_PARAMETERS: if paint is invalid
833 */
834 TVG_EXPORT Tvg_Result tvg_shape_set_stroke_dash(Tvg_Paint* paint, const float* dashPattern, uint32_t cnt);
835
836
837 /*!
838 * \fn TVG_EXPORT Tvg_Result tvg_shape_get_stroke_dash(const Tvg_Paint* paint, const float** dashPattern, uint32_t* cnt)
839 * \brief The function returns shape's stroke dash pattern and its size.
840 * \see tvg_shape_set_stroke_dash
841 * \param[in] paint Tvg_Paint pointer
842 * \param[out] dashPattern array of floats describing pattern
843 * \param[out] cnt size of an array
844 * \return Tvg_Result return value
845 * - TVG_RESULT_SUCCESS: if ok.
846 * - TVG_RESULT_INVALID_PARAMETERS: if paint is invalid
847 */
848 TVG_EXPORT Tvg_Result tvg_shape_get_stroke_dash(const Tvg_Paint* paint, const float** dashPattern, uint32_t* cnt);
849
850
851 /*!
852 * \fn TVG_EXPORT Tvg_Result tvg_shape_set_stroke_cap(Tvg_Paint* paint, Tvg_Stroke_Cap cap)
853 * \brief The function sets the stroke capabilities style to be used for stroking the path.
854 * \see Tvg_Stroke_Cap
855 * \see tvg_shape_get_stroke_cap
856 * \param[in] paint Tvg_Paint pointer
857 * \param[in] cap stroke capabilities
858 * \return Tvg_Result return value
859 * - TVG_RESULT_SUCCESS: if ok.
860 * - TVG_RESULT_INVALID_PARAMETERS: if paint is invalid
861 */
862 TVG_EXPORT Tvg_Result tvg_shape_set_stroke_cap(Tvg_Paint* paint, Tvg_Stroke_Cap cap);
863
864
865 /*!
866 * \fn TVG_EXPORT Tvg_Result tvg_shape_get_stroke_cap(const Tvg_Paint* paint, Tvg_Stroke_Cap* cap)
867 * \brief The function gets the stroke capabilities.
868 * \see Tvg_Stroke_Cap
869 * \see tvg_shape_set_stroke_cap
870 * \param[in] paint Tvg_Paint pointer
871 * \param[out] cap stroke capabilities
872 * \return Tvg_Result return value
873 * - TVG_RESULT_SUCCESS: if ok.
874 * - TVG_RESULT_INVALID_PARAMETERS: if paint is invalid
875 */
876 TVG_EXPORT Tvg_Result tvg_shape_get_stroke_cap(const Tvg_Paint* paint, Tvg_Stroke_Cap* cap);
877
878
879 /*!
880 * \fn TVG_EXPORT Tvg_Result tvg_shape_set_stroke_join(Tvg_Paint* paint, Tvg_Stroke_Join join)
881 * \brief The function sets the stroke join method.
882 * \see Tvg_Stroke_Join
883 * \see tvg_shape_set_stroke_cap
884 * \param[in] paint Tvg_Paint pointer
885 * \param[in] join join method
886 * \return Tvg_Result return value
887 * - TVG_RESULT_SUCCESS: if ok.
888 * - TVG_RESULT_INVALID_PARAMETERS: if paint is invalid
889 */
890 TVG_EXPORT Tvg_Result tvg_shape_set_stroke_join(Tvg_Paint* paint, Tvg_Stroke_Join join);
891
892
893 /*!
894 * \fn TVG_EXPORT Tvg_Result tvg_shape_get_stroke_join(const Tvg_Paint* paint, Tvg_Stroke_Join* join)
895 * \brief The function gets the stroke join method
896 * \param[in] paint Tvg_Paint pointer
897 * \param[out] join join method
898 * \return Tvg_Result return value
899 * - TVG_RESULT_SUCCESS: if ok.
900 * - TVG_RESULT_INVALID_PARAMETERS: if paint is invalid
901 */
902 TVG_EXPORT Tvg_Result tvg_shape_get_stroke_join(const Tvg_Paint* paint, Tvg_Stroke_Join* join);
903
904
905 /*!
906 * \fn TVG_EXPORT Tvg_Result tvg_shape_set_fill_color(Tvg_Paint* paint, uint8_t r, uint8_t g, uint8_t b, uint8_t a)
907 * \brief The function sets shape's fill color.
908 * \see tvg_shape_get_fill_color
909 * \param[in] paint Tvg_Paint pointer
910 * \param[in] r red value
911 * \param[in] g green value
912 * \param[in] b blue value
913 * \param[in] a alpha value
914 * \return Tvg_Result return value
915 * - TVG_RESULT_SUCCESS: if ok.
916 * - TVG_RESULT_INVALID_PARAMETERS: if paint is invalid
917 */
918 TVG_EXPORT Tvg_Result tvg_shape_set_fill_color(Tvg_Paint* paint, uint8_t r, uint8_t g, uint8_t b, uint8_t a);
919
920
921 /*!
922 * \fn 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)
923 * \brief The function gets shape's fill color
924 * \see tvg_shape_set_fill_color
925 * \param[in] paint Tvg_Paint pointer
926 * \param[out] r red value
927 * \param[out] g green value
928 * \param[out] b blue value
929 * \param[out] a alpha value
930 * \return Tvg_Result return value
931 * - TVG_RESULT_SUCCESS: if ok.
932 * - TVG_RESULT_INVALID_PARAMETERS: if paint is invalid
933 */
934 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);
935
936
937 /*!
938 * \fn TVG_EXPORT Tvg_Result tvg_shape_set_fill_rule(Tvg_Paint* paint, Tvg_Fill_Rule rule)
939 * \brief The function sets shape's fill rule.  TVG_FILL_RULE_WINDING is used as default fill rule
940 * \see \link Wiki https://en.wikipedia.org/wiki/Nonzero-rule \endlink
941 * \param[in] paint Tvg_Paint pointer
942 * \param[in] rule fill rule
943 * \return Tvg_Result return value
944 * - TVG_RESULT_SUCCESS: if ok.
945 * - TVG_RESULT_INVALID_PARAMETERS: if paint is invalid
946 */
947 TVG_EXPORT Tvg_Result tvg_shape_set_fill_rule(Tvg_Paint* paint, Tvg_Fill_Rule rule);
948
949
950 /*!
951 * \fn TVG_EXPORT Tvg_Result tvg_shape_get_fill_rule(const Tvg_Paint* paint, Tvg_Fill_Rule* rule)
952 * \brief The function gets shape's fill rule.
953 * \see tvg_shape_get_fill_rule
954 * \param[in] paint Tvg_Paint pointer
955 * \param[out] rule shape's fill rule
956 * \return Tvg_Result return value
957 * - TVG_RESULT_SUCCESS: if ok.
958 * - TVG_RESULT_INVALID_PARAMETERS: if paint is invalid
959 */
960 TVG_EXPORT Tvg_Result tvg_shape_get_fill_rule(const Tvg_Paint* paint, Tvg_Fill_Rule* rule);
961
962
963 /*!
964 * \fn TVG_EXPORT Tvg_Result tvg_shape_set_linear_gradient(Tvg_Paint* paint, Tvg_Gradient* grad)
965 * \brief The function inserts linear gradient object as an shape fill.
966 * \code
967 * Tvg_Gradient* grad = tvg_linear_gradient_new();
968 * tvg_linear_gradient_set(grad, 700, 700, 800, 800);
969 * tvg_shape_set_linear_gradient(shape, grad);
970 * \endcode
971 * \param[in] paint Tvg_Paint pointer
972 * \param[in] grad Tvg_Gradient pointer (linear)
973 * \return Tvg_Result return value
974 * - TVG_RESULT_SUCCESS: if ok.
975 * - TVG_RESULT_INVALID_PARAMETERS: if paint is invalid
976 */
977 TVG_EXPORT Tvg_Result tvg_shape_set_linear_gradient(Tvg_Paint* paint, Tvg_Gradient* grad);
978
979
980 /*!
981 * \fn TVG_EXPORT Tvg_Result tvg_shape_set_radial_gradient(Tvg_Paint* paint, Tvg_Gradient* grad)
982 * \brief The function inserts radial gradient object as an shape fill.
983 * \code
984 * Tvg_Gradient* grad = tvg_radial_gradient_new();
985 * tvg_radial_gradient_set(grad, 550, 550, 50));
986 * tvg_shape_set_radial_gradient(shape, grad);
987 * \endcode
988 * \param[in] paint Tvg_Paint pointer
989 * \param[in] grad Tvg_Gradient pointer
990 * \return Tvg_Result return value
991 * - TVG_RESULT_SUCCESS: if ok.
992 * - TVG_RESULT_INVALID_PARAMETERS: if paint is invalid
993 */
994 TVG_EXPORT Tvg_Result tvg_shape_set_radial_gradient(Tvg_Paint* paint, Tvg_Gradient* grad);
995
996
997 /*!
998 * \fn TVG_EXPORT Tvg_Result tvg_shape_get_gradient(const Tvg_Paint* paint, Tvg_Gradient** grad)
999 * \brief The function returns gradient previously inserted to given shape. Function deos not
1000 * allocate any data.
1001 * \param[in] paint Tvg_Paint pointer
1002 * \param[out] grad Tvg_Gradient pointer
1003 * \return Tvg_Result return value
1004 * - TVG_RESULT_SUCCESS: if ok.
1005 * - TVG_RESULT_INVALID_PARAMETERS: if paint is invalid
1006 */
1007 TVG_EXPORT Tvg_Result tvg_shape_get_gradient(const Tvg_Paint* paint, Tvg_Gradient** grad);
1008
1009 /************************************************************************/
1010 /* Gradient API                                                         */
1011 /************************************************************************/
1012 /*!
1013 * \fn TVG_EXPORT Tvg_Gradient* tvg_linear_gradient_new()
1014 * \brief The function creates new linear gradient object.
1015 * \code
1016 * Tvg_Paint shape = tvg_shape_new();
1017 * tvg_shape_append_rect(shape, 700, 700, 100, 100, 20, 20);
1018 * Tvg_Gradient* grad = tvg_linear_gradient_new();
1019 * tvg_linear_gradient_set(grad, 700, 700, 800, 800);
1020 * Tvg_Color_Stop color_stops[2] =
1021 * {
1022 *   {.offset=0, .r=0, .g=0, .b=0,   .a=255},
1023 *   {.offset=1, .r=0, .g=255, .b=0, .a=255},
1024 * };
1025 * tvg_gradient_set_color_stops(grad, color_stops, 2);
1026 * tvg_shape_set_linear_gradient(shape, grad);
1027 * \endcode
1028 * \return Tvg_Result return value
1029 * - TVG_RESULT_SUCCESS: if ok.
1030 * - TVG_RESULT_INVALID_PARAMETERS: if paint is invalid
1031 */
1032 TVG_EXPORT Tvg_Gradient* tvg_linear_gradient_new();
1033
1034
1035 /*!
1036 * \fn TVG_EXPORT Tvg_Gradient* tvg_radial_gradient_new()
1037 * \brief The function creates new gradient object.
1038 * \code
1039 * Tvg_Paint shape = tvg_shape_new();
1040 * tvg_shape_append_rect(shape, 700, 700, 100, 100, 20, 20);
1041 * Tvg_Gradient* grad = tvg_radial_gradient_new();
1042 * tvg_linear_gradient_set(grad, 550, 550, 50);
1043 * Tvg_Color_Stop color_stops[2] =
1044 * {
1045 *   {.offset=0, .r=0, .g=0, .b=0,   .a=255},
1046 *   {.offset=1, .r=0, .g=255, .b=0, .a=255},
1047 * };
1048 * tvg_gradient_set_color_stops(grad, color_stops, 2);
1049 * tvg_shape_set_radial_gradient(shape, grad);
1050 * \endcode
1051 * \return Tvg_Result return value
1052 * - TVG_RESULT_SUCCESS: if ok.
1053 * - TVG_RESULT_INVALID_PARAMETERS: if paint is invalid
1054 */
1055 TVG_EXPORT Tvg_Gradient* tvg_radial_gradient_new();
1056
1057
1058 /*!
1059 * \fn TVG_EXPORT Tvg_Result tvg_linear_gradient_set(Tvg_Gradient* grad, float x1, float y1, float x2, float y2)
1060 * \brief The function sets start (x1, y1) and end point (x2, y2) of the gradient.
1061 * \param[in] grad Tvg_Gradient pointer
1062 * \param[in] x1 start point x coordinate
1063 * \param[in] y1 start point y coordinate
1064 * \param[in] x2 end point x coordinate
1065 * \param[in] y2 end point y coordinate
1066 * \return Tvg_Result return value
1067 * - TVG_RESULT_SUCCESS: if ok.
1068 * - TVG_RESULT_INVALID_PARAMETERS: if paint is invalid
1069 */
1070 TVG_EXPORT Tvg_Result tvg_linear_gradient_set(Tvg_Gradient* grad, float x1, float y1, float x2, float y2);
1071
1072
1073 /*!
1074 * \fn TVG_EXPORT Tvg_Result tvg_linear_gradient_get(Tvg_Gradient* grad, float* x1, float* y1, float* x2, float* y2)
1075 * \brief The function gets linear gradient start and end postion.
1076 * \param[in] grad Tvg_Gradient pointer
1077 * \param[out] x1 start point x coordinate
1078 * \param[out] y1 start point y coordinate
1079 * \param[out] x2 end point x coordinate
1080 * \param[out] y2 end point y coordinate
1081 * \return Tvg_Result return value
1082 * - TVG_RESULT_SUCCESS: if ok.
1083 * - TVG_RESULT_INVALID_PARAMETERS: if paint is invalid
1084 */
1085 TVG_EXPORT Tvg_Result tvg_linear_gradient_get(Tvg_Gradient* grad, float* x1, float* y1, float* x2, float* y2);
1086
1087
1088 /*!
1089 * \fn TVG_EXPORT Tvg_Result tvg_radial_gradient_set(Tvg_Gradient* grad, float cx, float cy, float radius)
1090 * \brief The function sets radial gradient center and radius
1091 * \param[in] grad Tvg_Gradient pointer
1092 * \param[in] cx radial gradient center x coordinate
1093 * \param[in] cy radial gradient center y coordinate
1094 * \param[in] radius radial gradient radius value
1095 * \return Tvg_Result return value
1096 * - TVG_RESULT_SUCCESS: if ok.
1097 * - TVG_RESULT_INVALID_PARAMETERS: if paint is invalid
1098 */
1099 TVG_EXPORT Tvg_Result tvg_radial_gradient_set(Tvg_Gradient* grad, float cx, float cy, float radius);
1100
1101
1102 /*!
1103 * \fn TVG_EXPORT Tvg_Result tvg_radial_gradient_get(Tvg_Gradient* grad, float* cx, float* cy, float* radius)
1104 * \brief The function gets radial gradient center point ant radius
1105 * \param[in] grad Tvg_Gradient pointer
1106 * \param[out] cx gradient center x coordinate
1107 * \param[out] cy gradient center y coordinate
1108 * \param[out] radius gradient radius value
1109 * \return Tvg_Result return value
1110 * - TVG_RESULT_SUCCESS: if ok.
1111 * - TVG_RESULT_INVALID_PARAMETERS: if paint is invalid
1112 */
1113 TVG_EXPORT Tvg_Result tvg_radial_gradient_get(Tvg_Gradient* grad, float* cx, float* cy, float* radius);
1114
1115 /*!
1116 * \fn TVG_EXPORT Tvg_Result tvg_gradient_set_color_stops(Tvg_Gradient* grad, const Tvg_Color_Stop* color_stop, uint32_t cnt)
1117 * \brief The function sets lists of color stops for the given gradient
1118 * \see tvg_linear_gradient_new
1119 * \param[in] grad Tvg_Gradient pointer
1120 * \param[in] color_stop color stops list
1121 * \param[in] cnt color stops size
1122 * \return Tvg_Result return value
1123 * - TVG_RESULT_SUCCESS: if ok.
1124 * - TVG_RESULT_INVALID_PARAMETERS: if paint is invalid
1125 */
1126 TVG_EXPORT Tvg_Result tvg_gradient_set_color_stops(Tvg_Gradient* grad, const Tvg_Color_Stop* color_stop, uint32_t cnt);
1127
1128
1129 /*!
1130 * \fn TVG_EXPORT Tvg_Result tvg_gradient_get_color_stops(Tvg_Gradient* grad, const Tvg_Color_Stop** color_stop, uint32_t* cnt)
1131 * \brief The function gets lists of color stops for the given gradient
1132 * \param[in] grad Tvg_Gradient pointer
1133 * \param[out] color_stop color stops list
1134 * \param[out] cnt color stops list size
1135 * \return Tvg_Result return value
1136 * - TVG_RESULT_SUCCESS: if ok.
1137 * - TVG_RESULT_INVALID_PARAMETERS: if paint is invalid
1138 */
1139 TVG_EXPORT Tvg_Result tvg_gradient_get_color_stops(Tvg_Gradient* grad, const Tvg_Color_Stop** color_stop, uint32_t* cnt);
1140
1141
1142 /*!
1143 * \fn TVG_EXPORT Tvg_Result tvg_gradient_set_spread(Tvg_Gradient* grad, const Tvg_Stroke_Fill spread)
1144 * \brief The function sets spread fill method for given gradient
1145 * \param[in] grad Tvg_Gradient pointer
1146 * \param[in] spread spread method
1147 * \return Tvg_Result return value
1148 * - TVG_RESULT_SUCCESS: if ok.
1149 * - TVG_RESULT_INVALID_PARAMETERS: if paint is invalid
1150 */
1151 TVG_EXPORT Tvg_Result tvg_gradient_set_spread(Tvg_Gradient* grad, const Tvg_Stroke_Fill spread);
1152
1153
1154 /*!
1155 * \fn TVG_EXPORT Tvg_Result tvg_gradient_get_spread(Tvg_Gradient* grad, Tvg_Stroke_Fill* spread)
1156 * \brief The function gets spread fill method for given gradient
1157 * \param[in] grad Tvg_Gradient pointer
1158 * \param[out] spread spread method
1159 * \return Tvg_Result return value
1160 * - TVG_RESULT_SUCCESS: if ok.
1161 * - TVG_RESULT_INVALID_PARAMETERS: if paint is invalid
1162 */
1163 TVG_EXPORT Tvg_Result tvg_gradient_get_spread(Tvg_Gradient* grad, Tvg_Stroke_Fill* spread);
1164
1165
1166 /*!
1167 * \fn TVG_EXPORT Tvg_Result tvg_gradient_del(Tvg_Gradient* grad)
1168 * \brief The function deletes given gradient object
1169 * \param[in] grad Tvg_Gradient pointer
1170 * \return Tvg_Result return value
1171 * - TVG_RESULT_SUCCESS: if ok.
1172 * - TVG_RESULT_INVALID_PARAMETERS: if paint is invalid
1173 */
1174 TVG_EXPORT Tvg_Result tvg_gradient_del(Tvg_Gradient* grad);
1175
1176 /************************************************************************/
1177 /* Picture API                                                          */
1178 /************************************************************************/
1179 /*!
1180 * \fn TVG_EXPORT Tvg_Paint* tvg_picture_new()
1181 * \brief The function creates new picture object.
1182 * \return Tvg_Result return value
1183 * - TVG_RESULT_SUCCESS: if ok.
1184 * - TVG_RESULT_INVALID_PARAMETERS: if paint is invalid
1185 */
1186 TVG_EXPORT Tvg_Paint* tvg_picture_new();
1187
1188
1189 /*!
1190 * \fn TVG_EXPORT Tvg_Result tvg_picture_load(Tvg_Paint* paint, const char* path)
1191 * \brief The function loads image into given paint object
1192 * \param[in] paint Tvg_Paint pointer
1193 * \param[in] path absolute path to the image file
1194 * \return Tvg_Result return value
1195 * - TVG_RESULT_SUCCESS: if ok.
1196 * - TVG_RESULT_INVALID_PARAMETERS: if paint is invalid
1197 */
1198 TVG_EXPORT Tvg_Result tvg_picture_load(Tvg_Paint* paint, const char* path);
1199
1200
1201 /*!
1202 * \fn TVG_EXPORT Tvg_Result tvg_picture_load_raw(Tvg_Paint* paint, uint32_t *data, uint32_t w, uint32_t h, bool copy)
1203 * \brief The function loads raw image data into given paint object.
1204 * \param[in] paint Tvg_Paint pointer
1205 * \param[in] data raw data pointer
1206 * \param[in] w picture width
1207 * \param[in] h picture height
1208 * \param[in] copy if copy is set to true function copies data into the paint
1209 * \return Tvg_Result return value
1210 * - TVG_RESULT_SUCCESS: if ok.
1211 * - TVG_RESULT_INVALID_PARAMETERS: if paint is invalid
1212 */
1213 TVG_EXPORT Tvg_Result tvg_picture_load_raw(Tvg_Paint* paint, uint32_t *data, uint32_t w, uint32_t h, bool copy);
1214
1215
1216 /*!
1217 * \fn TVG_EXPORT Tvg_Result tvg_picture_get_viewbox(const Tvg_Paint* paint, float* x, float* y, float* w, float* h)
1218 * \brief The function returns viewbox coordinates and size for given paint
1219 * \param[in] paint Tvg_Paint pointer
1220 * \param[out] x left top corner x coordinate
1221 * \param[out] y left top corner y coordinate
1222 * \param[out] w viewbox width
1223 * \param[out] h viewbox height
1224 * \return Tvg_Result return value
1225 * - TVG_RESULT_SUCCESS: if ok.
1226 * - TVG_RESULT_INVALID_PARAMETERS: if paint is invalid
1227 */
1228 TVG_EXPORT Tvg_Result tvg_picture_get_viewbox(const Tvg_Paint* paint, float* x, float* y, float* w, float* h);
1229
1230 /************************************************************************/
1231 /* Scene API                                                            */
1232 /************************************************************************/
1233 /*!
1234 * \fn TVG_EXPORT Tvg_Paint* tvg_scene_new()
1235 * \brief The function creates new scene object. Scene object is used to group paints
1236 * into one object which can be manipulated using Tvg_Paint API.
1237 * \return Tvg_Paint pointer to newly allocated scene or NULL if something went wrong
1238 */
1239 TVG_EXPORT Tvg_Paint* tvg_scene_new();
1240
1241
1242 /*!
1243 * \fn TVG_EXPORT Tvg_Result tvg_scene_reserve(Tvg_Paint* scene, uint32_t size)
1244 * \brief The function reserves a space in given space for specific number of paints
1245 * \see tvg_canvas_reserve
1246 * \param[in] scene Tvg_Paint pointer
1247 * \param[in] size size to allocate
1248 * \return Tvg_Result return value
1249 * - TVG_RESULT_SUCCESS: if ok.
1250 * - TVG_RESULT_INVALID_PARAMETERS: if paint is invalid
1251 */
1252 TVG_EXPORT Tvg_Result tvg_scene_reserve(Tvg_Paint* scene, uint32_t size);
1253
1254
1255 /*!
1256 * \fn TVG_EXPORT Tvg_Result tvg_scene_push(Tvg_Paint* scene, Tvg_Paint* paint)
1257 * \brief The function inserts given paint in the specified scene.
1258 * \see tvg_canvas_push
1259 * \param[in] scene Tvg_Paint pointer (scene)
1260 * \param[in] paint Tvg_Paint pointer (paint)
1261 * \return Tvg_Result return value
1262 * - TVG_RESULT_SUCCESS: if ok.
1263 * - TVG_RESULT_INVALID_PARAMETERS: if paint or scene is invalid
1264 */
1265 TVG_EXPORT Tvg_Result tvg_scene_push(Tvg_Paint* scene, Tvg_Paint* paint);
1266
1267
1268 /*!
1269 * \fn TVG_EXPORT Tvg_Result tvg_scene_clear(Tvg_Paint* scene)
1270 * \brief The function claers paints inserted in scene
1271 * \see tvg_canvas_clear
1272 * \param scene Tvg_Paint pointer
1273 * \return Tvg_Result return value
1274 * - TVG_RESULT_SUCCESS: if ok.
1275 * - TVG_RESULT_INVALID_PARAMETERS: if paint is invalid
1276 */
1277 TVG_EXPORT Tvg_Result tvg_scene_clear(Tvg_Paint* scene);
1278
1279
1280 #ifdef __cplusplus
1281 }
1282 #endif
1283
1284 #endif //_THORVG_CAPI_H_