Adding a dark theme

This commit is contained in:
Markus Gans 2020-05-29 00:27:25 +02:00
parent df672dfd73
commit 1f1c6053a7
13 changed files with 422 additions and 51 deletions

View File

@ -1,3 +1,6 @@
2020-05-29 Markus Gans <guru.mail@muenster.de>
* Adding a dark theme. Can be activated with the --dark-theme parameter.
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

View File

@ -311,6 +311,8 @@ void FApplication::showParameterUsage()
<< " Set the standard vga 8x16 font\n"
<< " --newfont "
<< " Enables the graphical font\n"
<< " --dark-theme "
<< " Enables the dark theme\n"
#if defined(__FreeBSD__) || defined(__DragonFly__)
<< "\n"
@ -406,6 +408,7 @@ void FApplication::cmd_options (const int& argc, char* argv[])
{"no-sgr-optimizer", no_argument, nullptr, 0 },
{"vgafont", no_argument, nullptr, 0 },
{"newfont", no_argument, nullptr, 0 },
{"dark-theme", no_argument, nullptr, 0 },
#if defined(__FreeBSD__) || defined(__DragonFly__)
{"no-esc-for-alt-meta", no_argument, nullptr, 0 },
@ -470,6 +473,9 @@ void FApplication::cmd_options (const int& argc, char* argv[])
if ( std::strcmp(long_options[idx].name, "newfont") == 0 )
getStartOptions().newfont = true;
if ( std::strcmp(long_options[idx].name, "dark-theme") == 0 )
getStartOptions().dark_theme = true;
#if defined(__FreeBSD__) || defined(__DragonFly__)
if ( std::strcmp(long_options[idx].name, "no-esc-for-alt-meta") == 0 )
getStartOptions().meta_sends_escape = false;

View File

@ -31,7 +31,7 @@ namespace finalcut
// constructors and destructor
//----------------------------------------------------------------------
FColorPalette::FColorPalette (FSetPalette f)
FColorPalette::FColorPalette (const FSetPalette& f)
: set_palette{f}
{ }
@ -47,6 +47,26 @@ void FColorPalette::setPalette (FColor index, int r, int g, int b)
set_palette (index, r, g, b);
}
//----------------------------------------------------------------------
void FColorPalette::setVGAdefaultPalette()
{
setPalette (fc::Black, 0x00, 0x00, 0x00);
setPalette (fc::Blue, 0x00, 0x00, 0xaa);
setPalette (fc::Green, 0x00, 0xaa, 0x00);
setPalette (fc::Cyan, 0x00, 0x55, 0xaa);
setPalette (fc::Red, 0xaa, 0x00, 0x00);
setPalette (fc::Magenta, 0xaa, 0x00, 0xaa);
setPalette (fc::Brown, 0xaa, 0xaa, 0x00);
setPalette (fc::LightGray, 0xaa, 0xaa, 0xaa);
setPalette (fc::DarkGray, 0x55, 0x55, 0x55);
setPalette (fc::LightBlue, 0x55, 0x55, 0xff);
setPalette (fc::LightGreen, 0x55, 0xff, 0x55);
setPalette (fc::LightCyan, 0x55, 0xff, 0xff);
setPalette (fc::LightRed, 0xff, 0x55, 0x55);
setPalette (fc::LightMagenta, 0xff, 0x55, 0xff);
setPalette (fc::Yellow, 0xff, 0xff, 0x55);
setPalette (fc::White, 0xff, 0xff, 0xff);
}
//----------------------------------------------------------------------
// class default8ColorPalette
@ -54,7 +74,7 @@ void FColorPalette::setPalette (FColor index, int r, int g, int b)
// constructors and destructor
//----------------------------------------------------------------------
default8ColorPalette::default8ColorPalette (FSetPalette f)
default8ColorPalette::default8ColorPalette (const FSetPalette& f)
: FColorPalette(f)
{ }
@ -88,22 +108,7 @@ void default8ColorPalette::setColorPalette()
//----------------------------------------------------------------------
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);
setVGAdefaultPalette();
}
@ -113,7 +118,7 @@ void default8ColorPalette::resetColorPalette()
// constructors and destructor
//----------------------------------------------------------------------
default16ColorPalette::default16ColorPalette (FSetPalette f)
default16ColorPalette::default16ColorPalette (const FSetPalette& f)
: FColorPalette(f)
{ }
@ -146,24 +151,51 @@ void default16ColorPalette::setColorPalette()
//----------------------------------------------------------------------
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);
setVGAdefaultPalette();
}
//----------------------------------------------------------------------
// class default16DarkColorPalette
//----------------------------------------------------------------------
// constructors and destructor
//----------------------------------------------------------------------
default16DarkColorPalette::default16DarkColorPalette (const FSetPalette& f)
: FColorPalette(f)
{ }
//----------------------------------------------------------------------
default16DarkColorPalette::~default16DarkColorPalette()
{ }
// public methods of default8ColorPalette
//----------------------------------------------------------------------
void default16DarkColorPalette::setColorPalette()
{
setPalette (fc::Black, 0x00, 0x00, 0x00);
setPalette (fc::Blue, 0x41, 0x58, 0xb3);
setPalette (fc::Green, 0x18, 0x78, 0x18);
setPalette (fc::Cyan, 0x4e, 0x66, 0x72);
setPalette (fc::Red, 0xba, 0x49, 0x49);
setPalette (fc::Magenta, 0xb2, 0x18, 0xb2);
setPalette (fc::Brown, 0xe8, 0x87, 0x1f);
setPalette (fc::LightGray, 0xd2, 0xd2, 0xd2);
setPalette (fc::DarkGray, 0x27, 0x33, 0x39);
setPalette (fc::LightBlue, 0xb0, 0xb0, 0xb8);
setPalette (fc::LightGreen, 0x5e, 0xeb, 0x5c);
setPalette (fc::LightCyan, 0x62, 0xbf, 0xf8);
setPalette (fc::LightRed, 0xdd, 0x51, 0x45);
setPalette (fc::LightMagenta, 0xe9, 0xad, 0xff);
setPalette (fc::Yellow, 0xfb, 0xe8, 0x67);
setPalette (fc::White, 0xff, 0xff, 0xff);
}
//----------------------------------------------------------------------
void default16DarkColorPalette::resetColorPalette()
{
setVGAdefaultPalette();
}
} // namespace finalcut

View File

@ -51,6 +51,7 @@ FStartOptions::FStartOptions()
#elif defined(__NetBSD__) || defined(__OpenBSD__)
, meta_sends_escape{true}
#endif
, dark_theme{false}
{ }
//----------------------------------------------------------------------

View File

@ -627,7 +627,7 @@ void FStatusBar::drawKey (keyList::const_iterator iter)
if ( FTerm::hasHalfBlockCharacter() )
{
setColor (wc->statusbar_active_fg, wc->statusbar_active_bg);
setColor (wc->statusbar_bg, wc->statusbar_active_hotkey_bg);
print (fc::LeftHalfBlock); // ▐
}
else
@ -674,6 +674,7 @@ void FStatusBar::drawActiveKey (keyList::const_iterator iter)
{
print (item->getText());
x++;
setColor (wc->statusbar_bg, wc->statusbar_active_hotkey_bg);
print (fc::RightHalfBlock); // ▌
}
else

View File

@ -1888,10 +1888,17 @@ void FTerm::redefineColorPalette()
resetColorMap();
saveColorMap();
if ( FStartOptions::getFStartOptions().dark_theme )
{
setColorPaletteTheme<default16DarkColorPalette>(&FTerm::setPalette);
}
else
{
if ( getMaxColor() >= 16 )
setColorPaletteTheme<default16ColorPalette>(&FTerm::setPalette);
else // 8 colors
setColorPaletteTheme<default8ColorPalette>(&FTerm::setPalette);
}
getColorPaletteTheme()->setColorPalette();
}

View File

@ -26,6 +26,7 @@
#include "final/fevent.h"
#include "final/flog.h"
#include "final/fmenubar.h"
#include "final/fstartoptions.h"
#include "final/fstatusbar.h"
#include "final/fstring.h"
#include "final/ftermdata.h"
@ -1992,10 +1993,20 @@ void FWidget::initColorTheme()
{
// Sets the default color theme
if ( FStartOptions::getFStartOptions().dark_theme )
{
if ( FTerm::getMaxColor() < 16 ) // for 8 color mode
setColorTheme<default8ColorDarkTheme>();
else
setColorTheme<default16ColorDarkTheme>();
}
else
{
if ( FTerm::getMaxColor() < 16 ) // for 8 color mode
setColorTheme<default8ColorTheme>();
else
setColorTheme<default16ColorTheme>();
}
}
//----------------------------------------------------------------------

View File

@ -259,4 +259,219 @@ void default16ColorTheme::setColorTheme()
term_bg = fc::SkyBlue2;
}
//----------------------------------------------------------------------
// class default8ColorDarkTheme
//----------------------------------------------------------------------
// constructors and destructor
//----------------------------------------------------------------------
default8ColorDarkTheme::default8ColorDarkTheme()
{
default8ColorDarkTheme::setColorTheme();
}
//----------------------------------------------------------------------
default8ColorDarkTheme::~default8ColorDarkTheme()
{ }
// public methods of default8ColorDarkTheme
//----------------------------------------------------------------------
void default8ColorDarkTheme::setColorTheme()
{
term_fg = fc::LightGray;
term_bg = fc::Cyan;
list_fg = fc::Black;
list_bg = fc::LightGray;
selected_list_fg = fc::Cyan;
selected_list_bg = fc::LightGray;
dialog_fg = fc::Black;
dialog_resize_fg = fc::Blue;
dialog_emphasis_fg = fc::Blue;
dialog_bg = fc::LightGray;
error_box_fg = fc::LightGray;
error_box_emphasis_fg = fc::Black;
error_box_bg = fc::Red;
tooltip_fg = fc::LightGray;
tooltip_bg = fc::Black;
shadow_fg = fc::Black;
shadow_bg = fc::LightGray; // only for transparent shadow
current_element_focus_fg = fc::LightGray;
current_element_focus_bg = fc::Cyan;
current_element_fg = fc::Black;
current_element_bg = fc::Cyan;
current_inc_search_element_fg = fc::Red;
selected_current_element_focus_fg = fc::Cyan;
selected_current_element_focus_bg = fc::Cyan;
selected_current_element_fg = fc::Blue;
selected_current_element_bg = fc::Cyan;
label_fg = fc::Black;
label_bg = fc::LightGray;
label_inactive_fg = fc::Cyan;
label_inactive_bg = fc::LightGray;
label_hotkey_fg = fc::Red;
label_hotkey_bg = fc::LightGray;
label_emphasis_fg = fc::Blue;
label_ellipsis_fg = fc::Cyan;
inputfield_active_focus_fg = fc::LightGray;
inputfield_active_focus_bg = fc::Cyan;
inputfield_active_fg = fc::LightGray;
inputfield_active_bg = fc::Cyan;
inputfield_inactive_fg = fc::Cyan;
inputfield_inactive_bg = fc::LightGray;
toggle_button_active_focus_fg = fc::LightGray;
toggle_button_active_focus_bg = fc::Cyan;
toggle_button_active_fg = fc::Black;
toggle_button_active_bg = fc::LightGray;
toggle_button_inactive_fg = fc::Cyan;
toggle_button_inactive_bg = fc::LightGray;
button_active_focus_fg = fc::LightGray;
button_active_focus_bg = fc::Cyan;
button_active_fg = fc::LightGray;
button_active_bg = fc::Black;
button_inactive_fg = fc::Black;
button_inactive_bg = fc::Cyan;
button_hotkey_fg = fc::LightGray;
titlebar_active_fg = fc::LightGray;
titlebar_active_bg = fc::Black;
titlebar_inactive_fg = fc::Black;
titlebar_inactive_bg = fc::LightGray;
titlebar_button_fg = fc::Black;
titlebar_button_bg = fc::LightGray;
titlebar_button_focus_fg = fc::LightGray;
titlebar_button_focus_bg = fc::Black;
menu_active_focus_fg = fc::LightGray;
menu_active_focus_bg = fc::Blue;
menu_active_fg = fc::LightGray;
menu_active_bg = fc::Black;
menu_inactive_fg = fc::LightGray;
menu_inactive_bg = fc::Black;
menu_hotkey_fg = fc::Red;
menu_hotkey_bg = fc::Black;
statusbar_fg = fc::LightGray;
statusbar_bg = fc::Black;
statusbar_hotkey_fg = fc::Red;
statusbar_hotkey_bg = fc::Black;
statusbar_separator_fg = fc::LightGray;
statusbar_active_fg = fc::LightGray;
statusbar_active_bg = fc::Blue;
statusbar_active_hotkey_fg = fc::Red;
statusbar_active_hotkey_bg = fc::Blue;
scrollbar_fg = fc::Cyan;
scrollbar_bg = fc::LightGray;
scrollbar_button_fg = fc::Black;
scrollbar_button_bg = fc::LightGray;
scrollbar_button_inactive_fg = fc::Cyan;
scrollbar_button_inactive_bg = fc::LightGray;
progressbar_fg = fc::Cyan;
progressbar_bg = fc::LightGray;
}
//----------------------------------------------------------------------
// class default16ColorDarkTheme
//----------------------------------------------------------------------
// constructors and destructor
//----------------------------------------------------------------------
default16ColorDarkTheme::default16ColorDarkTheme()
{
default16ColorDarkTheme::setColorTheme();
}
//----------------------------------------------------------------------
default16ColorDarkTheme::~default16ColorDarkTheme()
{ }
// public methods of default16ColorDarkTheme
//----------------------------------------------------------------------
void default16ColorDarkTheme::setColorTheme()
{
term_fg = fc::White;
term_bg = fc::Cyan;
list_fg = fc::Black;
list_bg = fc::LightGray;
selected_list_fg = fc::Red;
selected_list_bg = fc::LightGray;
dialog_fg = fc::Black;
dialog_resize_fg = fc::LightBlue;
dialog_emphasis_fg = fc::Blue;
dialog_bg = fc::LightGray;
error_box_fg = fc::White;
error_box_emphasis_fg = fc::Yellow;
error_box_bg = fc::Red;
tooltip_fg = fc::White;
tooltip_bg = fc::Black;
shadow_fg = fc::Black;
shadow_bg = fc::LightGray; // only for transparent shadow
current_element_focus_fg = fc::White;
current_element_focus_bg = fc::Cyan;
current_element_fg = fc::LightBlue;
current_element_bg = fc::Cyan;
current_inc_search_element_fg = fc::LightRed;
selected_current_element_focus_fg = fc::LightRed;
selected_current_element_focus_bg = fc::Cyan;
selected_current_element_fg = fc::Red;
selected_current_element_bg = fc::Cyan;
label_fg = fc::Black;
label_bg = fc::LightGray;
label_inactive_fg = fc::DarkGray;
label_inactive_bg = fc::LightGray;
label_hotkey_fg = fc::Red;
label_hotkey_bg = fc::LightGray;
label_emphasis_fg = fc::Blue;
label_ellipsis_fg = fc::DarkGray;
inputfield_active_focus_fg = fc::White;
inputfield_active_focus_bg = fc::Cyan;
inputfield_active_fg = fc::White;
inputfield_active_bg = fc::DarkGray;
inputfield_inactive_fg = fc::DarkGray;
inputfield_inactive_bg = fc::LightGray;
toggle_button_active_focus_fg = fc::White;
toggle_button_active_focus_bg = fc::Cyan;
toggle_button_active_fg = fc::Black;
toggle_button_active_bg = fc::LightGray;
toggle_button_inactive_fg = fc::DarkGray;
toggle_button_inactive_bg = fc::LightGray;
button_active_focus_fg = fc::LightGray;
button_active_focus_bg = fc::Cyan;
button_active_fg = fc::LightGray;
button_active_bg = fc::DarkGray;
button_inactive_fg = fc::DarkGray;
button_inactive_bg = fc::LightBlue;
button_hotkey_fg = fc::White;
titlebar_active_fg = fc::White;
titlebar_active_bg = fc::DarkGray;
titlebar_inactive_fg = fc::DarkGray;
titlebar_inactive_bg = fc::LightGray;
titlebar_button_fg = fc::DarkGray;
titlebar_button_bg = fc::LightGray;
titlebar_button_focus_fg = fc::LightGray;
titlebar_button_focus_bg = fc::Black;
menu_active_focus_fg = fc::White;
menu_active_focus_bg = fc::Blue;
menu_active_fg = fc::White;
menu_active_bg = fc::DarkGray;
menu_inactive_fg = fc::LightGray;
menu_inactive_bg = fc::DarkGray;
menu_hotkey_fg = fc::LightRed;
menu_hotkey_bg = fc::DarkGray;
statusbar_fg = fc::White;
statusbar_bg = fc::DarkGray;
statusbar_hotkey_fg = fc::LightRed;
statusbar_hotkey_bg = fc::DarkGray;
statusbar_separator_fg = fc::LightGray;
statusbar_active_fg = fc::White;
statusbar_active_bg = fc::Blue;
statusbar_active_hotkey_fg = fc::LightRed;
statusbar_active_hotkey_bg = fc::Blue;
scrollbar_fg = fc::DarkGray;
scrollbar_bg = fc::LightBlue;
scrollbar_button_fg = fc::Black;
scrollbar_button_bg = fc::LightBlue;
scrollbar_button_inactive_fg = fc::DarkGray;
scrollbar_button_inactive_bg = fc::LightGray;
progressbar_fg = fc::DarkGray;
progressbar_bg = fc::LightBlue;
}
} // namespace finalcut

View File

@ -882,7 +882,8 @@ void closeDropDown (FWidget* widget, const FPoint& mouse_position)
if ( ! openmenu )
return;
if ( openmenu->isInstanceOf("FMenu") )
if ( openmenu->isInstanceOf("FMenu")
|| openmenu->isInstanceOf("FDialogListMenu") )
{
bool contains_menu_structure;
auto menu = static_cast<FMenu*>(openmenu);

View File

@ -53,7 +53,7 @@ class FColorPalette
typedef std::function<void(FColor, int, int, int)> FSetPalette;
// Constructor
FColorPalette(FSetPalette);
explicit FColorPalette (const FSetPalette&);
// Destructor
virtual ~FColorPalette();
@ -67,7 +67,9 @@ class FColorPalette
protected:
void setPalette (FColor, int, int, int);
void setVGAdefaultPalette();
private:
// Data members
FSetPalette set_palette;
};
@ -99,13 +101,13 @@ class default8ColorPalette final : public FColorPalette
{
public:
// Constructor
default8ColorPalette (FSetPalette);
explicit default8ColorPalette (const FSetPalette&);
// Destructor
~default8ColorPalette();
// Accessor
virtual const FString getClassName() const;
const FString getClassName() const override;
// Methods
void setColorPalette();
@ -139,13 +141,13 @@ class default16ColorPalette final : public FColorPalette
{
public:
// Constructor
default16ColorPalette (FSetPalette);
explicit default16ColorPalette (const FSetPalette&);
// Destructor
~default16ColorPalette();
// Accessor
virtual const FString getClassName() const;
const FString getClassName() const override;
// Methods
void setColorPalette();
@ -157,6 +159,33 @@ class default16ColorPalette final : public FColorPalette
inline const FString default16ColorPalette::getClassName() const
{ return "default16ColorPalette"; }
//----------------------------------------------------------------------
// class default16DarkColorPalette
//----------------------------------------------------------------------
class default16DarkColorPalette final : public FColorPalette
{
public:
// Constructor
explicit default16DarkColorPalette (const FSetPalette&);
// Destructor
~default16DarkColorPalette();
// Accessor
const FString getClassName() const override;
// Methods
void setColorPalette();
void resetColorPalette();
};
// default16ColorPalette inline functions
//----------------------------------------------------------------------
inline const FString default16DarkColorPalette::getClassName() const
{ return "default16DarkColorPalette"; }
} // namespace finalcut
#endif // FCOLORPALETTE_H

View File

@ -93,6 +93,8 @@ class FStartOptions final
uInt8 : 7; // padding bits
#endif
uInt16 dark_theme : 1;
uInt16 : 15; // padding bits
static FStartOptions* start_options;
};

View File

@ -163,6 +163,7 @@ class FTerm final
// Typedef
typedef std::function<int(int)> defaultPutChar;
typedef std::shared_ptr<FColorPalette> FColorPalettePtr;
typedef FColorPalette::FSetPalette FSetPalette;
// Constructor
explicit FTerm (bool = false);
@ -276,7 +277,7 @@ class FTerm final
static void resetColorMap();
static void setPalette (FColor, int, int, int);
template<typename ClassT>
static void setColorPaletteTheme (FColorPalette::FSetPalette);
static void setColorPaletteTheme (const FSetPalette&);
static void setBeep (int, int);
static void resetBeep();
static void beep();
@ -440,7 +441,7 @@ inline bool FTerm::unsetUTF8()
//----------------------------------------------------------------------
template<typename ClassT>
inline void FTerm::setColorPaletteTheme (FColorPalette::FSetPalette f)
inline void FTerm::setColorPaletteTheme (const FSetPalette& f)
{
getColorPaletteTheme() = std::make_shared<ClassT>(f);
}

View File

@ -207,6 +207,68 @@ class default16ColorTheme final : public FWidgetColors
void setColorTheme() override;
};
/* Inheritance diagram
*
*
*
* FWidgetColors
*
*
*
*
* default8ColorDarkTheme
*
*/
//----------------------------------------------------------------------
// class default8ColorDarkTheme
//----------------------------------------------------------------------
class default8ColorDarkTheme final : public FWidgetColors
{
public:
// Constructor
default8ColorDarkTheme();
// Destructor
~default8ColorDarkTheme() override;
// Method
void setColorTheme() override;
};
/* Inheritance diagram
*
*
*
* FWidgetColors
*
*
*
*
* default16ColorDarkTheme
*
*/
//----------------------------------------------------------------------
// class default16ColorDarkTheme
//----------------------------------------------------------------------
class default16ColorDarkTheme final : public FWidgetColors
{
public:
// Constructor
default16ColorDarkTheme();
// Destructor
~default16ColorDarkTheme() override;
// Method
void setColorTheme() override;
};
} // namespace finalcut
#endif // FWIDGETCOLORS_H