From 6b3a6a40b12a97308fbc348b2ec9ffd1a62ab0c9 Mon Sep 17 00:00:00 2001 From: "zhou.xu" Date: Thu, 31 Oct 2024 16:33:59 +0800 Subject: [PATCH] NEW:add "fit camera" button jira: none Change-Id: I97d4dd3d79ec8550e73ed21928133be4b4a8c92b (cherry picked from commit 99736e4ccc89f3f6af922ef2936e5e3e06a1bedf) --- resources/images/fit_camera.svg | 15 ++++++ resources/images/fit_camera_hover.svg | 19 ++++++++ src/slic3r/GUI/GLCanvas3D.cpp | 57 +++++++++++++++++++++++ src/slic3r/GUI/GLCanvas3D.hpp | 3 ++ src/slic3r/GUI/Gizmos/GLGizmosManager.cpp | 9 ++++ src/slic3r/GUI/Gizmos/GLGizmosManager.hpp | 2 + 6 files changed, 105 insertions(+) create mode 100644 resources/images/fit_camera.svg create mode 100644 resources/images/fit_camera_hover.svg diff --git a/resources/images/fit_camera.svg b/resources/images/fit_camera.svg new file mode 100644 index 000000000..bac816fbf --- /dev/null +++ b/resources/images/fit_camera.svg @@ -0,0 +1,15 @@ + + + + + + + + + + + + + + + diff --git a/resources/images/fit_camera_hover.svg b/resources/images/fit_camera_hover.svg new file mode 100644 index 000000000..3968dcf54 --- /dev/null +++ b/resources/images/fit_camera_hover.svg @@ -0,0 +1,19 @@ + + + + + + + + + + + + + + + + + + + diff --git a/src/slic3r/GUI/GLCanvas3D.cpp b/src/slic3r/GUI/GLCanvas3D.cpp index c3c10bef0..033c29370 100644 --- a/src/slic3r/GUI/GLCanvas3D.cpp +++ b/src/slic3r/GUI/GLCanvas3D.cpp @@ -5890,6 +5890,8 @@ void GLCanvas3D::_render_3d_navigator() } const float size = 128 * sc; + m_fit_camrea_button_pos[0] = size - 10; + m_sc = sc; const bool dirty = ImGuizmo::ViewManipulate(cameraView, cameraProjection, ImGuizmo::OPERATION::ROTATE, ImGuizmo::MODE::WORLD, identityMatrix, camDistance, ImVec2(viewManipulateLeft, viewManipulateTop - size), ImVec2(size, size), 0x00101010); @@ -7646,6 +7648,7 @@ void GLCanvas3D::_render_overlays() } m_labels.render(sorted_instances); _render_3d_navigator(); + _render_fit_camera_toolbar(); glsafe(::glPopMatrix()); } @@ -8314,6 +8317,60 @@ void GLCanvas3D::_render_return_toolbar() imgui.end(); } +void GLCanvas3D::_render_fit_camera_toolbar() +{ + float font_size = ImGui::GetFontSize(); + ImVec2 button_icon_size = ImVec2(font_size * 2.5, font_size * 2.5); + + ImGuiWrapper &imgui = *wxGetApp().imgui(); + float window_width = button_icon_size.x + imgui.scaled(2.0f); + float window_height = button_icon_size.y + imgui.scaled(2.0f); + + Size cnv_size = get_canvas_size(); + m_fit_camrea_button_pos[1] = cnv_size.get_height() - button_icon_size[1] - 20 * m_sc; + imgui.set_next_window_pos(m_fit_camrea_button_pos[0], m_fit_camrea_button_pos[1], ImGuiCond_Always, 0, 0); +#ifdef __WINDOWS__ + imgui.set_next_window_size(window_width, window_height, ImGuiCond_Always); +#endif + + imgui.begin(_L("Fit camera"), ImGuiWindowFlags_NoResize | ImGuiWindowFlags_NoBackground | ImGuiWindowFlags_NoScrollbar | ImGuiWindowFlags_NoMove | + ImGuiWindowFlags_NoTitleBar | ImGuiWindowFlags_NoCollapse);// + + ImTextureID normal_id = m_gizmos.get_icon_texture_id(GLGizmosManager::MENU_ICON_NAME::IC_FIT_CAMERA); + if (normal_id == 0) { + m_gizmos.init_icon_textures(); + } + normal_id = m_gizmos.get_icon_texture_id(GLGizmosManager::MENU_ICON_NAME::IC_FIT_CAMERA); + ImTextureID hover_id = m_gizmos.get_icon_texture_id(GLGizmosManager::MENU_ICON_NAME::IC_FIT_CAMERA_HOVER); // IC_FIT_CAMERA_HOVER + + ImGui::PushStyleVar(ImGuiStyleVar_FrameBorderSize, 0.0f); + ImGui::PushStyleVar(ImGuiStyleVar_FramePadding, {0, 0}); + + if (ImGui::ImageButton3(normal_id, hover_id, button_icon_size, ImVec2(0, 0), ImVec2(1, 1), -1, + ImVec4(0, 0, 0, 0), ImVec4(1, 1, 1, 1), ImVec2(10, 0))) { + select_view("plate"); + if (m_selection.is_empty()) { + if (m_canvas_type == ECanvasType::CanvasAssembleView) { + zoom_to_volumes(); + } + else { + zoom_to_bed(); + } + } + else { + zoom_to_selection(); + } + } + if (ImGui::IsItemHovered()) { + auto temp_tooltip = _L("Fit camera to scene or selected object."); + auto width = ImGui::CalcTextSize(temp_tooltip.c_str()).x + imgui.scaled(2.0f); + imgui.tooltip(temp_tooltip, width); + } + ImGui::PopStyleVar(2); + + imgui.end(); +} + void GLCanvas3D::_render_separator_toolbar_right() const { if (!m_separator_toolbar.is_enabled()) diff --git a/src/slic3r/GUI/GLCanvas3D.hpp b/src/slic3r/GUI/GLCanvas3D.hpp index 85f993974..d06275119 100644 --- a/src/slic3r/GUI/GLCanvas3D.hpp +++ b/src/slic3r/GUI/GLCanvas3D.hpp @@ -531,6 +531,8 @@ private: mutable IMToolbar m_sel_plate_toolbar; mutable GLToolbar m_assemble_view_toolbar; mutable IMReturnToolbar m_return_toolbar; + mutable Vec2i m_fit_camrea_button_pos = {128, 5}; + mutable float m_sc{1}; mutable float m_paint_toolbar_width; //BBS: add canvas type for assemble view usage @@ -1171,6 +1173,7 @@ private: void _render_imgui_select_plate_toolbar(); void _render_assemble_view_toolbar() const; void _render_return_toolbar(); + void _render_fit_camera_toolbar(); void _render_separator_toolbar_right() const; void _render_separator_toolbar_left() const; void _render_collapse_toolbar() const; diff --git a/src/slic3r/GUI/Gizmos/GLGizmosManager.cpp b/src/slic3r/GUI/Gizmos/GLGizmosManager.cpp index f0893df85..70692f592 100644 --- a/src/slic3r/GUI/Gizmos/GLGizmosManager.cpp +++ b/src/slic3r/GUI/Gizmos/GLGizmosManager.cpp @@ -288,6 +288,15 @@ bool GLGizmosManager::init_icon_textures() else return false; + if (IMTexture::load_from_svg_file(Slic3r::resources_dir() + "/images/fit_camera.svg", 32, 32, texture_id)) + icon_list.insert(std::make_pair((int) IC_FIT_CAMERA, texture_id)); + else + return false; + + if (IMTexture::load_from_svg_file(Slic3r::resources_dir() + "/images/fit_camera_hover.svg", 32, 32, texture_id)) + icon_list.insert(std::make_pair((int) IC_FIT_CAMERA_HOVER, texture_id)); + else + return false; if (IMTexture::load_from_svg_file(Slic3r::resources_dir() + "/images/text_B.svg", 20, 20, texture_id)) icon_list.insert(std::make_pair((int)IC_TEXT_B, texture_id)); diff --git a/src/slic3r/GUI/Gizmos/GLGizmosManager.hpp b/src/slic3r/GUI/Gizmos/GLGizmosManager.hpp index 57646797c..022fd048e 100644 --- a/src/slic3r/GUI/Gizmos/GLGizmosManager.hpp +++ b/src/slic3r/GUI/Gizmos/GLGizmosManager.hpp @@ -172,6 +172,8 @@ public: IC_TEXT_T, IC_TEXT_T_DARK, IC_NAME_COUNT, + IC_FIT_CAMERA, + IC_FIT_CAMERA_HOVER, }; explicit GLGizmosManager(GLCanvas3D& parent);