improve dialog highlighter

This commit is contained in:
lixianjing 2022-07-12 16:23:13 +08:00
parent 88c16f3287
commit 3f7e917012
6 changed files with 48 additions and 6 deletions

View File

@ -1,5 +1,8 @@
# 最新动态
2022/07/12
* 对话框高亮增加参数update\_background(感谢雨欣提供补丁)
2022/07/11
* grid控件的列定义增加参考fill\_available用于填充剩余宽度(只有一列可以指定)。

View File

@ -31,8 +31,10 @@
* start_alpha 起始 alpha 值 (0-255)。
* end_alpha 结束 alpha 值 (0-255)。
* alpha 相当于将 start\_alpha 和 end\_alpha 设置为同一个值。
* update_background 是否刷新底层窗口的截图,默认为 false设置为 true 则每帧都会刷新高亮对话框的底层窗口。
> 当 alpha=0 时,显示效果没有变化,但相当于了缓存背景窗口的绘制到图片中,从而提高显示效率,在特殊情况下可以酌情使用。
> 1. 当 alpha=0 时,显示效果没有变化,但相当于缓存了背景窗口的截图,从而提高显示效率,在特殊情况下可以酌情使用。
> 2. 当 update_background=true 时,每一帧都会重新缓存背景窗口的截图,会降低效率,非必要情况不建议使用。
## 四、自定义对话框高亮策略

View File

@ -507,6 +507,9 @@ uint32_t window_manager_get_curr_expected_sleep_time(widget_t* widget);
ret_t window_manager_set_curr_expected_sleep_time(widget_t* widget,
uint32_t curr_expected_sleep_time);
/* public for dialog highlighter */
#define WIDGET_PROP_CURR_WIN "curr_win"
#define WINDOW_MANAGER(widget) ((window_manager_t*)(widget))
END_C_DECLS

View File

@ -104,15 +104,30 @@ static ret_t dialog_highlighter_default_prepare(dialog_highlighter_t* h, canvas_
static ret_t dialog_highlighter_default_draw(dialog_highlighter_t* h, float_t percent) {
rect_t r;
rect_t src;
rect_t dst;
rect_t save_r;
canvas_t* c = h->canvas;
bitmap_t* img = &(h->img);
rect_t src = rect_init(0, 0, img->w, img->h);
rect_t dst = rect_init(0, 0, canvas_get_width(c), canvas_get_height(c));
canvas_t* c;
bitmap_t* img;
dialog_highlighter_default_t* dh = (dialog_highlighter_default_t*)h;
if (percent == 1 && dh->update_background) {
/* if window is open, update prev win image */
bitmap_t prev_img = {0};
widget_t* wm = window_manager();
widget_t* prev_win = window_manager_get_prev_window(wm);
if (widget_set_prop_pointer(wm, WIDGET_PROP_CURR_WIN, h->dialog) == RET_OK) {
window_manager_snap_prev_window(wm, prev_win, &prev_img);
}
}
c = h->canvas;
img = &(h->img);
src = rect_init(0, 0, img->w, img->h);
dst = rect_init(0, 0, canvas_get_width(c), canvas_get_height(c));
if (percent == 1) {
/*if window is open, enable clip and draw system bar*/
/* if window is open, enable clip and draw system bar */
canvas_draw_image(c, img, &src, &dst);
window_manager_paint_system_bar(window_manager(), c);
} else {
@ -164,6 +179,7 @@ dialog_highlighter_t* dialog_highlighter_default_create(tk_object_t* args) {
dh->end_alpha = 0;
dh->start_alpha = 0;
dh->system_bar_alpha = 0xff;
dh->update_background = FALSE;
if (tk_object_get_prop(args, DIALOG_HIGHLIGHTER_DEFAULT_ARG_ALPHA, &v) == RET_OK) {
dh->start_alpha = value_int(&v);
@ -178,5 +194,9 @@ dialog_highlighter_t* dialog_highlighter_default_create(tk_object_t* args) {
dh->end_alpha = value_int(&v);
}
if (tk_object_get_prop(args, DIALOG_HIGHLIGHTER_DEFAULT_ARG_UPDATE_BACKGROUND, &v) == RET_OK) {
dh->update_background = value_bool(&v);
}
return h;
}

View File

@ -57,6 +57,12 @@ struct _dialog_highlighter_default_t {
* system_bar
*/
uint8_t system_bar_alpha;
/**
* @property {bool_t} update_background
*
*/
bool_t update_background;
};
/**
@ -72,6 +78,7 @@ dialog_highlighter_t* dialog_highlighter_default_create(tk_object_t* args);
#define DIALOG_HIGHLIGHTER_DEFAULT_ARG_START_ALPHA "start_alpha"
#define DIALOG_HIGHLIGHTER_DEFAULT_ARG_END_ALPHA "end_alpha"
#define DIALOG_HIGHLIGHTER_DEFAULT_ARG_ALPHA "alpha"
#define DIALOG_HIGHLIGHTER_DEFAULT_ARG_UPDATE_BACKGROUND "update_background"
END_C_DECLS

View File

@ -1085,16 +1085,23 @@ static ret_t window_manager_default_get_prop(widget_t* widget, const char* name,
canvas_t* c = native_window_get_canvas(wm->native_window);
value_set_pointer(v, c);
return RET_OK;
} else if (tk_str_eq(name, WIDGET_PROP_CURR_WIN)) {
value_set_pointer(v, wm->curr_win);
return RET_OK;
}
return RET_NOT_FOUND;
}
static ret_t window_manager_default_set_prop(widget_t* widget, const char* name, const value_t* v) {
window_manager_default_t* wm = WINDOW_MANAGER_DEFAULT(widget);
return_value_if_fail(widget != NULL && name != NULL && v != NULL, RET_BAD_PARAMS);
if (tk_str_eq(name, WIDGET_PROP_POINTER_CURSOR)) {
return window_manager_set_cursor(widget, value_str(v));
} else if (tk_str_eq(name, WIDGET_PROP_CURR_WIN)) {
wm->curr_win = value_pointer(v);
return RET_OK;
}
return RET_NOT_FOUND;