Cdroid/apps/samples/animation1.cc

77 lines
2.2 KiB
C++
Raw Normal View History

2022-01-18 16:21:54 +08:00
#include <cdroid.h>
2021-09-27 15:14:59 +08:00
#include <cdlog.h>
#include <getopt.h>
2021-09-17 13:35:41 +08:00
class TestView:public View{
2021-09-27 15:14:59 +08:00
private:
std::string mText;
2021-09-17 13:35:41 +08:00
public:
2021-09-27 15:14:59 +08:00
TestView(const std::string&txt,int w,int h):View(w,h){
mText=txt;
2021-09-17 13:35:41 +08:00
}
2021-09-27 15:14:59 +08:00
void onDraw(Canvas&canvas)override{
2021-09-17 17:15:18 +08:00
canvas.set_color(SystemClock::uptimeMillis());
2021-09-22 17:33:39 +08:00
canvas.rectangle(0,0,getWidth(),getHeight());
2021-09-27 15:14:59 +08:00
canvas.fill();
2021-09-17 17:15:18 +08:00
canvas.set_color(0xFFFFFFFF);
2021-09-27 15:14:59 +08:00
#if 1
Layout ll(28,getWidth());
ll.setText(mText);
2021-09-17 13:35:41 +08:00
ll.draw(canvas);
2021-09-27 15:14:59 +08:00
#else
canvas.set_font_size(28);
canvas.move_to(0,getHeight()/4);
canvas.show_text(mText);
2021-09-17 13:35:41 +08:00
#endif
}
};
2021-09-27 15:14:59 +08:00
class MyGroup:public ViewGroup{
public:
MyGroup(int w,int h):ViewGroup(w,h){}
void onDraw(Canvas&canvas)override{
canvas.set_color(SystemClock::uptimeMillis()+time(nullptr));
canvas.rectangle(0,0,getWidth(),getHeight());
canvas.fill();
canvas.move_to(40,200);
canvas.set_font_size(68);
canvas.set_source_rgb(1,1,1);
canvas.show_text("ViewGroup");
ViewGroup::onDraw(canvas);
}
};
std::vector<CLA::Argument> appargs={
{CLA::EntryType::Switch, "", "type" , "animation type ",CLA::ValueType::None, (int)CLA::EntryFlags::Optional}
2021-09-27 15:14:59 +08:00
};
2021-09-17 13:35:41 +08:00
int main(int argc,const char*argv[]){
2021-09-27 15:14:59 +08:00
App app(argc,argv,appargs);
Window*w=new Window(0,0,800,600);
ViewGroup*grp=new MyGroup(400,400);
//grp->setId(10).setRotation(45);
w->addView(grp).setBackgroundColor(0xFFFF0000);
2021-09-17 13:35:41 +08:00
w->setBackgroundColor(0xFF111111);
2021-09-27 15:14:59 +08:00
View*tv=nullptr;
switch(app.getArgAsInt("type",1)){
default: //pass throught
case 0: tv=new TextView("TestButton",160,60); break;
case 1: tv=new TestView("TestButton",160,60); break;
case 2: tv=new ImageView(160,160);
((ImageView*)tv)->setImageResource("/home/houzh/images/1.png");
break;
}
2021-09-17 17:15:18 +08:00
tv->setId(100);
2021-09-27 15:14:59 +08:00
grp->addView(tv).setPos(50,50).setBackgroundColor(0xFF444444);
float rotation=15.f;
2021-09-17 13:35:41 +08:00
Runnable r([&](){
2021-09-27 15:14:59 +08:00
grp->setRotation(rotation);
2021-09-17 17:15:18 +08:00
tv->setRotation(rotation);
2021-09-17 13:35:41 +08:00
rotation+=5;
2021-09-27 15:14:59 +08:00
w->postDelayed(r,300);
2021-09-17 13:35:41 +08:00
});
w->postDelayed(r,1000);
return app.exec();
}