代码拉取完成,页面将自动刷新
同步操作将从 zlgopen/awtk 强制同步,此操作会覆盖自 Fork 仓库以来所做的任何修改,且无法恢复!!!
确定后同步将在后台操作,完成时将刷新页面,请耐心等待。
控件动画是一种很常见的动画,常用于入场动画、离场动画、装饰用户界面和吸引用户注意力等。
AWTK 目前支持的动画有:
示例:
widget_create_animator(image1, "opacity(to=0, duration=500, yoyo_times=1000)");
widget_pause_animator(image1, "opacity");
widget_pause_animator(NULL, NULL);
widget_start_animator(NULL, NULL);
在缺省情况下,动画创建后自动启动,完成后自动销毁。可以指定 auto_start=false 禁止创建后自动启动,指定参数 auto_destroy=false 禁止完成时自动销毁(控件销毁时仍然会自动销毁)。
动画创建、播放、暂停、停止、设置时间倍率和销毁等相关函数如下:
/**
* @method widget_create_animator
* 创建动画。
* 除非指定 auto_start=false,动画创建后自动启动。
* 除非指定 auto_destroy=false,动画播放完成后自动销毁。
* 参数的格式类似函数调用,如:
* opacity(from=0, to=255, yoyo_times=1000, duration=1000)
* move(x_from=10, x_to=100, y_from=10, y_to=100, duration=1000)
* 参考:https://github.com/zlgopen/awtk/blob/master/docs/widget_animator.md
*
* @annotation ["scriptable"]
* @param {widget_t*} widget 控件对象。
* @param {const char*} animation 动画参数。
*
* @return {ret_t} 返回 RET_OK 表示成功,否则表示失败。
*/
ret_t widget_create_animator(widget_t* widget, const char* animation);
/**
* @method widget_start_animator
* 播放动画。
* 1.widget 为 NULL 时,播放所有名称为 name 的动画。
* 2.name 为 NULL 时,播放所有 widget 相关的动画。
* 3.widget 和 name 均为 NULL,播放所有动画。
* @annotation ["scriptable"]
* @param {widget_t*} widget 控件对象。
* @param {const char*} name 动画名称。
*
* @return {ret_t} 返回 RET_OK 表示成功,否则表示失败。
*/
ret_t widget_start_animator(widget_t* widget, const char* name);
/**
* @method widget_set_animator_time_scale
* 设置动画的时间倍率,<0: 时间倒退,<1: 时间变慢,>1 时间变快。
* 1.widget 为 NULL 时,设置所有名称为 name 的动画的时间倍率。
* 2.name 为 NULL 时,设置所有 widget 相关的动画的时间倍率。
* 3.widget 和 name 均为 NULL,设置所有动画的时间倍率。
* @annotation ["scriptable"]
* @param {widget_t*} widget 控件对象。
* @param {const char*} name 动画名称。
* @param {float_t} time_scale 时间倍率。
*
* @return {ret_t} 返回 RET_OK 表示成功,否则表示失败。
*/
ret_t widget_set_animator_time_scale(widget_t* widget, const char* name, float_t time_scale);
/**
* @method widget_pause_animator
* 暂停动画。
* 1.widget 为 NULL 时,暂停所有名称为 name 的动画。
* 2.name 为 NULL 时,暂停所有 widget 相关的动画。
* 3.widget 和 name 均为 NULL,暂停所有动画。
* @annotation ["scriptable"]
* @param {widget_t*} widget 控件对象。
* @param {char*} name 动画名称。
*
* @return {ret_t} 返回 RET_OK 表示成功,否则表示失败。
*/
ret_t widget_pause_animator(widget_t* widget, const char* name);
/**
* @method widget_stop_animator
* 停止动画(控件的相应属性回归原位)。
* 1.widget 为 NULL 时,停止所有名称为 name 的动画。
* 2.name 为 NULL 时,停止所有 widget 相关的动画。
* 3.widget 和 name 均为 NULL,停止所有动画。
* @annotation ["scriptable"]
* @param {widget_t*} widget 控件对象。
* @param {char*} name 动画名称。
*
* @return {ret_t} 返回 RET_OK 表示成功,否则表示失败。
*/
ret_t widget_stop_animator(widget_t* widget, const char* name);
/**
* @method widget_destroy_animator
* 销毁动画。
* 1.widget 为 NULL 时,销毁所有名称为 name 的动画。
* 2.name 为 NULL 时,销毁所有 widget 相关的动画。
* 3.widget 和 name 均为 NULL,销毁所有动画。
* @annotation ["scriptable"]
* @param {widget_t*} widget 控件对象。
* @param {char*} name 动画名称。
*
* @return {ret_t} 返回 RET_OK 表示成功,否则表示失败。
*/
ret_t widget_destroy_animator(widget_t* widget, const char* name);
animation 参数的格式,类似与函数调用。多个参数可以用『;』分隔。如:
<button name="inc_value" text="Inc" animation="opacity(from=0, to=255, yoyo_times=1000, duration=1000)"/>
<button name="dec_value" text="Dec" animation="move(x_from=10, x_to=100, y_from=10, y_to=100, duration=1000);opacity(from=0, to=255, yoyo_times=1000, duration=1000)"/>
此方法最为简单,后续可以在程序中通过动画名字,对动画进行启动和暂停等控制。
使用控件动画时,一般需要创建动画、设置参数、设置模式和启动动画四个步骤。如:
animator = widget_animator_move_create(image, 1000, delay, EASING_SIN_INOUT);
widget_animator_move_set_params(animator, image->x, image->y, image->x + 100, image->y + 100);
widget_animator_set_yoyo(animator, 10);
widget_animator_start(animator);
此方法比较麻烦,不再推荐使用。
以下参数的缺省值为控件当前对应的值。
请参考:插值算法名称
完整示例请参考:demos/demo_animator_app.c
运行下列命令查看各种动画的效果:
./bin/demo_animator
动画对象一般不需主动销毁,在动画结束或控件被销毁时自动销毁。
如使用控件的入场动画,一般不要启用窗口动画。
此处可能存在不合适展示的内容,页面不予展示。您可通过相关编辑功能自查并修改。
如您确认内容无涉及 不当用语 / 纯广告导流 / 暴力 / 低俗色情 / 侵权 / 盗版 / 虚假 / 无价值内容或违法国家有关法律法规的内容,可点击提交进行申诉,我们将尽快为您处理。