2019-11-16 15:16:44 +01:00
|
|
|
/***********************************************************************
|
|
|
|
* background-color.cpp - Sets the background color palette *
|
|
|
|
* *
|
|
|
|
* This file is part of the Final Cut widget toolkit *
|
|
|
|
* *
|
|
|
|
* Copyright 2019 Markus Gans *
|
|
|
|
* *
|
|
|
|
* The 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 *
|
|
|
|
* 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 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;
|
|
|
|
using finalcut::FSize;
|
|
|
|
|
|
|
|
|
|
|
|
//----------------------------------------------------------------------
|
|
|
|
// class Background
|
|
|
|
//----------------------------------------------------------------------
|
|
|
|
|
|
|
|
class Background : public finalcut::FDialog
|
|
|
|
{
|
|
|
|
public:
|
2019-12-16 11:14:24 +01:00
|
|
|
// Typedef
|
|
|
|
typedef std::tuple<uChar,uChar,uChar> RGB;
|
|
|
|
|
|
|
|
// Constructors
|
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
|
|
|
|
~Background();
|
|
|
|
|
|
|
|
// Disable assignment operator (=)
|
|
|
|
Background& operator = (const Background&) = delete;
|
|
|
|
|
2019-11-16 15:16:44 +01:00
|
|
|
private:
|
|
|
|
// Callback method
|
|
|
|
void cb_changed (finalcut::FWidget*, FDataPtr);
|
2019-12-16 11:14:24 +01:00
|
|
|
void cb_choice (finalcut::FWidget*, FDataPtr);
|
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)
|
|
|
|
: FDialog(parent)
|
|
|
|
{
|
|
|
|
// Dialog settings
|
|
|
|
setText ("Background color palette");
|
2019-12-16 11:14:24 +01:00
|
|
|
setGeometry (FPoint(25, 5), FSize(32, 12));
|
|
|
|
|
|
|
|
// Combobox
|
|
|
|
color_choice.setGeometry (FPoint(2, 2), FSize(18, 1));
|
|
|
|
color_choice.setLabelOrientation (finalcut::FLineEdit::label_above);
|
|
|
|
color_choice.setLabelText ("Color choice");
|
|
|
|
color_choice.unsetEditable();
|
|
|
|
|
|
|
|
for (auto& c : color_list)
|
|
|
|
{
|
|
|
|
FDataPtr data_ptr = reinterpret_cast<FDataPtr>(&c.second);
|
|
|
|
finalcut::FListBoxItem item (c.first, data_ptr);
|
|
|
|
color_choice.insert(item);
|
|
|
|
}
|
2019-11-16 15:16:44 +01:00
|
|
|
|
|
|
|
// Spin boxes
|
2019-12-16 11:14:24 +01:00
|
|
|
red.setGeometry (FPoint(2, 5), FSize(7, 1));
|
2019-11-16 15:16:44 +01:00
|
|
|
red.setLabelOrientation (finalcut::FLineEdit::label_above);
|
|
|
|
red.setLabelText ("Red");
|
|
|
|
red.setRange (0, 255);
|
|
|
|
red.setValue (0x80);
|
|
|
|
|
2019-12-16 11:14:24 +01:00
|
|
|
green.setGeometry (FPoint(12, 5), FSize(7, 1));
|
2019-11-16 15:16:44 +01:00
|
|
|
green.setLabelOrientation (finalcut::FLineEdit::label_above);
|
|
|
|
green.setLabelText ("Green");
|
|
|
|
green.setRange (0, 255);
|
|
|
|
green.setValue (0xa4);
|
|
|
|
|
2019-12-16 11:14:24 +01:00
|
|
|
blue.setGeometry (FPoint(22, 5), FSize(7, 1));
|
2019-11-16 15:16:44 +01:00
|
|
|
blue.setLabelOrientation (finalcut::FLineEdit::label_above);
|
|
|
|
blue.setLabelText ("Blue");
|
|
|
|
blue.setRange (0, 255);
|
|
|
|
blue.setValue (0xec);
|
|
|
|
|
|
|
|
// Set the initial palette values
|
2019-12-16 11:14:24 +01:00
|
|
|
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
|
|
|
|
|
|
|
// Quit button
|
2019-12-16 11:14:24 +01:00
|
|
|
quit.setGeometry(FPoint(19, 8), FSize(10, 1));
|
2019-11-16 15:16:44 +01:00
|
|
|
|
|
|
|
// Add some function callbacks
|
|
|
|
quit.addCallback
|
|
|
|
(
|
|
|
|
"clicked",
|
|
|
|
F_METHOD_CALLBACK (this, &finalcut::FApplication::cb_exitApp)
|
|
|
|
);
|
|
|
|
|
|
|
|
red.addCallback
|
|
|
|
(
|
|
|
|
"changed",
|
|
|
|
F_METHOD_CALLBACK (this, &Background::cb_changed)
|
|
|
|
);
|
|
|
|
|
|
|
|
green.addCallback
|
|
|
|
(
|
|
|
|
"changed",
|
|
|
|
F_METHOD_CALLBACK (this, &Background::cb_changed)
|
|
|
|
);
|
|
|
|
|
|
|
|
blue.addCallback
|
|
|
|
(
|
|
|
|
"changed",
|
|
|
|
F_METHOD_CALLBACK (this, &Background::cb_changed)
|
|
|
|
);
|
2019-12-16 11:14:24 +01:00
|
|
|
|
|
|
|
color_choice.addCallback
|
|
|
|
(
|
|
|
|
"clicked",
|
|
|
|
F_METHOD_CALLBACK (this, &Background::cb_choice)
|
|
|
|
);
|
|
|
|
|
|
|
|
color_choice.addCallback
|
|
|
|
(
|
|
|
|
"row-changed",
|
|
|
|
F_METHOD_CALLBACK (this, &Background::cb_choice)
|
|
|
|
);
|
2019-11-16 15:16:44 +01:00
|
|
|
}
|
|
|
|
|
2019-11-16 19:10:08 +01:00
|
|
|
//----------------------------------------------------------------------
|
|
|
|
Background::~Background() // destructor
|
|
|
|
{ }
|
|
|
|
|
2019-11-16 15:16:44 +01:00
|
|
|
//----------------------------------------------------------------------
|
|
|
|
void Background::cb_changed (finalcut::FWidget*, FDataPtr)
|
|
|
|
{
|
2019-12-16 11:14:24 +01:00
|
|
|
finalcut::FTerm::setPalette ( finalcut::fc::LightMagenta
|
|
|
|
, int(red.getValue())
|
|
|
|
, int(green.getValue())
|
|
|
|
, int(blue.getValue()) );
|
|
|
|
redraw();
|
|
|
|
updateTerminal();
|
|
|
|
}
|
|
|
|
|
|
|
|
//----------------------------------------------------------------------
|
|
|
|
void Background::cb_choice (finalcut::FWidget*, FDataPtr)
|
|
|
|
{
|
|
|
|
uChar r{}, g{}, b{};
|
|
|
|
FDataPtr data_ptr = color_choice.getItemData();
|
|
|
|
RGB* rgb = reinterpret_cast<RGB*>(data_ptr);
|
|
|
|
std::tie(r, g, b) = *rgb;
|
|
|
|
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();
|
|
|
|
updateTerminal();
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
//----------------------------------------------------------------------
|
|
|
|
// main part
|
|
|
|
//----------------------------------------------------------------------
|
|
|
|
|
|
|
|
int main (int argc, char* argv[])
|
|
|
|
{
|
|
|
|
finalcut::FApplication app(argc, argv);
|
2019-12-16 11:14:24 +01:00
|
|
|
app.setBackgroundColor(finalcut::fc::LightMagenta);
|
2019-11-16 15:16:44 +01:00
|
|
|
Background dialog(&app);
|
|
|
|
app.setMainWidget(&dialog);
|
|
|
|
dialog.show();
|
|
|
|
return app.exec();
|
|
|
|
}
|
|
|
|
|