ENH: transparent filament color
Change-Id: I8f6a26763a3ad790bda6ca13327d40403d88dd59
This commit is contained in:
parent
8b893e631b
commit
149b1112fc
|
@ -0,0 +1,21 @@
|
|||
<svg width="48" height="48" viewBox="0 0 48 48" fill="none" xmlns="http://www.w3.org/2000/svg">
|
||||
<rect width="48" height="48" transform="matrix(1 0 0 -1 0 48)" fill="#FEFFFE"/>
|
||||
<rect width="8" height="8" transform="matrix(0 1 1 0 0 8)" fill="#D9D9D9"/>
|
||||
<rect width="8" height="8" transform="matrix(0 1 1 0 0 24)" fill="#D9D9D9"/>
|
||||
<rect width="8" height="8" transform="matrix(0 1 1 0 0 40)" fill="#D9D9D9"/>
|
||||
<rect width="8" height="8" transform="matrix(0 1 1 0 8 0)" fill="#D9D9D9"/>
|
||||
<rect width="8" height="8" transform="matrix(0 1 1 0 8 16)" fill="#D9D9D9"/>
|
||||
<rect width="8" height="8" transform="matrix(0 1 1 0 8 32)" fill="#D9D9D9"/>
|
||||
<rect width="8" height="8" transform="matrix(0 1 1 0 16 8)" fill="#D9D9D9"/>
|
||||
<rect width="8" height="8" transform="matrix(0 1 1 0 16 24)" fill="#D9D9D9"/>
|
||||
<rect width="8" height="8" transform="matrix(0 1 1 0 16 40)" fill="#D9D9D9"/>
|
||||
<rect width="8" height="8" transform="matrix(0 1 1 0 24 0)" fill="#D9D9D9"/>
|
||||
<rect width="8" height="8" transform="matrix(0 1 1 0 24 16)" fill="#D9D9D9"/>
|
||||
<rect width="8" height="8" transform="matrix(0 1 1 0 24 32)" fill="#D9D9D9"/>
|
||||
<rect width="8" height="8" transform="matrix(0 1 1 0 32 8)" fill="#D9D9D9"/>
|
||||
<rect width="8" height="8" transform="matrix(0 1 1 0 32 24)" fill="#D9D9D9"/>
|
||||
<rect width="8" height="8" transform="matrix(0 1 1 0 32 40)" fill="#D9D9D9"/>
|
||||
<rect width="8" height="8" transform="matrix(0 1 1 0 40 0)" fill="#D9D9D9"/>
|
||||
<rect width="8" height="8" transform="matrix(0 1 1 0 40 16)" fill="#D9D9D9"/>
|
||||
<rect width="8" height="8" transform="matrix(0 1 1 0 40 32)" fill="#D9D9D9"/>
|
||||
</svg>
|
After Width: | Height: | Size: 1.5 KiB |
|
@ -391,20 +391,7 @@ void PresetComboBox::add_ams_filaments(std::string selected, bool alias_name)
|
|||
const_cast<Preset&>(*iter).is_visible = true;
|
||||
auto color = f.opt_string("filament_colour", 0u);
|
||||
auto name = f.opt_string("tray_name", 0u);
|
||||
wxColour clr(color);
|
||||
wxImage img(24, 16);
|
||||
if (clr.Red() > 224 && clr.Blue() > 224 && clr.Green() > 224) {
|
||||
img.SetRGB(wxRect({0, 0}, img.GetSize()), 128, 128, 128);
|
||||
img.SetRGB(wxRect({1, 1}, img.GetSize() - wxSize{2, 2}), clr.Red(), clr.Green(), clr.Blue());
|
||||
} else {
|
||||
img.SetRGB(wxRect({0, 0}, img.GetSize()), clr.Red(), clr.Green(), clr.Blue());
|
||||
}
|
||||
wxBitmap bmp(img);
|
||||
wxMemoryDC dc(bmp);
|
||||
dc.SetFont(Label::Body_10);
|
||||
dc.SetTextForeground(different_color(clr));
|
||||
auto size = dc.GetTextExtent(name);
|
||||
dc.DrawText(name, bmp.GetWidth() / 2 - size.x / 2, bmp.GetHeight() / 2 - size.y / 2);
|
||||
wxBitmap bmp(*get_extruder_color_icon(color, name, 24, 16));
|
||||
int item_id = Append(get_preset_name(*iter), bmp.ConvertToImage(), &m_first_ams_filament + (&f - &m_preset_bundle->filament_ams_list.front()));
|
||||
//validate_selection(id->value == selected); // can not select
|
||||
}
|
||||
|
@ -683,7 +670,7 @@ PlaterPresetComboBox::PlaterPresetComboBox(wxWindow *parent, Preset::Type preset
|
|||
// BBS
|
||||
if (m_type == Preset::TYPE_FILAMENT) {
|
||||
int em = wxGetApp().em_unit();
|
||||
clr_picker = new wxButton(parent, wxID_ANY, "", wxDefaultPosition, wxSize(FromDIP(20), FromDIP(20)), wxBU_EXACTFIT | wxBU_AUTODRAW | wxBORDER_NONE);
|
||||
clr_picker = new wxBitmapButton(parent, wxID_ANY, {}, wxDefaultPosition, wxSize(FromDIP(20), FromDIP(20)), wxBU_EXACTFIT | wxBU_AUTODRAW | wxBORDER_NONE);
|
||||
clr_picker->SetToolTip(_L("Click to pick filament color"));
|
||||
clr_picker->Bind(wxEVT_BUTTON, [this](wxCommandEvent& e) {
|
||||
m_clrData.SetColour(clr_picker->GetBackgroundColour());
|
||||
|
@ -938,12 +925,7 @@ void PlaterPresetComboBox::update()
|
|||
// filament_color.clear();
|
||||
// BBS
|
||||
wxColor clr(filament_color);
|
||||
clr_picker->SetBackgroundColour(clr);
|
||||
auto diff_clr = different_color(clr);
|
||||
clr_picker->SetForegroundColour(diff_clr);
|
||||
auto style = clr_picker->GetWindowStyle() & ~(wxBORDER_NONE | wxBORDER_SIMPLE);
|
||||
style = clr.Red() > 224 && clr.Blue() > 224 && clr.Green() > 224 ? (style | wxBORDER_SIMPLE) : (style | wxBORDER_NONE);
|
||||
clr_picker->SetWindowStyle(style);
|
||||
clr_picker->SetBitmap(*get_extruder_color_icons(true)[m_filament_idx]);
|
||||
#ifdef __WXOSX__
|
||||
clr_picker->SetLabel(clr_picker->GetLabel()); // Let setBezelStyle: be called
|
||||
clr_picker->Refresh();
|
||||
|
|
|
@ -502,8 +502,6 @@ wxBitmap* get_default_extruder_color_icon(bool thin_icon/* = false*/)
|
|||
|
||||
std::vector<wxBitmap*> get_extruder_color_icons(bool thin_icon/* = false*/)
|
||||
{
|
||||
static Slic3r::GUI::BitmapCache bmp_cache;
|
||||
|
||||
// Create the bitmap with color bars.
|
||||
std::vector<wxBitmap*> bmps;
|
||||
std::vector<std::string> colors = Slic3r::GUI::wxGetApp().plater()->get_extruder_colors_from_plater_config();
|
||||
|
@ -518,33 +516,55 @@ std::vector<wxBitmap*> get_extruder_color_icons(bool thin_icon/* = false*/)
|
|||
* and scale them in respect to em_unit value
|
||||
*/
|
||||
const double em = Slic3r::GUI::wxGetApp().em_unit();
|
||||
const int icon_width = lround((thin_icon ? 2 : 4.5) * em);
|
||||
const int icon_width = lround((thin_icon ? 2 : 4.4) * em);
|
||||
const int icon_height = lround(2 * em);
|
||||
|
||||
bool dark_mode = Slic3r::GUI::wxGetApp().dark_mode();
|
||||
|
||||
int index = 0;
|
||||
wxClientDC cdc((wxWindow*)Slic3r::GUI::wxGetApp().mainframe);
|
||||
wxMemoryDC dc(&cdc);
|
||||
dc.SetFont(::Label::Body_12);
|
||||
for (const std::string &color : colors)
|
||||
{
|
||||
auto label = std::to_string(++index);
|
||||
std::string bitmap_key = color + "-h" + std::to_string(icon_height) + "-w" + std::to_string(icon_width)
|
||||
+ "-i" + label;
|
||||
bmps.push_back(get_extruder_color_icon(color, label, icon_width, icon_height));
|
||||
}
|
||||
|
||||
wxBitmap* bitmap = bmp_cache.find(bitmap_key);
|
||||
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);
|
||||
// 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));
|
||||
wxClientDC cdc((wxWindow *) Slic3r::GUI::wxGetApp().mainframe);
|
||||
wxMemoryDC dc(&cdc);
|
||||
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();
|
||||
if (clr.Red() > 224 && clr.Blue() > 224 && clr.Green() > 224) {
|
||||
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);
|
||||
}
|
||||
|
@ -553,10 +573,7 @@ std::vector<wxBitmap*> get_extruder_color_icons(bool thin_icon/* = false*/)
|
|||
dc.DrawText(label, (icon_width - size.x) / 2, (icon_height - size.y) / 2);
|
||||
dc.SelectObject(wxNullBitmap);
|
||||
}
|
||||
bmps.emplace_back(bitmap);
|
||||
}
|
||||
|
||||
return bmps;
|
||||
return bitmap;
|
||||
}
|
||||
|
||||
|
||||
|
|
|
@ -66,7 +66,8 @@ wxBitmap create_scaled_bitmap(const std::string& bmp_name, wxWindow *win = nullp
|
|||
#endif
|
||||
|
||||
wxBitmap* get_default_extruder_color_icon(bool thin_icon = false);
|
||||
std::vector<wxBitmap*> get_extruder_color_icons(bool thin_icon = false);
|
||||
std::vector<wxBitmap *> 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 {
|
||||
|
|
Loading…
Reference in New Issue