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-10-29 17:09:11 +08:00
|
|
|
TEST_F(ANIMATOR,ofInt1){
|
|
|
|
ValueAnimator*anim=ValueAnimator::ofInt({0,100});
|
|
|
|
anim->addUpdateListener(ValueAnimator::AnimatorUpdateListener([this](ValueAnimator&anim){
|
2021-12-01 13:38:50 +08:00
|
|
|
LOGD("value=%d",anim.getAnimatedValue().get<int>());
|
2021-10-29 17:09:11 +08:00
|
|
|
}));
|
|
|
|
for(int i=0;i<=10;i++){
|
|
|
|
anim->setCurrentFraction((float)i/10.f);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
TEST_F(ANIMATOR,ofInt2){
|
2021-08-16 11:13:00 +08:00
|
|
|
IntPropertyValuesHolder iprop;
|
2021-11-30 16:48:10 +08:00
|
|
|
iprop.setValues(std::vector<int>({0,100}));
|
2021-08-16 11:13:00 +08:00
|
|
|
ValueAnimator*anim=ValueAnimator::ofPropertyValuesHolder({&iprop});
|
2021-10-29 17:09:11 +08:00
|
|
|
anim->addUpdateListener(ValueAnimator::AnimatorUpdateListener([this](ValueAnimator&anim){
|
2021-12-01 13:38:50 +08:00
|
|
|
LOGD("value=%d",anim.getAnimatedValue().get<int>());
|
2021-10-29 17:09:11 +08:00
|
|
|
}));
|
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;
|
2021-11-30 16:48:10 +08:00
|
|
|
fprop.setValues(std::vector<float>({0,100}));
|
2021-08-16 11:13:00 +08:00
|
|
|
ValueAnimator*anim=ValueAnimator::ofPropertyValuesHolder({&fprop});
|
2021-10-29 17:09:11 +08:00
|
|
|
anim->addUpdateListener(ValueAnimator::AnimatorUpdateListener([this](ValueAnimator&anim){
|
2021-12-01 13:38:50 +08:00
|
|
|
LOGD("value=%f",anim.getAnimatedValue().get<float>());
|
2021-10-29 17:09:11 +08:00
|
|
|
}));
|
|
|
|
for(int i=0;i<=10;i++){
|
|
|
|
anim->setCurrentFraction((float)i/10.f);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2021-12-01 13:38:50 +08:00
|
|
|
TEST_F(ANIMATOR,start){
|
|
|
|
App app;
|
|
|
|
FloatPropertyValuesHolder fprop;
|
|
|
|
fprop.setValues(std::vector<float>({0,100}));
|
|
|
|
ValueAnimator*anim=ValueAnimator::ofPropertyValuesHolder({&fprop});
|
|
|
|
anim->addUpdateListener(ValueAnimator::AnimatorUpdateListener([this](ValueAnimator&anim){
|
|
|
|
LOGD("value=%f",anim.getAnimatedValue().get<float>());
|
|
|
|
}));
|
|
|
|
anim->setDuration(200);
|
|
|
|
anim->start();
|
|
|
|
LOGD("====");
|
|
|
|
app.exec();
|
|
|
|
}
|
|
|
|
TEST_F(ANIMATOR,startDelay){
|
|
|
|
App app;
|
|
|
|
FloatPropertyValuesHolder fprop;
|
|
|
|
fprop.setValues(std::vector<float>({0,100}));
|
|
|
|
ValueAnimator*anim=ValueAnimator::ofPropertyValuesHolder({&fprop});
|
|
|
|
anim->addUpdateListener(ValueAnimator::AnimatorUpdateListener([this](ValueAnimator&anim){
|
|
|
|
LOGD("value=%f",anim.getAnimatedValue().get<float>());
|
|
|
|
}));
|
|
|
|
anim->setDuration(200);
|
|
|
|
anim->setStartDelay(1000);
|
|
|
|
anim->start();
|
|
|
|
LOGD("====");
|
|
|
|
app.exec();
|
|
|
|
}
|
|
|
|
|
2021-10-29 17:09:11 +08:00
|
|
|
class MyProperty: public Property{
|
|
|
|
public:
|
|
|
|
MyProperty(const std::string&name):Property(name){
|
|
|
|
}
|
|
|
|
void set(void* object, float value)override{
|
|
|
|
LOGD("value=%f",value);
|
|
|
|
}
|
|
|
|
};
|
|
|
|
TEST_F(ANIMATOR,ofProperty){
|
|
|
|
MyProperty*myprop=new MyProperty("test");
|
|
|
|
ObjectAnimator*anim=ObjectAnimator::ofInt(nullptr,myprop,{0,100});
|
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;
|
2021-11-30 16:48:10 +08:00
|
|
|
iprop.setValues(std::vector<int>({0,100}));
|
2021-08-16 11:13:00 +08:00
|
|
|
|
|
|
|
ValueAnimator*anim=ValueAnimator::ofPropertyValuesHolder({&iprop});
|
2021-10-29 17:09:11 +08:00
|
|
|
anim->addUpdateListener(ValueAnimator::AnimatorUpdateListener([this](ValueAnimator&anim){
|
2021-12-01 13:38:50 +08:00
|
|
|
LOGD("value=%d",anim.getAnimatedValue().get<int>());
|
2021-10-29 17:09:11 +08:00
|
|
|
}));
|
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");
|
2021-11-30 16:48:10 +08:00
|
|
|
xprop.setValues(std::vector<int>({0,100,300}));
|
2021-08-16 11:13:00 +08:00
|
|
|
|
|
|
|
IntPropertyValuesHolder yprop;
|
|
|
|
yprop.setPropertyName("y");
|
2021-11-30 16:48:10 +08:00
|
|
|
yprop.setValues(std::vector<int>({0,200,200}));
|
2021-08-16 11:13:00 +08:00
|
|
|
|
2021-11-30 16:48:10 +08:00
|
|
|
PropertyValuesHolder cprop;
|
|
|
|
cprop.setValues(std::vector<uint32_t>({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-10-29 17:09:11 +08:00
|
|
|
anim->addUpdateListener(ValueAnimator::AnimatorUpdateListener([tv](ValueAnimator&anim){
|
2021-11-30 16:48:10 +08:00
|
|
|
PropertyValuesHolder*xp=anim.getValues(0);
|
|
|
|
PropertyValuesHolder*yp=anim.getValues(1);
|
|
|
|
PropertyValuesHolder*cp=anim.getValues(2);
|
|
|
|
tv->setPos(xp->getAnimatedValue().get<int>(),yp->getAnimatedValue().get<int>());
|
|
|
|
tv->setBackgroundColor(cp->getAnimatedValue().get<uint32_t>());
|
2021-10-29 17:09:11 +08:00
|
|
|
}));
|
2021-09-07 18:12:21 +08:00
|
|
|
|
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");
|
2021-11-30 16:48:10 +08:00
|
|
|
fprop.setValues(std::vector<float>({0,2.0}));
|
2021-09-07 18:12:21 +08:00
|
|
|
|
|
|
|
ValueAnimator*anim=ValueAnimator::ofPropertyValuesHolder({&fprop});
|
2021-10-29 17:09:11 +08:00
|
|
|
anim->addUpdateListener(ValueAnimator::AnimatorUpdateListener([tv](ValueAnimator&anim){
|
2021-12-01 13:38:50 +08:00
|
|
|
const float scale=anim.getAnimatedValue().get<float>();
|
2021-08-17 16:01:58 +08:00
|
|
|
tv->setScaleX(scale);
|
|
|
|
tv->setScaleY(scale);
|
2021-10-29 17:09:11 +08:00
|
|
|
}));
|
2021-08-17 16:01:58 +08:00
|
|
|
anim->setDuration(5000);
|
|
|
|
anim->start();
|
|
|
|
app.exec();
|
|
|
|
}
|
2021-09-07 18:12:21 +08:00
|
|
|
|