diff --git a/resources/images/filament_transparent.svg b/resources/images/filament_transparent.svg new file mode 100644 index 000000000..07bf35a7a --- /dev/null +++ b/resources/images/filament_transparent.svg @@ -0,0 +1,39 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/src/slic3r/GUI/DragDropPanel.cpp b/src/slic3r/GUI/DragDropPanel.cpp index 588f1d2d0..4b10f9728 100644 --- a/src/slic3r/GUI/DragDropPanel.cpp +++ b/src/slic3r/GUI/DragDropPanel.cpp @@ -7,7 +7,7 @@ namespace Slic3r { namespace GUI { struct CustomData { int filament_id; - unsigned char r, g, b; + unsigned char r, g, b, a; }; @@ -43,7 +43,7 @@ public: set_custom_data_color(color); } - wxColour GetColor() const { return wxColor(m_data.r, m_data.g, m_data.b); } + wxColour GetColor() const { return wxColor(m_data.r, m_data.g, m_data.b, m_data.a); } void SetColor(const wxColour &color) { set_custom_data_color(color); } int GetFilament() const { return m_data.filament_id; } @@ -57,6 +57,7 @@ public: m_data.r = color.Red(); m_data.g = color.Green(); m_data.b = color.Blue(); + m_data.a = color.Alpha(); } virtual size_t GetDataSize() const override { return sizeof(m_data); } @@ -101,7 +102,11 @@ void ColorPanel::OnPaint(wxPaintEvent &event) wxPaintDC dc(this); wxSize size = GetSize(); std::string replace_color = m_color.GetAsString(wxC2S_HTML_SYNTAX).ToStdString(); - wxBitmap bmp = ScalableBitmap(this, "filament_green", 40, false, false, false, { replace_color }).bmp(); + std::string svg_name = "filament_green"; + if (replace_color == "#FFFFFF00") { + svg_name = "filament_transparent"; + } + wxBitmap bmp = ScalableBitmap(this, svg_name, 40, false, false, false, { replace_color }).bmp(); dc.DrawBitmap(bmp, wxPoint(0,0)); wxString label = wxString::Format(wxT("%d"), m_filament_id); dc.SetTextForeground(m_color.GetLuminance() < 0.51 ? *wxWHITE : *wxBLACK); // set text color diff --git a/src/slic3r/GUI/ImGuiWrapper.cpp b/src/slic3r/GUI/ImGuiWrapper.cpp index b875669bb..4d6a9a6ca 100644 --- a/src/slic3r/GUI/ImGuiWrapper.cpp +++ b/src/slic3r/GUI/ImGuiWrapper.cpp @@ -2908,9 +2908,14 @@ void ImGuiWrapper::filament_group(const std::string &filament_type, const char * float img_width = ImGui::CalcTextSize("ABC").x; ImVec2 img_size = {img_width, img_width * 1.5f}; ImVec2 id_text_size = this->calc_text_size(id); - unsigned char rgb[3]; - - BitmapCache::load_from_svg_file_change_color(Slic3r::resources_dir() + "/images/filament_green.svg", img_size.x, img_size.y, transparent, hex_color); + unsigned char rgba[4]; + rgba[3] = 0xff; + Slic3r::GUI::BitmapCache::parse_color4(hex_color, rgba); + std::string svg_path = "/images/filament_green.svg"; + if (rgba[3] == 0x00) { + svg_path = "/images/filament_transparent.svg"; + } + BitmapCache::load_from_svg_file_change_color(Slic3r::resources_dir() + svg_path, img_size.x, img_size.y, transparent, hex_color); ImGui::BeginGroup(); { ImVec2 cursor_pos = ImGui::GetCursorScreenPos(); @@ -2919,8 +2924,8 @@ void ImGuiWrapper::filament_group(const std::string &filament_type, const char * // draw_list->AddRect(cursor_pos, {cursor_pos.x + img_size.x, cursor_pos.y + img_size.y}, IM_COL32(0, 0, 0, 255)); ImVec2 current_cursor = ImGui::GetCursorPos(); ImGui::SetCursorPos({current_cursor.x + (img_size.x - id_text_size.x) * 0.5f + 2, current_cursor.y + (img_size.y - id_text_size.y) * 0.5f - 2}); - Slic3r::GUI::BitmapCache::parse_color(hex_color, rgb); - float gray = 0.299 * rgb[0] + 0.587 * rgb[1] + 0.114 * rgb[2]; + + float gray = 0.299 * rgba[0] + 0.587 * rgba[1] + 0.114 * rgba[2]; ImVec4 text_color = gray < 80 ? ImVec4(1.0f, 1.0f, 1.0f, 1.0f) : ImVec4(0, 0, 0, 1.0f); this->text_colored(text_color, id.c_str()); float text_width_max = four_word_width;