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
|
|
|
|
{
|
2016-08-27 23:23:42 +02:00
|
|
|
public:
|
2016-11-02 00:37:58 +01:00
|
|
|
// Typedef and Enumeration
|
2016-08-27 23:23:42 +02:00
|
|
|
typedef enum ttype
|
|
|
|
{
|
|
|
|
transparent = 0,
|
|
|
|
shadow = 1,
|
|
|
|
inherit_background = 2
|
|
|
|
} trans_type;
|
|
|
|
|
2016-11-02 00:37:58 +01:00
|
|
|
public:
|
|
|
|
// Constructor
|
|
|
|
explicit Transparent (FWidget* = 0, trans_type = transparent);
|
|
|
|
|
|
|
|
// Destructor
|
|
|
|
~Transparent();
|
2016-08-21 21:29:04 +02:00
|
|
|
|
|
|
|
private:
|
2016-09-30 04:55:28 +02:00
|
|
|
// Disable copy constructor
|
|
|
|
Transparent (const Transparent&);
|
2016-11-02 00:37:58 +01:00
|
|
|
|
2016-09-30 04:55:28 +02:00
|
|
|
// Disable assignment operator (=)
|
|
|
|
Transparent& operator = (const Transparent&);
|
|
|
|
|
2016-11-02 00:37:58 +01:00
|
|
|
// Method
|
2016-08-21 21:29:04 +02:00
|
|
|
void draw();
|
2016-09-30 04:55:28 +02:00
|
|
|
|
|
|
|
// Event handlers
|
2016-09-05 19:14:51 +02:00
|
|
|
void onKeyPress (FKeyEvent* ev);
|
2016-08-21 21:29:04 +02:00
|
|
|
|
2016-11-02 00:37:58 +01:00
|
|
|
// Data Members
|
|
|
|
trans_type type;
|
2016-08-21 21:29:04 +02:00
|
|
|
};
|
|
|
|
#pragma pack(pop)
|
|
|
|
|
|
|
|
//----------------------------------------------------------------------
|
2016-08-27 23:23:42 +02:00
|
|
|
Transparent::Transparent (FWidget* parent, Transparent::trans_type tt)
|
2016-08-21 21:29:04 +02:00
|
|
|
: FDialog(parent)
|
2016-08-27 23:23:42 +02:00
|
|
|
, type(tt)
|
2016-08-21 21:29:04 +02:00
|
|
|
{
|
|
|
|
setStatusbarMessage("Press Q to quit");
|
|
|
|
}
|
|
|
|
|
|
|
|
//----------------------------------------------------------------------
|
|
|
|
Transparent::~Transparent()
|
|
|
|
{ }
|
|
|
|
|
|
|
|
//----------------------------------------------------------------------
|
|
|
|
void Transparent::draw()
|
|
|
|
{
|
|
|
|
FDialog::draw();
|
|
|
|
updateVTerm(false);
|
|
|
|
|
|
|
|
if ( isMonochron() )
|
|
|
|
setReverse(true);
|
|
|
|
|
2016-08-27 23:23:42 +02:00
|
|
|
if ( type == shadow )
|
2016-08-21 21:29:04 +02:00
|
|
|
{
|
|
|
|
setColor(wc.shadow_bg, wc.shadow_fg);
|
|
|
|
setTransShadow();
|
|
|
|
}
|
2016-08-27 23:23:42 +02:00
|
|
|
else if ( type == inherit_background )
|
|
|
|
{
|
2016-11-05 23:12:05 +01:00
|
|
|
if ( getMaxColor() > 8 )
|
|
|
|
setColor(fc::Blue, fc::Black);
|
|
|
|
else
|
|
|
|
setColor(fc::Green, fc::Black);
|
|
|
|
|
2016-08-27 23:23:42 +02:00
|
|
|
setInheritBackground();
|
|
|
|
}
|
2016-08-21 21:29:04 +02:00
|
|
|
else
|
|
|
|
setTransparent();
|
|
|
|
|
2016-08-27 23:23:42 +02:00
|
|
|
FString line(getClientWidth(), wchar_t('.'));
|
2016-08-21 21:29:04 +02:00
|
|
|
|
|
|
|
for (int n=1; n <= getClientHeight(); n++)
|
|
|
|
{
|
2016-10-11 04:57:36 +02:00
|
|
|
setPrintPos (2, 2+n);
|
2016-08-21 21:29:04 +02:00
|
|
|
print(line);
|
|
|
|
}
|
|
|
|
|
2016-08-27 23:23:42 +02:00
|
|
|
if ( type == shadow )
|
2016-08-21 21:29:04 +02:00
|
|
|
unsetTransShadow();
|
2016-08-27 23:23:42 +02:00
|
|
|
else if ( type == inherit_background )
|
|
|
|
unsetInheritBackground();
|
2016-08-21 21:29:04 +02:00
|
|
|
else
|
|
|
|
unsetTransparent();
|
|
|
|
|
|
|
|
if ( isMonochron() )
|
|
|
|
setReverse(false);
|
|
|
|
|
|
|
|
updateVTerm(true);
|
|
|
|
}
|
|
|
|
|
2016-09-05 19:14:51 +02:00
|
|
|
//----------------------------------------------------------------------
|
|
|
|
void Transparent::onKeyPress (FKeyEvent* ev)
|
|
|
|
{
|
2016-10-17 08:44:38 +02:00
|
|
|
if ( ! ev )
|
|
|
|
return;
|
|
|
|
|
|
|
|
if ( ev->key() == 'q' && getParentWidget() )
|
2016-09-05 19:14:51 +02:00
|
|
|
{
|
2016-10-17 08:44:38 +02:00
|
|
|
if ( getParentWidget()->close() )
|
|
|
|
ev->accept();
|
2016-09-05 19:14:51 +02:00
|
|
|
else
|
2016-10-17 08:44:38 +02:00
|
|
|
ev->ignore();
|
2016-09-05 19:14:51 +02:00
|
|
|
}
|
2016-10-17 08:44:38 +02:00
|
|
|
else
|
|
|
|
FDialog::onKeyPress(ev);
|
2016-09-05 19:14:51 +02:00
|
|
|
}
|
|
|
|
|
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:
|
2016-09-30 04:55:28 +02:00
|
|
|
// Disable copy constructor
|
|
|
|
MainWindow (const MainWindow&);
|
|
|
|
// Disable assignment operator (=)
|
|
|
|
MainWindow& operator = (const MainWindow&);
|
|
|
|
|
2016-08-21 21:29:04 +02:00
|
|
|
void draw();
|
2016-09-30 04:55:28 +02:00
|
|
|
|
|
|
|
// Event handlers
|
2016-08-21 21:29:04 +02:00
|
|
|
void onClose (FCloseEvent*);
|
|
|
|
void onShow (FShowEvent*);
|
|
|
|
void onTimer (FTimerEvent*);
|
2016-09-05 19:14:51 +02:00
|
|
|
void onKeyPress (FKeyEvent* ev)
|
2016-08-21 21:29:04 +02:00
|
|
|
{
|
2016-10-17 08:44:38 +02:00
|
|
|
if ( ! ev )
|
|
|
|
return;
|
|
|
|
|
|
|
|
if ( ev->key() == 'q' )
|
2016-09-05 19:14:51 +02:00
|
|
|
{
|
2016-10-17 08:44:38 +02:00
|
|
|
close();
|
|
|
|
ev->accept();
|
2016-09-05 19:14:51 +02:00
|
|
|
}
|
2016-10-17 08:44:38 +02:00
|
|
|
else
|
|
|
|
FDialog::onKeyPress(ev);
|
2016-08-21 21:29:04 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
public:
|
2016-09-30 04:55:28 +02:00
|
|
|
// 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");
|
2016-08-27 23:23:42 +02:00
|
|
|
transpwin->setGeometry (6, 3, 29, 12);
|
2016-09-04 18:31:31 +02:00
|
|
|
transpwin->unsetTransparentShadow();
|
2016-08-21 21:29:04 +02:00
|
|
|
transpwin->show();
|
|
|
|
|
2016-08-27 23:23:42 +02:00
|
|
|
Transparent* shadowwin = new Transparent(this, Transparent::shadow);
|
2016-08-21 21:29:04 +02:00
|
|
|
shadowwin->setText("shadow");
|
2016-08-27 23:23:42 +02:00
|
|
|
shadowwin->setGeometry (46, 11, 29, 12);
|
2016-09-04 18:31:31 +02:00
|
|
|
shadowwin->unsetTransparentShadow();
|
2016-08-21 21:29:04 +02:00
|
|
|
shadowwin->show();
|
|
|
|
|
2016-08-27 23:23:42 +02:00
|
|
|
Transparent* ibg = new Transparent(this, Transparent::inherit_background);
|
|
|
|
ibg->setText("inherit background");
|
|
|
|
ibg->setGeometry (42, 3, 29, 7);
|
2016-09-04 18:31:31 +02:00
|
|
|
ibg->unsetTransparentShadow();
|
2016-08-27 23:23:42 +02:00
|
|
|
ibg->show();
|
|
|
|
|
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');
|
2016-09-04 18:31:31 +02:00
|
|
|
unsetTransparentShadow();
|
2016-08-27 23:23:42 +02:00
|
|
|
activateDialog();
|
2016-08-21 21:29:04 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
//----------------------------------------------------------------------
|
|
|
|
MainWindow::~MainWindow()
|
|
|
|
{ }
|
|
|
|
|
|
|
|
//----------------------------------------------------------------------
|
|
|
|
void MainWindow::draw()
|
|
|
|
{
|
|
|
|
FDialog::draw();
|
|
|
|
updateVTerm(false);
|
2016-08-28 22:43:14 +02:00
|
|
|
|
2016-08-21 21:29:04 +02:00
|
|
|
if ( isMonochron() )
|
|
|
|
setReverse(true);
|
|
|
|
|
2016-09-25 23:53:48 +02:00
|
|
|
setColor();
|
2016-10-11 04:57:36 +02:00
|
|
|
setPrintPos (2,4);
|
2016-08-21 21:29:04 +02:00
|
|
|
print(line1);
|
2016-10-11 04:57:36 +02:00
|
|
|
setPrintPos (2,5);
|
2016-08-21 21:29:04 +02:00
|
|
|
print(line2);
|
|
|
|
|
|
|
|
if ( isMonochron() )
|
|
|
|
setReverse(false);
|
|
|
|
|
|
|
|
updateVTerm(true);
|
|
|
|
}
|
|
|
|
|
|
|
|
//----------------------------------------------------------------------
|
|
|
|
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[])
|
|
|
|
{
|
2016-10-06 23:15:09 +02:00
|
|
|
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();
|
2016-10-06 23:15:09 +02:00
|
|
|
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");
|
2016-08-27 23:23:42 +02:00
|
|
|
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();
|
|
|
|
}
|