mirror of
https://github.com/lvgl/lvgl.git
synced 2026-05-26 02:37:01 +08:00
fix(vector): rename and enhance rectangle path function with xywh parameters (#8934)
Signed-off-by: wangsimiao1 <wangsimiao1@xiaomi.com> Co-authored-by: pengyiqiang <pengyiqiang@xiaomi.com>
This commit is contained in:
+57
-57
@@ -390,12 +390,9 @@ void lv_vector_path_get_bounding(const lv_vector_path_t * path, lv_area_t * area
|
||||
area->y2 = lroundf(y2);
|
||||
}
|
||||
|
||||
void lv_vector_path_append_rect(lv_vector_path_t * path, const lv_area_t * rect, float rx, float ry)
|
||||
void lv_vector_path_append_rectangle(lv_vector_path_t * path, float x, float y, float w, float h, float rx, float ry)
|
||||
{
|
||||
float x = rect->x1;
|
||||
float y = rect->y1;
|
||||
float w = (float)lv_area_get_width(rect);
|
||||
float h = (float)lv_area_get_height(rect);
|
||||
if(w <= 0.0f || h <= 0.0f) return;
|
||||
|
||||
float hw = w * 0.5f;
|
||||
float hh = h * 0.5f;
|
||||
@@ -403,7 +400,7 @@ void lv_vector_path_append_rect(lv_vector_path_t * path, const lv_area_t * rect,
|
||||
if(rx > hw) rx = hw;
|
||||
if(ry > hh) ry = hh;
|
||||
|
||||
if(rx == 0 && ry == 0) {
|
||||
if(rx <= 0.0f && ry <= 0.0f) {
|
||||
lv_fpoint_t pt = {x, y};
|
||||
lv_vector_path_move_to(path, &pt);
|
||||
pt.x += w;
|
||||
@@ -413,69 +410,72 @@ void lv_vector_path_append_rect(lv_vector_path_t * path, const lv_area_t * rect,
|
||||
pt.x -= w;
|
||||
lv_vector_path_line_to(path, &pt);
|
||||
lv_vector_path_close(path);
|
||||
return;
|
||||
}
|
||||
else if(rx == hw && ry == hh) {
|
||||
lv_fpoint_t pt = {x + w * 0.5f, y + h * 0.5f};
|
||||
|
||||
if(rx == hw && ry == hh) {
|
||||
lv_fpoint_t pt = {x + hw, y + hh};
|
||||
lv_vector_path_append_circle(path, &pt, rx, ry);
|
||||
return;
|
||||
}
|
||||
else {
|
||||
float hrx = rx * 0.5f;
|
||||
float hry = ry * 0.5f;
|
||||
lv_fpoint_t pt, pt2, pt3;
|
||||
|
||||
pt.x = x + rx;
|
||||
pt.y = y;
|
||||
lv_vector_path_move_to(path, &pt);
|
||||
float hrx = rx * 0.5f;
|
||||
float hry = ry * 0.5f;
|
||||
lv_fpoint_t pt, pt2, pt3;
|
||||
|
||||
pt.x = x + w - rx;
|
||||
pt.y = y;
|
||||
lv_vector_path_line_to(path, &pt);
|
||||
pt.x = x + rx;
|
||||
pt.y = y;
|
||||
lv_vector_path_move_to(path, &pt);
|
||||
|
||||
pt.x = x + w - rx + hrx;
|
||||
pt.y = y;
|
||||
pt2.x = x + w;
|
||||
pt2.y = y + ry - hry;
|
||||
pt3.x = x + w;
|
||||
pt3.y = y + ry;
|
||||
lv_vector_path_cubic_to(path, &pt, &pt2, &pt3);
|
||||
pt.x = x + w - rx;
|
||||
pt.y = y;
|
||||
lv_vector_path_line_to(path, &pt);
|
||||
|
||||
pt.x = x + w;
|
||||
pt.y = y + h - ry;
|
||||
lv_vector_path_line_to(path, &pt);
|
||||
pt.x = x + w - rx + hrx;
|
||||
pt.y = y;
|
||||
pt2.x = x + w;
|
||||
pt2.y = y + ry - hry;
|
||||
pt3.x = x + w;
|
||||
pt3.y = y + ry;
|
||||
lv_vector_path_cubic_to(path, &pt, &pt2, &pt3);
|
||||
|
||||
pt.x = x + w;
|
||||
pt.y = y + h - ry + hry;
|
||||
pt2.x = x + w - rx + hrx;
|
||||
pt2.y = y + h;
|
||||
pt3.x = x + w - rx;
|
||||
pt3.y = y + h;
|
||||
lv_vector_path_cubic_to(path, &pt, &pt2, &pt3);
|
||||
pt.x = x + w;
|
||||
pt.y = y + h - ry;
|
||||
lv_vector_path_line_to(path, &pt);
|
||||
|
||||
pt.x = x + rx;
|
||||
pt.y = y + h;
|
||||
lv_vector_path_line_to(path, &pt);
|
||||
pt.x = x + w;
|
||||
pt.y = y + h - ry + hry;
|
||||
pt2.x = x + w - rx + hrx;
|
||||
pt2.y = y + h;
|
||||
pt3.x = x + w - rx;
|
||||
pt3.y = y + h;
|
||||
lv_vector_path_cubic_to(path, &pt, &pt2, &pt3);
|
||||
|
||||
pt.x = x + rx - hrx;
|
||||
pt.y = y + h;
|
||||
pt2.x = x;
|
||||
pt2.y = y + h - ry + hry;
|
||||
pt3.x = x;
|
||||
pt3.y = y + h - ry;
|
||||
lv_vector_path_cubic_to(path, &pt, &pt2, &pt3);
|
||||
pt.x = x + rx;
|
||||
pt.y = y + h;
|
||||
lv_vector_path_line_to(path, &pt);
|
||||
|
||||
pt.x = x;
|
||||
pt.y = y + ry;
|
||||
lv_vector_path_line_to(path, &pt);
|
||||
pt.x = x + rx - hrx;
|
||||
pt.y = y + h;
|
||||
pt2.x = x;
|
||||
pt2.y = y + h - ry + hry;
|
||||
pt3.x = x;
|
||||
pt3.y = y + h - ry;
|
||||
lv_vector_path_cubic_to(path, &pt, &pt2, &pt3);
|
||||
|
||||
pt.x = x;
|
||||
pt.y = y + ry - hry;
|
||||
pt2.x = x + rx - hrx;
|
||||
pt2.y = y;
|
||||
pt3.x = x + rx;
|
||||
pt3.y = y;
|
||||
lv_vector_path_cubic_to(path, &pt, &pt2, &pt3);
|
||||
lv_vector_path_close(path);
|
||||
}
|
||||
pt.x = x;
|
||||
pt.y = y + ry;
|
||||
lv_vector_path_line_to(path, &pt);
|
||||
|
||||
pt.x = x;
|
||||
pt.y = y + ry - hry;
|
||||
pt2.x = x + rx - hrx;
|
||||
pt2.y = y;
|
||||
pt3.x = x + rx;
|
||||
pt3.y = y;
|
||||
lv_vector_path_cubic_to(path, &pt, &pt2, &pt3);
|
||||
|
||||
lv_vector_path_close(path);
|
||||
}
|
||||
|
||||
void lv_vector_path_append_circle(lv_vector_path_t * path, const lv_fpoint_t * c, float rx, float ry)
|
||||
|
||||
@@ -199,13 +199,32 @@ void lv_vector_path_close(lv_vector_path_t * path);
|
||||
void lv_vector_path_get_bounding(const lv_vector_path_t * path, lv_area_t * area);
|
||||
|
||||
/**
|
||||
* Add a rectangle to the path
|
||||
* Add a rectangle to the path by x/y/w/h. rx/ry are corner radii
|
||||
* @param path pointer to a path
|
||||
* @param x the x coordinate of the top-left corner of the rectangle
|
||||
* @param y the y coordinate of the top-left corner of the rectangle
|
||||
* @param w the width of the rectangle
|
||||
* @param h the height of the rectangle
|
||||
* @param rx the horizontal radius for rounded rectangle
|
||||
* @param ry the vertical radius for rounded rectangle
|
||||
*/
|
||||
void lv_vector_path_append_rectangle(lv_vector_path_t * path, float x, float y, float w, float h, float rx, float ry);
|
||||
|
||||
/**
|
||||
* Add a rectangle to the path (legacy api, recommend use lv_vector_path_append_rectangle instead)
|
||||
* @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);
|
||||
static inline void lv_vector_path_append_rect(lv_vector_path_t * path, const lv_area_t * rect, float rx, float ry)
|
||||
{
|
||||
LV_ASSERT_NULL(path);
|
||||
LV_ASSERT_NULL(rect);
|
||||
|
||||
lv_vector_path_append_rectangle(path, rect->x1, rect->y1, (float)lv_area_get_width(rect),
|
||||
(float)lv_area_get_height(rect), rx, ry);
|
||||
}
|
||||
|
||||
/**
|
||||
* Add a circle to the path
|
||||
|
||||
Reference in New Issue
Block a user