From f76a9d21149ceb10963ca13a4025d05722d61c9b Mon Sep 17 00:00:00 2001 From: Markus Gans Date: Sat, 30 May 2020 23:02:53 +0200 Subject: [PATCH] Added FApplication::setDarkTheme() and FApplication::setDefaultTheme() --- ChangeLog | 6 ++ examples/opti-move.cpp | 40 +++++++++++++- examples/ui.cpp | 28 ++++++++++ src/fapplication.cpp | 31 +++++++++++ src/fbutton.cpp | 14 +++++ src/fbuttongroup.cpp | 5 +- src/fcheckbox.cpp | 2 +- src/fcolorpalette.cpp | 2 +- src/fdialog.cpp | 13 ++++- src/flabel.cpp | 15 +---- src/flineedit.cpp | 92 +++++++++++-------------------- src/flistbox.cpp | 6 +- src/flistview.cpp | 5 +- src/fmenu.cpp | 14 +++-- src/fmenubar.cpp | 13 ++++- src/foptimove.cpp | 75 +++++++++++++------------ src/fprogressbar.cpp | 12 +--- src/fradiobutton.cpp | 2 +- src/fscrollbar.cpp | 2 +- src/fscrollview.cpp | 13 ++++- src/fstatusbar.cpp | 13 ++++- src/fstringstream.cpp | 2 +- src/fterm.cpp | 14 ++--- src/ftextview.cpp | 13 ++++- src/ftogglebutton.cpp | 48 +++++++++------- src/ftooltip.cpp | 13 ++++- src/fwidget.cpp | 36 ++++++++++++ src/fwidgetcolors.cpp | 4 +- src/include/final/fapplication.h | 2 + src/include/final/fbutton.h | 1 + src/include/final/fdialog.h | 1 + src/include/final/flineedit.h | 1 + src/include/final/fmenu.h | 1 + src/include/final/fmenubar.h | 1 + src/include/final/fscrollview.h | 1 + src/include/final/fstatusbar.h | 1 + src/include/final/fstringstream.h | 2 +- src/include/final/fterm.h | 1 + src/include/final/ftextview.h | 1 + src/include/final/ftogglebutton.h | 1 + src/include/final/ftooltip.h | 1 + src/include/final/fwidget.h | 2 + 42 files changed, 358 insertions(+), 192 deletions(-) diff --git a/ChangeLog b/ChangeLog index 6dbcc9a3..f0701d49 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,9 @@ +2020-05-30 Markus Gans + * With the two new methods FApplication::setDarkTheme() and + FApplication::setDefaultTheme() you can now change the theme + within an application. An example can be found in examples/ui + via the menu items "View" -> "Dark mode". + 2020-05-29 Markus Gans * Adding a dark theme. Can be activated with the --dark-theme parameter. diff --git a/examples/opti-move.cpp b/examples/opti-move.cpp index b2eebf10..ed6061a1 100644 --- a/examples/opti-move.cpp +++ b/examples/opti-move.cpp @@ -132,6 +132,40 @@ void move (int xold, int yold, int xnew, int ynew) << std::right << std::setw(10) << byte << "\r\n"; } +//---------------------------------------------------------------------- +class DirectLogger : public finalcut::FLog +{ + public: + void info (const std::string& entry) override + { + output << entry << "\r" << std::endl; + } + + void warn (const std::string&) override + { } + + void error (const std::string&) override + { } + + void debug (const std::string&) override + { } + + void setOutputStream (const std::ostream& os) override + { output.rdbuf(os.rdbuf()); } + + void setLineEnding (LineEnding) override + { } + + void enableTimestamp() override + { } + + void disableTimestamp() override + { } + + private: + // Data member + std::ostream output{std::cerr.rdbuf()}; +}; //---------------------------------------------------------------------- // main part @@ -189,7 +223,11 @@ int main (int argc, char* argv[]) keyPressed(); // Show terminal speed and milliseconds for all cursor movement sequence - std::cout << "\r" << line; + std::cout << "\r" << line << std::flush; + // Generation of a logger in a shared_ptr via a pointer + finalcut::FApplication::setLog(std::make_shared()); + // Get the shared_ptr with the base class + std::shared_ptr log = finalcut::FApplication::getLog(); const finalcut::FOptiMove& opti_move = *finalcut::FTerm::getFOptiMove(); finalcut::printDurations(opti_move); diff --git a/examples/ui.cpp b/examples/ui.cpp index f20ae301..9e696d09 100644 --- a/examples/ui.cpp +++ b/examples/ui.cpp @@ -301,6 +301,7 @@ class MyDialog final : public finalcut::FDialog void cb_copyClipboard (const finalcut::FWidget*, const FDataPtr); void cb_pasteClipboard (const finalcut::FWidget*, const FDataPtr); void cb_clearInput (const finalcut::FWidget*, const FDataPtr); + void cb_switchTheme (const finalcut::FWidget*, const FDataPtr); void cb_input2buttonText (finalcut::FWidget*, FDataPtr); void cb_setTitlebar (finalcut::FWidget*, const FDataPtr); void cb_showProgressBar (const finalcut::FWidget*, const FDataPtr); @@ -339,6 +340,8 @@ class MyDialog final : public finalcut::FDialog // "View" menu items finalcut::FMenuItem Env{"&Terminal...", &View}; finalcut::FMenuItem Drive{"&Drive symbols...", &View}; + finalcut::FMenuItem Line3{&View}; + finalcut::FCheckMenuItem Theme{"Dark &mode", &View}; // Statusbar finalcut::FStatusBar Statusbar{this}; finalcut::FStatusKey key_F1{fc::Fkey_f1, "About", &Statusbar}; @@ -422,6 +425,10 @@ void MyDialog::initMenu() // "View" menu items Env.setStatusbarMessage ("Informations about this terminal"); Drive.setStatusbarMessage ("Show drive symbols"); + Line3.setSeparator(); + + if ( finalcut::FStartOptions::getFStartOptions().dark_theme ) + Theme.setChecked(); } //---------------------------------------------------------------------- @@ -517,6 +524,12 @@ void MyDialog::initViewMenuCallbacks() "clicked", F_METHOD_CALLBACK (this, &MyDialog::cb_drives) ); + + Theme.addCallback + ( + "clicked", + F_METHOD_CALLBACK (this, &MyDialog::cb_switchTheme) + ); } //---------------------------------------------------------------------- @@ -902,6 +915,21 @@ void MyDialog::cb_clearInput (const finalcut::FWidget*, const FDataPtr) myLineEdit.redraw(); } +//---------------------------------------------------------------------- +void MyDialog::cb_switchTheme (const finalcut::FWidget* widget, const FDataPtr) +{ + const auto& check_menu = *(static_cast(widget)); + + if ( check_menu.isChecked() ) + finalcut::FApplication::setDarkTheme(); + else + finalcut::FApplication::setDefaultTheme(); + + auto root_widget = getRootWidget(); + root_widget->resetColors(); + root_widget->redraw(); +} + //---------------------------------------------------------------------- void MyDialog::cb_input2buttonText (finalcut::FWidget* widget, FDataPtr data) { diff --git a/src/fapplication.cpp b/src/fapplication.cpp index 9087cbd9..1278b856 100644 --- a/src/fapplication.cpp +++ b/src/fapplication.cpp @@ -282,6 +282,37 @@ FWidget* FApplication::processParameters (const int& argc, char* argv[]) return nullptr; } +//---------------------------------------------------------------------- +void FApplication::setDefaultTheme() +{ + if ( FTerm::getMaxColor() < 16 ) // for 8 color mode + { + if ( getStartOptions().color_change ) + FTerm::setColorPaletteTheme(&FTerm::setPalette); + + setColorTheme(); + } + else + { + if ( getStartOptions().color_change ) + FTerm::setColorPaletteTheme(&FTerm::setPalette); + + setColorTheme(); + } +} + +//---------------------------------------------------------------------- +void FApplication::setDarkTheme() +{ + if ( getStartOptions().color_change ) + FTerm::setColorPaletteTheme(&FTerm::setPalette); + + if ( FTerm::getMaxColor() < 16 ) // for 8 color mode + setColorTheme(); + else + setColorTheme(); +} + //---------------------------------------------------------------------- void FApplication::showParameterUsage() { diff --git a/src/fbutton.cpp b/src/fbutton.cpp index 498c201b..f970fa0a 100644 --- a/src/fbutton.cpp +++ b/src/fbutton.cpp @@ -127,6 +127,20 @@ void FButton::setInactiveBackgroundColor (FColor color) updateButtonColor(); } +//---------------------------------------------------------------------- +void FButton::resetColors() +{ + const auto& wc = getColorTheme(); + setForegroundColor (wc->button_active_fg); + setBackgroundColor (wc->button_active_bg); + setHotkeyForegroundColor (wc->button_hotkey_fg); + setFocusForegroundColor (wc->button_active_focus_fg); + setFocusBackgroundColor (wc->button_active_focus_bg); + setInactiveForegroundColor (wc->button_inactive_fg); + setInactiveBackgroundColor (wc->button_inactive_bg); + FWidget::resetColors(); +} + //---------------------------------------------------------------------- bool FButton::setNoUnderline (bool enable) { diff --git a/src/fbuttongroup.cpp b/src/fbuttongroup.cpp index 54a35c0e..85943373 100644 --- a/src/fbuttongroup.cpp +++ b/src/fbuttongroup.cpp @@ -383,7 +383,7 @@ void FButtonGroup::draw() if ( FTerm::isMonochron() ) setReverse(true); - setColor(); + useParentWidgetColor(); clearArea(); if ( FTerm::isMonochron() ) @@ -427,9 +427,6 @@ bool FButtonGroup::isRadioButton (const FToggleButton* button) const //---------------------------------------------------------------------- void FButtonGroup::init() { - const auto& wc = getColorTheme(); - setForegroundColor (wc->label_fg); - setBackgroundColor (wc->label_bg); setMinimumSize (FSize{7, 3}); buttonlist.clear(); // no buttons yet } diff --git a/src/fcheckbox.cpp b/src/fcheckbox.cpp index 44ba8b57..1e6f6c27 100644 --- a/src/fcheckbox.cpp +++ b/src/fcheckbox.cpp @@ -74,7 +74,7 @@ void FCheckBox::draw() void FCheckBox::drawCheckButton() { print() << FPoint{1, 1}; - setColor(); + useParentWidgetColor(); if ( FTerm::isMonochron() ) { diff --git a/src/fcolorpalette.cpp b/src/fcolorpalette.cpp index bbcdf73a..ab003a40 100644 --- a/src/fcolorpalette.cpp +++ b/src/fcolorpalette.cpp @@ -177,7 +177,7 @@ void default16DarkColorPalette::setColorPalette() 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::Red, 0xa5, 0x40, 0x40); setPalette (fc::Magenta, 0xb2, 0x18, 0xb2); setPalette (fc::Brown, 0xe8, 0x87, 0x1f); setPalette (fc::LightGray, 0xd2, 0xd2, 0xd2); diff --git a/src/fdialog.cpp b/src/fdialog.cpp index eeb46d5a..c34a3d5c 100644 --- a/src/fdialog.cpp +++ b/src/fdialog.cpp @@ -136,6 +136,15 @@ bool FDialog::setBorder (bool enable) return (setFlags().no_border = ! enable); } +//---------------------------------------------------------------------- +void FDialog::resetColors() +{ + const auto& wc = getColorTheme(); + setForegroundColor (wc->dialog_fg); + setBackgroundColor (wc->dialog_bg); + FWidget::resetColors(); +} + //---------------------------------------------------------------------- bool FDialog::setResizeable (bool enable) { @@ -800,9 +809,7 @@ void FDialog::init() addDialog(this); setActiveWindow(this); setTransparentShadow(); - const auto& wc = getColorTheme(); - setForegroundColor (wc->dialog_fg); - setBackgroundColor (wc->dialog_bg); + resetColors(); auto old_focus = FWidget::getFocusWidget(); if ( old_focus ) diff --git a/src/flabel.cpp b/src/flabel.cpp index dc3f143f..51d5881a 100644 --- a/src/flabel.cpp +++ b/src/flabel.cpp @@ -246,20 +246,7 @@ void FLabel::cb_accelWidgetDestroyed (const FWidget*, const FDataPtr) //---------------------------------------------------------------------- void FLabel::init() { - const auto& parent_widget = getParentWidget(); unsetFocusable(); - - if ( parent_widget ) - { - setForegroundColor (parent_widget->getForegroundColor()); - setBackgroundColor (parent_widget->getBackgroundColor()); - } - else - { - const auto& wc = getColorTheme(); - setForegroundColor (wc->dialog_fg); - setBackgroundColor (wc->dialog_bg); - } } //---------------------------------------------------------------------- @@ -303,6 +290,8 @@ void FLabel::draw() if ( text.isEmpty() ) return; + useParentWidgetColor(); + if ( FTerm::isMonochron() ) { setReverse(true); diff --git a/src/flineedit.cpp b/src/flineedit.cpp index 640c7a42..47d05fc7 100644 --- a/src/flineedit.cpp +++ b/src/flineedit.cpp @@ -99,28 +99,8 @@ const FLineEdit& FLineEdit::operator >> (FString& s) //---------------------------------------------------------------------- bool FLineEdit::setEnable (bool enable) { - const auto& wc = getColorTheme(); FWidget::setEnable(enable); - - if ( enable ) - { - if ( hasFocus() ) - { - setForegroundColor (wc->inputfield_active_focus_fg); - setBackgroundColor (wc->inputfield_active_focus_bg); - } - else - { - setForegroundColor (wc->inputfield_active_fg); - setBackgroundColor (wc->inputfield_active_bg); - } - } - else - { - setForegroundColor (wc->inputfield_inactive_fg); - setBackgroundColor (wc->inputfield_inactive_bg); - } - + resetColors(); return enable; } @@ -128,23 +108,7 @@ bool FLineEdit::setEnable (bool enable) bool FLineEdit::setFocus (bool enable) { FWidget::setFocus(enable); - - if ( isEnabled() ) - { - const auto& wc = getColorTheme(); - - if ( enable ) - { - setForegroundColor (wc->inputfield_active_focus_fg); - setBackgroundColor (wc->inputfield_active_focus_bg); - } - else - { - setForegroundColor (wc->inputfield_active_fg); - setBackgroundColor (wc->inputfield_active_bg); - } - } - + resetColors(); return enable; } @@ -255,6 +219,34 @@ void FLineEdit::setLabelOrientation (const label_o o) adjustLabel(); } +//---------------------------------------------------------------------- +void FLineEdit::resetColors() +{ + const auto& wc = getColorTheme(); + + if ( isEnabled() ) // active + { + if ( hasFocus() ) + { + setForegroundColor (wc->inputfield_active_focus_fg); + setBackgroundColor (wc->inputfield_active_focus_bg); + } + else + { + setForegroundColor (wc->inputfield_active_fg); + setBackgroundColor (wc->inputfield_active_bg); + } + } + else // inactive + { + setForegroundColor (wc->inputfield_inactive_fg); + setBackgroundColor (wc->inputfield_inactive_bg); + } + + FWidget::resetColors(); +} + + //---------------------------------------------------------------------- void FLineEdit::setSize (const FSize& size, bool adjust) { @@ -655,34 +647,14 @@ void FLineEdit::adjustSize() //---------------------------------------------------------------------- void FLineEdit::init() { - const auto& wc = getColorTheme(); label->setAccelWidget(this); + setShadow(); + resetColors(); if ( isReadOnly() ) unsetVisibleCursor(); else setVisibleCursor(); - - setShadow(); - - if ( isEnabled() ) - { - if ( hasFocus() ) - { - setForegroundColor (wc->inputfield_active_focus_fg); - setBackgroundColor (wc->inputfield_active_focus_bg); - } - else - { - setForegroundColor (wc->inputfield_active_fg); - setBackgroundColor (wc->inputfield_active_bg); - } - } - else // inactive - { - setForegroundColor (wc->inputfield_inactive_fg); - setBackgroundColor (wc->inputfield_inactive_bg); - } } //---------------------------------------------------------------------- diff --git a/src/flistbox.cpp b/src/flistbox.cpp index c718aa0f..8211a6a1 100644 --- a/src/flistbox.cpp +++ b/src/flistbox.cpp @@ -655,9 +655,6 @@ void FListBox::init() initScrollbar (vbar, fc::vertical, this, &FListBox::cb_vbarChange); initScrollbar (hbar, fc::horizontal, this, &FListBox::cb_hbarChange); setGeometry (FPoint{1, 1}, FSize{5, 4}, false); // initialize geometry values - const auto& wc = getColorTheme(); - setForegroundColor (wc->dialog_fg); - setBackgroundColor (wc->dialog_bg); nf_offset = FTerm::isNewFont() ? 1 : 0; setTopPadding(1); setLeftPadding(1); @@ -722,7 +719,8 @@ void FListBox::draw() if ( current < 1 ) current = 1; - setColor(); + useParentWidgetColor(); + if ( FTerm::isMonochron() ) setReverse(true); diff --git a/src/flistview.cpp b/src/flistview.cpp index eff0293a..a4226a0c 100644 --- a/src/flistview.cpp +++ b/src/flistview.cpp @@ -1523,9 +1523,6 @@ void FListView::init() root = selflist.begin(); getNullIterator() = selflist.end(); setGeometry (FPoint{1, 1}, FSize{5, 4}, false); // initialize geometry values - const auto& wc = getColorTheme(); - setForegroundColor (wc->dialog_fg); - setBackgroundColor (wc->dialog_bg); nf_offset = FTerm::isNewFont() ? 1 : 0; setTopPadding(1); setLeftPadding(1); @@ -1637,7 +1634,7 @@ void FListView::draw() if ( current_iter.getPosition() < 1 ) current_iter = itemlist.begin(); - setColor(); + useParentWidgetColor(); if ( FTerm::isMonochron() ) setReverse(true); diff --git a/src/fmenu.cpp b/src/fmenu.cpp index a525fc61..060bc3d1 100644 --- a/src/fmenu.cpp +++ b/src/fmenu.cpp @@ -83,6 +83,15 @@ void FMenu::setStatusbarMessage (const FString& msg) menuitem.setStatusbarMessage(msg); } +//---------------------------------------------------------------------- +void FMenu::resetColors() +{ + const auto& wc = getColorTheme(); + setForegroundColor (wc->menu_active_fg); + setBackgroundColor (wc->menu_active_bg); + FWidget::resetColors(); +} + //---------------------------------------------------------------------- void FMenu::show() { @@ -458,10 +467,7 @@ void FMenu::init(FWidget* parent) setTransparentShadow(); setMenuWidget(); hide(); - - const auto& wc = getColorTheme(); - setForegroundColor (wc->menu_active_fg); - setBackgroundColor (wc->menu_active_bg); + resetColors(); menuitem.setMenu(this); if ( parent ) diff --git a/src/fmenubar.cpp b/src/fmenubar.cpp index cda7f659..5923248a 100644 --- a/src/fmenubar.cpp +++ b/src/fmenubar.cpp @@ -55,6 +55,15 @@ FMenuBar::~FMenuBar() // destructor // public methods of FMenuBar +//---------------------------------------------------------------------- +void FMenuBar::resetColors() +{ + const auto& wc = getColorTheme(); + setForegroundColor (wc->menu_active_fg); + setBackgroundColor (wc->menu_active_bg); + FWidget::resetColors(); +} + //---------------------------------------------------------------------- void FMenuBar::resetMenu() { @@ -249,9 +258,7 @@ void FMenuBar::init() addAccelerator (fc::Fkey_f10); addAccelerator (fc::Fckey_space); - const auto& wc = getColorTheme(); - setForegroundColor (wc->menu_active_fg); - setBackgroundColor (wc->menu_active_bg); + resetColors(); unsetFocusable(); } diff --git a/src/foptimove.cpp b/src/foptimove.cpp index 083b071f..dcafbcf0 100644 --- a/src/foptimove.cpp +++ b/src/foptimove.cpp @@ -22,7 +22,9 @@ #include +#include "final/fapplication.h" #include "final/fc.h" +#include "final/flog.h" #include "final/foptimove.h" #include "final/ftermcap.h" @@ -1105,42 +1107,43 @@ void FOptiMove::moveByMethod ( int method //---------------------------------------------------------------------- void printDurations (const FOptiMove& om) { - std::cout << " speed: " - << om.baudrate << " baud\r\n"; - std::cout << " char_duration: " - << om.char_duration << " ms\r\n"; - std::cout << " cursor_home: " - << om.F_cursor_home.duration << " ms\r\n"; - std::cout << " cursor_to_ll: " - << om.F_cursor_to_ll.duration << " ms\r\n"; - std::cout << " carriage_return: " - << om.F_carriage_return.duration << " ms\r\n"; - std::cout << " tab: " - << om.F_tab.duration << " ms\r\n"; - std::cout << " back_tab: " - << om.F_back_tab.duration << " ms\r\n"; - std::cout << " cursor_up: " - << om.F_cursor_up.duration << " ms\r\n"; - std::cout << " cursor_down: " - << om.F_cursor_down.duration << " ms\r\n"; - std::cout << " cursor_left: " - << om.F_cursor_left.duration << " ms\r\n"; - std::cout << " cursor_right: " - << om.F_cursor_right.duration << " ms\r\n"; - std::cout << " cursor_address: " - << om.F_cursor_address.duration << " ms\r\n"; - std::cout << " column_address: " - << om.F_column_address.duration << " ms\r\n"; - std::cout << " row_address: " - << om.F_row_address.duration << " ms\r\n"; - std::cout << " parm_up_cursor: " - << om.F_parm_up_cursor.duration << " ms\r\n"; - std::cout << " parm_down_cursor: " - << om.F_parm_down_cursor.duration << " ms\r\n"; - std::cout << " parm_left_cursor: " - << om.F_parm_left_cursor.duration << " ms\r\n"; - std::cout << "parm_right_cursor: " - << om.F_parm_right_cursor.duration << " ms\r\n"; + finalcut::FLog& log = *FApplication::getLog(); + log << " speed: " + << om.baudrate << " baud" << std::flush; + log << " char_duration: " + << om.char_duration << " ms" << std::flush; + log << " cursor_home: " + << om.F_cursor_home.duration << " ms" << std::flush; + log << " cursor_to_ll: " + << om.F_cursor_to_ll.duration << " ms" << std::flush; + log << " carriage_return: " + << om.F_carriage_return.duration << " ms" << std::flush; + log << " tab: " + << om.F_tab.duration << " ms" << std::flush; + log << " back_tab: " + << om.F_back_tab.duration << " ms" << std::flush; + log << " cursor_up: " + << om.F_cursor_up.duration << " ms" << std::flush; + log << " cursor_down: " + << om.F_cursor_down.duration << " ms" << std::flush; + log << " cursor_left: " + << om.F_cursor_left.duration << " ms" << std::flush; + log << " cursor_right: " + << om.F_cursor_right.duration << " ms" << std::flush; + log << " cursor_address: " + << om.F_cursor_address.duration << " ms" << std::flush; + log << " column_address: " + << om.F_column_address.duration << " ms" << std::flush; + log << " row_address: " + << om.F_row_address.duration << " ms" << std::flush; + log << " parm_up_cursor: " + << om.F_parm_up_cursor.duration << " ms" << std::flush; + log << " parm_down_cursor: " + << om.F_parm_down_cursor.duration << " ms" << std::flush; + log << " parm_left_cursor: " + << om.F_parm_left_cursor.duration << " ms" << std::flush; + log << "parm_right_cursor: " + << om.F_parm_right_cursor.duration << " ms" << std::flush; } } // namespace finalcut diff --git a/src/fprogressbar.cpp b/src/fprogressbar.cpp index 52a28250..b006546a 100644 --- a/src/fprogressbar.cpp +++ b/src/fprogressbar.cpp @@ -148,20 +148,10 @@ void FProgressbar::draw() //---------------------------------------------------------------------- void FProgressbar::drawProgressLabel() { - const auto& parent_widget = getParentWidget(); - - if ( parent_widget ) - setColor ( parent_widget->getForegroundColor() - , parent_widget->getBackgroundColor() ); - else - { - const auto& wc = getColorTheme(); - setColor (wc->dialog_fg, wc->dialog_bg); - } - if ( FTerm::isMonochron() ) setReverse(true); + useParentWidgetColor(); print() << FPoint{int(getWidth()) - 3, 0}; if ( percentage > 100 ) diff --git a/src/fradiobutton.cpp b/src/fradiobutton.cpp index 5f511b6b..08707354 100644 --- a/src/fradiobutton.cpp +++ b/src/fradiobutton.cpp @@ -74,7 +74,7 @@ void FRadioButton::draw() void FRadioButton::drawRadioButton() { print() << FPoint{1, 1}; - setColor(); + useParentWidgetColor(); if ( FTerm::isMonochron() ) { diff --git a/src/fscrollbar.cpp b/src/fscrollbar.cpp index ecf0cd8c..c8e6c7e8 100644 --- a/src/fscrollbar.cpp +++ b/src/fscrollbar.cpp @@ -512,7 +512,7 @@ inline void FScrollbar::drawVerticalBackgroundLine() if ( FTerm::isMonochron() || max_color < 16 ) print (fc::MediumShade); // ▒ else if ( FTerm::isNewFont() ) - print (fc::NF_rev_border_line_right); // ⎹ + print (fc::NF_rev_border_line_right); //⎹ else print (' '); } diff --git a/src/fscrollview.cpp b/src/fscrollview.cpp index 1408527f..cbc11031 100644 --- a/src/fscrollview.cpp +++ b/src/fscrollview.cpp @@ -293,6 +293,15 @@ bool FScrollView::setViewportPrint (bool enable) return (use_own_print_area = ! enable); } +//---------------------------------------------------------------------- +void FScrollView::resetColors() +{ + const auto& wc = getColorTheme(); + setForegroundColor (wc->dialog_fg); + setBackgroundColor (wc->dialog_bg); + FWidget::resetColors(); +} + //---------------------------------------------------------------------- bool FScrollView::setBorder (bool enable) { @@ -712,9 +721,7 @@ void FScrollView::init (const FWidget* parent) initScrollbar (vbar, fc::vertical, &FScrollView::cb_vbarChange); initScrollbar (hbar, fc::horizontal, &FScrollView::cb_hbarChange); mapKeyFunctions(); - const auto& wc = getColorTheme(); - setForegroundColor (wc->dialog_fg); - setBackgroundColor (wc->dialog_bg); + resetColors(); setGeometry (FPoint{1, 1}, FSize{4, 4}); setMinimumSize (FSize{4, 4}); const int xoffset_end = int(getScrollWidth() - getViewportWidth()); diff --git a/src/fstatusbar.cpp b/src/fstatusbar.cpp index afbe3649..a2ec6983 100644 --- a/src/fstatusbar.cpp +++ b/src/fstatusbar.cpp @@ -158,6 +158,15 @@ void FStatusBar::setMessage (const FString& mgs) text.setString(mgs); } +//---------------------------------------------------------------------- +void FStatusBar::resetColors() +{ + const auto& wc = getColorTheme(); + setForegroundColor (wc->statusbar_fg); + setBackgroundColor (wc->statusbar_bg); + FWidget::resetColors(); +} + //---------------------------------------------------------------------- bool FStatusBar::hasActivatedKey() const { @@ -513,9 +522,7 @@ void FStatusBar::init() if ( getRootWidget() ) getRootWidget()->setBottomPadding(1, true); - const auto& wc = getColorTheme(); - setForegroundColor (wc->statusbar_fg); - setBackgroundColor (wc->statusbar_bg); + resetColors(); unsetFocusable(); } diff --git a/src/fstringstream.cpp b/src/fstringstream.cpp index 3b94b8ed..31a3523d 100644 --- a/src/fstringstream.cpp +++ b/src/fstringstream.cpp @@ -57,7 +57,7 @@ FStringStream::~FStringStream() // destructor // public methods of FStringStream //---------------------------------------------------------------------- -FStringStream& FStringStream::operator = (FStringStream&& sstream) +FStringStream& FStringStream::operator = (FStringStream&& sstream) noexcept { std::wiostream::operator = (std::move(sstream)); buffer = std::move(sstream.buffer); diff --git a/src/fterm.cpp b/src/fterm.cpp index 931aec5e..663a5dad 100644 --- a/src/fterm.cpp +++ b/src/fterm.cpp @@ -1882,13 +1882,13 @@ void FTerm::redefineColorPalette() { // Redefine the color palette - if ( ! canChangeColorPalette() ) + if ( ! (canChangeColorPalette() && getStartOptions().color_change) ) return; resetColorMap(); saveColorMap(); - if ( FStartOptions::getFStartOptions().dark_theme ) + if ( getStartOptions().dark_theme ) { setColorPaletteTheme(&FTerm::setPalette); } @@ -1899,14 +1899,12 @@ void FTerm::redefineColorPalette() else // 8 colors setColorPaletteTheme(&FTerm::setPalette); } - - getColorPaletteTheme()->setColorPalette(); } //---------------------------------------------------------------------- void FTerm::restoreColorPalette() { - if ( ! canChangeColorPalette() ) + if ( ! (canChangeColorPalette() && getStartOptions().color_change) ) return; // Reset screen settings @@ -2283,8 +2281,7 @@ void FTerm::init (bool disable_alt_screen) initTermspecifics(); // Redefine the color palette - if ( getStartOptions().color_change ) - redefineColorPalette(); + redefineColorPalette(); // Set 220 Hz beep (100 ms) setBeep(220, 100); @@ -2447,8 +2444,7 @@ void FTerm::finish() getFTermXTerminal()->setCursorStyle (fc::steady_block); // Restore the color palette - if ( getStartOptions().color_change ) - restoreColorPalette(); + restoreColorPalette(); // Switch to normal escape key mode disableApplicationEscKey(); diff --git a/src/ftextview.cpp b/src/ftextview.cpp index 7c6bb4dd..15ce3574 100644 --- a/src/ftextview.cpp +++ b/src/ftextview.cpp @@ -104,6 +104,15 @@ void FTextView::setGeometry ( const FPoint& pos, const FSize& size changeOnResize(); } +//---------------------------------------------------------------------- +void FTextView::resetColors() +{ + const auto& wc = getColorTheme(); + setForegroundColor (wc->dialog_fg); + setBackgroundColor (wc->dialog_bg); + FWidget::resetColors(); +} + //---------------------------------------------------------------------- void FTextView::setText (const FString& str) { @@ -569,9 +578,7 @@ void FTextView::init() { initScrollbar (vbar, fc::vertical, this, &FTextView::cb_vbarChange); initScrollbar (hbar, fc::horizontal, this, &FTextView::cb_hbarChange); - const auto& wc = getColorTheme(); - setForegroundColor (wc->dialog_fg); - setBackgroundColor (wc->dialog_bg); + resetColors(); nf_offset = FTerm::isNewFont() ? 1 : 0; setTopPadding(1); setLeftPadding(1); diff --git a/src/ftogglebutton.cpp b/src/ftogglebutton.cpp index a1c2cda8..6f665eb4 100644 --- a/src/ftogglebutton.cpp +++ b/src/ftogglebutton.cpp @@ -111,6 +111,33 @@ void FToggleButton::setGeometry ( const FPoint& pos, const FSize& s FWidget::setGeometry (pos, size, adjust); } +//---------------------------------------------------------------------- +void FToggleButton::resetColors() +{ + const auto& wc = getColorTheme(); + + if ( isEnabled() ) // active + { + if ( hasFocus() ) + { + setForegroundColor (wc->toggle_button_active_focus_fg); + setBackgroundColor (wc->toggle_button_active_focus_bg); + } + else + { + setForegroundColor (wc->toggle_button_active_fg); + setBackgroundColor (wc->toggle_button_active_bg); + } + } + else // inactive + { + setForegroundColor (wc->label_inactive_fg); + setBackgroundColor (wc->label_inactive_bg); + } + + FWidget::resetColors(); +} + //---------------------------------------------------------------------- bool FToggleButton::setNoUnderline (bool enable) { @@ -497,26 +524,7 @@ void FToggleButton::setGroup (FButtonGroup* btngroup) void FToggleButton::init() { setGeometry (FPoint{1, 1}, FSize{4, 1}, false); // initialize geometry values - const auto& wc = getColorTheme(); - - if ( isEnabled() ) - { - if ( hasFocus() ) - { - setForegroundColor (wc->toggle_button_active_focus_fg); - setBackgroundColor (wc->toggle_button_active_focus_bg); - } - else - { - setForegroundColor (wc->toggle_button_active_fg); - setBackgroundColor (wc->toggle_button_active_bg); - } - } - else // inactive - { - setForegroundColor (wc->label_inactive_fg); - setBackgroundColor (wc->label_inactive_bg); - } + resetColors(); } //---------------------------------------------------------------------- diff --git a/src/ftooltip.cpp b/src/ftooltip.cpp index f921ef14..ca26b639 100644 --- a/src/ftooltip.cpp +++ b/src/ftooltip.cpp @@ -73,6 +73,15 @@ void FToolTip::setText (const FString& txt) calculateDimensions(); } +//---------------------------------------------------------------------- +void FToolTip::resetColors() +{ + const auto& wc = getColorTheme(); + setForegroundColor (wc->tooltip_fg); + setBackgroundColor (wc->tooltip_bg); + FWidget::resetColors(); +} + //---------------------------------------------------------------------- bool FToolTip::setBorder (bool enable) { @@ -107,9 +116,7 @@ void FToolTip::init() // initialize geometry values setGeometry (FPoint{1, 1}, FSize{3, 3}, false); setMinimumSize (FSize{3, 3}); - const auto& wc = getColorTheme(); - setForegroundColor (wc->tooltip_fg); - setBackgroundColor (wc->tooltip_bg); + resetColors(); calculateDimensions(); } diff --git a/src/fwidget.cpp b/src/fwidget.cpp index ff87ccd8..22bbf124 100644 --- a/src/fwidget.cpp +++ b/src/fwidget.cpp @@ -305,6 +305,42 @@ bool FWidget::setFocus (bool enable) return (flags.focus = enable); } +//---------------------------------------------------------------------- +void FWidget::resetColors() +{ + if ( ! hasChildren() ) + return; + + for (auto&& child : getChildren()) + { + if ( child->isWidget() ) + { + auto widget = static_cast(child); + widget->resetColors(); + } + } +} + +//---------------------------------------------------------------------- +void FWidget::useParentWidgetColor() +{ + const auto& parent_widget = getParentWidget(); + + if ( parent_widget ) + { + setForegroundColor (parent_widget->getForegroundColor()); + setBackgroundColor (parent_widget->getBackgroundColor()); + } + else // Fallback + { + const auto& wc = getColorTheme(); + setForegroundColor (wc->dialog_fg); + setBackgroundColor (wc->dialog_bg); + } + + setColor(); +} + //---------------------------------------------------------------------- void FWidget::setColor() { diff --git a/src/fwidgetcolors.cpp b/src/fwidgetcolors.cpp index 3617eced..e54d4541 100644 --- a/src/fwidgetcolors.cpp +++ b/src/fwidgetcolors.cpp @@ -442,9 +442,9 @@ void default16ColorDarkTheme::setColorTheme() titlebar_active_fg = fc::White; titlebar_active_bg = fc::DarkGray; titlebar_inactive_fg = fc::DarkGray; - titlebar_inactive_bg = fc::LightGray; + titlebar_inactive_bg = fc::LightBlue; titlebar_button_fg = fc::DarkGray; - titlebar_button_bg = fc::LightGray; + titlebar_button_bg = fc::LightBlue; titlebar_button_focus_fg = fc::LightGray; titlebar_button_focus_bg = fc::Black; menu_active_focus_fg = fc::White; diff --git a/src/include/final/fapplication.h b/src/include/final/fapplication.h index 62e028b6..aeeadb68 100644 --- a/src/include/final/fapplication.h +++ b/src/include/final/fapplication.h @@ -131,6 +131,8 @@ class FApplication : public FWidget bool removeQueuedEvent (const FObject*); virtual void processExternalUserEvent(); static FWidget* processParameters (const int&, char*[]); + static void setDefaultTheme(); + static void setDarkTheme(); static void showParameterUsage () #if defined(__clang__) || defined(__GNUC__) __attribute__((noreturn)) diff --git a/src/include/final/fbutton.h b/src/include/final/fbutton.h index c5baccb2..0da65e26 100644 --- a/src/include/final/fbutton.h +++ b/src/include/final/fbutton.h @@ -88,6 +88,7 @@ class FButton : public FWidget void setFocusBackgroundColor (FColor); void setInactiveForegroundColor (FColor); void setInactiveBackgroundColor (FColor); + void resetColors(); bool setNoUnderline(bool); bool setNoUnderline(); bool unsetNoUnderline(); diff --git a/src/include/final/fdialog.h b/src/include/final/fdialog.h index 424b8d02..c46c82a8 100644 --- a/src/include/final/fdialog.h +++ b/src/include/final/fdialog.h @@ -108,6 +108,7 @@ class FDialog : public FWindow bool setBorder (bool); bool setBorder(); bool unsetBorder(); + void resetColors(); virtual void setText (const FString&); // Inquiries diff --git a/src/include/final/flineedit.h b/src/include/final/flineedit.h index dacd50e8..2e7feaf5 100644 --- a/src/include/final/flineedit.h +++ b/src/include/final/flineedit.h @@ -120,6 +120,7 @@ class FLineEdit : public FWidget void setInputType (const inputType); void setLabelOrientation (const label_o); void setLabelAssociatedWidget (FWidget*); + void resetColors(); void setSize (const FSize&, bool = true) override; void setGeometry ( const FPoint&, const FSize& , bool = true ) override; diff --git a/src/include/final/fmenu.h b/src/include/final/fmenu.h index af04b2f6..618ae436 100644 --- a/src/include/final/fmenu.h +++ b/src/include/final/fmenu.h @@ -106,6 +106,7 @@ class FMenu : public FWindow, public FMenuList void setStatusbarMessage (const FString&) override; void setMenu (FMenu*); void setText (const FString&); + void resetColors(); // Inquiries bool isSelected() const; diff --git a/src/include/final/fmenubar.h b/src/include/final/fmenubar.h index bf1e81d5..5f7193e3 100644 --- a/src/include/final/fmenubar.h +++ b/src/include/final/fmenubar.h @@ -86,6 +86,7 @@ class FMenuBar : public FWindow, public FMenuList const FString getClassName() const override; // Methods + void resetColors(); void resetMenu(); void hide() override; void adjustSize() override; diff --git a/src/include/final/fscrollview.h b/src/include/final/fscrollview.h index 12bffba8..cb67c55b 100644 --- a/src/include/final/fscrollview.h +++ b/src/include/final/fscrollview.h @@ -108,6 +108,7 @@ class FScrollView : public FWidget bool setViewportPrint (bool); bool setViewportPrint(); bool unsetViewportPrint(); + void resetColors(); bool setBorder (bool); bool setBorder(); bool unsetBorder(); diff --git a/src/include/final/fstatusbar.h b/src/include/final/fstatusbar.h index 2a86d383..972986e5 100644 --- a/src/include/final/fstatusbar.h +++ b/src/include/final/fstatusbar.h @@ -205,6 +205,7 @@ class FStatusBar : public FWindow void activateKey (int); void deactivateKey (int); void setMessage (const FString&); + void resetColors(); // Inquiries bool isActivated (int) const; diff --git a/src/include/final/fstringstream.h b/src/include/final/fstringstream.h index c691c125..e0c111c8 100644 --- a/src/include/final/fstringstream.h +++ b/src/include/final/fstringstream.h @@ -78,7 +78,7 @@ class FStringStream : public std::wiostream FStringStream& operator = (const FStringStream&) = delete; // Move assignment operator (=) - FStringStream& operator = (FStringStream&& sstream); + FStringStream& operator = (FStringStream&& sstream) noexcept; virtual const FString getClassName() const; void swap (FStringStream&) noexcept; diff --git a/src/include/final/fterm.h b/src/include/final/fterm.h index 7d9a0950..ff8fd129 100644 --- a/src/include/final/fterm.h +++ b/src/include/final/fterm.h @@ -444,6 +444,7 @@ template inline void FTerm::setColorPaletteTheme (const FSetPalette& f) { getColorPaletteTheme() = std::make_shared(f); + getColorPaletteTheme()->setColorPalette(); } //---------------------------------------------------------------------- diff --git a/src/include/final/ftextview.h b/src/include/final/ftextview.h index 54606d4f..41c913df 100644 --- a/src/include/final/ftextview.h +++ b/src/include/final/ftextview.h @@ -100,6 +100,7 @@ class FTextView : public FWidget void setSize (const FSize&, bool = true) override; void setGeometry ( const FPoint&, const FSize& , bool = true ) override; + void resetColors(); void setText (const FString&); void scrollToX (int); void scrollToY (int); diff --git a/src/include/final/ftogglebutton.h b/src/include/final/ftogglebutton.h index 60f10601..6d23e907 100644 --- a/src/include/final/ftogglebutton.h +++ b/src/include/final/ftogglebutton.h @@ -86,6 +86,7 @@ class FToggleButton : public FWidget void setSize (const FSize&, bool = true) override; void setGeometry ( const FPoint&, const FSize& , bool = true ) override; + void resetColors(); bool setNoUnderline (bool); bool setNoUnderline(); bool unsetNoUnderline(); diff --git a/src/include/final/ftooltip.h b/src/include/final/ftooltip.h index 16769727..d18aa2cb 100644 --- a/src/include/final/ftooltip.h +++ b/src/include/final/ftooltip.h @@ -85,6 +85,7 @@ class FToolTip : public FWindow // Mutators void setText (const FString&); + void resetColors(); bool setBorder (bool); bool setBorder(); bool unsetBorder(); diff --git a/src/include/final/fwidget.h b/src/include/final/fwidget.h index 0ea4899c..fcc6fdfd 100644 --- a/src/include/final/fwidget.h +++ b/src/include/final/fwidget.h @@ -266,6 +266,8 @@ class FWidget : public FVTerm, public FObject bool acceptPadding(); virtual void setForegroundColor (FColor); virtual void setBackgroundColor (FColor); + virtual void resetColors(); + void useParentWidgetColor(); void setColor(); FWidgetFlags& setFlags(); // Positioning and sizes mutators...