mcu_ab568x/app/platform/gui/components/compo_shape.c
2025-05-30 18:03:10 +08:00

150 lines
4.0 KiB
C

#include "include.h"
#define TRACE_EN 0
#if TRACE_EN
#define TRACE(...) printf(__VA_ARGS__)
#else
#define TRACE(...)
#endif
/**
* @brief 创建一个形状
* @param[in] frm : 窗体指针
* @param[in] shape_type : COMPO_SHAPE_TYPE_RECTANGLE 矩形
* @return 返回矩形指针
**/
compo_shape_t *compo_shape_create(compo_form_t *frm, u8 shape_type)
{
compo_shape_t *shape = compo_create(frm, COMPO_TYPE_SHAPE);
void *rect = widget_rect_create(frm->page_body);
shape->rect = rect;
shape->shape_type = shape_type;
return shape;
}
/**@author:gzj
* @brief 创建一个半径为r的圆角矩形
* @param[in] frm : 窗体指针
* @param[in] shape_type : COMPO_SHAPE_TYPE_ROUNDED_RECTANGLE 圆角矩形
* @return 返回矩形指针
**/
compo_shape_t *compo_radius_shape_create(compo_form_t *frm, u8 shape_type , u16 r)
{
compo_shape_t *shape = compo_create(frm, COMPO_TYPE_SHAPE);
void *rect = widget_rect_create(frm->page_body);
widget_rect_set_radius(rect, r);
shape->rect = rect;
shape->shape_type = shape_type;
return shape;
}
/**
* @brief 设置形状的坐标及大小
注意:该设置默认的坐标是以中心点作为参考点
* @param[in] shape : 矩形指针
* @param[in] x : x轴坐标
* @param[in] y : y轴坐标
* @param[in] width : 矩形宽度
* @param[in] height : 矩形高度
**/
void compo_shape_set_location(compo_shape_t *shape, s16 x, s16 y, s16 width, s16 height)
{
widget_set_location(shape->rect, x, y, width, height);
}
/**
* @brief 获取形状的坐标及大小
注意:该设置默认的坐标是以中心点作为参考点
* @param[in] shape : 矩形指针
* @param[out] x : x轴坐标
* @param[out] y : y轴坐标
* @param[out] width : 矩形宽度
* @param[out] height : 矩形高度
**/
rect_t compo_shape_get_location(compo_shape_t *shape)
{
rect_t rect = widget_get_location(shape->rect);
return rect;
}
/**
* @brief 设置形状的大小
注意:该设置默认的坐标是以中心点作为参考点
* @param[in] shape : 矩形指针
* @param[in] x : x轴坐标
* @param[in] y : y轴坐标
* @param[in] width : 矩形宽度
* @param[in] height : 矩形高度
**/
void compo_shape_set_size(compo_shape_t *shape, s16 width, s16 height)
{
widget_set_size(shape->rect, width, height);
}
/**author:gzj
* @brief 设置矩形框是否居中
* @param[in] textbox : 文本指针
* @param[in] align_center : 是否居中
**/
void compo_shape_set_align_center(compo_shape_t *shape, bool align_center)
{
widget_set_align_center(shape->rect, align_center);
}
/**
* @brief 设置形状的坐标
注意:该设置默认的坐标是以中心点作为参考点
* @param[in] shape : 矩形指针
* @param[in] x : x轴坐标
* @param[in] y : y轴坐标
**/
void compo_shape_set_pos(compo_shape_t *shape, s16 x, s16 y)
{
widget_set_pos(shape->rect, x, y);
}
/**
* @brief 设置形状的颜色
* @param[in] shape : 矩形指针
* @param[in] color : 颜色
**/
void compo_shape_set_color(compo_shape_t *shape, u16 color)
{
widget_rect_set_color(shape->rect, color);
}
/**
* @brief 设置形状的透明度
* @param[in] shape : 矩形指针
* @param[in] alpha : 透明度
**/
void compo_shape_set_alpha(compo_shape_t *shape, u8 alpha)
{
widget_set_alpha(shape->rect, alpha);
}
/**
* @brief 设置形状是否可见
* @param[in] shape : 矩形指针
* @param[in] visible : true 可见
false 不可见
**/
void compo_shape_set_visible(compo_shape_t *shape, bool visible)
{
widget_set_visible(shape->rect, visible);
}
/**
* @brief 设置形状(矩形)圆角半径
* @param[in] shape : 矩形指针
* @param[in] r : 半径
**/
void compo_shape_set_radius(compo_shape_t *shape, u16 r)
{
if (shape->shape_type == COMPO_SHAPE_TYPE_RECTANGLE) {
widget_rect_set_radius(shape->rect, r);
}
}