2015-09-25 21:37:19 +02:00
|
|
|
// File: timer.cpp
|
2015-05-23 13:35:12 +02:00
|
|
|
|
2017-09-17 21:32:46 +02:00
|
|
|
#include <final/final.h>
|
2015-05-23 13:35:12 +02:00
|
|
|
|
|
|
|
//----------------------------------------------------------------------
|
|
|
|
// class timer
|
|
|
|
//----------------------------------------------------------------------
|
|
|
|
|
|
|
|
class timer : public FWidget
|
|
|
|
{
|
2017-09-11 03:06:02 +02:00
|
|
|
public:
|
|
|
|
// Constructor
|
|
|
|
explicit timer (FWidget* = 0);
|
2016-09-30 04:55:28 +02:00
|
|
|
|
2017-09-11 03:06:02 +02:00
|
|
|
protected:
|
|
|
|
// Method
|
|
|
|
void draw();
|
2016-11-02 00:37:58 +01:00
|
|
|
|
2017-09-11 03:06:02 +02:00
|
|
|
// Event handlers
|
|
|
|
void onTimer (FTimerEvent*);
|
|
|
|
void onAccel (FAccelEvent*);
|
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
|
|
|
}
|
|
|
|
|
2016-11-02 00:37:58 +01:00
|
|
|
//----------------------------------------------------------------------
|
|
|
|
void timer::draw()
|
|
|
|
{
|
|
|
|
setPrintPos (1,1);
|
2016-12-26 01:15:32 +01:00
|
|
|
print() << "---------------\n"
|
|
|
|
<< "Press Q to quit\n"
|
|
|
|
<< "---------------\n";
|
2016-11-02 00:37:58 +01:00
|
|
|
setAreaCursor (1, 4, true, vdesktop);
|
|
|
|
}
|
|
|
|
|
2015-05-23 13:35:12 +02:00
|
|
|
//----------------------------------------------------------------------
|
|
|
|
void timer::onTimer (FTimerEvent* ev)
|
|
|
|
{
|
2016-10-08 02:54:32 +02:00
|
|
|
bool is_last_line = false;
|
|
|
|
int timer_id = ev->timerId();
|
|
|
|
|
|
|
|
if ( getPrintPos().getY() == getLineNumber() )
|
|
|
|
is_last_line = true;
|
|
|
|
|
|
|
|
setColor (short(1 + timer_id), fc::Default);
|
2016-12-26 01:15:32 +01:00
|
|
|
print() << "Timer event, id " << timer_id << '\n';
|
2016-10-08 02:54:32 +02:00
|
|
|
|
|
|
|
if ( is_last_line )
|
|
|
|
scrollAreaForward (vdesktop);
|
|
|
|
|
|
|
|
setAreaCursor (1, getPrintPos().getY(), true, vdesktop);
|
2015-05-23 13:35:12 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
//----------------------------------------------------------------------
|
|
|
|
void timer::onAccel (FAccelEvent* ev)
|
|
|
|
{
|
|
|
|
quit();
|
|
|
|
ev->accept();
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
//----------------------------------------------------------------------
|
|
|
|
// main part
|
|
|
|
//----------------------------------------------------------------------
|
|
|
|
int main (int argc, char* argv[])
|
|
|
|
{
|
2017-09-19 06:18:03 +02:00
|
|
|
// Create the application object
|
2015-05-23 13:35:12 +02:00
|
|
|
FApplication app(argc, argv);
|
2016-11-27 00:41:34 +01:00
|
|
|
app.setForegroundColor(fc::Default);
|
|
|
|
app.setBackgroundColor(fc::Default);
|
2017-09-19 06:18:03 +02:00
|
|
|
|
|
|
|
// Create a timer object t
|
2015-05-23 13:35:12 +02:00
|
|
|
timer t(&app);
|
|
|
|
t.addAccelerator('q');
|
2017-09-19 06:18:03 +02:00
|
|
|
|
|
|
|
// Set the timer object t as main widget
|
2015-05-23 13:35:12 +02:00
|
|
|
app.setMainWidget(&t);
|
2017-09-19 06:18:03 +02:00
|
|
|
|
|
|
|
// Show and start the application
|
2015-05-23 13:35:12 +02:00
|
|
|
t.show();
|
|
|
|
return app.exec();
|
|
|
|
}
|