Improve quality of bed name / number texture (#9535)

* init

* update

* update

* update

* update

* update

* Update PartPlate.cpp
This commit is contained in:
yw4z
2025-05-08 07:33:57 +03:00
committed by GitHub
parent 13225c817a
commit 92b31a6435
5 changed files with 47 additions and 31 deletions

View File

@@ -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) {