NEW:Adapt to multicolour and gradient colour

JIRA:xxxx
Change-Id: I8084cab603d5681cbcaf2d6f5e0d7ad5419cb2af
This commit is contained in:
hu.wang 2023-12-26 15:57:45 +08:00 committed by Lane.Wei
parent 557d587bfa
commit cafc1c7148
7 changed files with 115 additions and 25 deletions

View File

@ -673,6 +673,10 @@ void AMSMaterialsSetting::set_colors(std::vector<wxColour> colors)
m_clr_picker->set_colors(colors);
}
void AMSMaterialsSetting::set_ctype(int ctype)
{
m_clr_picker->ctype = ctype;
}
void AMSMaterialsSetting::on_picker_color(wxCommandEvent& event)
{
@ -1201,8 +1205,8 @@ void ColorPicker::doRender(wxDC& dc)
if (alpha == 0) {
dc.DrawBitmap(m_bitmap_transparent, 0, 0);
}
if (m_cols.size() > 1) {
if (ctype == 0) {
int left = FromDIP(0);
float total_width = size.x;
int gwidth = std::round(total_width / (m_cols.size() - 1));
@ -1219,6 +1223,22 @@ void ColorPicker::doRender(wxDC& dc)
}
dc.DrawBitmap(m_bitmap_border, wxPoint(0, 0));
}
else {
float ev_angle = 360.0 / m_cols.size();
float startAngle = 270.0;
float endAngle = 270.0;
dc.SetPen(*wxTRANSPARENT_PEN);
for (int i = 0; i < m_cols.size(); i++) {
dc.SetBrush(m_cols[i]);
endAngle += ev_angle;
endAngle = endAngle > 360.0 ? endAngle - 360.0 : endAngle;
wxPoint center(size.x / 2, size.y / 2);
dc.DrawEllipticArc(center.x - radius, center.y - radius, 2 * radius, 2 * radius, startAngle, endAngle);
startAngle += ev_angle;
startAngle = startAngle > 360.0 ? startAngle - 360.0 : startAngle;
}
}
}
}
if (m_is_empty) {

View File

@ -41,6 +41,7 @@ public:
bool m_selected{false};
bool m_show_full{false};
bool m_is_empty{false};
int ctype;
ColorPicker(wxWindow* parent, wxWindowID id, const wxPoint& pos = wxDefaultPosition, const wxSize& size = wxDefaultSize);
~ColorPicker();
@ -109,6 +110,7 @@ public:
void set_color(wxColour color);
void set_empty_color(wxColour color);
void set_colors(std::vector<wxColour> colors);
void set_ctype(int ctype);
void on_picker_color(wxCommandEvent& color);
MachineObject* obj{ nullptr };

View File

@ -3884,6 +3884,10 @@ int MachineObject::parse_json(std::string payload)
curr_tray->color = "";
}
if (tray_it->contains("ctype"))
curr_tray->ctype = (*tray_it)["ctype"].get<int>();
else
curr_tray->ctype = 0;
curr_tray->cols.clear();
if (tray_it->contains("cols")) {
if ((*tray_it)["cols"].is_array()) {

View File

@ -194,6 +194,7 @@ public:
std::string nozzle_temp_min;
std::string xcam_info;
std::string uuid;
int ctype = 0;
float k = 0.0f; // k range: 0 ~ 0.5
float n = 0.0f; // k range: 0.6 ~ 2.0
int cali_idx = 0;

View File

@ -3504,7 +3504,7 @@ void StatusPanel::on_filament_edit(wxCommandEvent &event)
for (auto col : tray_it->second->cols) {
cols.push_back( AmsTray::decode_color(col));
}
m_filament_setting_dlg->set_ctype(tray_it->second->ctype);
m_filament_setting_dlg->ams_filament_id = tray_it->second->setting_id;
if (m_filament_setting_dlg->ams_filament_id.empty()) {

View File

@ -52,6 +52,7 @@ bool AMSinfo::parse_ams_info(MachineObject *obj, Ams *ams, bool remain_flag, boo
if (it != ams->trayList.end() && it->second->is_exists) {
if (it->second->is_tray_info_ready()) {
info.can_id = it->second->id;
info.ctype = it->second->ctype;
info.material_name = it->second->get_display_filament_type();
if (!it->second->color.empty()) {
info.material_colour = AmsTray::decode_color(it->second->color);
@ -81,6 +82,7 @@ bool AMSinfo::parse_ams_info(MachineObject *obj, Ams *ams, bool remain_flag, boo
} else {
info.can_id = it->second->id;
info.material_name = "";
info.ctype = 0;
info.material_colour = AMS_TRAY_DEFAULT_COL;
info.material_state = AMSCanType::AMS_CAN_TYPE_THIRDBRAND;
wxColour(255, 255, 255);
@ -1016,10 +1018,33 @@ void AMSLib::render_extra_lib(wxDC& dc)
}
dc.SetPen(wxPen(*wxTRANSPARENT_PEN));
if (m_info.material_cols.size() > 1) {
int left = FromDIP(10);
int gwidth = std::round(size.x / (m_info.material_cols.size() - 1));
//gradient
if (m_info.ctype == 0) {
for (int i = 0; i < m_info.material_cols.size() - 1; i++) {
auto rect = wxRect(left, FromDIP(10), size.x - FromDIP(20), size.y - FromDIP(20));
dc.GradientFillLinear(rect, m_info.material_cols[i], m_info.material_cols[i + 1], wxEAST);
left += gwidth;
}
}
else {
int cols_size = m_info.material_cols.size();
for (int i = 0; i < cols_size; i++) {
dc.SetBrush(wxBrush(m_info.material_cols[i]));
float x = FromDIP(10) + ((float)size.x - FromDIP(20)) * i / cols_size;
dc.DrawRoundedRectangle(x, FromDIP(10), ((float)size.x - FromDIP(20)) / cols_size, size.y - FromDIP(20), 0);
}
dc.SetBrush(wxBrush(tmp_lib_colour));
}
}
else {
dc.SetBrush(wxBrush(tmp_lib_colour));
dc.DrawRoundedRectangle(FromDIP(10), FromDIP(10), size.x - FromDIP(20), size.y - FromDIP(20), 0);
}
dc.SetPen(wxPen(*wxTRANSPARENT_PEN));
dc.SetBrush(wxBrush(tmp_lib_colour));
if (!m_disable_mode) {
// edit icon
if (m_info.material_state != AMSCanType::AMS_CAN_TYPE_EMPTY && m_info.material_state != AMSCanType::AMS_CAN_TYPE_NONE)
@ -1122,12 +1147,13 @@ void AMSLib::render_generic_lib(wxDC &dc)
dc.DrawBitmap(m_bitmap_transparent.bmp(), FromDIP(4), FromDIP(4));
}
//gradient
if (m_info.material_cols.size() > 1) {
int left = FromDIP(4);
float total_width = size.x - FromDIP(8);
int gwidth = std::round(total_width / (m_info.material_cols.size() - 1));
//gradient
if (m_info.ctype == 0) {
for (int i = 0; i < m_info.material_cols.size() - 1; i++) {
if ((left + gwidth) > (size.x - FromDIP(8))) {
@ -1140,6 +1166,42 @@ void AMSLib::render_generic_lib(wxDC &dc)
}
}
else {
//multicolour
gwidth = std::round(total_width / m_info.material_cols.size());
for (int i = 0; i < m_info.material_cols.size(); i++) {
dc.SetPen(wxPen(*wxTRANSPARENT_PEN));
dc.SetBrush(wxBrush(m_info.material_cols[i]));
if (i == 0 || i == m_info.material_cols.size() - 1) {
#ifdef __APPLE__
dc.DrawRoundedRectangle(left + gwidth * i, height - curr_height + FromDIP(4), gwidth, curr_height, m_radius);
#else
dc.DrawRoundedRectangle(left + gwidth * i, height - curr_height + FromDIP(4), gwidth, curr_height, m_radius - 1);
#endif
//add rectangle
int dr_gwidth = std::round(gwidth * 0.6);
if (i == 0) {
dc.DrawRectangle(left + gwidth - dr_gwidth, height - curr_height + FromDIP(4), dr_gwidth, curr_height);
}
else {
dc.DrawRectangle(left + gwidth*i, height - curr_height + FromDIP(4), dr_gwidth, curr_height);
}
}
else {
dc.DrawRectangle(left + gwidth * i, height - curr_height + FromDIP(4), gwidth, curr_height);
}
}
//reset pen and brush
if (m_selected || m_hover) {
dc.SetPen(wxPen(*wxTRANSPARENT_PEN));
dc.SetBrush(wxBrush(tmp_lib_colour));
}
else {
dc.SetPen(wxPen(tmp_lib_colour, 1, wxSOLID));
dc.SetBrush(wxBrush(tmp_lib_colour));
}
}
}
else {
#ifdef __APPLE__
dc.DrawRoundedRectangle(FromDIP(4), FromDIP(4) + top, size.x - FromDIP(8), curr_height, m_radius);
#else

View File

@ -140,6 +140,7 @@ struct Caninfo
wxString material_name;
wxColour material_colour = {*wxWHITE};
AMSCanType material_state;
int ctype=0;
int material_remain = 100;
float k = 0.0f;
float n = 0.0f;