support any number property animation.

This commit is contained in:
xianjimli 2018-12-12 09:21:13 +08:00
parent 70e20c88c1
commit e2a1d4a921
20 changed files with 480 additions and 735 deletions

View File

@ -143,7 +143,7 @@ ret_t application_init() {
widget_create_animator(image4,
"scale(x_to=2, y_to=2, yoyo_times=1000, duration=1000, easing=sin_out)");
widget_create_animator(image5, "move(y_to=400, duration=1000, easing=sin_out)");
widget_create_animator(image5, "y(to=400, duration=1000, easing=sin_out)");
widget_create_animator(image5, "opacity(to=0, duration=500, yoyo_times=1000, delay=1000)");
widget_on(start, EVT_CLICK, on_start, NULL);

View File

@ -1,5 +1,8 @@
# 最新动态
* 2018/12/12
* 支持任何数值型属性的动画。如x/y/w/h等等。
* 2018/12/11
* gradiant支持alpha渐变。
* 完善slide menu控件增加测试和demo。

View File

@ -11,6 +11,7 @@ AWTK目前支持的动画有
* opacity通过改变控件的透明度形成动画效果。
* scale通过改变控件的缩放比例形成动画效果(目前需要vgcanvas)。
* rotation通过改变控件的旋转角度形成动画效果(目前需要vgcanvas)。
* 其它任何数值型的属性。如x/y/w/h等等。
### 二、主要特色
@ -214,6 +215,10 @@ animation参数的格式类似与函数调用。多个参数可以用『;』
* from 起始值(弧度)。
* to 结束值(弧度)。
#### 7. 其它数值型属性动画的参数
* from 起始值。
* to 结束值。
### 五、插值算法名称(easing)
* linear
@ -254,7 +259,7 @@ animation参数的格式类似与函数调用。多个参数可以用『;』
```
### 五、其它
> 1.动画对象一般不需主动销毁,在动画结束或控件被销毁时自动销毁。
>
> 2.如使用控件的入场动画,一般不要启用窗口动画。
1.动画对象一般不需主动销毁,在动画结束或控件被销毁时自动销毁。
2.如使用控件的入场动画,一般不要启用窗口动画。

View File

@ -1,5 +1,5 @@
/**
* File: widget_animator_factory.h
* File: widget_animator_factory.c
* Author: AWTK Develop Team
* Brief: widget animator factory
*
@ -26,11 +26,9 @@
#ifndef WITHOUT_WIDGET_ANIMATOR
#include "widget_animators/widget_animator_prop.h"
#include "widget_animators/widget_animator_move.h"
#include "widget_animators/widget_animator_scale.h"
#include "widget_animators/widget_animator_value.h"
#include "widget_animators/widget_animator_opacity.h"
#include "widget_animators/widget_animator_rotation.h"
typedef struct _move_params_t {
xy_t x_to;
@ -46,20 +44,10 @@ typedef struct _scale_params_t {
float_t y_from;
} scale_params_t;
typedef struct _value_params_t {
int32_t to;
int32_t from;
} value_params_t;
typedef struct _opacity_params_t {
uint8_t to;
uint8_t from;
} opacity_params_t;
typedef struct _rotation_params_t {
typedef struct _prop_params_t {
float_t to;
float_t from;
} rotation_params_t;
} prop_params_t;
typedef struct _animator_params_t {
char type[NAME_LEN + 1];
@ -69,9 +57,7 @@ typedef struct _animator_params_t {
union {
move_params_t move;
scale_params_t scale;
value_params_t value;
opacity_params_t opacity;
rotation_params_t rotation;
prop_params_t prop;
} u;
uint32_t delay;
@ -96,154 +82,91 @@ static ret_t parser_on_name(func_call_parser_t* parser, const char* func_name) {
value_t v;
widget_animator_parser_t* p = (widget_animator_parser_t*)parser;
widget_t* widget = p->params.widget;
const char* type = p->params.type;
tk_strncpy(p->params.type, func_name, NAME_LEN);
switch (p->params.type[0]) {
case 'm': /*move*/
{
move_params_t* params = &p->params.u.move;
if (tk_str_eq(type, "move")) {
move_params_t* params = &p->params.u.move;
params->x_from = widget->x;
params->y_from = widget->y;
params->x_to = widget->x;
params->y_to = widget->y;
break;
params->x_from = widget->x;
params->y_from = widget->y;
params->x_to = widget->x;
params->y_to = widget->y;
} else if (tk_str_eq(type, "scale")) {
float_t scale_x = 1.0f;
float_t scale_y = 1.0f;
scale_params_t* params = &p->params.u.scale;
if (widget_get_prop(widget, WIDGET_PROP_SCALE_X, &v) == RET_OK) {
scale_x = value_float(&v);
}
case 's': /*scale*/
{
float_t scale_x = 1.0f;
float_t scale_y = 1.0f;
scale_params_t* params = &p->params.u.scale;
if (widget_get_prop(widget, WIDGET_PROP_SCALE_X, &v) == RET_OK) {
scale_x = value_float(&v);
}
if (widget_get_prop(widget, WIDGET_PROP_SCALE_Y, &v) == RET_OK) {
scale_y = value_float(&v);
}
params->x_from = scale_x;
params->y_from = scale_y;
params->x_to = scale_x;
params->y_to = scale_y;
break;
if (widget_get_prop(widget, WIDGET_PROP_SCALE_Y, &v) == RET_OK) {
scale_y = value_float(&v);
}
case 'r': /*rotation*/
{
float_t value = 0;
rotation_params_t* params = &p->params.u.rotation;
if (widget_get_prop(widget, WIDGET_PROP_ROTATION, &v) == RET_OK) {
value = value_float(&v);
}
params->x_from = scale_x;
params->y_from = scale_y;
params->x_to = scale_x;
params->y_to = scale_y;
} else {
float_t value = 0;
const char* prop_name = p->params.type;
prop_params_t* params = &p->params.u.prop;
params->from = value;
params->to = value;
break;
if (widget_get_prop(widget, prop_name, &v) == RET_OK) {
value = value_float(&v);
}
case 'v': /*value*/
{
int32_t value = widget_get_value(widget);
value_params_t* params = &p->params.u.value;
params->from = value;
params->to = value;
break;
}
case 'o': /*opacity*/
{
int32_t value = widget->opacity;
opacity_params_t* params = &p->params.u.opacity;
params->from = value;
params->to = value;
break;
}
default:
break;
params->from = value;
params->to = value;
}
return RET_OK;
}
static ret_t parser_on_param(func_call_parser_t* parser, const char* name, const char* value) {
widget_animator_parser_t* p = (widget_animator_parser_t*)parser;
const char* type = p->params.type;
switch (p->params.type[0]) {
case 'm': /*move*/
{
move_params_t* move = &p->params.u.move;
if (tk_str_eq(name, "x_from")) {
move->x_from = tk_atoi(value);
return RET_OK;
} else if (tk_str_eq(name, "y_from")) {
move->y_from = tk_atoi(value);
return RET_OK;
} else if (tk_str_eq(name, "x_to")) {
move->x_to = tk_atoi(value);
return RET_OK;
} else if (tk_str_eq(name, "y_to")) {
move->y_to = tk_atoi(value);
return RET_OK;
}
break;
if (tk_str_eq(type, "move")) {
move_params_t* move = &p->params.u.move;
if (tk_str_eq(name, "x_from")) {
move->x_from = tk_atoi(value);
return RET_OK;
} else if (tk_str_eq(name, "y_from")) {
move->y_from = tk_atoi(value);
return RET_OK;
} else if (tk_str_eq(name, "x_to")) {
move->x_to = tk_atoi(value);
return RET_OK;
} else if (tk_str_eq(name, "y_to")) {
move->y_to = tk_atoi(value);
return RET_OK;
}
case 's': /*scale*/
{
scale_params_t* scale = &p->params.u.scale;
if (tk_str_eq(name, "x_from")) {
scale->x_from = tk_atof(value);
return RET_OK;
} else if (tk_str_eq(name, "y_from")) {
scale->y_from = tk_atof(value);
return RET_OK;
} else if (tk_str_eq(name, "x_to")) {
scale->x_to = tk_atof(value);
return RET_OK;
} else if (tk_str_eq(name, "y_to")) {
scale->y_to = tk_atof(value);
return RET_OK;
}
break;
} else if (tk_str_eq(type, "scale")) {
scale_params_t* scale = &p->params.u.scale;
if (tk_str_eq(name, "x_from")) {
scale->x_from = tk_atof(value);
return RET_OK;
} else if (tk_str_eq(name, "y_from")) {
scale->y_from = tk_atof(value);
return RET_OK;
} else if (tk_str_eq(name, "x_to")) {
scale->x_to = tk_atof(value);
return RET_OK;
} else if (tk_str_eq(name, "y_to")) {
scale->y_to = tk_atof(value);
return RET_OK;
}
case 'r': /*rotation*/
{
rotation_params_t* rotation = &p->params.u.rotation;
if (tk_str_eq(name, "from")) {
rotation->from = tk_atof(value);
return RET_OK;
} else if (tk_str_eq(name, "to")) {
rotation->to = tk_atof(value);
return RET_OK;
}
break;
} else {
prop_params_t* v = &p->params.u.prop;
if (tk_str_eq(name, "from")) {
v->from = tk_atof(value);
return RET_OK;
} else if (tk_str_eq(name, "to")) {
v->to = tk_atof(value);
return RET_OK;
}
case 'v': /*value*/
{
value_params_t* v = &p->params.u.value;
if (tk_str_eq(name, "from")) {
v->from = tk_atoi(value);
return RET_OK;
} else if (tk_str_eq(name, "to")) {
v->to = tk_atoi(value);
return RET_OK;
}
break;
}
case 'o': /*opacity*/
{
opacity_params_t* opacity = &p->params.u.opacity;
if (tk_str_eq(name, "from")) {
opacity->from = tk_atoi(value);
return RET_OK;
} else if (tk_str_eq(name, "to")) {
opacity->to = tk_atoi(value);
return RET_OK;
}
break;
}
default:
break;
}
switch (name[0]) {
@ -323,6 +246,7 @@ widget_animator_t* widget_animator_create(widget_t* widget, const char* params)
uint32_t delay = 0;
uint32_t easing = 0;
uint32_t duration = 0;
const char* type = NULL;
widget_animator_t* wa = NULL;
widget_animator_parser_t parser;
return_value_if_fail(params != NULL && widget != NULL, NULL);
@ -333,55 +257,28 @@ widget_animator_t* widget_animator_create(widget_t* widget, const char* params)
easing = parser.params.easing;
duration = parser.params.duration;
switch (parser.params.type[0]) {
case 'm': /*move*/
{
move_params_t* move = &parser.params.u.move;
wa = widget_animator_move_create(widget, duration, delay, (easing_type_t)easing);
type = parser.params.type;
if (tk_str_eq(type, "move")) {
move_params_t* move = &parser.params.u.move;
wa = widget_animator_move_create(widget, duration, delay, (easing_type_t)easing);
return_value_if_fail(wa != NULL, NULL);
widget_animator_move_set_params(wa, move->x_from, move->y_from, move->x_to, move->y_to);
break;
}
case 's': /*scale*/
{
scale_params_t* scale = &parser.params.u.scale;
wa = widget_animator_scale_create(widget, duration, delay, (easing_type_t)easing);
return_value_if_fail(wa != NULL, NULL);
widget_animator_move_set_params(wa, move->x_from, move->y_from, move->x_to, move->y_to);
} else if (tk_str_eq(type, "scale")) {
scale_params_t* scale = &parser.params.u.scale;
wa = widget_animator_scale_create(widget, duration, delay, (easing_type_t)easing);
return_value_if_fail(wa != NULL, NULL);
widget_animator_scale_set_params(wa, scale->x_from, scale->y_from, scale->x_to, scale->y_to);
break;
}
case 'r': /*rotation*/
{
rotation_params_t* rotation = &parser.params.u.rotation;
wa = widget_animator_rotation_create(widget, duration, delay, (easing_type_t)easing);
return_value_if_fail(wa != NULL, NULL);
widget_animator_scale_set_params(wa, scale->x_from, scale->y_from, scale->x_to, scale->y_to);
} else {
const char* prop_name = parser.params.type;
prop_params_t* param = &parser.params.u.prop;
return_value_if_fail(wa != NULL, NULL);
widget_animator_rotation_set_params(wa, rotation->from, rotation->to);
break;
}
case 'v': /*value*/
{
value_params_t* value = &parser.params.u.value;
wa = widget_animator_value_create(widget, duration, delay, (easing_type_t)easing);
return_value_if_fail(wa != NULL, NULL);
widget_animator_value_set_params(wa, value->from, value->to);
break;
}
case 'o': /*opacity*/
{
opacity_params_t* opacity = &parser.params.u.opacity;
wa = widget_animator_opacity_create(widget, duration, delay, (easing_type_t)easing);
return_value_if_fail(wa != NULL, NULL);
widget_animator_opacity_set_params(wa, opacity->from, opacity->to);
break;
}
default:
break;
wa = widget_animator_prop_create(widget, duration, delay, (easing_type_t)easing, prop_name);
return_value_if_fail(wa != NULL, NULL);
widget_animator_prop_set_params(wa, param->from, param->to);
}
func_call_parser_deinit(&(parser.base));
if (wa != NULL) {

View File

@ -1,61 +0,0 @@
/**
* File: widget_animator_move.h
* Author: AWTK Develop Team
* Brief: animate widget by change its position.
*
* Copyright (c) 2018 - 2018 Guangzhou ZHIYUAN Electronics Co.,Ltd.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* License file for more details.
*
*/
/**
* History:
* ================================================================
* 2018-05-15 Li XianJing <xianjimli@hotmail.com> created
*
*/
#include "base/mem.h"
#include "widget_animators/widget_animator_move.h"
static ret_t widget_animator_move_update(widget_animator_t* animator, float_t percent) {
widget_animator_move_t* move = (widget_animator_move_t*)animator;
return_value_if_fail(move != NULL, RET_BAD_PARAMS);
widget_invalidate_force(animator->widget, NULL);
animator->widget->x = move->x_from + (move->x_to - move->x_from) * percent;
animator->widget->y = move->y_from + (move->y_to - move->y_from) * percent;
widget_invalidate_force(animator->widget, NULL);
return RET_OK;
}
widget_animator_t* widget_animator_move_create(widget_t* widget, uint32_t duration, uint32_t delay,
easing_type_t easing) {
widget_animator_t* animator = NULL;
return_value_if_fail(widget != NULL && duration > 0, NULL);
animator = (widget_animator_t*)TKMEM_ZALLOC(widget_animator_move_t);
return_value_if_fail(
widget_animator_init(animator, widget, duration, delay, easing_get(easing)) == RET_OK, NULL);
animator->update = widget_animator_move_update;
return animator;
}
ret_t widget_animator_move_set_params(widget_animator_t* animator, xy_t x_from, xy_t y_from,
xy_t x_to, xy_t y_to) {
widget_animator_move_t* move = (widget_animator_move_t*)animator;
return_value_if_fail(move != NULL, RET_BAD_PARAMS);
move->x_to = x_to;
move->y_to = y_to;
move->x_from = x_from;
move->y_from = y_from;
return RET_OK;
}

View File

@ -1,7 +1,7 @@
/**
* File: widget_animator_move.h
* Author: AWTK Develop Team
* Brief: animate widget by change its position.
* Brief: animate widget by change its x/y(just wrap widget_animator_prop2)
*
* Copyright (c) 2018 - 2018 Guangzhou ZHIYUAN Electronics Co.,Ltd.
*
@ -15,56 +15,21 @@
/**
* History:
* ================================================================
* 2018-05-15 Li XianJing <xianjimli@hotmail.com> created
* 2018-05-16 Li XianJing <xianjimli@hotmail.com> created
*
*/
#ifndef TK_WIDGET_ANIMATOR_MOVE_H
#define TK_WIDGET_ANIMATOR_MOVE_H
#include "base/widget_animator.h"
#include "widget_animators/widget_animator_prop2.h"
BEGIN_C_DECLS
/**
* @class widget_animator_move_t
*
*/
typedef struct _widget_animator_move_t {
widget_animator_t base;
#define widget_animator_move_create(widget, duration, delay, easing) \
widget_animator_prop2_create(widget, duration, delay, easing, WIDGET_PROP_X, WIDGET_PROP_Y)
xy_t x_to;
xy_t y_to;
xy_t x_from;
xy_t y_from;
} widget_animator_move_t;
/**
* @method widget_animator_move_create
*
* @param {widget_t*} widget
* @param {uint32_t} duration
* @param {uint32_t} delay
* @param {easing_type_t} easing
*
* @return {widget_animator_t*} NULL
*/
widget_animator_t* widget_animator_move_create(widget_t* widget, uint32_t duration, uint32_t delay,
easing_type_t easing);
/**
* @method widget_animator_move_set_params
*
* @param {widget_animator_t*} animator
* @param {xy_t} x_from x起点值
* @param {xy_t} y_from y起点值
* @param {xy_t} x_to x终点值
* @param {xy_t} y_to y终点值
*
* @return {ret_t} RET_OK表示成功
*/
ret_t widget_animator_move_set_params(widget_animator_t* animator, xy_t x_from, xy_t y_from,
xy_t x_to, xy_t y_to);
#define widget_animator_move_set_params widget_animator_prop2_set_params
END_C_DECLS

View File

@ -1,57 +0,0 @@
/**
* File: widget_animator_opacity.h
* Author: AWTK Develop Team
* Brief: animate widget by change its opacity
*
* Copyright (c) 2018 - 2018 Guangzhou ZHIYUAN Electronics Co.,Ltd.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* License file for more details.
*
*/
/**
* History:
* ================================================================
* 2018-05-30 Li XianJing <xianjimli@hotmail.com> created
*
*/
#include "base/mem.h"
#include "widget_animators/widget_animator_opacity.h"
static ret_t widget_animator_opacity_update(widget_animator_t* animator, float_t percent) {
uint8_t new_opacity = 0;
widget_animator_opacity_t* opacity = (widget_animator_opacity_t*)animator;
return_value_if_fail(opacity != NULL, RET_BAD_PARAMS);
new_opacity = opacity->from + (opacity->to - opacity->from) * percent;
widget_set_opacity(animator->widget, new_opacity);
return RET_OK;
}
widget_animator_t* widget_animator_opacity_create(widget_t* widget, uint32_t duration,
uint32_t delay, easing_type_t easing) {
widget_animator_t* animator = NULL;
return_value_if_fail(widget != NULL && duration > 0, NULL);
animator = (widget_animator_t*)TKMEM_ZALLOC(widget_animator_opacity_t);
return_value_if_fail(
widget_animator_init(animator, widget, duration, delay, easing_get(easing)) == RET_OK, NULL);
animator->update = widget_animator_opacity_update;
return animator;
}
ret_t widget_animator_opacity_set_params(widget_animator_t* animator, uint8_t from, uint8_t to) {
widget_animator_opacity_t* opacity = (widget_animator_opacity_t*)animator;
return_value_if_fail(opacity != NULL, RET_BAD_PARAMS);
opacity->to = to;
opacity->from = from;
return RET_OK;
}

View File

@ -1,7 +1,7 @@
/**
* File: widget_animator_opacity.h
* Author: AWTK Develop Team
* Brief: animate widget by change its opacity
* Brief: animate widget by change its opacity(just wrap widget_animator_prop)
*
* Copyright (c) 2018 - 2018 Guangzhou ZHIYUAN Electronics Co.,Ltd.
*
@ -15,51 +15,21 @@
/**
* History:
* ================================================================
* 2018-05-30 Li XianJing <xianjimli@hotmail.com> created
* 2018-05-16 Li XianJing <xianjimli@hotmail.com> created
*
*/
#ifndef TK_WIDGET_ANIMATOR_OPACITY_H
#define TK_WIDGET_ANIMATOR_OPACITY_H
#include "base/widget_animator.h"
#include "widget_animators/widget_animator_prop.h"
BEGIN_C_DECLS
/**
* @class widget_animator_opacity_t
*
*/
typedef struct _widget_animator_opacity_t {
widget_animator_t base;
#define widget_animator_opacity_create(widget, duration, delay, easing) \
widget_animator_prop_create(widget, duration, delay, easing, WIDGET_PROP_OPACITY)
uint8_t to;
uint8_t from;
} widget_animator_opacity_t;
/**
* @method widget_animator_opacity_create
*
* @param {widget_t*} widget
* @param {uint32_t} duration
* @param {uint32_t} delay
* @param {easing_type_t} easing
*
* @return {widget_animator_t*} NULL
*/
widget_animator_t* widget_animator_opacity_create(widget_t* widget, uint32_t duration,
uint32_t delay, easing_type_t easing);
/**
* @method widget_animator_opacity_set_params
*
* @param {widget_animator_t*} animator
* @param {uint8_t} from opacity起始值
* @param {uint8_t} to opacity结束值
*
* @return {ret_t} RET_OK表示成功
*/
ret_t widget_animator_opacity_set_params(widget_animator_t* animator, uint8_t from, uint8_t to);
#define widget_animator_opacity_set_params widget_animator_prop_set_params
END_C_DECLS

View File

@ -0,0 +1,65 @@
/**
* File: widget_animator_prop.c
* Author: AWTK Develop Team
* Brief: animate widget by change its prop
*
* Copyright (c) 2018 - 2018 Guangzhou ZHIYUAN Electronics Co.,Ltd.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* License file for more details.
*
*/
/**
* History:
* ================================================================
* 2018-12-11 Li XianJing <xianjimli@hotmail.com> created
*
*/
#include "base/mem.h"
#include "base/utils.h"
#include "widget_animators/widget_animator_prop.h"
static ret_t widget_animator_prop_update(widget_animator_t* animator, float_t percent) {
value_t v;
float_t new_prop = 0;
widget_animator_prop_t* prop = (widget_animator_prop_t*)animator;
return_value_if_fail(prop != NULL, RET_BAD_PARAMS);
new_prop = prop->from + (prop->to - prop->from) * percent;
widget_set_prop(animator->widget, prop->prop_name, value_set_float(&v, new_prop));
return RET_OK;
}
widget_animator_t* widget_animator_prop_create(widget_t* widget, uint32_t duration, uint32_t delay,
easing_type_t easing, const char* prop_name) {
widget_animator_t* animator = NULL;
widget_animator_prop_t* prop = NULL;
return_value_if_fail(widget != NULL && duration > 0 && prop_name != NULL, NULL);
animator = (widget_animator_t*)TKMEM_ZALLOC(widget_animator_prop_t);
return_value_if_fail(animator != NULL, NULL);
return_value_if_fail(
widget_animator_init(animator, widget, duration, delay, easing_get(easing)) == RET_OK, NULL);
prop = (widget_animator_t*)animator;
animator->update = widget_animator_prop_update;
tk_strncpy(prop->prop_name, prop_name, NAME_LEN);
return animator;
}
ret_t widget_animator_prop_set_params(widget_animator_t* animator, float_t from, float_t to) {
widget_animator_prop_t* prop = (widget_animator_prop_t*)animator;
return_value_if_fail(prop != NULL, RET_BAD_PARAMS);
prop->to = to;
prop->from = from;
return RET_OK;
}

View File

@ -0,0 +1,68 @@
/**
* File: widget_animator_prop.h
* Author: AWTK Develop Team
* Brief: animate widget by change its prop
*
* Copyright (c) 2018 - 2018 Guangzhou ZHIYUAN Electronics Co.,Ltd.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* License file for more details.
*
*/
/**
* History:
* ================================================================
* 2018-12-11 Li XianJing <xianjimli@hotmail.com> created
*
*/
#ifndef TK_WIDGET_ANIMATOR_PROP_H
#define TK_WIDGET_ANIMATOR_PROP_H
#include "base/widget_animator.h"
BEGIN_C_DECLS
/**
* @class widget_animator_prop_t
*
*/
typedef struct _widget_animator_prop_t {
widget_animator_t base;
float_t to;
float_t from;
char prop_name[NAME_LEN + 1];
} widget_animator_prop_t;
/**
* @method widget_animator_prop_create
*
* @param {widget_t*} widget
* @param {uint32_t} duration
* @param {uint32_t} delay
* @param {easing_type_t} easing
* @param {const char*} prop_name
*
* @return {widget_animator_t*} NULL
*/
widget_animator_t* widget_animator_prop_create(widget_t* widget, uint32_t duration, uint32_t delay,
easing_type_t easing, const char* prop_name);
/**
* @method widget_animator_prop_set_params
*
* @param {widget_animator_t*} animator
* @param {float_t} from prop起始值
* @param {float_t} to prop结束值
*
* @return {ret_t} RET_OK表示成功
*/
ret_t widget_animator_prop_set_params(widget_animator_t* animator, float_t from, float_t to);
END_C_DECLS
#endif /*TK_WIDGET_ANIMATOR_PROP_H*/

View File

@ -0,0 +1,77 @@
/**
* File: widget_animator_prop2.h
* Author: AWTK Develop Team
* Brief: animate widget by change its 2 props.
*
* Copyright (c) 2018 - 2018 Guangzhou ZHIYUAN Electronics Co.,Ltd.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* License file for more details.
*
*/
/**
* History:
* ================================================================
* 2018-12-11 Li XianJing <xianjimli@hotmail.com> created
*
*/
#include "base/mem.h"
#include "base/utils.h"
#include "widget_animators/widget_animator_prop2.h"
static ret_t widget_animator_prop2_update(widget_animator_t* animator, float_t percent) {
value_t v;
widget_animator_prop2_t* prop2 = (widget_animator_prop2_t*)animator;
return_value_if_fail(prop2 != NULL, RET_BAD_PARAMS);
if (prop2->to1 != prop2->from1) {
value_set_float(&v, prop2->from1 + (prop2->to1 - prop2->from1) * percent);
widget_set_prop(animator->widget, prop2->prop1_name, &v);
}
if (prop2->to2 != prop2->from2) {
value_set_float(&v, prop2->from2 + (prop2->to2 - prop2->from2) * percent);
widget_set_prop(animator->widget, prop2->prop2_name, &v);
}
return RET_OK;
}
widget_animator_t* widget_animator_prop2_create(widget_t* widget, uint32_t duration, uint32_t delay,
easing_type_t easing, const char* prop1_name,
const char* prop2_name) {
widget_animator_t* animator = NULL;
widget_animator_prop2_t* prop2 = NULL;
return_value_if_fail(widget != NULL && duration > 0 && prop1_name != NULL && prop2_name != NULL,
NULL);
animator = (widget_animator_t*)TKMEM_ZALLOC(widget_animator_prop2_t);
return_value_if_fail(animator != NULL, NULL);
return_value_if_fail(
widget_animator_init(animator, widget, duration, delay, easing_get(easing)) == RET_OK, NULL);
prop2 = (widget_animator_prop2_t*)animator;
animator->update = widget_animator_prop2_update;
tk_strncpy(prop2->prop1_name, prop1_name, NAME_LEN);
tk_strncpy(prop2->prop2_name, prop2_name, NAME_LEN);
return animator;
}
ret_t widget_animator_prop2_set_params(widget_animator_t* animator, float_t from1, float_t from2,
float_t to1, float_t to2) {
widget_animator_prop2_t* prop2 = (widget_animator_prop2_t*)animator;
return_value_if_fail(prop2 != NULL, RET_BAD_PARAMS);
prop2->to1 = to1;
prop2->to2 = to2;
prop2->from1 = from1;
prop2->from2 = from2;
return RET_OK;
}

View File

@ -0,0 +1,76 @@
/**
* File: widget_animator_prop2.h
* Author: AWTK Develop Team
* Brief: animate widget by change its 2 props.
*
* Copyright (c) 2018 - 2018 Guangzhou ZHIYUAN Electronics Co.,Ltd.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* License file for more details.
*
*/
/**
* History:
* ================================================================
* 2018-12-11 Li XianJing <xianjimli@hotmail.com> created
*
*/
#ifndef TK_WIDGET_ANIMATOR_PROP2_H
#define TK_WIDGET_ANIMATOR_PROP2_H
#include "base/widget_animator.h"
BEGIN_C_DECLS
/**
* @class widget_animator_prop2_t
*
*/
typedef struct _widget_animator_prop2_t {
widget_animator_t base;
float_t to1;
float_t to2;
float_t from1;
float_t from2;
char prop1_name[NAME_LEN + 1];
char prop2_name[NAME_LEN + 1];
} widget_animator_prop2_t;
/**
* @method widget_animator_prop2_create
*
* @param {widget_t*} widget
* @param {uint32_t} duration
* @param {uint32_t} delay
* @param {easing_type_t} easing
* @param {const char*} prop1_name 1
* @param {const char*} prop2_name 2
*
* @return {widget_animator_t*} NULL
*/
widget_animator_t* widget_animator_prop2_create(widget_t* widget, uint32_t duration, uint32_t delay,
easing_type_t easing, const char* prop1_name,
const char* prop2_name);
/**
* @method widget_animator_prop2_set_params
*
* @param {widget_animator_t*} animator
* @param {float_t} from1 x的初值
* @param {float_t} from2 y的初值
* @param {float_t} to1 x的终值
* @param {float_t} to2 y的终值
*
* @return {ret_t} RET_OK表示成功
*/
ret_t widget_animator_prop2_set_params(widget_animator_t* animator, float_t from1, float_t from2,
float_t to1, float_t to2);
END_C_DECLS
#endif /*TK_WIDGET_ANIMATOR_PROP2_H*/

View File

@ -1,60 +0,0 @@
/**
* File: widget_animator_rotation.h
* Author: AWTK Develop Team
* Brief: animate widget by change its rotation
*
* Copyright (c) 2018 - 2018 Guangzhou ZHIYUAN Electronics Co.,Ltd.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* License file for more details.
*
*/
/**
* History:
* ================================================================
* 2018-05-31 Li XianJing <xianjimli@hotmail.com> created
*
*/
#include "base/mem.h"
#include "widget_animators/widget_animator_rotation.h"
static ret_t widget_animator_rotation_update(widget_animator_t* animator, float_t percent) {
value_t v;
float_t new_rotation = 0;
widget_animator_rotation_t* rotation = (widget_animator_rotation_t*)animator;
return_value_if_fail(rotation != NULL, RET_BAD_PARAMS);
new_rotation = rotation->from + (rotation->to - rotation->from) * percent;
value_set_float(&v, new_rotation);
widget_set_prop(animator->widget, WIDGET_PROP_ROTATION, &v);
return RET_OK;
}
widget_animator_t* widget_animator_rotation_create(widget_t* widget, uint32_t duration,
uint32_t delay, easing_type_t easing) {
widget_animator_t* animator = NULL;
return_value_if_fail(widget != NULL && duration > 0, NULL);
animator = (widget_animator_t*)TKMEM_ZALLOC(widget_animator_rotation_t);
return_value_if_fail(
widget_animator_init(animator, widget, duration, delay, easing_get(easing)) == RET_OK, NULL);
animator->update = widget_animator_rotation_update;
return animator;
}
ret_t widget_animator_rotation_set_params(widget_animator_t* animator, float_t from, float_t to) {
widget_animator_rotation_t* rotation = (widget_animator_rotation_t*)animator;
return_value_if_fail(rotation != NULL, RET_BAD_PARAMS);
rotation->to = to;
rotation->from = from;
return RET_OK;
}

View File

@ -1,7 +1,7 @@
/**
* File: widget_animator_rotation.h
* Author: AWTK Develop Team
* Brief: animate widget by change its rotation
* Brief: animate widget by change its rotation(just wrap widget_animator_prop)
*
* Copyright (c) 2018 - 2018 Guangzhou ZHIYUAN Electronics Co.,Ltd.
*
@ -15,51 +15,21 @@
/**
* History:
* ================================================================
* 2018-05-31 Li XianJing <xianjimli@hotmail.com> created
* 2018-05-16 Li XianJing <xianjimli@hotmail.com> created
*
*/
#ifndef TK_WIDGET_ANIMATOR_ROTATION_H
#define TK_WIDGET_ANIMATOR_ROTATION_H
#include "base/widget_animator.h"
#include "widget_animators/widget_animator_prop.h"
BEGIN_C_DECLS
/**
* @class widget_animator_rotation_t
*
*/
typedef struct _widget_animator_rotation_t {
widget_animator_t base;
#define widget_animator_rotation_create(widget, duration, delay, easing) \
widget_animator_prop_create(widget, duration, delay, easing, WIDGET_PROP_ROTATION)
float_t to;
float_t from;
} widget_animator_rotation_t;
/**
* @method widget_animator_value_create
*
* @param {widget_t*} widget
* @param {uint32_t} duration
* @param {uint32_t} delay
* @param {easing_type_t} easing
*
* @return {widget_animator_t*} NULL
*/
widget_animator_t* widget_animator_rotation_create(widget_t* widget, uint32_t duration,
uint32_t delay, easing_type_t easing);
/**
* @method widget_animator_rotation_set_params
*
* @param {widget_animator_t*} animator
* @param {float_t} from rotation起始值()
* @param {float_t} to rotation结束值()
*
* @return {ret_t} RET_OK表示成功
*/
ret_t widget_animator_rotation_set_params(widget_animator_t* animator, float_t from, float_t to);
#define widget_animator_rotation_set_params widget_animator_prop_set_params
END_C_DECLS

View File

@ -1,70 +0,0 @@
/**
* File: widget_animator_scale.h
* Author: AWTK Develop Team
* Brief: animate widget by change its position.
*
* Copyright (c) 2018 - 2018 Guangzhou ZHIYUAN Electronics Co.,Ltd.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* License file for more details.
*
*/
/**
* History:
* ================================================================
* 2018-05-31 Li XianJing <xianjimli@hotmail.com> created
*
*/
#include "base/mem.h"
#include "widget_animators/widget_animator_scale.h"
static ret_t widget_animator_scale_update(widget_animator_t* animator, float_t percent) {
value_t v;
float_t scale_x = 0;
float_t scale_y = 0;
widget_animator_scale_t* scale = (widget_animator_scale_t*)animator;
return_value_if_fail(scale != NULL, RET_BAD_PARAMS);
scale_x = scale->x_from + (scale->x_to - scale->x_from) * percent;
scale_y = scale->y_from + (scale->y_to - scale->y_from) * percent;
widget_invalidate_force(animator->widget, NULL);
value_set_float(&v, scale_x);
widget_set_prop(animator->widget, WIDGET_PROP_SCALE_X, &v);
value_set_float(&v, scale_y);
widget_set_prop(animator->widget, WIDGET_PROP_SCALE_Y, &v);
widget_invalidate_force(animator->widget, NULL);
return RET_OK;
}
widget_animator_t* widget_animator_scale_create(widget_t* widget, uint32_t duration, uint32_t delay,
easing_type_t easing) {
widget_animator_t* animator = NULL;
return_value_if_fail(widget != NULL && duration > 0, NULL);
animator = (widget_animator_t*)TKMEM_ZALLOC(widget_animator_scale_t);
return_value_if_fail(
widget_animator_init(animator, widget, duration, delay, easing_get(easing)) == RET_OK, NULL);
animator->update = widget_animator_scale_update;
return animator;
}
ret_t widget_animator_scale_set_params(widget_animator_t* animator, float_t x_from, float_t y_from,
float_t x_to, float_t y_to) {
widget_animator_scale_t* scale = (widget_animator_scale_t*)animator;
return_value_if_fail(scale != NULL, RET_BAD_PARAMS);
scale->x_to = x_to;
scale->y_to = y_to;
scale->x_from = x_from;
scale->y_from = y_from;
return RET_OK;
}

View File

@ -1,7 +1,7 @@
/**
* File: widget_animator_scale.h
* Author: AWTK Develop Team
* Brief: animate widget by change its scale.
* Brief: animate widget by change its scale(just wrap widget_animator_prop2)
*
* Copyright (c) 2018 - 2018 Guangzhou ZHIYUAN Electronics Co.,Ltd.
*
@ -15,56 +15,22 @@
/**
* History:
* ================================================================
* 2018-05-31 Li XianJing <xianjimli@hotmail.com> created
* 2018-05-16 Li XianJing <xianjimli@hotmail.com> created
*
*/
#ifndef TK_WIDGET_ANIMATOR_SCALE_H
#define TK_WIDGET_ANIMATOR_SCALE_H
#include "base/widget_animator.h"
#include "widget_animators/widget_animator_prop2.h"
BEGIN_C_DECLS
/**
* @class widget_animator_scale_t
*
*/
typedef struct _widget_animator_scale_t {
widget_animator_t base;
#define widget_animator_scale_create(widget, duration, delay, easing) \
widget_animator_prop2_create(widget, duration, delay, easing, WIDGET_PROP_SCALE_X, \
WIDGET_PROP_SCALE_Y)
float_t x_to;
float_t y_to;
float_t x_from;
float_t y_from;
} widget_animator_scale_t;
/**
* @method widget_animator_scale_create
*
* @param {widget_t*} widget
* @param {uint32_t} duration
* @param {uint32_t} delay
* @param {easing_type_t} easing
*
* @return {widget_animator_t*} NULL
*/
widget_animator_t* widget_animator_scale_create(widget_t* widget, uint32_t duration, uint32_t delay,
easing_type_t easing);
/**
* @method widget_animator_scale_set_params
*
* @param {widget_animator_t*} animator
* @param {xy_t} x_from x方向起始缩放比例
* @param {xy_t} y_from y方向起始缩放比例
* @param {xy_t} x_to x方向结束缩放比例
* @param {xy_t} y_to y方向结束缩放比例
*
* @return {ret_t} RET_OK表示成功
*/
ret_t widget_animator_scale_set_params(widget_animator_t* animator, float_t x_from, float_t y_from,
float_t x_to, float_t y_to);
#define widget_animator_scale_set_params widget_animator_prop2_set_params
END_C_DECLS

View File

@ -1,7 +1,7 @@
/**
* File: widget_animator_scroll.h
* Author: AWTK Develop Team
* Brief: animate widget by change its position.
* Brief: animate widget by change its xoffset/yoffset.
*
* Copyright (c) 2018 - 2018 Guangzhou ZHIYUAN Electronics Co.,Ltd.
*
@ -28,7 +28,8 @@ BEGIN_C_DECLS
/**
* @class widget_animator_scroll_t
*
*
* widget_animator_prop2实现访
*/
typedef struct _widget_animator_scroll_t {
widget_animator_t base;

View File

@ -1,59 +0,0 @@
/**
* File: widget_animator_value.h
* Author: AWTK Develop Team
* Brief: animate widget by change its value
*
* Copyright (c) 2018 - 2018 Guangzhou ZHIYUAN Electronics Co.,Ltd.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* License file for more details.
*
*/
/**
* History:
* ================================================================
* 2018-05-16 Li XianJing <xianjimli@hotmail.com> created
*
*/
#include "base/mem.h"
#include "widget_animators/widget_animator_value.h"
static ret_t widget_animator_value_update(widget_animator_t* animator, float_t percent) {
value_t v;
float_t new_value = 0;
widget_animator_value_t* value = (widget_animator_value_t*)animator;
return_value_if_fail(value != NULL, RET_BAD_PARAMS);
new_value = value->from + (value->to - value->from) * percent;
widget_set_prop(animator->widget, WIDGET_PROP_VALUE, value_set_float(&v, new_value));
widget_invalidate(animator->widget, NULL);
return RET_OK;
}
widget_animator_t* widget_animator_value_create(widget_t* widget, uint32_t duration, uint32_t delay,
easing_type_t easing) {
widget_animator_t* animator = NULL;
return_value_if_fail(widget != NULL && duration > 0, NULL);
animator = (widget_animator_t*)TKMEM_ZALLOC(widget_animator_value_t);
return_value_if_fail(
widget_animator_init(animator, widget, duration, delay, easing_get(easing)) == RET_OK, NULL);
animator->update = widget_animator_value_update;
return animator;
}
ret_t widget_animator_value_set_params(widget_animator_t* animator, int32_t from, int32_t to) {
widget_animator_value_t* value = (widget_animator_value_t*)animator;
return_value_if_fail(value != NULL, RET_BAD_PARAMS);
value->to = to;
value->from = from;
return RET_OK;
}

View File

@ -1,7 +1,7 @@
/**
* File: widget_animator_value.h
* File: widget_animator_prop.h
* Author: AWTK Develop Team
* Brief: animate widget by change its value
* Brief: animate widget by change its value(just wrap widget_animator_prop)
*
* Copyright (c) 2018 - 2018 Guangzhou ZHIYUAN Electronics Co.,Ltd.
*
@ -22,44 +22,14 @@
#ifndef TK_WIDGET_ANIMATOR_VALUE_H
#define TK_WIDGET_ANIMATOR_VALUE_H
#include "base/widget_animator.h"
#include "widget_animators/widget_animator_prop.h"
BEGIN_C_DECLS
/**
* @class widget_animator_value_t
*
*/
typedef struct _widget_animator_value_t {
widget_animator_t base;
#define widget_animator_value_create(widget, duration, delay, easing) \
widget_animator_prop_create(widget, duration, delay, easing, WIDGET_PROP_VALUE)
int32_t to;
int32_t from;
} widget_animator_value_t;
/**
* @method widget_animator_value_create
*
* @param {widget_t*} widget
* @param {uint32_t} duration
* @param {uint32_t} delay
* @param {easing_type_t} easing
*
* @return {widget_animator_t*} NULL
*/
widget_animator_t* widget_animator_value_create(widget_t* widget, uint32_t duration, uint32_t delay,
easing_type_t easing);
/**
* @method widget_animator_value_set_params
*
* @param {widget_animator_t*} animator
* @param {int32_t} from value起始值
* @param {int32_t} to value结束值
*
* @return {ret_t} RET_OK表示成功
*/
ret_t widget_animator_value_set_params(widget_animator_t* animator, int32_t from, int32_t to);
#define widget_animator_value_set_params widget_animator_prop_set_params
END_C_DECLS

View File

@ -19,7 +19,7 @@ TEST(WidgetAnimatorFactory, opacity) {
widget_animator_t* wa = widget_animator_create(
b, "opacity(from=1, to=200, yoyo_times=1000, duration=2000, delay=1234)");
widget_animator_opacity_t* opacity = (widget_animator_opacity_t*)wa;
widget_animator_prop_t* opacity = (widget_animator_prop_t*)wa;
ASSERT_EQ(wa != NULL, true);
ASSERT_EQ(wa->delay, 1234);
@ -36,14 +36,14 @@ TEST(WidgetAnimatorFactory, opacity_default) {
widget_t* b = button_create(NULL, 10, 20, 100, 30);
b->opacity = 200;
widget_animator_t* wa = widget_animator_create(b, "opacity(from=12)");
widget_animator_opacity_t* opacity = (widget_animator_opacity_t*)wa;
widget_animator_prop_t* opacity = (widget_animator_prop_t*)wa;
ASSERT_EQ(opacity->from, 12);
ASSERT_EQ(opacity->to, 200);
widget_animator_destroy(wa);
b->opacity = 200;
wa = widget_animator_create(b, "opacity(to=12)");
opacity = (widget_animator_opacity_t*)wa;
opacity = (widget_animator_prop_t*)wa;
ASSERT_EQ(opacity->from, 200);
ASSERT_EQ(opacity->to, 12);
widget_animator_destroy(wa);
@ -56,7 +56,7 @@ TEST(WidgetAnimatorFactory, rotation) {
widget_animator_t* wa = widget_animator_create(
b, "rotation(from=1, to=200, yoyo_times=1000, duration=2000, delay=1234)");
widget_animator_rotation_t* rotation = (widget_animator_rotation_t*)wa;
widget_animator_prop_t* rotation = (widget_animator_prop_t*)wa;
ASSERT_EQ(wa != NULL, true);
ASSERT_EQ(wa->delay, 1234);
@ -77,13 +77,13 @@ TEST(WidgetAnimatorFactory, rotation_default) {
widget_set_prop(b, WIDGET_PROP_ROTATION, &v);
widget_animator_t* wa = widget_animator_create(b, "rotation(from=1)");
widget_animator_rotation_t* rotation = (widget_animator_rotation_t*)wa;
widget_animator_prop_t* rotation = (widget_animator_prop_t*)wa;
ASSERT_EQ(rotation->from, 1);
ASSERT_EQ(rotation->to, 200);
widget_animator_destroy(wa);
wa = widget_animator_create(b, "rotation(to=1)");
rotation = (widget_animator_rotation_t*)wa;
rotation = (widget_animator_prop_t*)wa;
ASSERT_EQ(rotation->to, 1);
ASSERT_EQ(rotation->from, 200);
widget_animator_destroy(wa);
@ -96,7 +96,7 @@ TEST(WidgetAnimatorFactory, value) {
widget_animator_t* wa = widget_animator_create(
b, "value(from=1, to=200, yoyo_times=1000, duration=2000, delay=1234)");
widget_animator_value_t* value = (widget_animator_value_t*)wa;
widget_animator_prop_t* value = (widget_animator_prop_t*)wa;
ASSERT_EQ(wa != NULL, true);
ASSERT_EQ(wa->delay, 1234);
@ -114,13 +114,13 @@ TEST(WidgetAnimatorFactory, value_default) {
widget_set_value(b, 20);
widget_animator_t* wa = widget_animator_create(b, "value(from=10)");
widget_animator_value_t* value = (widget_animator_value_t*)wa;
widget_animator_prop_t* value = (widget_animator_prop_t*)wa;
ASSERT_EQ(value->from, 10);
ASSERT_EQ(value->to, 20);
widget_animator_destroy(wa);
wa = widget_animator_create(b, "value(to=10)");
value = (widget_animator_value_t*)wa;
value = (widget_animator_prop_t*)wa;
ASSERT_EQ(value->from, 20);
ASSERT_EQ(value->to, 10);
widget_animator_destroy(wa);
@ -133,16 +133,16 @@ TEST(WidgetAnimatorFactory, move) {
widget_animator_t* wa = widget_animator_create(
b, "move(x_from=1, x_to=200, yoyo_times=1000, duration=2000, delay=1234)");
widget_animator_move_t* move = (widget_animator_move_t*)wa;
widget_animator_prop2_t* move = (widget_animator_prop2_t*)wa;
ASSERT_EQ(wa != NULL, true);
ASSERT_EQ(wa->delay, 1234);
ASSERT_EQ(wa->yoyo_times, 1000);
ASSERT_EQ(wa->duration, 2000);
ASSERT_EQ(move->x_from, 1);
ASSERT_EQ(move->x_to, 200);
ASSERT_EQ(move->y_from, b->y);
ASSERT_EQ(move->y_to, b->y);
ASSERT_EQ(move->from1, 1);
ASSERT_EQ(move->to1, 200);
ASSERT_EQ(move->from2, b->y);
ASSERT_EQ(move->to2, b->y);
widget_animator_destroy(wa);
widget_destroy(b);
@ -152,19 +152,19 @@ TEST(WidgetAnimatorFactory, move_default) {
widget_t* b = button_create(NULL, 10, 20, 100, 30);
widget_animator_t* wa = widget_animator_create(b, "move(x_from=1, x_to=200)");
widget_animator_move_t* move = (widget_animator_move_t*)wa;
ASSERT_EQ(move->x_from, 1);
ASSERT_EQ(move->x_to, 200);
ASSERT_EQ(move->y_from, b->y);
ASSERT_EQ(move->y_to, b->y);
widget_animator_prop2_t* move = (widget_animator_prop2_t*)wa;
ASSERT_EQ(move->from1, 1);
ASSERT_EQ(move->to1, 200);
ASSERT_EQ(move->from2, b->y);
ASSERT_EQ(move->to2, b->y);
widget_animator_destroy(wa);
wa = widget_animator_create(b, "move(y_from=1, y_to=200)");
move = (widget_animator_move_t*)wa;
ASSERT_EQ(move->y_from, 1);
ASSERT_EQ(move->y_to, 200);
ASSERT_EQ(move->x_from, b->x);
ASSERT_EQ(move->x_to, b->x);
move = (widget_animator_prop2_t*)wa;
ASSERT_EQ(move->from2, 1);
ASSERT_EQ(move->to2, 200);
ASSERT_EQ(move->from1, b->x);
ASSERT_EQ(move->to1, b->x);
widget_animator_destroy(wa);
widget_destroy(b);
@ -175,16 +175,16 @@ TEST(WidgetAnimatorFactory, scale) {
widget_animator_t* wa = widget_animator_create(
b, "scale(x_from=1, x_to=-1, repeat_times=1000, duration=2000, delay=1234)");
widget_animator_scale_t* scale = (widget_animator_scale_t*)wa;
widget_animator_prop2_t* scale = (widget_animator_prop2_t*)wa;
ASSERT_EQ(wa != NULL, true);
ASSERT_EQ(wa->delay, 1234);
ASSERT_EQ(wa->repeat_times, 1000);
ASSERT_EQ(wa->duration, 2000);
ASSERT_EQ(scale->x_from, 1);
ASSERT_EQ(scale->x_to, -1);
ASSERT_EQ(scale->y_from, 1);
ASSERT_EQ(scale->y_to, 1);
ASSERT_EQ(scale->from1, 1);
ASSERT_EQ(scale->to1, -1);
ASSERT_EQ(scale->from2, 1);
ASSERT_EQ(scale->to2, 1);
ASSERT_EQ(wa->forever, FALSE);
widget_animator_destroy(wa);
@ -196,19 +196,19 @@ TEST(WidgetAnimatorFactory, scale_default) {
image_set_scale(b, 2, 4);
widget_animator_t* wa = widget_animator_create(b, "scale(x_from=1, x_to=200)");
widget_animator_scale_t* scale = (widget_animator_scale_t*)wa;
ASSERT_EQ(scale->x_from, 1);
ASSERT_EQ(scale->x_to, 200);
ASSERT_EQ(scale->y_from, 4);
ASSERT_EQ(scale->y_to, 4);
widget_animator_prop2_t* scale = (widget_animator_prop2_t*)wa;
ASSERT_EQ(scale->from1, 1);
ASSERT_EQ(scale->to1, 200);
ASSERT_EQ(scale->from2, 4);
ASSERT_EQ(scale->to2, 4);
widget_animator_destroy(wa);
wa = widget_animator_create(b, "scale(y_from=1, y_to=200)");
scale = (widget_animator_scale_t*)wa;
ASSERT_EQ(scale->y_from, 1);
ASSERT_EQ(scale->y_to, 200);
ASSERT_EQ(scale->x_from, 2);
ASSERT_EQ(scale->x_to, 2);
scale = (widget_animator_prop2_t*)wa;
ASSERT_EQ(scale->from2, 1);
ASSERT_EQ(scale->to2, 200);
ASSERT_EQ(scale->from1, 2);
ASSERT_EQ(scale->to1, 2);
widget_animator_destroy(wa);
widget_destroy(b);
@ -313,3 +313,22 @@ TEST(WidgetAnimatorFactory, time_scale) {
widget_destroy(b);
}
TEST(WidgetAnimatorFactory, any_prop) {
widget_t* b = progress_bar_create(NULL, 10, 20, 100, 30);
widget_animator_t* wa = widget_animator_create(
b, "any_prop(from=1, to=200, yoyo_times=1000, duration=2000, delay=1234)");
widget_animator_prop_t* prop = (widget_animator_prop_t*)wa;
ASSERT_EQ(wa != NULL, true);
ASSERT_EQ(wa->delay, 1234);
ASSERT_EQ(wa->yoyo_times, 1000);
ASSERT_EQ(wa->duration, 2000);
ASSERT_EQ(prop->from, 1);
ASSERT_EQ(prop->to, 200);
ASSERT_EQ(prop->prop_name, string("any_prop"));
widget_animator_destroy(wa);
widget_destroy(b);
}