Fix panning and rotating from the center of mass details box (#17137)

A drag that starts on the center of mass details box, off its close button, now turns or pans the view like a drag over empty space. Its release no longer opens the canvas context menu. A right click off the box now closes it, the same as a left click. A click inside the box always goes to ImGui, including the click that closes a context menu.

(cherry picked from commit 6d33e58347)
This commit is contained in:
TheLegendTubaGuy authored and Hanif Koh committed 2026-11-14 09:39:44 +08:00
1 parent 81b8b3eb81
commit 75d2de2078
3 files changed
+46 -3

No files matched your search

+3 -2
View File
@@ -164,12 +164,13 @@ The markers drawn last are kept, and a left click is tested against them before
center and a point a radius to its right are projected to the screen, and the click hits a marker
within that distance. The solid markers are tested before the faded ones and the smaller kinds
before the larger, the order in which they cover each other. A hit opens the details of that marker
and keeps the click from changing the selection; a click anywhere else, or Esc, closes them. The box is an
and keeps the click from changing the selection; a left or right click anywhere else, or Esc, closes them. The box is an
ImGui window beside the marker, redrawn with the overlay from the markers of the last scene, so it
follows a dragged object, and in Preview the layer slider. It closes when its marker is gone, or when
the number of markers of its kind changes, as then it may stand for something else. As it moves with
the view, zooming toward the cursor can bring it under the mouse, so the wheel zooms over it rather
than going to ImGui.
than going to ImGui. It also covers the model, so a drag that starts on it, off its close button,
turns or pans the view as one over empty space would.
Its title says what the marker stands for: the plate, an object, an assembly or a part, the body of
an assembly. The G-code export lists the object instances for the processor, marking assemblies, as
+39 -1
View File
@@ -1345,6 +1345,27 @@ bool GLCanvas3D::CenterOfMass::details_hovered() const
return m_picked && hovered != nullptr && hovered == ImGui::FindWindowByName(details_window);
}
bool GLCanvas3D::CenterOfMass::details_contain(const Vec2d& point) const
{
const ImGuiWindow* window = ImGui::FindWindowByName(details_window);
return m_picked && window != nullptr && window->Rect().Contains(ImVec2(float(point.x()), float(point.y())));
}
bool GLCanvas3D::CenterOfMass::details_pressed() const
{
if (!details_hovered())
return false;
const ImGuiContext& g = *ImGui::GetCurrentContext();
const ImGuiWindow* window = g.HoveredWindow;
// The close button is active after a press on it, the window's move id after a press elsewhere on the window.
if (g.ActiveIdWindow == window && g.ActiveId != window->MoveId)
return false;
for (int button = 0; button < IM_ARRAYSIZE(g.IO.MouseDown); ++button)
if (g.IO.MouseDown[button] && window->Rect().Contains(g.IO.MouseClickedPos[button]))
return true;
return false;
}
bool GLCanvas3D::CenterOfMass::hide_details(GLCanvas3D& canvas)
{
if (!m_picked)
@@ -4819,7 +4840,21 @@ void GLCanvas3D::on_mouse(wxMouseEvent& evt)
// that incorrectly suppresses the active drag's tooltip and can interrupt its processing. The active drag always takes priority.
const bool other_drag_active = m_gizmos.is_dragging() || m_mouse.dragging || m_rectangle_selection.is_dragging() || m_layers_editing.state == LayersEditing::Editing;
if (imgui->update_mouse_data(evt) && !other_drag_active) {
// A drag that starts on a marker's details moves the view, as over empty space. Checked on the first drag event only,
// while ImGui still hovers what was under the press. After that, m_mouse.dragging keeps the drag on the canvas.
const bool camera_drag = evt.Dragging() && !other_drag_active && m_center_of_mass.details_pressed();
if (camera_drag) {
// Else the object under the details keeps a left drag from turning the view.
m_hover_volume_idxs.clear();
// From the press, as the canvas does, which went to the ImGui branch below and left its position in m_mouse.position.
m_mouse.drag.start_position_2D = Point(m_mouse.position.x(), m_mouse.position.y());
// Its release is no right click on the canvas, also when the view has not turned yet, as that takes a second drag event.
m_mouse.ignore_right_up = true;
}
// A click that closes a context menu has no move before it, so ImGui may not yet hover the details.
const bool click_on_details = (evt.ButtonDown() || evt.ButtonUp()) && m_center_of_mass.details_contain(pos.cast<double>());
if ((imgui->update_mouse_data(evt) || click_on_details) && !other_drag_active && !camera_drag) {
if ((evt.LeftDown() || (evt.Moving() && (evt.AltDown() || evt.ShiftDown()))) && m_canvas != nullptr)
m_canvas->SetFocus();
m_mouse.position = evt.Leaving() ? Vec2d(-1.0, -1.0) : pos.cast<double>();
@@ -5015,6 +5050,9 @@ void GLCanvas3D::on_mouse(wxMouseEvent& evt)
m_mouse.ignore_left_up = true;
return;
}
// A right click off the details hides them, as a left one does.
if (evt.RightDown() && !mouse_in_layer_editing)
m_center_of_mass.hide_details(*this);
bool any_gizmo_active = m_gizmos.get_current() != nullptr;
+4
View File
@@ -544,6 +544,10 @@ class GLCanvas3D
void render_details(GLCanvas3D& canvas);
// Whether the mouse is over the details.
bool details_hovered() const;
// Whether the details cover a point, also when ImGui has not seen the mouse move there.
bool details_contain(const Vec2d& point) const;
// Whether a button held down was pressed on the details, off their close button.
bool details_pressed() const;
// Whether there were details to hide.
bool hide_details(GLCanvas3D& canvas);
};