ENH: dark mode of StateColor

Change-Id: I5928898c50280c7f2eedbb9389032230c7e251c4
This commit is contained in:
chunmao.guo 2022-10-31 14:12:14 +08:00 committed by Lane.Wei
parent faec57d263
commit b209243b27
20 changed files with 155 additions and 38 deletions

View File

@ -322,10 +322,13 @@ wxBitmap* BitmapCache::load_svg(const std::string &bitmap_name, unsigned target_
// map of color replaces // map of color replaces
std::map<std::string, std::string> replaces; std::map<std::string, std::string> replaces;
if (dark_mode) if (dark_mode) {
replaces["\"#808080\""] = "\"#FFFFFF\""; replaces["\"#262E30\""] = "\"#EFEFF0\"";
if (!new_color.empty()) replaces["\"#323A3D\""] = "\"#B3B3B5\"";
replaces["\"#ED6B21\""] = "\"" + new_color + "\""; replaces["\"#808080\""] = "\"#818183\"";
}
//if (!new_color.empty())
// replaces["\"#ED6B21\""] = "\"" + new_color + "\"";
NSVGimage *image = nsvgParseFromFileWithReplace(Slic3r::var(bitmap_name + ".svg").c_str(), "px", 96.0f, replaces); NSVGimage *image = nsvgParseFromFileWithReplace(Slic3r::var(bitmap_name + ".svg").c_str(), "px", 96.0f, replaces);
if (image == nullptr) if (image == nullptr)

View File

@ -730,7 +730,7 @@ void CheckBox::BUILD() {
// BBS: use ::CheckBox // BBS: use ::CheckBox
auto temp = new ::CheckBox(m_parent); auto temp = new ::CheckBox(m_parent);
if (!wxOSX) temp->SetBackgroundStyle(wxBG_STYLE_PAINT); if (!wxOSX) temp->SetBackgroundStyle(wxBG_STYLE_PAINT);
temp->SetBackgroundColour(*wxWHITE); //temp->SetBackgroundColour(*wxWHITE);
temp->SetValue(check_value); temp->SetValue(check_value);
temp->Bind(wxEVT_TOGGLEBUTTON, ([this](wxCommandEvent & e) { temp->Bind(wxEVT_TOGGLEBUTTON, ([this](wxCommandEvent & e) {

View File

@ -2616,10 +2616,10 @@ const wxColour GUI_App::get_label_default_clr_modified()
void GUI_App::init_label_colours() void GUI_App::init_label_colours()
{ {
m_color_label_modified = wxColour("#F1754E");
m_color_label_sys = wxColour("#323A3D");
bool is_dark_mode = dark_mode(); bool is_dark_mode = dark_mode();
m_color_label_modified = is_dark_mode ? wxColour("#F1754E") : wxColour("#F1754E");
m_color_label_sys = is_dark_mode ? wxColour("#B2B3B5") : wxColour("#363636");
#ifdef _WIN32 #ifdef _WIN32
m_color_label_default = is_dark_mode ? wxColour(250, 250, 250) : m_color_label_sys; // wxSystemSettings::GetColour(wxSYS_COLOUR_WINDOWTEXT); m_color_label_default = is_dark_mode ? wxColour(250, 250, 250) : m_color_label_sys; // wxSystemSettings::GetColour(wxSYS_COLOUR_WINDOWTEXT);
m_color_highlight_label_default = is_dark_mode ? wxColour(230, 230, 230): wxSystemSettings::GetColour(/*wxSYS_COLOUR_HIGHLIGHTTEXT*/wxSYS_COLOUR_WINDOWTEXT); m_color_highlight_label_default = is_dark_mode ? wxColour(230, 230, 230): wxSystemSettings::GetColour(/*wxSYS_COLOUR_HIGHLIGHTTEXT*/wxSYS_COLOUR_WINDOWTEXT);
@ -2630,6 +2630,7 @@ void GUI_App::init_label_colours()
m_color_label_default = wxSystemSettings::GetColour(wxSYS_COLOUR_WINDOWTEXT); m_color_label_default = wxSystemSettings::GetColour(wxSYS_COLOUR_WINDOWTEXT);
#endif #endif
m_color_window_default = is_dark_mode ? wxColour(43, 43, 43) : wxSystemSettings::GetColour(wxSYS_COLOUR_WINDOW); m_color_window_default = is_dark_mode ? wxColour(43, 43, 43) : wxSystemSettings::GetColour(wxSYS_COLOUR_WINDOW);
StateColor::SetDarkMode(is_dark_mode);
} }
void GUI_App::update_label_colours_from_appconfig() void GUI_App::update_label_colours_from_appconfig()
@ -2645,8 +2646,10 @@ void GUI_App::update_label_colours()
void GUI_App::UpdateDarkUI(wxWindow* window, bool highlited/* = false*/, bool just_font/* = false*/) void GUI_App::UpdateDarkUI(wxWindow* window, bool highlited/* = false*/, bool just_font/* = false*/)
{ {
//BBS disable DarkUI mode if (wxButton *btn = dynamic_cast<wxButton *>(window)) {
if (btn->GetWindowStyleFlag() & wxBU_AUTODRAW)
return; return;
}
#ifdef _WIN32 #ifdef _WIN32
if (wxButton* btn = dynamic_cast<wxButton*>(window)) { if (wxButton* btn = dynamic_cast<wxButton*>(window)) {

View File

@ -168,7 +168,7 @@ bool ObjectTableSettings::update_settings_list(bool is_object, bool is_multiple_
btn->SetToolTip(_(L("Reset parameter"))); btn->SetToolTip(_(L("Reset parameter")));
#ifdef __WINDOWS__ #ifdef __WINDOWS__
btn->SetBackgroundColour(*wxWHITE); btn->SetBackgroundColour(parent->GetBackgroundColour());
#endif // DEBUG #endif // DEBUG

View File

@ -44,7 +44,6 @@ ImageGrid::ImageGrid(wxWindow * parent)
{ {
SetBackgroundStyle(wxBG_STYLE_PAINT); SetBackgroundStyle(wxBG_STYLE_PAINT);
SetBackgroundColour(0xEEEEEE); SetBackgroundColour(0xEEEEEE);
SetForegroundColour(*wxWHITE); // time text color
SetFont(Label::Head_20); SetFont(Label::Head_20);
m_timer.Bind(wxEVT_TIMER, [this](auto & e) { Refresh(); }); m_timer.Bind(wxEVT_TIMER, [this](auto & e) { Refresh(); });
@ -558,6 +557,7 @@ void ImageGrid::render(wxDC& dc)
dc.DrawBitmap(file.IsSelect() ? m_checked_icon.bmp() : m_unchecked_icon.bmp(), dc.DrawBitmap(file.IsSelect() ? m_checked_icon.bmp() : m_unchecked_icon.bmp(),
pt + wxPoint{10, m_image_size.GetHeight() - m_checked_icon.GetBmpHeight() - 10}); pt + wxPoint{10, m_image_size.GetHeight() - m_checked_icon.GetBmpHeight() - 10});
} else { } else {
dc.SetTextForeground(*wxWHITE); // time text color
auto date = wxDateTime((time_t) file.time).Format(_L(formats[m_file_sys->GetGroupMode()])); auto date = wxDateTime((time_t) file.time).Format(_L(formats[m_file_sys->GetGroupMode()]));
dc.DrawText(date, pt + wxPoint{24, 16}); dc.DrawText(date, pt + wxPoint{24, 16});
} }
@ -582,7 +582,7 @@ void ImageGrid::render(wxDC& dc)
auto date1 = wxDateTime((time_t) file1.time).Format(_L(formats[m_file_sys->GetGroupMode()])); auto date1 = wxDateTime((time_t) file1.time).Format(_L(formats[m_file_sys->GetGroupMode()]));
auto date2 = wxDateTime((time_t) file2.time).Format(_L(formats[m_file_sys->GetGroupMode()])); auto date2 = wxDateTime((time_t) file2.time).Format(_L(formats[m_file_sys->GetGroupMode()]));
dc.SetFont(Label::Head_16); dc.SetFont(Label::Head_16);
dc.SetTextForeground(wxColor("#262E30")); dc.SetTextForeground(StateColor::darkModeColorFor("#262E30"));
dc.DrawText(date1 + " - " + date2, wxPoint{off.x, 2}); dc.DrawText(date1 + " - " + date2, wxPoint{off.x, 2});
} }
// Draw bottom background // Draw bottom background
@ -627,13 +627,12 @@ void Slic3r::GUI::ImageGrid::renderButtons(wxDC &dc, wxStringList const &texts,
rect.Inflate(10, 5); rect.Inflate(10, 5);
rect.Offset(rect.GetWidth(), 0); rect.Offset(rect.GetWidth(), 0);
} }
dc.SetTextForeground(*wxWHITE); // time text color
dc.SetFont(GetFont()); dc.SetFont(GetFont());
} }
void Slic3r::GUI::ImageGrid::renderText(wxDC &dc, wxString const &text, wxRect const &rect, int states) void Slic3r::GUI::ImageGrid::renderText(wxDC &dc, wxString const &text, wxRect const &rect, int states)
{ {
dc.SetTextForeground(m_buttonTextColor.colorForStates(states)); dc.SetTextForeground(m_buttonTextColor.colorForStatesNoDark(states));
wxRect rc({0, 0}, dc.GetTextExtent(text)); wxRect rc({0, 0}, dc.GetTextExtent(text));
rc = rc.CenterIn(rect); rc = rc.CenterIn(rect);
dc.DrawText(text, rc.GetTopLeft()); dc.DrawText(text, rc.GetTopLeft());

View File

@ -1770,6 +1770,7 @@ void MainFrame::on_sys_color_changed()
// BBS // BBS
m_tabpanel->Rescale(); m_tabpanel->Rescale();
m_param_panel->msw_rescale();
// update Plater // update Plater
wxGetApp().plater()->sys_color_changed(); wxGetApp().plater()->sys_color_changed();

View File

@ -48,6 +48,7 @@ OG_CustomCtrl::OG_CustomCtrl( wxWindow* parent,
{ {
if (!wxOSX) if (!wxOSX)
SetDoubleBuffered(true);// SetDoubleBuffered exists on Win and Linux/GTK, but is missing on OSX SetDoubleBuffered(true);// SetDoubleBuffered exists on Win and Linux/GTK, but is missing on OSX
SetBackgroundColour(parent->GetBackgroundColour());
// BBS: new font // BBS: new font
m_font = Label::Body_14; m_font = Label::Body_14;
@ -332,7 +333,7 @@ void OG_CustomCtrl::OnPaint(wxPaintEvent&)
// BBS: new layout // BBS: new layout
if (!GetLabel().IsEmpty()) { if (!GetLabel().IsEmpty()) {
dc.SetFont(Label::Head_16); dc.SetFont(Label::Head_16);
wxColour color("#283436"); wxColour color = StateColor::darkModeColorFor("#283436");
draw_title(dc, {0, v_pos}, GetLabel(), &color, h_pos); draw_title(dc, {0, v_pos}, GetLabel(), &color, h_pos);
dc.SetFont(m_font); dc.SetFont(m_font);
} }
@ -759,10 +760,10 @@ void OG_CustomCtrl::CtrlLine::render(wxDC& dc, wxCoord h_pos, wxCoord v_pos)
const std::vector<Option>& option_set = og_line.get_options(); const std::vector<Option>& option_set = og_line.get_options();
wxString label = og_line.label; wxString label = og_line.label;
wxColour blink_color("#00AE42"); wxColour blink_color = StateColor::darkModeColorFor("#00AE42");
bool is_url_string = false; bool is_url_string = false;
if (ctrl->opt_group->label_width != 0 && !label.IsEmpty()) { if (ctrl->opt_group->label_width != 0 && !label.IsEmpty()) {
const wxColour* text_clr = (option_set.size() == 1 && field ? field->label_color() : og_line.full_Label_color); const wxColour* text_clr = field ? field->label_color() : og_line.full_Label_color;
for (const Option& opt : option_set) { for (const Option& opt : option_set) {
Field* field = ctrl->opt_group->get_field(opt.opt_id); Field* field = ctrl->opt_group->get_field(opt.opt_id);
if (field && field->blink()) { if (field && field->blink()) {
@ -850,7 +851,7 @@ void OG_CustomCtrl::CtrlLine::render(wxDC& dc, wxCoord h_pos, wxCoord v_pos)
is_url_string = false; is_url_string = false;
else if(opt == option_set.front()) else if(opt == option_set.front())
is_url_string = !suppress_hyperlinks && !og_line.label_path.empty(); is_url_string = !suppress_hyperlinks && !og_line.label_path.empty();
static wxColor c("#6B6B6B"); wxColor c = StateColor::darkModeColorFor("#6B6B6B");
h_pos = draw_text(dc, wxPoint(h_pos, v_pos), label, field ? (field->blink() ? &blink_color : &c) : nullptr, ctrl->opt_group->sublabel_width * ctrl->m_em_unit, is_url_string); h_pos = draw_text(dc, wxPoint(h_pos, v_pos), label, field ? (field->blink() ? &blink_color : &c) : nullptr, ctrl->opt_group->sublabel_width * ctrl->m_em_unit, is_url_string);
h_pos += 8; h_pos += 8;
} }
@ -905,7 +906,7 @@ wxCoord OG_CustomCtrl::CtrlLine::draw_text(wxDC &dc, wxPoint pos, const wxString
wxColour old_clr = dc.GetTextForeground(); wxColour old_clr = dc.GetTextForeground();
wxFont old_font = dc.GetFont(); wxFont old_font = dc.GetFont();
static wxColor clr_url("#00AE42"); wxColor clr_url = StateColor::darkModeColorFor("#00AE42");
if (is_focused && is_url) { if (is_focused && is_url) {
// temporary workaround for the OSX because of strange Bold font behavior on BigSerf // temporary workaround for the OSX because of strange Bold font behavior on BigSerf
#ifdef __APPLE__ #ifdef __APPLE__

View File

@ -453,6 +453,7 @@ bool OptionsGroup::activate(std::function<void()> throw_if_canceled/* = [](){}*/
if (staticbox) { if (staticbox) {
wxStaticBox * stb = new wxStaticBox(m_parent, wxID_ANY, _(title)); wxStaticBox * stb = new wxStaticBox(m_parent, wxID_ANY, _(title));
if (!wxOSX) stb->SetBackgroundStyle(wxBG_STYLE_PAINT); if (!wxOSX) stb->SetBackgroundStyle(wxBG_STYLE_PAINT);
stb->SetBackgroundColour(m_parent->GetBackgroundColour());
stb->SetFont(wxOSX ? wxGetApp().normal_font() : wxGetApp().bold_font()); stb->SetFont(wxOSX ? wxGetApp().normal_font() : wxGetApp().bold_font());
wxGetApp().UpdateDarkUI(stb); wxGetApp().UpdateDarkUI(stb);
// BBS: new layout // BBS: new layout

View File

@ -1137,8 +1137,16 @@ void Sidebar::sys_color_changed()
for (wxWindow* win : std::vector<wxWindow*>{ p->scrolled, p->presets_panel }) for (wxWindow* win : std::vector<wxWindow*>{ p->scrolled, p->presets_panel })
wxGetApp().UpdateAllStaticTextDarkUI(win); wxGetApp().UpdateAllStaticTextDarkUI(win);
#endif #endif
for (wxWindow* btn : std::vector<wxWindow*>{ p->btn_reslice, p->btn_export_gcode }) //for (wxWindow* btn : std::vector<wxWindow*>{ p->btn_reslice, p->btn_export_gcode })
wxGetApp().UpdateDarkUI(btn, true); // wxGetApp().UpdateDarkUI(btn, true);
p->m_printer_icon->msw_rescale();
p->m_printer_setting->msw_rescale();
p->m_filament_icon->msw_rescale();
p->m_bpButton_add_filament->msw_rescale();
p->m_bpButton_del_filament->msw_rescale();
p->m_bpButton_ams_filament->msw_rescale();
p->m_bpButton_set_filament->msw_rescale();
p->m_flushing_volume_btn->Rescale();
// BBS // BBS
#if 0 #if 0
@ -10211,7 +10219,6 @@ void Plater::sys_color_changed()
{ {
p->preview->sys_color_changed(); p->preview->sys_color_changed();
p->sidebar->sys_color_changed(); p->sidebar->sys_color_changed();
p->menus.sys_color_changed(); p->menus.sys_color_changed();
Layout(); Layout();

View File

@ -670,7 +670,7 @@ PlaterPresetComboBox::PlaterPresetComboBox(wxWindow *parent, Preset::Type preset
// BBS // BBS
if (m_type == Preset::TYPE_FILAMENT) { if (m_type == Preset::TYPE_FILAMENT) {
int em = wxGetApp().em_unit(); int em = wxGetApp().em_unit();
clr_picker = new wxButton(parent, wxID_ANY, "", wxDefaultPosition, wxSize(FromDIP(20), FromDIP(20)), wxBU_EXACTFIT | wxBORDER_NONE); clr_picker = new wxButton(parent, wxID_ANY, "", wxDefaultPosition, wxSize(FromDIP(20), FromDIP(20)), wxBU_EXACTFIT | wxBU_AUTODRAW | wxBORDER_NONE);
clr_picker->SetToolTip(_L("Click to pick filament color")); clr_picker->SetToolTip(_L("Click to pick filament color"));
clr_picker->Bind(wxEVT_BUTTON, [this](wxCommandEvent& e) { clr_picker->Bind(wxEVT_BUTTON, [this](wxCommandEvent& e) {
m_clrData.SetColour(clr_picker->GetBackgroundColour()); m_clrData.SetColour(clr_picker->GetBackgroundColour());

View File

@ -719,7 +719,7 @@ void Tab::update_label_colours()
(m_type < Preset::TYPE_COUNT ? &m_default_text_clr : &m_modified_label_clr); (m_type < Preset::TYPE_COUNT ? &m_default_text_clr : &m_modified_label_clr);
m_tabctrl->SetItemTextColour(cur_item, clr == &m_modified_label_clr ? *clr : StateColor( m_tabctrl->SetItemTextColour(cur_item, clr == &m_modified_label_clr ? *clr : StateColor(
std::make_pair(0x6B6B6B, (int) StateColor::NotChecked), std::make_pair(0x6B6B6C, (int) StateColor::NotChecked),
std::make_pair(*clr, (int) StateColor::Normal))); std::make_pair(*clr, (int) StateColor::Normal)));
break; break;
} }
@ -972,7 +972,7 @@ void Tab::update_changed_tree_ui()
if (page->set_item_colour(clr)) if (page->set_item_colour(clr))
m_tabctrl->SetItemTextColour(cur_item, clr == &m_modified_label_clr ? *clr : StateColor( m_tabctrl->SetItemTextColour(cur_item, clr == &m_modified_label_clr ? *clr : StateColor(
std::make_pair(0x6B6B6B, (int) StateColor::NotChecked), std::make_pair(0x6B6B6C, (int) StateColor::NotChecked),
std::make_pair(*clr, (int) StateColor::Normal))); std::make_pair(*clr, (int) StateColor::Normal)));
page->m_is_nonsys_values = !sys_page; page->m_is_nonsys_values = !sys_page;
@ -3657,7 +3657,7 @@ void Tab::rebuild_page_tree()
continue; continue;
auto itemId = m_tabctrl->AppendItem(translate_category(p->title(), m_type), p->iconID()); auto itemId = m_tabctrl->AppendItem(translate_category(p->title(), m_type), p->iconID());
m_tabctrl->SetItemTextColour(itemId, p->get_item_colour() == m_modified_label_clr ? p->get_item_colour() : StateColor( m_tabctrl->SetItemTextColour(itemId, p->get_item_colour() == m_modified_label_clr ? p->get_item_colour() : StateColor(
std::make_pair(0x6B6B6B, (int) StateColor::NotChecked), std::make_pair(0x6B6B6C, (int) StateColor::NotChecked),
std::make_pair(p->get_item_colour(), (int) StateColor::Normal))); std::make_pair(p->get_item_colour(), (int) StateColor::Normal)));
if (translate_category(p->title(), m_type) == selected) if (translate_category(p->title(), m_type) == selected)
item = itemId; item = itemId;

View File

@ -75,7 +75,7 @@ void TabButtonsListCtrl::OnPaint(wxPaintEvent &)
wxPoint pos = btn->GetPosition(); wxPoint pos = btn->GetPosition();
wxSize size = btn->GetSize(); wxSize size = btn->GetSize();
const wxColour &clr = idx == m_selection ? btn_marker_color : TAB_BUTTON_BG; const wxColour &clr = StateColor::darkModeColorFor(idx == m_selection ? btn_marker_color : TAB_BUTTON_BG);
dc.SetPen(clr); dc.SetPen(clr);
dc.SetBrush(clr); dc.SetBrush(clr);
dc.DrawRectangle(pos.x, pos.y + size.y, size.x, sz.y - size.y); dc.DrawRectangle(pos.x, pos.y + size.y, size.x, sz.y - size.y);

View File

@ -189,7 +189,7 @@ void DropDown::render(wxDC &dc)
if (texts.size() == 0) return; if (texts.size() == 0) return;
int states = state_handler.states(); int states = state_handler.states();
dc.SetPen(wxPen(border_color.colorForStates(states))); dc.SetPen(wxPen(border_color.colorForStates(states)));
dc.SetBrush(wxBrush(GetBackgroundColour())); dc.SetBrush(wxBrush(StateColor::darkModeColorFor(GetBackgroundColour())));
// if (GetWindowStyle() & wxBORDER_NONE) // if (GetWindowStyle() & wxBORDER_NONE)
// dc.SetPen(wxNullPen); // dc.SetPen(wxNullPen);

View File

@ -1,5 +1,73 @@
#include "StateColor.hpp" #include "StateColor.hpp"
static bool gDarkMode = false;
static bool operator<(wxColour const &l, wxColour const &r) { return l.GetRGBA() < r.GetRGBA(); }
static std::map<wxColour, wxColour> gDarkColors{
{"#00AE42", "#21A452"},
{"#1F8EEA", "#2778D2"},
{"#FF6F00", "#D15B00"},
{"#D01B1B", "#BB2A3A"},
{"#262E30", "#EFEFF0"},
{"#2C2C2E", "#B3B3B4"},
{"#6B6B6B", "#818183"},
{"#ACACAC", "#54545A"},
{"#EEEEEE", "#4C4C55"},
{"#E8E8E8", "#3E3E45"},
{"#323A3D", "#E5E5E4"},
{"#FFFFFF", "#2D2D31"},
{"#F8F8F8", "#36363C"},
{"#F1F1F1", "#36363B"},
{"#3B4446", "#2D2D30"},
{"#CECECE", "#54545B"},
{"#DBFDD5", "#3B3B40"},
{"#000000", "#FFFFFE"},
{"#F4F4F4", "#36363D"},
{"#DBDBDB", "#4A4A51"},
{"#EDFAF2", "#283232"},
{"#323A3C", "#E5E5E6"},
{"#6B6B6A", "#B3B3B5"},
{"#303A3C", "#E5E5E5"},
{"#FEFFFF", "#242428"},
{"#A6A9AA", "#2D2D29"},
{"#363636", "#B2B3B5"},
};
std::map<wxColour, wxColour> const & StateColor::GetDarkMap()
{
return gDarkColors;
}
void StateColor::SetDarkMode(bool dark) { gDarkMode = dark; }
inline wxColour darkModeColorFor2(wxColour const &color)
{
if (!gDarkMode)
return color;
auto iter = gDarkColors.find(color);
wxFAIL(iter != gDarkColors.end());
if (iter != gDarkColors.end()) return iter->second;
return color;
}
std::map<wxColour, wxColour> revert(std::map<wxColour, wxColour> const & map)
{
std::map<wxColour, wxColour> map2;
for (auto &p : map) map2.emplace(p.second, p.first);
return map2;
}
wxColour StateColor::lightModeColorFor(wxColour const &color)
{
static std::map<wxColour, wxColour> gLightColors = revert(gDarkColors);
auto iter = gLightColors.find(color);
wxFAIL(iter != gLightColors.end());
if (iter != gLightColors.end()) return iter->second;
return *wxRED;
}
wxColour StateColor::darkModeColorFor(wxColour const &color) { return darkModeColorFor2(color); }
StateColor::StateColor(wxColour const &color) { append(color, 0); } StateColor::StateColor(wxColour const &color) { append(color, 0); }
StateColor::StateColor(wxString const &color) { append(color, 0); } StateColor::StateColor(wxString const &color) { append(color, 0); }
@ -47,6 +115,27 @@ wxColour StateColor::defaultColor() {
} }
wxColour StateColor::colorForStates(int states) wxColour StateColor::colorForStates(int states)
{
bool focused = takeFocusedAsHovered_ && (states & Focused);
for (int i = 0; i < statesList_.size(); ++i) {
int s = statesList_[i];
int on = s & 0xffff;
int off = s >> 16;
if ((on & states) == on && (off & ~states) == off) {
return darkModeColorFor2(colors_[i]);
}
if (focused && (on & Hovered)) {
on |= Focused;
on &= ~Hovered;
if ((on & states) == on && (off & ~states) == off) {
return darkModeColorFor2(colors_[i]);
}
}
}
return wxColour(0, 0, 0, 0);
}
wxColour StateColor::colorForStatesNoDark(int states)
{ {
bool focused = takeFocusedAsHovered_ && (states & Focused); bool focused = takeFocusedAsHovered_ && (states & Focused);
for (int i = 0; i < statesList_.size(); ++i) { for (int i = 0; i < statesList_.size(); ++i) {
@ -90,4 +179,3 @@ bool StateColor::setColorForStates(wxColour const &color, int states)
} }
void StateColor::setTakeFocusedAsHovered(bool set) { takeFocusedAsHovered_ = set; } void StateColor::setTakeFocusedAsHovered(bool set) { takeFocusedAsHovered_ = set; }

View File

@ -3,6 +3,8 @@
#include <wx/colour.h> #include <wx/colour.h>
#include <map>
class StateColor class StateColor
{ {
public: public:
@ -20,6 +22,13 @@ public:
NotPressed = 16 << 16, NotPressed = 16 << 16,
}; };
public:
static void SetDarkMode(bool dark);
static std::map<wxColour, wxColour> const & GetDarkMap();
static wxColour darkModeColorFor(wxColour const &color);
static wxColour lightModeColorFor(wxColour const &color);
public: public:
template<typename ...Colors> template<typename ...Colors>
StateColor(std::pair<Colors, int>... colors) { StateColor(std::pair<Colors, int>... colors) {
@ -54,6 +63,8 @@ public:
wxColour colorForStates(int states); wxColour colorForStates(int states);
wxColour colorForStatesNoDark(int states);
int colorIndexForStates(int states); int colorIndexForStates(int states);
bool setColorForStates(wxColour const & color, int states); bool setColorForStates(wxColour const & color, int states);

View File

@ -1,5 +1,6 @@
#include "StaticLine.hpp" #include "StaticLine.hpp"
#include "Label.hpp" #include "Label.hpp"
#include "StateColor.hpp"
#include <wx/dcgraph.h> #include <wx/dcgraph.h>
@ -15,7 +16,7 @@ StaticLine::StaticLine(wxWindow *parent, bool vertical, const wxString &label, c
, vertical(vertical) , vertical(vertical)
{ {
wxWindow::SetBackgroundColour(parent->GetBackgroundColour()); wxWindow::SetBackgroundColour(parent->GetBackgroundColour());
this->pen = wxPen(wxColour("#EEEEEE")); this->lineColor = wxColour("#EEEEEE");
DisableFocusFromKeyboard(); DisableFocusFromKeyboard();
SetFont(Label::Body_14); SetFont(Label::Body_14);
wxWindow::SetLabel(label); wxWindow::SetLabel(label);
@ -39,7 +40,7 @@ void StaticLine::SetIcon(const wxString &icon)
void StaticLine::SetLineColour(wxColour color) void StaticLine::SetLineColour(wxColour color)
{ {
this->pen = wxPen(color); this->lineColor = color;
} }
void StaticLine::Rescale() void StaticLine::Rescale()
@ -98,10 +99,11 @@ void StaticLine::render(wxDC& dc)
titleRect.x += icon.GetBmpWidth() + 5; titleRect.x += icon.GetBmpWidth() + 5;
} }
if (!label.IsEmpty()) { if (!label.IsEmpty()) {
dc.SetTextForeground(StateColor::darkModeColorFor(GetForegroundColour()));
dc.DrawText(label, titleRect.x, (size.GetHeight() - textSize.GetHeight()) / 2); dc.DrawText(label, titleRect.x, (size.GetHeight() - textSize.GetHeight()) / 2);
titleRect.x += textSize.GetWidth() + 5; titleRect.x += textSize.GetWidth() + 5;
} }
dc.SetPen(pen); dc.SetPen(wxPen(StateColor::darkModeColorFor(lineColor)));
if (vertical) { if (vertical) {
size.x /= 2; size.x /= 2;
if (titleRect.y > 0) titleRect.y += 5; if (titleRect.y > 0) titleRect.y += 5;

View File

@ -19,7 +19,7 @@ public:
void Rescale(); void Rescale();
private: private:
wxPen pen; wxColour lineColor;
bool vertical; bool vertical;
ScalableBitmap icon; ScalableBitmap icon;

View File

@ -57,6 +57,7 @@ void SwitchButton::Rescale()
m_off.msw_rescale(); m_off.msw_rescale();
} }
else { else {
SetBackgroundColour(StaticBox::GetParentBackgroundColor(GetParent()));
#ifdef __WXOSX__ #ifdef __WXOSX__
auto scale = Slic3r::GUI::mac_max_scaling_factor(); auto scale = Slic3r::GUI::mac_max_scaling_factor();
int BS = (int) scale; int BS = (int) scale;

View File

@ -99,9 +99,9 @@ int TabCtrl::AppendItem(const wxString &item,
btn->Create(this, item, "", wxBORDER_NONE); btn->Create(this, item, "", wxBORDER_NONE);
btn->SetFont(GetFont()); btn->SetFont(GetFont());
btn->SetTextColor(StateColor( btn->SetTextColor(StateColor(
std::make_pair(0x6B6B6B, (int) StateColor::NotChecked), std::make_pair(0x6B6B6C, (int) StateColor::NotChecked),
std::make_pair(*wxLIGHT_GREY, (int) StateColor::Normal))); std::make_pair(*wxLIGHT_GREY, (int) StateColor::Normal)));
btn->SetBackgroundColor(GetBackgroundColour()); btn->SetBackgroundColor(StateColor());
btn->SetCornerRadius(0); btn->SetCornerRadius(0);
btn->SetPaddingSize({TAB_BUTTON_PADDING}); btn->SetPaddingSize({TAB_BUTTON_PADDING});
btns.push_back(btn); btns.push_back(btn);

View File

@ -194,7 +194,7 @@ void WipingPanel::create_panels(wxWindow* parent, const int num) {
auto sizer = new wxBoxSizer(wxHORIZONTAL); auto sizer = new wxBoxSizer(wxHORIZONTAL);
panel->SetSizer(sizer); panel->SetSizer(sizer);
wxButton* icon = new wxButton(panel, wxID_ANY, wxString("") << i + 1, wxDefaultPosition, ICON_SIZE, wxBORDER_NONE); wxButton *icon = new wxButton(panel, wxID_ANY, wxString("") << i + 1, wxDefaultPosition, ICON_SIZE, wxBORDER_NONE | wxBU_AUTODRAW);
icon->SetBackgroundColour(m_colours[i]); icon->SetBackgroundColour(m_colours[i]);
//auto icon_style = icon->GetWindowStyle() & ~(wxBORDER_NONE | wxBORDER_SIMPLE); //auto icon_style = icon->GetWindowStyle() & ~(wxBORDER_NONE | wxBORDER_SIMPLE);
//icon->SetWindowStyle(m_colours[i].Red() > 224 && m_colours[i].Blue() > 224 && m_colours[i].Green() > 224 ? (icon_style | wxBORDER_SIMPLE) : (icon_style | wxBORDER_NONE)); //icon->SetWindowStyle(m_colours[i].Red() > 224 && m_colours[i].Blue() > 224 && m_colours[i].Green() > 224 ? (icon_style | wxBORDER_SIMPLE) : (icon_style | wxBORDER_NONE));
@ -307,7 +307,7 @@ WipingPanel::WipingPanel(wxWindow* parent, const std::vector<float>& matrix, con
header_line_sizer->AddSpacer(HEADER_BEG_PADDING); header_line_sizer->AddSpacer(HEADER_BEG_PADDING);
for (unsigned int i = 0; i < m_number_of_extruders; ++i) { for (unsigned int i = 0; i < m_number_of_extruders; ++i) {
wxButton* icon = new wxButton(header_line_panel, wxID_ANY, wxString("") << i + 1, wxDefaultPosition, ICON_SIZE, wxBORDER_NONE); wxButton* icon = new wxButton(header_line_panel, wxID_ANY, wxString("") << i + 1, wxDefaultPosition, ICON_SIZE, wxBORDER_NONE | wxBU_AUTODRAW);
icon->SetBackgroundColour(m_colours[i]); icon->SetBackgroundColour(m_colours[i]);
//auto icon_style = icon->GetWindowStyle() & ~(wxBORDER_NONE | wxBORDER_SIMPLE); //auto icon_style = icon->GetWindowStyle() & ~(wxBORDER_NONE | wxBORDER_SIMPLE);
//icon->SetWindowStyle(m_colours[i].Red() > 224 && m_colours[i].Blue() > 224 && m_colours[i].Green() > 224 ? (icon_style | wxBORDER_SIMPLE) : (icon_style | wxBORDER_NONE)); //icon->SetWindowStyle(m_colours[i].Red() > 224 && m_colours[i].Blue() > 224 && m_colours[i].Green() > 224 ? (icon_style | wxBORDER_SIMPLE) : (icon_style | wxBORDER_NONE));