2015-09-25 21:37:19 +02:00
|
|
|
// File: timer.cpp
|
2015-05-23 13:35:12 +02:00
|
|
|
|
|
|
|
#include "final.h"
|
|
|
|
|
|
|
|
//----------------------------------------------------------------------
|
|
|
|
// class timer
|
|
|
|
//----------------------------------------------------------------------
|
|
|
|
|
|
|
|
class timer : public FWidget
|
|
|
|
{
|
|
|
|
public:
|
2016-09-30 04:55:28 +02:00
|
|
|
// Constructor
|
2015-09-27 16:45:28 +02:00
|
|
|
explicit timer (FWidget* = 0);
|
2016-09-30 04:55:28 +02:00
|
|
|
|
2015-05-23 13:35:12 +02:00
|
|
|
protected:
|
2016-09-30 04:55:28 +02:00
|
|
|
// Event handlers
|
2015-05-23 13:35:12 +02:00
|
|
|
void onTimer (FTimerEvent*);
|
|
|
|
void onAccel (FAccelEvent*);
|
2016-09-30 04:55:28 +02:00
|
|
|
|
2016-01-08 01:00:05 +01:00
|
|
|
void draw();
|
2015-05-23 13:35:12 +02:00
|
|
|
};
|
|
|
|
|
|
|
|
//----------------------------------------------------------------------
|
2015-10-29 21:10:50 +01:00
|
|
|
timer::timer (FWidget* parent)
|
|
|
|
: FWidget(parent)
|
2015-05-23 13:35:12 +02:00
|
|
|
{
|
|
|
|
addTimer (60000); // 1-minute timer
|
|
|
|
int id = addTimer (50); // 50-millisecond timer
|
|
|
|
addTimer (1000); // 1-second timer
|
|
|
|
delTimer (id);
|
|
|
|
addTimer (250); // 250-millisecond timer
|
|
|
|
|
2016-01-08 01:00:05 +01:00
|
|
|
resetXTermForeground();
|
|
|
|
resetXTermBackground();
|
2016-01-10 00:56:52 +01:00
|
|
|
wc.term_fg = fc::Default;
|
|
|
|
wc.term_bg = fc::Default;
|
2015-05-23 13:35:12 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
//----------------------------------------------------------------------
|
|
|
|
void timer::onTimer (FTimerEvent* ev)
|
|
|
|
{
|
|
|
|
::printf("timer event, id %d\n\r", ev->timerId() );
|
|
|
|
}
|
|
|
|
|
|
|
|
//----------------------------------------------------------------------
|
|
|
|
void timer::onAccel (FAccelEvent* ev)
|
|
|
|
{
|
|
|
|
quit();
|
|
|
|
ev->accept();
|
|
|
|
}
|
|
|
|
|
2016-01-08 01:00:05 +01:00
|
|
|
//----------------------------------------------------------------------
|
|
|
|
void timer::draw()
|
|
|
|
{
|
|
|
|
setNormal();
|
2016-01-10 00:56:52 +01:00
|
|
|
setColor (fc::Default, fc::Default);
|
2016-08-06 21:43:39 +02:00
|
|
|
clearArea();
|
2016-09-25 23:53:48 +02:00
|
|
|
printPosTerm (1,1);
|
2016-01-08 01:00:05 +01:00
|
|
|
print ("---------------\n");
|
|
|
|
print ("Press Q to quit\n");
|
|
|
|
print ("---------------\n");
|
|
|
|
setCursorPos (1,4);
|
|
|
|
}
|
|
|
|
|
2015-05-23 13:35:12 +02:00
|
|
|
|
|
|
|
//----------------------------------------------------------------------
|
|
|
|
// main part
|
|
|
|
//----------------------------------------------------------------------
|
|
|
|
int main (int argc, char* argv[])
|
|
|
|
{
|
|
|
|
FApplication app(argc, argv);
|
|
|
|
timer t(&app);
|
|
|
|
t.addAccelerator('q');
|
|
|
|
app.setMainWidget(&t);
|
|
|
|
t.show();
|
|
|
|
return app.exec();
|
|
|
|
}
|