finalcut/test/keyboard.cpp

72 lines
1.7 KiB
C++
Raw Normal View History

2015-10-29 21:10:50 +01:00
// File: keyboard.cpp
#include "final.h"
//----------------------------------------------------------------------
// class keyboard
//----------------------------------------------------------------------
class keyboard : public FWidget
{
public:
// Constructor
2015-10-29 21:10:50 +01:00
explicit keyboard (FWidget* = 0);
2015-10-29 21:10:50 +01:00
protected:
// Event handlers
2015-10-29 21:10:50 +01:00
void onKeyPress (FKeyEvent*);
void onAccel (FAccelEvent*);
void draw();
2015-10-29 21:10:50 +01:00
};
//----------------------------------------------------------------------
keyboard::keyboard (FWidget* parent)
: FWidget(parent)
{
resetXTermForeground();
resetXTermBackground();
2016-01-10 00:56:52 +01:00
wc.term_fg = fc::Default;
wc.term_bg = fc::Default;
2015-10-29 21:10:50 +01:00
}
//----------------------------------------------------------------------
void keyboard::onKeyPress (FKeyEvent* ev)
{
int key_id = ev->key();
std::printf("Key %s (id %d)\n\r", getKeyName(key_id).c_str(), key_id);
2015-10-29 21:10:50 +01:00
}
//----------------------------------------------------------------------
void keyboard::onAccel (FAccelEvent* ev)
{
quit();
ev->accept();
}
//----------------------------------------------------------------------
void keyboard::draw()
{
setNormal();
2016-01-10 00:56:52 +01:00
setColor(fc::Default, fc::Default);
clearArea();
printPosTerm (1,1);
print ("---------------\n");
print ("Press Q to quit\n");
print ("---------------\n");
setCursorPos (1,5);
}
2015-10-29 21:10:50 +01:00
//----------------------------------------------------------------------
// main part
//----------------------------------------------------------------------
int main (int argc, char* argv[])
{
FApplication app(argc, argv);
keyboard key(&app);
key.addAccelerator('q');
app.setMainWidget(&key);
key.show();
2015-10-29 21:10:50 +01:00
return app.exec();
}