From 07dd4c3672799ac6795d2b249099d8194a73384b Mon Sep 17 00:00:00 2001 From: "liz.li" Date: Thu, 22 Sep 2022 20:17:13 +0800 Subject: [PATCH] FIX:mousewheel bug in preview slider Change-Id: I9366a9c36250519259c132380e0a69697b6ee18c --- src/slic3r/GUI/ImGuiWrapper.cpp | 36 ++++++++++++++++----------------- 1 file changed, 18 insertions(+), 18 deletions(-) diff --git a/src/slic3r/GUI/ImGuiWrapper.cpp b/src/slic3r/GUI/ImGuiWrapper.cpp index 9d7ec1014..e78dfcbab 100644 --- a/src/slic3r/GUI/ImGuiWrapper.cpp +++ b/src/slic3r/GUI/ImGuiWrapper.cpp @@ -118,6 +118,7 @@ int ImGuiWrapper::TOOLBAR_WINDOW_FLAGS = ImGuiWindowFlags_AlwaysAutoResize | ImGuiWindowFlags_NoCollapse | ImGuiWindowFlags_NoTitleBar; +static float accer = 1.f; bool get_data_from_svg(const std::string &filename, unsigned int max_size_px, ThumbnailData &thumbnail_data) { @@ -195,21 +196,7 @@ bool slider_behavior(ImGuiID id, const ImRect& region, const ImS32 v_min, const if (axis == ImGuiAxis_Y) mouse_wheel_responsive_region = ImRect(region.Min - ImVec2(0, handle_sz.y), region.Max + ImVec2(0, handle_sz.y)); if (ImGui::ItemHoverable(mouse_wheel_responsive_region, id)) { -#ifdef __APPLE__ - if (io.KeyShift) - v_new = ImClamp(*out_value - 5 * (ImS32) (context.IO.MouseWheel), v_min, v_max); - else if (io.KeyCtrl) - v_new = ImClamp(*out_value + 5 * (ImS32) (context.IO.MouseWheel), v_min, v_max); - else { - v_new = ImClamp(*out_value + (ImS32) (context.IO.MouseWheel), v_min, v_max); - } -#else - if (io.KeyCtrl || io.KeyShift) - v_new = ImClamp(*out_value + 5 * (ImS32) (context.IO.MouseWheel), v_min, v_max); - else { - v_new = ImClamp(*out_value + (ImS32) (context.IO.MouseWheel), v_min, v_max); - } -#endif + v_new = ImClamp(*out_value + (ImS32)(context.IO.MouseWheel * accer), v_min, v_max); } // drag behavior if (context.ActiveId == id) @@ -416,9 +403,9 @@ bool ImGuiWrapper::update_mouse_data(wxMouseEvent& evt) io.MouseDown[1] = evt.RightIsDown(); io.MouseDown[2] = evt.MiddleIsDown(); float wheel_delta = static_cast(evt.GetWheelDelta()); - if (wheel_delta != 0.0f) - io.MouseWheel = static_cast(evt.GetWheelRotation()) / wheel_delta; - + if (wheel_delta != 0.0f) { + io.MouseWheel = evt.GetWheelRotation() > 0 ? 1.f : -1.f; + } unsigned buttons = (evt.LeftIsDown() ? 1 : 0) | (evt.RightIsDown() ? 2 : 0) | (evt.MiddleIsDown() ? 4 : 0); m_mouse_buttons = buttons; @@ -435,6 +422,19 @@ bool ImGuiWrapper::update_key_data(wxKeyEvent &evt) ImGuiIO& io = ImGui::GetIO(); + if (evt.CmdDown()) { + accer = 5.f; + } + else if (evt.ShiftDown()) { +#ifdef __APPLE__ + accer = -5.f; +#else + accer = 5.f; +#endif + } + else + accer = 1.f; + if (evt.GetEventType() == wxEVT_CHAR) { // Char event const auto key = evt.GetUnicodeKey();