From 1c79e3174c32e6ef09ad3552568ea39724094b56 Mon Sep 17 00:00:00 2001 From: Peter Montgomery Date: Sun, 27 Dec 2020 17:43:52 +0000 Subject: [PATCH] Pcbnew: Prevent footprint jumping when starting to drag it CHANGED: When dragging a footprint, if the mouse isn't directly over the footprint anchor when 'D' is pressed, the footprint center will jump to the mouse position when dragging begins. This MR uses the current mouse position instead of the footprint anchor as the inital reference point when starting to drag. Fixes https://gitlab.com/kicad/code/kicad/issues/6813 --- pcbnew/router/router_tool.cpp | 20 +++++++++++++++++++- 1 file changed, 19 insertions(+), 1 deletion(-) diff --git a/pcbnew/router/router_tool.cpp b/pcbnew/router/router_tool.cpp index 06c2d8b054..0c37cdfd3c 100644 --- a/pcbnew/router/router_tool.cpp +++ b/pcbnew/router/router_tool.cpp @@ -1518,7 +1518,25 @@ int ROUTER_TOOL::InlineDrag( const TOOL_EVENT& aEvent ) } else if( footprint ) { - p = footprint->GetPosition(); + // The mouse is going to be moved on grid before dragging begins. + VECTOR2I tweakedMousePos; + PCB_BASE_EDIT_FRAME* editFrame = getEditFrame(); + + // Check if user wants to warp the mouse to origin of moved object + + if( editFrame->GetMoveWarpsCursor() ) + tweakedMousePos = footprint->GetPosition(); // Use footprint anchor to warp mouse + else + tweakedMousePos = controls()->GetCursorPosition(); // Just use current mouse pos + + // We tweak the mouse position using the value from above, and then use that as the + // start position to prevent the footprint from jumping when we start dragging. + // First we move the visual crosshair cursor... + controls()->ForceCursorPosition( true, tweakedMousePos ); + controls()->SetCursorPosition( tweakedMousePos ); // ...then the mouse pointer + + // Now that the mouse is in the right position, get a copy of the position to use later + p = controls()->GetCursorPosition(); } int dragMode = aEvent.Parameter ();