diff --git a/src/slic3r/GUI/3DScene.cpp b/src/slic3r/GUI/3DScene.cpp index 39fd70d46..3e79b4515 100644 --- a/src/slic3r/GUI/3DScene.cpp +++ b/src/slic3r/GUI/3DScene.cpp @@ -1518,27 +1518,28 @@ void GLVolumeCollection::update_colors_by_extruder(const DynamicPrintConfig* con struct Color { std::string text; - unsigned char rgb[3]; + unsigned char rgba[4]; Color() : text("") { - rgb[0] = 255; - rgb[1] = 255; - rgb[2] = 255; + rgba[0] = 255; + rgba[1] = 255; + rgba[2] = 255; + rgba[3] = 255; } - void set(const std::string& text, unsigned char* rgb) + void set(const std::string& text, unsigned char* rgba) { this->text = text; - ::memcpy((void*)this->rgb, (const void*)rgb, 3 * sizeof(unsigned char)); + ::memcpy((void*)this->rgba, (const void*)rgba, 4 * sizeof(unsigned char)); } }; if (config == nullptr) return; - unsigned char rgb[3]; + unsigned char rgba[4]; std::vector colors; if (static_cast(config->opt_int("printer_technology")) == ptSLA) @@ -1546,9 +1547,9 @@ void GLVolumeCollection::update_colors_by_extruder(const DynamicPrintConfig* con const std::string& txt_color = config->opt_string("material_colour").empty() ? print_config_def.get("material_colour")->get_default_value()->value : config->opt_string("material_colour"); - if (Slic3r::GUI::BitmapCache::parse_color(txt_color, rgb)) { + if (Slic3r::GUI::BitmapCache::parse_color4(txt_color, rgba)) { colors.resize(1); - colors[0].set(txt_color, rgb); + colors[0].set(txt_color, rgba); } } else @@ -1564,8 +1565,8 @@ void GLVolumeCollection::update_colors_by_extruder(const DynamicPrintConfig* con for (unsigned int i = 0; i < colors_count; ++i) { const std::string& txt_color = config->opt_string("filament_colour", i); - if (Slic3r::GUI::BitmapCache::parse_color(txt_color, rgb)) - colors[i].set(txt_color, rgb); + if (Slic3r::GUI::BitmapCache::parse_color4(txt_color, rgba)) + colors[i].set(txt_color, rgba); } } @@ -1579,8 +1580,8 @@ void GLVolumeCollection::update_colors_by_extruder(const DynamicPrintConfig* con const Color& color = colors[extruder_id]; if (!color.text.empty()) { - for (int i = 0; i < 3; ++i) { - volume->color[i] = (float)color.rgb[i] * inv_255; + for (int i = 0; i < 4; ++i) { + volume->color[i] = (float)color.rgba[i] * inv_255; } } } diff --git a/src/slic3r/GUI/BitmapCache.cpp b/src/slic3r/GUI/BitmapCache.cpp index 06b0a2f16..3aa064b8a 100644 --- a/src/slic3r/GUI/BitmapCache.cpp +++ b/src/slic3r/GUI/BitmapCache.cpp @@ -444,5 +444,21 @@ bool BitmapCache::parse_color(const std::string& scolor, unsigned char* rgb_out) return true; } +bool BitmapCache::parse_color4(const std::string& scolor, unsigned char* rgba_out) +{ + rgba_out[0] = rgba_out[1] = rgba_out[2] = 0; rgba_out[3] = 255; + if ((scolor.size() != 7 && scolor.size() != 9) || scolor.front() != '#') + return false; + const char* c = scolor.data() + 1; + for (size_t i = 0; i < scolor.size() / 2; ++i) { + int digit1 = hex_digit_to_int(*c++); + int digit2 = hex_digit_to_int(*c++); + if (digit1 == -1 || digit2 == -1) + return false; + rgba_out[i] = (unsigned char)(digit1 * 16 + digit2); + } + return true; +} + } // namespace GUI } // namespace Slic3r diff --git a/src/slic3r/GUI/BitmapCache.hpp b/src/slic3r/GUI/BitmapCache.hpp index 6d63b17e3..4803fa961 100644 --- a/src/slic3r/GUI/BitmapCache.hpp +++ b/src/slic3r/GUI/BitmapCache.hpp @@ -48,6 +48,7 @@ public: wxBitmap mkclear(size_t width, size_t height) { return mksolid(width, height, 0, 0, 0, wxALPHA_TRANSPARENT); } static bool parse_color(const std::string& scolor, unsigned char* rgb_out); + static bool parse_color4(const std::string& scolor, unsigned char* rgba_out); private: std::map m_map; diff --git a/src/slic3r/GUI/PresetComboBoxes.cpp b/src/slic3r/GUI/PresetComboBoxes.cpp index 7cf623629..8a1ecd478 100644 --- a/src/slic3r/GUI/PresetComboBoxes.cpp +++ b/src/slic3r/GUI/PresetComboBoxes.cpp @@ -486,16 +486,6 @@ wxBitmap* PresetComboBox::get_bmp( std::string bitmap_key, bool wide_icons, con if (m_type == Preset::TYPE_FILAMENT && !filament_rgb.empty()) { // BBS -#if 0 - unsigned char rgb[3]; - // Paint the color bars. - bitmap_cache().parse_color(filament_rgb, rgb); - bmps.emplace_back(bitmap_cache().mksolid(is_single_bar ? wide_icon_width : norm_icon_width, icon_height, rgb, false, 1, dark_mode)); - if (!is_single_bar) { - bitmap_cache().parse_color(extruder_rgb, rgb); - bmps.emplace_back(bitmap_cache().mksolid(thin_icon_width, icon_height, rgb, false, 1, dark_mode)); - } -#endif // Paint a lock at the system presets. bmps.emplace_back(bitmap_cache().mkclear(space_icon_width, icon_height)); } @@ -920,10 +910,6 @@ void PlaterPresetComboBox::update() { //unsigned char rgb[3]; filament_color = m_preset_bundle->project_config.opt_string("filament_colour", (unsigned int) m_filament_idx); - //if (!bitmap_cache().parse_color(filament_color, rgb)) - // // Extruder color is not defined. - // filament_color.clear(); - // BBS wxColor clr(filament_color); clr_picker->SetBitmap(*get_extruder_color_icons(true)[m_filament_idx]); #ifdef __WXOSX__