From f5eb2899e7252ea3ff0f8a79ef8d55c6009ebb28 Mon Sep 17 00:00:00 2001 From: "zhou.xu" Date: Wed, 12 Jun 2024 09:26:47 +0800 Subject: [PATCH] NEW:add tip button for move,rotate,scale jira: STUDIO-7273 Change-Id: I44aeecd8aaa17ec49ac1d8ff2bee5c3729c52061 (cherry picked from commit 998f33b4ce588f59cef345e327a97f6f669f6089) --- src/slic3r/GUI/GLCanvas3D.cpp | 13 +- .../GUI/Gizmos/GizmoObjectManipulation.cpp | 131 +++++++++++++++++- .../GUI/Gizmos/GizmoObjectManipulation.hpp | 8 +- 3 files changed, 146 insertions(+), 6 deletions(-) diff --git a/src/slic3r/GUI/GLCanvas3D.cpp b/src/slic3r/GUI/GLCanvas3D.cpp index f33b8889d..a65af0cfd 100644 --- a/src/slic3r/GUI/GLCanvas3D.cpp +++ b/src/slic3r/GUI/GLCanvas3D.cpp @@ -4200,11 +4200,22 @@ void GLCanvas3D::on_mouse(wxMouseEvent& evt) int volume_idx = get_first_hover_volume_idx(); bool already_selected = m_selection.contains_volume(volume_idx); bool ctrl_down = evt.CmdDown(); - + bool alt_down = evt.AltDown(); Selection::IndicesList curr_idxs = m_selection.get_volume_idxs(); if (already_selected && ctrl_down) m_selection.remove(volume_idx); + else if (alt_down) { + Selection::EMode mode = Selection::Volume; + if (already_selected) { + std::vector volume_idxs; + for (auto idx : curr_idxs) { volume_idxs.emplace_back(idx); } + m_selection.remove_volumes(mode, volume_idxs); + } + std::vector add_volume_idxs; + add_volume_idxs.emplace_back(volume_idx); + m_selection.add_volumes(mode, add_volume_idxs, true); + } else { m_selection.add(volume_idx, !ctrl_down, true); m_mouse.drag.move_requires_threshold = !already_selected; diff --git a/src/slic3r/GUI/Gizmos/GizmoObjectManipulation.cpp b/src/slic3r/GUI/Gizmos/GizmoObjectManipulation.cpp index 484caa0b9..c2b01f05d 100644 --- a/src/slic3r/GUI/Gizmos/GizmoObjectManipulation.cpp +++ b/src/slic3r/GUI/Gizmos/GizmoObjectManipulation.cpp @@ -54,6 +54,24 @@ GizmoObjectManipulation::GizmoObjectManipulation(GLCanvas3D& glcanvas) { m_imperial_units = wxGetApp().app_config->get("use_inches") == "1"; m_new_unit_string = m_imperial_units ? L("in") : L("mm"); + + const wxString shift = "Shift+"; + const wxString alt = GUI::shortkey_alt_prefix(); + const wxString ctrl = GUI::shortkey_ctrl_prefix(); + m_desc_move["part_selection_caption"] = alt + _L("Left mouse button"); + m_desc_move["part_selection"] = _L("Part selection"); + m_desc_move["snap_step_caption"] = shift + _L("Left mouse button"); + m_desc_move["snap_step"] = _L("Fixed step drag"); + + m_desc_rotate["part_selection_caption"] = alt + _L("Left mouse button"); + m_desc_rotate["part_selection"] = _L("Part selection"); + + m_desc_scale["part_selection_caption"] = alt + _L("Left mouse button"); + m_desc_scale["part_selection"] = _L("Part selection"); + m_desc_scale["snap_step_caption"] = shift + _L("Left mouse button"); + m_desc_scale["snap_step"] = _L("Fixed step drag"); + m_desc_scale["single_sided_caption"] = ctrl + _L("Left mouse button"); + m_desc_scale["single_sided"] = _L("Single sided scaling"); } void GizmoObjectManipulation::UpdateAndShow(const bool show) @@ -559,7 +577,91 @@ bool GizmoObjectManipulation::reset_button(ImGuiWrapper *imgui_wrapper, float ca if (b_value) { ImGui::PopStyleColor(3); } return result; - } +} + +void GizmoObjectManipulation::show_move_tooltip_information(ImGuiWrapper *imgui_wrapper, float caption_max, float x, float y) +{ + ImTextureID normal_id = m_glcanvas.get_gizmos_manager().get_icon_texture_id(GLGizmosManager::MENU_ICON_NAME::IC_TOOLBAR_TOOLTIP); + ImTextureID hover_id = m_glcanvas.get_gizmos_manager().get_icon_texture_id(GLGizmosManager::MENU_ICON_NAME::IC_TOOLBAR_TOOLTIP_HOVER); + + caption_max += imgui_wrapper->calc_text_size(": ").x + 35.f; + + float font_size = ImGui::GetFontSize(); + ImVec2 button_size = ImVec2(font_size * 1.8, font_size * 1.3); + ImGui::PushStyleVar(ImGuiStyleVar_FrameBorderSize, 0.0f); + ImGui::PushStyleVar(ImGuiStyleVar_FramePadding, {0, ImGui::GetStyle().FramePadding.y}); + ImGui::ImageButton3(normal_id, hover_id, button_size); + + if (ImGui::IsItemHovered()) { + ImGui::BeginTooltip2(ImVec2(x, y)); + auto draw_text_with_caption = [this, &imgui_wrapper,& caption_max](const wxString &caption, const wxString &text) { + imgui_wrapper->text_colored(ImGuiWrapper::COL_ACTIVE, caption); + ImGui::SameLine(caption_max); + imgui_wrapper->text_colored(ImGuiWrapper::COL_WINDOW_BG, text); + }; + + for (const auto &t : std::array{"part_selection", "snap_step"}) + draw_text_with_caption(m_desc_move.at(t + "_caption") + ": ", m_desc_move.at(t)); + ImGui::EndTooltip(); + } + ImGui::PopStyleVar(2); +} + +void GizmoObjectManipulation::show_rotate_tooltip_information(ImGuiWrapper *imgui_wrapper, float caption_max, float x, float y) +{ + ImTextureID normal_id = m_glcanvas.get_gizmos_manager().get_icon_texture_id(GLGizmosManager::MENU_ICON_NAME::IC_TOOLBAR_TOOLTIP); + ImTextureID hover_id = m_glcanvas.get_gizmos_manager().get_icon_texture_id(GLGizmosManager::MENU_ICON_NAME::IC_TOOLBAR_TOOLTIP_HOVER); + + caption_max += imgui_wrapper->calc_text_size(": ").x + 35.f; + + float font_size = ImGui::GetFontSize(); + ImVec2 button_size = ImVec2(font_size * 1.8, font_size * 1.3); + ImGui::PushStyleVar(ImGuiStyleVar_FrameBorderSize, 0.0f); + ImGui::PushStyleVar(ImGuiStyleVar_FramePadding, {0, ImGui::GetStyle().FramePadding.y}); + ImGui::ImageButton3(normal_id, hover_id, button_size); + + if (ImGui::IsItemHovered()) { + ImGui::BeginTooltip2(ImVec2(x, y)); + auto draw_text_with_caption = [this, &imgui_wrapper, &caption_max](const wxString &caption, const wxString &text) { + imgui_wrapper->text_colored(ImGuiWrapper::COL_ACTIVE, caption); + ImGui::SameLine(caption_max); + imgui_wrapper->text_colored(ImGuiWrapper::COL_WINDOW_BG, text); + }; + + for (const auto &t : std::array{"part_selection"}) + draw_text_with_caption(m_desc_rotate.at(t + "_caption") + ": ", m_desc_rotate.at(t)); + ImGui::EndTooltip(); + } + ImGui::PopStyleVar(2); +} + +void GizmoObjectManipulation::show_scale_tooltip_information(ImGuiWrapper *imgui_wrapper, float caption_max, float x, float y) +{ + ImTextureID normal_id = m_glcanvas.get_gizmos_manager().get_icon_texture_id(GLGizmosManager::MENU_ICON_NAME::IC_TOOLBAR_TOOLTIP); + ImTextureID hover_id = m_glcanvas.get_gizmos_manager().get_icon_texture_id(GLGizmosManager::MENU_ICON_NAME::IC_TOOLBAR_TOOLTIP_HOVER); + + caption_max += imgui_wrapper->calc_text_size(": ").x + 35.f; + + float font_size = ImGui::GetFontSize(); + ImVec2 button_size = ImVec2(font_size * 1.8, font_size * 1.3); + ImGui::PushStyleVar(ImGuiStyleVar_FrameBorderSize, 0.0f); + ImGui::PushStyleVar(ImGuiStyleVar_FramePadding, {0, ImGui::GetStyle().FramePadding.y}); + ImGui::ImageButton3(normal_id, hover_id, button_size); + + if (ImGui::IsItemHovered()) { + ImGui::BeginTooltip2(ImVec2(x, y)); + auto draw_text_with_caption = [this, &imgui_wrapper, &caption_max](const wxString &caption, const wxString &text) { + imgui_wrapper->text_colored(ImGuiWrapper::COL_ACTIVE, caption); + ImGui::SameLine(caption_max); + imgui_wrapper->text_colored(ImGuiWrapper::COL_WINDOW_BG, text); + }; + + for (const auto &t : std::array{"part_selection", "snap_step", "single_sided"}) + draw_text_with_caption(m_desc_scale.at(t + "_caption") + ": ", m_desc_scale.at(t)); + ImGui::EndTooltip(); + } + ImGui::PopStyleVar(2); +} void GizmoObjectManipulation::do_render_move_window(ImGuiWrapper *imgui_wrapper, std::string window_name, float x, float y, float bottom_limit) { @@ -685,7 +787,14 @@ bool GizmoObjectManipulation::reset_button(ImGuiWrapper *imgui_wrapper, float ca } } if (!focued_on_text) m_glcanvas.handle_sidebar_focus_event("", false); - + float get_cur_y = ImGui::GetContentRegionMax().y + ImGui::GetFrameHeight() + y; + float tip_caption_max = 0.f; + float total_text_max = 0.f; + for (const auto &t : std::array{"part_selection", "snap_step"}) { + tip_caption_max = std::max(tip_caption_max, imgui_wrapper->calc_text_size(m_desc_move[t + "_caption"]).x); + total_text_max = std::max(total_text_max, imgui_wrapper->calc_text_size(m_desc_move[t]).x); + } + show_move_tooltip_information(imgui_wrapper, tip_caption_max, x, get_cur_y); m_last_active_item = current_active_id; last_move_input_window_width = ImGui::GetWindowWidth(); imgui_wrapper->end(); @@ -802,7 +911,14 @@ void GizmoObjectManipulation::do_render_rotate_window(ImGuiWrapper *imgui_wrappe } } if (!focued_on_text) m_glcanvas.handle_sidebar_focus_event("", false); - + float get_cur_y = ImGui::GetContentRegionMax().y + ImGui::GetFrameHeight() + y; + float tip_caption_max = 0.f; + float total_text_max = 0.f; + for (const auto &t : std::array{"part_selection"}) { + tip_caption_max = std::max(tip_caption_max, imgui_wrapper->calc_text_size(m_desc_move[t + "_caption"]).x); + total_text_max = std::max(total_text_max, imgui_wrapper->calc_text_size(m_desc_move[t]).x); + } + show_rotate_tooltip_information(imgui_wrapper, tip_caption_max, x, get_cur_y); m_last_active_item = current_active_id; last_rotate_input_window_width = ImGui::GetWindowWidth(); imgui_wrapper->end(); @@ -1004,7 +1120,14 @@ void GizmoObjectManipulation::do_render_scale_input_window(ImGuiWrapper* imgui_w } if (!focued_on_text) m_glcanvas.handle_sidebar_focus_event("", false); - + float get_cur_y = ImGui::GetContentRegionMax().y + ImGui::GetFrameHeight() + y; + float tip_caption_max = 0.f; + float total_text_max = 0.f; + for (const auto &t : std::array{"part_selection", "snap_step", "single_sided"}) { + tip_caption_max = std::max(tip_caption_max, imgui_wrapper->calc_text_size(m_desc_scale[t + "_caption"]).x); + total_text_max = std::max(total_text_max, imgui_wrapper->calc_text_size(m_desc_scale[t]).x); + } + show_scale_tooltip_information(imgui_wrapper, tip_caption_max, x, get_cur_y); m_last_active_item = current_active_id; last_scale_input_window_width = ImGui::GetWindowWidth(); diff --git a/src/slic3r/GUI/Gizmos/GizmoObjectManipulation.hpp b/src/slic3r/GUI/Gizmos/GizmoObjectManipulation.hpp index f809b6c19..41148542f 100644 --- a/src/slic3r/GUI/Gizmos/GizmoObjectManipulation.hpp +++ b/src/slic3r/GUI/Gizmos/GizmoObjectManipulation.hpp @@ -126,6 +126,9 @@ public: bool reset_button(ImGuiWrapper *imgui_wrapper, float caption_max, float unit_size, float space_size, float end_text_size); bool bbl_checkbox(const wxString &label, bool &value); + void show_move_tooltip_information(ImGuiWrapper *imgui_wrapper, float caption_max, float x, float y); + void show_rotate_tooltip_information(ImGuiWrapper *imgui_wrapper, float caption_max, float x, float y); + void show_scale_tooltip_information(ImGuiWrapper *imgui_wrapper, float caption_max, float x, float y); private: void reset_settings_value(); void update_settings_value(const Selection& selection); @@ -136,7 +139,7 @@ private: //Show or hide mirror buttons //void update_mirror_buttons_visibility(); - // change values + // change values void change_position_value(int axis, double value); void change_rotation_value(int axis, double value); void change_scale_value(int axis, double value); @@ -148,6 +151,9 @@ private: GLCanvas3D& m_glcanvas; unsigned int m_last_active_item { 0 }; + std::map m_desc_move; + std::map m_desc_rotate; + std::map m_desc_scale; }; }}