notifications: avoid collision with gizmos on same position by moving to left

This commit is contained in:
David Kocik 2020-10-02 10:26:11 +02:00
parent ec6599da98
commit 092a9f80b6
5 changed files with 50 additions and 10 deletions

View file

@ -215,6 +215,8 @@ void GLCanvas3D::LayersEditing::set_enabled(bool enabled)
m_enabled = is_allowed() && enabled;
}
float GLCanvas3D::LayersEditing::s_overelay_window_width;
void GLCanvas3D::LayersEditing::render_overlay(const GLCanvas3D& canvas) const
{
if (!m_enabled)
@ -297,6 +299,7 @@ void GLCanvas3D::LayersEditing::render_overlay(const GLCanvas3D& canvas) const
if (imgui.button(_L("Reset")))
wxPostEvent((wxEvtHandler*)canvas.get_wxglcanvas(), SimpleEvent(EVT_GLCANVAS_RESET_LAYER_HEIGHT_PROFILE));
GLCanvas3D::LayersEditing::s_overelay_window_width = ImGui::GetWindowSize().x /*+ (float)m_layers_texture.width/4*/;
imgui.end();
const Rect& bar_rect = get_bar_rect_viewport(canvas);
@ -1426,6 +1429,16 @@ void GLCanvas3D::Tooltip::render(const Vec2d& mouse_position, GLCanvas3D& canvas
}
#if ENABLE_SLOPE_RENDERING
float GLCanvas3D::Slope::s_window_width;
void GLCanvas3D::Slope::show_dialog(bool show) {
if (show && is_used())
return; use(show);
m_dialog_shown = show;
wxGetApp().plater()->get_notification_manager()->set_move_from_slope(show);
}
void GLCanvas3D::Slope::render() const
{
if (m_dialog_shown) {
@ -1482,6 +1495,8 @@ void GLCanvas3D::Slope::render() const
if (ImGui::GetWindowContentRegionWidth() + 2.0f * ImGui::GetStyle().WindowPadding.x != ImGui::CalcWindowExpectedSize(ImGui::GetCurrentWindow()).x)
m_canvas.request_extra_frame();
s_window_width = ImGui::GetWindowSize().x;
imgui.end();
if (modified)
@ -2151,7 +2166,7 @@ void GLCanvas3D::render()
wxGetApp().plater()->get_mouse3d_controller().render_settings_dialog(*this);
wxGetApp().plater()->get_notification_manager()->render_notifications(*this);
wxGetApp().plater()->get_notification_manager()->render_notifications(*this, get_overelay_window_width(), get_slope_window_width());
wxGetApp().imgui()->render();

View file

@ -186,6 +186,8 @@ private:
mutable float m_adaptive_quality;
mutable HeightProfileSmoothingParams m_smooth_params;
static float s_overelay_window_width;
class LayersTexture
{
@ -241,6 +243,7 @@ private:
static bool bar_rect_contains(const GLCanvas3D& canvas, float x, float y);
static Rect get_bar_rect_screen(const GLCanvas3D& canvas);
static Rect get_bar_rect_viewport(const GLCanvas3D& canvas);
static float get_overelay_window_width() { return LayersEditing::s_overelay_window_width; }
float object_max_z() const { return m_object_max_z; }
@ -254,6 +257,7 @@ private:
void update_slicing_parameters();
static float thickness_bar_width(const GLCanvas3D &canvas);
};
struct Mouse
@ -425,7 +429,7 @@ private:
bool m_dialog_shown{ false };
GLCanvas3D& m_canvas;
GLVolumeCollection& m_volumes;
static float s_window_width;
public:
Slope(GLCanvas3D& canvas, GLVolumeCollection& volumes) : m_canvas(canvas), m_volumes(volumes) {}
@ -433,12 +437,13 @@ private:
bool is_enabled() const { return m_enabled; }
void use(bool use) { m_volumes.set_slope_active(m_enabled ? use : false); }
bool is_used() const { return m_volumes.is_slope_active(); }
void show_dialog(bool show) { if (show && is_used()) return; use(show); m_dialog_shown = show; }
void show_dialog(bool show);
bool is_dialog_shown() const { return m_dialog_shown; }
void render() const;
void set_range(const std::array<float, 2>& range) const {
m_volumes.set_slope_z_range({ -::cos(Geometry::deg2rad(90.0f - range[0])), -::cos(Geometry::deg2rad(90.0f - range[1])) });
}
static float get_window_width() { return s_window_width; };
};
#endif // ENABLE_SLOPE_RENDERING
@ -772,6 +777,8 @@ public:
void set_slope_range(const std::array<float, 2>& range) { m_slope.set_range(range); }
#endif // ENABLE_SLOPE_RENDERING
private:
bool _is_shown_on_screen() const;
@ -892,6 +899,15 @@ private:
bool _activate_search_toolbar_item();
bool _deactivate_collapse_toolbar_items();
float get_overelay_window_width() { return LayersEditing::get_overelay_window_width(); }
float get_slope_window_width() {
#if ENABLE_SLOPE_RENDERING
return Slope::get_window_width();
#else
return 0.0f;
#endif
}
static std::vector<float> _parse_colors(const std::vector<std::string>& colors);
public:

View file

@ -54,7 +54,7 @@ NotificationManager::PopNotification::PopNotification(const NotificationData &n,
NotificationManager::PopNotification::~PopNotification()
{
}
NotificationManager::PopNotification::RenderResult NotificationManager::PopNotification::render(GLCanvas3D& canvas, const float& initial_y)
NotificationManager::PopNotification::RenderResult NotificationManager::PopNotification::render(GLCanvas3D& canvas, const float& initial_y, bool move_from_overlay, float overlay_width, bool move_from_slope, float slope_width)
{
if (!m_initialized) {
init();
@ -76,6 +76,7 @@ NotificationManager::PopNotification::RenderResult NotificationManager::PopNotif
bool shown = true;
std::string name;
ImVec2 mouse_pos = ImGui::GetMousePos();
float right_gap = SPACE_RIGHT_PANEL + (move_from_overlay ? overlay_width + m_line_height * 5 : (move_from_slope ? slope_width /*+ m_line_height * 0.3f*/ : 0));
if (m_line_height != ImGui::CalcTextSize("A").y)
init();
@ -85,10 +86,11 @@ NotificationManager::PopNotification::RenderResult NotificationManager::PopNotif
//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() - SPACE_RIGHT_PANEL, 1.0f * (float)cnv_size.get_height() - m_top_y);
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)
{
@ -820,7 +822,7 @@ bool NotificationManager::push_notification_data(NotificationManager::PopNotific
return false;
}
}
void NotificationManager::render_notifications(GLCanvas3D& canvas)
void NotificationManager::render_notifications(GLCanvas3D& canvas, float overlay_width, float slope_width)
{
float last_x = 0.0f;
float current_height = 0.0f;
@ -835,7 +837,7 @@ void NotificationManager::render_notifications(GLCanvas3D& canvas)
it = m_pop_notifications.erase(it);
} else {
(*it)->set_paused(m_hovered);
PopNotification::RenderResult res = (*it)->render(canvas, last_x);
PopNotification::RenderResult res = (*it)->render(canvas, last_x, m_move_from_overlay, overlay_width, m_move_from_slope, slope_width);
if (res != PopNotification::RenderResult::Finished) {
last_x = (*it)->get_top() + GAP_WIDTH;
current_height = std::max(current_height, (*it)->get_current_top());

View file

@ -76,7 +76,7 @@ public:
};
PopNotification(const NotificationData &n, const int id, wxEvtHandler* evt_handler);
virtual ~PopNotification();
RenderResult render(GLCanvas3D& canvas, const float& initial_y);
RenderResult render(GLCanvas3D& canvas, const float& initial_y, bool move_from_overlay, float overlay_width, bool move_from_slope, float slope_width);
// close will dissapear notification on next render
void close() { m_close_pending = true; }
// data from newer notification of same type
@ -229,11 +229,15 @@ public:
void set_slicing_complete_print_time(std::string info);
void set_slicing_complete_large(bool large);
// renders notifications in queue and deletes expired ones
void render_notifications(GLCanvas3D& canvas);
void render_notifications(GLCanvas3D& canvas, float overlay_width, float slope_width);
// finds and closes all notifications of given type
void close_notification_of_type(const NotificationType type);
void dpi_changed();
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; }
// or slope visualization gizmo
void set_move_from_slope (bool move) { m_move_from_slope = move; }
private:
//pushes notification into the queue of notifications that are rendered
//can be used to create custom notification
@ -252,6 +256,8 @@ private:
//timestamps used for slining finished - notification could be gone so it needs to be stored here
std::unordered_set<int> m_used_timestamps;
bool m_in_preview { false };
bool m_move_from_overlay { false };
bool m_move_from_slope{ false };
//prepared (basic) notifications
const std::vector<NotificationData> basic_notifications = {

View file

@ -3625,6 +3625,7 @@ void Plater::priv::on_action_split_volumes(SimpleEvent&)
void Plater::priv::on_action_layersediting(SimpleEvent&)
{
view3D->enable_layers_editing(!view3D->is_layers_editing_enabled());
notification_manager->set_move_from_overlay(view3D->is_layers_editing_enabled());
}
void Plater::priv::on_object_select(SimpleEvent& evt)