2021-08-02 11:21:56 +08:00
|
|
|
#include <gtest/gtest.h>
|
|
|
|
#include <windows.h>
|
|
|
|
#include <ngl_os.h>
|
|
|
|
#include <ngl_timer.h>
|
|
|
|
#include <cdlog.h>
|
|
|
|
#include <animation/objectanimator.h>
|
|
|
|
|
|
|
|
class ANIMATOR:public testing::Test{
|
|
|
|
|
|
|
|
public :
|
|
|
|
virtual void SetUp(){
|
|
|
|
}
|
|
|
|
virtual void TearDown(){
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
2021-08-16 11:13:00 +08:00
|
|
|
TEST_F(ANIMATOR,callback){
|
|
|
|
App app;
|
|
|
|
ValueAnimator *anim=new ValueAnimator();
|
|
|
|
anim->getAnimationHandler().addAnimationFrameCallback(anim,100);
|
|
|
|
anim->getAnimationHandler().removeCallback(anim);
|
|
|
|
app.exec();
|
|
|
|
}
|
|
|
|
|
2021-08-02 11:21:56 +08:00
|
|
|
TEST_F(ANIMATOR,ofInt){
|
2021-08-16 11:13:00 +08:00
|
|
|
IntPropertyValuesHolder iprop;
|
|
|
|
iprop.setValues({0,100});
|
|
|
|
ValueAnimator*anim=ValueAnimator::ofPropertyValuesHolder({&iprop});
|
2021-09-07 18:12:21 +08:00
|
|
|
anim->addUpdateListener([this](ValueAnimator&anim){
|
|
|
|
IntPropertyValuesHolder*ip=(IntPropertyValuesHolder*)anim.getValues(0);
|
|
|
|
LOGD("value=%d",ip->getAnimatedValue());
|
|
|
|
});
|
2021-08-02 11:21:56 +08:00
|
|
|
for(int i=0;i<=10;i++){
|
|
|
|
anim->setCurrentFraction((float)i/10.f);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2021-08-16 11:13:00 +08:00
|
|
|
TEST_F(ANIMATOR,ofFloat){
|
|
|
|
FloatPropertyValuesHolder fprop;
|
|
|
|
fprop.setValues({0,100});
|
|
|
|
ValueAnimator*anim=ValueAnimator::ofPropertyValuesHolder({&fprop});
|
2021-09-07 18:12:21 +08:00
|
|
|
anim->addUpdateListener([this](ValueAnimator&anim){
|
|
|
|
FloatPropertyValuesHolder*fp=(FloatPropertyValuesHolder*)anim.getValues(0);
|
|
|
|
LOGD("value=%f",fp->getAnimatedValue());
|
|
|
|
});
|
2021-08-02 11:21:56 +08:00
|
|
|
for(int i=0;i<=10;i++){
|
|
|
|
anim->setCurrentFraction((float)i/10.f);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2021-08-16 11:13:00 +08:00
|
|
|
TEST_F(ANIMATOR,loopdrivered){
|
|
|
|
App app;
|
|
|
|
IntPropertyValuesHolder iprop;
|
|
|
|
iprop.setValues({0,100});
|
|
|
|
|
|
|
|
ValueAnimator*anim=ValueAnimator::ofPropertyValuesHolder({&iprop});
|
2021-09-07 18:12:21 +08:00
|
|
|
anim->addUpdateListener([this](ValueAnimator&anim){
|
|
|
|
IntPropertyValuesHolder*fp=(IntPropertyValuesHolder*)anim.getValues(0);
|
|
|
|
LOGD("value=%d",fp->getAnimatedValue());
|
|
|
|
});
|
2021-08-16 11:13:00 +08:00
|
|
|
anim->setDuration(2000);
|
|
|
|
anim->start();
|
|
|
|
app.exec();
|
|
|
|
}
|
|
|
|
|
|
|
|
TEST_F(ANIMATOR,translate){
|
|
|
|
App app;
|
|
|
|
Window*w=new Window(0,0,800,600);
|
|
|
|
TextView*tv=new TextView("Hello World!",120,30);
|
|
|
|
tv->setBackgroundColor(0xFF111111);
|
|
|
|
w->addView(tv);
|
2021-09-07 18:12:21 +08:00
|
|
|
|
2021-08-16 11:13:00 +08:00
|
|
|
IntPropertyValuesHolder xprop;
|
|
|
|
xprop.setPropertyName("x");
|
|
|
|
xprop.setValues({0,100,300});
|
|
|
|
|
|
|
|
IntPropertyValuesHolder yprop;
|
|
|
|
yprop.setPropertyName("y");
|
|
|
|
yprop.setValues({0,200,200});
|
|
|
|
|
|
|
|
ColorPropertyValuesHolder cprop;
|
|
|
|
cprop.setValues({0xFF000000,0xFFFF8844});
|
2021-09-07 18:12:21 +08:00
|
|
|
|
2021-08-16 11:13:00 +08:00
|
|
|
ValueAnimator*anim=ValueAnimator::ofPropertyValuesHolder({&xprop,&yprop,&cprop});
|
2021-09-07 18:12:21 +08:00
|
|
|
anim->addUpdateListener([tv](ValueAnimator&anim){
|
|
|
|
IntPropertyValuesHolder*xp=(IntPropertyValuesHolder*)anim.getValues(0);
|
|
|
|
IntPropertyValuesHolder*yp=(IntPropertyValuesHolder*)anim.getValues(1);
|
|
|
|
ColorPropertyValuesHolder*cp=(ColorPropertyValuesHolder*)anim.getValues(2);
|
|
|
|
tv->setPos(xp->getAnimatedValue(),tv->getTop());
|
|
|
|
tv->setPos(tv->getLeft(),yp->getAnimatedValue());
|
|
|
|
tv->setBackgroundColor(cp->getAnimatedValue());
|
|
|
|
});
|
|
|
|
|
2021-08-16 11:13:00 +08:00
|
|
|
anim->setDuration(5000);
|
|
|
|
anim->start();
|
|
|
|
app.exec();
|
|
|
|
}
|
2021-08-17 16:01:58 +08:00
|
|
|
TEST_F(ANIMATOR,scale){
|
|
|
|
App app;
|
|
|
|
Window*w=new Window(0,0,800,600);
|
|
|
|
TextView*tv=new TextView("Hello World!",120,30);
|
|
|
|
tv->setBackgroundColor(0xFF111111);
|
|
|
|
w->addView(tv);
|
2021-09-07 18:12:21 +08:00
|
|
|
|
2021-08-17 16:01:58 +08:00
|
|
|
FloatPropertyValuesHolder fprop;
|
|
|
|
fprop.setPropertyName("scale");
|
|
|
|
fprop.setValues({0,2.0});
|
2021-09-07 18:12:21 +08:00
|
|
|
|
|
|
|
ValueAnimator*anim=ValueAnimator::ofPropertyValuesHolder({&fprop});
|
|
|
|
anim->addUpdateListener([tv](ValueAnimator&anim){
|
|
|
|
FloatPropertyValuesHolder*fp=(FloatPropertyValuesHolder*)anim.getValues(0);
|
|
|
|
float scale=fp->getAnimatedValue();
|
2021-08-17 16:01:58 +08:00
|
|
|
tv->setScaleX(scale);
|
|
|
|
tv->setScaleY(scale);
|
|
|
|
});
|
|
|
|
anim->setDuration(5000);
|
|
|
|
anim->start();
|
|
|
|
app.exec();
|
|
|
|
}
|
2021-09-07 18:12:21 +08:00
|
|
|
|