With FColorPalette you can now create your own color palette themes

This commit is contained in:
Markus Gans 2020-05-28 01:02:53 +02:00
parent a0e1115ff6
commit df672dfd73
10 changed files with 496 additions and 265 deletions

View File

@ -1,3 +1,7 @@
2020-05-28 Markus Gans <guru.mail@muenster.de>
* FColorPalette now also uses polymorphism, so you can now
easily create your own color palette theme
2020-05-26 Markus Gans <guru.mail@muenster.de>
* FWidgetColors now uses polymorphism, so you can now easily
create your own widget color theme

View File

@ -70,6 +70,7 @@ libfinal_la_SOURCES = \
foptimove.cpp \
ftermbuffer.cpp \
fapplication.cpp \
fcolorpalette.cpp \
fwidgetcolors.cpp \
fwidget.cpp \
fwidget_functions.cpp \

View File

@ -145,6 +145,7 @@ OBJS = \
foptimove.o \
ftermbuffer.o \
fapplication.o \
fcolorpalette.o \
fwidgetcolors.o \
fwidget.o \
fwidget_functions.o \

View File

@ -145,6 +145,7 @@ OBJS = \
foptimove.o \
ftermbuffer.o \
fapplication.o \
fcolorpalette.o \
fwidgetcolors.o \
fwidget.o \
fwidget_functions.o \

169
src/fcolorpalette.cpp Normal file
View File

@ -0,0 +1,169 @@
/***********************************************************************
* fcolorpalette.cpp - Define RGB color value for a palette entry *
* *
* This file is part of the Final Cut widget toolkit *
* *
* Copyright 2020 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/>. *
***********************************************************************/
#include "final/fcolorpalette.h"
namespace finalcut
{
//----------------------------------------------------------------------
// class FColorPalette
//----------------------------------------------------------------------
// constructors and destructor
//----------------------------------------------------------------------
FColorPalette::FColorPalette (FSetPalette f)
: set_palette{f}
{ }
//----------------------------------------------------------------------
FColorPalette::~FColorPalette() // destructor
{ }
// protected methods of FColorPalette
//----------------------------------------------------------------------
void FColorPalette::setPalette (FColor index, int r, int g, int b)
{
set_palette (index, r, g, b);
}
//----------------------------------------------------------------------
// class default8ColorPalette
//----------------------------------------------------------------------
// constructors and destructor
//----------------------------------------------------------------------
default8ColorPalette::default8ColorPalette (FSetPalette f)
: FColorPalette(f)
{ }
//----------------------------------------------------------------------
default8ColorPalette::~default8ColorPalette()
{ }
// public methods of default8ColorPalette
//----------------------------------------------------------------------
void default8ColorPalette::setColorPalette()
{
setPalette (fc::Black, 0x00, 0x00, 0x00);
setPalette (fc::Blue, 0x10, 0x3b, 0x9e);
setPalette (fc::Green, 0x18, 0x78, 0x18);
setPalette (fc::Cyan, 0xa0, 0xb2, 0xb2);
setPalette (fc::Red, 0xb2, 0x18, 0x18);
setPalette (fc::Magenta, 0xb2, 0x18, 0xb2);
setPalette (fc::Brown, 0xe8, 0x87, 0x1f);
setPalette (fc::LightGray, 0xe0, 0xe0, 0xe0);
// The same colors again...
setPalette (fc::DarkGray, 0x00, 0x00, 0x00);
setPalette (fc::LightBlue, 0x10, 0x3b, 0x9e);
setPalette (fc::LightGreen, 0x18, 0x78, 0x18);
setPalette (fc::Cyan, 0xa0, 0xb2, 0xb2);
setPalette (fc::LightRed, 0xb2, 0x18, 0x18);
setPalette (fc::LightMagenta, 0xb2, 0x18, 0xb2);
setPalette (fc::Yellow, 0xe8, 0x87, 0x1f);
setPalette (fc::White, 0xe0, 0xe0, 0xe0);
}
//----------------------------------------------------------------------
void default8ColorPalette::resetColorPalette()
{
set_palette (fc::Black, 0x00, 0x00, 0x00);
set_palette (fc::Blue, 0x00, 0x00, 0xaa);
set_palette (fc::Green, 0x00, 0xaa, 0x00);
set_palette (fc::Cyan, 0x00, 0x55, 0xaa);
set_palette (fc::Red, 0xaa, 0x00, 0x00);
set_palette (fc::Magenta, 0xaa, 0x00, 0xaa);
set_palette (fc::Brown, 0xaa, 0xaa, 0x00);
set_palette (fc::LightGray, 0xaa, 0xaa, 0xaa);
set_palette (fc::DarkGray, 0x55, 0x55, 0x55);
set_palette (fc::LightBlue, 0x55, 0x55, 0xff);
set_palette (fc::LightGreen, 0x55, 0xff, 0x55);
set_palette (fc::LightCyan, 0x55, 0xff, 0xff);
set_palette (fc::LightRed, 0xff, 0x55, 0x55);
set_palette (fc::LightMagenta, 0xff, 0x55, 0xff);
set_palette (fc::Yellow, 0xff, 0xff, 0x55);
set_palette (fc::White, 0xff, 0xff, 0xff);
}
//----------------------------------------------------------------------
// class default16ColorPalette
//----------------------------------------------------------------------
// constructors and destructor
//----------------------------------------------------------------------
default16ColorPalette::default16ColorPalette (FSetPalette f)
: FColorPalette(f)
{ }
//----------------------------------------------------------------------
default16ColorPalette::~default16ColorPalette()
{ }
// public methods of default8ColorPalette
//----------------------------------------------------------------------
void default16ColorPalette::setColorPalette()
{
setPalette (fc::Black, 0x00, 0x00, 0x00);
setPalette (fc::Blue, 0x10, 0x3b, 0x9e);
setPalette (fc::Green, 0x18, 0x78, 0x18);
setPalette (fc::Cyan, 0x55, 0x6a, 0xcf);
setPalette (fc::Red, 0xba, 0x1a, 0x1a);
setPalette (fc::Magenta, 0xb2, 0x18, 0xb2);
setPalette (fc::Brown, 0xe8, 0x87, 0x1f);
setPalette (fc::LightGray, 0xbc, 0xbc, 0xbc);
setPalette (fc::DarkGray, 0x50, 0x50, 0x50);
setPalette (fc::LightBlue, 0x80, 0xa4, 0xec);
setPalette (fc::LightGreen, 0x5e, 0xeb, 0x5c);
setPalette (fc::LightCyan, 0x62, 0xbf, 0xf8);
setPalette (fc::LightRed, 0xee, 0x44, 0x44);
setPalette (fc::LightMagenta, 0xe9, 0xad, 0xff);
setPalette (fc::Yellow, 0xfb, 0xe8, 0x67);
setPalette (fc::White, 0xff, 0xff, 0xff);
}
//----------------------------------------------------------------------
void default16ColorPalette::resetColorPalette()
{
set_palette (fc::Black, 0x00, 0x00, 0x00);
set_palette (fc::Blue, 0x00, 0x00, 0xaa);
set_palette (fc::Green, 0x00, 0xaa, 0x00);
set_palette (fc::Cyan, 0x00, 0x55, 0xaa);
set_palette (fc::Red, 0xaa, 0x00, 0x00);
set_palette (fc::Magenta, 0xaa, 0x00, 0xaa);
set_palette (fc::Brown, 0xaa, 0xaa, 0x00);
set_palette (fc::LightGray, 0xaa, 0xaa, 0xaa);
set_palette (fc::DarkGray, 0x55, 0x55, 0x55);
set_palette (fc::LightBlue, 0x55, 0x55, 0xff);
set_palette (fc::LightGreen, 0x55, 0xff, 0x55);
set_palette (fc::LightCyan, 0x55, 0xff, 0xff);
set_palette (fc::LightRed, 0xff, 0x55, 0x55);
set_palette (fc::LightMagenta, 0xff, 0x55, 0xff);
set_palette (fc::Yellow, 0xff, 0xff, 0x55);
set_palette (fc::White, 0xff, 0xff, 0xff);
}
} // namespace finalcut

View File

@ -28,7 +28,6 @@
#include "final/fapplication.h"
#include "final/fc.h"
#include "final/fcharmap.h"
#include "final/fcolorpalette.h"
#include "final/fkey_map.h"
#include "final/fkeyboard.h"
#include "final/flog.h"
@ -181,6 +180,13 @@ int FTerm::getMaxColor()
return FTermcap::max_color;
}
//----------------------------------------------------------------------
FTerm::FColorPalettePtr& FTerm::getColorPaletteTheme()
{
static FColorPalettePtr* color_theme = new FColorPalettePtr();
return *color_theme;
}
//----------------------------------------------------------------------
FTermData* FTerm::getFTermData()
{
@ -1883,9 +1889,11 @@ void FTerm::redefineColorPalette()
saveColorMap();
if ( getMaxColor() >= 16 )
FColorPalette::set16ColorPalette (FTerm::setPalette);
setColorPaletteTheme<default16ColorPalette>(&FTerm::setPalette);
else // 8 colors
FColorPalette::set8ColorPalette (FTerm::setPalette);
setColorPaletteTheme<default8ColorPalette>(&FTerm::setPalette);
getColorPaletteTheme()->setColorPalette();
}
//----------------------------------------------------------------------
@ -1895,11 +1903,7 @@ void FTerm::restoreColorPalette()
return;
// Reset screen settings
if ( getMaxColor() >= 16 )
FColorPalette::reset16ColorPalette (FTerm::setPalette);
else // 8 colors
FColorPalette::reset8ColorPalette (FTerm::setPalette);
getColorPaletteTheme()->resetColorPalette();
getFTermXTerminal()->resetColorMap();
resetColorMap();
}
@ -2498,6 +2502,13 @@ void FTerm::finish_encoding()
#endif
}
//----------------------------------------------------------------------
void FTerm::destroyColorPaletteTheme()
{
const FColorPalettePtr* theme = &(getColorPaletteTheme());
delete theme;
}
//----------------------------------------------------------------------
void FTerm::setSignalHandler()
{

View File

@ -2001,7 +2001,7 @@ void FWidget::initColorTheme()
//----------------------------------------------------------------------
void FWidget::destroyColorTheme()
{
FWidgetColorsPtr* theme = &(getColorTheme());
const FWidgetColorsPtr* theme = &(getColorTheme());
delete theme;
}

View File

@ -46,27 +46,30 @@ namespace finalcut
// class FColorPalette
//----------------------------------------------------------------------
class FColorPalette final
class FColorPalette
{
public:
// Typedef
typedef std::function<void(FColor, int, int, int)> FSetPalette;
// Constructor
FColorPalette() = default;
FColorPalette(FSetPalette);
// Destructor
~FColorPalette();
virtual ~FColorPalette();
// Accessor
const FString getClassName() const;
virtual const FString getClassName() const;
// Methods
template<typename funcT>
static void set8ColorPalette (funcT);
template<typename funcT>
static void set16ColorPalette (funcT);
template<typename funcT>
static void reset8ColorPalette (funcT);
template<typename funcT>
static void reset16ColorPalette (funcT);
virtual void setColorPalette() = 0;
virtual void resetColorPalette() = 0;
protected:
void setPalette (FColor, int, int, int);
// Data members
FSetPalette set_palette;
};
// FColorPalette inline functions
@ -74,85 +77,85 @@ class FColorPalette final
inline const FString FColorPalette::getClassName() const
{ return "FColorPalette"; }
// constructors and destructor
//----------------------------------------------------------------------
inline FColorPalette::~FColorPalette() // destructor
{ }
// public methods of FColorPalette
//----------------------------------------------------------------------
template<typename funcT>
void FColorPalette::set8ColorPalette (funcT set_palette)
{
set_palette (fc::Black, 0x00, 0x00, 0x00);
set_palette (fc::Blue, 0x10, 0x3b, 0x9e);
set_palette (fc::Green, 0x18, 0x78, 0x18);
set_palette (fc::Cyan, 0xa0, 0xb2, 0xb2);
set_palette (fc::Red, 0xb2, 0x18, 0x18);
set_palette (fc::Magenta, 0xb2, 0x18, 0xb2);
set_palette (fc::Brown, 0xe8, 0x87, 0x1f);
set_palette (fc::LightGray, 0xe0, 0xe0, 0xe0);
// The same colors again...
set_palette (fc::DarkGray, 0x00, 0x00, 0x00);
set_palette (fc::LightBlue, 0x10, 0x3b, 0x9e);
set_palette (fc::LightGreen, 0x18, 0x78, 0x18);
set_palette (fc::Cyan, 0xa0, 0xb2, 0xb2);
set_palette (fc::LightRed, 0xb2, 0x18, 0x18);
set_palette (fc::LightMagenta, 0xb2, 0x18, 0xb2);
set_palette (fc::Yellow, 0xe8, 0x87, 0x1f);
set_palette (fc::White, 0xe0, 0xe0, 0xe0);
}
/* Inheritance diagram
*
*
*
* FColorPalette
*
*
*
*
* default8ColorPalette
*
*/
//----------------------------------------------------------------------
template<typename funcT>
void FColorPalette::set16ColorPalette (funcT set_palette)
// class default8ColorPalette
//----------------------------------------------------------------------
class default8ColorPalette final : public FColorPalette
{
set_palette (fc::Black, 0x00, 0x00, 0x00);
set_palette (fc::Blue, 0x10, 0x3b, 0x9e);
set_palette (fc::Green, 0x18, 0x78, 0x18);
set_palette (fc::Cyan, 0x55, 0x6a, 0xcf);
set_palette (fc::Red, 0xba, 0x1a, 0x1a);
set_palette (fc::Magenta, 0xb2, 0x18, 0xb2);
set_palette (fc::Brown, 0xe8, 0x87, 0x1f);
set_palette (fc::LightGray, 0xbc, 0xbc, 0xbc);
set_palette (fc::DarkGray, 0x50, 0x50, 0x50);
set_palette (fc::LightBlue, 0x80, 0xa4, 0xec);
set_palette (fc::LightGreen, 0x5e, 0xeb, 0x5c);
set_palette (fc::LightCyan, 0x62, 0xbf, 0xf8);
set_palette (fc::LightRed, 0xee, 0x44, 0x44);
set_palette (fc::LightMagenta, 0xe9, 0xad, 0xff);
set_palette (fc::Yellow, 0xfb, 0xe8, 0x67);
set_palette (fc::White, 0xff, 0xff, 0xff);
}
public:
// Constructor
default8ColorPalette (FSetPalette);
// Destructor
~default8ColorPalette();
// Accessor
virtual const FString getClassName() const;
// Methods
void setColorPalette();
void resetColorPalette();
};
// default8ColorPalette inline functions
//----------------------------------------------------------------------
inline const FString default8ColorPalette::getClassName() const
{ return "default8ColorPalette"; }
/* Inheritance diagram
*
*
*
* FColorPalette
*
*
*
*
* default16ColorPalette
*
*/
//----------------------------------------------------------------------
template<typename funcT>
void FColorPalette::reset8ColorPalette (funcT set_palette)
{
reset16ColorPalette(set_palette);
}
// class default16ColorPalette
//----------------------------------------------------------------------
template<typename funcT>
void FColorPalette::reset16ColorPalette (funcT set_palette)
class default16ColorPalette final : public FColorPalette
{
set_palette (fc::Black, 0x00, 0x00, 0x00);
set_palette (fc::Blue, 0x00, 0x00, 0xaa);
set_palette (fc::Green, 0x00, 0xaa, 0x00);
set_palette (fc::Cyan, 0x00, 0x55, 0xaa);
set_palette (fc::Red, 0xaa, 0x00, 0x00);
set_palette (fc::Magenta, 0xaa, 0x00, 0xaa);
set_palette (fc::Brown, 0xaa, 0xaa, 0x00);
set_palette (fc::LightGray, 0xaa, 0xaa, 0xaa);
set_palette (fc::DarkGray, 0x55, 0x55, 0x55);
set_palette (fc::LightBlue, 0x55, 0x55, 0xff);
set_palette (fc::LightGreen, 0x55, 0xff, 0x55);
set_palette (fc::LightCyan, 0x55, 0xff, 0xff);
set_palette (fc::LightRed, 0xff, 0x55, 0x55);
set_palette (fc::LightMagenta, 0xff, 0x55, 0xff);
set_palette (fc::Yellow, 0xff, 0xff, 0x55);
set_palette (fc::White, 0xff, 0xff, 0xff);
}
public:
// Constructor
default16ColorPalette (FSetPalette);
// Destructor
~default16ColorPalette();
// Accessor
virtual const FString getClassName() const;
// Methods
void setColorPalette();
void resetColorPalette();
};
// default16ColorPalette inline functions
//----------------------------------------------------------------------
inline const FString default16ColorPalette::getClassName() const
{ return "default16ColorPalette"; }
} // namespace finalcut

View File

@ -112,12 +112,14 @@
#include <csignal>
#include <functional>
#include <map>
#include <memory>
#include <queue>
#include <utility>
#include <string>
#include <vector>
#include "final/fc.h"
#include "final/fcolorpalette.h"
#include "final/fstring.h"
#include "final/fsystem.h"
@ -125,6 +127,7 @@ namespace finalcut
{
// class forward declaration
class FColorPalette;
class FKeyboard;
class FMouseControl;
class FOptiAttr;
@ -159,6 +162,7 @@ class FTerm final
public:
// Typedef
typedef std::function<int(int)> defaultPutChar;
typedef std::shared_ptr<FColorPalette> FColorPalettePtr;
// Constructor
explicit FTerm (bool = false);
@ -182,6 +186,7 @@ class FTerm final
static const char* getTermFileName();
static int getTabstop();
static int getMaxColor();
static FColorPalettePtr& getColorPaletteTheme();
charSubstitution& getCharSubstitutionMap();
static FTermData* getFTermData();
@ -270,6 +275,8 @@ class FTerm final
static void saveColorMap();
static void resetColorMap();
static void setPalette (FColor, int, int, int);
template<typename ClassT>
static void setColorPaletteTheme (FColorPalette::FSetPalette);
static void setBeep (int, int);
static void resetBeep();
static void beep();
@ -352,6 +359,7 @@ class FTerm final
void finish();
void finishOSspecifics1();
void finish_encoding();
void destroyColorPaletteTheme();
static void setSignalHandler();
static void resetSignalHandler();
static void signal_handler (int);
@ -430,6 +438,13 @@ inline bool FTerm::setUTF8()
inline bool FTerm::unsetUTF8()
{ return setUTF8(false); }
//----------------------------------------------------------------------
template<typename ClassT>
inline void FTerm::setColorPaletteTheme (FColorPalette::FSetPalette f)
{
getColorPaletteTheme() = std::make_shared<ClassT>(f);
}
//----------------------------------------------------------------------
template<typename... Args>
inline void FTerm::putstringf (const char format[], Args&&... args)

View File

@ -146,6 +146,19 @@ class FWidgetColors
};
/* Inheritance diagram
*
*
*
* FWidgetColors
*
*
*
*
* default8ColorTheme
*
*/
//----------------------------------------------------------------------
// class default8ColorTheme
//----------------------------------------------------------------------
@ -157,13 +170,26 @@ class default8ColorTheme final : public FWidgetColors
default8ColorTheme();
// Destructor
virtual ~default8ColorTheme() override;
~default8ColorTheme() override;
// Method
void setColorTheme() override;
};
/* Inheritance diagram
*
*
*
* FWidgetColors
*
*
*
*
* default16ColorTheme
*
*/
//----------------------------------------------------------------------
// class default16ColorTheme
//----------------------------------------------------------------------
@ -175,7 +201,7 @@ class default16ColorTheme final : public FWidgetColors
default16ColorTheme();
// Destructor
virtual ~default16ColorTheme() override;
~default16ColorTheme() override;
// Method
void setColorTheme() override;