mirror of
https://github.com/OrcaSlicer/OrcaSlicer.git
synced 2026-09-09 10:16:50 +00:00
Make sure settings tab are still marked as modified even if modified variant is not currently selected
This commit is contained in:
@@ -395,6 +395,171 @@ void ModeSwitchButton::update_tooltip()
|
||||
SetToolTip(m_tooltips[m_selection]);
|
||||
}
|
||||
|
||||
SwitchBoard::SwitchBoard(wxWindow *parent, wxString leftL, wxString right, wxSize size)
|
||||
: wxWindow(parent, wxID_ANY, wxDefaultPosition, size)
|
||||
{
|
||||
#ifdef __WINDOWS__
|
||||
SetDoubleBuffered(true);
|
||||
#endif //__WINDOWS__
|
||||
|
||||
SetBackgroundColour(*wxWHITE);
|
||||
leftLabel = leftL;
|
||||
rightLabel = right;
|
||||
|
||||
SetMinSize(size);
|
||||
SetMaxSize(size);
|
||||
|
||||
Bind(wxEVT_PAINT, &SwitchBoard::paintEvent, this);
|
||||
Bind(wxEVT_LEFT_DOWN, &SwitchBoard::on_left_down, this);
|
||||
|
||||
Bind(wxEVT_ENTER_WINDOW, [this](auto &e) { SetCursor(wxCURSOR_HAND); });
|
||||
Bind(wxEVT_LEAVE_WINDOW, [this](auto &e) { SetCursor(wxCURSOR_ARROW); });
|
||||
}
|
||||
|
||||
void SwitchBoard::updateState(wxString target)
|
||||
{
|
||||
if (target.empty()) {
|
||||
if (!switch_left && !switch_right) {
|
||||
return;
|
||||
}
|
||||
|
||||
switch_left = false;
|
||||
switch_right = false;
|
||||
} else {
|
||||
if (target == "left") {
|
||||
if (switch_left && !switch_right) {
|
||||
return;
|
||||
}
|
||||
|
||||
switch_left = true;
|
||||
switch_right = false;
|
||||
} else if (target == "right") {
|
||||
if (!switch_left && switch_right) {
|
||||
return;
|
||||
}
|
||||
|
||||
switch_left = false;
|
||||
switch_right = true;
|
||||
}
|
||||
}
|
||||
|
||||
Refresh();
|
||||
}
|
||||
|
||||
void SwitchBoard::paintEvent(wxPaintEvent &evt)
|
||||
{
|
||||
wxPaintDC dc(this);
|
||||
render(dc);
|
||||
}
|
||||
|
||||
void SwitchBoard::render(wxDC &dc)
|
||||
{
|
||||
#ifdef __WXMSW__
|
||||
wxSize size = GetSize();
|
||||
wxMemoryDC memdc;
|
||||
wxBitmap bmp(size.x, size.y);
|
||||
memdc.SelectObject(bmp);
|
||||
memdc.Blit({0, 0}, size, &dc, {0, 0});
|
||||
|
||||
{
|
||||
wxGCDC dc2(memdc);
|
||||
doRender(dc2);
|
||||
}
|
||||
|
||||
memdc.SelectObject(wxNullBitmap);
|
||||
dc.DrawBitmap(bmp, 0, 0);
|
||||
#else
|
||||
doRender(dc);
|
||||
#endif
|
||||
}
|
||||
|
||||
void SwitchBoard::doRender(wxDC &dc)
|
||||
{
|
||||
wxColour disable_color = wxColour(0xCECECE);
|
||||
|
||||
dc.SetPen(*wxTRANSPARENT_PEN);
|
||||
|
||||
if (is_enable) {dc.SetBrush(wxBrush(0xeeeeee));
|
||||
} else {dc.SetBrush(disable_color);}
|
||||
dc.DrawRoundedRectangle(0, 0, GetSize().x, GetSize().y, 8);
|
||||
|
||||
/*left*/
|
||||
if (switch_left) {
|
||||
is_enable ? dc.SetBrush(wxBrush(wxColour(0, 150, 136))) : dc.SetBrush(disable_color);
|
||||
dc.DrawRoundedRectangle(0, 0, GetSize().x / 2, GetSize().y, 8);
|
||||
}
|
||||
|
||||
if (switch_left) {
|
||||
dc.SetTextForeground(*wxWHITE);
|
||||
} else {
|
||||
dc.SetTextForeground(0x333333);
|
||||
}
|
||||
|
||||
dc.SetFont(::Label::Body_13);
|
||||
Slic3r::GUI::WxFontUtils::get_suitable_font_size(0.6 * GetSize().GetHeight(), dc);
|
||||
|
||||
auto left_txt_size = dc.GetTextExtent(leftLabel);
|
||||
dc.DrawText(leftLabel, wxPoint((GetSize().x / 2 - left_txt_size.x) / 2, (GetSize().y - left_txt_size.y) / 2));
|
||||
|
||||
/*right*/
|
||||
if (switch_right) {
|
||||
if (is_enable) {dc.SetBrush(wxBrush(wxColour(0, 150, 136)));
|
||||
} else {dc.SetBrush(disable_color);}
|
||||
dc.DrawRoundedRectangle(GetSize().x / 2, 0, GetSize().x / 2, GetSize().y, 8);
|
||||
}
|
||||
|
||||
auto right_txt_size = dc.GetTextExtent(rightLabel);
|
||||
if (switch_right) {
|
||||
dc.SetTextForeground(*wxWHITE);
|
||||
} else {
|
||||
dc.SetTextForeground(0x333333);
|
||||
}
|
||||
dc.DrawText(rightLabel, wxPoint((GetSize().x / 2 - right_txt_size.x) / 2 + GetSize().x / 2, (GetSize().y - right_txt_size.y) / 2));
|
||||
|
||||
}
|
||||
|
||||
void SwitchBoard::on_left_down(wxMouseEvent &evt)
|
||||
{
|
||||
if (!is_enable) {
|
||||
return;
|
||||
}
|
||||
int index = -1;
|
||||
auto pos = ClientToScreen(evt.GetPosition());
|
||||
auto rect = ClientToScreen(wxPoint(0, 0));
|
||||
|
||||
if (pos.x > 0 && pos.x < rect.x + GetSize().x / 2) {
|
||||
switch_left = true;
|
||||
switch_right = false;
|
||||
index = 1;
|
||||
} else {
|
||||
switch_left = false;
|
||||
switch_right = true;
|
||||
index = 0;
|
||||
}
|
||||
|
||||
if (auto_disable_when_switch)
|
||||
{
|
||||
is_enable = false;// make it disable while switching
|
||||
}
|
||||
Refresh();
|
||||
|
||||
wxCommandEvent event(wxCUSTOMEVT_SWITCH_POS);
|
||||
event.SetInt(index);
|
||||
wxPostEvent(this, event);
|
||||
}
|
||||
|
||||
bool SwitchBoard::Enable(bool enable /* = true */)
|
||||
{
|
||||
if (is_enable == enable)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
is_enable = enable;
|
||||
Refresh();
|
||||
return true;
|
||||
}
|
||||
|
||||
MultiSwitchButton::MultiSwitchButton(wxWindow *parent, wxWindowID id, const wxPoint &pos, const wxSize &size, long style)
|
||||
: StaticBox(parent, id, pos, size, style)
|
||||
, m_bg_color(StateColor(
|
||||
@@ -580,168 +745,3 @@ bool MultiSwitchButton::send_selection_event()
|
||||
GetEventHandler()->ProcessEvent(evt);
|
||||
return true;
|
||||
}
|
||||
|
||||
SwitchBoard::SwitchBoard(wxWindow *parent, wxString leftL, wxString right, wxSize size)
|
||||
: wxWindow(parent, wxID_ANY, wxDefaultPosition, size)
|
||||
{
|
||||
#ifdef __WINDOWS__
|
||||
SetDoubleBuffered(true);
|
||||
#endif //__WINDOWS__
|
||||
|
||||
SetBackgroundColour(*wxWHITE);
|
||||
leftLabel = leftL;
|
||||
rightLabel = right;
|
||||
|
||||
SetMinSize(size);
|
||||
SetMaxSize(size);
|
||||
|
||||
Bind(wxEVT_PAINT, &SwitchBoard::paintEvent, this);
|
||||
Bind(wxEVT_LEFT_DOWN, &SwitchBoard::on_left_down, this);
|
||||
|
||||
Bind(wxEVT_ENTER_WINDOW, [this](auto &e) { SetCursor(wxCURSOR_HAND); });
|
||||
Bind(wxEVT_LEAVE_WINDOW, [this](auto &e) { SetCursor(wxCURSOR_ARROW); });
|
||||
}
|
||||
|
||||
void SwitchBoard::updateState(wxString target)
|
||||
{
|
||||
if (target.empty()) {
|
||||
if (!switch_left && !switch_right) {
|
||||
return;
|
||||
}
|
||||
|
||||
switch_left = false;
|
||||
switch_right = false;
|
||||
} else {
|
||||
if (target == "left") {
|
||||
if (switch_left && !switch_right) {
|
||||
return;
|
||||
}
|
||||
|
||||
switch_left = true;
|
||||
switch_right = false;
|
||||
} else if (target == "right") {
|
||||
if (!switch_left && switch_right) {
|
||||
return;
|
||||
}
|
||||
|
||||
switch_left = false;
|
||||
switch_right = true;
|
||||
}
|
||||
}
|
||||
|
||||
Refresh();
|
||||
}
|
||||
|
||||
void SwitchBoard::paintEvent(wxPaintEvent &evt)
|
||||
{
|
||||
wxPaintDC dc(this);
|
||||
render(dc);
|
||||
}
|
||||
|
||||
void SwitchBoard::render(wxDC &dc)
|
||||
{
|
||||
#ifdef __WXMSW__
|
||||
wxSize size = GetSize();
|
||||
wxMemoryDC memdc;
|
||||
wxBitmap bmp(size.x, size.y);
|
||||
memdc.SelectObject(bmp);
|
||||
memdc.Blit({0, 0}, size, &dc, {0, 0});
|
||||
|
||||
{
|
||||
wxGCDC dc2(memdc);
|
||||
doRender(dc2);
|
||||
}
|
||||
|
||||
memdc.SelectObject(wxNullBitmap);
|
||||
dc.DrawBitmap(bmp, 0, 0);
|
||||
#else
|
||||
doRender(dc);
|
||||
#endif
|
||||
}
|
||||
|
||||
void SwitchBoard::doRender(wxDC &dc)
|
||||
{
|
||||
wxColour disable_color = wxColour(0xCECECE);
|
||||
|
||||
dc.SetPen(*wxTRANSPARENT_PEN);
|
||||
|
||||
if (is_enable) {dc.SetBrush(wxBrush(0xeeeeee));
|
||||
} else {dc.SetBrush(disable_color);}
|
||||
dc.DrawRoundedRectangle(0, 0, GetSize().x, GetSize().y, 8);
|
||||
|
||||
/*left*/
|
||||
if (switch_left) {
|
||||
is_enable ? dc.SetBrush(wxBrush(wxColour(0, 150, 136))) : dc.SetBrush(disable_color);
|
||||
dc.DrawRoundedRectangle(0, 0, GetSize().x / 2, GetSize().y, 8);
|
||||
}
|
||||
|
||||
if (switch_left) {
|
||||
dc.SetTextForeground(*wxWHITE);
|
||||
} else {
|
||||
dc.SetTextForeground(0x333333);
|
||||
}
|
||||
|
||||
dc.SetFont(::Label::Body_13);
|
||||
Slic3r::GUI::WxFontUtils::get_suitable_font_size(0.6 * GetSize().GetHeight(), dc);
|
||||
|
||||
auto left_txt_size = dc.GetTextExtent(leftLabel);
|
||||
dc.DrawText(leftLabel, wxPoint((GetSize().x / 2 - left_txt_size.x) / 2, (GetSize().y - left_txt_size.y) / 2));
|
||||
|
||||
/*right*/
|
||||
if (switch_right) {
|
||||
if (is_enable) {dc.SetBrush(wxBrush(wxColour(0, 150, 136)));
|
||||
} else {dc.SetBrush(disable_color);}
|
||||
dc.DrawRoundedRectangle(GetSize().x / 2, 0, GetSize().x / 2, GetSize().y, 8);
|
||||
}
|
||||
|
||||
auto right_txt_size = dc.GetTextExtent(rightLabel);
|
||||
if (switch_right) {
|
||||
dc.SetTextForeground(*wxWHITE);
|
||||
} else {
|
||||
dc.SetTextForeground(0x333333);
|
||||
}
|
||||
dc.DrawText(rightLabel, wxPoint((GetSize().x / 2 - right_txt_size.x) / 2 + GetSize().x / 2, (GetSize().y - right_txt_size.y) / 2));
|
||||
|
||||
}
|
||||
|
||||
void SwitchBoard::on_left_down(wxMouseEvent &evt)
|
||||
{
|
||||
if (!is_enable) {
|
||||
return;
|
||||
}
|
||||
int index = -1;
|
||||
auto pos = ClientToScreen(evt.GetPosition());
|
||||
auto rect = ClientToScreen(wxPoint(0, 0));
|
||||
|
||||
if (pos.x > 0 && pos.x < rect.x + GetSize().x / 2) {
|
||||
switch_left = true;
|
||||
switch_right = false;
|
||||
index = 1;
|
||||
} else {
|
||||
switch_left = false;
|
||||
switch_right = true;
|
||||
index = 0;
|
||||
}
|
||||
|
||||
if (auto_disable_when_switch)
|
||||
{
|
||||
is_enable = false;// make it disable while switching
|
||||
}
|
||||
Refresh();
|
||||
|
||||
wxCommandEvent event(wxCUSTOMEVT_SWITCH_POS);
|
||||
event.SetInt(index);
|
||||
wxPostEvent(this, event);
|
||||
}
|
||||
|
||||
bool SwitchBoard::Enable(bool enable /* = true */)
|
||||
{
|
||||
if (is_enable == enable)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
is_enable = enable;
|
||||
Refresh();
|
||||
return true;
|
||||
}
|
||||
|
||||
@@ -8,12 +8,11 @@
|
||||
#include <vector>
|
||||
#include <wx/sizer.h>
|
||||
#include <wx/tglbtn.h>
|
||||
#include "Button.hpp"
|
||||
|
||||
wxDECLARE_EVENT(wxCUSTOMEVT_SWITCH_POS, wxCommandEvent);
|
||||
wxDECLARE_EVENT(wxCUSTOMEVT_MULTISWITCH_SELECTION, wxCommandEvent);
|
||||
|
||||
class Button;
|
||||
|
||||
class SwitchButton : public wxBitmapToggleButton
|
||||
{
|
||||
public:
|
||||
@@ -81,53 +80,6 @@ private:
|
||||
wxString m_tooltips[3];
|
||||
};
|
||||
|
||||
class MultiSwitchButton : public StaticBox
|
||||
{
|
||||
public:
|
||||
MultiSwitchButton(wxWindow *parent = nullptr, wxWindowID id = wxID_ANY, const wxPoint &pos = wxDefaultPosition,
|
||||
const wxSize &size = wxDefaultSize, long style = 0);
|
||||
~MultiSwitchButton();
|
||||
|
||||
int AppendOption(const wxString &option, void *clientData = nullptr);
|
||||
void SetOptions(const std::vector<wxString> &options);
|
||||
void DeleteAllOptions();
|
||||
|
||||
unsigned int GetCount() const;
|
||||
|
||||
int GetSelection() const;
|
||||
void SetSelection(int index);
|
||||
wxString GetSelectedText() const;
|
||||
|
||||
wxString GetOptionText(unsigned int index) const;
|
||||
void SetOptionText(unsigned int index, const wxString &text);
|
||||
|
||||
void *GetOptionData(unsigned int index) const;
|
||||
void SetOptionData(unsigned int index, void *clientData);
|
||||
|
||||
void SetBackgroundColor(const StateColor &color);
|
||||
void SetTextColor(const StateColor &color);
|
||||
void SetButtonCornerRadius(double radius);
|
||||
void SetButtonPadding(const wxSize &padding);
|
||||
|
||||
void Rescale();
|
||||
|
||||
protected:
|
||||
void button_clicked(wxCommandEvent &event);
|
||||
void update_button_styles();
|
||||
|
||||
bool send_selection_event();
|
||||
|
||||
private:
|
||||
std::vector<Button *> btns;
|
||||
wxBoxSizer *sizer = nullptr;
|
||||
int sel = -1;
|
||||
|
||||
StateColor m_bg_color;
|
||||
StateColor m_text_color;
|
||||
double m_button_radius;
|
||||
wxSize m_button_padding;
|
||||
};
|
||||
|
||||
class SwitchBoard : public wxWindow
|
||||
{
|
||||
public:
|
||||
@@ -163,4 +115,63 @@ private:
|
||||
bool auto_disable_when_switch = false;
|
||||
};
|
||||
|
||||
class MultiSwitchButton : public StaticBox
|
||||
{
|
||||
public:
|
||||
MultiSwitchButton(wxWindow *parent = nullptr, wxWindowID id = wxID_ANY, const wxPoint &pos = wxDefaultPosition,
|
||||
const wxSize &size = wxDefaultSize, long style = 0);
|
||||
~MultiSwitchButton();
|
||||
|
||||
int AppendOption(const wxString &option, void *clientData = nullptr);
|
||||
void SetOptions(const std::vector<wxString> &options);
|
||||
void DeleteAllOptions();
|
||||
|
||||
unsigned int GetCount() const;
|
||||
|
||||
int GetSelection() const;
|
||||
void SetSelection(int index);
|
||||
wxString GetSelectedText() const;
|
||||
|
||||
Button* GetButton(unsigned int index) const
|
||||
{
|
||||
return index >= 0 && index < btns.size() ? btns[index] : nullptr;
|
||||
}
|
||||
|
||||
wxString GetOptionText(unsigned int index) const;
|
||||
void SetOptionText(unsigned int index, const wxString &text);
|
||||
|
||||
void *GetOptionData(unsigned int index) const;
|
||||
void SetOptionData(unsigned int index, void *clientData);
|
||||
|
||||
void SetBackgroundColor(const StateColor &color);
|
||||
void SetTextColor(const StateColor &color);
|
||||
void SetButtonTextColor(int index, const StateColor &color)
|
||||
{
|
||||
if (index >= btns.size()) return;
|
||||
|
||||
btns[index]->SetTextColor(color);
|
||||
btns[index]->Refresh();
|
||||
}
|
||||
void SetButtonCornerRadius(double radius);
|
||||
void SetButtonPadding(const wxSize &padding);
|
||||
|
||||
void Rescale();
|
||||
|
||||
protected:
|
||||
void button_clicked(wxCommandEvent &event);
|
||||
void update_button_styles();
|
||||
|
||||
bool send_selection_event();
|
||||
|
||||
private:
|
||||
std::vector<Button *> btns;
|
||||
wxBoxSizer *sizer = nullptr;
|
||||
int sel = -1;
|
||||
|
||||
StateColor m_bg_color;
|
||||
StateColor m_text_color;
|
||||
double m_button_radius;
|
||||
wxSize m_button_padding;
|
||||
};
|
||||
|
||||
#endif // !slic3r_GUI_SwitchButton_hpp_
|
||||
|
||||
Reference in New Issue
Block a user