finalcut/test/transparent.cpp

292 lines
6.4 KiB
C++
Raw Normal View History

2016-08-21 21:29:04 +02:00
// File: transparent.cpp
#include "fapp.h"
#include "fdialog.h"
#include "flabel.h"
#include "fmessagebox.h"
#include "fstatusbar.h"
#include "fstring.h"
//----------------------------------------------------------------------
// class Transparent
//----------------------------------------------------------------------
#pragma pack(push)
#pragma pack(1)
class Transparent : public FDialog
{
public:
// Typedef and Enumeration
typedef enum ttype
{
transparent = 0,
shadow = 1,
inherit_background = 2
} trans_type;
public:
// Constructor
explicit Transparent (FWidget* = 0, trans_type = transparent);
// Destructor
~Transparent();
2016-08-21 21:29:04 +02:00
private:
// Disable copy constructor
Transparent (const Transparent&);
// Disable assignment operator (=)
Transparent& operator = (const Transparent&);
// Method
2016-08-21 21:29:04 +02:00
void draw();
// Event handlers
void onKeyPress (FKeyEvent* ev);
2016-08-21 21:29:04 +02:00
// Data Members
trans_type type;
2016-08-21 21:29:04 +02:00
};
#pragma pack(pop)
//----------------------------------------------------------------------
Transparent::Transparent (FWidget* parent, Transparent::trans_type tt)
2016-08-21 21:29:04 +02:00
: FDialog(parent)
, type(tt)
2016-08-21 21:29:04 +02:00
{
setStatusbarMessage("Press Q to quit");
}
//----------------------------------------------------------------------
Transparent::~Transparent()
{ }
//----------------------------------------------------------------------
void Transparent::draw()
{
FDialog::draw();
if ( isMonochron() )
setReverse(true);
if ( type == shadow )
2016-08-21 21:29:04 +02:00
{
setColor(wc.shadow_bg, wc.shadow_fg);
setTransShadow();
}
else if ( type == inherit_background )
{
if ( getMaxColor() > 8 )
setColor(fc::Blue, fc::Black);
else
setColor(fc::Green, fc::Black);
setInheritBackground();
}
2016-08-21 21:29:04 +02:00
else
setTransparent();
FString line(getClientWidth(), wchar_t('.'));
2016-08-21 21:29:04 +02:00
for (int n=1; n <= getClientHeight(); n++)
{
setPrintPos (2, 2+n);
2016-08-21 21:29:04 +02:00
print(line);
}
if ( type == shadow )
2016-08-21 21:29:04 +02:00
unsetTransShadow();
else if ( type == inherit_background )
unsetInheritBackground();
2016-08-21 21:29:04 +02:00
else
unsetTransparent();
if ( isMonochron() )
setReverse(false);
}
//----------------------------------------------------------------------
void Transparent::onKeyPress (FKeyEvent* ev)
{
if ( ! ev )
return;
if ( ev->key() == 'q' && getParentWidget() )
{
if ( getParentWidget()->close() )
ev->accept();
else
ev->ignore();
}
else
FDialog::onKeyPress(ev);
}
2016-08-21 21:29:04 +02:00
//----------------------------------------------------------------------
// class MainWindow
//----------------------------------------------------------------------
#pragma pack(push)
#pragma pack(1)
class MainWindow : public FDialog
{
private:
FString line1;
FString line2;
private:
// Disable copy constructor
MainWindow (const MainWindow&);
// Disable assignment operator (=)
MainWindow& operator = (const MainWindow&);
2016-08-21 21:29:04 +02:00
void draw();
// Event handlers
2016-08-21 21:29:04 +02:00
void onClose (FCloseEvent*);
void onShow (FShowEvent*);
void onTimer (FTimerEvent*);
void onKeyPress (FKeyEvent* ev)
2016-08-21 21:29:04 +02:00
{
if ( ! ev )
return;
if ( ev->key() == 'q' )
{
close();
ev->accept();
}
else
FDialog::onKeyPress(ev);
2016-08-21 21:29:04 +02:00
}
public:
// Constructor
explicit MainWindow (FWidget* = 0);
// Destructor
~MainWindow();
2016-08-21 21:29:04 +02:00
};
#pragma pack(pop)
//----------------------------------------------------------------------
MainWindow::MainWindow (FWidget* parent)
: FDialog(parent)
, line1()
, line2()
{
line1 = " .-. .-. .-.";
line2 = "`._.' `._.' `._.' ";
Transparent* transpwin = new Transparent(this);
transpwin->setText("transparent");
transpwin->setGeometry (6, 3, 29, 12);
transpwin->unsetTransparentShadow();
2016-08-21 21:29:04 +02:00
Transparent* shadowwin = new Transparent(this, Transparent::shadow);
2016-08-21 21:29:04 +02:00
shadowwin->setText("shadow");
shadowwin->setGeometry (46, 11, 29, 12);
shadowwin->unsetTransparentShadow();
2016-08-21 21:29:04 +02:00
Transparent* ibg = new Transparent(this, Transparent::inherit_background);
ibg->setText("inherit background");
ibg->setGeometry (42, 3, 29, 7);
ibg->unsetTransparentShadow();
2016-08-21 21:29:04 +02:00
// Statusbar at the bottom
FStatusBar* statusbar = new FStatusBar (this);
statusbar->setMessage("Press Q to quit");
addAccelerator('q');
unsetTransparentShadow();
activateDialog();
2016-08-21 21:29:04 +02:00
}
//----------------------------------------------------------------------
MainWindow::~MainWindow()
{ }
//----------------------------------------------------------------------
void MainWindow::draw()
{
FDialog::draw();
2016-08-21 21:29:04 +02:00
if ( isMonochron() )
setReverse(true);
setColor();
setPrintPos (2,4);
2016-08-21 21:29:04 +02:00
print(line1);
setPrintPos (2,5);
2016-08-21 21:29:04 +02:00
print(line2);
if ( isMonochron() )
setReverse(false);
updateTerminal();
2016-08-21 21:29:04 +02:00
}
//----------------------------------------------------------------------
void MainWindow::onClose (FCloseEvent* ev)
{
int ret = FMessageBox::info ( this, "Quit"
, "Do you really want\n"
"to quit the program ?"
, FMessageBox::Yes
, FMessageBox::No );
if ( ret == FMessageBox::Yes )
ev->accept();
else
ev->ignore();
}
//----------------------------------------------------------------------
void MainWindow::onShow (FShowEvent*)
{
addTimer(100);
}
//----------------------------------------------------------------------
void MainWindow::onTimer (FTimerEvent*)
{
wchar_t first_Char[2];
uInt length = line1.getLength();
first_Char[0] = line1[0];
first_Char[1] = line2[0];
line1 = line1.right(length - 1) + first_Char[0];
line2 = line2.right(length - 1) + first_Char[1];
redraw();
flush_out();
}
//----------------------------------------------------------------------
// main part
//----------------------------------------------------------------------
int main (int argc, char* argv[])
{
if ( argv[1] && ( std::strcmp(argv[1], "--help") == 0
|| std::strcmp(argv[1], "-h") == 0 ) )
2016-08-21 21:29:04 +02:00
{
std::cout << "Generic options:" << std::endl
<< " -h, --help "
<< "Display this help and exit" << std::endl;
FApplication::print_cmd_Options();
std::exit(EXIT_SUCCESS);
2016-08-21 21:29:04 +02:00
}
FApplication app (argc, argv);
MainWindow main_dlg (&app);
main_dlg.setText ("non-transparent");
main_dlg.setGeometry (8, 16, 26, 7);
2016-08-21 21:29:04 +02:00
app.setMainWidget (&main_dlg);
main_dlg.show();
return app.exec();
}