From 388deb71ab5d03116ef5ec1266c39eea8fb51520 Mon Sep 17 00:00:00 2001 From: Vojtech Kral Date: Mon, 9 Apr 2018 14:41:55 +0200 Subject: [PATCH] Adapt settings label colors to light vs dark UI themes --- xs/src/slic3r/GUI/GUI.cpp | 38 ++++++++++++++++++++++++++++++++++---- xs/src/slic3r/GUI/GUI.hpp | 6 ++++-- xs/src/slic3r/GUI/Tab.cpp | 14 +++++++------- 3 files changed, 45 insertions(+), 13 deletions(-) diff --git a/xs/src/slic3r/GUI/GUI.cpp b/xs/src/slic3r/GUI/GUI.cpp index 3eca4e707..9109e8b5c 100644 --- a/xs/src/slic3r/GUI/GUI.cpp +++ b/xs/src/slic3r/GUI/GUI.cpp @@ -1,6 +1,7 @@ #include "GUI.hpp" #include +#include #include #include @@ -37,6 +38,7 @@ #include #include #include +#include #include "wxExtensions.hpp" @@ -174,6 +176,8 @@ wxFrame *g_wxMainFrame = nullptr; wxNotebook *g_wxTabPanel = nullptr; AppConfig *g_AppConfig = nullptr; PresetBundle *g_PresetBundle= nullptr; +wxColour g_color_label_modified; +wxColour g_color_label_sys; std::vector g_tabs_list; @@ -182,9 +186,22 @@ wxLocale* g_wxLocale; std::shared_ptr m_optgroup; double m_brim_width = 0.0; +static void init_label_colours() +{ + auto luma = get_colour_approx_luma(wxSystemSettings::GetColour(wxSYS_COLOUR_WINDOW)); + if (luma >= 128) { + g_color_label_modified = wxColour(253, 88, 0); + g_color_label_sys = wxColour(26, 132, 57); + } else { + g_color_label_modified = wxColour(253, 111, 40); + g_color_label_sys = wxColour(115, 220, 103); + } +} + void set_wxapp(wxApp *app) { g_wxApp = app; + init_label_colours(); } void set_main_frame(wxFrame *main_frame) @@ -514,12 +531,25 @@ wxApp* get_app(){ return g_wxApp; } -wxColour* get_modified_label_clr(){ - return new wxColour(253, 88, 0); +const wxColour& get_modified_label_clr() { + return g_color_label_modified; } -wxColour* get_sys_label_clr(){ - return new wxColour(26, 132, 57); +const wxColour& get_sys_label_clr() { + return g_color_label_sys; +} + +unsigned get_colour_approx_luma(const wxColour &colour) +{ + double r = colour.Red(); + double g = colour.Green(); + double b = colour.Blue(); + + std::round(std::sqrt( + r * r * .241 + + g * g * .691 + + b * b * .068 + )); } void create_combochecklist(wxComboCtrl* comboCtrl, std::string text, std::string items, bool initial_value) diff --git a/xs/src/slic3r/GUI/GUI.hpp b/xs/src/slic3r/GUI/GUI.hpp index 362b15307..24c3ec3f4 100644 --- a/xs/src/slic3r/GUI/GUI.hpp +++ b/xs/src/slic3r/GUI/GUI.hpp @@ -79,8 +79,10 @@ void set_preset_bundle(PresetBundle *preset_bundle); AppConfig* get_app_config(); wxApp* get_app(); -wxColour* get_modified_label_clr(); -wxColour* get_sys_label_clr(); + +const wxColour& get_modified_label_clr(); +const wxColour& get_sys_label_clr(); +unsigned get_colour_approx_luma(const wxColour &colour); void add_debug_menu(wxMenuBar *menu, int event_language_change); diff --git a/xs/src/slic3r/GUI/Tab.cpp b/xs/src/slic3r/GUI/Tab.cpp index babff7d80..7db35f5cf 100644 --- a/xs/src/slic3r/GUI/Tab.cpp +++ b/xs/src/slic3r/GUI/Tab.cpp @@ -265,14 +265,14 @@ void Tab::update_changed_ui() bool is_modified_value = true; std::string sys_icon = wxMSW ? "sys_lock.png" : "lock.png"; std::string icon = wxMSW ? "action_undo.png" : "arrow_undo.png"; - wxColour& color = *get_sys_label_clr(); + wxColour color = get_sys_label_clr(); if (find(m_sys_options.begin(), m_sys_options.end(), opt_key) == m_sys_options.end()) { is_nonsys_value = true; sys_icon = m_nonsys_btn_icon; if(find(m_dirty_options.begin(), m_dirty_options.end(), opt_key) == m_dirty_options.end()) - color = wxSYS_COLOUR_WINDOWTEXT; + color = wxSystemSettings::GetColour(wxSYS_COLOUR_WINDOWTEXT); else - color = *get_modified_label_clr(); + color = get_modified_label_clr(); } if (find(m_dirty_options.begin(), m_dirty_options.end(), opt_key) == m_dirty_options.end()) { @@ -343,7 +343,7 @@ void Tab::update_sys_ui_after_sel_preset() field->m_Undo_to_sys_btn->SetBitmap(wxBitmap(from_u8(var(m_nonsys_btn_icon)), wxBITMAP_TYPE_PNG)); field->m_is_nonsys_value = true; if (field->m_Label != nullptr){ - field->m_Label->SetForegroundColour(wxSYS_COLOUR_WINDOWTEXT); + field->m_Label->SetForegroundColour(wxSystemSettings::GetColour(wxSYS_COLOUR_WINDOWTEXT)); field->m_Label->Refresh(true); } } @@ -386,11 +386,11 @@ void Tab::update_changed_tree_ui() break; } if (sys_page) - m_treectrl->SetItemTextColour(cur_item, *get_sys_label_clr()); + m_treectrl->SetItemTextColour(cur_item, get_sys_label_clr()); else if (modified_page) - m_treectrl->SetItemTextColour(cur_item, *get_modified_label_clr()); + m_treectrl->SetItemTextColour(cur_item, get_modified_label_clr()); else - m_treectrl->SetItemTextColour(cur_item, wxSYS_COLOUR_WINDOWTEXT); + m_treectrl->SetItemTextColour(cur_item, wxSystemSettings::GetColour(wxSYS_COLOUR_WINDOWTEXT)); page->m_is_nonsys_values = !sys_page; page->m_is_modified_values = modified_page;