mirror of
https://github.com/SoftFever/OrcaSlicer.git
synced 2025-11-30 06:11:05 -07:00
ENH: dark mode of StateColor
Change-Id: I5928898c50280c7f2eedbb9389032230c7e251c4
This commit is contained in:
parent
faec57d263
commit
b209243b27
20 changed files with 155 additions and 38 deletions
|
|
@ -189,7 +189,7 @@ void DropDown::render(wxDC &dc)
|
|||
if (texts.size() == 0) return;
|
||||
int states = state_handler.states();
|
||||
dc.SetPen(wxPen(border_color.colorForStates(states)));
|
||||
dc.SetBrush(wxBrush(GetBackgroundColour()));
|
||||
dc.SetBrush(wxBrush(StateColor::darkModeColorFor(GetBackgroundColour())));
|
||||
// if (GetWindowStyle() & wxBORDER_NONE)
|
||||
// dc.SetPen(wxNullPen);
|
||||
|
||||
|
|
|
|||
|
|
@ -1,5 +1,73 @@
|
|||
#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(wxString const &color) { append(color, 0); }
|
||||
|
|
@ -47,6 +115,27 @@ wxColour StateColor::defaultColor() {
|
|||
}
|
||||
|
||||
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);
|
||||
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; }
|
||||
|
||||
|
|
|
|||
|
|
@ -3,6 +3,8 @@
|
|||
|
||||
#include <wx/colour.h>
|
||||
|
||||
#include <map>
|
||||
|
||||
class StateColor
|
||||
{
|
||||
public:
|
||||
|
|
@ -20,6 +22,13 @@ public:
|
|||
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:
|
||||
template<typename ...Colors>
|
||||
StateColor(std::pair<Colors, int>... colors) {
|
||||
|
|
@ -54,6 +63,8 @@ public:
|
|||
|
||||
wxColour colorForStates(int states);
|
||||
|
||||
wxColour colorForStatesNoDark(int states);
|
||||
|
||||
int colorIndexForStates(int states);
|
||||
|
||||
bool setColorForStates(wxColour const & color, int states);
|
||||
|
|
|
|||
|
|
@ -1,5 +1,6 @@
|
|||
#include "StaticLine.hpp"
|
||||
#include "Label.hpp"
|
||||
#include "StateColor.hpp"
|
||||
|
||||
#include <wx/dcgraph.h>
|
||||
|
||||
|
|
@ -15,7 +16,7 @@ StaticLine::StaticLine(wxWindow *parent, bool vertical, const wxString &label, c
|
|||
, vertical(vertical)
|
||||
{
|
||||
wxWindow::SetBackgroundColour(parent->GetBackgroundColour());
|
||||
this->pen = wxPen(wxColour("#EEEEEE"));
|
||||
this->lineColor = wxColour("#EEEEEE");
|
||||
DisableFocusFromKeyboard();
|
||||
SetFont(Label::Body_14);
|
||||
wxWindow::SetLabel(label);
|
||||
|
|
@ -39,7 +40,7 @@ void StaticLine::SetIcon(const wxString &icon)
|
|||
|
||||
void StaticLine::SetLineColour(wxColour color)
|
||||
{
|
||||
this->pen = wxPen(color);
|
||||
this->lineColor = color;
|
||||
}
|
||||
|
||||
void StaticLine::Rescale()
|
||||
|
|
@ -98,10 +99,11 @@ void StaticLine::render(wxDC& dc)
|
|||
titleRect.x += icon.GetBmpWidth() + 5;
|
||||
}
|
||||
if (!label.IsEmpty()) {
|
||||
dc.SetTextForeground(StateColor::darkModeColorFor(GetForegroundColour()));
|
||||
dc.DrawText(label, titleRect.x, (size.GetHeight() - textSize.GetHeight()) / 2);
|
||||
titleRect.x += textSize.GetWidth() + 5;
|
||||
}
|
||||
dc.SetPen(pen);
|
||||
dc.SetPen(wxPen(StateColor::darkModeColorFor(lineColor)));
|
||||
if (vertical) {
|
||||
size.x /= 2;
|
||||
if (titleRect.y > 0) titleRect.y += 5;
|
||||
|
|
|
|||
|
|
@ -19,7 +19,7 @@ public:
|
|||
void Rescale();
|
||||
|
||||
private:
|
||||
wxPen pen;
|
||||
wxColour lineColor;
|
||||
bool vertical;
|
||||
ScalableBitmap icon;
|
||||
|
||||
|
|
|
|||
|
|
@ -57,6 +57,7 @@ void SwitchButton::Rescale()
|
|||
m_off.msw_rescale();
|
||||
}
|
||||
else {
|
||||
SetBackgroundColour(StaticBox::GetParentBackgroundColor(GetParent()));
|
||||
#ifdef __WXOSX__
|
||||
auto scale = Slic3r::GUI::mac_max_scaling_factor();
|
||||
int BS = (int) scale;
|
||||
|
|
|
|||
|
|
@ -99,9 +99,9 @@ int TabCtrl::AppendItem(const wxString &item,
|
|||
btn->Create(this, item, "", wxBORDER_NONE);
|
||||
btn->SetFont(GetFont());
|
||||
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)));
|
||||
btn->SetBackgroundColor(GetBackgroundColour());
|
||||
btn->SetBackgroundColor(StateColor());
|
||||
btn->SetCornerRadius(0);
|
||||
btn->SetPaddingSize({TAB_BUTTON_PADDING});
|
||||
btns.push_back(btn);
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue