diff --git a/src/slic3r/GUI/Gizmos/GLGizmoEmboss.cpp b/src/slic3r/GUI/Gizmos/GLGizmoEmboss.cpp index c49f57ce11..6e5738560e 100644 --- a/src/slic3r/GUI/Gizmos/GLGizmoEmboss.cpp +++ b/src/slic3r/GUI/Gizmos/GLGizmoEmboss.cpp @@ -1879,21 +1879,38 @@ bool GLGizmoEmboss::bold_button() { return false; } +template bool exist_change(const T &value, const T *default_value){ + if (default_value == nullptr) return false; + return (value != *default_value); +} + +template<> bool exist_change(const std::optional &value, const std::optional *default_value){ + if (default_value == nullptr) return false; + return !is_approx(value, *default_value); +} + +template<> bool exist_change(const float &value, const float *default_value){ + if (default_value == nullptr) return false; + return !is_approx(value, *default_value); +} + template bool GLGizmoEmboss::revertible(const std::string &name, T &value, T *default_value, - bool exist_change, const std::string &undo_tooltip, float undo_offset, Draw draw) { - if (exist_change) + bool changed = exist_change(value, default_value); + if (changed) ImGuiWrapper::text_colored(ImGuiWrapper::COL_ORANGE_LIGHT, name); else ImGuiWrapper::text(name); + + bool result = draw(); // render revert changes button - if (exist_change) { + if (changed) { ImGui::SameLine(undo_offset); if (draw_button(IconType::undo)) { value = *default_value; @@ -1901,7 +1918,7 @@ bool GLGizmoEmboss::revertible(const std::string &name, } else if (ImGui::IsItemHovered()) ImGui::SetTooltip("%s", undo_tooltip.c_str()); } - return draw(); + return result; } @@ -1924,8 +1941,7 @@ bool GLGizmoEmboss::rev_input(const std::string &name, &value, step, step_fast, format, flags); }; float undo_offset = ImGui::GetStyle().FramePadding.x; - bool exist_change = default_value != nullptr ? (!is_approx(value, *default_value)) : false; - return revertible(name, value, default_value, exist_change, undo_tooltip, undo_offset, draw_offseted_input); + return revertible(name, value, default_value, undo_tooltip, undo_offset, draw_offseted_input); } bool GLGizmoEmboss::rev_checkbox(const std::string &name, @@ -1939,10 +1955,7 @@ bool GLGizmoEmboss::rev_checkbox(const std::string &name, return ImGui::Checkbox(("##" + name).c_str(), &value); }; float undo_offset = ImGui::GetStyle().FramePadding.x; - bool exist_change = default_value != nullptr ? - (value != *default_value) : - false; - return revertible(name, value, default_value, exist_change, undo_tooltip, + return revertible(name, value, default_value, undo_tooltip, undo_offset, draw_offseted_input); } @@ -2086,9 +2099,8 @@ bool GLGizmoEmboss::rev_slider(const std::string &name, return m_imgui->slider_optional_int( ("##" + name).c_str(), value, v_min, v_max, format.c_str(), 1.f, false, tooltip); }; - float undo_offset = ImGui::GetStyle().FramePadding.x; - bool exist_change = default_value != nullptr ? (value != *default_value) : false; - return revertible(name, value, default_value, exist_change, + float undo_offset = ImGui::GetStyle().FramePadding.x; + return revertible(name, value, default_value, undo_tooltip, undo_offset, draw_slider_optional_int); } @@ -2109,10 +2121,8 @@ bool GLGizmoEmboss::rev_slider(const std::string &name, return m_imgui->slider_optional_float(("##" + name).c_str(), value, v_min, v_max, format.c_str(), 1.f, false, tooltip); }; - float undo_offset = ImGui::GetStyle().FramePadding.x; - bool exist_change = (default_value != nullptr)? - (!is_approx(value, *default_value)) : false; - return revertible(name, value, default_value, exist_change, + float undo_offset = ImGui::GetStyle().FramePadding.x; + return revertible(name, value, default_value, undo_tooltip, undo_offset, draw_slider_optional_float); } @@ -2133,10 +2143,8 @@ bool GLGizmoEmboss::rev_slider(const std::string &name, return m_imgui->slider_float("##" + name, &value, v_min, v_max, format.c_str(), 1.f, false, tooltip); }; - float undo_offset = ImGui::GetStyle().FramePadding.x; - bool exist_change = default_value != nullptr ? - (!is_approx(value, *default_value)) : false; - return revertible(name, value, default_value, exist_change, + float undo_offset = ImGui::GetStyle().FramePadding.x; + return revertible(name, value, default_value, undo_tooltip, undo_offset, draw_slider_float); } diff --git a/src/slic3r/GUI/Gizmos/GLGizmoEmboss.hpp b/src/slic3r/GUI/Gizmos/GLGizmoEmboss.hpp index 85516d6c4a..952d6c5bf1 100644 --- a/src/slic3r/GUI/Gizmos/GLGizmoEmboss.hpp +++ b/src/slic3r/GUI/Gizmos/GLGizmoEmboss.hpp @@ -132,7 +132,7 @@ private: bool rev_slider(const std::string &name, float &value, float *default_value, const std::string &undo_tooltip, float v_min, float v_max, const std::string &format, const wxString &tooltip); template - bool revertible(const std::string &name, T &value, T *default_value, bool exist_change, const std::string &undo_tooltip, float undo_offset, Draw draw); + bool revertible(const std::string &name, T &value, T *default_value, const std::string &undo_tooltip, float undo_offset, Draw draw); void set_minimal_window_size(bool is_advance_edit_style); const ImVec2 &get_minimal_window_size() const; diff --git a/src/slic3r/GUI/Selection.cpp b/src/slic3r/GUI/Selection.cpp index f2f6a7018b..7a54f84f7c 100644 --- a/src/slic3r/GUI/Selection.cpp +++ b/src/slic3r/GUI/Selection.cpp @@ -773,7 +773,9 @@ void Selection::translate(const Vec3d& displacement, TransformationType transfor if (!m_valid) return; - assert(transformation_type.relative()); + // Emboss use translate in local coordinate + assert(transformation_type.relative() || + transformation_type.local()); for (unsigned int i : m_list) { GLVolume& v = *(*m_volumes)[i];