- 积分
- 55
- 帖子
- 26
- 主题
- 10
- 精华
- 0
- 最后登录
- 2018-1-4
- 在线时间
- 22 小时
- 私信
|
发表时间 : 2011-8-25 16:57:47
|
浏览 : 999 评论 : 4
vp中高级培训--数字时钟的sample
上次的培训做了好些sample
其中有一个是对switch的简单应用,做一个数字时钟
[cpp]#include <vuAllocTracer.h>
#include <vuField.h>
#include <vpApp.h>
#include <vpObject.h>
#include <time.h>
#include <vsSwitch.h>
// our main application class
class myApp : public vpApp {
public:
myApp()
{}
~myApp()
{
}
int configure() {
vpApp::configure();
m_pObj=vpObject::find("time");
assert(m_pObj);
hur1= (vsSwitch *) m_pObj->find_named("hour1");
assert(hur1!=NULL);
hur2= (vsSwitch *) m_pObj->find_named("hour2");
assert(hur2!=NULL);
min1= (vsSwitch *) m_pObj->find_named("min1");
assert(min1!=NULL);
min2= (vsSwitch *) m_pObj->find_named("min2");
assert(min2!=NULL);
sec1= (vsSwitch *) m_pObj->find_named("sec1");
assert(sec1!=NULL);
sec2= (vsSwitch *) m_pObj->find_named("sec2");
assert(sec2!=NULL);
return vsgu::SUCCESS;
}
virtual void onKeyInput(vrWindow::Key key, int mod)
{
vpChannel *channel = *vpChannel::begin();
switch (key) {
case vrWindow::KEY_F1:
break;
default:
vpApp::onKeyInput(key, mod);
break;
}
}
virtual int endFrame(void) const
{
//获取当前时间
tm *newtime;
time_t ltime;
time( <ime );
newtime = localtime( <ime );
//这里的setActiveMask函数的作用是什么??
hur1->setActiveMask(int(newtime->tm_hour/10));
hur2->setActiveMask(int(newtime->tm_hour%10));
min1->setActiveMask(int(newtime->tm_min/10));
min2->setActiveMask(int(newtime->tm_min%10));
sec1->setActiveMask(int(newtime->tm_sec/10));
sec2->setActiveMask(int(newtime->tm_sec%10));
return vpApp::endFrame();
}
private:
vpObject* m_pObj;
vsSwitch* hur1;
vsSwitch* hur2;
vsSwitch* min1;
vsSwitch* min2;
vsSwitch* sec1;
vsSwitch* sec2;
};
int main(int argc, char *argv[])
{
// initialize vega prime
vp::initialize(argc, argv);
// create my app instance
myApp *app = new myApp;
// load the acf file
if (argc <= 1)
app->define("pipeuv.acf");
else app->define(argv[1]);
// configure my app
app->configure();
// execute the main runtime loop
app->run();
// delete my app instance
app->unref();
// shutdown vega prime
vp::shutdown();
return 0;
}
[/cpp]
|
|