From 972dbe238f76aaf95dd232a6a655d9ea3a2d95b8 Mon Sep 17 00:00:00 2001 From: David Kocik Date: Sun, 14 Mar 2021 18:01:10 +0100 Subject: [PATCH] preventing hidden notification to show when updated and close them correctly. --- src/slic3r/GUI/GLCanvas3D.cpp | 1 + src/slic3r/GUI/NotificationManager.cpp | 28 +++++++++++++++++--------- src/slic3r/GUI/NotificationManager.hpp | 27 ++++++++++++++++--------- 3 files changed, 38 insertions(+), 18 deletions(-) diff --git a/src/slic3r/GUI/GLCanvas3D.cpp b/src/slic3r/GUI/GLCanvas3D.cpp index 0a2b5cd655..5352e21b3e 100644 --- a/src/slic3r/GUI/GLCanvas3D.cpp +++ b/src/slic3r/GUI/GLCanvas3D.cpp @@ -1752,6 +1752,7 @@ void GLCanvas3D::render() m_tooltip.render(m_mouse.position, *this); wxGetApp().plater()->get_mouse3d_controller().render_settings_dialog(*this); + wxGetApp().plater()->get_notification_manager()->render_notifications(*this, get_overlay_window_width()); wxGetApp().imgui()->render(); diff --git a/src/slic3r/GUI/NotificationManager.cpp b/src/slic3r/GUI/NotificationManager.cpp index eb028d3d36..a9ac68036a 100644 --- a/src/slic3r/GUI/NotificationManager.cpp +++ b/src/slic3r/GUI/NotificationManager.cpp @@ -1,12 +1,9 @@ #include "NotificationManager.hpp" -#include "GUI_App.hpp" + #include "GUI.hpp" -#include "Plater.hpp" -#include "GLCanvas3D.hpp" #include "ImGuiWrapper.hpp" #include "PrintHostDialogs.hpp" - #include "wxExtensions.hpp" #include @@ -147,6 +144,12 @@ void NotificationManager::PopNotification::render(GLCanvas3D& canvas, float init return; } + if (m_state == EState::ClosePending || m_state == EState::Finished) + { + m_state = EState::Finished; + return; + } + Size cnv_size = canvas.get_canvas_size(); ImGuiWrapper& imgui = *wxGetApp().imgui(); ImVec2 mouse_pos = ImGui::GetMousePos(); @@ -240,7 +243,11 @@ void NotificationManager::PopNotification::count_spaces() void NotificationManager::PopNotification::init() { - std::string text = m_text1 + " " + m_hypertext; + // Do not init closing notification + if (is_finished()) + return; + + std::string text = m_text1 + " " + m_hypertext; size_t last_end = 0; m_lines_count = 0; @@ -291,7 +298,9 @@ void NotificationManager::PopNotification::init() } if (m_lines_count == 3) m_multiline = true; - m_state = EState::Shown; + m_notification_start = GLCanvas3D::timestamp_now(); + //if (m_state != EState::Hidden) + // m_state = EState::Shown; } void NotificationManager::PopNotification::set_next_window_size(ImGuiWrapper& imgui) { @@ -653,6 +662,7 @@ void NotificationManager::SlicingCompleteLargeNotification::set_large(bool l) // m_counting_down = !l; m_hypertext = l ? _u8L("Export G-Code.") : std::string(); m_state = l ? EState::Shown : EState::Hidden; + init(); } //---------------ExportFinishedNotification----------- void NotificationManager::ExportFinishedNotification::count_spaces() @@ -1270,9 +1280,10 @@ bool NotificationManager::activate_existing(const NotificationManager::PopNotifi for (auto it = m_pop_notifications.begin(); it != m_pop_notifications.end(); ++it) { if ((*it)->get_type() == new_type && !(*it)->is_finished()) { if (std::find(m_multiple_types.begin(), m_multiple_types.end(), new_type) != m_multiple_types.end()) { - //if (new_type == NotificationType::CustomNotification || new_type == NotificationType::PlaterWarning || new_type == NotificationType::ProgressBar) { - if (!(*it)->compare_text(new_text)) + // If found same type and same text, return true - update will be performed on the old notif + if ((*it)->compare_text(new_text) == false) { continue; + } } else if (new_type == NotificationType::SlicingWarning) { auto w1 = dynamic_cast(notification); auto w2 = dynamic_cast(it->get()); @@ -1284,7 +1295,6 @@ bool NotificationManager::activate_existing(const NotificationManager::PopNotifi continue; } } - if (it != m_pop_notifications.end() - 1) std::rotate(it, it + 1, m_pop_notifications.end()); return true; diff --git a/src/slic3r/GUI/NotificationManager.hpp b/src/slic3r/GUI/NotificationManager.hpp index 222d6b1552..e86ac8056a 100644 --- a/src/slic3r/GUI/NotificationManager.hpp +++ b/src/slic3r/GUI/NotificationManager.hpp @@ -1,6 +1,9 @@ #ifndef slic3r_GUI_NotificationManager_hpp_ #define slic3r_GUI_NotificationManager_hpp_ +#include "GUI_App.hpp" +#include "Plater.hpp" +#include "GLCanvas3D.hpp" #include "Event.hpp" #include "I18N.hpp" @@ -211,9 +214,9 @@ private: PopNotification(const NotificationData &n, NotificationIDProvider &id_provider, wxEvtHandler* evt_handler); virtual ~PopNotification() { if (m_id) m_id_provider.release_id(m_id); } - void render(GLCanvas3D& canvas, float initial_y, bool move_from_overlay, float overlay_width); + virtual void render(GLCanvas3D& canvas, float initial_y, bool move_from_overlay, float overlay_width); // close will dissapear notification on next render - virtual void close() { m_state = EState::ClosePending; } + virtual void close() { m_state = EState::ClosePending; wxGetApp().plater()->get_current_canvas3D()->schedule_extra_frame(0);} // data from newer notification of same type void update(const NotificationData& n); bool is_finished() const { return m_state == EState::ClosePending || m_state == EState::Finished; } @@ -226,7 +229,7 @@ private: const bool is_gray() const { return m_is_gray; } void set_gray(bool g) { m_is_gray = g; } bool compare_text(const std::string& text); - void hide(bool h) { m_state = h ? EState::Hidden : EState::Unknown; } + void hide(bool h) { if (is_finished()) return; m_state = h ? EState::Hidden : EState::Unknown; } // sets m_next_render with time of next mandatory rendering. Delta is time since last render. bool update_state(bool paused, const int64_t delta); int64_t next_render() const { return is_finished() ? 0 : m_next_render; } @@ -313,10 +316,16 @@ private: { public: SlicingCompleteLargeNotification(const NotificationData& n, NotificationIDProvider& id_provider, wxEvtHandler* evt_handler, bool largeds); - void set_large(bool l); - bool get_large() { return m_is_large; } - - void set_print_info(const std::string &info); + void set_large(bool l); + bool get_large() { return m_is_large; } + void set_print_info(const std::string &info); + virtual void render(GLCanvas3D& canvas, float initial_y, bool move_from_overlay, float overlay_width) + { + // This notification is always hidden if !large (means side bar is collapsed) + if (!get_large() && !is_finished()) + m_state == EState::Hidden; + PopNotification::render(canvas, initial_y, move_from_overlay, overlay_width); + } protected: virtual void render_text(ImGuiWrapper& imgui, const float win_size_x, const float win_size_y, @@ -339,8 +348,8 @@ private: { public: PlaterWarningNotification(const NotificationData& n, NotificationIDProvider& id_provider, wxEvtHandler* evt_handler) : PopNotification(n, id_provider, evt_handler) {} - virtual void close() { m_state = EState::Hidden; } - void real_close() { m_state = EState::ClosePending; } + virtual void close() { if(is_finished()) return; m_state = EState::Hidden; wxGetApp().plater()->get_current_canvas3D()->schedule_extra_frame(0); } + void real_close() { m_state = EState::ClosePending; wxGetApp().plater()->get_current_canvas3D()->schedule_extra_frame(0); } void show() { m_state = EState::Unknown; } };