mirror of
https://gitee.com/zlgopen/awtk.git
synced 2024-11-29 18:48:09 +08:00
improve nanovg and progress circle
This commit is contained in:
parent
22ee99c484
commit
651768419b
@ -155,6 +155,7 @@ static float nvg__absf(float a) { return a >= 0.0f ? a : -a; }
|
||||
static float nvg__signf(float a) { return a >= 0.0f ? 1.0f : -1.0f; }
|
||||
static float nvg__clampf(float a, float mn, float mx) { return a < mn ? mn : (a > mx ? mx : a); }
|
||||
static float nvg__cross(float dx0, float dy0, float dx1, float dy1) { return dx1*dy0 - dx0*dy1; }
|
||||
static int nvg__fequalf(float a, float b) { float t = a - b; return t > -1e-6 && t < 1e-6; }
|
||||
|
||||
static float nvg__normalize(float *x, float* y)
|
||||
{
|
||||
@ -2465,6 +2466,7 @@ void nvgPathWinding(NVGcontext* ctx, int dir)
|
||||
|
||||
void nvgArc(NVGcontext* ctx, float cx, float cy, float r, float a0, float a1, int dir)
|
||||
{
|
||||
float ads_da = 0;
|
||||
float a = 0, da = 0, hda = 0, kappa = 0;
|
||||
float dx = 0, dy = 0, x = 0, y = 0, tanx = 0, tany = 0;
|
||||
float px = 0, py = 0, ptanx = 0, ptany = 0;
|
||||
@ -2474,14 +2476,15 @@ void nvgArc(NVGcontext* ctx, float cx, float cy, float r, float a0, float a1, in
|
||||
|
||||
// Clamp angles
|
||||
da = a1 - a0;
|
||||
ads_da = nvg__absf(da);
|
||||
if (dir == NVG_CW) {
|
||||
if (nvg__absf(da) >= NVG_PI*2) {
|
||||
if (ads_da > NVG_PI*2 || nvg__fequalf(ads_da, NVG_PI*2)) {
|
||||
da = NVG_PI*2;
|
||||
} else {
|
||||
while (da < 0.0f) da += NVG_PI*2;
|
||||
}
|
||||
} else {
|
||||
if (nvg__absf(da) >= NVG_PI*2) {
|
||||
if (ads_da > NVG_PI*2 || nvg__fequalf(ads_da, NVG_PI*2)) {
|
||||
da = -NVG_PI*2;
|
||||
} else {
|
||||
while (da > 0.0f) da -= NVG_PI*2;
|
||||
|
@ -1,6 +1,7 @@
|
||||
# 最新动态
|
||||
2023/09/26
|
||||
* 修复对旧linux-fb的debug模式为true的问题(感谢智明提供补丁)
|
||||
* 修复环形进度条value为0时候画成百分百以及修改nanovg的浮点比较问题(感谢智明提供补丁)
|
||||
|
||||
2023/09/25
|
||||
* 按标准c库修正iswspace 函数定义(感谢陈谭提供补丁)
|
||||
|
@ -221,10 +221,16 @@ static ret_t progress_circle_on_paint_self(widget_t* widget, canvas_t* c) {
|
||||
if (vg != NULL && (has_image || color.rgba.a)) {
|
||||
xy_t cx = widget->w / 2;
|
||||
xy_t cy = widget->h / 2;
|
||||
float_t end_angle = 0.0f;
|
||||
float_t r = progress_circle_get_radius(widget);
|
||||
bool_t ccw = progress_circle->counter_clock_wise;
|
||||
float_t start_angle = TK_D2R(progress_circle->start_angle);
|
||||
float_t end_angle = progress_circle_value_to_angle(widget, progress_circle->value);
|
||||
|
||||
if (tk_fequal(progress_circle->value, 0)) {
|
||||
end_angle = start_angle;
|
||||
} else {
|
||||
end_angle = progress_circle_value_to_angle(widget, progress_circle->value);
|
||||
}
|
||||
|
||||
vgcanvas_save(vg);
|
||||
vgcanvas_translate(vg, c->ox, c->oy);
|
||||
@ -390,7 +396,8 @@ static ret_t progress_circle_get_prop(widget_t* widget, const char* name, value_
|
||||
}
|
||||
|
||||
static ret_t progress_circle_set_prop(widget_t* widget, const char* name, const value_t* v) {
|
||||
return_value_if_fail(widget != NULL && name != NULL && v != NULL, RET_BAD_PARAMS);
|
||||
progress_circle_t* progress_circle = PROGRESS_CIRCLE(widget);
|
||||
return_value_if_fail(progress_circle != NULL && name != NULL && v != NULL, RET_BAD_PARAMS);
|
||||
|
||||
if (tk_str_eq(name, WIDGET_PROP_VALUE)) {
|
||||
return progress_circle_set_value(widget, value_float(v));
|
||||
@ -408,7 +415,11 @@ static ret_t progress_circle_set_prop(widget_t* widget, const char* name, const
|
||||
return progress_circle_set_start_angle(widget, value_int(v));
|
||||
} else if (tk_str_eq(name, PROGRESS_CIRCLE_PROP_LINE_CAP)) {
|
||||
return progress_circle_set_line_cap(widget, value_str(v));
|
||||
}
|
||||
} else if (tk_str_eq(name, WIDGET_PROP_W)) {
|
||||
progress_circle->dirty_rect = rect_init(0, 0, value_int(v), widget->h);
|
||||
} else if (tk_str_eq(name, WIDGET_PROP_H)) {
|
||||
progress_circle->dirty_rect = rect_init(0, 0, widget->w, value_int(v));
|
||||
}
|
||||
|
||||
return RET_NOT_FOUND;
|
||||
}
|
||||
@ -442,6 +453,7 @@ widget_t* progress_circle_create(widget_t* parent, xy_t x, xy_t y, wh_t w, wh_t
|
||||
progress_circle->start_angle = -90;
|
||||
progress_circle->show_text = TRUE;
|
||||
progress_circle->counter_clock_wise = FALSE;
|
||||
progress_circle->dirty_rect = rect_init(0, 0, w, h);
|
||||
progress_circle_set_line_cap(widget, VGCANVAS_LINE_CAP_ROUND);
|
||||
|
||||
return widget;
|
||||
|
Loading…
Reference in New Issue
Block a user