From 200a811dca759f9d2c169bfcc8fa99346b8bf152 Mon Sep 17 00:00:00 2001 From: "zhou.xu" Date: Wed, 15 Jan 2025 12:18:58 +0800 Subject: [PATCH] ENH:add "text to image" function in TextInput jira: none Change-Id: Ibdb57b74511432e81faa0c556bb6e639d5a174f5 (cherry picked from commit 09323aeed34f29f105b95d3d6a2c7a151e17e42a) --- resources/images/BambuStudioBlack.svg | 13 +++++++++++++ src/slic3r/GUI/AmsMappingPopup.cpp | 2 +- src/slic3r/GUI/Plater.cpp | 7 ++++--- src/slic3r/GUI/PresetComboBoxes.cpp | 4 +++- src/slic3r/GUI/SyncAmsInfoDialog.cpp | 8 ++++---- src/slic3r/GUI/Widgets/ComboBox.cpp | 21 +++++++++++++++++++-- src/slic3r/GUI/Widgets/ComboBox.hpp | 4 ++++ src/slic3r/GUI/Widgets/TextInput.cpp | 27 +++++++++++++++++++++++++++ src/slic3r/GUI/Widgets/TextInput.hpp | 3 +++ 9 files changed, 78 insertions(+), 11 deletions(-) create mode 100644 resources/images/BambuStudioBlack.svg diff --git a/resources/images/BambuStudioBlack.svg b/resources/images/BambuStudioBlack.svg new file mode 100644 index 0000000000..3363a7e8ce --- /dev/null +++ b/resources/images/BambuStudioBlack.svg @@ -0,0 +1,13 @@ + + + + + + + + + + + + + diff --git a/src/slic3r/GUI/AmsMappingPopup.cpp b/src/slic3r/GUI/AmsMappingPopup.cpp index 353ef65971..97024a7585 100644 --- a/src/slic3r/GUI/AmsMappingPopup.cpp +++ b/src/slic3r/GUI/AmsMappingPopup.cpp @@ -553,7 +553,7 @@ void AmsMapingPopup::update(MachineObject* obj) m_left_extra_slot->Hide(); //m_left_marea_panel->Show(); m_right_marea_panel->Show(); - set_sizer_title(m_right_split_ams_sizer, _L("Ams")); + set_sizer_title(m_right_split_ams_sizer, _L("AMS")); m_right_extra_slot->Show(); } else if (nozzle_nums > 1) { diff --git a/src/slic3r/GUI/Plater.cpp b/src/slic3r/GUI/Plater.cpp index c6870c4ba7..787e769747 100644 --- a/src/slic3r/GUI/Plater.cpp +++ b/src/slic3r/GUI/Plater.cpp @@ -2618,8 +2618,10 @@ void Sidebar::load_ams_list(std::string const &device, MachineObject* obj) return; wxGetApp().preset_bundle->filament_ams_list = filament_ams_list; - for (auto c : p->combos_filament) + for (auto c : p->combos_filament){ c->update(); + c->ShowBadge(false);//change printer,then clear badge + } p->combo_printer->update(); } @@ -2730,9 +2732,8 @@ void Sidebar::sync_ams_list() } } auto badge_combox_filament = [](PlaterPresetComboBox *c) { - auto cur_tip = c->GetToolTip()->GetTip(); auto tip = _L("\nMaterial and color information have been synchronized, but slot information is not included."); - c->SetToolTip(cur_tip + tip); + c->SetToolTip(tip); c->ShowBadge(true); }; { // badge ams filament diff --git a/src/slic3r/GUI/PresetComboBoxes.cpp b/src/slic3r/GUI/PresetComboBoxes.cpp index 15876492ed..b968e32f31 100644 --- a/src/slic3r/GUI/PresetComboBoxes.cpp +++ b/src/slic3r/GUI/PresetComboBoxes.cpp @@ -1185,8 +1185,10 @@ void PlaterPresetComboBox::update() if (m_type == Preset::TYPE_PRINTER) add_connected_printers("", true); - if (m_type == Preset::TYPE_FILAMENT && m_preset_bundle->is_bbl_vendor()) + if (m_type == Preset::TYPE_FILAMENT && m_preset_bundle->is_bbl_vendor()) { + set_replace_text("Bambu", "BambuStudioBlack"); add_ams_filaments(into_u8(selected_user_preset), true); + } //BBS: add project embedded preset logic if (!project_embedded_presets.empty()) diff --git a/src/slic3r/GUI/SyncAmsInfoDialog.cpp b/src/slic3r/GUI/SyncAmsInfoDialog.cpp index c49dfb9622..fc0e1aae7d 100644 --- a/src/slic3r/GUI/SyncAmsInfoDialog.cpp +++ b/src/slic3r/GUI/SyncAmsInfoDialog.cpp @@ -136,8 +136,6 @@ void SyncAmsInfoDialog::updata_ui_data_after_connected_printer() { if (!m_input_info.connected_printer) { return; } if (is_dirty_filament()) { return; } - show_sizer(m_plate_combox_sizer, true); - update_printer_name();//m_printer_is_map_title is in m_plate_combox_sizer show_sizer(m_sizer_line, true); show_sizer(m_sizer_two_image, true); @@ -1167,9 +1165,8 @@ SyncAmsInfoDialog::SyncAmsInfoDialog(wxWindow *parent, SyncInfo &info) : tip_sizer->Add(m_attention_text, 0, wxALIGN_LEFT | wxTOP, FromDIP(2)); m_tip_text = new wxStaticText(this, wxID_ANY, _L("Only synchronize filament type and color, not including AMS slot information.")); m_tip_text->SetForegroundColour(wxColour(107, 107, 107, 100)); - tip_sizer->AddSpacer(FromDIP(25)); tip_sizer->Add(m_tip_text, 0, wxALIGN_LEFT | wxTOP, FromDIP(2)); - + tip_sizer->AddSpacer(FromDIP(25)); bSizer->Add(tip_sizer, 0, wxEXPAND | wxLEFT, FromDIP(25)); add_two_image_control(); @@ -3200,6 +3197,9 @@ void SyncAmsInfoDialog::on_timer(wxTimerEvent &event) update_select_layout(obj_); update_ams_check(obj_); m_check_flag = true; + + show_sizer(m_plate_combox_sizer, true); + update_printer_name(); // m_printer_is_map_title is in m_plate_combox_sizer } if (!obj_ || obj_->amsList.empty() || obj_->ams_exist_bits == 0 || !obj_->is_support_filament_backup || !obj_->is_support_show_filament_backup || diff --git a/src/slic3r/GUI/Widgets/ComboBox.cpp b/src/slic3r/GUI/Widgets/ComboBox.cpp index 3fe59c9a5d..c29ff2ad1d 100644 --- a/src/slic3r/GUI/Widgets/ComboBox.cpp +++ b/src/slic3r/GUI/Widgets/ComboBox.cpp @@ -121,8 +121,18 @@ void ComboBox::SetLabel(const wxString &value) { if (GetTextCtrl()->IsShown() || text_off) GetTextCtrl()->SetValue(value); - else - TextInput::SetLabel(value); + else { + if (is_replace_text_to_image) { + auto new_value = value; + new_value.Replace(replace_text, "", false);//replace first text + TextInput::SetIcon_1(image_for_text); + TextInput::SetLabel(new_value); + } + else { + TextInput::SetIcon_1(""); + TextInput::SetLabel(value); + } + } } wxString ComboBox::GetLabel() const @@ -201,6 +211,13 @@ void ComboBox::DoDeleteOneItem(unsigned int pos) unsigned int ComboBox::GetCount() const { return items.size(); } +void ComboBox::set_replace_text(wxString text, wxString image_name) +{ + replace_text = text; + image_for_text = image_name; + is_replace_text_to_image = true; +} + wxString ComboBox::GetString(unsigned int n) const { return n < items.size() ? items[n].text : wxString{}; } diff --git a/src/slic3r/GUI/Widgets/ComboBox.hpp b/src/slic3r/GUI/Widgets/ComboBox.hpp index 535c965c1c..ae00144d79 100644 --- a/src/slic3r/GUI/Widgets/ComboBox.hpp +++ b/src/slic3r/GUI/Widgets/ComboBox.hpp @@ -15,6 +15,9 @@ class ComboBox : public wxWindowWithItems DropDown drop; bool drop_down = false; bool text_off = false; + bool is_replace_text_to_image = false; + wxString replace_text; + wxString image_for_text; public: ComboBox(wxWindow * parent, @@ -37,6 +40,7 @@ public: int Append(const wxString &item, const wxBitmap &bitmap, const wxString &group, void *clientData = nullptr); + void set_replace_text(wxString text, wxString image_name); unsigned int GetCount() const override; int GetSelection() const override; diff --git a/src/slic3r/GUI/Widgets/TextInput.cpp b/src/slic3r/GUI/Widgets/TextInput.cpp index 1318044f66..787972022d 100644 --- a/src/slic3r/GUI/Widgets/TextInput.cpp +++ b/src/slic3r/GUI/Widgets/TextInput.cpp @@ -111,6 +111,17 @@ void TextInput::SetIcon(const wxString &icon) Rescale(); } +void TextInput::SetIcon_1(const wxString &icon) { + if (this->icon_1.name() == icon.ToStdString()) + return; + if (icon.empty()) { + this->icon_1 = ScalableBitmap(); + return; + } + this->icon_1 = ScalableBitmap(this, icon.ToStdString(), 16); + Rescale(); +} + void TextInput::SetLabelColor(StateColor const &color) { label_color = color; @@ -127,6 +138,8 @@ void TextInput::Rescale() { if (!this->icon.name().empty()) this->icon.msw_rescale(); + if (!this->icon_1.name().empty()) + this->icon_1.msw_rescale(); messureSize(); Refresh(); } @@ -166,6 +179,10 @@ void TextInput::DoSetSize(int x, int y, int width, int height, int sizeFlags) wxSize szIcon = this->icon.GetBmpSize(); textPos.x += szIcon.x; } + if (this->icon_1.bmp().IsOk()) { + wxSize szIcon = this->icon_1.GetBmpSize(); + textPos.x += (szIcon.x); + } bool align_right = GetWindowStyle() & wxALIGN_RIGHT; if (align_right) textPos.x += labelSize.x; @@ -214,6 +231,16 @@ void TextInput::render(wxDC& dc) dc.DrawBitmap(icon.bmp(), pt); pt.x += szIcon.x + 0; } + if (icon_1.bmp().IsOk()) { + wxSize szIcon = icon_1.GetBmpSize(); + pt.y = (size.y - szIcon.y) / 2; + if (align_center) { + if (pt.x * 2 + szIcon.x + 0 + labelSize.x < size.x) + pt.x = (size.x - (szIcon.x + 0 + labelSize.x)) / 2; + } + dc.DrawBitmap(icon_1.bmp(), pt); + pt.x += szIcon.x + 0; + } auto text = wxWindow::GetLabel(); if (!text.IsEmpty()) { wxSize textSize = text_ctrl->GetSize(); diff --git a/src/slic3r/GUI/Widgets/TextInput.hpp b/src/slic3r/GUI/Widgets/TextInput.hpp index 61f729506c..d44a4e6303 100644 --- a/src/slic3r/GUI/Widgets/TextInput.hpp +++ b/src/slic3r/GUI/Widgets/TextInput.hpp @@ -9,6 +9,7 @@ class TextInput : public wxNavigationEnabled wxSize labelSize; ScalableBitmap icon; + ScalableBitmap icon_1; StateColor label_color; StateColor text_color; wxTextCtrl * text_ctrl; @@ -44,6 +45,8 @@ public: void SetIcon(const wxString & icon); + void SetIcon_1(const wxString &icon); + void SetLabelColor(StateColor const &color); void SetTextColor(StateColor const &color);