2019-11-16 15:16:44 +01:00
|
|
|
/***********************************************************************
|
|
|
|
* background-color.cpp - Sets the background color palette *
|
|
|
|
* *
|
2020-07-08 21:32:47 +02:00
|
|
|
* This file is part of the FINAL CUT widget toolkit *
|
2019-11-16 15:16:44 +01:00
|
|
|
* *
|
2020-02-02 22:34:27 +01:00
|
|
|
* Copyright 2019-2020 Markus Gans *
|
2019-11-16 15:16:44 +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 *
|
2019-11-16 15:16:44 +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 *
|
2019-11-16 15:16:44 +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/>. *
|
|
|
|
***********************************************************************/
|
|
|
|
|
2019-12-16 11:14:24 +01:00
|
|
|
#include <tuple>
|
|
|
|
#include <utility>
|
2019-11-16 15:16:44 +01:00
|
|
|
#include <vector>
|
|
|
|
|
|
|
|
#include <final/final.h>
|
|
|
|
|
|
|
|
using finalcut::FPoint;
|
2020-04-17 02:49:33 +02:00
|
|
|
using finalcut::FRect;
|
2019-11-16 15:16:44 +01:00
|
|
|
using finalcut::FSize;
|
|
|
|
|
|
|
|
|
|
|
|
//----------------------------------------------------------------------
|
|
|
|
// class Background
|
|
|
|
//----------------------------------------------------------------------
|
|
|
|
|
2020-04-14 23:46:42 +02:00
|
|
|
class Background final : public finalcut::FDialog
|
2019-11-16 15:16:44 +01:00
|
|
|
{
|
|
|
|
public:
|
2020-11-24 21:06:39 +01:00
|
|
|
// Using-declaration
|
|
|
|
using RGB = std::tuple<uChar, uChar, uChar>;
|
2019-12-16 11:14:24 +01:00
|
|
|
|
2020-04-17 02:49:33 +02:00
|
|
|
// Constructor
|
2019-11-16 15:16:44 +01:00
|
|
|
explicit Background (finalcut::FWidget* = nullptr);
|
|
|
|
|
2019-11-16 19:10:08 +01:00
|
|
|
// Disable copy constructor
|
|
|
|
Background (const Background&) = delete;
|
|
|
|
|
|
|
|
// Destructor
|
2020-11-24 21:06:39 +01:00
|
|
|
~Background() noexcept override;
|
2019-11-16 19:10:08 +01:00
|
|
|
|
2020-04-15 23:44:08 +02:00
|
|
|
// Disable copy assignment operator (=)
|
2019-11-16 19:10:08 +01:00
|
|
|
Background& operator = (const Background&) = delete;
|
|
|
|
|
2019-11-16 15:16:44 +01:00
|
|
|
private:
|
|
|
|
// Callback method
|
2020-08-11 23:04:46 +02:00
|
|
|
void cb_changed();
|
|
|
|
void cb_choice();
|
2019-11-16 15:16:44 +01:00
|
|
|
|
|
|
|
// Data members
|
2019-12-16 11:14:24 +01:00
|
|
|
finalcut::FComboBox color_choice{this};
|
2019-11-16 15:16:44 +01:00
|
|
|
finalcut::FSpinBox red{this};
|
|
|
|
finalcut::FSpinBox green{this};
|
|
|
|
finalcut::FSpinBox blue{this};
|
|
|
|
finalcut::FButton quit{"&Quit", this};
|
2019-12-16 11:14:24 +01:00
|
|
|
std::vector<std::pair<finalcut::FString, RGB>> color_list
|
|
|
|
{
|
|
|
|
{ "Light blue" , std::make_tuple(0x80, 0xa4, 0xec) },
|
|
|
|
{ "Vivid blue" , std::make_tuple(0x37, 0x97, 0xfd) },
|
|
|
|
{ "Bright blue" , std::make_tuple(0x3c, 0x85, 0xd2) },
|
|
|
|
{ "Strong blue" , std::make_tuple(0x32, 0x64, 0x9f) },
|
|
|
|
{ "Light cyan" , std::make_tuple(0x6c, 0xfe, 0xfe) },
|
|
|
|
{ "Vivid cyan" , std::make_tuple(0x0b, 0xdd, 0xd4) },
|
|
|
|
{ "Soft cyan" , std::make_tuple(0x49, 0xa8, 0xac) },
|
|
|
|
{ "Light green" , std::make_tuple(0x81, 0xdf, 0xbb) },
|
|
|
|
{ "Vivid green" , std::make_tuple(0x5c, 0x9e, 0x4a) },
|
|
|
|
{ "Bright green" , std::make_tuple(0x0f, 0xba, 0x78) },
|
|
|
|
{ "Strong green" , std::make_tuple(0x03, 0x8f, 0x68) },
|
|
|
|
{ "Mint green" , std::make_tuple(0x4a, 0xfd, 0x91) },
|
|
|
|
{ "Green" , std::make_tuple(0x6b, 0xe8, 0x1b) },
|
|
|
|
{ "Dark green" , std::make_tuple(0x01, 0x65, 0x05) },
|
|
|
|
{ "Dark sea green", std::make_tuple(0x7d, 0xb6, 0x96) },
|
|
|
|
{ "Bright purple" , std::make_tuple(0x83, 0x76, 0xa2) },
|
|
|
|
{ "Taupe" , std::make_tuple(0xa6, 0x8c, 0x99) },
|
|
|
|
{ "Silver" , std::make_tuple(0xc1, 0xc1, 0xcb) }
|
|
|
|
};
|
2019-11-16 15:16:44 +01:00
|
|
|
};
|
|
|
|
|
|
|
|
//----------------------------------------------------------------------
|
|
|
|
Background::Background (finalcut::FWidget* parent)
|
2020-05-24 23:55:08 +02:00
|
|
|
: FDialog{parent}
|
2019-11-16 15:16:44 +01:00
|
|
|
{
|
|
|
|
// Dialog settings
|
2020-04-19 20:38:52 +02:00
|
|
|
// Avoids calling a virtual function from the constructor
|
|
|
|
// (CERT, OOP50-CPP)
|
|
|
|
FDialog::setText ("Background color palette");
|
2020-05-02 00:07:35 +02:00
|
|
|
FDialog::setGeometry (FPoint{25, 5}, FSize{32, 12});
|
2019-12-16 11:14:24 +01:00
|
|
|
|
|
|
|
// Combobox
|
2020-05-02 00:07:35 +02:00
|
|
|
color_choice.setGeometry (FPoint{2, 2}, FSize{18, 1});
|
2020-12-05 21:24:09 +01:00
|
|
|
color_choice.setLabelOrientation (finalcut::FLineEdit::LabelOrientation::above);
|
2019-12-16 11:14:24 +01:00
|
|
|
color_choice.setLabelText ("Color choice");
|
|
|
|
color_choice.unsetEditable();
|
|
|
|
|
|
|
|
for (auto& c : color_list)
|
|
|
|
{
|
2020-09-18 17:13:52 +02:00
|
|
|
finalcut::FListBoxItem item (c.first, c.second);
|
2019-12-16 11:14:24 +01:00
|
|
|
color_choice.insert(item);
|
|
|
|
}
|
2019-11-16 15:16:44 +01:00
|
|
|
|
|
|
|
// Spin boxes
|
2020-05-02 00:07:35 +02:00
|
|
|
red.setGeometry (FPoint{2, 5}, FSize{7, 1});
|
2020-12-05 21:24:09 +01:00
|
|
|
red.setLabelOrientation (finalcut::FLineEdit::LabelOrientation::above);
|
2019-11-16 15:16:44 +01:00
|
|
|
red.setLabelText ("Red");
|
|
|
|
red.setRange (0, 255);
|
|
|
|
red.setValue (0x80);
|
|
|
|
|
2020-05-02 00:07:35 +02:00
|
|
|
green.setGeometry (FPoint{12, 5}, FSize{7, 1});
|
2020-12-05 21:24:09 +01:00
|
|
|
green.setLabelOrientation (finalcut::FLineEdit::LabelOrientation::above);
|
2019-11-16 15:16:44 +01:00
|
|
|
green.setLabelText ("Green");
|
|
|
|
green.setRange (0, 255);
|
|
|
|
green.setValue (0xa4);
|
|
|
|
|
2020-05-02 00:07:35 +02:00
|
|
|
blue.setGeometry (FPoint{22, 5}, FSize{7, 1});
|
2020-12-05 21:24:09 +01:00
|
|
|
blue.setLabelOrientation (finalcut::FLineEdit::LabelOrientation::above);
|
2019-11-16 15:16:44 +01:00
|
|
|
blue.setLabelText ("Blue");
|
|
|
|
blue.setRange (0, 255);
|
|
|
|
blue.setValue (0xec);
|
|
|
|
|
|
|
|
// Set the initial palette values
|
2019-12-31 06:32:51 +01:00
|
|
|
if ( finalcut::FTerm::canChangeColorPalette() )
|
|
|
|
{
|
|
|
|
finalcut::FTerm::setPalette ( finalcut::fc::LightMagenta
|
|
|
|
, int(red.getValue())
|
|
|
|
, int(green.getValue())
|
|
|
|
, int(blue.getValue()) );
|
|
|
|
}
|
2019-11-16 15:16:44 +01:00
|
|
|
|
|
|
|
// Quit button
|
2020-05-02 00:07:35 +02:00
|
|
|
quit.setGeometry(FPoint{19, 8}, FSize{10, 1});
|
2019-11-16 15:16:44 +01:00
|
|
|
|
|
|
|
// Add some function callbacks
|
|
|
|
quit.addCallback
|
|
|
|
(
|
|
|
|
"clicked",
|
2020-08-11 23:04:46 +02:00
|
|
|
finalcut::getFApplication(),
|
|
|
|
&finalcut::FApplication::cb_exitApp,
|
|
|
|
this
|
2019-11-16 15:16:44 +01:00
|
|
|
);
|
|
|
|
|
2019-12-23 14:20:31 +01:00
|
|
|
for (const auto spinbox : {&red, &green, &blue})
|
|
|
|
{
|
|
|
|
spinbox->addCallback
|
|
|
|
(
|
|
|
|
"changed",
|
2020-08-11 23:04:46 +02:00
|
|
|
this, &Background::cb_changed
|
2019-12-23 14:20:31 +01:00
|
|
|
);
|
|
|
|
}
|
2019-12-16 11:14:24 +01:00
|
|
|
|
2019-12-23 14:20:31 +01:00
|
|
|
for (const auto& signal : {"row-changed", "clicked"})
|
|
|
|
{
|
|
|
|
color_choice.addCallback
|
|
|
|
(
|
|
|
|
signal,
|
2020-08-11 23:04:46 +02:00
|
|
|
this, &Background::cb_choice
|
2019-12-23 14:20:31 +01:00
|
|
|
);
|
|
|
|
}
|
2019-11-16 15:16:44 +01:00
|
|
|
}
|
|
|
|
|
2019-11-16 19:10:08 +01:00
|
|
|
//----------------------------------------------------------------------
|
2020-11-24 21:06:39 +01:00
|
|
|
Background::~Background() noexcept = default; // destructor
|
2019-11-16 19:10:08 +01:00
|
|
|
|
2019-11-16 15:16:44 +01:00
|
|
|
//----------------------------------------------------------------------
|
2020-08-11 23:04:46 +02:00
|
|
|
void Background::cb_changed()
|
2019-11-16 15:16:44 +01:00
|
|
|
{
|
2019-12-31 06:32:51 +01:00
|
|
|
if ( ! finalcut::FTerm::canChangeColorPalette() )
|
|
|
|
return;
|
|
|
|
|
2019-12-16 11:14:24 +01:00
|
|
|
finalcut::FTerm::setPalette ( finalcut::fc::LightMagenta
|
|
|
|
, int(red.getValue())
|
|
|
|
, int(green.getValue())
|
|
|
|
, int(blue.getValue()) );
|
|
|
|
redraw();
|
|
|
|
}
|
|
|
|
|
|
|
|
//----------------------------------------------------------------------
|
2020-08-11 23:04:46 +02:00
|
|
|
void Background::cb_choice()
|
2019-12-16 11:14:24 +01:00
|
|
|
{
|
2019-12-31 06:32:51 +01:00
|
|
|
if ( ! finalcut::FTerm::canChangeColorPalette() )
|
|
|
|
return;
|
|
|
|
|
2020-04-13 12:40:11 +02:00
|
|
|
uChar r{};
|
|
|
|
uChar g{};
|
|
|
|
uChar b{};
|
2020-09-18 17:13:52 +02:00
|
|
|
const RGB rgb = color_choice.getItemData<RGB>();
|
|
|
|
std::tie(r, g, b) = rgb;
|
2019-12-16 11:14:24 +01:00
|
|
|
red.setValue(r);
|
|
|
|
green.setValue(g);
|
|
|
|
blue.setValue(b);
|
|
|
|
finalcut::FTerm::setPalette ( finalcut::fc::LightMagenta
|
2019-11-16 19:10:08 +01:00
|
|
|
, int(red.getValue())
|
|
|
|
, int(green.getValue())
|
|
|
|
, int(blue.getValue()) );
|
2019-11-16 15:16:44 +01:00
|
|
|
redraw();
|
|
|
|
}
|
|
|
|
|
|
|
|
//----------------------------------------------------------------------
|
|
|
|
// main part
|
|
|
|
//----------------------------------------------------------------------
|
|
|
|
|
|
|
|
int main (int argc, char* argv[])
|
|
|
|
{
|
2020-06-06 21:10:06 +02:00
|
|
|
// Create the application object
|
2019-11-16 15:16:44 +01:00
|
|
|
finalcut::FApplication app(argc, argv);
|
2019-12-31 06:32:51 +01:00
|
|
|
|
2020-06-06 21:10:06 +02:00
|
|
|
// Force terminal initialization without calling show()
|
|
|
|
app.initTerminal();
|
|
|
|
|
|
|
|
// The following lines require an initialized terminal
|
2019-12-31 06:32:51 +01:00
|
|
|
if ( finalcut::FTerm::canChangeColorPalette() )
|
|
|
|
app.setBackgroundColor(finalcut::fc::LightMagenta);
|
|
|
|
|
2019-11-16 15:16:44 +01:00
|
|
|
Background dialog(&app);
|
2020-04-13 12:40:11 +02:00
|
|
|
finalcut::FWidget::setMainWidget(&dialog);
|
2019-11-16 15:16:44 +01:00
|
|
|
dialog.show();
|
|
|
|
return app.exec();
|
|
|
|
}
|
|
|
|
|