Tech ENABLE_NEW_NOTIFICATIONS_FADE_OUT set as default

This commit is contained in:
enricoturri1966 2021-02-19 12:18:09 +01:00
parent fbd8d57adc
commit 0a1448196b
4 changed files with 7 additions and 335 deletions

View file

@ -19,14 +19,12 @@
static constexpr float GAP_WIDTH = 10.0f;
static constexpr float SPACE_RIGHT_PANEL = 10.0f;
#if ENABLE_NEW_NOTIFICATIONS_FADE_OUT
static constexpr float FADING_OUT_DURATION = 2.0f;
// Time in Miliseconds after next render when fading out is requested
static constexpr int FADING_OUT_TIMEOUT = 100;
// If timeout is changed to higher than 1 second, substract_time call should be revorked
//static constexpr int MAX_TIMEOUT_MILISECONDS = 1000;
//static constexpr int MAX_TIMEOUT_SECONDS = 1;
#endif // ENABLE_NEW_NOTIFICATIONS_FADE_OUT
namespace Slic3r {
namespace GUI {
@ -144,12 +142,11 @@ NotificationManager::PopNotification::PopNotification(const NotificationData &n,
{
//init();
}
#if ENABLE_NEW_NOTIFICATIONS_FADE_OUT
void NotificationManager::PopNotification::render(GLCanvas3D& canvas, float initial_y, bool move_from_overlay, float overlay_width)
{
if (!m_initialized) {
if (!m_initialized)
init();
}
if (m_hidden) {
m_top_y = initial_y - GAP_WIDTH;
@ -240,142 +237,7 @@ void NotificationManager::PopNotification::render(GLCanvas3D& canvas, float init
if (fading_pop)
ImGui::PopStyleColor(2);
}
#else
NotificationManager::PopNotification::RenderResult NotificationManager::PopNotification::render(GLCanvas3D& canvas, const float& initial_y, bool move_from_overlay, float overlay_width)
{
if (!m_initialized) {
init();
}
if (m_finished)
return RenderResult::Finished;
if (m_close_pending) {
// request of extra frame will be done in caller function by ret val ClosePending
m_finished = true;
return RenderResult::ClosePending;
}
if (m_hidden) {
m_top_y = initial_y - GAP_WIDTH;
return RenderResult::Static;
}
RenderResult ret_val = m_counting_down ? RenderResult::Countdown : RenderResult::Static;
Size cnv_size = canvas.get_canvas_size();
ImGuiWrapper& imgui = *wxGetApp().imgui();
bool shown = true;
ImVec2 mouse_pos = ImGui::GetMousePos();
float right_gap = SPACE_RIGHT_PANEL + (move_from_overlay ? overlay_width + m_line_height * 5 : 0);
if (m_line_height != ImGui::CalcTextSize("A").y)
init();
set_next_window_size(imgui);
//top y of window
m_top_y = initial_y + m_window_height;
//top right position
ImVec2 win_pos(1.0f * (float)cnv_size.get_width() - right_gap, 1.0f * (float)cnv_size.get_height() - m_top_y);
imgui.set_next_window_pos(win_pos.x, win_pos.y, ImGuiCond_Always, 1.0f, 0.0f);
imgui.set_next_window_size(m_window_width, m_window_height, ImGuiCond_Always);
//find if hovered
if (mouse_pos.x < win_pos.x && mouse_pos.x > win_pos.x - m_window_width && mouse_pos.y > win_pos.y&& mouse_pos.y < win_pos.y + m_window_height)
{
ImGui::SetNextWindowFocus();
ret_val = RenderResult::Hovered;
//reset fading
m_fading_out = false;
m_current_fade_opacity = 1.f;
m_remaining_time = m_data.duration;
m_countdown_frame = 0;
}
if (m_counting_down && m_remaining_time < 0)
m_close_pending = true;
if (m_close_pending) {
// request of extra frame will be done in caller function by ret val ClosePending
m_finished = true;
return RenderResult::ClosePending;
}
// color change based on fading out
bool fading_pop = false;
if (m_fading_out) {
if (!m_paused)
m_current_fade_opacity -= 1.f / ((m_fading_time + 1.f) * 60.f);
Notifications_Internal::push_style_color(ImGuiCol_WindowBg, ImGui::GetStyleColorVec4(ImGuiCol_WindowBg), m_fading_out, m_current_fade_opacity);
Notifications_Internal::push_style_color(ImGuiCol_Text, ImGui::GetStyleColorVec4(ImGuiCol_Text), m_fading_out, m_current_fade_opacity);
fading_pop = true;
}
// background color
if (m_is_gray) {
ImVec4 backcolor(0.7f, 0.7f, 0.7f, 0.5f);
Notifications_Internal::push_style_color(ImGuiCol_WindowBg, backcolor, m_fading_out, m_current_fade_opacity);
} else if (m_data.level == NotificationLevel::ErrorNotification) {
ImVec4 backcolor = ImGui::GetStyleColorVec4(ImGuiCol_WindowBg);
backcolor.x += 0.3f;
Notifications_Internal::push_style_color(ImGuiCol_WindowBg, backcolor, m_fading_out, m_current_fade_opacity);
} else if (m_data.level == NotificationLevel::WarningNotification) {
ImVec4 backcolor = ImGui::GetStyleColorVec4(ImGuiCol_WindowBg);
backcolor.x += 0.3f;
backcolor.y += 0.15f;
Notifications_Internal::push_style_color(ImGuiCol_WindowBg, backcolor, m_fading_out, m_current_fade_opacity);
}
//name of window - probably indentifies window and is shown so last_end add whitespaces according to id
if (! m_id)
m_id = m_id_provider.allocate_id();
std::string name;
{
// Create a unique ImGUI window name. The name may be recycled using a name of an already released notification.
char buf[32];
sprintf(buf, "!!Ntfctn%d", m_id);
name = buf;
}
if (imgui.begin(name, &shown, ImGuiWindowFlags_NoCollapse | ImGuiWindowFlags_NoTitleBar | ImGuiWindowFlags_NoMove | ImGuiWindowFlags_NoResize | ImGuiWindowFlags_NoScrollbar )) {
if (shown) {
ImVec2 win_size = ImGui::GetWindowSize();
//FIXME: dont forget to us this for texts
//GUI::format(_utf8(L()));
/*
//countdown numbers
ImGui::SetCursorPosX(15);
ImGui::SetCursorPosY(15);
imgui.text(std::to_string(m_remaining_time).c_str());
*/
if(m_counting_down)
render_countdown(imgui, win_size.x, win_size.y, win_pos.x, win_pos.y);
render_left_sign(imgui);
render_text(imgui, win_size.x, win_size.y, win_pos.x, win_pos.y);
render_close_button(imgui, win_size.x, win_size.y, win_pos.x, win_pos.y);
m_minimize_b_visible = false;
if (m_multiline && m_lines_count > 3)
render_minimize_button(imgui, win_pos.x, win_pos.y);
} else {
// the user clicked on the [X] button ( ImGuiWindowFlags_NoTitleBar means theres no [X] button)
m_close_pending = true;
canvas.set_as_dirty();
}
}
imgui.end();
if (fading_pop) {
ImGui::PopStyleColor();
ImGui::PopStyleColor();
}
if (m_is_gray)
ImGui::PopStyleColor();
else if (m_data.level == NotificationLevel::ErrorNotification)
ImGui::PopStyleColor();
else if (m_data.level == NotificationLevel::WarningNotification)
ImGui::PopStyleColor();
return ret_val;
}
#endif // ENABLE_NEW_NOTIFICATIONS_FADE_OUT
void NotificationManager::PopNotification::count_spaces()
{
//determine line width
@ -633,55 +495,7 @@ void NotificationManager::PopNotification::render_close_button(ImGuiWrapper& img
ImGui::PopStyleColor();
ImGui::PopStyleColor();
}
#if !ENABLE_NEW_NOTIFICATIONS_FADE_OUT
void NotificationManager::PopNotification::render_countdown(ImGuiWrapper& imgui, const float win_size_x, const float win_size_y, const float win_pos_x, const float win_pos_y)
{
/*
ImVec2 win_size(win_size_x, win_size_y);
ImVec2 win_pos(win_pos_x, win_pos_y);
//countdown dots
std::string dot_text;
dot_text = m_remaining_time <= (float)m_data.duration / 4 * 3 ? ImGui::TimerDotEmptyMarker : ImGui::TimerDotMarker;
ImGui::SetCursorPosX(win_size.x - m_line_height);
//ImGui::SetCursorPosY(win_size.y / 2 - 24);
ImGui::SetCursorPosY(0);
imgui.text(dot_text.c_str());
dot_text = m_remaining_time < m_data.duration / 2 ? ImGui::TimerDotEmptyMarker : ImGui::TimerDotMarker;
ImGui::SetCursorPosX(win_size.x - m_line_height);
//ImGui::SetCursorPosY(win_size.y / 2 - 9);
ImGui::SetCursorPosY(win_size.y / 2 - m_line_height / 2);
imgui.text(dot_text.c_str());
dot_text = m_remaining_time <= m_data.duration / 4 ? ImGui::TimerDotEmptyMarker : ImGui::TimerDotMarker;
ImGui::SetCursorPosX(win_size.x - m_line_height);
//ImGui::SetCursorPosY(win_size.y / 2 + 6);
ImGui::SetCursorPosY(win_size.y - m_line_height);
imgui.text(dot_text.c_str());
*/
if (!m_fading_out && m_remaining_time <= m_data.duration / 4) {
m_fading_out = true;
m_fading_time = m_remaining_time;
}
if (m_last_remaining_time != m_remaining_time) {
m_last_remaining_time = m_remaining_time;
m_countdown_frame = 0;
}
/*
//countdown line
ImVec4 orange_color = ImGui::GetStyleColorVec4(ImGuiCol_Button);
float invisible_length = ((float)(m_data.duration - m_remaining_time) / (float)m_data.duration * win_size_x);
invisible_length -= win_size_x / ((float)m_data.duration * 60.f) * (60 - m_countdown_frame);
ImVec2 lineEnd = ImVec2(win_pos_x - invisible_length, win_pos_y + win_size_y - 5);
ImVec2 lineStart = ImVec2(win_pos_x - win_size_x, win_pos_y + win_size_y - 5);
ImGui::GetWindowDrawList()->AddLine(lineStart, lineEnd, IM_COL32((int)(orange_color.x * 255), (int)(orange_color.y * 255), (int)(orange_color.z * 255), (int)(orange_color.picture_width * 255.f * (m_fading_out ? m_current_fade_opacity : 1.f))), 2.f);
if (!m_paused)
m_countdown_frame++;
*/
}
#endif // !ENABLE_NEW_NOTIFICATIONS_FADE_OUT
void NotificationManager::PopNotification::render_left_sign(ImGuiWrapper& imgui)
{
if (m_data.level == NotificationLevel::ErrorNotification || m_data.level == NotificationLevel::WarningNotification) {
@ -750,7 +564,6 @@ bool NotificationManager::PopNotification::compare_text(const std::string& text)
return false;
}
#if ENABLE_NEW_NOTIFICATIONS_FADE_OUT
void NotificationManager::PopNotification::update_state()
{
if (!m_initialized)
@ -817,7 +630,6 @@ void NotificationManager::PopNotification::update_state()
}
}
}
#endif // ENABLE_NEW_NOTIFICATIONS_FADE_OUT
NotificationManager::SlicingCompleteLargeNotification::SlicingCompleteLargeNotification(const NotificationData& n, NotificationIDProvider& id_provider, wxEvtHandler* evt_handler, bool large) :
NotificationManager::PopNotification(n, id_provider, evt_handler)
@ -1210,11 +1022,6 @@ bool NotificationManager::push_notification_data(const NotificationData& notific
}
bool NotificationManager::push_notification_data(std::unique_ptr<NotificationManager::PopNotification> notification, int timestamp)
{
/*
#if ENABLE_NEW_NOTIFICATIONS_FADE_OUT
m_requires_update = true;
#endif // ENABLE_NEW_NOTIFICATIONS_FADE_OUT
*/
// if timestamped notif, push only new one
if (timestamp != 0) {
if (m_used_timestamps.find(timestamp) == m_used_timestamps.end()) {
@ -1236,10 +1043,9 @@ bool NotificationManager::push_notification_data(std::unique_ptr<NotificationMan
return true;
}
}
#if ENABLE_NEW_NOTIFICATIONS_FADE_OUT
void NotificationManager::render_notifications(float overlay_width)
{
sort_notifications();
GLCanvas3D& canvas = *wxGetApp().plater()->get_current_canvas3D();
@ -1255,71 +1061,6 @@ void NotificationManager::render_notifications(float overlay_width)
}
update_notifications();
}
#else
void NotificationManager::render_notifications(float overlay_width)
{
float last_x = 0.0f;
float current_height = 0.0f;
bool request_next_frame = false;
bool render_main = false;
bool hovered = false;
sort_notifications();
GLCanvas3D& canvas = *wxGetApp().plater()->get_current_canvas3D();
// iterate thru notifications and render them / erase them
for (auto it = m_pop_notifications.begin(); it != m_pop_notifications.end();) {
if ((*it)->is_finished()) {
it = m_pop_notifications.erase(it);
} else {
(*it)->set_paused(m_hovered);
PopNotification::RenderResult res = (*it)->render(canvas, last_x, m_move_from_overlay && !m_in_preview, overlay_width);
if (res != PopNotification::RenderResult::Finished) {
last_x = (*it)->get_top() + GAP_WIDTH;
current_height = std::max(current_height, (*it)->get_current_top());
render_main = true;
}
if (res == PopNotification::RenderResult::Countdown || res == PopNotification::RenderResult::ClosePending || res == PopNotification::RenderResult::Finished)
request_next_frame = true;
if (res == PopNotification::RenderResult::Hovered)
hovered = true;
++it;
}
}
m_hovered = hovered;
//actualizate timers and request frame if needed
wxWindow* p = dynamic_cast<wxWindow*> (wxGetApp().plater());
while (p->GetParent())
p = p->GetParent();
wxTopLevelWindow* top_level_wnd = dynamic_cast<wxTopLevelWindow*>(p);
if (!top_level_wnd->IsActive())
return;
{
// Control the fade-out.
// time in seconds
long now = wxGetLocalTime();
// Pausing fade-out when the mouse is over some notification.
if (!m_hovered && m_last_time < now)
{
if (now - m_last_time == 1)
{
for (auto &notification : m_pop_notifications)
{
notification->substract_remaining_time();
}
}
m_last_time = now;
}
}
if (request_next_frame)
//FIXME this is very expensive for fade-out control.
// If any of the notifications is fading out, 100% of the CPU/GPU is consumed.
canvas.request_extra_frame();
}
#endif // ENABLE_NEW_NOTIFICATIONS_FADE_OUT
void NotificationManager::sort_notifications()
{
@ -1371,7 +1112,6 @@ void NotificationManager::set_in_preview(bool preview)
}
}
#if ENABLE_NEW_NOTIFICATIONS_FADE_OUT
void NotificationManager::update_notifications()
{
// no update if not top window
@ -1468,7 +1208,6 @@ void NotificationManager::update_notifications()
}
*/
}
#endif // ENABLE_NEW_NOTIFICATIONS_FADE_OUT
bool NotificationManager::has_slicing_error_notification()
{