1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
|
/**
* @file lv_draw_vector.h
*
*/
#ifndef LV_DRAW_VECTOR_H
#define LV_DRAW_VECTOR_H
#ifdef __cplusplus
extern "C" {
#endif
/*********************
* INCLUDES
*********************/
#include "lv_draw.h"
#include "../misc/lv_array.h"
#include "../misc/lv_matrix.h"
#if LV_USE_VECTOR_GRAPHIC
#if !LV_USE_MATRIX
#error "lv_draw_vector needs LV_USE_MATRIX = 1"
#endif
/**********************
* TYPEDEFS
**********************/
typedef enum {
LV_VECTOR_FILL_NONZERO = 0,
LV_VECTOR_FILL_EVENODD,
} lv_vector_fill_t;
typedef enum {
LV_VECTOR_STROKE_CAP_BUTT = 0,
LV_VECTOR_STROKE_CAP_SQUARE,
LV_VECTOR_STROKE_CAP_ROUND,
} lv_vector_stroke_cap_t;
typedef enum {
LV_VECTOR_STROKE_JOIN_MITER = 0,
LV_VECTOR_STROKE_JOIN_BEVEL,
LV_VECTOR_STROKE_JOIN_ROUND,
} lv_vector_stroke_join_t;
typedef enum {
LV_VECTOR_PATH_QUALITY_MEDIUM = 0, /* default*/
LV_VECTOR_PATH_QUALITY_HIGH,
LV_VECTOR_PATH_QUALITY_LOW,
} lv_vector_path_quality_t;
typedef enum {
LV_VECTOR_BLEND_SRC_OVER = 0,
LV_VECTOR_BLEND_SRC_IN,
LV_VECTOR_BLEND_DST_OVER,
LV_VECTOR_BLEND_DST_IN,
LV_VECTOR_BLEND_SCREEN,
LV_VECTOR_BLEND_MULTIPLY,
LV_VECTOR_BLEND_NONE,
LV_VECTOR_BLEND_ADDITIVE,
LV_VECTOR_BLEND_SUBTRACTIVE,
} lv_vector_blend_t;
typedef enum {
LV_VECTOR_PATH_OP_MOVE_TO = 0,
LV_VECTOR_PATH_OP_LINE_TO,
LV_VECTOR_PATH_OP_QUAD_TO,
LV_VECTOR_PATH_OP_CUBIC_TO,
LV_VECTOR_PATH_OP_CLOSE,
} lv_vector_path_op_t;
typedef enum {
LV_VECTOR_DRAW_STYLE_SOLID = 0,
LV_VECTOR_DRAW_STYLE_PATTERN,
LV_VECTOR_DRAW_STYLE_GRADIENT,
} lv_vector_draw_style_t;
typedef enum {
LV_VECTOR_GRADIENT_SPREAD_PAD = 0,
LV_VECTOR_GRADIENT_SPREAD_REPEAT,
LV_VECTOR_GRADIENT_SPREAD_REFLECT,
} lv_vector_gradient_spread_t;
typedef enum {
LV_VECTOR_GRADIENT_STYLE_LINEAR = 0,
LV_VECTOR_GRADIENT_STYLE_RADIAL,
} lv_vector_gradient_style_t;
struct lv_fpoint_t {
float x;
float y;
};
/**********************
* GLOBAL PROTOTYPES
**********************/
/**
* Transform the coordinates of a point using given matrix
* @param matrix pointer to a matrix
* @param point pointer to a point
*/
void lv_matrix_transform_point(const lv_matrix_t * matrix, lv_fpoint_t * point);
/**
* Transform all the coordinates of a path using given matrix
* @param matrix pointer to a matrix
* @param path pointer to a path
*/
void lv_matrix_transform_path(const lv_matrix_t * matrix, lv_vector_path_t * path);
/**
* Create a vector graphic path object
* @param quality the quality hint of path
* @return pointer to the created path object
*/
lv_vector_path_t * lv_vector_path_create(lv_vector_path_quality_t quality);
/**
* Copy a path data to another
* @param target_path pointer to a path
* @param path pointer to source path
*/
void lv_vector_path_copy(lv_vector_path_t * target_path, const lv_vector_path_t * path);
/**
* Clear path data
* @param path pointer to a path
*/
void lv_vector_path_clear(lv_vector_path_t * path);
/**
* Delete the graphic path object
* @param path pointer to a path
*/
void lv_vector_path_delete(lv_vector_path_t * path);
/**
* Begin a new sub path and set a point to path
* @param path pointer to a path
* @param p pointer to a `lv_fpoint_t` variable
*/
void lv_vector_path_move_to(lv_vector_path_t * path, const lv_fpoint_t * p);
/**
* Add a line to the path from last point to the point
* @param path pointer to a path
* @param p pointer to a `lv_fpoint_t` variable
*/
void lv_vector_path_line_to(lv_vector_path_t * path, const lv_fpoint_t * p);
/**
* Add a quadratic bezier line to the path from last point to the point
* @param path pointer to a path
* @param p1 pointer to a `lv_fpoint_t` variable for control point
* @param p2 pointer to a `lv_fpoint_t` variable for end point
*/
void lv_vector_path_quad_to(lv_vector_path_t * path, const lv_fpoint_t * p1, const lv_fpoint_t * p2);
/**
* Add a cubic bezier line to the path from last point to the point
* @param path pointer to a path
* @param p1 pointer to a `lv_fpoint_t` variable for first control point
* @param p2 pointer to a `lv_fpoint_t` variable for second control point
* @param p3 pointer to a `lv_fpoint_t` variable for end point
*/
void lv_vector_path_cubic_to(lv_vector_path_t * path, const lv_fpoint_t * p1, const lv_fpoint_t * p2,
const lv_fpoint_t * p3);
/**
* Close the sub path
* @param path pointer to a path
*/
void lv_vector_path_close(lv_vector_path_t * path);
/**
* Get the bounding box of a path
* @param path pointer to a path
* @param area pointer to a `lv_area_t` variable for bounding box
*/
void lv_vector_path_get_bounding(const lv_vector_path_t * path, lv_area_t * area);
/**
* Add a rectangle to the path
* @param path pointer to a path
* @param rect pointer to a `lv_area_t` variable
* @param rx the horizontal radius for rounded rectangle
* @param ry the vertical radius for rounded rectangle
*/
void lv_vector_path_append_rect(lv_vector_path_t * path, const lv_area_t * rect, float rx, float ry);
/**
* Add a circle to the path
* @param path pointer to a path
* @param c pointer to a `lv_fpoint_t` variable for center of the circle
* @param rx the horizontal radius for circle
* @param ry the vertical radius for circle
*/
void lv_vector_path_append_circle(lv_vector_path_t * path, const lv_fpoint_t * c, float rx, float ry);
/**
* Add a arc to the path
* @param path pointer to a path
* @param c pointer to a `lv_fpoint_t` variable for center of the circle
* @param radius the radius for arc
* @param start_angle the start angle for arc
* @param sweep the sweep angle for arc, could be negative
* @param pie true: draw a pie, false: draw a arc
*/
void lv_vector_path_append_arc(lv_vector_path_t * path, const lv_fpoint_t * c, float radius, float start_angle,
float sweep, bool pie);
/**
* Add an sub path to the path
* @param path pointer to a path
* @param subpath pointer to another path which will be added
*/
void lv_vector_path_append_path(lv_vector_path_t * path, const lv_vector_path_t * subpath);
/**
* Create a vector graphic descriptor
* @param layer pointer to a layer
* @return pointer to the created descriptor
*/
lv_vector_dsc_t * lv_vector_dsc_create(lv_layer_t * layer);
/**
* Delete the vector graphic descriptor
* @param dsc pointer to a vector graphic descriptor
*/
void lv_vector_dsc_delete(lv_vector_dsc_t * dsc);
/**
* Set a matrix to current transformation matrix
* @param dsc pointer to a vector graphic descriptor
* @param matrix pointer to a matrix
*/
void lv_vector_dsc_set_transform(lv_vector_dsc_t * dsc, const lv_matrix_t * matrix);
/**
* Set blend mode for descriptor
* @param dsc pointer to a vector graphic descriptor
* @param blend the blend mode to be set in `lv_vector_blend_t`
*/
void lv_vector_dsc_set_blend_mode(lv_vector_dsc_t * dsc, lv_vector_blend_t blend);
/**
* Set fill color for descriptor
* @param dsc pointer to a vector graphic descriptor
* @param color the color to be set in lv_color32_t format
*/
void lv_vector_dsc_set_fill_color32(lv_vector_dsc_t * dsc, lv_color32_t color);
/**
* Set fill color for descriptor
* @param dsc pointer to a vector graphic descriptor
* @param color the color to be set in lv_color_t format
*/
void lv_vector_dsc_set_fill_color(lv_vector_dsc_t * dsc, lv_color_t color);
/**
* Set fill opacity for descriptor
* @param dsc pointer to a vector graphic descriptor
* @param opa the opacity to be set in lv_opa_t format
*/
void lv_vector_dsc_set_fill_opa(lv_vector_dsc_t * dsc, lv_opa_t opa);
/**
* Set fill rule for descriptor
* @param dsc pointer to a vector graphic descriptor
* @param rule the fill rule to be set in lv_vector_fill_t format
*/
void lv_vector_dsc_set_fill_rule(lv_vector_dsc_t * dsc, lv_vector_fill_t rule);
/**
* Set fill image for descriptor
* @param dsc pointer to a vector graphic descriptor
* @param img_dsc pointer to a `lv_draw_image_dsc_t` variable
*/
void lv_vector_dsc_set_fill_image(lv_vector_dsc_t * dsc, const lv_draw_image_dsc_t * img_dsc);
/**
* Set fill linear gradient for descriptor
* @param dsc pointer to a vector graphic descriptor
* @param x1 the x for start point
* @param y1 the y for start point
* @param x2 the x for end point
* @param y2 the y for end point
*/
void lv_vector_dsc_set_fill_linear_gradient(lv_vector_dsc_t * dsc, float x1, float y1, float x2, float y2);
/**
* Set fill radial gradient radius for descriptor
* @param dsc pointer to a vector graphic descriptor
* @param cx the x for center of the circle
* @param cy the y for center of the circle
* @param radius the radius for circle
*/
void lv_vector_dsc_set_fill_radial_gradient(lv_vector_dsc_t * dsc, float cx, float cy, float radius);
/**
* Set fill radial gradient spread for descriptor
* @param dsc pointer to a vector graphic descriptor
* @param spread the gradient spread to be set in lv_vector_gradient_spread_t format
*/
void lv_vector_dsc_set_fill_gradient_spread(lv_vector_dsc_t * dsc, lv_vector_gradient_spread_t spread);
/**
* Set fill gradient color stops for descriptor
* @param dsc pointer to a vector graphic descriptor
* @param stops an array of `lv_gradient_stop_t` variables
* @param count the number of stops in the array, range: 0..LV_GRADIENT_MAX_STOPS
*/
void lv_vector_dsc_set_fill_gradient_color_stops(lv_vector_dsc_t * dsc, const lv_gradient_stop_t * stops,
uint16_t count);
/**
* Set a matrix to current fill transformation matrix
* @param dsc pointer to a vector graphic descriptor
* @param matrix pointer to a matrix
*/
void lv_vector_dsc_set_fill_transform(lv_vector_dsc_t * dsc, const lv_matrix_t * matrix);
/**
* Set stroke color for descriptor
* @param dsc pointer to a vector graphic descriptor
* @param color the color to be set in lv_color32_t format
*/
void lv_vector_dsc_set_stroke_color32(lv_vector_dsc_t * dsc, lv_color32_t color);
/**
* Set stroke color for descriptor
* @param dsc pointer to a vector graphic descriptor
* @param color the color to be set in lv_color_t format
*/
void lv_vector_dsc_set_stroke_color(lv_vector_dsc_t * dsc, lv_color_t color);
/**
* Set stroke opacity for descriptor
* @param dsc pointer to a vector graphic descriptor
* @param opa the opacity to be set in lv_opa_t format
*/
void lv_vector_dsc_set_stroke_opa(lv_vector_dsc_t * dsc, lv_opa_t opa);
/**
* Set stroke line width for descriptor
* @param dsc pointer to a vector graphic descriptor
* @param width the stroke line width
*/
void lv_vector_dsc_set_stroke_width(lv_vector_dsc_t * dsc, float width);
/**
* Set stroke line dash pattern for descriptor
* @param dsc pointer to a vector graphic descriptor
* @param dash_pattern an array of values that specify the segments of dash line
* @param dash_count the length of dash pattern array
*/
void lv_vector_dsc_set_stroke_dash(lv_vector_dsc_t * dsc, float * dash_pattern, uint16_t dash_count);
/**
* Set stroke line cap style for descriptor
* @param dsc pointer to a vector graphic descriptor
* @param cap the line cap to be set in lv_vector_stroke_cap_t format
*/
void lv_vector_dsc_set_stroke_cap(lv_vector_dsc_t * dsc, lv_vector_stroke_cap_t cap);
/**
* Set stroke line join style for descriptor
* @param dsc pointer to a vector graphic descriptor
* @param join the line join to be set in lv_vector_stroke_join_t format
*/
void lv_vector_dsc_set_stroke_join(lv_vector_dsc_t * dsc, lv_vector_stroke_join_t join);
/**
* Set stroke miter limit for descriptor
* @param dsc pointer to a vector graphic descriptor
* @param miter_limit the stroke miter_limit
*/
void lv_vector_dsc_set_stroke_miter_limit(lv_vector_dsc_t * dsc, uint16_t miter_limit);
/**
* Set stroke linear gradient for descriptor
* @param dsc pointer to a vector graphic descriptor
* @param x1 the x for start point
* @param y1 the y for start point
* @param x2 the x for end point
* @param y2 the y for end point
*/
void lv_vector_dsc_set_stroke_linear_gradient(lv_vector_dsc_t * dsc, float x1, float y1, float x2, float y2);
/**
* Set stroke radial gradient for descriptor
* @param dsc pointer to a vector graphic descriptor
* @param cx the x for center of the circle
* @param cy the y for center of the circle
* @param radius the radius for circle
*/
void lv_vector_dsc_set_stroke_radial_gradient(lv_vector_dsc_t * dsc, float cx, float cy, float radius);
/**
* Set stroke color stops for descriptor
* @param dsc pointer to a vector graphic descriptor
* @param spread the gradient spread to be set in lv_vector_gradient_spread_t format
*/
void lv_vector_dsc_set_stroke_gradient_spread(lv_vector_dsc_t * dsc, lv_vector_gradient_spread_t spread);
/**
* Set stroke color stops for descriptor
* @param dsc pointer to a vector graphic descriptor
* @param stops an array of `lv_gradient_stop_t` variables
* @param count the number of stops in the array
*/
void lv_vector_dsc_set_stroke_gradient_color_stops(lv_vector_dsc_t * dsc, const lv_gradient_stop_t * stops,
uint16_t count);
/**
* Set a matrix to current stroke transformation matrix
* @param dsc pointer to a vector graphic descriptor
* @param matrix pointer to a matrix
*/
void lv_vector_dsc_set_stroke_transform(lv_vector_dsc_t * dsc, const lv_matrix_t * matrix);
/**
* Set current transformation matrix to identity matrix
* @param dsc pointer to a vector graphic descriptor
*/
void lv_vector_dsc_identity(lv_vector_dsc_t * dsc);
/**
* Change the scale factor of current transformation matrix
* @param dsc pointer to a vector graphic descriptor
* @param scale_x the scale factor for the X direction
* @param scale_y the scale factor for the Y direction
*/
void lv_vector_dsc_scale(lv_vector_dsc_t * dsc, float scale_x, float scale_y);
/**
* Rotate current transformation matrix with origin
* @param dsc pointer to a vector graphic descriptor
* @param degree angle to rotate
*/
void lv_vector_dsc_rotate(lv_vector_dsc_t * dsc, float degree);
/**
* Translate current transformation matrix to new position
* @param dsc pointer to a vector graphic descriptor
* @param tx the amount of translate in x direction
* @param tx the amount of translate in y direction
*/
void lv_vector_dsc_translate(lv_vector_dsc_t * dsc, float tx, float ty);
/**
* Change the skew factor of current transformation matrix
* @param dsc pointer to a vector graphic descriptor
* @param skew_x the skew factor for x direction
* @param skew_y the skew factor for y direction
*/
void lv_vector_dsc_skew(lv_vector_dsc_t * dsc, float skew_x, float skew_y);
/**
* Add a graphic path to the draw list
* @param dsc pointer to a vector graphic descriptor
* @param path pointer to a path
*/
void lv_vector_dsc_add_path(lv_vector_dsc_t * dsc, const lv_vector_path_t * path);
/**
* Clear a rectangle area use current fill color
* @param dsc pointer to a vector graphic descriptor
* @param rect the area to clear in the buffer
*/
void lv_vector_clear_area(lv_vector_dsc_t * dsc, const lv_area_t * rect);
/**
* Draw all the vector graphic paths
* @param dsc pointer to a vector graphic descriptor
*/
void lv_draw_vector(lv_vector_dsc_t * dsc);
/* Traverser for task list */
typedef void (*vector_draw_task_cb)(void * ctx, const lv_vector_path_t * path, const lv_vector_draw_dsc_t * dsc);
#endif /* LV_USE_VECTOR_GRAPHIC */
#ifdef __cplusplus
} /* extern "C" */
#endif
#endif /* LV_DRAW_VECTOR_H */
|