2017-11-04 07:03:53 +01:00
|
|
|
/***********************************************************************
|
|
|
|
* transparent.cpp - Demonstrates transparent windows *
|
|
|
|
* *
|
2020-07-08 21:32:47 +02:00
|
|
|
* This file is part of the FINAL CUT widget toolkit *
|
2017-11-04 07:03:53 +01:00
|
|
|
* *
|
2020-02-02 22:34:27 +01:00
|
|
|
* Copyright 2016-2020 Markus Gans *
|
2017-11-04 07:03:53 +01:00
|
|
|
* *
|
2020-07-08 21:32:47 +02:00
|
|
|
* FINAL CUT is free software; you can redistribute it and/or modify *
|
|
|
|
* it under the terms of the GNU Lesser General Public License as *
|
|
|
|
* published by the Free Software Foundation; either version 3 of *
|
2017-11-04 07:03:53 +01:00
|
|
|
* the License, or (at your option) any later version. *
|
|
|
|
* *
|
2020-07-08 21:32:47 +02:00
|
|
|
* FINAL CUT is distributed in the hope that it will be useful, but *
|
|
|
|
* WITHOUT ANY WARRANTY; without even the implied warranty of *
|
2017-11-04 07:03:53 +01:00
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
|
|
|
|
* GNU Lesser General Public License for more details. *
|
|
|
|
* *
|
|
|
|
* You should have received a copy of the GNU Lesser General Public *
|
|
|
|
* License along with this program. If not, see *
|
|
|
|
* <http://www.gnu.org/licenses/>. *
|
|
|
|
***********************************************************************/
|
2016-08-21 21:29:04 +02:00
|
|
|
|
2017-10-31 00:41:59 +01:00
|
|
|
#include <final/final.h>
|
2016-08-21 21:29:04 +02:00
|
|
|
|
2019-04-26 21:06:04 +02:00
|
|
|
namespace fc = finalcut::fc;
|
2020-02-16 00:01:36 +01:00
|
|
|
using finalcut::FColorPair;
|
2020-12-31 20:45:10 +01:00
|
|
|
using finalcut::FColor;
|
2019-01-21 03:42:18 +01:00
|
|
|
using finalcut::FPoint;
|
|
|
|
using finalcut::FSize;
|
2020-02-16 00:01:36 +01:00
|
|
|
using finalcut::FStyle;
|
2019-01-21 03:42:18 +01:00
|
|
|
|
2016-08-21 21:29:04 +02:00
|
|
|
|
|
|
|
//----------------------------------------------------------------------
|
|
|
|
// class Transparent
|
|
|
|
//----------------------------------------------------------------------
|
|
|
|
|
2020-04-14 23:46:42 +02:00
|
|
|
class Transparent final : public finalcut::FDialog
|
2016-08-21 21:29:04 +02:00
|
|
|
{
|
2017-09-11 03:06:02 +02:00
|
|
|
public:
|
2020-11-24 21:06:39 +01:00
|
|
|
// Enumeration
|
|
|
|
enum class Type
|
2017-09-11 03:06:02 +02:00
|
|
|
{
|
2020-12-31 20:45:10 +01:00
|
|
|
Transparent = 0,
|
|
|
|
Shadow = 1,
|
|
|
|
InheritBackground = 2
|
2020-11-24 21:06:39 +01:00
|
|
|
};
|
2016-08-27 23:23:42 +02:00
|
|
|
|
2017-09-11 03:06:02 +02:00
|
|
|
// Constructor
|
2018-12-10 01:48:26 +01:00
|
|
|
explicit Transparent ( finalcut::FWidget* = nullptr
|
2020-12-31 20:45:10 +01:00
|
|
|
, Type = Type::Transparent );
|
2018-12-24 18:11:16 +01:00
|
|
|
|
2018-12-09 22:04:55 +01:00
|
|
|
// Disable copy constructor
|
|
|
|
Transparent (const Transparent&) = delete;
|
2018-12-24 18:11:16 +01:00
|
|
|
|
2017-09-11 03:06:02 +02:00
|
|
|
// Destructor
|
2020-11-24 21:06:39 +01:00
|
|
|
~Transparent() override = default;
|
2016-08-21 21:29:04 +02:00
|
|
|
|
2020-04-15 23:44:08 +02:00
|
|
|
// Disable copy assignment operator (=)
|
2018-12-09 22:04:55 +01:00
|
|
|
Transparent& operator = (const Transparent&) = delete;
|
2016-09-30 04:55:28 +02:00
|
|
|
|
2018-12-09 22:04:55 +01:00
|
|
|
private:
|
2017-09-11 03:06:02 +02:00
|
|
|
// Method
|
2019-08-06 23:45:28 +02:00
|
|
|
void draw() override;
|
2016-09-30 04:55:28 +02:00
|
|
|
|
2017-09-11 03:06:02 +02:00
|
|
|
// Event handlers
|
2019-08-06 23:45:28 +02:00
|
|
|
void onKeyPress (finalcut::FKeyEvent* ev) override;
|
2016-08-21 21:29:04 +02:00
|
|
|
|
2019-09-04 23:57:31 +02:00
|
|
|
// Data members
|
2020-11-24 21:06:39 +01:00
|
|
|
Type type;
|
2016-08-21 21:29:04 +02:00
|
|
|
};
|
|
|
|
|
|
|
|
//----------------------------------------------------------------------
|
2018-09-20 23:59:01 +02:00
|
|
|
Transparent::Transparent ( finalcut::FWidget* parent
|
2020-11-24 21:06:39 +01:00
|
|
|
, Transparent::Type tt )
|
2020-05-24 23:55:08 +02:00
|
|
|
: finalcut::FDialog{parent}
|
|
|
|
, type{tt}
|
2016-08-21 21:29:04 +02:00
|
|
|
{
|
2020-04-14 23:46:42 +02:00
|
|
|
// Set statusbar text for this window
|
2020-04-20 01:01:20 +02:00
|
|
|
// Avoids calling a virtual function from the constructor
|
|
|
|
// (CERT, OOP50-CPP)
|
|
|
|
FWidget::setStatusbarMessage("Press Q to quit");
|
2016-08-21 21:29:04 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
//----------------------------------------------------------------------
|
|
|
|
void Transparent::draw()
|
|
|
|
{
|
2018-09-20 23:59:01 +02:00
|
|
|
finalcut::FDialog::draw();
|
2016-08-21 21:29:04 +02:00
|
|
|
|
2020-05-16 22:24:36 +02:00
|
|
|
if ( finalcut::FTerm::isMonochron() )
|
2016-08-21 21:29:04 +02:00
|
|
|
setReverse(true);
|
|
|
|
|
2020-12-31 20:45:10 +01:00
|
|
|
if ( type == Type::Shadow )
|
2016-08-21 21:29:04 +02:00
|
|
|
{
|
2020-05-26 21:37:39 +02:00
|
|
|
const auto& wc = getColorTheme();
|
|
|
|
print() << FColorPair {wc->shadow_bg, wc->shadow_fg}
|
2020-12-31 20:45:10 +01:00
|
|
|
<< FStyle {finalcut::Style::ColorOverlay};
|
2016-08-21 21:29:04 +02:00
|
|
|
}
|
2020-12-31 20:45:10 +01:00
|
|
|
else if ( type == Type::InheritBackground )
|
2016-08-27 23:23:42 +02:00
|
|
|
{
|
2020-05-16 22:24:36 +02:00
|
|
|
if ( finalcut::FTerm::getMaxColor() > 8 )
|
2020-12-31 20:45:10 +01:00
|
|
|
print() << FColorPair {FColor::Blue, FColor::Black};
|
2016-11-05 23:12:05 +01:00
|
|
|
else
|
2020-12-31 20:45:10 +01:00
|
|
|
print() << FColorPair {FColor::Green, FColor::Black};
|
2016-11-05 23:12:05 +01:00
|
|
|
|
2020-12-31 20:45:10 +01:00
|
|
|
print() << FStyle {finalcut::Style::InheritBackground};
|
2016-08-27 23:23:42 +02:00
|
|
|
}
|
2016-08-21 21:29:04 +02:00
|
|
|
else
|
2020-12-31 20:45:10 +01:00
|
|
|
print() << FStyle {finalcut::Style::Transparent};
|
2016-08-21 21:29:04 +02:00
|
|
|
|
2020-05-02 00:07:35 +02:00
|
|
|
const finalcut::FString line{getClientWidth(), '.'};
|
2016-08-21 21:29:04 +02:00
|
|
|
|
2020-02-16 00:01:36 +01:00
|
|
|
// Fill window area
|
2020-10-25 01:21:45 +02:00
|
|
|
for (auto n{1}; n <= int(getClientHeight()); n++)
|
2016-08-21 21:29:04 +02:00
|
|
|
{
|
2020-05-02 00:07:35 +02:00
|
|
|
print() << FPoint{2, 2 + n}
|
2020-02-16 00:01:36 +01:00
|
|
|
<< line;
|
2016-08-21 21:29:04 +02:00
|
|
|
}
|
|
|
|
|
2020-12-31 20:45:10 +01:00
|
|
|
print() << FStyle{finalcut::Style::None};
|
2016-08-21 21:29:04 +02:00
|
|
|
}
|
|
|
|
|
2016-09-05 19:14:51 +02:00
|
|
|
//----------------------------------------------------------------------
|
2018-09-20 23:59:01 +02:00
|
|
|
void Transparent::onKeyPress (finalcut::FKeyEvent* ev)
|
2016-09-05 19:14:51 +02:00
|
|
|
{
|
2016-10-17 08:44:38 +02:00
|
|
|
if ( ! ev )
|
|
|
|
return;
|
|
|
|
|
2020-12-31 20:45:10 +01:00
|
|
|
if ( ev->key() == finalcut::FKey('q') && getParentWidget() )
|
2016-09-05 19:14:51 +02:00
|
|
|
{
|
2019-01-07 05:03:00 +01:00
|
|
|
getParentWidget()->close();
|
|
|
|
ev->accept();
|
2016-09-05 19:14:51 +02:00
|
|
|
}
|
2016-10-17 08:44:38 +02:00
|
|
|
else
|
2018-09-20 23:59:01 +02:00
|
|
|
finalcut::FDialog::onKeyPress(ev);
|
2016-09-05 19:14:51 +02:00
|
|
|
}
|
|
|
|
|
2016-08-21 21:29:04 +02:00
|
|
|
|
|
|
|
//----------------------------------------------------------------------
|
|
|
|
// class MainWindow
|
|
|
|
//----------------------------------------------------------------------
|
|
|
|
|
2020-04-14 23:46:42 +02:00
|
|
|
class MainWindow final : public finalcut::FDialog
|
2016-08-21 21:29:04 +02:00
|
|
|
{
|
2018-10-03 22:23:55 +02:00
|
|
|
public:
|
|
|
|
// Constructor
|
2018-12-10 01:48:26 +01:00
|
|
|
explicit MainWindow (finalcut::FWidget* = nullptr);
|
2018-12-24 18:11:16 +01:00
|
|
|
|
2018-12-09 22:04:55 +01:00
|
|
|
// Disable copy constructor
|
|
|
|
MainWindow (const MainWindow&) = delete;
|
2018-12-24 18:11:16 +01:00
|
|
|
|
2018-10-03 22:23:55 +02:00
|
|
|
// Destructor
|
2020-11-24 21:06:39 +01:00
|
|
|
~MainWindow() override = default;
|
2017-09-11 03:06:02 +02:00
|
|
|
|
2020-04-15 23:44:08 +02:00
|
|
|
// Disable copy assignment operator (=)
|
2018-12-09 22:04:55 +01:00
|
|
|
MainWindow& operator = (const MainWindow&) = delete;
|
2017-09-11 03:06:02 +02:00
|
|
|
|
2018-12-09 22:04:55 +01:00
|
|
|
private:
|
|
|
|
// Method
|
2019-08-06 23:45:28 +02:00
|
|
|
void draw() override;
|
2017-09-11 03:06:02 +02:00
|
|
|
|
|
|
|
// Event handlers
|
2019-08-06 23:45:28 +02:00
|
|
|
void onClose (finalcut::FCloseEvent*) override;
|
|
|
|
void onShow (finalcut::FShowEvent*) override;
|
|
|
|
void onTimer (finalcut::FTimerEvent*) override;
|
|
|
|
void onKeyPress (finalcut::FKeyEvent* ev) override
|
2017-09-11 03:06:02 +02:00
|
|
|
{
|
|
|
|
if ( ! ev )
|
|
|
|
return;
|
|
|
|
|
2020-12-31 20:45:10 +01:00
|
|
|
if ( ev->key() == finalcut::FKey('q') )
|
2017-09-11 03:06:02 +02:00
|
|
|
{
|
|
|
|
close();
|
|
|
|
ev->accept();
|
|
|
|
}
|
|
|
|
else
|
2018-09-20 23:59:01 +02:00
|
|
|
finalcut::FDialog::onKeyPress(ev);
|
2017-09-11 03:06:02 +02:00
|
|
|
}
|
|
|
|
|
2019-09-04 23:57:31 +02:00
|
|
|
// Data members
|
2020-04-19 20:38:52 +02:00
|
|
|
finalcut::FString line1{" .-. .-. .-."};
|
|
|
|
finalcut::FString line2{"`._.' `._.' `._.' "};
|
2018-12-10 01:48:26 +01:00
|
|
|
Transparent* transpwin{nullptr};
|
|
|
|
Transparent* shadowwin{nullptr};
|
|
|
|
Transparent* ibg{nullptr};
|
2018-12-03 03:22:36 +01:00
|
|
|
finalcut::FStatusBar status_bar{this};
|
2016-08-21 21:29:04 +02:00
|
|
|
};
|
2019-09-08 02:04:24 +02:00
|
|
|
|
2016-08-21 21:29:04 +02:00
|
|
|
|
|
|
|
//----------------------------------------------------------------------
|
2018-09-20 23:59:01 +02:00
|
|
|
MainWindow::MainWindow (finalcut::FWidget* parent)
|
2020-05-24 23:55:08 +02:00
|
|
|
: FDialog{parent}
|
2016-08-21 21:29:04 +02:00
|
|
|
{
|
2018-11-24 23:43:09 +01:00
|
|
|
// The memory allocation for the following three sub windows occurs
|
|
|
|
// with the operator new. The lifetime of the generated widget
|
|
|
|
// is managed by the parent object (this). The operator delete
|
2018-12-19 22:04:02 +01:00
|
|
|
// is not required in this class and would result in a double free.
|
2018-11-24 23:43:09 +01:00
|
|
|
transpwin = new Transparent(this);
|
|
|
|
transpwin->setText("transparent");
|
2020-05-02 00:07:35 +02:00
|
|
|
transpwin->setGeometry (FPoint{6, 3}, FSize{29, 12});
|
2018-11-24 23:43:09 +01:00
|
|
|
transpwin->unsetTransparentShadow();
|
|
|
|
|
2020-12-31 20:45:10 +01:00
|
|
|
shadowwin = new Transparent(this, Transparent::Type::Shadow);
|
2018-11-24 23:43:09 +01:00
|
|
|
shadowwin->setText("shadow");
|
2020-05-02 00:07:35 +02:00
|
|
|
shadowwin->setGeometry (FPoint{46, 11}, FSize{29, 12});
|
2018-11-24 23:43:09 +01:00
|
|
|
shadowwin->unsetTransparentShadow();
|
|
|
|
|
2020-12-31 20:45:10 +01:00
|
|
|
ibg = new Transparent(this, Transparent::Type::InheritBackground);
|
2018-11-24 23:43:09 +01:00
|
|
|
ibg->setText("inherit background");
|
2020-05-02 00:07:35 +02:00
|
|
|
ibg->setGeometry (FPoint{42, 3}, FSize{29, 7});
|
2018-11-24 23:43:09 +01:00
|
|
|
ibg->unsetTransparentShadow();
|
2016-08-27 23:23:42 +02:00
|
|
|
|
2020-04-14 23:46:42 +02:00
|
|
|
// Set statusbar text for this window
|
2020-10-04 02:55:15 +02:00
|
|
|
FDialog::setStatusbarMessage("Press Q to quit");
|
2016-08-21 21:29:04 +02:00
|
|
|
|
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
|
|
|
}
|
|
|
|
|
|
|
|
//----------------------------------------------------------------------
|
|
|
|
void MainWindow::draw()
|
|
|
|
{
|
2018-09-20 23:59:01 +02:00
|
|
|
finalcut::FDialog::draw();
|
2016-08-28 22:43:14 +02:00
|
|
|
|
2020-05-16 22:24:36 +02:00
|
|
|
if ( finalcut::FTerm::isMonochron() )
|
2016-08-21 21:29:04 +02:00
|
|
|
setReverse(true);
|
|
|
|
|
2016-09-25 23:53:48 +02:00
|
|
|
setColor();
|
2020-05-02 00:07:35 +02:00
|
|
|
print() << FPoint{2, 4} << line1;
|
|
|
|
print() << FPoint{2, 5} << line2;
|
2016-08-21 21:29:04 +02:00
|
|
|
|
2020-05-16 22:24:36 +02:00
|
|
|
if ( finalcut::FTerm::isMonochron() )
|
2016-08-21 21:29:04 +02:00
|
|
|
setReverse(false);
|
|
|
|
}
|
|
|
|
|
|
|
|
//----------------------------------------------------------------------
|
2018-09-20 23:59:01 +02:00
|
|
|
void MainWindow::onClose (finalcut::FCloseEvent* ev)
|
2016-08-21 21:29:04 +02:00
|
|
|
{
|
2018-09-20 23:59:01 +02:00
|
|
|
finalcut::FApplication::closeConfirmationDialog (this, ev);
|
2016-08-21 21:29:04 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
//----------------------------------------------------------------------
|
2018-09-20 23:59:01 +02:00
|
|
|
void MainWindow::onShow (finalcut::FShowEvent*)
|
2016-08-21 21:29:04 +02:00
|
|
|
{
|
2020-11-18 22:10:09 +01:00
|
|
|
addTimer(90); // Call onTimer() every 90 ms
|
2016-08-21 21:29:04 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
//----------------------------------------------------------------------
|
2018-09-20 23:59:01 +02:00
|
|
|
void MainWindow::onTimer (finalcut::FTimerEvent*)
|
2016-08-21 21:29:04 +02:00
|
|
|
{
|
2018-10-14 06:25:33 +02:00
|
|
|
std::size_t length = line1.getLength();
|
2020-10-04 00:59:21 +02:00
|
|
|
const wchar_t first_char1 = line1[0];
|
|
|
|
const wchar_t first_char2 = line2[0];
|
|
|
|
line1 = line1.right(length - 1) + first_char1;
|
|
|
|
line2 = line2.right(length - 1) + first_char2;
|
2016-08-21 21:29:04 +02:00
|
|
|
redraw();
|
2019-12-16 11:14:24 +01:00
|
|
|
flush();
|
2016-08-21 21:29:04 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
//----------------------------------------------------------------------
|
|
|
|
// main part
|
|
|
|
//----------------------------------------------------------------------
|
|
|
|
|
|
|
|
int main (int argc, char* argv[])
|
|
|
|
{
|
2017-09-19 06:18:03 +02:00
|
|
|
// Create the application object
|
2020-05-02 00:07:35 +02:00
|
|
|
finalcut::FApplication app {argc, argv};
|
2020-03-05 21:30:54 +01:00
|
|
|
app.setNonBlockingRead();
|
2016-08-21 21:29:04 +02:00
|
|
|
|
2017-09-19 06:18:03 +02:00
|
|
|
// Create main dialog object
|
2020-05-02 00:07:35 +02:00
|
|
|
MainWindow main_dlg {&app};
|
2016-08-21 21:29:04 +02:00
|
|
|
main_dlg.setText ("non-transparent");
|
2020-05-02 00:07:35 +02:00
|
|
|
main_dlg.setGeometry (FPoint{8, 16}, FSize{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
|
2020-04-13 12:40:11 +02:00
|
|
|
finalcut::FWidget::setMainWidget (&main_dlg);
|
2016-08-21 21:29:04 +02:00
|
|
|
|
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();
|
|
|
|
}
|