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> 2020-05-26 Markus Gans <guru.mail@muenster.de>
* FWidgetColors now uses polymorphism, so you can now easily * FWidgetColors now uses polymorphism, so you can now easily
create your own widget color theme create your own widget color theme

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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