diff --git a/src/slic3r/CMakeLists.txt b/src/slic3r/CMakeLists.txt index 46d1a87da3..4ff280a560 100644 --- a/src/slic3r/CMakeLists.txt +++ b/src/slic3r/CMakeLists.txt @@ -386,6 +386,8 @@ set(SLIC3R_GUI_SOURCES GUI/AmsMappingPopup.cpp GUI/ReleaseNote.hpp GUI/ReleaseNote.cpp + GUI/SingleChoiceDialog.hpp + GUI/SingleChoiceDialog.cpp GUI/Calibration.hpp GUI/Calibration.cpp GUI/PrintOptionsDialog.hpp diff --git a/src/slic3r/GUI/GUI_ObjectList.cpp b/src/slic3r/GUI/GUI_ObjectList.cpp index 67306217b4..e5fa9cef20 100644 --- a/src/slic3r/GUI/GUI_ObjectList.cpp +++ b/src/slic3r/GUI/GUI_ObjectList.cpp @@ -21,6 +21,7 @@ #include "NotificationManager.hpp" #include "MsgDialog.hpp" #include "Widgets/ProgressDialog.hpp" +#include "SingleChoiceDialog.hpp" #include #include @@ -4940,7 +4941,8 @@ void ObjectList::change_part_type() } const wxString names[] = { _L("Part"), _L("Negative Part"), _L("Modifier"), _L("Support Blocker"), _L("Support Enforcer") }; - auto new_type = ModelVolumeType(wxGetApp().GetSingleChoiceIndex(_L("Type:"), _L("Choose part type"), wxArrayString(5, names), int(type))); + SingleChoiceDialog dlg(_L("Type:"), _L("Choose part type"), wxArrayString(5, names), int(type)); + auto new_type = ModelVolumeType(dlg.GetSingleChoiceIndex()); if (new_type == type || new_type == ModelVolumeType::INVALID) return; diff --git a/src/slic3r/GUI/SingleChoiceDialog.cpp b/src/slic3r/GUI/SingleChoiceDialog.cpp new file mode 100644 index 0000000000..15808dc0ed --- /dev/null +++ b/src/slic3r/GUI/SingleChoiceDialog.cpp @@ -0,0 +1,69 @@ +#include "SingleChoiceDialog.hpp" + +#include "GUI_App.hpp" +#include "MainFrame.hpp" + +namespace Slic3r { namespace GUI { + +SingleChoiceDialog::SingleChoiceDialog(const wxString &message, const wxString &caption, const wxArrayString &choices, int initialSelection, wxWindow *parent) + : DPIDialog(parent ? parent : static_cast(wxGetApp().mainframe), wxID_ANY, caption, wxDefaultPosition, wxDefaultSize, wxCAPTION | wxCLOSE_BOX) +{ + SetBackgroundColour(*wxWHITE); + + const int dlg_width = 200; + wxBoxSizer *bSizer = new wxBoxSizer(wxVERTICAL); + bSizer->SetMinSize(wxSize(FromDIP(dlg_width), -1)); + + wxStaticText *message_text = new wxStaticText(this, wxID_ANY, message, wxDefaultPosition, wxDefaultSize, 0); + message_text->Wrap(-1); + bSizer->Add(message_text, 0, wxALL, 5); + + type_comboBox = new ComboBox(this, wxID_ANY, choices[0], wxDefaultPosition, wxSize(FromDIP(dlg_width - 10), -1), 0, NULL, wxCB_READONLY); + for (const wxString &type_name : choices) { type_comboBox->Append(type_name); } + bSizer->Add(type_comboBox, 0, wxALL | wxALIGN_CENTER, 5); + bSizer->Add(0, 0, 1, wxEXPAND, FromDIP(type_comboBox->GetClientSize().GetHeight())); + type_comboBox->SetSelection(initialSelection); + + wxBoxSizer *bSizer_button = new wxBoxSizer(wxHORIZONTAL); + + StateColor btn_bg_green(std::pair(wxColour(27, 136, 68), StateColor::Pressed), std::pair(wxColour(61, 203, 115), StateColor::Hovered), + std::pair(AMS_CONTROL_BRAND_COLOUR, StateColor::Normal)); + + m_button_ok = new Button(this, _L("OK")); + m_button_ok->SetBackgroundColor(btn_bg_green); + m_button_ok->SetBorderColor(*wxWHITE); + m_button_ok->SetTextColor(wxColour(0xFFFFFE)); + m_button_ok->SetFont(Label::Body_12); + m_button_ok->SetSize(wxSize(FromDIP(58), FromDIP(24))); + m_button_ok->SetMinSize(wxSize(FromDIP(58), FromDIP(24))); + m_button_ok->SetCornerRadius(FromDIP(12)); + bSizer_button->Add(m_button_ok, 0, wxALIGN_CENTER_VERTICAL | wxRIGHT, FromDIP(int(dlg_width - 58 * 2) / 6)); + + m_button_ok->Bind(wxEVT_LEFT_DOWN, [this](wxMouseEvent &e) { EndModal(wxID_OK); }); + + StateColor btn_bg_white(std::pair(wxColour(206, 206, 206), StateColor::Pressed), std::pair(wxColour(238, 238, 238), StateColor::Hovered), + std::pair(*wxWHITE, StateColor::Normal)); + + m_button_cancel = new Button(this, _L("Cancel")); + m_button_cancel->SetBackgroundColor(btn_bg_white); + m_button_cancel->SetBorderColor(wxColour(38, 46, 48)); + m_button_cancel->SetFont(Label::Body_12); + m_button_cancel->SetSize(wxSize(FromDIP(58), FromDIP(24))); + m_button_cancel->SetMinSize(wxSize(FromDIP(58), FromDIP(24))); + m_button_cancel->SetCornerRadius(FromDIP(12)); + bSizer_button->Add(m_button_cancel, 0, wxALIGN_CENTER_VERTICAL | wxLEFT, FromDIP(int(dlg_width - 58 * 2) / 6)); + + m_button_cancel->Bind(wxEVT_LEFT_DOWN, [this](wxMouseEvent &e) { EndModal(wxID_CANCEL); }); + + bSizer->Add(bSizer_button, 1, wxALIGN_CENTER_HORIZONTAL | wxBOTTOM, FromDIP(5)); + + this->SetSizer(bSizer); + this->Layout(); + bSizer->Fit(this); + wxGetApp().UpdateDlgDarkUI(this); +} +SingleChoiceDialog::~SingleChoiceDialog() {} +int SingleChoiceDialog::GetSingleChoiceIndex() { return this->ShowModal() == wxID_OK ? GetTypeComboBox()->GetSelection() : -1; } + +void SingleChoiceDialog::on_dpi_changed(const wxRect &suggested_rect) {} +}} // namespace Slic3r::GUI \ No newline at end of file diff --git a/src/slic3r/GUI/SingleChoiceDialog.hpp b/src/slic3r/GUI/SingleChoiceDialog.hpp new file mode 100644 index 0000000000..1e7b12d272 --- /dev/null +++ b/src/slic3r/GUI/SingleChoiceDialog.hpp @@ -0,0 +1,29 @@ +#ifndef slic3r_GUI_SingleChoice_hpp_ +#define slic3r_GUI_SingleChoice_hpp_ + +#include "GUI_Utils.hpp" +#include "Widgets/Button.hpp" +#include "Widgets/ComboBox.hpp" + +namespace Slic3r { namespace GUI { + +class SingleChoiceDialog : public DPIDialog +{ +public: + SingleChoiceDialog(const wxString &message, const wxString &caption, const wxArrayString &choices, int initialSelectionwx, wxWindow *parent = nullptr); + ~SingleChoiceDialog(); + + int GetSingleChoiceIndex(); + ComboBox *GetTypeComboBox() { return type_comboBox; }; + + void on_dpi_changed(const wxRect &suggested_rect) override; + +protected: + ComboBox *type_comboBox = nullptr; + Button * m_button_ok = nullptr; + Button * m_button_cancel = nullptr; +}; + +}} // namespace Slic3r::GUI + +#endif \ No newline at end of file