1 /** 2 * @file lv_draw_sw_mask.h 3 * 4 */ 5 6 #ifndef LV_DRAW_SW_MASK_H 7 #define LV_DRAW_SW_MASK_H 8 9 #ifdef __cplusplus 10 extern "C" { 11 #endif 12 13 /********************* 14 * INCLUDES 15 *********************/ 16 #include "../../misc/lv_area.h" 17 #include "../../misc/lv_color.h" 18 #include "../../misc/lv_math.h" 19 #include "../../misc/lv_types.h" 20 21 /********************* 22 * DEFINES 23 *********************/ 24 #define LV_MASK_ID_INV (-1) 25 #if LV_DRAW_SW_COMPLEX 26 # define LV_MASK_MAX_NUM 16 27 #else 28 # define LV_MASK_MAX_NUM 1 29 #endif 30 31 /********************** 32 * TYPEDEFS 33 **********************/ 34 35 typedef enum { 36 LV_DRAW_SW_MASK_RES_TRANSP, 37 LV_DRAW_SW_MASK_RES_FULL_COVER, 38 LV_DRAW_SW_MASK_RES_CHANGED, 39 LV_DRAW_SW_MASK_RES_UNKNOWN 40 } lv_draw_sw_mask_res_t; 41 42 #if LV_DRAW_SW_COMPLEX 43 44 typedef enum { 45 LV_DRAW_SW_MASK_TYPE_LINE, 46 LV_DRAW_SW_MASK_TYPE_ANGLE, 47 LV_DRAW_SW_MASK_TYPE_RADIUS, 48 LV_DRAW_SW_MASK_TYPE_FADE, 49 LV_DRAW_SW_MASK_TYPE_MAP, 50 } lv_draw_sw_mask_type_t; 51 52 typedef enum { 53 LV_DRAW_SW_MASK_LINE_SIDE_LEFT = 0, 54 LV_DRAW_SW_MASK_LINE_SIDE_RIGHT, 55 LV_DRAW_SW_MASK_LINE_SIDE_TOP, 56 LV_DRAW_SW_MASK_LINE_SIDE_BOTTOM, 57 } lv_draw_sw_mask_line_side_t; 58 59 /** 60 * A common callback type for every mask type. 61 * Used internally by the library. 62 */ 63 typedef lv_draw_sw_mask_res_t (*lv_draw_sw_mask_xcb_t)(lv_opa_t * mask_buf, int32_t abs_x, int32_t abs_y, 64 int32_t len, 65 void * p); 66 67 /********************** 68 * GLOBAL PROTOTYPES 69 **********************/ 70 71 void lv_draw_sw_mask_init(void); 72 73 void lv_draw_sw_mask_deinit(void); 74 75 //! @cond Doxygen_Suppress 76 77 /** 78 * Apply the added buffers on a line. Used internally by the library's drawing routines. 79 * @param masks the masks list to apply, must be ended with NULL pointer in array. 80 * @param mask_buf store the result mask here. Has to be `len` byte long. Should be initialized with `0xFF`. 81 * @param abs_x absolute X coordinate where the line to calculate start 82 * @param abs_y absolute Y coordinate where the line to calculate start 83 * @param len length of the line to calculate (in pixel count) 84 * @return One of these values: 85 * - `LV_DRAW_MASK_RES_FULL_TRANSP`: the whole line is transparent. `mask_buf` is not set to zero 86 * - `LV_DRAW_MASK_RES_FULL_COVER`: the whole line is fully visible. `mask_buf` is unchanged 87 * - `LV_DRAW_MASK_RES_CHANGED`: `mask_buf` has changed, it shows the desired opacity of each pixel in the given line 88 */ 89 lv_draw_sw_mask_res_t /* LV_ATTRIBUTE_FAST_MEM */ lv_draw_sw_mask_apply(void * masks[], lv_opa_t * mask_buf, 90 int32_t abs_x, 91 int32_t abs_y, 92 int32_t len); 93 94 //! @endcond 95 96 /** 97 * Free the data from the parameter. 98 * It's called inside `lv_draw_sw_mask_remove_id` and `lv_draw_sw_mask_remove_custom` 99 * Needs to be called only in special cases when the mask is not added by `lv_draw_mask_add` 100 * and not removed by `lv_draw_mask_remove_id` or `lv_draw_mask_remove_custom` 101 * @param p pointer to a mask parameter 102 */ 103 void lv_draw_sw_mask_free_param(void * p); 104 105 /** 106 *Initialize a line mask from two points. 107 * @param param pointer to a `lv_draw_mask_param_t` to initialize 108 * @param p1x X coordinate of the first point of the line 109 * @param p1y Y coordinate of the first point of the line 110 * @param p2x X coordinate of the second point of the line 111 * @param p2y y coordinate of the second point of the line 112 * @param side and element of `lv_draw_mask_line_side_t` to describe which side to keep. 113 * With `LV_DRAW_MASK_LINE_SIDE_LEFT/RIGHT` and horizontal line all pixels are kept 114 * With `LV_DRAW_MASK_LINE_SIDE_TOP/BOTTOM` and vertical line all pixels are kept 115 */ 116 void lv_draw_sw_mask_line_points_init(lv_draw_sw_mask_line_param_t * param, int32_t p1x, int32_t p1y, 117 int32_t p2x, 118 int32_t p2y, lv_draw_sw_mask_line_side_t side); 119 120 /** 121 *Initialize a line mask from a point and an angle. 122 * @param param pointer to a `lv_draw_mask_param_t` to initialize 123 * @param px X coordinate of a point of the line 124 * @param py X coordinate of a point of the line 125 * @param angle right 0 deg, bottom: 90 126 * @param side an element of `lv_draw_mask_line_side_t` to describe which side to keep. 127 * With `LV_DRAW_MASK_LINE_SIDE_LEFT/RIGHT` and horizontal line all pixels are kept 128 * With `LV_DRAW_MASK_LINE_SIDE_TOP/BOTTOM` and vertical line all pixels are kept 129 */ 130 void lv_draw_sw_mask_line_angle_init(lv_draw_sw_mask_line_param_t * param, int32_t px, int32_t py, int16_t angle, 131 lv_draw_sw_mask_line_side_t side); 132 133 /** 134 * Initialize an angle mask. 135 * @param param pointer to a `lv_draw_mask_param_t` to initialize 136 * @param vertex_x X coordinate of the angle vertex (absolute coordinates) 137 * @param vertex_y Y coordinate of the angle vertex (absolute coordinates) 138 * @param start_angle start angle in degrees. 0 deg on the right, 90 deg, on the bottom 139 * @param end_angle end angle 140 */ 141 void lv_draw_sw_mask_angle_init(lv_draw_sw_mask_angle_param_t * param, int32_t vertex_x, int32_t vertex_y, 142 int32_t start_angle, int32_t end_angle); 143 144 /** 145 * Initialize a fade mask. 146 * @param param pointer to an `lv_draw_mask_radius_param_t` to initialize 147 * @param rect coordinates of the rectangle to affect (absolute coordinates) 148 * @param radius radius of the rectangle 149 * @param inv true: keep the pixels inside the rectangle; keep the pixels outside of the rectangle 150 */ 151 void lv_draw_sw_mask_radius_init(lv_draw_sw_mask_radius_param_t * param, const lv_area_t * rect, int32_t radius, 152 bool inv); 153 154 /** 155 * Initialize a fade mask. 156 * @param param pointer to a `lv_draw_mask_param_t` to initialize 157 * @param coords coordinates of the area to affect (absolute coordinates) 158 * @param opa_top opacity on the top 159 * @param y_top at which coordinate start to change to opacity to `opa_bottom` 160 * @param opa_bottom opacity at the bottom 161 * @param y_bottom at which coordinate reach `opa_bottom`. 162 */ 163 void lv_draw_sw_mask_fade_init(lv_draw_sw_mask_fade_param_t * param, const lv_area_t * coords, lv_opa_t opa_top, 164 int32_t y_top, 165 lv_opa_t opa_bottom, int32_t y_bottom); 166 167 /** 168 * Initialize a map mask. 169 * @param param pointer to a `lv_draw_mask_param_t` to initialize 170 * @param coords coordinates of the map (absolute coordinates) 171 * @param map array of bytes with the mask values 172 */ 173 void lv_draw_sw_mask_map_init(lv_draw_sw_mask_map_param_t * param, const lv_area_t * coords, const lv_opa_t * map); 174 175 #endif /*LV_DRAW_SW_COMPLEX*/ 176 177 /********************** 178 * MACROS 179 **********************/ 180 181 #ifdef __cplusplus 182 } /*extern "C"*/ 183 #endif 184 185 #endif /*LV_DRAW_SW_MASK_H*/ 186