diff --git a/src/slic3r/GUI/GLCanvas3D.cpp b/src/slic3r/GUI/GLCanvas3D.cpp index eba723e0d7..e815c5bb92 100644 --- a/src/slic3r/GUI/GLCanvas3D.cpp +++ b/src/slic3r/GUI/GLCanvas3D.cpp @@ -3921,6 +3921,19 @@ void GLCanvas3D::bind_event_handlers() render(); evt.Skip(); }); + // ORCA If the mouse capture is lost while a button is held (Alt+Tab, dialog, lock screen), the button-up + // never arrives and ImGui keeps the widget active. Cancel the interaction: clear the active widget + // before releasing the buttons so the release is not taken as a click. + m_canvas->Bind(wxEVT_MOUSE_CAPTURE_LOST, [this](wxMouseCaptureLostEvent&) { + if (GImGui != nullptr) { + ImGui::ClearActiveID(); + ImGuiIO& io = ImGui::GetIO(); + for (bool& down : io.MouseDown) + down = false; + } + m_navigator_dragging = false; + render(); + }); m_event_handlers_bound = true; m_canvas->Bind(wxEVT_GESTURE_PAN, &GLCanvas3D::on_gesture, this); diff --git a/src/slic3r/GUI/Gizmos/GLGizmoCut.cpp b/src/slic3r/GUI/Gizmos/GLGizmoCut.cpp index 9f14152e2e..a8dfc71a69 100644 --- a/src/slic3r/GUI/Gizmos/GLGizmoCut.cpp +++ b/src/slic3r/GUI/Gizmos/GLGizmoCut.cpp @@ -2762,11 +2762,16 @@ void GLGizmoCut3D::render_groove_int_input(const std::string& label, int& in_val ImGui::AlignTextToFramePadding(); ImGui::SameLine(m_label_width); ImGui::PushItemWidth(m_control_width); - if (ImGui::InputInt("##int_input", &in_val, 1, 5)) { - in_val = std::clamp(in_val, min_val, max_val); - - is_changed = true; + int val = in_val; + if (ImGui::InputInt("##int_input", &val, 1, 5)) { + val = std::clamp(val, min_val, max_val); + // ORCA Holding +/- at the limit clamps back to the same value, don't rebuild for that. + if (val != in_val) { + in_val = val; + is_changed = true; + } } + m_imgui->request_frames_while_held(); // ORCA auto-repeat of the +/- buttons ImGui::SameLine(); m_imgui->disabled_begin(in_val == init_val); diff --git a/src/slic3r/GUI/Gizmos/GLGizmoEmboss.cpp b/src/slic3r/GUI/Gizmos/GLGizmoEmboss.cpp index a3f680da59..93ae2ffd47 100644 --- a/src/slic3r/GUI/Gizmos/GLGizmoEmboss.cpp +++ b/src/slic3r/GUI/Gizmos/GLGizmoEmboss.cpp @@ -2642,12 +2642,14 @@ bool GLGizmoEmboss::rev_input(const std::string &name, T &value, const T *defaul const std::string &undo_tooltip, T step, T step_fast, const char *format, ImGuiInputTextFlags flags) const { // draw offseted input - auto draw_offseted_input = [&offset = m_gui_cfg->input_offset, &width = m_gui_cfg->input_width, + auto draw_offseted_input = [this, &offset = m_gui_cfg->input_offset, &width = m_gui_cfg->input_width, &name, &value, &step, &step_fast, format, flags](){ ImGui::SameLine(offset); ImGui::SetNextItemWidth(width); - return imgui_input(("##" + name).c_str(), + bool changed = imgui_input(("##" + name).c_str(), &value, step, step_fast, format, flags); + m_imgui->request_frames_while_held(); // ORCA auto-repeat of the +/- buttons + return changed; }; return revertible(name, value, default_value, undo_tooltip, 0.0f, draw_offseted_input); diff --git a/src/slic3r/GUI/Gizmos/GLGizmoSVG.cpp b/src/slic3r/GUI/Gizmos/GLGizmoSVG.cpp index 1dd9fdc18d..10312b2c98 100644 --- a/src/slic3r/GUI/Gizmos/GLGizmoSVG.cpp +++ b/src/slic3r/GUI/Gizmos/GLGizmoSVG.cpp @@ -1689,7 +1689,9 @@ void GLGizmoSVG::draw_depth() result_scale = 1. / (*m_scale_depth); } - if (ImGui::InputDouble("##depth", &input, step, step_fast, size_format)) { + const bool input_changed = ImGui::InputDouble("##depth", &input, step, step_fast, size_format); + m_imgui->request_frames_while_held(); // ORCA auto-repeat of the +/- buttons + if (input_changed) { if (result_scale.has_value()) input *= (*result_scale); apply(input, limits.depth); diff --git a/src/slic3r/GUI/Gizmos/GLGizmoTextureDisplacement.cpp b/src/slic3r/GUI/Gizmos/GLGizmoTextureDisplacement.cpp index adc9982a80..8ff45ae905 100644 --- a/src/slic3r/GUI/Gizmos/GLGizmoTextureDisplacement.cpp +++ b/src/slic3r/GUI/Gizmos/GLGizmoTextureDisplacement.cpp @@ -4056,10 +4056,11 @@ void GLGizmoTextureDisplacement::ensure_panel_icons() // Seconds on a real clock, for the tooltips' own timing. // -// Not ImGui::GetTime(): nothing in OrcaSlicer ever sets io.DeltaTime, so it keeps imgui's default of -// 1/60 per frame and its clock counts frames rather than seconds. On a canvas that renders only when -// something asks it to, that is not a clock at all - an animation driven by it crawled while the canvas -// was idle and raced while a moving mouse was rendering it flat out. +// Not ImGui::GetTime(): ImGuiWrapper::new_frame() feeds io.DeltaTime the real frame time but caps it +// at 1/60 s, so the idle gaps of the event-driven canvas don't count as time a +/- button is held. +// That cap also means ImGui's clock stalls while the canvas is idle - a pointer resting still on a +// control renders nothing, so the tooltip delay would never run out on ImGui's clock. A real clock +// keeps the tooltip timing and media playback independent of how often the canvas renders. static double tip_now() { using clock = std::chrono::steady_clock; diff --git a/src/slic3r/GUI/ImGuiWrapper.cpp b/src/slic3r/GUI/ImGuiWrapper.cpp index 432bd80cae..a2a2848e85 100644 --- a/src/slic3r/GUI/ImGuiWrapper.cpp +++ b/src/slic3r/GUI/ImGuiWrapper.cpp @@ -13,6 +13,7 @@ #include #include #include +#include #include "libslic3r/Point.hpp" #include #include @@ -588,6 +589,16 @@ void ImGuiWrapper::new_frame() ImGuiIO& io = ImGui::GetIO(); + // ORCA ImGui times button and key repeat with io.DeltaTime. At its default of 1/60 s per frame the clock + // counts frames, so a held +/- button repeats as fast as the canvas renders. Feed it the real frame time, + // capped at 1/60 s so the idle gaps of the event-driven canvas don't count as time held. + const auto now = std::chrono::steady_clock::now(); + if (m_last_frame_time != std::chrono::steady_clock::time_point{}) { + const float dt = std::chrono::duration(now - m_last_frame_time).count(); + io.DeltaTime = std::clamp(dt, 1e-4f, 1.f / 60.f); // ImGui asserts a positive DeltaTime + } + m_last_frame_time = now; + ImGui::NewFrame(); m_new_frame_open = true; diff --git a/src/slic3r/GUI/ImGuiWrapper.hpp b/src/slic3r/GUI/ImGuiWrapper.hpp index e4b8dabd77..14f382eda1 100644 --- a/src/slic3r/GUI/ImGuiWrapper.hpp +++ b/src/slic3r/GUI/ImGuiWrapper.hpp @@ -9,6 +9,7 @@ #include #include #include +#include #include @@ -68,6 +69,8 @@ class ImGuiWrapper unsigned m_mouse_buttons{ 0 }; bool m_disabled{ false }; bool m_new_frame_open{ false }; + // ORCA Start of the previous frame, see new_frame(). + std::chrono::steady_clock::time_point m_last_frame_time{}; #if ENABLE_ENHANCED_IMGUI_SLIDER_FLOAT bool m_requires_extra_frame{ false }; #endif // ENABLE_ENHANCED_IMGUI_SLIDER_FLOAT @@ -361,6 +364,13 @@ public: bool requires_extra_frame() const { return m_requires_extra_frame; } void set_requires_extra_frame() { m_requires_extra_frame = true; } void reset_requires_extra_frame() { m_requires_extra_frame = false; } + // ORCA Call right after a widget with +/- buttons. ImGui repeats a held button only on new frames and the + // canvas renders on events only, so keep frames coming while the widget is held. + void request_frames_while_held() + { + if (ImGui::IsItemActive() && ImGui::IsMouseDown(ImGuiMouseButton_Left)) + set_requires_extra_frame(); + } void disable_background_fadeout_animation();