From c17c4d2e9a19a2b3c2b3cbb3b5d02655057cf9ff Mon Sep 17 00:00:00 2001 From: enricoturri1966 Date: Tue, 8 Mar 2022 09:24:42 +0100 Subject: [PATCH] Follow-up of 005fef7bf68e2e589e8ecb3de80a43aa37043ce3 - Fixed imgui dialogs associated to gizmo bar and toolbar items --- src/slic3r/GUI/GLCanvas3D.cpp | 17 ++++-- src/slic3r/GUI/GLToolbar.cpp | 63 ++++++++++++++++------- src/slic3r/GUI/GLToolbar.hpp | 5 ++ src/slic3r/GUI/Gizmos/GLGizmosManager.cpp | 10 ++-- 4 files changed, 66 insertions(+), 29 deletions(-) diff --git a/src/slic3r/GUI/GLCanvas3D.cpp b/src/slic3r/GUI/GLCanvas3D.cpp index 5cf8c0619..a056dc1bd 100644 --- a/src/slic3r/GUI/GLCanvas3D.cpp +++ b/src/slic3r/GUI/GLCanvas3D.cpp @@ -4199,8 +4199,12 @@ bool GLCanvas3D::_render_undo_redo_stack(const bool is_undo, float pos_x) ImGuiWrapper* imgui = wxGetApp().imgui(); +#if ENABLE_GLBEGIN_GLEND_SHADERS_ATTRIBUTES + imgui->set_next_window_pos(pos_x, m_undoredo_toolbar.get_height(), ImGuiCond_Always, 0.5f, 0.0f); +#else const float x = pos_x * (float)wxGetApp().plater()->get_camera().get_zoom() + 0.5f * (float)get_canvas_size().get_width(); imgui->set_next_window_pos(x, m_undoredo_toolbar.get_height(), ImGuiCond_Always, 0.5f, 0.0f); +#endif // ENABLE_GLBEGIN_GLEND_SHADERS_ATTRIBUTES std::string title = is_undo ? L("Undo History") : L("Redo History"); imgui->begin(_(title), ImGuiWindowFlags_NoMove | ImGuiWindowFlags_NoResize | ImGuiWindowFlags_NoCollapse); @@ -4239,8 +4243,12 @@ bool GLCanvas3D::_render_search_list(float pos_x) bool action_taken = false; ImGuiWrapper* imgui = wxGetApp().imgui(); +#if ENABLE_GLBEGIN_GLEND_SHADERS_ATTRIBUTES + imgui->set_next_window_pos(pos_x, m_main_toolbar.get_height(), ImGuiCond_Always, 0.5f, 0.0f); +#else const float x = /*pos_x * (float)wxGetApp().plater()->get_camera().get_zoom() + */0.5f * (float)get_canvas_size().get_width(); imgui->set_next_window_pos(x, m_main_toolbar.get_height(), ImGuiCond_Always, 0.5f, 0.0f); +#endif // ENABLE_GLBEGIN_GLEND_SHADERS_ATTRIBUTES std::string title = L("Search"); imgui->begin(_(title), ImGuiWindowFlags_NoMove | ImGuiWindowFlags_NoResize | ImGuiWindowFlags_NoCollapse); @@ -4293,9 +4301,13 @@ bool GLCanvas3D::_render_arrange_menu(float pos_x) { ImGuiWrapper *imgui = wxGetApp().imgui(); +#if ENABLE_GLBEGIN_GLEND_SHADERS_ATTRIBUTES + imgui->set_next_window_pos(pos_x, m_main_toolbar.get_height(), ImGuiCond_Always, 0.5f, 0.0f); +#else auto canvas_w = float(get_canvas_size().get_width()); const float x = pos_x * float(wxGetApp().plater()->get_camera().get_zoom()) + 0.5f * canvas_w; imgui->set_next_window_pos(x, m_main_toolbar.get_height(), ImGuiCond_Always, 0.5f, 0.0f); +#endif // ENABLE_GLBEGIN_GLEND_SHADERS_ATTRIBUTES imgui->begin(_L("Arrange options"), ImGuiWindowFlags_NoMove | ImGuiWindowFlags_AlwaysAutoResize | ImGuiWindowFlags_NoCollapse); @@ -4827,9 +4839,7 @@ bool GLCanvas3D::_init_main_toolbar() item.right.toggable = true; item.right.render_callback = [this](float left, float right, float, float) { if (m_canvas != nullptr) - { _render_arrange_menu(0.5f * (left + right)); - } }; if (!m_main_toolbar.add_item(item)) return false; @@ -4932,8 +4942,7 @@ bool GLCanvas3D::_init_main_toolbar() item.sprite_id = 11; item.left.toggable = true; item.left.render_callback = [this](float left, float right, float, float) { - if (m_canvas != nullptr) - { + if (m_canvas != nullptr) { if (_render_search_list(0.5f * (left + right))) _deactivate_search_toolbar_item(); } diff --git a/src/slic3r/GUI/GLToolbar.cpp b/src/slic3r/GUI/GLToolbar.cpp index d35c0e060..7b8029e5c 100644 --- a/src/slic3r/GUI/GLToolbar.cpp +++ b/src/slic3r/GUI/GLToolbar.cpp @@ -85,26 +85,29 @@ bool GLToolbarItem::update_enabled_state() return ret; } +#if ENABLE_GLBEGIN_GLEND_SHADERS_ATTRIBUTES +void GLToolbarItem::render(const GLCanvas3D& parent, unsigned int tex_id, float left, float right, float bottom, float top, unsigned int tex_width, unsigned int tex_height, unsigned int icon_size) const +#else void GLToolbarItem::render(unsigned int tex_id, float left, float right, float bottom, float top, unsigned int tex_width, unsigned int tex_height, unsigned int icon_size) const +#endif // ENABLE_GLBEGIN_GLEND_SHADERS_ATTRIBUTES { - auto uvs = [this](unsigned int tex_width, unsigned int tex_height, unsigned int icon_size) -> GLTexture::Quad_UVs - { - assert((tex_width != 0) && (tex_height != 0)); + auto uvs = [this](unsigned int tex_width, unsigned int tex_height, unsigned int icon_size) -> GLTexture::Quad_UVs { + assert(tex_width != 0 && tex_height != 0); GLTexture::Quad_UVs ret; // tiles in the texture are spaced by 1 pixel - float icon_size_px = (float)(tex_width - 1) / ((float)Num_States + (float)Num_Rendered_Highlight_States); - char render_state = (m_highlight_state == NotHighlighted ? m_state : Num_States + m_highlight_state); - float inv_tex_width = 1.0f / (float)tex_width; - float inv_tex_height = 1.0f / (float)tex_height; + const float icon_size_px = (float)(tex_width - 1) / ((float)Num_States + (float)Num_Rendered_Highlight_States); + const char render_state = (m_highlight_state == NotHighlighted ? m_state : Num_States + m_highlight_state); + const float inv_tex_width = 1.0f / (float)tex_width; + const float inv_tex_height = 1.0f / (float)tex_height; // tiles in the texture are spaced by 1 pixel - float u_offset = 1.0f * inv_tex_width; - float v_offset = 1.0f * inv_tex_height; - float du = icon_size_px * inv_tex_width; - float dv = icon_size_px * inv_tex_height; - float left = u_offset + (float)render_state * du; - float right = left + du - u_offset; - float top = v_offset + (float)m_data.sprite_id * dv; - float bottom = top + dv - v_offset; + const float u_offset = 1.0f * inv_tex_width; + const float v_offset = 1.0f * inv_tex_height; + const float du = icon_size_px * inv_tex_width; + const float dv = icon_size_px * inv_tex_height; + const float left = u_offset + (float)render_state * du; + const float right = left + du - u_offset; + const float top = v_offset + (float)m_data.sprite_id * dv; + const float bottom = top + dv - v_offset; ret.left_top = { left, top }; ret.left_bottom = { left, bottom }; ret.right_bottom = { right, bottom }; @@ -114,12 +117,26 @@ void GLToolbarItem::render(unsigned int tex_id, float left, float right, float b GLTexture::render_sub_texture(tex_id, left, right, bottom, top, uvs(tex_width, tex_height, icon_size)); - if (is_pressed()) - { - if ((m_last_action_type == Left) && m_data.left.can_render()) + if (is_pressed()) { +#if ENABLE_GLBEGIN_GLEND_SHADERS_ATTRIBUTES + const Size cnv_size = parent.get_canvas_size(); + const float cnv_w = (float)cnv_size.get_width(); + const float cnv_h = (float)cnv_size.get_height(); + + const float out_left = (0.5f * left + 0.5f) * cnv_w; + const float out_right = (0.5f * right + 0.5f) * cnv_w; + const float out_top = (0.5f * top + 0.5f) * cnv_h; + const float out_bottom = (0.5f * bottom + 0.5f) * cnv_h; + if (m_last_action_type == Left && m_data.left.can_render()) + m_data.left.render_callback(out_left, out_right, out_bottom, out_top); + else if (m_last_action_type == Right && m_data.right.can_render()) + m_data.right.render_callback(out_left, out_right, out_bottom, out_top); +#else + if (m_last_action_type == Left && m_data.left.can_render()) m_data.left.render_callback(left, right, bottom, top); - else if ((m_last_action_type == Right) && m_data.right.can_render()) + else if (m_last_action_type == Right && m_data.right.can_render()) m_data.right.render_callback(left, right, bottom, top); +#endif // ENABLE_GLBEGIN_GLEND_SHADERS_ATTRIBUTES } } @@ -1756,7 +1773,11 @@ void GLToolbar::render_horizontal(const GLCanvas3D& parent) if (item->is_separator()) left += separator_stride; else { +#if ENABLE_GLBEGIN_GLEND_SHADERS_ATTRIBUTES + item->render(parent, tex_id, left, left + icons_size_x, top - icons_size_y, top, (unsigned int)tex_width, (unsigned int)tex_height, (unsigned int)(m_layout.icons_size * m_layout.scale)); +#else item->render(tex_id, left, left + icons_size_x, top - icons_size_y, top, (unsigned int)tex_width, (unsigned int)tex_height, (unsigned int)(m_layout.icons_size * m_layout.scale)); +#endif // ENABLE_GLBEGIN_GLEND_SHADERS_ATTRIBUTES left += icon_stride; } } @@ -1811,7 +1832,11 @@ void GLToolbar::render_vertical(const GLCanvas3D& parent) if (item->is_separator()) top -= separator_stride; else { +#if ENABLE_GLBEGIN_GLEND_SHADERS_ATTRIBUTES + item->render(parent, tex_id, left, left + icons_size_x, top - icons_size_y, top, (unsigned int)tex_width, (unsigned int)tex_height, (unsigned int)(m_layout.icons_size * m_layout.scale)); +#else item->render(tex_id, left, left + icons_size_x, top - icons_size_y, top, (unsigned int)tex_width, (unsigned int)tex_height, (unsigned int)(m_layout.icons_size * m_layout.scale)); +#endif // ENABLE_GLBEGIN_GLEND_SHADERS_ATTRIBUTES top -= icon_stride; } } diff --git a/src/slic3r/GUI/GLToolbar.hpp b/src/slic3r/GUI/GLToolbar.hpp index aa0a5b1d9..ae958bce0 100644 --- a/src/slic3r/GUI/GLToolbar.hpp +++ b/src/slic3r/GUI/GLToolbar.hpp @@ -153,7 +153,12 @@ public: // returns true if the state changes bool update_enabled_state(); +#if ENABLE_GLBEGIN_GLEND_SHADERS_ATTRIBUTES + void render(const GLCanvas3D& parent, unsigned int tex_id, float left, float right, float bottom, float top, unsigned int tex_width, unsigned int tex_height, unsigned int icon_size) const; +#else void render(unsigned int tex_id, float left, float right, float bottom, float top, unsigned int tex_width, unsigned int tex_height, unsigned int icon_size) const; +#endif // ENABLE_GLBEGIN_GLEND_SHADERS_ATTRIBUTES + private: void set_visible(bool visible) { m_data.visible = visible; } diff --git a/src/slic3r/GUI/Gizmos/GLGizmosManager.cpp b/src/slic3r/GUI/Gizmos/GLGizmosManager.cpp index 6991c5356..0a2d5b285 100644 --- a/src/slic3r/GUI/Gizmos/GLGizmosManager.cpp +++ b/src/slic3r/GUI/Gizmos/GLGizmosManager.cpp @@ -802,7 +802,7 @@ void GLGizmosManager::render_arrow(const GLCanvas3D& parent, EType highlighted_t const float inv_cnv_h = 1.0f / cnv_h; const float top_x = -1.0f; - float top_y = 0.5f * 2.0f * get_scaled_total_height() * inv_cnv_h; + float top_y = get_scaled_total_height() * inv_cnv_h; const float icons_size_x = 2.0f * m_layout.scaled_icons_size() * inv_cnv_w; const float icons_size_y = 2.0f * m_layout.scaled_icons_size() * inv_cnv_h; @@ -936,15 +936,13 @@ void GLGizmosManager::do_render_overlay() const if (idx == m_current || current_y == FLT_MAX) { // The FLT_MAX trick is here so that even non-selectable but activable // gizmos are passed some meaningful value. - current_y = 0.5f * cnv_h - top_y; + current_y = 0.5f * cnv_h - 0.5f * top_y * cnv_h; } top_y -= stride_y; } - if (m_current != Undefined) { - const float toolbar_top = cnv_h - wxGetApp().plater()->get_view_toolbar().get_height(); - m_gizmos[m_current]->render_input_window(width, current_y, toolbar_top); - } + if (m_current != Undefined) + m_gizmos[m_current]->render_input_window(get_scaled_total_width(), current_y, cnv_h - wxGetApp().plater()->get_view_toolbar().get_height()); } #else void GLGizmosManager::do_render_overlay() const