Fix:filament svg icon add transparent color

jira: STUDIO-9929
Change-Id: I7650670988d3c3538818278417ab9fb48c232400
This commit is contained in:
Mack 2025-01-20 19:52:23 +08:00 committed by lane.wei
parent 07e77c3d61
commit 45e7d7bb7d
3 changed files with 57 additions and 8 deletions

View File

@ -0,0 +1,39 @@
<svg width="30" height="40" viewBox="0 0 30 40" fill="none" xmlns="http://www.w3.org/2000/svg">
<rect x="19.7593" y="9.39136" width="3.59999" height="3.5734" fill="#D9D9D9"/>
<rect x="12.5596" y="5.81812" width="3.59999" height="3.5734" fill="white"/>
<rect x="16.1592" y="5.81812" width="3.59999" height="3.5734" fill="#D9D9D9"/>
<rect x="8.62891" y="5.81812" width="3.92951" height="3.5734" fill="#D9D9D9"/>
<rect x="12.5591" y="9.39136" width="3.59999" height="3.5734" fill="#D9D9D9"/>
<rect x="19.7598" y="5.81812" width="3.59999" height="3.5734" fill="white"/>
<rect x="16.1597" y="9.39136" width="3.59999" height="3.5734" fill="white"/>
<rect x="8.62939" y="9.39136" width="3.92951" height="3.5734" fill="white"/>
<rect x="19.7593" y="16.5383" width="3.59999" height="3.5734" fill="#D9D9D9"/>
<rect x="12.5591" y="12.9648" width="3.59999" height="3.5734" fill="white"/>
<rect x="16.1597" y="12.9648" width="3.59999" height="3.5734" fill="#D9D9D9"/>
<rect x="8.62939" y="12.9648" width="3.92951" height="3.5734" fill="#D9D9D9"/>
<rect x="12.5591" y="16.5383" width="3.59999" height="3.5734" fill="#D9D9D9"/>
<rect x="19.7593" y="12.9648" width="3.59999" height="3.5734" fill="white"/>
<rect x="16.1597" y="16.5383" width="3.59999" height="3.5734" fill="white"/>
<rect x="8.62939" y="16.5383" width="3.92951" height="3.5734" fill="white"/>
<rect x="19.7593" y="23.6853" width="3.59999" height="3.5734" fill="#D9D9D9"/>
<rect x="12.5591" y="20.1116" width="3.59999" height="3.5734" fill="white"/>
<rect x="16.1597" y="20.1116" width="3.59999" height="3.5734" fill="#D9D9D9"/>
<rect x="8.62939" y="20.1116" width="3.92951" height="3.5734" fill="#D9D9D9"/>
<rect x="12.5591" y="23.6853" width="3.59999" height="3.5734" fill="#D9D9D9"/>
<rect x="19.7593" y="20.1116" width="3.59999" height="3.5734" fill="white"/>
<rect x="16.1597" y="23.6853" width="3.59999" height="3.5734" fill="white"/>
<rect x="8.62939" y="23.6853" width="3.92951" height="3.5734" fill="white"/>
<rect x="19.7593" y="30.6084" width="3.59999" height="3.5734" fill="#D9D9D9"/>
<rect x="12.5591" y="27.0354" width="3.59999" height="3.5734" fill="white"/>
<rect x="16.1597" y="27.0354" width="3.59999" height="3.5734" fill="#D9D9D9"/>
<rect x="8.62939" y="27.0354" width="3.92951" height="3.5734" fill="#D9D9D9"/>
<rect x="12.5591" y="30.6084" width="3.59999" height="3.5734" fill="#D9D9D9"/>
<rect x="19.7593" y="27.0354" width="3.59999" height="3.5734" fill="white"/>
<rect x="16.1597" y="30.6084" width="3.59999" height="3.5734" fill="white"/>
<rect x="8.62939" y="30.6084" width="3.92951" height="3.5734" fill="white"/>
<path d="M23.2596 37.5131C25.5229 37.5131 27.3577 29.5764 27.3577 19.7859C27.3577 9.99536 25.5229 2.05859 23.2596 2.05859C22.3784 2.05859 21.3802 3.55703 20.7119 5.60405H22.2969C22.7771 6.93611 23.7442 11.4734 23.7442 20.5097C23.7442 29.546 22.4689 33.0115 22.2969 34.0043H20.8278C21.5273 36.4088 22.2967 37.5131 23.2596 37.5131Z" fill="#F2F2F2"/>
<path d="M20.7119 5.60405C21.3802 3.55703 22.3784 2.05859 23.2596 2.05859C25.5229 2.05859 27.3577 9.99536 27.3577 19.7859C27.3577 29.5764 25.5229 37.5131 23.2596 37.5131C22.2967 37.5131 21.4114 36.0767 20.7119 33.6722" stroke="#5C5C5C" stroke-width="2"/>
<path d="M8.62891 5.60352H22.3115C23.2206 8.8144 23.7331 14.1019 23.7331 20.0808C23.7331 25.7062 23.1308 30.7196 22.3115 33.9672H8.62891" stroke="#5C5C5C"/>
<path d="M6.51399 37.5132C8.68286 37.5132 10.4411 29.5764 10.4411 19.7859C10.4411 9.99538 8.68286 2.05859 6.51399 2.05859C4.34513 2.05859 2.58691 9.99538 2.58691 19.7859C2.58691 29.5764 4.34513 37.5132 6.51399 37.5132Z" fill="#F2F2F2" stroke="#5C5C5C" stroke-width="2"/>
<path d="M6.21159 22.7401C6.54526 22.7401 6.81576 21.5495 6.81576 20.081C6.81576 18.6124 6.54526 17.4219 6.21159 17.4219C5.87792 17.4219 5.60742 18.6124 5.60742 20.081C5.60742 21.5495 5.87792 22.7401 6.21159 22.7401Z" fill="#5C5C5C"/>
</svg>

After

Width:  |  Height:  |  Size: 3.8 KiB

View File

@ -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

View File

@ -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;