FIX: add thread for load font
jira: none Change-Id: Iba53e1cf55beb77acbdbd731f052940b55349b8f
This commit is contained in:
parent
d5a59a5fde
commit
46da98c432
|
@ -552,9 +552,6 @@ bool GLTexture::generate_from_text(const std::string &text_str, wxFont &font, wx
|
|||
|
||||
bool GLTexture::generate_texture_from_text(const std::string& text_str, wxFont& font, int& ww, int& hh, int& hl, wxColor background, wxColor foreground)
|
||||
{
|
||||
if(!can_generate_text_shape(text_str))
|
||||
return false;
|
||||
|
||||
if (text_str.empty())
|
||||
{
|
||||
BOOST_LOG_TRIVIAL(error) << __FUNCTION__ << ":no text string, should not happen\n";
|
||||
|
|
|
@ -190,6 +190,9 @@ GLGizmoText::GLGizmoText(GLCanvas3D& parent, const std::string& icon_filename, u
|
|||
|
||||
GLGizmoText::~GLGizmoText()
|
||||
{
|
||||
if (m_thread.joinable())
|
||||
m_thread.join();
|
||||
|
||||
for (int i = 0; i < m_textures.size(); i++) {
|
||||
if (m_textures[i].texture != nullptr)
|
||||
delete m_textures[i].texture;
|
||||
|
@ -198,10 +201,13 @@ GLGizmoText::~GLGizmoText()
|
|||
|
||||
bool GLGizmoText::on_init()
|
||||
{
|
||||
m_init_texture = false;
|
||||
m_avail_font_names = init_face_names();
|
||||
|
||||
m_thread = std::thread(&GLGizmoText::update_font_status, this);
|
||||
|
||||
//m_avail_font_names = init_occt_fonts();
|
||||
update_font_texture();
|
||||
//update_font_texture();
|
||||
m_scale = m_imgui->get_font_size();
|
||||
m_shortcut_key = WXK_CONTROL_T;
|
||||
|
||||
|
@ -232,7 +238,8 @@ void GLGizmoText::update_font_texture()
|
|||
auto retina_scale = m_parent.get_scale();
|
||||
wxFont font { (int)round(retina_scale * FONT_SIZE), wxFONTFAMILY_SWISS, wxFONTSTYLE_NORMAL, wxFONTWEIGHT_NORMAL, false, face };
|
||||
int w, h, hl;
|
||||
if (texture->generate_texture_from_text(m_avail_font_names[i], font, w, h, hl, FONT_TEXTURE_BG, FONT_TEXTURE_FG)) {
|
||||
std::unique_lock<std::mutex> lock(m_mutex);
|
||||
if (m_font_status[i] && texture->generate_texture_from_text(m_avail_font_names[i], font, w, h, hl, FONT_TEXTURE_BG, FONT_TEXTURE_FG)) {
|
||||
//if (h < m_imgui->scaled(2.f)) {
|
||||
TextureInfo info;
|
||||
info.texture = texture;
|
||||
|
@ -689,6 +696,11 @@ void GLGizmoText::pop_combo_style()
|
|||
// BBS
|
||||
void GLGizmoText::on_render_input_window(float x, float y, float bottom_limit)
|
||||
{
|
||||
if (!m_init_texture) {
|
||||
update_font_texture();
|
||||
m_init_texture = true;
|
||||
}
|
||||
|
||||
if (m_imgui->get_font_size() != m_scale) {
|
||||
m_scale = m_imgui->get_font_size();
|
||||
update_font_texture();
|
||||
|
@ -992,6 +1004,19 @@ void GLGizmoText::reset_text_info()
|
|||
m_is_modify = false;
|
||||
}
|
||||
|
||||
void GLGizmoText::update_font_status() {
|
||||
std::unique_lock<std::mutex> lock(m_mutex);
|
||||
m_font_status.reserve(m_avail_font_names.size());
|
||||
for (std::string font_name : m_avail_font_names) {
|
||||
if (!can_generate_text_shape(font_name)) {
|
||||
m_font_status.emplace_back(false);
|
||||
}
|
||||
else {
|
||||
m_font_status.emplace_back(true);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
bool GLGizmoText::update_text_positions(const std::vector<std::string>& texts)
|
||||
{
|
||||
std::vector<double> text_lengths;
|
||||
|
|
|
@ -57,6 +57,11 @@ private:
|
|||
|
||||
std::vector<std::string> m_font_names;
|
||||
|
||||
bool m_init_texture = false;
|
||||
std::vector<bool> m_font_status;
|
||||
std::mutex m_mutex;
|
||||
std::thread m_thread;
|
||||
|
||||
bool m_is_modify = false;
|
||||
bool m_need_update_text = false;
|
||||
|
||||
|
@ -108,6 +113,7 @@ protected:
|
|||
|
||||
private:
|
||||
ModelVolume *get_selected_single_volume(int& out_object_idx, int& out_volume_idx) const;
|
||||
void update_font_status();
|
||||
void reset_text_info();
|
||||
bool update_text_positions(const std::vector<std::string>& texts);
|
||||
TriangleMesh get_text_mesh(const char* text_str, const Vec3d &position, const Vec3d &normal, const Vec3d &text_up_dir);
|
||||
|
|
Loading…
Reference in New Issue