NEW:ams control support for more gradient colors

Change-Id: I3e7e7e1f340a443200b9225b142f6398b4824513
This commit is contained in:
tao wang 2023-03-27 21:02:35 +08:00 committed by Lane.Wei
parent e3d89f2154
commit ee2ef44dc7
5 changed files with 72 additions and 1 deletions

View File

@ -0,0 +1,3 @@
<svg width="25" height="25" viewBox="0 0 25 25" fill="none" xmlns="http://www.w3.org/2000/svg">
<path fill-rule="evenodd" clip-rule="evenodd" d="M12.5 0H0V12.5V25H12.5H25V12.5V0H12.5ZM12.5 0C19.4033 0 25 5.59644 25 12.5C25 19.4036 19.4033 25 12.5 25C5.59668 25 0 19.4036 0 12.5C0 5.59644 5.59668 0 12.5 0Z" fill="white"/>
</svg>

After

Width:  |  Height:  |  Size: 329 B

View File

@ -536,6 +536,13 @@ void AMSMaterialsSetting::set_color(wxColour color)
m_clr_picker->set_color(color);
}
void AMSMaterialsSetting::set_colors(std::vector<wxColour> colors)
{
//m_clrData->SetColour(color);
m_clr_picker->set_colors(colors);
}
void AMSMaterialsSetting::on_picker_color(wxCommandEvent& event)
{
unsigned int color_num = event.GetInt();
@ -836,6 +843,7 @@ ColorPicker::ColorPicker(wxWindow* parent, wxWindowID id, const wxPoint& pos /*=
wxWindow::Create(parent, id, pos, size);
Bind(wxEVT_PAINT, &ColorPicker::paintEvent, this);
m_bitmap_border = create_scaled_bitmap("color_picker_border", nullptr, 25);
}
ColorPicker::~ColorPicker(){}
@ -846,6 +854,12 @@ void ColorPicker::set_color(wxColour col)
Refresh();
}
void ColorPicker::set_colors(std::vector<wxColour> cols)
{
m_cols = cols;
Refresh();
}
void ColorPicker::paintEvent(wxPaintEvent& evt)
{
wxPaintDC dc(this);
@ -894,6 +908,24 @@ void ColorPicker::doRender(wxDC& dc)
dc.SetPen(wxPen(wxColour(0x6B6B6B)));
dc.SetBrush(*wxTRANSPARENT_BRUSH);
dc.DrawCircle(size.x / 2, size.x / 2, radius);
if (m_cols.size() > 1) {
int left = FromDIP(0);
float total_width = size.x;
int gwidth = std::round(total_width / (m_cols.size() - 1));
for (int i = 0; i < m_cols.size() - 1; i++) {
if ((left + gwidth) > (size.x)) {
gwidth = size.x - left;
}
auto rect = wxRect(left, 0, gwidth, size.y);
dc.GradientFillLinear(rect, m_cols[i], m_cols[i + 1], wxEAST);
left += gwidth;
}
dc.DrawBitmap(m_bitmap_border, wxPoint(0, 0));
}
}
}

View File

@ -31,7 +31,9 @@ namespace Slic3r { namespace GUI {
class ColorPicker : public wxWindow
{
public:
wxBitmap m_bitmap_border;
wxColour m_colour;
std::vector<wxColour> m_cols;
bool m_selected{false};
bool m_show_full{false};
@ -39,6 +41,7 @@ public:
~ColorPicker();
void set_color(wxColour col);
void set_colors(std::vector<wxColour> cols);
void set_selected(bool sel) {m_selected = sel;Refresh();};
void set_show_full(bool full) {m_show_full = full;Refresh();};
@ -92,6 +95,7 @@ public:
void post_select_event();
void set_color(wxColour color);
void set_colors(std::vector<wxColour> colors);
void on_picker_color(wxCommandEvent& color);
MachineObject* obj{ nullptr };

View File

@ -2763,6 +2763,14 @@ void StatusPanel::on_filament_edit(wxCommandEvent &event)
n_val = wxString::Format("%.3f", tray_it->second->n);
wxColor color = AmsTray::decode_color(tray_it->second->color);
m_filament_setting_dlg->set_color(color);
std::vector<wxColour> cols;
for (auto col : tray_it->second->cols) {
cols.push_back( AmsTray::decode_color(col));
}
m_filament_setting_dlg->set_colors(cols);
m_filament_setting_dlg->ams_filament_id = tray_it->second->setting_id;
m_filament_setting_dlg->m_is_third = !MachineObject::is_bbl_filament(tray_it->second->tag_uid);
if (!m_filament_setting_dlg->m_is_third) {

View File

@ -1374,7 +1374,31 @@ void AMSItem::doRender(wxDC &dc)
dc.SetBrush(AMS_CONTROL_DISABLE_COLOUR);
}
dc.DrawRoundedRectangle(left, (size.y - AMS_ITEM_CUBE_SIZE.y) / 2, AMS_ITEM_CUBE_SIZE.x, AMS_ITEM_CUBE_SIZE.y, 2);
if (iter->material_cols.size() > 1) {
int fleft = left;
float total_width = AMS_ITEM_CUBE_SIZE.x;
int gwidth = std::round(total_width / (iter->material_cols.size() - 1));
for (int i = 0; i < iter->material_cols.size() - 1; i++) {
if ((fleft + gwidth) > (AMS_ITEM_CUBE_SIZE.x)) {
gwidth = (fleft + AMS_ITEM_CUBE_SIZE.x) - fleft;
}
auto rect = wxRect(fleft, (size.y - AMS_ITEM_CUBE_SIZE.y) / 2, gwidth, AMS_ITEM_CUBE_SIZE.y);
dc.GradientFillLinear(rect, iter->material_cols[i], iter->material_cols[i + 1], wxEAST);
fleft += gwidth;
}
dc.SetPen(wxPen(StateColor::darkModeColorFor(m_background_colour)));
dc.SetBrush(*wxTRANSPARENT_BRUSH);
dc.DrawRoundedRectangle(left - 1, (size.y - AMS_ITEM_CUBE_SIZE.y) / 2 - 1, AMS_ITEM_CUBE_SIZE.x + 2, AMS_ITEM_CUBE_SIZE.y + 2, 2);
}else {
dc.DrawRoundedRectangle(left, (size.y - AMS_ITEM_CUBE_SIZE.y) / 2, AMS_ITEM_CUBE_SIZE.x, AMS_ITEM_CUBE_SIZE.y, 2);
}
left += AMS_ITEM_CUBE_SIZE.x;
left += m_space;
}