diff --git a/src/colorscheme.cpp b/src/colorscheme.cpp index d01d0201f8..eae7668bf4 100644 --- a/src/colorscheme.cpp +++ b/src/colorscheme.cpp @@ -59,8 +59,11 @@ inline wxColour sRGB(int r, int g, int b, double a = 1.0) } // anonymous namespace std::unique_ptr ColorScheme::s_data; +bool ColorScheme::s_appModeDetermined = false; +ColorScheme::Mode ColorScheme::s_appMode = ColorScheme::Mode::Light; -wxColour ColorScheme::DoGet(Color color, Type type) + +wxColour ColorScheme::DoGet(Color color, Mode type) { switch (color) { @@ -130,9 +133,12 @@ wxColour ColorScheme::DoGet(Color color, Type type) // Backgrounds: case Color::SidebarBackground: - return "#edf0f4"; + if (GetAppMode() == Dark) + return "#120f0b"; + else + return "#edf0f4"; case Color::EditingBackground: - return *wxWHITE; + return wxSystemSettings::GetColour(wxSYS_COLOUR_LISTBOX); // Fuzzy toggle: case Color::FuzzySwitch: @@ -184,12 +190,26 @@ wxColour ColorScheme::DoGet(Color color, Type type) } -ColorScheme::Type ColorScheme::GetSchemeTypeFromWindow(const wxVisualAttributes& win) +ColorScheme::Mode ColorScheme::GetAppMode() +{ + if (!s_appModeDetermined) + { + auto colBg = wxSystemSettings::GetColour(wxSYS_COLOUR_WINDOW); + if (colBg.Red() < 0x60 && colBg.Green() < 0x60 && colBg.Blue() < 0x60) + s_appMode = Dark; + else + s_appMode = Light; + s_appModeDetermined = true; + } + + return s_appMode; +} + + +ColorScheme::Mode ColorScheme::GetWindowMode(const wxVisualAttributes& win) { // Use dark scheme for very dark backgrounds: - if (win.colBg.Red() < 0x60 && - win.colBg.Green() < 0x60 && - win.colBg.Blue() < 0x60) + if (win.colBg.Red() < 0x60 && win.colBg.Green() < 0x60 && win.colBg.Blue() < 0x60) { return Dark; } diff --git a/src/colorscheme.h b/src/colorscheme.h index b75bf04ba1..5bd562ae80 100644 --- a/src/colorscheme.h +++ b/src/colorscheme.h @@ -88,14 +88,14 @@ enum class Color : size_t class ColorScheme { public: - /// Type of the scheme to use (not used a lot for now) - enum Type + /// Mode of the scheme to use (not used a lot for now) + enum Mode { Light, Dark }; - static const wxColour& Get(Color color, Type type = Light) + static const wxColour& Get(Color color, Mode type = Light) { if (!s_data) s_data = std::make_unique(); @@ -113,11 +113,19 @@ class ColorScheme static const wxColour& Get(Color color, const wxVisualAttributes& win) { - return Get(color, GetSchemeTypeFromWindow(win)); + return Get(color, GetWindowMode(win)); } static wxColour GetBlendedOn(Color color, wxWindow *win); + /// Returns app-wide mode (dark, light) + static Mode GetAppMode(); + static Mode GetWindowMode(const wxVisualAttributes& win); + static Mode GetWindowMode(wxWindow *win) + { + return GetWindowMode(win->GetDefaultAttributes()); + } + static void CleanUp(); private: @@ -126,10 +134,11 @@ class ColorScheme wxColour colors[static_cast(Color::Max)][2]; }; - static wxColour DoGet(Color color, Type type); - static Type GetSchemeTypeFromWindow(const wxVisualAttributes& win); + static wxColour DoGet(Color color, Mode type); static std::unique_ptr s_data; + static bool s_appModeDetermined; + static Mode s_appMode; }; #endif // Poedit_colorscheme_h diff --git a/src/editing_area.cpp b/src/editing_area.cpp index 24034fb8a9..83dd50a895 100644 --- a/src/editing_area.cpp +++ b/src/editing_area.cpp @@ -453,6 +453,9 @@ void EditingArea::CreateEditControls(wxBoxSizer *sizer) m_pluralNotebook = new wxNotebook(this, -1, wxDefaultPosition, wxDefaultSize, wxNB_NOPAGETHEME); m_pluralNotebook->SetWindowVariant(wxWINDOW_VARIANT_SMALL); +#ifdef __WXMSW__ + m_pluralNotebook->SetBackgroundColour(GetBackgroundColour()); +#endif sizer->Add(transLineSizer, wxSizerFlags().Expand().Border(wxLEFT|wxTOP, PX(6))); sizer->AddSpacer(PX(6)); diff --git a/src/edlistctrl.cpp b/src/edlistctrl.cpp index e196d3cca9..6a117b8bd3 100644 --- a/src/edlistctrl.cpp +++ b/src/edlistctrl.cpp @@ -505,6 +505,11 @@ PoeditListCtrl::PoeditListCtrl(wxWindow *parent, wxWindowID id, bool dispIDs) UpdateHeaderAttrs(); +#ifdef __WXMSW__ + if (ColorScheme::GetWindowMode(this) == ColorScheme::Dark) + SetAlternateRowColour(GetBackgroundColour().ChangeLightness(108)); +#endif + Bind(wxEVT_SIZE, &PoeditListCtrl::OnSize, this); } diff --git a/src/text_control.cpp b/src/text_control.cpp index be0811dc81..ffe2f2b410 100644 --- a/src/text_control.cpp +++ b/src/text_control.cpp @@ -469,7 +469,7 @@ class AnyTranslatableTextCtrl::Attributes NSDictionary *m_attrSpace, *m_attrEscape, *m_attrMarkup, *m_attrFormat; typedef NSDictionary* AttrType; - Attributes() + Attributes(wxTextCtrl*) { m_attrSpace = @{NSBackgroundColorAttributeName: ColorScheme::Get(Color::SyntaxLeadingWhitespaceBg).OSXGetNSColor()}; m_attrEscape = @{NSBackgroundColorAttributeName: ColorScheme::Get(Color::SyntaxEscapeBg).OSXGetNSColor(), @@ -481,10 +481,10 @@ class AnyTranslatableTextCtrl::Attributes wxTextAttr m_attrDefault, m_attrSpace, m_attrEscape, m_attrMarkup, m_attrFormat; typedef wxTextAttr AttrType; - Attributes() + Attributes(wxTextCtrl *ctrl) { - m_attrDefault.SetBackgroundColour(*wxWHITE); - m_attrDefault.SetTextColour(*wxBLACK); + m_attrDefault.SetBackgroundColour(ctrl->GetBackgroundColour()); + m_attrDefault.SetTextColour(ctrl->GetForegroundColour()); m_attrSpace.SetBackgroundColour(ColorScheme::Get(Color::SyntaxLeadingWhitespaceBg)); @@ -514,9 +514,9 @@ class AnyTranslatableTextCtrl::Attributes AnyTranslatableTextCtrl::AnyTranslatableTextCtrl(wxWindow *parent, wxWindowID winid, int style) - : CustomizedTextCtrl(parent, winid, style), - m_attrs(new Attributes) + : CustomizedTextCtrl(parent, winid, style) { + m_attrs.reset(new Attributes(this)); Bind(wxEVT_TEXT, [=](wxCommandEvent& e){ e.Skip(); HighlightText(); diff --git a/src/welcomescreen.cpp b/src/welcomescreen.cpp index 4982088ba7..4ec3bde17f 100644 --- a/src/welcomescreen.cpp +++ b/src/welcomescreen.cpp @@ -25,6 +25,7 @@ #include "welcomescreen.h" +#include "colorscheme.h" #include "crowdin_gui.h" #include "edapp.h" #include "edframe.h" @@ -165,7 +166,15 @@ WelcomeScreenBase::WelcomeScreenBase(wxWindow *parent) m_clrNorm("#444444"), m_clrSub("#aaaaaa") { - SetBackgroundColour(wxColour("#fffcf5")); + switch (ColorScheme::GetAppMode()) + { + case ColorScheme::Light: + SetBackgroundColour("#fffcf5"); + break; + case ColorScheme::Dark: + SetBackgroundColour("#00030a"); + break; + } #if defined(__WXOSX__) auto guiface = wxSystemSettings::GetFont(wxSYS_DEFAULT_GUI_FONT).GetFaceName();