finalcut/test/keyboard.cpp

81 lines
1.9 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();
bool is_last_line = false;
if ( getPrintPos().getY() == getLineNumber() )
is_last_line = true;
printf ("Key %s (id %d)\n", getKeyName(key_id).c_str(), key_id);
if ( is_last_line )
scrollAreaForward (vdesktop);
setAreaCursor (1, getPrintPos().getY(), true, vdesktop);
2015-10-29 21:10:50 +01:00
}
//----------------------------------------------------------------------
void keyboard::onAccel (FAccelEvent* ev)
{
quit();
ev->accept();
}
//----------------------------------------------------------------------
void keyboard::draw()
{
setPrintPos (1,1);
print ("---------------\n");
print ("Press Q to quit\n");
print ("---------------\n");
setAreaCursor (1, 4, true, vdesktop);
}
2015-10-29 21:10:50 +01:00
//----------------------------------------------------------------------
// main part
//----------------------------------------------------------------------
int main (int argc, char* argv[])
{
FApplication app(argc, argv);
app.setForegroundColor(fc::Default);
app.setBackgroundColor(fc::Default);
keyboard key(&app);
key.addAccelerator('q');
app.setMainWidget(&key);
key.show();
2015-10-29 21:10:50 +01:00
return app.exec();
}