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

@ -80,14 +80,6 @@
#define ENABLE_CUSTOMIZABLE_FILES_ASSOCIATION_ON_WIN (1 && ENABLE_2_3_0_BETA1)
//===================
// 2.3.0.beta2 techs
//===================
#define ENABLE_2_3_0_BETA2 1
#define ENABLE_NEW_NOTIFICATIONS_FADE_OUT (1 && ENABLE_2_3_0_BETA2)
//===================
// 2.3.0.beta3 techs
//===================

View File

@ -2447,13 +2447,7 @@ void GLCanvas3D::on_idle(wxIdleEvent& evt)
{
if (!m_initialized)
return;
#if ENABLE_NEW_NOTIFICATIONS_FADE_OUT
/*NotificationManager* notification_mgr = wxGetApp().plater()->get_notification_manager();
if (notification_mgr->requires_update())
notification_mgr->update_notifications();
m_dirty |= notification_mgr->requires_render();*/
#endif // ENABLE_NEW_NOTIFICATIONS_FADE_OUT
// FIXME
m_dirty |= m_main_toolbar.update_items_state();
m_dirty |= m_undoredo_toolbar.update_items_state();
@ -2462,13 +2456,6 @@ void GLCanvas3D::on_idle(wxIdleEvent& evt)
bool mouse3d_controller_applied = wxGetApp().plater()->get_mouse3d_controller().apply(wxGetApp().plater()->get_camera());
m_dirty |= mouse3d_controller_applied;
#if ENABLE_NEW_NOTIFICATIONS_FADE_OUT
/*
if (notification_mgr->requires_update()) {
evt.RequestMore();
}*/
#endif // ENABLE_NEW_NOTIFICATIONS_FADE_OUT
if (!m_dirty)
return;

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()
{

View File

@ -148,13 +148,7 @@ public:
void set_in_preview(bool preview);
// Move to left to avoid colision with variable layer height gizmo.
void set_move_from_overlay(bool move) { m_move_from_overlay = move; }
/*
#if ENABLE_NEW_NOTIFICATIONS_FADE_OUT
bool requires_update() const { return m_requires_update; }
bool requires_render() const { return m_requires_render; }
#endif // ENABLE_NEW_NOTIFICATIONS_FADE_OUT
*/
private:
// duration 0 means not disapearing
struct NotificationData {
@ -190,7 +184,6 @@ private:
{
public:
#if ENABLE_NEW_NOTIFICATIONS_FADE_OUT
enum class EState
{
Unknown,
@ -200,32 +193,16 @@ private:
ClosePending, // Requesting Render
Finished, // Requesting Render
};
#else
enum class RenderResult
{
Finished,
ClosePending,
Static,
Countdown,
Hovered
};
#endif // ENABLE_NEW_NOTIFICATIONS_FADE_OUT
PopNotification(const NotificationData &n, NotificationIDProvider &id_provider, wxEvtHandler* evt_handler);
virtual ~PopNotification() { if (m_id) m_id_provider.release_id(m_id); }
#if ENABLE_NEW_NOTIFICATIONS_FADE_OUT
void render(GLCanvas3D& canvas, float initial_y, bool move_from_overlay, float overlay_width);
#else
RenderResult render(GLCanvas3D& canvas, const float& initial_y, bool move_from_overlay, float overlay_width);
#endif // ENABLE_NEW_NOTIFICATIONS_FADE_OUT
// close will dissapear notification on next render
void close() { m_close_pending = true; }
// data from newer notification of same type
void update(const NotificationData& n);
bool is_finished() const { return m_finished || m_close_pending; }
#if ENABLE_NEW_NOTIFICATIONS_FADE_OUT
bool is_hovered() const { return m_hovered; }
#endif // ENABLE_NEW_NOTIFICATIONS_FADE_OUT
// returns top after movement
float get_top() const { return m_top_y; }
//returns top in actual frame
@ -239,7 +216,6 @@ private:
void set_paused(bool p) { m_paused = p; }
bool compare_text(const std::string& text);
void hide(bool h) { m_hidden = h; }
#if ENABLE_NEW_NOTIFICATIONS_FADE_OUT
// sets m_next_render with time of next mandatory rendering
void update_state();
int64_t next_render() const { return m_next_render; }
@ -248,7 +224,6 @@ private:
bool requires_update() const { return m_state != EState::Hidden; }
*/
EState get_state() const { return m_state; }
#endif // ENABLE_NEW_NOTIFICATIONS_FADE_OUT
protected:
// Call after every size change
void init();
@ -262,11 +237,6 @@ private:
virtual void render_close_button(ImGuiWrapper& imgui,
const float win_size_x, const float win_size_y,
const float win_pos_x , const float win_pos_y);
#if !ENABLE_NEW_NOTIFICATIONS_FADE_OUT
void render_countdown(ImGuiWrapper& imgui,
const float win_size_x, const float win_size_y,
const float win_pos_x , const float win_pos_y);
#endif // !ENABLE_NEW_NOTIFICATIONS_FADE_OUT
virtual void render_hypertext(ImGuiWrapper& imgui,
const float text_x, const float text_y,
const std::string text,
@ -284,9 +254,7 @@ private:
// For reusing ImGUI windows.
NotificationIDProvider &m_id_provider;
#if ENABLE_NEW_NOTIFICATIONS_FADE_OUT
EState m_state { EState::Unknown };
#endif // ENABLE_NEW_NOTIFICATIONS_FADE_OUT
int m_id { 0 };
bool m_initialized { false };
@ -303,7 +271,6 @@ private:
bool m_paused { false };
int m_countdown_frame { 0 };
bool m_fading_out { false };
#if ENABLE_NEW_NOTIFICATIONS_FADE_OUT
int64_t m_fading_start { 0LL };
// time of last done render when fading
int64_t m_last_render_fading { 0LL };
@ -311,20 +278,14 @@ private:
int64_t m_notification_start;
// time to next must-do render
int64_t m_next_render { std::numeric_limits<int64_t>::max() };
#else
// total time left when fading beggins
float m_fading_time{ 0.0f };
#endif // ENABLE_NEW_NOTIFICATIONS_FADE_OUT
float m_current_fade_opacity { 1.0f };
// If hidden the notif is alive but not visible to user
bool m_hidden { false };
// m_finished = true - does not render, marked to delete
bool m_finished { false };
// Will go to m_finished next render
bool m_close_pending { false };
#if ENABLE_NEW_NOTIFICATIONS_FADE_OUT
bool m_close_pending { false };
bool m_hovered { false };
#endif // ENABLE_NEW_NOTIFICATIONS_FADE_OUT
// variables to count positions correctly
// all space without text
float m_window_width_offset;
@ -438,11 +399,9 @@ private:
void sort_notifications();
// If there is some error notification active, then the "Export G-code" notification after the slicing is finished is suppressed.
bool has_slicing_error_notification();
#if ENABLE_NEW_NOTIFICATIONS_FADE_OUT
// perform update_state on each notification and ask for more frames if needed
void update_notifications();
#endif // ENABLE_NEW_NOTIFICATIONS_FADE_OUT
// Target for wxWidgets events sent by clicking on the hyperlink available at some notifications.
wxEvtHandler* m_evt_handler;
// Cache of IDs to identify and reuse ImGUI windows.
@ -458,12 +417,7 @@ private:
bool m_in_preview { false };
// True if the layer editing is enabled in Plater, so that the notifications are shifted left of it.
bool m_move_from_overlay { false };
/*
#if ENABLE_NEW_NOTIFICATIONS_FADE_OUT
bool m_requires_update{ false };
bool m_requires_render{ false };
#endif // ENABLE_NEW_NOTIFICATIONS_FADE_OUT
*/
//prepared (basic) notifications
const std::vector<NotificationData> basic_notifications = {
// {NotificationType::SlicingNotPossible, NotificationLevel::RegularNotification, 10, _u8L("Slicing is not possible.")},