2017-10-02 07:32:33 +02:00
|
|
|
/************************************************************************
|
|
|
|
* transparent.cpp - Demonstrates transparent windows *
|
|
|
|
* *
|
|
|
|
* This file is part of the Final Cut widget toolkit *
|
|
|
|
* *
|
|
|
|
* Copyright 2016-2017 Markus Gans *
|
|
|
|
* *
|
|
|
|
* The Final Cut is free software; you can redistribute it and/or modify *
|
|
|
|
* it under the terms of the GNU General Public License as published by *
|
|
|
|
* the Free Software Foundation; either version 3 of the License, or *
|
|
|
|
* (at your option) any later version. *
|
|
|
|
* *
|
|
|
|
* The Final Cut is distributed in the hope that it will be useful, *
|
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of *
|
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
|
|
|
|
* GNU General Public License for more details. *
|
|
|
|
* *
|
|
|
|
* You should have received a copy of the GNU General Public License *
|
|
|
|
* along with this program. If not, see <http://www.gnu.org/licenses/>. *
|
|
|
|
************************************************************************/
|
2016-08-21 21:29:04 +02:00
|
|
|
|
2017-09-17 21:32:46 +02:00
|
|
|
#include <final/fapplication.h>
|
|
|
|
#include <final/fdialog.h>
|
|
|
|
#include <final/flabel.h>
|
|
|
|
#include <final/fmessagebox.h>
|
|
|
|
#include <final/fstatusbar.h>
|
|
|
|
#include <final/fstring.h>
|
2016-08-21 21:29:04 +02:00
|
|
|
|
|
|
|
|
|
|
|
//----------------------------------------------------------------------
|
|
|
|
// class Transparent
|
|
|
|
//----------------------------------------------------------------------
|
|
|
|
|
|
|
|
#pragma pack(push)
|
|
|
|
#pragma pack(1)
|
|
|
|
|
|
|
|
class Transparent : public FDialog
|
|
|
|
{
|
2017-09-11 03:06:02 +02:00
|
|
|
public:
|
|
|
|
// Typedef and Enumeration
|
|
|
|
typedef enum ttype
|
|
|
|
{
|
|
|
|
transparent = 0,
|
|
|
|
shadow = 1,
|
|
|
|
inherit_background = 2
|
|
|
|
} trans_type;
|
2016-08-27 23:23:42 +02:00
|
|
|
|
2017-09-11 03:06:02 +02:00
|
|
|
public:
|
|
|
|
// Constructor
|
|
|
|
explicit Transparent (FWidget* = 0, trans_type = transparent);
|
2016-11-02 00:37:58 +01:00
|
|
|
|
2017-09-11 03:06:02 +02:00
|
|
|
// Destructor
|
|
|
|
~Transparent();
|
2016-08-21 21:29:04 +02:00
|
|
|
|
2017-09-11 03:06:02 +02:00
|
|
|
private:
|
|
|
|
// Disable copy constructor
|
|
|
|
Transparent (const Transparent&);
|
2016-11-02 00:37:58 +01:00
|
|
|
|
2017-09-11 03:06:02 +02:00
|
|
|
// Disable assignment operator (=)
|
|
|
|
Transparent& operator = (const Transparent&);
|
2016-09-30 04:55:28 +02:00
|
|
|
|
2017-09-11 03:06:02 +02:00
|
|
|
// Method
|
|
|
|
void draw();
|
2016-09-30 04:55:28 +02:00
|
|
|
|
2017-09-11 03:06:02 +02:00
|
|
|
// Event handlers
|
|
|
|
void onKeyPress (FKeyEvent* ev);
|
2016-08-21 21:29:04 +02:00
|
|
|
|
2017-09-11 03:06:02 +02: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();
|
|
|
|
|
|
|
|
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
|
|
|
|
2017-08-27 09:50:30 +02:00
|
|
|
for (int n = 1; n <= getClientHeight(); n++)
|
2016-08-21 21:29:04 +02:00
|
|
|
{
|
2017-08-27 09:50:30 +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);
|
|
|
|
}
|
|
|
|
|
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
|
|
|
|
{
|
2017-09-11 03:06:02 +02:00
|
|
|
private:
|
|
|
|
FString line1;
|
|
|
|
FString line2;
|
|
|
|
|
|
|
|
private:
|
|
|
|
// Disable copy constructor
|
|
|
|
MainWindow (const MainWindow&);
|
|
|
|
// Disable assignment operator (=)
|
|
|
|
MainWindow& operator = (const MainWindow&);
|
|
|
|
|
|
|
|
void draw();
|
|
|
|
|
|
|
|
// Event handlers
|
|
|
|
void onClose (FCloseEvent*);
|
|
|
|
void onShow (FShowEvent*);
|
|
|
|
void onTimer (FTimerEvent*);
|
|
|
|
void onKeyPress (FKeyEvent* ev)
|
|
|
|
{
|
|
|
|
if ( ! ev )
|
|
|
|
return;
|
|
|
|
|
|
|
|
if ( ev->key() == 'q' )
|
|
|
|
{
|
|
|
|
close();
|
|
|
|
ev->accept();
|
|
|
|
}
|
|
|
|
else
|
|
|
|
FDialog::onKeyPress(ev);
|
|
|
|
}
|
|
|
|
|
|
|
|
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");
|
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
|
|
|
|
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
|
|
|
|
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
|
|
|
|
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();
|
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();
|
2017-09-11 03:06:02 +02:00
|
|
|
setPrintPos (2, 4);
|
2016-08-21 21:29:04 +02:00
|
|
|
print(line1);
|
2017-09-11 03:06:02 +02:00
|
|
|
setPrintPos (2, 5);
|
2016-08-21 21:29:04 +02:00
|
|
|
print(line2);
|
|
|
|
|
|
|
|
if ( isMonochron() )
|
|
|
|
setReverse(false);
|
|
|
|
|
2016-12-18 23:34:11 +01:00
|
|
|
updateTerminal();
|
2016-08-21 21:29:04 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
//----------------------------------------------------------------------
|
|
|
|
void MainWindow::onClose (FCloseEvent* ev)
|
|
|
|
{
|
2017-10-30 20:56:00 +01:00
|
|
|
FApplication::closeConfirmationDialog (this, ev);
|
2016-08-21 21:29:04 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
//----------------------------------------------------------------------
|
|
|
|
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[])
|
|
|
|
{
|
2017-09-19 06:18:03 +02:00
|
|
|
// Create the application object
|
2016-08-21 21:29:04 +02:00
|
|
|
FApplication app (argc, argv);
|
|
|
|
|
2017-09-19 06:18:03 +02:00
|
|
|
// Create main dialog object
|
2016-08-21 21:29:04 +02:00
|
|
|
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
|
|
|
|
2017-09-19 06:18:03 +02:00
|
|
|
// Set dialog main_dlg as main widget
|
2016-08-21 21:29:04 +02:00
|
|
|
app.setMainWidget (&main_dlg);
|
|
|
|
|
2017-09-19 06:18:03 +02:00
|
|
|
// Show and start the application
|
|
|
|
main_dlg.show();
|
2016-08-21 21:29:04 +02:00
|
|
|
return app.exec();
|
|
|
|
}
|