DarkMode for MSW (#6632)

* MSW specific: Dark Mode: First implementation

* Use menu instead of NoteBook

* Implemented MessageDialog
+ Fixed DarkMode for all dialogs and ColorPicker

* MSW DarkMode: Added missed updates for the switching between modes

* MSW DarkMode: Updated all existed context menus after switching of the mode
+ Added markers for the menu item witch is related to the selected tab

* Used wxFrame instead of wxDialog for SettingsDialog
(this change allow us to use menu bar in SettingsDialog)

+ fix for #6548 - Prusa Slicer 2.3.1 not activating non-modal settings window if settings window is minimized

* Implemented "Always use Dark mode colors" preference option

* Fixes for non_MSW build

* Next fixes for non-MSW builds

* Preferences: Fixed selection of the Settings Layout for non-MSW platforms
+ Updated DarkMode for colorpickers

* Windows DarkMode next fixes

* MSWDarkMode: Suppress to use system color to the PrusaSlicer
Select "Preferences -> Use Dark color mode (experimental)" to allow dark mode for the application

* Fixed MSW build

* MSWDarkMode: Upadteed color mode for ExtruderSequenceDialog and for dialogs related to the DoubleSlider

* Implemented Auto recreation of the PrusaSlicer when color mode is changed.

* Preferences: Added option "Set settings tabs as menu items (experimental)"
This commit is contained in:
Oleksandra Yushchenko 2021-06-18 19:46:04 +02:00 committed by GitHub
parent 65f440c2ba
commit fd071421cb
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
66 changed files with 2011 additions and 443 deletions

View file

@ -15,6 +15,7 @@
#include "GUI_Utils.hpp"
#include "Plater.hpp"
#include "../Utils/MacDarkMode.hpp"
#include "BitmapComboBox.hpp"
#ifndef __linux__
// msw_menuitem_bitmaps is used for MSW and OSX
@ -26,7 +27,7 @@ void msw_rescale_menu(wxMenu* menu)
static void run(wxMenuItem* item) {
const auto it = msw_menuitem_bitmaps.find(item->GetId());
if (it != msw_menuitem_bitmaps.end()) {
const wxBitmap& item_icon = create_scaled_bitmap(it->second);
const wxBitmap& item_icon = create_menu_bitmap(it->second);
if (item_icon.IsOk())
item->SetBitmap(item_icon);
}
@ -96,7 +97,7 @@ wxMenuItem* append_menu_item(wxMenu* menu, int id, const wxString& string, const
if (id == wxID_ANY)
id = wxNewId();
const wxBitmap& bmp = !icon.empty() ? create_scaled_bitmap(icon) : wxNullBitmap; // FIXME: pass window ptr
const wxBitmap& bmp = !icon.empty() ? create_menu_bitmap(icon) : wxNullBitmap; // FIXME: pass window ptr
//#ifdef __WXMSW__
#ifndef __WXGTK__
if (bmp.IsOk())
@ -114,7 +115,7 @@ wxMenuItem* append_submenu(wxMenu* menu, wxMenu* sub_menu, int id, const wxStrin
wxMenuItem* item = new wxMenuItem(menu, id, string, description);
if (!icon.empty()) {
item->SetBitmap(create_scaled_bitmap(icon)); // FIXME: pass window ptr
item->SetBitmap(create_menu_bitmap(icon)); // FIXME: pass window ptr
//#ifdef __WXMSW__
#ifndef __WXGTK__
msw_menuitem_bitmaps[id] = icon;
@ -416,13 +417,19 @@ int mode_icon_px_size()
#endif
}
wxBitmap create_menu_bitmap(const std::string& bmp_name)
{
return create_scaled_bitmap(bmp_name, nullptr, 16, false, true);
}
// win is used to get a correct em_unit value
// It's important for bitmaps of dialogs.
// if win == nullptr, em_unit value of MainFrame will be used
wxBitmap create_scaled_bitmap( const std::string& bmp_name_in,
wxWindow *win/* = nullptr*/,
const int px_cnt/* = 16*/,
const bool grayscale/* = false*/)
const bool grayscale/* = false*/,
const bool menu_bitmap/* = false*/)
{
static Slic3r::GUI::BitmapCache cache;
@ -432,8 +439,14 @@ wxBitmap create_scaled_bitmap( const std::string& bmp_name_in,
std::string bmp_name = bmp_name_in;
boost::replace_last(bmp_name, ".png", "");
bool dark_mode =
#ifdef _WIN32
menu_bitmap ? Slic3r::GUI::check_dark_mode() :
#endif
Slic3r::GUI::wxGetApp().dark_mode();
// Try loading an SVG first, then PNG if SVG is not found:
wxBitmap *bmp = cache.load_svg(bmp_name, width, height, grayscale, Slic3r::GUI::wxGetApp().dark_mode());
wxBitmap *bmp = cache.load_svg(bmp_name, width, height, grayscale, dark_mode);
if (bmp == nullptr) {
bmp = cache.load_png(bmp_name, width, height, grayscale);
}
@ -487,7 +500,7 @@ std::vector<wxBitmap*> get_extruder_color_icons(bool thin_icon/* = false*/)
}
void apply_extruder_selector(wxBitmapComboBox** ctrl,
void apply_extruder_selector(Slic3r::GUI::BitmapComboBox** ctrl,
wxWindow* parent,
const std::string& first_item/* = ""*/,
wxPoint pos/* = wxDefaultPosition*/,
@ -496,9 +509,10 @@ void apply_extruder_selector(wxBitmapComboBox** ctrl,
{
std::vector<wxBitmap*> icons = get_extruder_color_icons(use_thin_icon);
if (!*ctrl)
*ctrl = new wxBitmapComboBox(parent, wxID_ANY, wxEmptyString, pos, size,
0, nullptr, wxCB_READONLY);
if (!*ctrl) {
*ctrl = new Slic3r::GUI::BitmapComboBox(parent, wxID_ANY, wxEmptyString, pos, size, 0, nullptr, wxCB_READONLY);
Slic3r::GUI::wxGetApp().UpdateDarkUI(*ctrl);
}
else
{
(*ctrl)->SetPosition(pos);
@ -550,9 +564,7 @@ LockButton::LockButton( wxWindow *parent,
m_bmp_lock_open = ScalableBitmap(this, "lock_open");
m_bmp_lock_open_f = ScalableBitmap(this, "lock_open_f");
#ifdef __WXMSW__
SetBackgroundColour(wxSystemSettings::GetColour(wxSYS_COLOUR_WINDOW));
#endif // __WXMSW__
Slic3r::GUI::wxGetApp().UpdateDarkUI(this);
SetBitmap(m_bmp_lock_open.bmp());
SetBitmapDisabled(m_bmp_lock_open.bmp());
SetBitmapHover(m_bmp_lock_closed_f.bmp());
@ -590,9 +602,7 @@ void LockButton::msw_rescale()
void LockButton::update_button_bitmaps()
{
#ifdef __WXMSW__
SetBackgroundColour(wxSystemSettings::GetColour(wxSYS_COLOUR_WINDOW));
#endif
Slic3r::GUI::wxGetApp().UpdateDarkUI(this);
SetBitmap(m_is_pushed ? m_bmp_lock_closed.bmp() : m_bmp_lock_open.bmp());
SetBitmapHover(m_is_pushed ? m_bmp_lock_closed_f.bmp() : m_bmp_lock_open_f.bmp());
@ -662,6 +672,7 @@ void ModeButton::focus_button(const bool focus)
Slic3r::GUI::wxGetApp().normal_font();
SetFont(new_font);
#ifndef _WIN32
SetForegroundColour(wxSystemSettings::GetColour(focus ? wxSYS_COLOUR_BTNTEXT :
#if defined (__linux__) && defined (__WXGTK3__)
wxSYS_COLOUR_GRAYTEXT
@ -671,6 +682,7 @@ void ModeButton::focus_button(const bool focus)
wxSYS_COLOUR_BTNSHADOW
#endif
));
#endif /* no _WIN32 */
Refresh();
Update();
@ -820,13 +832,11 @@ ScalableButton::ScalableButton( wxWindow * parent,
m_parent(parent),
m_current_icon_name(icon_name),
m_use_default_disabled_bitmap (use_default_disabled_bitmap),
m_px_cnt(bmp_px_cnt)
m_px_cnt(bmp_px_cnt),
m_has_border(!(style & wxNO_BORDER))
{
Create(parent, id, label, pos, size, style);
#ifdef __WXMSW__
if (style & wxNO_BORDER)
SetBackgroundColour(wxSystemSettings::GetColour(wxSYS_COLOUR_WINDOW));
#endif // __WXMSW__
Slic3r::GUI::wxGetApp().UpdateDarkUI(this);
SetBitmap(create_scaled_bitmap(icon_name, parent, m_px_cnt));
if (m_use_default_disabled_bitmap)
@ -848,13 +858,11 @@ ScalableButton::ScalableButton( wxWindow * parent,
long style /*= wxBU_EXACTFIT | wxNO_BORDER*/) :
m_parent(parent),
m_current_icon_name(bitmap.name()),
m_px_cnt(bitmap.px_cnt())
m_px_cnt(bitmap.px_cnt()),
m_has_border(!(style& wxNO_BORDER))
{
Create(parent, id, label, wxDefaultPosition, wxDefaultSize, style);
#ifdef __WXMSW__
if (style & wxNO_BORDER)
SetBackgroundColour(wxSystemSettings::GetColour(wxSYS_COLOUR_WINDOW));
#endif // __WXMSW__
Slic3r::GUI::wxGetApp().UpdateDarkUI(this);
SetBitmap(bitmap.bmp());
}
@ -888,9 +896,8 @@ void ScalableButton::UseDefaultBitmapDisabled()
void ScalableButton::msw_rescale()
{
#ifdef __WXMSW__
SetBackgroundColour(wxSystemSettings::GetColour(wxSYS_COLOUR_WINDOW));
#endif
Slic3r::GUI::wxGetApp().UpdateDarkUI(this, m_has_border);
SetBitmap(create_scaled_bitmap(m_current_icon_name, m_parent, m_px_cnt));
if (!m_disabled_icon_name.empty())
SetBitmapDisabled(create_scaled_bitmap(m_disabled_icon_name, m_parent, m_px_cnt));