From 2659ac567a8f8c1a588b83c4f10fe371a71e5e95 Mon Sep 17 00:00:00 2001 From: David Kocik Date: Sun, 6 Dec 2020 14:53:13 +0100 Subject: Timeout in requesting renders at notification fadeout. --- src/slic3r/GUI/NotificationManager.cpp | 30 ++++++++++++++++++++++-------- src/slic3r/GUI/NotificationManager.hpp | 15 ++++++++------- 2 files changed, 30 insertions(+), 15 deletions(-) (limited to 'src') diff --git a/src/slic3r/GUI/NotificationManager.cpp b/src/slic3r/GUI/NotificationManager.cpp index bf4142b9c..1adf984d7 100644 --- a/src/slic3r/GUI/NotificationManager.cpp +++ b/src/slic3r/GUI/NotificationManager.cpp @@ -746,7 +746,7 @@ void NotificationManager::PopNotification::update_state() init(); if (m_hidden) { - m_state = EState::Static; + m_state = EState::Hidden; return; } @@ -777,10 +777,16 @@ void NotificationManager::PopNotification::update_state() } if (m_fading_out) { if (!m_paused) { - wxMilliClock_t curr_time = wxGetLocalTimeMillis() - m_fading_start; + m_state = EState::FadingOutStatic; + wxMilliClock_t curr_time = wxGetLocalTimeMillis() - m_fading_start; + wxMilliClock_t no_render_time = wxGetLocalTimeMillis() - m_last_render_fading; m_current_fade_opacity = std::clamp(1.0f - 0.001f * static_cast(curr_time.GetValue()) / FADING_OUT_DURATION, 0.0f, 1.0f); + if (no_render_time > 100) { + m_last_render_fading = wxGetLocalTimeMillis(); + m_state = EState::FadingOutRender; + } } - m_state = EState::FadingOut; + } } #endif // ENABLE_NEW_NOTIFICATIONS_FADE_OUT @@ -1207,9 +1213,12 @@ void NotificationManager::render_notifications(float overlay_width) float last_y = 0.0f; for (const auto& notification : m_pop_notifications) { - notification->render(canvas, last_y, m_move_from_overlay && !m_in_preview, overlay_width); - if (notification->get_state() != PopNotification::EState::Finished) - last_y = notification->get_top() + GAP_WIDTH; + if (notification->get_state() != PopNotification::EState::Hidden) { + notification->render(canvas, last_y, m_move_from_overlay && !m_in_preview, overlay_width); + if (notification->get_state() != PopNotification::EState::Finished) + last_y = notification->get_top() + GAP_WIDTH; + } + } } #else @@ -1331,7 +1340,7 @@ void NotificationManager::set_in_preview(bool preview) #if ENABLE_NEW_NOTIFICATIONS_FADE_OUT void NotificationManager::update_notifications() { - static size_t last_size = 0; + static size_t last_size = m_pop_notifications.size(); for (auto it = m_pop_notifications.begin(); it != m_pop_notifications.end();) { std::unique_ptr& notification = *it; @@ -1361,10 +1370,12 @@ void NotificationManager::update_notifications() } } + // Reuire render if some notification was just deleted. size_t curr_size = m_pop_notifications.size(); m_requires_render = m_hovered || (last_size != curr_size); last_size = curr_size; + // Ask notification if it needs render if (!m_requires_render) { for (const std::unique_ptr& notification : m_pop_notifications) { if (notification->requires_render()) { @@ -1373,6 +1384,9 @@ void NotificationManager::update_notifications() } } } + // Make sure there will be update after last notification erased + if (m_requires_render) + m_requires_update = true; // actualizate timers wxWindow* p = dynamic_cast(wxGetApp().plater()); @@ -1390,7 +1404,7 @@ void NotificationManager::update_notifications() if (!m_hovered && m_last_time < now) { if (now - m_last_time >= 1) { for (auto& notification : m_pop_notifications) { - if (notification->get_state() != PopNotification::EState::Static) + //if (notification->get_state() != PopNotification::EState::Static) notification->substract_remaining_time(); } } diff --git a/src/slic3r/GUI/NotificationManager.hpp b/src/slic3r/GUI/NotificationManager.hpp index 79299182e..d60fc0b7d 100644 --- a/src/slic3r/GUI/NotificationManager.hpp +++ b/src/slic3r/GUI/NotificationManager.hpp @@ -188,11 +188,11 @@ private: enum class EState { Unknown, - Static, - Countdown, - FadingOut, - ClosePending, - Finished + Hidden, + FadingOutRender, // Requesting Render + FadingOutStatic, + ClosePending, // Requesting Render + Finished, // Requesting Render }; #else enum class RenderResult @@ -234,8 +234,8 @@ private: void hide(bool h) { m_hidden = h; } #if ENABLE_NEW_NOTIFICATIONS_FADE_OUT void update_state(); - bool requires_render() const { return m_fading_out || m_close_pending || m_finished; } - bool requires_update() const { return m_state != EState::Static; } + bool requires_render() const { return m_state == EState::FadingOutRender || m_state == EState::ClosePending || m_state == EState::Finished; } + bool requires_update() const { return m_state != EState::Hidden; } EState get_state() const { return m_state; } #endif // ENABLE_NEW_NOTIFICATIONS_FADE_OUT @@ -293,6 +293,7 @@ private: bool m_fading_out { false }; #if ENABLE_NEW_NOTIFICATIONS_FADE_OUT wxMilliClock_t m_fading_start { 0LL }; + wxMilliClock_t m_last_render_fading { 0LL }; #else // total time left when fading beggins float m_fading_time{ 0.0f }; -- cgit v1.2.3