From 538316469a07ea27bf7b5a2c8b6cfeb86c1cf97e Mon Sep 17 00:00:00 2001 From: tao wang Date: Wed, 15 Jan 2025 14:20:47 +0800 Subject: [PATCH] ENH:redraw the ams preview item jira:[STUDIO-9823, STUDIO-9609,STUDIO-9366] Change-Id: I9bb71986e474257dc4d22fcb66706e4f61228e4e --- resources/images/ext_ams_item.svg | 3 - resources/images/four_slot_ams_item.svg | 7 +- resources/images/single_slot_ams_item.svg | 14 ++- src/slic3r/GUI/Widgets/AMSItem.cpp | 117 ++++++++-------------- src/slic3r/GUI/Widgets/AMSItem.hpp | 6 +- 5 files changed, 58 insertions(+), 89 deletions(-) delete mode 100644 resources/images/ext_ams_item.svg diff --git a/resources/images/ext_ams_item.svg b/resources/images/ext_ams_item.svg deleted file mode 100644 index f05222c7f..000000000 --- a/resources/images/ext_ams_item.svg +++ /dev/null @@ -1,3 +0,0 @@ - - - diff --git a/resources/images/four_slot_ams_item.svg b/resources/images/four_slot_ams_item.svg index 2973eaecf..b42e94a6c 100644 --- a/resources/images/four_slot_ams_item.svg +++ b/resources/images/four_slot_ams_item.svg @@ -1,4 +1,5 @@ - - - + + + + diff --git a/resources/images/single_slot_ams_item.svg b/resources/images/single_slot_ams_item.svg index d194b85a2..a1f94f84f 100644 --- a/resources/images/single_slot_ams_item.svg +++ b/resources/images/single_slot_ams_item.svg @@ -1,4 +1,12 @@ - - - + + + + + + + + + + + diff --git a/src/slic3r/GUI/Widgets/AMSItem.cpp b/src/slic3r/GUI/Widgets/AMSItem.cpp index 232ff66a0..5a0a536cd 100644 --- a/src/slic3r/GUI/Widgets/AMSItem.cpp +++ b/src/slic3r/GUI/Widgets/AMSItem.cpp @@ -1098,7 +1098,6 @@ void AMSLib::doRender(wxDC &dc) else { render_generic_lib(dc); } - //render_extra_lib(dc); } void AMSLib::render_lite_lib(wxDC& dc) @@ -1184,7 +1183,7 @@ void AMSLib::render_lite_lib(wxDC& dc) for (int i = 0; i < cols_size; i++) { dc.SetBrush(wxBrush(m_info.material_cols[i])); float x = FromDIP(10) + ((float)libsize.x - FromDIP(18)) * i / cols_size; - dc.DrawRoundedRectangle(x, FromDIP(10), ((float)libsize.x - FromDIP(17)) / cols_size, libsize.y - FromDIP(18), 0); + dc.DrawRoundedRectangle(x, FromDIP(10), ((float)libsize.x - FromDIP(17)) / cols_size, libsize.y - FromDIP(20), 0); } dc.SetBrush(wxBrush(tmp_lib_colour)); } @@ -1195,7 +1194,7 @@ void AMSLib::render_lite_lib(wxDC& dc) dc.DrawRoundedRectangle(FromDIP(10), (size.y - libsize.y) / 2 + FromDIP(8), libsize.x - FromDIP(17), libsize.y - FromDIP(16), 0); } else{ - dc.DrawRoundedRectangle(FromDIP(10), (size.y - libsize.y) / 2 + FromDIP(10), libsize.x - FromDIP(17), libsize.y - FromDIP(18), 0); + dc.DrawRoundedRectangle(FromDIP(10), (size.y - libsize.y) / 2 + FromDIP(10), libsize.x - FromDIP(17), libsize.y - FromDIP(20), 0); } } @@ -1237,8 +1236,6 @@ void AMSLib::render_generic_lib(wxDC &dc) //draw def background dc.SetPen(wxPen(*wxTRANSPARENT_PEN)); dc.SetBrush(wxBrush(AMS_CONTROL_DEF_LIB_BK_COLOUR)); - //dc.DrawRoundedRectangle(FromDIP(4), FromDIP(4), size.x - FromDIP(8), size.y - FromDIP(8), m_radius); - //dc.DrawRoundedRectangle(FromDIP(4), FromDIP(4), size.x - FromDIP(8), size.y - FromDIP(m_radius - 2), m_radius); dc.DrawRoundedRectangle(FromDIP(2), FromDIP(2), size.x - FromDIP(4), size.y - FromDIP(3), m_radius); if (tmp_lib_colour.GetLuminance() < 0.6) { @@ -1272,12 +1269,7 @@ void AMSLib::render_generic_lib(wxDC &dc) int top = height - curr_height; if (m_ams_model == EXT_AMS){ - if (m_radius > 0){ - dc.DrawRoundedRectangle(FromDIP(1), FromDIP(1), size.x - FromDIP(2), size.y - FromDIP(1), m_radius - 1); - } - else{ - dc.DrawRectangle(FromDIP(1), FromDIP(1), size.x - FromDIP(2), size.y - FromDIP(1)); - } + dc.DrawRoundedRectangle(FromDIP(1), FromDIP(1), size.x - FromDIP(2), size.y - FromDIP(1), m_radius - 1); 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){ @@ -1385,20 +1377,9 @@ void AMSLib::render_generic_lib(wxDC &dc) dc.SetBrush(wxBrush(m_info.material_cols[i])); if (i == 0 || i == m_info.material_cols.size() - 1) { #ifdef __APPLE__ - if (height - curr_height < m_radius){ - dc.DrawRoundedRectangle(left + gwidth * i, height - curr_height, gwidth, curr_height, m_radius); - } - else{ - dc.DrawRoundedRectangle(left + gwidth * i, height - curr_height, gwidth, curr_height, 0); - } - + dc.DrawRoundedRectangle(left + gwidth * i - FromDIP(1), height - curr_height, gwidth, curr_height, m_radius); #else - if (height - curr_height < m_radius) { - dc.DrawRoundedRectangle(left + gwidth * i, height - curr_height, gwidth, curr_height, m_radius - 1); - } - else { - dc.DrawRoundedRectangle(left + gwidth * i, height - curr_height, gwidth, curr_height, 0); - } + dc.DrawRoundedRectangle(left + gwidth * i, height - curr_height, gwidth, curr_height, m_radius - 1); #endif //add rectangle int dr_gwidth = std::round(gwidth * 0.6); @@ -1428,21 +1409,9 @@ void AMSLib::render_generic_lib(wxDC &dc) 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); - if (top < m_radius){ - dc.DrawRoundedRectangle(FromDIP(4), FromDIP(4) + top, size.x - FromDIP(8), curr_height, m_radius - 1); - } - else{ - dc.DrawRectangle(FromDIP(1), FromDIP(1), size.x - FromDIP(2), size.y - FromDIP(1)); - } + dc.DrawRoundedRectangle(FromDIP(1), FromDIP(1), size.x - FromDIP(2), size.y - FromDIP(1), m_radius - 1); #else - if (top < m_radius) { - dc.DrawRoundedRectangle(FromDIP(2), FromDIP(1) + top, size.x - FromDIP(4), curr_height, m_radius - 1); - } - else { - dc.DrawRoundedRectangle(FromDIP(2), FromDIP(1) + top, size.x - FromDIP(4), curr_height, 0); - } + dc.DrawRoundedRectangle(FromDIP(2), FromDIP(1) + top, size.x - FromDIP(4), curr_height, m_radius - 1); #endif dc.SetBrush(brush); } @@ -2398,13 +2367,11 @@ void AMSPreview::Update(AMSinfo amsinfo) void AMSPreview::create(wxWindow *parent, wxWindowID id, const wxPoint &pos, const wxSize &size) { m_ts_bitmap_cube = ScalableBitmap(this, "ts_bitmap_cube", 14); - m_four_slot_bitmap = ScalableBitmap(this, "four_slot_ams_item", 26); - m_single_slot_bitmap = ScalableBitmap(this, "single_slot_ams_item", 26); - m_ext_bitmap = ScalableBitmap(this, "ext_ams_item", 26); + m_four_slot_bitmap = ScalableBitmap(this, "four_slot_ams_item", 32); + m_single_slot_bitmap = ScalableBitmap(this, "single_slot_ams_item", 32); wxWindow::Create(parent, id, pos, size); SetMinSize(size); SetMaxSize(size); - //SetBackgroundColour(StateColor::darkModeColorFor(*wxWHITE)); Refresh(); } @@ -2465,19 +2432,15 @@ void AMSPreview::render(wxDC &dc) void AMSPreview::doRender(wxDC &dc) { wxSize size = GetSize(); - /*dc.SetPen(wxPen(StateColor::darkModeColorFor(m_background_colour))); - dc.SetBrush(wxBrush(StateColor::darkModeColorFor(m_background_colour))); - dc.DrawRoundedRectangle(0, 0, size.x, size.y, 3);*/ - - auto left = 8; - m_space = 9; auto color = *wxWHITE; dc.SetPen(wxPen(*wxTRANSPARENT_PEN)); dc.SetBrush(color); dc.DrawRoundedRectangle(0, 0, size.x, size.y, FromDIP(3)); + auto left = 0; //four slot if (m_ams_item_type != AMSModel::EXT_AMS && m_ams_item_type != AMSModel::N3S_AMS){ + left = FromDIP(8); for (std::vector::iterator iter = m_amsinfo.cans.begin(); iter != m_amsinfo.cans.end(); iter++) { dc.SetPen(wxPen(*wxTRANSPARENT_PEN)); @@ -2491,9 +2454,9 @@ void AMSPreview::doRender(wxDC &dc) dc.SetBrush(AMS_CONTROL_DISABLE_COLOUR); } if (iter->material_cols.size() > 1) { - int fleft = FromDIP(left); - float total_width = AMS_ITEM_CUBE_SIZE.x; - int gwidth = (total_width / (iter->material_cols.size() - 1)); + int fleft = left; + + int gwidth = (AMS_ITEM_CUBE_SIZE.x / (iter->material_cols.size() - 1)); if (iter->ctype == 0) { for (int i = 0; i < iter->material_cols.size() - 1; i++) { if (fleft + gwidth > (AMS_ITEM_CUBE_SIZE.x)) { @@ -2509,34 +2472,31 @@ void AMSPreview::doRender(wxDC &dc) int cols_size = iter->material_cols.size(); for (int i = 0; i < cols_size; i++) { dc.SetBrush(wxBrush(iter->material_cols[i])); - int x = FromDIP(left) + total_width * i / cols_size; - dc.DrawRectangle(x, (size.y - AMS_ITEM_CUBE_SIZE.y) / 2, total_width / cols_size, AMS_ITEM_CUBE_SIZE.y); + int x = left + AMS_ITEM_CUBE_SIZE.x * i / cols_size; + dc.DrawRectangle(x, (size.y - AMS_ITEM_CUBE_SIZE.y) / 2, AMS_ITEM_CUBE_SIZE.x / cols_size, AMS_ITEM_CUBE_SIZE.y); } } } else { if (iter->material_colour.Alpha() == 0) { - dc.DrawBitmap(m_ts_bitmap_cube.bmp(), FromDIP(left), (size.y - AMS_ITEM_CUBE_SIZE.y) / 2); + dc.DrawBitmap(m_ts_bitmap_cube.bmp(), left, (size.y - AMS_ITEM_CUBE_SIZE.y) / 2); } else { - wxRect rect(FromDIP(left), (size.y - AMS_ITEM_CUBE_SIZE.y) / 2, AMS_ITEM_CUBE_SIZE.x, AMS_ITEM_CUBE_SIZE.y); + wxRect rect(left, (size.y - AMS_ITEM_CUBE_SIZE.y) / 2, AMS_ITEM_CUBE_SIZE.x, AMS_ITEM_CUBE_SIZE.y); if (iter->material_state == AMSCanType::AMS_CAN_TYPE_EMPTY) { - - // draw a slash when ams slot is empty - /*dc.SetPen(wxPen(wxColor(0, 0, 0))); - dc.DrawRoundedRectangle(rect, 3);*/ - //dc.DrawLine(rect.GetRight() - FromDIP(1), rect.GetTop() + FromDIP(1), rect.GetLeft() + FromDIP(1), rect.GetBottom() - FromDIP(1)); + dc.SetPen(wxPen(wxColor(0, 0, 0))); + dc.DrawLine(rect.GetRight() - FromDIP(1), rect.GetTop() + FromDIP(1), rect.GetLeft() + FromDIP(1), rect.GetBottom() - FromDIP(1)); } else { dc.DrawRoundedRectangle(rect, 2); } } } - left += m_space; + left += AMS_ITEM_CUBE_SIZE.x; } - auto pot = wxPoint((size.x - m_four_slot_bitmap.GetBmpSize().x) / 2, (size.y - m_four_slot_bitmap.GetBmpSize().y) / 2); - dc.DrawBitmap(m_four_slot_bitmap.bmp(), pot); + //auto pot = wxPoint((size.x - m_four_slot_bitmap.GetBmpSize().x) / 2, (size.y - m_four_slot_bitmap.GetBmpSize().y) / 2); + dc.DrawBitmap(m_four_slot_bitmap.bmp(), wxPoint(0,0)); } //single slot @@ -2578,19 +2538,25 @@ void AMSPreview::doRender(wxDC &dc) dc.SetPen(wxPen(*wxTRANSPARENT_PEN)); dc.SetBrush(iter.material_colour); //dc.SetBrush(*wxGREEN); - auto rect = wxRect(((size.x - AMS_ITEM_CUBE_SIZE.x) / 2), ((size.y - AMS_ITEM_CUBE_SIZE.y) / 2), (AMS_ITEM_CUBE_SIZE.x), (AMS_ITEM_CUBE_SIZE.y)); - dc.DrawRoundedRectangle(rect, FromDIP(4)); + if (m_ams_item_type == AMSModel::N3S_AMS) { + auto rect = wxRect(((size.x - AMS_ITEM_CUBE_SIZE.x) / 2), ((size.y - AMS_ITEM_CUBE_SIZE.y) / 2), (AMS_ITEM_CUBE_SIZE.x), (AMS_ITEM_CUBE_SIZE.y)); + dc.DrawRoundedRectangle(rect, 0); + } else { + auto rect = wxRect(((size.x - AMS_ITEM_CUBE_SIZE2.x) / 2), ((size.y - AMS_ITEM_CUBE_SIZE2.y) / 2), (AMS_ITEM_CUBE_SIZE2.x), (AMS_ITEM_CUBE_SIZE2.y)); + dc.DrawRoundedRectangle(rect, FromDIP(3)); + } } + if (m_ams_item_type == AMSModel::N3S_AMS) { - auto pot = wxPoint(((size.x - m_single_slot_bitmap.GetBmpSize().x) / 2), ((size.y - m_single_slot_bitmap.GetBmpSize().y) / 2)); - dc.DrawBitmap(m_single_slot_bitmap.bmp(), pot); + //auto pot = wxPoint(((size.x - m_single_slot_bitmap.GetBmpSize().x) / 2), ((size.y - m_single_slot_bitmap.GetBmpSize().y) / 2)); + dc.DrawBitmap(m_single_slot_bitmap.bmp(), wxPoint(0,0)); } if (((iter.material_colour.Red() >= 238 && iter.material_colour.Green() >= 238 && iter.material_colour.Blue() >= 238) || iter.material_colour.Alpha() == 0) && m_ams_item_type == AMSModel::EXT_AMS) { dc.SetPen(wxPen(AMS_CONTROL_GRAY500)); dc.SetBrush(wxBrush(*wxTRANSPARENT_BRUSH)); - auto rect = wxRect((size.x - AMS_ITEM_CUBE_SIZE.x) / 2, (size.y - AMS_ITEM_CUBE_SIZE.y) / 2, AMS_ITEM_CUBE_SIZE.x, AMS_ITEM_CUBE_SIZE.y); - dc.DrawRoundedRectangle(rect, FromDIP(4)); + auto rect = wxRect(((size.x - AMS_ITEM_CUBE_SIZE2.x) / 2), ((size.y - AMS_ITEM_CUBE_SIZE2.y) / 2), (AMS_ITEM_CUBE_SIZE2.x), (AMS_ITEM_CUBE_SIZE2.y)); + dc.DrawRoundedRectangle(rect, FromDIP(3)); } } auto border_colour = AMS_CONTROL_BRAND_COLOUR; @@ -2610,14 +2576,13 @@ void AMSPreview::doRender(wxDC &dc) } } -void AMSPreview::DoSetSize(int x, int y, int width, int height, int sizeFlags /*= wxSIZE_AUTO*/) { wxWindow::DoSetSize(x, y, width, height, sizeFlags); } -void AMSPreview::msw_rescale() { +void AMSPreview::msw_rescale() +{ m_ts_bitmap_cube = ScalableBitmap(this, "ts_bitmap_cube", 14); - m_four_slot_bitmap = ScalableBitmap(this, "four_slot_ams_item", 26); - m_single_slot_bitmap = ScalableBitmap(this, "single_slot_ams_item", 26); - m_ext_bitmap = ScalableBitmap(this, "ext_ams_item", 26); - - Layout(); + //m_four_slot_bitmap = ScalableBitmap(this, "four_slot_ams_item", 32); + //m_single_slot_bitmap = ScalableBitmap(this, "single_slot_ams_item", 28); + m_four_slot_bitmap.msw_rescale(); + m_single_slot_bitmap.msw_rescale(); Refresh(); } diff --git a/src/slic3r/GUI/Widgets/AMSItem.hpp b/src/slic3r/GUI/Widgets/AMSItem.hpp index 759be6605..920034c69 100644 --- a/src/slic3r/GUI/Widgets/AMSItem.hpp +++ b/src/slic3r/GUI/Widgets/AMSItem.hpp @@ -140,7 +140,8 @@ enum FilamentStepType { STEP_TYPE_VT_LOAD = 2, }; -#define AMS_ITEM_CUBE_SIZE wxSize(FromDIP(8), FromDIP(14)) +#define AMS_ITEM_CUBE_SIZE wxSize(FromDIP(9), FromDIP(14)) +#define AMS_ITEM_CUBE_SIZE2 wxSize(FromDIP(6), FromDIP(12)) #define AMS_PREVIEW_SIZE wxSize(FromDIP(82), FromDIP(27)) #define AMS_ITEM_SIZE wxSize(FromDIP(78), FromDIP(184)) #define AMS_PREV_FOUR_SIZE wxSize(FromDIP(52), FromDIP(32)) @@ -617,7 +618,6 @@ public: /************************************************* Description:AMSPreview **************************************************/ - class AMSPreview : public wxWindow { public: @@ -651,12 +651,10 @@ protected: ScalableBitmap m_ts_bitmap_cube; ScalableBitmap m_four_slot_bitmap; ScalableBitmap m_single_slot_bitmap; - ScalableBitmap m_ext_bitmap; void paintEvent(wxPaintEvent &evt); void render(wxDC &dc); void doRender(wxDC &dc); - virtual void DoSetSize(int x, int y, int width, int height, int sizeFlags = wxSIZE_AUTO); };