improve for awtk-web

This commit is contained in:
xianjimli 2019-04-30 12:43:03 +08:00
parent 7cc65025f8
commit c75d85c401
3 changed files with 42 additions and 14 deletions

View File

@ -19,6 +19,10 @@
*
*/
#ifdef AWTK_WEB
#include <emscripten.h>
#endif /*AWTK_WEB*/
#include "base/window_animator.h"
#include "base/window_manager.h"
#include "base/dialog_highlighter_factory.h"
@ -83,6 +87,9 @@ ret_t window_animator_update(window_animator_t* wa, uint32_t time_ms) {
ret_t window_animator_destroy(window_animator_t* wa) {
return_value_if_fail(wa != NULL, RET_FAIL);
#ifdef AWTK_WEB
EM_ASM_INT({ return VGCanvas.animateEnd(); }, 0);
#endif /*AWTK_WEB*/
if (wa->open) {
return window_animator_open_destroy(wa);
@ -96,8 +103,17 @@ ret_t window_animator_destroy(window_animator_t* wa) {
static ret_t window_animator_paint_system_bar(window_animator_t* wa) {
window_manager_t* wm = WINDOW_MANAGER(wa->curr_win->parent);
if (!(wa->canvas->lcd->support_dirty_rect) && wm->system_bar) {
widget_paint(wm->system_bar, wa->canvas);
if (wm->system_bar != NULL) {
#ifdef AWTK_WEB
widget_t* widget = wm->system_bar;
rect_t src = rect_init(widget->x, widget->y, widget->w, widget->h);
rect_t dst = rect_init(widget->x, widget->y, widget->w, widget->h);
canvas_draw_image(wa->canvas, &(wa->prev_img), rect_scale(&src, wa->ratio), &dst);
#else
if (!(wa->canvas->lcd->support_dirty_rect)) {
widget_paint(wm->system_bar, wa->canvas);
}
#endif /*AWTK_WEB*/
}
return RET_OK;
@ -187,6 +203,10 @@ window_animator_t* window_animator_create(bool_t open, const window_animator_vta
wa->open = open;
wa->easing = easing_get(EASING_CUBIC_OUT);
#ifdef AWTK_WEB
EM_ASM_INT({ return VGCanvas.animateBegin(); }, 0);
#endif /*AWTK_WEB*/
return wa;
}
@ -214,7 +234,13 @@ static ret_t window_animator_draw_prev_window(window_animator_t* wa) {
return_value_if_fail(wa != NULL && wa->vt != NULL && wa->vt->draw_prev_window, RET_BAD_PARAMS);
if (wa->dialog_highlighter != NULL) {
return dialog_highlighter_draw(wa->dialog_highlighter, wa->percent);
float_t percent = wa->percent;
/*always < 1 to tell highlighter that it is animating.*/
if (percent >= 1) {
percent = 0.999;
}
return dialog_highlighter_draw(wa->dialog_highlighter, percent);
} else {
return wa->vt->draw_prev_window(wa);
}

17
src/base/window_manager.c Executable file → Normal file
View File

@ -205,6 +205,8 @@ ret_t window_manager_snap_prev_window(widget_t* widget, widget_t* prev_win, bitm
if (wm->system_bar) {
widget_paint(wm->system_bar, c);
}
window_manager_paint_system_bar(widget, c);
ENSURE(widget_paint(prev_win, c) == RET_OK);
if (dialog_highlighter != NULL) {
@ -218,9 +220,7 @@ ret_t window_manager_snap_prev_window(widget_t* widget, widget_t* prev_win, bitm
ENSURE(canvas_begin_frame(c, &r, LCD_DRAW_OFFLINE) == RET_OK);
canvas_set_clip_rect(c, &r);
ENSURE(widget_on_paint_background(widget, c) == RET_OK);
if (wm->system_bar) {
widget_paint(wm->system_bar, c);
}
window_manager_paint_system_bar(widget, c);
ENSURE(widget_paint(prev_win, c) == RET_OK);
if (dialog_highlighter != NULL) {
dialog_highlighter_prepare(dialog_highlighter, c);
@ -608,15 +608,18 @@ static ret_t window_manager_paint_animation(widget_t* widget, canvas_t* c) {
window_manager_inc_fps(widget);
if (ret == RET_DONE) {
if (wm->animator->open) {
window_manager_dispatch_window_event(wm->animator->curr_win, EVT_WINDOW_OPEN);
}
bool_t is_open = wm->animator->open;
widget_t* curr_win = wm->animator->curr_win;
window_animator_destroy(wm->animator);
wm->animator = NULL;
wm->animating = FALSE;
wm->ignore_user_input = FALSE;
if (is_open) {
window_manager_dispatch_window_event(curr_win, EVT_WINDOW_OPEN);
}
if (wm->pending_close_window != NULL) {
widget_t* window = wm->pending_close_window;
wm->pending_close_window = NULL;

View File

@ -252,7 +252,8 @@ TEST(SVGToBSVG, polygon_no_fill3) {
uint32_t out_length = 0;
const svg_shape_polygon_t* shape = NULL;
const char* content =
"<polygon points=\"10 \n20 \r\n30 \t40\" stroke=\"black\" fill=\"transparent\" stroke-width=\"5\"/>";
"<polygon points=\"10 \n20 \r\n30 \t40\" stroke=\"black\" fill=\"transparent\" "
"stroke-width=\"5\"/>";
tk_snprintf(s_buff, sizeof(s_buff) - 1, s_template, content);
svg_to_bsvg(s_buff, strlen(s_buff), &out, &out_length);
@ -293,8 +294,7 @@ TEST(SVGToBSVG, polygon_no_stroke2) {
uint32_t* out = NULL;
uint32_t out_length = 0;
const svg_shape_polygon_t* shape = NULL;
const char* content =
"<polygon points=\"10 \n20 \r\n30 \t40\" stroke=\"\" stroke-width=\"5\"/>";
const char* content = "<polygon points=\"10 \n20 \r\n30 \t40\" stroke=\"\" stroke-width=\"5\"/>";
tk_snprintf(s_buff, sizeof(s_buff) - 1, s_template, content);
svg_to_bsvg(s_buff, strlen(s_buff), &out, &out_length);
@ -325,4 +325,3 @@ TEST(SVGToBSVG, polygon_no_stroke3) {
TKMEM_FREE(out);
}