From a148b9d85f1eb5b24c1d9afc45a15e247fba7554 Mon Sep 17 00:00:00 2001 From: SoftFever Date: Sat, 19 Aug 2023 09:30:54 +0800 Subject: [PATCH] fix build error --- src/slic3r/GUI/PlateSettingsDialog.cpp | 88 +------------------------- src/slic3r/GUI/wxExtensions.cpp | 49 ++++++++++++++ src/slic3r/GUI/wxExtensions.hpp | 1 + 3 files changed, 53 insertions(+), 85 deletions(-) diff --git a/src/slic3r/GUI/PlateSettingsDialog.cpp b/src/slic3r/GUI/PlateSettingsDialog.cpp index a40d20c94c..454b59adc9 100644 --- a/src/slic3r/GUI/PlateSettingsDialog.cpp +++ b/src/slic3r/GUI/PlateSettingsDialog.cpp @@ -215,6 +215,9 @@ void PlateSettingsDialog::on_dpi_changed(const wxRect& suggested_rect) wxString PlateSettingsDialog::get_plate_name() const { return m_ti_plate_name->GetTextCtrl()->GetValue(); +} + +void PlateSettingsDialog::set_plate_name(const wxString &name) { m_ti_plate_name->GetTextCtrl()->SetValue(name); } std::vector PlateSettingsDialog::get_first_layer_print_seq() { @@ -222,89 +225,4 @@ std::vector PlateSettingsDialog::get_first_layer_print_seq() } -//PlateNameEditDialog -PlateNameEditDialog::PlateNameEditDialog(wxWindow *parent, wxWindowID id, const wxString &title, const wxPoint &pos, const wxSize &size, long style) - : DPIDialog(parent, id, title, pos, size, style) -{ - std::string icon_path = (boost::format("%1%/images/BambuStudioTitle.ico") % resources_dir()).str(); - SetIcon(wxIcon(encode_path(icon_path.c_str()), wxBITMAP_TYPE_ICO)); - - SetBackgroundColour(*wxWHITE); - wxBoxSizer *m_sizer_main = new wxBoxSizer(wxVERTICAL); - auto m_line_top = new wxPanel(this, wxID_ANY, wxDefaultPosition, wxSize(FromDIP(400), -1)); - m_line_top->SetBackgroundColour(wxColour(166, 169, 170)); - m_sizer_main->Add(m_line_top, 0, wxEXPAND, 0); - m_sizer_main->Add(0, 0, 0, wxTOP, FromDIP(5)); - - wxFlexGridSizer *top_sizer = new wxFlexGridSizer(0, 2, FromDIP(5), 0); - top_sizer->AddGrowableCol(0, 1); - top_sizer->SetFlexibleDirection(wxBOTH); - top_sizer->SetNonFlexibleGrowMode(wxFLEX_GROWMODE_SPECIFIED); - - auto plate_name_txt = new wxStaticText(this, wxID_ANY, _L("Plate name")); - plate_name_txt->SetFont(Label::Body_14); - m_ti_plate_name = new TextInput(this, wxString::FromDouble(0.0), "", "", wxDefaultPosition, wxSize(FromDIP(240), -1), wxTE_PROCESS_ENTER); - top_sizer->Add(plate_name_txt, 0, wxALIGN_CENTER_VERTICAL | wxALIGN_LEFT | wxALL, FromDIP(5)); - top_sizer->Add(m_ti_plate_name, 0, wxALIGN_CENTER_VERTICAL | wxALIGN_RIGHT | wxALL, FromDIP(5)); - m_ti_plate_name->GetTextCtrl()->SetMaxLength(40); - - m_sizer_main->Add(top_sizer, 0, wxEXPAND | wxALL, FromDIP(30)); - - auto sizer_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(wxColour(0, 174, 66), StateColor::Normal)); - - 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_ok = new Button(this, _L("OK")); - m_button_ok->SetBackgroundColor(btn_bg_green); - m_button_ok->SetBorderColor(*wxWHITE); - m_button_ok->SetTextColor(wxColour("#FFFFFE")); - 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)); - m_button_ok->Bind(wxEVT_LEFT_DOWN, [this](wxMouseEvent &e) { - wxCommandEvent evt(EVT_SET_BED_TYPE_CONFIRM, GetId()); - e.SetEventObject(this); - GetEventHandler()->ProcessEvent(evt); - if (this->IsModal()) - EndModal(wxID_YES); - else - this->Close(); - }); - - 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)); - m_button_cancel->Bind(wxEVT_LEFT_DOWN, [this](wxMouseEvent &e) { - if (this->IsModal()) - EndModal(wxID_NO); - else - this->Close(); - }); - - sizer_button->AddStretchSpacer(); - sizer_button->Add(m_button_ok, 0, wxALL, FromDIP(5)); - sizer_button->Add(m_button_cancel, 0, wxALL, FromDIP(5)); - sizer_button->Add(FromDIP(30), 0, 0, 0); - - m_sizer_main->Add(sizer_button, 0, wxEXPAND, FromDIP(20)); - - SetSizer(m_sizer_main); - Layout(); - m_sizer_main->Fit(this); - - CenterOnParent(); - - wxGetApp().UpdateDlgDarkUI(this); -} - -void PlateSettingsDialog::set_plate_name(const wxString &name) { m_ti_plate_name->GetTextCtrl()->SetValue(name); } - }} // namespace Slic3r::GUI \ No newline at end of file diff --git a/src/slic3r/GUI/wxExtensions.cpp b/src/slic3r/GUI/wxExtensions.cpp index b17a58ef4a..b4ab1969a4 100644 --- a/src/slic3r/GUI/wxExtensions.cpp +++ b/src/slic3r/GUI/wxExtensions.cpp @@ -559,6 +559,55 @@ std::vector get_extruder_color_icons(bool thin_icon/* = false*/) return bmps; } +wxBitmap *get_extruder_color_icon(std::string color, std::string label, int icon_width, int icon_height) +{ + static Slic3r::GUI::BitmapCache bmp_cache; + + std::string bitmap_key = color + "-h" + std::to_string(icon_height) + "-w" + std::to_string(icon_width) + "-i" + label; + + wxBitmap *bitmap = bmp_cache.find(bitmap_key); + if (bitmap == nullptr) { + // Paint the color icon. + // Slic3r::GUI::BitmapCache::parse_color(color, rgb); + // there is no neede to scale created solid bitmap + wxColor clr(color); + bitmap = bmp_cache.insert(bitmap_key, wxBitmap(icon_width, icon_height)); +#ifndef __WXMSW__ + wxMemoryDC dc; +#else + wxClientDC cdc((wxWindow *) Slic3r::GUI::wxGetApp().mainframe); + wxMemoryDC dc(&cdc); +#endif + dc.SetFont(::Label::Body_12); + dc.SelectObject(*bitmap); + if (clr.Alpha() == 0) { + int size = icon_height * 2; + static wxBitmap transparent = *Slic3r::GUI::BitmapCache().load_svg("transparent", size, size); + if (transparent.GetHeight() != size) transparent = *Slic3r::GUI::BitmapCache().load_svg("transparent", size, size); + wxPoint pt(0, 0); + while (pt.x < icon_width) { + dc.DrawBitmap(transparent, pt); + pt.x += size; + } + clr.SetRGB(0xffffff); // for text color + dc.SetBrush(*wxTRANSPARENT_BRUSH); + } else { + dc.SetBackground(wxBrush(clr)); + dc.Clear(); + dc.SetBrush(wxBrush(clr)); + } + if (clr.Red() > 224 && clr.Blue() > 224 && clr.Green() > 224) { + dc.SetPen(*wxGREY_PEN); + dc.DrawRectangle(0, 0, icon_width, icon_height); + } + auto size = dc.GetTextExtent(wxString(label)); + dc.SetTextForeground(clr.GetLuminance() < 0.51 ? *wxWHITE : *wxBLACK); + dc.DrawText(label, (icon_width - size.x) / 2, (icon_height - size.y) / 2); + dc.SelectObject(wxNullBitmap); + } + return bitmap; +} + void apply_extruder_selector(Slic3r::GUI::BitmapComboBox** ctrl, wxWindow* parent, diff --git a/src/slic3r/GUI/wxExtensions.hpp b/src/slic3r/GUI/wxExtensions.hpp index e890d30ae3..7b5c8ee09b 100644 --- a/src/slic3r/GUI/wxExtensions.hpp +++ b/src/slic3r/GUI/wxExtensions.hpp @@ -67,6 +67,7 @@ wxBitmap create_scaled_bitmap(const std::string& bmp_name, wxWindow *win = nullp wxBitmap* get_default_extruder_color_icon(bool thin_icon = false); std::vector get_extruder_color_icons(bool thin_icon = false); +wxBitmap * get_extruder_color_icon(std::string color, std::string label, int icon_width, int icon_height); namespace Slic3r { namespace GUI {