mirror of
https://gitee.com/zlgopen/awtk.git
synced 2024-11-30 02:58:26 +08:00
ignore user input when window animating
This commit is contained in:
parent
6d5f099997
commit
132ac68121
@ -10,8 +10,8 @@ GTEST_ROOT = os.path.join(LFTK_ROOT, '3rd/gtest/googletest')
|
||||
BIN_DIR=os.path.join(LFTK_ROOT, 'bin')
|
||||
LIB_DIR=os.path.join(LFTK_ROOT, 'lib')
|
||||
|
||||
LCD='NANOVG'
|
||||
LCD='SDL'
|
||||
LCD='NANOVG'
|
||||
|
||||
os.environ['LCD'] = LCD
|
||||
os.environ['BIN_DIR'] = BIN_DIR;
|
||||
|
47
lua/custom.c
47
lua/custom.c
@ -181,3 +181,50 @@ static int wrap_timer_remove(lua_State* L) {
|
||||
|
||||
return 1;
|
||||
}
|
||||
|
||||
static ret_t call_on_idle(const idle_info_t* idle) {
|
||||
ret_t ret = RET_REMOVE;
|
||||
lua_State* L = (lua_State*)s_current_L;
|
||||
int func_id = (char*)(idle->ctx) - (char*)NULL;
|
||||
|
||||
lua_settop(L, 0);
|
||||
lua_rawgeti(L, LUA_REGISTRYINDEX, func_id);
|
||||
|
||||
lua_pcall(L, 0, 1, 0);
|
||||
|
||||
ret = (ret_t)lua_tonumber(L, -1);
|
||||
|
||||
return ret;
|
||||
}
|
||||
|
||||
static int wrap_idle_add(lua_State* L) {
|
||||
uint32_t id = 0;
|
||||
if (lua_isfunction(L, 1)) {
|
||||
int func_id = 0;
|
||||
lua_pushvalue(L, 1);
|
||||
func_id = luaL_ref(L, LUA_REGISTRYINDEX);
|
||||
|
||||
id = idle_add(call_on_idle, (char*)NULL + func_id);
|
||||
lua_pushnumber(L, (lua_Number)id);
|
||||
|
||||
return 1;
|
||||
} else {
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
|
||||
static int wrap_idle_remove(lua_State* L) {
|
||||
ret_t ret = 0;
|
||||
uint32_t id = (uint32_t)luaL_checkinteger(L, 1);
|
||||
const idle_info_t* idle = idle_find(id);
|
||||
|
||||
if (idle) {
|
||||
uint32_t func_id = (char*)(idle->ctx) - (char*)NULL;
|
||||
luaL_unref(L, LUA_REGISTRYINDEX, func_id);
|
||||
ret = (ret_t)idle_remove(id);
|
||||
}
|
||||
|
||||
lua_pushnumber(L, (lua_Number)(ret));
|
||||
|
||||
return 1;
|
||||
}
|
||||
|
@ -3,7 +3,7 @@ function on_click(ctx, evt)
|
||||
end
|
||||
|
||||
function application_init()
|
||||
local win = Window.open("window1");
|
||||
local win = Window.open("window");
|
||||
|
||||
win.inc:on(EventType.CLICK, function(evt)
|
||||
win.bar2:set_value(win.bar2.value + 10);
|
||||
@ -39,7 +39,7 @@ function application_init()
|
||||
dlg:destroy()
|
||||
end
|
||||
|
||||
win.dialog:on(EventType.CLICK, function(evt)
|
||||
win.dialog1:on(EventType.CLICK, function(evt)
|
||||
show_dialog("dialog1");
|
||||
end);
|
||||
|
||||
|
1398
lua/lftk_lua.c
1398
lua/lftk_lua.c
File diff suppressed because it is too large
Load Diff
@ -49,7 +49,7 @@ static ret_t window_animator_open_scale_draw_curr(window_animator_t* wa) {
|
||||
rect_init(dst, 0, 0, win->w * scale, win->h * scale);
|
||||
dst.x = win->x + ((win->w - dst.w) >> 1);
|
||||
dst.y = win->y + ((win->h - dst.h) >> 1);
|
||||
log_debug("%d %d %d %d\n", dst.x, dst.y, dst.w, dst.h);
|
||||
//log_debug("%d %d %d %d\n", dst.x, dst.y, dst.w, dst.h);
|
||||
lcd_set_global_alpha(c->lcd, alpha * 0xff);
|
||||
lcd_draw_image(c->lcd, &(wa->curr_img), &src, &dst);
|
||||
#endif
|
||||
|
@ -55,7 +55,7 @@ ret_t window_animator_update(window_animator_t* wa, uint32_t time_ms) {
|
||||
wa->draw_curr_window(wa);
|
||||
}
|
||||
|
||||
log_debug("percent=%f time_percent=%f time=%u\n", wa->percent, wa->time_percent, time_ms);
|
||||
//log_debug("percent=%f time_percent=%f time=%u\n", wa->percent, wa->time_percent, time_ms);
|
||||
ENSURE(canvas_end_frame(c) == RET_OK);
|
||||
|
||||
return wa->time_percent >= 1 ? RET_DONE : RET_OK;
|
||||
|
@ -22,6 +22,7 @@
|
||||
#include "base/keys.h"
|
||||
#include "base/mem.h"
|
||||
#include "base/idle.h"
|
||||
#include "base/timer.h"
|
||||
#include "base/platform.h"
|
||||
#include "base/prop_names.h"
|
||||
#include "base/window_manager.h"
|
||||
@ -62,6 +63,10 @@ static ret_t window_manager_check_if_need_open_animation(const idle_info_t* info
|
||||
if (type > WINDOW_ANIMATOR_NONE && type < WINDOW_ANIMATOR_NR) {
|
||||
wm->animator = window_animator_create_for_open(type, wm->canvas, prev_win, curr_win);
|
||||
wm->animating = wm->animator != NULL;
|
||||
if(wm->animating) {
|
||||
wm->ignore_user_input = TRUE;
|
||||
log_debug("ignore_user_input\n");
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@ -85,7 +90,10 @@ static ret_t window_manager_check_if_need_close_animation(window_manager_t* wm,
|
||||
if (type > WINDOW_ANIMATOR_NONE && type < WINDOW_ANIMATOR_NR) {
|
||||
wm->animator = window_animator_create_for_close(type, wm->canvas, prev_win, curr_win);
|
||||
wm->animating = wm->animator != NULL;
|
||||
|
||||
if(wm->animating) {
|
||||
wm->ignore_user_input = TRUE;
|
||||
log_debug("ignore_user_input\n");
|
||||
}
|
||||
return wm->animator != NULL ? RET_OK : RET_FAIL;
|
||||
}
|
||||
}
|
||||
@ -120,6 +128,7 @@ static ret_t on_window_destroy(void* ctx, event_t* e) {
|
||||
}
|
||||
|
||||
ret_t window_manager_add_child(widget_t* wm, widget_t* window) {
|
||||
ret_t ret = RET_OK;
|
||||
return_value_if_fail(wm != NULL && window != NULL, RET_BAD_PARAMS);
|
||||
|
||||
if (window->type == WIDGET_NORMAL_WINDOW) {
|
||||
@ -137,7 +146,12 @@ ret_t window_manager_add_child(widget_t* wm, widget_t* window) {
|
||||
idle_add((idle_func_t)window_manager_check_if_need_open_animation, window);
|
||||
}
|
||||
|
||||
return widget_add_child(wm, window);
|
||||
ret = widget_add_child(wm, window);
|
||||
if(ret == RET_OK) {
|
||||
wm->target = window;
|
||||
}
|
||||
|
||||
return ret;
|
||||
}
|
||||
|
||||
static ret_t window_manager_idle_destroy_window(const idle_info_t* info) {
|
||||
@ -185,7 +199,7 @@ widget_t* window_manager_find_target(widget_t* widget, xy_t x, xy_t y) {
|
||||
}
|
||||
|
||||
if (iter->type == WIDGET_NORMAL_WINDOW || iter->type == WIDGET_DIALOG) {
|
||||
break;
|
||||
return iter;
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -221,6 +235,15 @@ static ret_t window_manager_paint_normal(widget_t* widget, canvas_t* c) {
|
||||
return RET_OK;
|
||||
}
|
||||
|
||||
static ret_t timer_enable_user_input(const timer_info_t* timer) {
|
||||
window_manager_t* wm = WINDOW_MANAGER(timer->ctx);
|
||||
|
||||
wm->ignore_user_input = FALSE;
|
||||
log_debug("enable user input\n");
|
||||
|
||||
return RET_OK;
|
||||
}
|
||||
|
||||
static ret_t window_manager_paint_animation(widget_t* widget, canvas_t* c) {
|
||||
uint32_t time_ms = get_time_ms();
|
||||
window_manager_t* wm = WINDOW_MANAGER(widget);
|
||||
@ -228,8 +251,9 @@ static ret_t window_manager_paint_animation(widget_t* widget, canvas_t* c) {
|
||||
ret_t ret = window_animator_update(wm->animator, time_ms);
|
||||
if (ret == RET_DONE) {
|
||||
window_animator_destroy(wm->animator);
|
||||
wm->animating = FALSE;
|
||||
wm->animator = NULL;
|
||||
wm->animating = FALSE;
|
||||
timer_add(timer_enable_user_input, wm, 500);
|
||||
}
|
||||
|
||||
return RET_OK;
|
||||
@ -424,8 +448,8 @@ ret_t window_manager_dispatch_input_event(widget_t* widget, event_t* e) {
|
||||
window_manager_t* wm = WINDOW_MANAGER(widget);
|
||||
return_value_if_fail(wm != NULL && e != NULL, RET_BAD_PARAMS);
|
||||
|
||||
if (wm->animator) {
|
||||
log_debug("animating ignore input.\n");
|
||||
if (wm->ignore_user_input) {
|
||||
log_debug("animating ignore input\n");
|
||||
return RET_OK;
|
||||
}
|
||||
|
||||
|
@ -47,6 +47,7 @@ typedef struct _window_manager_t {
|
||||
point_t pointer;
|
||||
|
||||
bool_t animating;
|
||||
bool_t ignore_user_input;
|
||||
window_animator_t* animator;
|
||||
canvas_t* canvas;
|
||||
} window_manager_t;
|
||||
|
File diff suppressed because it is too large
Load Diff
Loading…
Reference in New Issue
Block a user