Calculate scale of text during drag&drop

This commit is contained in:
Filip Sykala - NTB T15p 2023-01-12 15:27:20 +01:00
parent 095ba5fbe8
commit 0bedaa247d

View file

@ -524,6 +524,9 @@ bool GLGizmoEmboss::on_mouse_for_translate(const wxMouseEvent &mouse_event)
// temp is in world coors // temp is in world coors
m_temp_transformation = object_trmat * trmat; m_temp_transformation = object_trmat * trmat;
// calculate scale
calculate_scale();
} else if (mouse_event.LeftUp()) { } else if (mouse_event.LeftUp()) {
// Added because of weird case after double click into scene // Added because of weird case after double click into scene
// with Mesa driver OR on Linux // with Mesa driver OR on Linux
@ -545,6 +548,9 @@ bool GLGizmoEmboss::on_mouse_for_translate(const wxMouseEvent &mouse_event)
m_volume->set_transformation(volume_trmat); m_volume->set_transformation(volume_trmat);
process(); process();
} }
// calculate scale
calculate_scale();
} }
return false; return false;
} }
@ -1130,21 +1136,30 @@ bool GLGizmoEmboss::set_volume(ModelVolume *volume)
} }
void GLGizmoEmboss::calculate_scale() { void GLGizmoEmboss::calculate_scale() {
Transform3d to_world = priv::world_matrix(m_parent.get_selection()); Transform3d to_world = m_temp_transformation.has_value()?
*m_temp_transformation :
priv::world_matrix(m_parent.get_selection());
auto to_world_linear = to_world.linear(); auto to_world_linear = to_world.linear();
Vec3d up_world = to_world_linear * Vec3d::UnitY(); auto calc = [&to_world_linear](const Vec3d &axe, std::optional<float>& scale)->bool {
double norm_sq = up_world.squaredNorm(); Vec3d axe_world = to_world_linear * axe;
if (is_approx(norm_sq, 1.)) double norm_sq = axe_world.squaredNorm();
m_scale_height.reset(); if (is_approx(norm_sq, 1.)) {
else if (scale.has_value())
m_scale_height = sqrt(norm_sq); scale.reset();
else
return false;
} else {
scale = sqrt(norm_sq);
}
return true;
};
Vec3d depth_world = to_world_linear * Vec3d::UnitZ(); bool exist_change = calc(Vec3d::UnitY(), m_scale_height);
double depth_sq = depth_world.squaredNorm(); exist_change |= calc(Vec3d::UnitZ(), m_scale_depth);
if (is_approx(depth_sq, 1.))
m_scale_depth.reset(); // Change of scale has to change font imgui font size
else if (exist_change)
m_scale_depth = sqrt(depth_sq); m_style_manager.clear_imgui_font();
} }
ModelVolume *priv::get_model_volume(const GLVolume *gl_volume, const ModelObject *object) ModelVolume *priv::get_model_volume(const GLVolume *gl_volume, const ModelObject *object)