From 92b31a6435634e19392820315eba3391d8c59654 Mon Sep 17 00:00:00 2001 From: yw4z Date: Thu, 8 May 2025 07:33:57 +0300 Subject: [PATCH] Improve quality of bed name / number texture (#9535) * init * update * update * update * update * update * Update PartPlate.cpp --- resources/images/plate_name_edit.svg | 2 +- resources/images/plate_name_edit_dark.svg | 2 +- resources/images/plate_name_edit_hover.svg | 2 +- .../images/plate_name_edit_hover_dark.svg | 2 +- src/slic3r/GUI/PartPlate.cpp | 70 ++++++++++++------- 5 files changed, 47 insertions(+), 31 deletions(-) diff --git a/resources/images/plate_name_edit.svg b/resources/images/plate_name_edit.svg index 54a607d222..c7ecc2f1af 100644 --- a/resources/images/plate_name_edit.svg +++ b/resources/images/plate_name_edit.svg @@ -1 +1 @@ - \ No newline at end of file + \ No newline at end of file diff --git a/resources/images/plate_name_edit_dark.svg b/resources/images/plate_name_edit_dark.svg index 729cb18431..5207d63a86 100644 --- a/resources/images/plate_name_edit_dark.svg +++ b/resources/images/plate_name_edit_dark.svg @@ -1 +1 @@ - \ No newline at end of file + \ No newline at end of file diff --git a/resources/images/plate_name_edit_hover.svg b/resources/images/plate_name_edit_hover.svg index 66befdaebd..eb8dd62d4a 100644 --- a/resources/images/plate_name_edit_hover.svg +++ b/resources/images/plate_name_edit_hover.svg @@ -1 +1 @@ - \ No newline at end of file + \ No newline at end of file diff --git a/resources/images/plate_name_edit_hover_dark.svg b/resources/images/plate_name_edit_hover_dark.svg index 0382c829ff..c6d417a258 100644 --- a/resources/images/plate_name_edit_hover_dark.svg +++ b/resources/images/plate_name_edit_hover_dark.svg @@ -1 +1 @@ - \ No newline at end of file + \ No newline at end of file diff --git a/src/slic3r/GUI/PartPlate.cpp b/src/slic3r/GUI/PartPlate.cpp index fc9b851893..0c79b38e38 100644 --- a/src/slic3r/GUI/PartPlate.cpp +++ b/src/slic3r/GUI/PartPlate.cpp @@ -53,7 +53,7 @@ static unsigned int GLOBAL_PLATE_INDEX = 0; static const double LOGICAL_PART_PLATE_GAP = 1. / 5.; static const int PARTPLATE_ICON_SIZE = 16; -static const int PARTPLATE_EDIT_PLATE_NAME_ICON_SIZE = 12; +static const int PARTPLATE_EDIT_PLATE_NAME_ICON_SIZE = 9; // ORCA this also scales height of plate name static const int PARTPLATE_ICON_GAP_TOP = 3; static const int PARTPLATE_ICON_GAP_LEFT = 3; static const int PARTPLATE_ICON_GAP_Y = 5; @@ -570,21 +570,25 @@ void PartPlate::calc_vertex_for_plate_name_edit_icon(GLTexture *texture, int ind ExPolygon poly; auto bed_ext = get_extents(m_shape); Vec2d p = bed_ext[3]; - auto factor = bed_ext.size()(1) / 200.0; - float width = 0.f; - float height = PARTPLATE_EDIT_PLATE_NAME_ICON_SIZE * factor; - float offset_x = 1 * factor; - float offset_y = PARTPLATE_TEXT_OFFSET_Y * factor; + float factor = bed_ext.size()(1) / 200.0; + float icon_sz = factor * PARTPLATE_EDIT_PLATE_NAME_ICON_SIZE; + float width = icon_sz; + float height = icon_sz; + float offset_y = factor * PARTPLATE_TEXT_OFFSET_Y; + float name_width; if (texture && texture->get_width() > 0 && texture->get_height()) - width = int(factor * (texture->get_original_width() * 16) / texture->get_height()); + // original width give correct ratio in here since rendering width can be much higher because of next_highest_power_of_2 for rendering + name_width = icon_sz * texture->m_original_width / texture->get_height(); - p += Vec2d(width + offset_x, offset_y + height); + //if (m_plater && m_plater->get_build_volume_type() == BuildVolume_Type::Circle) + // px = scale_(bed_ext.center()(0)) + m_name_texture_width * 0.50 - height * 0.50; + p += Vec2d(name_width, offset_y); - poly.contour.append({ scale_(p(0)) , scale_(p(1) - height) }); - poly.contour.append({ scale_(p(0) + height), scale_(p(1) - height) }); - poly.contour.append({ scale_(p(0) + height), scale_(p(1)) }); - poly.contour.append({ scale_(p(0)) , scale_(p(1)) }); + poly.contour.append({ scale_(p(0) ), scale_(p(1) ) }); + poly.contour.append({ scale_(p(0) + width), scale_(p(1) ) }); + poly.contour.append({ scale_(p(0) + width), scale_(p(1) + height) }); + poly.contour.append({ scale_(p(0) ), scale_(p(1) + height) }); if (!init_model_from_poly(model.model, poly, GROUND_Z)) BOOST_LOG_TRIVIAL(error) << __FUNCTION__ << "Unable to generate geometry buffers for icons\n"; @@ -1869,25 +1873,34 @@ void PartPlate::generate_plate_name_texture() // generate m_name_texture texture from m_name with generate_from_text_string m_name_texture.reset(); auto text = m_name.empty()? _L("Untitled") : from_u8(m_name); - wxCoord w, h; - auto* font = &Label::Head_32; + // ORCA also scale font size to prevent low res texture + int size = wxGetApp().em_unit() * PARTPLATE_EDIT_PLATE_NAME_ICON_SIZE; + auto l = Label::sysFont(size, true); + wxFont* font = &l; wxColour foreground(0xf2, 0x75, 0x4e, 0xff); if (!m_name_texture.generate_from_text_string(text.ToUTF8().data(), *font, *wxBLACK, foreground)) BOOST_LOG_TRIVIAL(error) << "PartPlate::generate_plate_name_texture(): generate_from_text_string() failed"; - auto bed_ext = get_extents(m_shape); - auto factor = bed_ext.size()(1) / 200.0; - ExPolygon poly; - float offset_x = 1 * factor; - float offset_y = PARTPLATE_TEXT_OFFSET_Y * factor; - w = int(factor * (m_name_texture.get_width() * 16) / m_name_texture.get_height()); - h = int(factor * 16); - Vec2d p = bed_ext[3] + Vec2d(0, 1 + h * m_name_texture.m_original_height / m_name_texture.get_height()); - poly.contour.append({ scale_(p(0) + offset_x) , scale_(p(1) - h + offset_y) }); - poly.contour.append({ scale_(p(0) + w - offset_x), scale_(p(1) - h + offset_y) }); - poly.contour.append({ scale_(p(0) + w - offset_x), scale_(p(1) - offset_y) }); - poly.contour.append({ scale_(p(0) + offset_x) , scale_(p(1) - offset_y) }); + + ExPolygon poly; + auto bed_ext = get_extents(m_shape); + Vec2d p = bed_ext[3]; + float factor = bed_ext.size()(1) / 200.0; + float icon_sz = factor * PARTPLATE_EDIT_PLATE_NAME_ICON_SIZE; + float width = icon_sz * m_name_texture.get_width() / m_name_texture.get_height(); // icon size * text_bb_ratio + float height = icon_sz; // scale with icon size to preserve ratio while system scaling + float offset_y = factor * PARTPLATE_TEXT_OFFSET_Y; + + //if (m_plater && m_plater->get_build_volume_type() == BuildVolume_Type::Circle) + // px = scale_(bed_ext.center()(0)) - (width + height) / 2.00; + + p += Vec2d(0, offset_y); + + poly.contour.append({ scale_(p(0) ), scale_(p(1) ) }); + poly.contour.append({ scale_(p(0) + width), scale_(p(1) ) }); + poly.contour.append({ scale_(p(0) + width), scale_(p(1) + height) }); + poly.contour.append({ scale_(p(0) ), scale_(p(1) + height) }); if (!init_model_from_poly(m_plate_name_icon, poly, GROUND_Z)) BOOST_LOG_TRIVIAL(error) << __FUNCTION__ << "Unable to generate geometry buffers for icons\n"; @@ -3367,7 +3380,10 @@ void PartPlateList::generate_icon_textures() } std::string text_str = "01"; - wxFont* font = find_font(text_str,32); + // ORCA also scale font size to prevent low res texture + int size = wxGetApp().em_unit() * PARTPLATE_ICON_SIZE; + auto l = Label::sysFont(int(size), true); + wxFont* font = &l; for (int i = 0; i < MAX_PLATE_COUNT; i++) { if (m_idx_textures[i].get_id() == 0) {