acid-drop- Hacking the planet from a LilyGo T-Deck using custom firmware |
git clone git://git.acid.vegas/acid-drop.git |
Log | Files | Refs | Archive | README | LICENSE |
lv_draw_arc.c (5977B)
1 /** 2 * @file lv_draw_arc.c 3 * 4 */ 5 6 /********************* 7 * INCLUDES 8 *********************/ 9 #include "lv_draw.h" 10 #include "lv_draw_arc.h" 11 12 /********************* 13 * DEFINES 14 *********************/ 15 16 /********************** 17 * TYPEDEFS 18 **********************/ 19 20 /********************** 21 * STATIC PROTOTYPES 22 **********************/ 23 24 /********************** 25 * STATIC VARIABLES 26 **********************/ 27 28 /********************** 29 * MACROS 30 **********************/ 31 32 /********************** 33 * GLOBAL FUNCTIONS 34 **********************/ 35 36 void lv_draw_arc_dsc_init(lv_draw_arc_dsc_t * dsc) 37 { 38 lv_memset_00(dsc, sizeof(lv_draw_arc_dsc_t)); 39 dsc->width = 1; 40 dsc->opa = LV_OPA_COVER; 41 dsc->color = lv_color_black(); 42 } 43 44 void lv_draw_arc(lv_draw_ctx_t * draw_ctx, const lv_draw_arc_dsc_t * dsc, const lv_point_t * center, uint16_t radius, 45 uint16_t start_angle, uint16_t end_angle) 46 { 47 if(dsc->opa <= LV_OPA_MIN) return; 48 if(dsc->width == 0) return; 49 if(start_angle == end_angle) return; 50 51 draw_ctx->draw_arc(draw_ctx, dsc, center, radius, start_angle, end_angle); 52 53 // const lv_draw_backend_t * backend = lv_draw_backend_get(); 54 // backend->draw_arc(center_x, center_y, radius, start_angle, end_angle, clip_area, dsc); 55 } 56 57 void lv_draw_arc_get_area(lv_coord_t x, lv_coord_t y, uint16_t radius, uint16_t start_angle, uint16_t end_angle, 58 lv_coord_t w, bool rounded, lv_area_t * area) 59 { 60 lv_coord_t rout = radius; 61 62 /*Special case: full arc invalidation */ 63 if(end_angle == start_angle + 360) { 64 area->x1 = x - rout; 65 area->y1 = y - rout; 66 area->x2 = x + rout; 67 area->y2 = y + rout; 68 return; 69 } 70 71 if(start_angle > 360) start_angle -= 360; 72 if(end_angle > 360) end_angle -= 360; 73 74 lv_coord_t rin = radius - w; 75 lv_coord_t extra_area = rounded ? w / 2 + 1 : 0; 76 uint8_t start_quarter = start_angle / 90; 77 uint8_t end_quarter = end_angle / 90; 78 79 /*360 deg still counts as quarter 3 (360 / 90 would be 4)*/ 80 if(start_quarter == 4) start_quarter = 3; 81 if(end_quarter == 4) end_quarter = 3; 82 83 if(start_quarter == end_quarter && start_angle <= end_angle) { 84 if(start_quarter == 0) { 85 area->y1 = y + ((lv_trigo_sin(start_angle) * rin) >> LV_TRIGO_SHIFT) - extra_area; 86 area->x2 = x + ((lv_trigo_sin(start_angle + 90) * rout) >> LV_TRIGO_SHIFT) + extra_area; 87 88 area->y2 = y + ((lv_trigo_sin(end_angle) * rout) >> LV_TRIGO_SHIFT) + extra_area; 89 area->x1 = x + ((lv_trigo_sin(end_angle + 90) * rin) >> LV_TRIGO_SHIFT) - extra_area; 90 } 91 else if(start_quarter == 1) { 92 area->y2 = y + ((lv_trigo_sin(start_angle) * rout) >> LV_TRIGO_SHIFT) + extra_area; 93 area->x2 = x + ((lv_trigo_sin(start_angle + 90) * rin) >> LV_TRIGO_SHIFT) + extra_area; 94 95 area->y1 = y + ((lv_trigo_sin(end_angle) * rin) >> LV_TRIGO_SHIFT) - extra_area; 96 area->x1 = x + ((lv_trigo_sin(end_angle + 90) * rout) >> LV_TRIGO_SHIFT) - extra_area; 97 } 98 else if(start_quarter == 2) { 99 area->x1 = x + ((lv_trigo_sin(start_angle + 90) * rout) >> LV_TRIGO_SHIFT) - extra_area; 100 area->y2 = y + ((lv_trigo_sin(start_angle) * rin) >> LV_TRIGO_SHIFT) + extra_area; 101 102 area->y1 = y + ((lv_trigo_sin(end_angle) * rout) >> LV_TRIGO_SHIFT) - extra_area; 103 area->x2 = x + ((lv_trigo_sin(end_angle + 90) * rin) >> LV_TRIGO_SHIFT) + extra_area; 104 } 105 else if(start_quarter == 3) { 106 area->x1 = x + ((lv_trigo_sin(start_angle + 90) * rin) >> LV_TRIGO_SHIFT) - extra_area; 107 area->y1 = y + ((lv_trigo_sin(start_angle) * rout) >> LV_TRIGO_SHIFT) - extra_area; 108 109 area->x2 = x + ((lv_trigo_sin(end_angle + 90) * rout) >> LV_TRIGO_SHIFT) + extra_area; 110 area->y2 = y + ((lv_trigo_sin(end_angle) * rin) >> LV_TRIGO_SHIFT) + extra_area; 111 } 112 } 113 else if(start_quarter == 0 && end_quarter == 1) { 114 area->x1 = x + ((lv_trigo_sin(end_angle + 90) * rout) >> LV_TRIGO_SHIFT) - extra_area; 115 area->y1 = y + ((LV_MIN(lv_trigo_sin(end_angle), 116 lv_trigo_sin(start_angle)) * rin) >> LV_TRIGO_SHIFT) - extra_area; 117 area->x2 = x + ((lv_trigo_sin(start_angle + 90) * rout) >> LV_TRIGO_SHIFT) + extra_area; 118 area->y2 = y + rout + extra_area; 119 } 120 else if(start_quarter == 1 && end_quarter == 2) { 121 area->x1 = x - rout - extra_area; 122 area->y1 = y + ((lv_trigo_sin(end_angle) * rout) >> LV_TRIGO_SHIFT) - extra_area; 123 area->x2 = x + ((LV_MAX(lv_trigo_sin(start_angle + 90), 124 lv_trigo_sin(end_angle + 90)) * rin) >> LV_TRIGO_SHIFT) + extra_area; 125 area->y2 = y + ((lv_trigo_sin(start_angle) * rout) >> LV_TRIGO_SHIFT) + extra_area; 126 } 127 else if(start_quarter == 2 && end_quarter == 3) { 128 area->x1 = x + ((lv_trigo_sin(start_angle + 90) * rout) >> LV_TRIGO_SHIFT) - extra_area; 129 area->y1 = y - rout - extra_area; 130 area->x2 = x + ((lv_trigo_sin(end_angle + 90) * rout) >> LV_TRIGO_SHIFT) + extra_area; 131 area->y2 = y + (LV_MAX(lv_trigo_sin(end_angle) * rin, 132 lv_trigo_sin(start_angle) * rin) >> LV_TRIGO_SHIFT) + extra_area; 133 } 134 else if(start_quarter == 3 && end_quarter == 0) { 135 area->x1 = x + ((LV_MIN(lv_trigo_sin(end_angle + 90), 136 lv_trigo_sin(start_angle + 90)) * rin) >> LV_TRIGO_SHIFT) - extra_area; 137 area->y1 = y + ((lv_trigo_sin(start_angle) * rout) >> LV_TRIGO_SHIFT) - extra_area; 138 area->x2 = x + rout + extra_area; 139 area->y2 = y + ((lv_trigo_sin(end_angle) * rout) >> LV_TRIGO_SHIFT) + extra_area; 140 141 } 142 else { 143 area->x1 = x - rout; 144 area->y1 = y - rout; 145 area->x2 = x + rout; 146 area->y2 = y + rout; 147 } 148 } 149 150 /********************** 151 * STATIC FUNCTIONS 152 **********************/