Skip to content

Commit

Permalink
FIX:adapt to multicolour and semi transparent materials
Browse files Browse the repository at this point in the history
JIRA:5683,5765,5768,5784,5800
Change-Id: I7c5844279abb316e92714b847e6a88f98c61dfa8
  • Loading branch information
bam-winterfell authored and lanewei120 committed Mar 25, 2024
1 parent b55bffa commit eb033cc
Show file tree
Hide file tree
Showing 6 changed files with 68 additions and 32 deletions.
3 changes: 3 additions & 0 deletions resources/images/color_picker_border_dark.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
29 changes: 19 additions & 10 deletions src/slic3r/GUI/AMSMaterialsSetting.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1123,6 +1123,7 @@ ColorPicker::ColorPicker(wxWindow* parent, wxWindowID id, const wxPoint& pos /*=
Bind(wxEVT_PAINT, &ColorPicker::paintEvent, this);

m_bitmap_border = create_scaled_bitmap("color_picker_border", nullptr, 25);
m_bitmap_border_dark = create_scaled_bitmap("color_picker_border_dark", nullptr, 25);
m_bitmap_transparent = create_scaled_bitmap("transparent_color_picker", nullptr, 25);
}

Expand All @@ -1131,12 +1132,14 @@ ColorPicker::~ColorPicker(){}
void ColorPicker::msw_rescale()
{
m_bitmap_border = create_scaled_bitmap("color_picker_border", nullptr, 25);
m_bitmap_border_dark = create_scaled_bitmap("color_picker_border_dark", nullptr, 25);

Refresh();
}

void ColorPicker::set_color(wxColour col)
{
if (m_colour != col&&col.Alpha()!=0&&col.Alpha()!=255) {
if (m_colour != col && col.Alpha() != 0 && col.Alpha() != 255 && col.Alpha() != 254) {
transparent_changed = true;
}
m_colour = col;
Expand Down Expand Up @@ -1186,22 +1189,22 @@ void ColorPicker::doRender(wxDC& dc)
if (alpha == 0) {
dc.DrawBitmap(m_bitmap_transparent, 0, 0);
}
else if (alpha != 0 && alpha != 255) {
else if (alpha != 254 && alpha != 255) {
if (transparent_changed) {
std::string rgb = (m_colour.GetAsString(wxC2S_HTML_SYNTAX)).ToStdString();
if (rgb.size() == 8) {
//delete alpha value
rgb = rgb.substr(0, rgb.size() - 2);
}
float alpha_f = 0.3 * m_colour.Alpha() / 255.0;
float alpha_f = 0.7 * m_colour.Alpha() / 255.0;
std::vector<std::string> replace;
replace.push_back(rgb);
std::string fill_replace = "fill-opacity=\"" + std::to_string(alpha_f);
replace.push_back(fill_replace);
m_bitmap_transparent = ScalableBitmap(this, "transparent_color_picker", 25, false, false, true, replace).bmp();
transparent_changed = false;
dc.DrawBitmap(m_bitmap_transparent, 0, 0);
}
dc.DrawBitmap(m_bitmap_transparent, 0, 0);
}
else {
dc.SetPen(wxPen(m_colour));
Expand All @@ -1220,10 +1223,6 @@ void ColorPicker::doRender(wxDC& dc)
dc.SetBrush(*wxTRANSPARENT_BRUSH);
dc.DrawCircle(size.x / 2, size.y / 2, radius);

//transparent
if (alpha == 0) {
dc.DrawBitmap(m_bitmap_transparent, 0, 0);
}
if (m_cols.size() > 1) {
if (ctype == 0) {
int left = FromDIP(0);
Expand All @@ -1240,7 +1239,12 @@ void ColorPicker::doRender(wxDC& dc)
dc.GradientFillLinear(rect, m_cols[i], m_cols[i + 1], wxEAST);
left += gwidth;
}
dc.DrawBitmap(m_bitmap_border, wxPoint(0, 0));
if (wxGetApp().dark_mode()) {
dc.DrawBitmap(m_bitmap_border_dark, wxPoint(0, 0));
}
else {
dc.DrawBitmap(m_bitmap_border, wxPoint(0, 0));
}
}
else {
float ev_angle = 360.0 / m_cols.size();
Expand All @@ -1256,7 +1260,12 @@ void ColorPicker::doRender(wxDC& dc)
startAngle += ev_angle;
startAngle = startAngle > 360.0 ? startAngle - 360.0 : startAngle;
}
dc.DrawBitmap(m_bitmap_border, wxPoint(0, 0));
if (wxGetApp().dark_mode()) {
dc.DrawBitmap(m_bitmap_border_dark, wxPoint(0, 0));
}
else {
dc.DrawBitmap(m_bitmap_border, wxPoint(0, 0));
}
}
}
}
Expand Down
1 change: 1 addition & 0 deletions src/slic3r/GUI/AMSMaterialsSetting.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@ class ColorPicker : public wxWindow
{
public:
wxBitmap m_bitmap_border;
wxBitmap m_bitmap_border_dark;
wxBitmap m_bitmap_transparent;

wxColour m_colour;
Expand Down
3 changes: 3 additions & 0 deletions src/slic3r/GUI/AMSSetting.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -264,6 +264,9 @@ void AMSSetting::update_insert_material_read_mode(bool selected)

void AMSSetting::update_ams_img(std::string ams_icon_str)
{
if (wxGetApp().dark_mode()&& ams_icon_str=="extra_icon") {
ams_icon_str += "_dark";
}
m_am_img->SetBitmap(create_scaled_bitmap(ams_icon_str, nullptr, 126));
}

Expand Down
62 changes: 41 additions & 21 deletions src/slic3r/GUI/Widgets/AMSControl.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -863,7 +863,7 @@ void AMSLib::render_generic_text(wxDC &dc)
dc.SetFont(::Label::Body_13);
dc.SetTextForeground(temp_text_colour);
auto alpha = m_info.material_colour.Alpha();
if (alpha != 0 && alpha != 255) {
if (alpha != 0 && alpha != 255 && alpha != 254) {
dc.SetTextForeground(*wxBLACK);
}

Expand Down Expand Up @@ -1108,6 +1108,9 @@ void AMSLib::render_generic_lib(wxDC &dc)
// selected
if (m_selected) {
dc.SetPen(wxPen(tmp_lib_colour, 2, wxSOLID));
if (tmp_lib_colour.Alpha() == 0) {
dc.SetPen(wxPen(wxColour(tmp_lib_colour.Red(), tmp_lib_colour.Green(),tmp_lib_colour.Blue(),128), 2, wxSOLID));
}
dc.SetBrush(wxBrush(*wxTRANSPARENT_BRUSH));
if (m_radius == 0) {
dc.DrawRectangle(0, 0, size.x, size.y);
Expand Down Expand Up @@ -1139,18 +1142,38 @@ void AMSLib::render_generic_lib(wxDC &dc)
}

//draw remain
auto alpha = m_info.material_colour.Alpha();
int height = size.y - FromDIP(8);
int curr_height = height * float(m_info.material_remain * 1.0 / 100.0); dc.SetFont(::Label::Body_13);
int curr_height = height * float(m_info.material_remain * 1.0 / 100.0);
dc.SetFont(::Label::Body_13);

int top = height - curr_height;

if (curr_height >= FromDIP(6)) {

//transparent
auto alpha = m_info.material_colour.Alpha();

if (alpha == 0) {
dc.DrawBitmap(m_bitmap_transparent.bmp(), FromDIP(4), FromDIP(4));
}
else if (alpha != 255 && alpha != 254) {
if (transparent_changed) {
std::string rgb = (tmp_lib_colour.GetAsString(wxC2S_HTML_SYNTAX)).ToStdString();
if (rgb.size() == 9) {
//delete alpha value
rgb = rgb.substr(0, rgb.size() - 2);
}
float alpha_f = 0.7 * tmp_lib_colour.Alpha() / 255.0;
std::vector<std::string> replace;
replace.push_back(rgb);
std::string fill_replace = "fill-opacity=\"" + std::to_string(alpha_f);
replace.push_back(fill_replace);
m_bitmap_transparent = ScalableBitmap(this, "transparent_ams_lib", 68, false, false, true, replace);
transparent_changed = false;

}
dc.DrawBitmap(m_bitmap_transparent.bmp(), FromDIP(4), FromDIP(4));
}
//gradient
if (m_info.material_cols.size() > 1) {
int left = FromDIP(4);
Expand Down Expand Up @@ -1206,34 +1229,29 @@ void AMSLib::render_generic_lib(wxDC &dc)
}
}
else {
auto brush = dc.GetBrush();
if (alpha != 0 && alpha != 255 && alpha != 254) dc.SetBrush(wxBrush(*wxTRANSPARENT_BRUSH));
#ifdef __APPLE__
dc.DrawRoundedRectangle(FromDIP(4), FromDIP(4) + top, size.x - FromDIP(8), curr_height, m_radius);
#else
dc.DrawRoundedRectangle(FromDIP(4), FromDIP(4) + top, size.x - FromDIP(8), curr_height, m_radius - 1);
if (alpha != 0 && alpha != 255) {
if (transparent_changed) {
std::string rgb = (tmp_lib_colour.GetAsString(wxC2S_HTML_SYNTAX)).ToStdString();
if (rgb.size() == 8) {
//delete alpha value
rgb= rgb.substr(0, rgb.size() - 2);
}
float alpha_f = 0.3 * tmp_lib_colour.Alpha() / 255.0;
std::vector<std::string> replace;
replace.push_back(rgb);
std::string fill_replace = "fill-opacity=\"" + std::to_string(alpha_f);
replace.push_back(fill_replace);
m_bitmap_transparent = ScalableBitmap(this, "transparent_ams_lib", 68, false, false, true, replace);
transparent_changed = false;
}
dc.DrawBitmap(m_bitmap_transparent.bmp(), FromDIP(4), FromDIP(4));
}
#endif
dc.SetBrush(brush);
}
}

if (top > 2) {
if (curr_height >= FromDIP(6)) {
dc.DrawRectangle(FromDIP(4), FromDIP(4) + top, size.x - FromDIP(8), FromDIP(2));
if (alpha != 255 && alpha != 254) {
dc.SetPen(wxPen(*wxWHITE));
dc.SetBrush(wxBrush(*wxWHITE));
#ifdef __APPLE__
dc.DrawRoundedRectangle(FromDIP(4), FromDIP(4) , size.x - FromDIP(8), top, m_radius);
#else
dc.DrawRoundedRectangle(FromDIP(4), FromDIP(4) , size.x - FromDIP(8), top, m_radius - 1);
#endif
}
if (tmp_lib_colour.Red() > 238 && tmp_lib_colour.Green() > 238 && tmp_lib_colour.Blue() > 238) {
dc.SetPen(wxPen(wxColour(130, 129, 128), 1, wxSOLID));
dc.SetBrush(wxBrush(*wxTRANSPARENT_BRUSH));
Expand Down Expand Up @@ -1295,7 +1313,7 @@ void AMSLib::Update(Caninfo info, bool refresh)
if (dev->get_selected_machine() && dev->get_selected_machine() != m_obj) {
m_obj = dev->get_selected_machine();
}
if (info.material_colour.Alpha() != 0 && info.material_colour.Alpha() != 255 && m_info.material_colour != info.material_colour) {
if (info.material_colour.Alpha() != 0 && info.material_colour.Alpha() != 255 && info.material_colour.Alpha() != 254 && m_info.material_colour != info.material_colour) {
transparent_changed = true;
}
m_info = info;
Expand Down Expand Up @@ -2612,6 +2630,7 @@ AMSControl::AMSControl(wxWindow *parent, wxWindowID id, const wxPoint &pos, cons
m_vams_top_sizer->Add(m_vams_lib, 0, wxEXPAND | wxTOP | wxLEFT | wxRIGHT, FromDIP(4));
m_vams_top_sizer->Add(m_vams_road, 0, wxALL, 0);


//extra road

vams_panel->SetSizer(m_vams_top_sizer);
Expand Down Expand Up @@ -2889,6 +2908,7 @@ AMSControl::AMSControl(wxWindow *parent, wxWindowID id, const wxPoint &pos, cons
CreateAms();
SetSelection(0);
EnterNoneAMSMode();

}

void AMSControl::on_retry()
Expand Down
2 changes: 1 addition & 1 deletion src/slic3r/GUI/Widgets/AMSControl.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -124,7 +124,7 @@ enum FilamentStepType {
#define AMS_ITEM_CUBE_SIZE wxSize(FromDIP(14), FromDIP(14))
#define AMS_ITEM_SIZE wxSize(FromDIP(82), FromDIP(27))
#define AMS_ITEM_HUMIDITY_SIZE wxSize(FromDIP(120), FromDIP(27))
#define AMS_CAN_LIB_SIZE wxSize(FromDIP(58), FromDIP(80))
#define AMS_CAN_LIB_SIZE wxSize(FromDIP(58), FromDIP(75))
#define AMS_CAN_ROAD_SIZE wxSize(FromDIP(66), FromDIP(70))
#define AMS_CAN_ITEM_HEIGHT_SIZE FromDIP(27)
#define AMS_CANS_SIZE wxSize(FromDIP(284), FromDIP(196))
Expand Down

0 comments on commit eb033cc

Please sign in to comment.