1 /**
2 * MIT License
3 *
4 * -----------------------------------------------------------------------------
5 * Copyright (c) 2008-24 Think Silicon Single Member PC
6 * -----------------------------------------------------------------------------
7 *
8 * Permission is hereby granted, free of charge, to any person obtaining a copy
9 * of this software and associated documentation files (the "Software"), to deal
10 * in the Software without restriction, including without limitation the rights to
11 * use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of
12 * the Software, and to permit persons to whom the Software is furnished to do so,
13 * subject to the following conditions:
14 *
15 * The above copyright notice and this permission notice (including the next paragraph)
16 * shall be included in all copies or substantial portions of the Software.
17 *
18 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED,
19 * INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A
20 * PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT
21 * HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF
22 * CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE
23 * OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
24 *
25 */
26
27 /**
28 * @file lv_draw_nema_gfx_arc.c
29 *
30 */
31
32 /*********************
33 * INCLUDES
34 *********************/
35 #include "lv_draw_nema_gfx.h"
36
37 #if LV_USE_NEMA_GFX && LV_USE_NEMA_VG
38
39 /**********************
40 * GLOBAL FUNCTIONS
41 **********************/
lv_draw_nema_gfx_arc(lv_draw_unit_t * draw_unit,const lv_draw_arc_dsc_t * dsc,const lv_area_t * coords)42 void lv_draw_nema_gfx_arc(lv_draw_unit_t * draw_unit, const lv_draw_arc_dsc_t * dsc, const lv_area_t * coords)
43 {
44
45 LV_UNUSED(coords);
46
47 if(dsc->opa <= (lv_opa_t)LV_OPA_MIN)
48 return;
49 if(dsc->width == 0)
50 return;
51 if(dsc->start_angle == dsc->end_angle)
52 return;
53
54 lv_draw_nema_gfx_unit_t * draw_nema_gfx_unit = (lv_draw_nema_gfx_unit_t *)draw_unit;
55
56 lv_layer_t * layer = draw_unit->target_layer;
57 lv_point_t center = {dsc->center.x - layer->buf_area.x1, dsc->center.y - layer->buf_area.y1};
58
59 lv_area_t clip_area;
60 lv_area_copy(&clip_area, draw_unit->clip_area);
61 lv_area_move(&clip_area, -layer->buf_area.x1, -layer->buf_area.y1);
62
63 nema_set_clip(clip_area.x1, clip_area.y1, lv_area_get_width(&clip_area), lv_area_get_height(&clip_area));
64
65 lv_value_precise_t start_angle = dsc->start_angle;
66 lv_value_precise_t end_angle = dsc->end_angle;
67
68 if(start_angle >= end_angle) {
69 end_angle += 360.0f;
70 }
71
72 if(end_angle - start_angle > 360.0f) {
73 start_angle = 0.0f;
74 end_angle = 360.0f;
75 }
76 else {
77 while(end_angle > 360.0f) {
78 start_angle -= 360.0f;
79 end_angle -= 360.0f;
80 }
81 }
82
83 nema_vg_paint_clear(draw_nema_gfx_unit->paint);
84 nema_vg_paint_set_type(draw_nema_gfx_unit->paint, NEMA_VG_PAINT_COLOR);
85 lv_color32_t col32 = lv_color_to_32(dsc->color, dsc->opa);
86 uint32_t bg_color = nema_rgba(col32.red, col32.green, col32.blue, col32.alpha);
87 nema_vg_paint_set_paint_color(draw_nema_gfx_unit->paint, bg_color); // green
88 nema_vg_paint_set_stroke_width(draw_nema_gfx_unit->paint, dsc->width);
89 nema_vg_set_blend(NEMA_BL_SRC_OVER | NEMA_BLOP_SRC_PREMULT);
90
91 if(dsc->rounded == 1) {
92 nema_vg_draw_ring(center.x, center.y, (float)dsc->radius - (float)dsc->width * 0.5f, start_angle, end_angle,
93 draw_nema_gfx_unit->paint);
94 }
95 else {
96 nema_vg_draw_ring_generic(center.x, center.y, (float)dsc->radius - (float)dsc->width * 0.5f, start_angle,
97 end_angle, draw_nema_gfx_unit->paint, 0U);
98 }
99
100 nema_cl_submit(&(draw_nema_gfx_unit->cl));
101
102 }
103
104 #endif
105
106