call render in main thread by function callAfter(hint by @Vojtech)
This commit is contained in:
parent
8fab4885c7
commit
6d895872b0
4 changed files with 30 additions and 14 deletions
|
@ -157,9 +157,8 @@ void GLGizmoBase::update(const UpdateData& data)
|
|||
|
||||
bool GLGizmoBase::update_items_state()
|
||||
{
|
||||
std::lock_guard<std::mutex> g(m_dirty_access);
|
||||
bool res = m_dirty;
|
||||
m_dirty = false;
|
||||
m_dirty = false;
|
||||
return res;
|
||||
};
|
||||
|
||||
|
@ -218,8 +217,7 @@ std::string GLGizmoBase::format(float value, unsigned int decimals) const
|
|||
return Slic3r::string_printf("%.*f", decimals, value);
|
||||
}
|
||||
|
||||
void GLGizmoBase::set_dirty() {
|
||||
std::lock_guard<std::mutex> g(m_dirty_access);
|
||||
void GLGizmoBase::set_dirty() {
|
||||
m_dirty = true;
|
||||
}
|
||||
|
||||
|
|
|
@ -1,7 +1,6 @@
|
|||
#ifndef slic3r_GLGizmoBase_hpp_
|
||||
#define slic3r_GLGizmoBase_hpp_
|
||||
|
||||
#include <mutex>
|
||||
#include "libslic3r/Point.hpp"
|
||||
|
||||
#include "slic3r/GUI/I18N.hpp"
|
||||
|
@ -154,6 +153,8 @@ public:
|
|||
bool is_dragging() const { return m_dragging; }
|
||||
|
||||
void update(const UpdateData& data);
|
||||
|
||||
// returns True when Gizmo changed its state
|
||||
bool update_items_state();
|
||||
|
||||
void render() { m_tooltip.clear(); on_render(); }
|
||||
|
@ -190,10 +191,11 @@ protected:
|
|||
|
||||
std::string format(float value, unsigned int decimals) const;
|
||||
|
||||
// Mark gizmo as dirty to Re-Render when idle()
|
||||
void set_dirty();
|
||||
|
||||
private:
|
||||
std::mutex m_dirty_access;
|
||||
// Flag for dirty visible state of Gizmo
|
||||
// When True then need new rendering
|
||||
bool m_dirty;
|
||||
};
|
||||
|
||||
|
|
|
@ -253,7 +253,7 @@ void GLGizmoSimplify::process()
|
|||
plater->clear_before_change_mesh(m_obj_index);
|
||||
m_progress = 0;
|
||||
if (m_worker.joinable()) m_worker.join();
|
||||
m_worker = std::thread([&]() {
|
||||
m_worker = std::thread([this]() {
|
||||
// store original triangles
|
||||
uint32_t triangle_count = (m_configuration.use_count) ? m_configuration.wanted_count : 0;
|
||||
float max_error = (m_configuration.use_error) ?
|
||||
|
@ -264,10 +264,16 @@ void GLGizmoSimplify::process()
|
|||
throw SimplifyCanceledException();
|
||||
}
|
||||
};
|
||||
std::function<void(int)> statusfn = [&](int percent) {
|
||||
|
||||
std::function<void(int)> statusfn = [this](int percent) {
|
||||
m_progress = percent;
|
||||
set_dirty();
|
||||
m_parent.schedule_extra_frame(0);
|
||||
|
||||
// check max 4fps
|
||||
static int64_t last = 0;
|
||||
int64_t now = m_parent.timestamp_now();
|
||||
if ((now - last) < 250) return;
|
||||
|
||||
request_rerender();
|
||||
};
|
||||
|
||||
indexed_triangle_set collapsed;
|
||||
|
@ -290,9 +296,8 @@ void GLGizmoSimplify::process()
|
|||
// set state out of main thread
|
||||
m_state = State::settings;
|
||||
}
|
||||
// need to render last status fn to change bar graph to buttons
|
||||
set_dirty();
|
||||
m_parent.schedule_extra_frame(0);
|
||||
// need to render last status fn to change bar graph to buttons
|
||||
request_rerender();
|
||||
});
|
||||
}
|
||||
|
||||
|
@ -335,6 +340,9 @@ void GLGizmoSimplify::on_set_state()
|
|||
|
||||
// invalidate selected model
|
||||
m_volume = nullptr;
|
||||
} else if (GLGizmoBase::m_state == GLGizmoBase::On) {
|
||||
// when open by hyperlink it needs to show up
|
||||
request_rerender();
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -360,4 +368,11 @@ void GLGizmoSimplify::create_gui_cfg() {
|
|||
m_gui_cfg = cfg;
|
||||
}
|
||||
|
||||
void GLGizmoSimplify::request_rerender() {
|
||||
wxGetApp().plater()->CallAfter([this]() {
|
||||
set_dirty();
|
||||
m_parent.schedule_extra_frame(0);
|
||||
});
|
||||
}
|
||||
|
||||
} // namespace Slic3r::GUI
|
||||
|
|
|
@ -35,6 +35,7 @@ private:
|
|||
void process();
|
||||
void set_its(indexed_triangle_set &its);
|
||||
void create_gui_cfg();
|
||||
void request_rerender();
|
||||
|
||||
bool m_is_valid_result; // differ what to do in apply
|
||||
volatile int m_progress; // percent of done work
|
||||
|
|
Loading…
Reference in a new issue