Skip to content

Commit

Permalink
Fix the worst of bad dark themes support
Browse files Browse the repository at this point in the history
Make Poedit usable with dark mode themes that use black or almost-black
backgrounds. There are still more defects in this area that will be
fixed, this fixes only the worst of them, in the main editing window.

More fixes forthcoming.

Fixes #416.
Fixes #273.
  • Loading branch information
vslavik committed Jun 13, 2018
1 parent e72d35d commit a5dc59d
Show file tree
Hide file tree
Showing 6 changed files with 66 additions and 20 deletions.
34 changes: 27 additions & 7 deletions src/colorscheme.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -59,8 +59,11 @@ inline wxColour sRGB(int r, int g, int b, double a = 1.0)
} // anonymous namespace

std::unique_ptr<ColorScheme::Data> 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)
{
Expand Down Expand Up @@ -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:
Expand Down Expand Up @@ -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;
}
Expand Down
21 changes: 15 additions & 6 deletions src/colorscheme.h
Original file line number Diff line number Diff line change
Expand Up @@ -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<Data>();
Expand All @@ -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:
Expand All @@ -126,10 +134,11 @@ class ColorScheme
wxColour colors[static_cast<size_t>(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<Data> s_data;
static bool s_appModeDetermined;
static Mode s_appMode;
};

#endif // Poedit_colorscheme_h
3 changes: 3 additions & 0 deletions src/editing_area.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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));
Expand Down
5 changes: 5 additions & 0 deletions src/edlistctrl.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}

Expand Down
12 changes: 6 additions & 6 deletions src/text_control.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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(),
Expand All @@ -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));

Expand Down Expand Up @@ -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();
Expand Down
11 changes: 10 additions & 1 deletion src/welcomescreen.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@

#include "welcomescreen.h"

#include "colorscheme.h"
#include "crowdin_gui.h"
#include "edapp.h"
#include "edframe.h"
Expand Down Expand Up @@ -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();
Expand Down

0 comments on commit a5dc59d

Please sign in to comment.