Commit 1fa49ce7 authored by Maciej Suminski's avatar Maciej Suminski

Fixed drifting for items dragged using EDIT_TOOL.

parent 39bca76d
...@@ -81,13 +81,15 @@ int EDIT_TOOL::Main( TOOL_EVENT& aEvent ) ...@@ -81,13 +81,15 @@ int EDIT_TOOL::Main( TOOL_EVENT& aEvent )
if( !makeSelection( selection ) ) if( !makeSelection( selection ) )
return 0; return 0;
VECTOR2I dragPosition; // The last position of the cursor while dragging
m_dragging = false; // Are selected items being dragged? m_dragging = false; // Are selected items being dragged?
bool restore = false; // Should items' state be restored when finishing the tool? bool restore = false; // Should items' state be restored when finishing the tool?
// By default, modified items need to update their geometry // By default, modified items need to update their geometry
m_updateFlag = KIGFX::VIEW_ITEM::GEOMETRY; m_updateFlag = KIGFX::VIEW_ITEM::GEOMETRY;
// Offset from the dragged item's center (anchor)
wxPoint offset;
VIEW_CONTROLS* controls = getViewControls(); VIEW_CONTROLS* controls = getViewControls();
PCB_EDIT_FRAME* editFrame = static_cast<PCB_EDIT_FRAME*>( m_toolMgr->GetEditFrame() ); PCB_EDIT_FRAME* editFrame = static_cast<PCB_EDIT_FRAME*>( m_toolMgr->GetEditFrame() );
controls->ShowCursor( true ); controls->ShowCursor( true );
...@@ -128,29 +130,34 @@ int EDIT_TOOL::Main( TOOL_EVENT& aEvent ) ...@@ -128,29 +130,34 @@ int EDIT_TOOL::Main( TOOL_EVENT& aEvent )
else if( evt->IsMotion() || evt->IsDrag( BUT_LEFT ) ) else if( evt->IsMotion() || evt->IsDrag( BUT_LEFT ) )
{ {
VECTOR2I cursor( controls->GetCursorPosition() );
if( m_dragging ) if( m_dragging )
{ {
wxPoint movement = wxPoint( cursor.x, cursor.y ) -
static_cast<BOARD_ITEM*>( selection.items.GetPickedItem( 0 ) )->GetPosition();
// Drag items to the current cursor position // Drag items to the current cursor position
VECTOR2I movement = ( controls->GetCursorPosition() - dragPosition );
for( unsigned int i = 0; i < selection.items.GetCount(); ++i ) for( unsigned int i = 0; i < selection.items.GetCount(); ++i )
{ {
BOARD_ITEM* item = static_cast<BOARD_ITEM*>( selection.items.GetPickedItem( i ) ); BOARD_ITEM* item = static_cast<BOARD_ITEM*>( selection.items.GetPickedItem( i ) );
item->Move( wxPoint( movement.x, movement.y ) ); item->Move( movement + offset );
} }
updateRatsnest( true ); updateRatsnest( true );
} }
else else // Prepare to start dragging
{ {
// Prepare to drag - save items, so changes can be undone // Save items, so changes can be undone
editFrame->OnModify(); editFrame->OnModify();
editFrame->SaveCopyInUndoList( selection.items, UR_CHANGED ); editFrame->SaveCopyInUndoList( selection.items, UR_CHANGED );
offset = static_cast<BOARD_ITEM*>( selection.items.GetPickedItem( 0 ) )->GetPosition() -
wxPoint( cursor.x, cursor.y );
m_dragging = true; m_dragging = true;
} }
selection.group->ViewUpdate( VIEW_ITEM::GEOMETRY ); selection.group->ViewUpdate( VIEW_ITEM::GEOMETRY );
dragPosition = controls->GetCursorPosition();
m_toolMgr->RunAction( COMMON_ACTIONS::pointEditorUpdate ); m_toolMgr->RunAction( COMMON_ACTIONS::pointEditorUpdate );
} }
...@@ -350,6 +357,7 @@ int EDIT_TOOL::Remove( TOOL_EVENT& aEvent ) ...@@ -350,6 +357,7 @@ int EDIT_TOOL::Remove( TOOL_EVENT& aEvent )
// Save them // Save them
for( unsigned int i = 0; i < selectedItems.GetCount(); ++i ) for( unsigned int i = 0; i < selectedItems.GetCount(); ++i )
selectedItems.SetPickedItemStatus( UR_DELETED, i ); selectedItems.SetPickedItemStatus( UR_DELETED, i );
editFrame->OnModify(); editFrame->OnModify();
editFrame->SaveCopyInUndoList( selectedItems, UR_DELETED ); editFrame->SaveCopyInUndoList( selectedItems, UR_DELETED );
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment