diff --git a/common/draw_frame.cpp b/common/draw_frame.cpp index 976aa1e60b..1300ff9718 100644 --- a/common/draw_frame.cpp +++ b/common/draw_frame.cpp @@ -119,6 +119,7 @@ EDA_DRAW_FRAME::EDA_DRAW_FRAME( KIWAY* aKiway, wxWindow* aParent, m_GridColor = DARKGRAY; // Grid color m_snapToGrid = true; m_MsgFrameHeight = EDA_MSG_PANEL::GetRequiredHeight(); + m_movingCursorWithKeyboard = false; m_auimgr.SetFlags(wxAUI_MGR_DEFAULT|wxAUI_MGR_LIVE_RESIZE); @@ -1110,3 +1111,119 @@ void EDA_DRAW_FRAME::SetScrollCenterPosition( const wxPoint& aPoint ) } //------------------------------------------------- + +void EDA_DRAW_FRAME::RefreshCrossHair( const wxPoint &aOldPos, + const wxPoint &aEvtPos, + wxDC* aDC ) +{ + wxPoint newpos = GetCrossHairPosition(); + + // Redraw the crosshair if it moved + if( aOldPos != newpos ) + { + SetCrossHairPosition( aOldPos, false ); + m_canvas->CrossHairOff( aDC ); + SetCrossHairPosition( newpos, false ); + m_canvas->CrossHairOn( aDC ); + + if( m_canvas->IsMouseCaptured() ) + { +#ifdef USE_WX_OVERLAY + wxDCOverlay oDC( m_overlay, (wxWindowDC*)aDC ); + oDC.Clear(); + m_canvas->CallMouseCapture( aDC, aEvtPos, false ); +#else + m_canvas->CallMouseCapture( aDC, aEvtPos, true ); +#endif + } +#ifdef USE_WX_OVERLAY + else + { + m_overlay.Reset(); + } +#endif + } +} + +void EDA_DRAW_FRAME::GeneralControlKeyMovement( int aHotKey, wxPoint *aPos, + bool aSnapToGrid ) +{ + + // If requested snap the current position to the grid + if( aSnapToGrid ) + *aPos = GetNearestGridPosition( *aPos ); + + switch( aHotKey ) + { + // All these keys have almost the same treatment + case GR_KB_CTRL | WXK_NUMPAD8: case GR_KB_CTRL | WXK_UP: + case GR_KB_CTRL | WXK_NUMPAD2: case GR_KB_CTRL | WXK_DOWN: + case GR_KB_CTRL | WXK_NUMPAD4: case GR_KB_CTRL | WXK_LEFT: + case GR_KB_CTRL | WXK_NUMPAD6: case GR_KB_CTRL | WXK_RIGHT: + case WXK_NUMPAD8: case WXK_UP: case WXK_NUMPAD2: case WXK_DOWN: + case WXK_NUMPAD4: case WXK_LEFT: case WXK_NUMPAD6: case WXK_RIGHT: + { + /* Here's a tricky part: when doing cursor key movement, the + * 'previous' point should be taken from memory, *not* from the + * freshly computed position in the event. Otherwise you can't do + * sub-pixel movement. The m_movingCursorWithKeyboard oneshot 'eats' + * the automatic motion event generated by cursor warping */ + wxRealPoint gridSize = GetScreen()->GetGridSize(); + *aPos = GetCrossHairPosition(); + + // Bonus: ^key moves faster (x10) + switch( aHotKey ) + { + case GR_KB_CTRL|WXK_NUMPAD8: + case GR_KB_CTRL|WXK_UP: + aPos->y -= KiROUND( 10 * gridSize.y ); + break; + + case GR_KB_CTRL|WXK_NUMPAD2: + case GR_KB_CTRL|WXK_DOWN: + aPos->y += KiROUND( 10 * gridSize.y ); + break; + + case GR_KB_CTRL|WXK_NUMPAD4: + case GR_KB_CTRL|WXK_LEFT: + aPos->x -= KiROUND( 10 * gridSize.x ); + break; + + case GR_KB_CTRL|WXK_NUMPAD6: + case GR_KB_CTRL|WXK_RIGHT: + aPos->x += KiROUND( 10 * gridSize.x ); + break; + + case WXK_NUMPAD8: + case WXK_UP: + aPos->y -= KiROUND( gridSize.y ); + break; + + case WXK_NUMPAD2: + case WXK_DOWN: + aPos->y += KiROUND( gridSize.y ); + break; + + case WXK_NUMPAD4: + case WXK_LEFT: + aPos->x -= KiROUND( gridSize.x ); + break; + + case WXK_NUMPAD6: + case WXK_RIGHT: + aPos->x += KiROUND( gridSize.x ); + break; + + default: /* Can't happen since we entered the statement */ + break; + } + m_canvas->MoveCursor( *aPos ); + m_movingCursorWithKeyboard = true; + } + break; + + default: + break; + } +} + diff --git a/cvpcb/class_DisplayFootprintsFrame.cpp b/cvpcb/class_DisplayFootprintsFrame.cpp index 7b8b836f6f..9ccef06ec1 100644 --- a/cvpcb/class_DisplayFootprintsFrame.cpp +++ b/cvpcb/class_DisplayFootprintsFrame.cpp @@ -327,17 +327,19 @@ void DISPLAY_FOOTPRINTS_FRAME::OnSelectOptionToolbar( wxCommandEvent& event ) void DISPLAY_FOOTPRINTS_FRAME::GeneralControl( wxDC* aDC, const wxPoint& aPosition, int aHotKey ) { - wxRealPoint gridSize; - wxPoint oldpos; - PCB_SCREEN* screen = GetScreen(); - wxPoint pos = aPosition; + // Filter out the 'fake' mouse motion after a keyboard movement + if( !aHotKey && m_movingCursorWithKeyboard ) + { + m_movingCursorWithKeyboard = false; + return; + } wxCommandEvent cmd( wxEVT_COMMAND_MENU_SELECTED ); cmd.SetEventObject( this ); - pos = GetNearestGridPosition( pos ); - oldpos = GetCrossHairPosition(); - gridSize = screen->GetGridSize(); + wxPoint pos = aPosition; + wxPoint oldpos = GetCrossHairPosition(); + GeneralControlKeyMovement( aHotKey, &pos, true ); switch( aHotKey ) { @@ -367,49 +369,12 @@ void DISPLAY_FOOTPRINTS_FRAME::GeneralControl( wxDC* aDC, const wxPoint& aPositi break; case ' ': - screen->m_O_Curseur = GetCrossHairPosition(); - break; - - case WXK_NUMPAD8: /* cursor moved up */ - case WXK_UP: - pos.y -= KiROUND( gridSize.y ); - m_canvas->MoveCursor( pos ); - break; - - case WXK_NUMPAD2: /* cursor moved down */ - case WXK_DOWN: - pos.y += KiROUND( gridSize.y ); - m_canvas->MoveCursor( pos ); - break; - - case WXK_NUMPAD4: /* cursor moved left */ - case WXK_LEFT: - pos.x -= KiROUND( gridSize.x ); - m_canvas->MoveCursor( pos ); - break; - - case WXK_NUMPAD6: /* cursor moved right */ - case WXK_RIGHT: - pos.x += KiROUND( gridSize.x ); - m_canvas->MoveCursor( pos ); + GetScreen()->m_O_Curseur = GetCrossHairPosition(); break; } SetCrossHairPosition( pos ); - - if( oldpos != GetCrossHairPosition() ) - { - pos = GetCrossHairPosition(); - SetCrossHairPosition( oldpos ); - m_canvas->CrossHairOff( aDC ); - SetCrossHairPosition( pos ); - m_canvas->CrossHairOn( aDC ); - - if( m_canvas->IsMouseCaptured() ) - { - m_canvas->CallMouseCapture( aDC, aPosition, 0 ); - } - } + RefreshCrossHair( oldpos, aPosition, aDC ); UpdateStatusBar(); /* Display new cursor coordinates */ } diff --git a/eeschema/controle.cpp b/eeschema/controle.cpp index 9e64f9219e..bbb671eaae 100644 --- a/eeschema/controle.cpp +++ b/eeschema/controle.cpp @@ -205,10 +205,12 @@ SCH_ITEM* SCH_EDIT_FRAME::LocateItem( const wxPoint& aPosition, const KICAD_T aF void SCH_EDIT_FRAME::GeneralControl( wxDC* aDC, const wxPoint& aPosition, int aHotKey ) { - wxRealPoint gridSize; - SCH_SCREEN* screen = GetScreen(); - wxPoint oldpos; - wxPoint pos = aPosition; + // Filter out the 'fake' mouse motion after a keyboard movement + if( !aHotKey && m_movingCursorWithKeyboard ) + { + m_movingCursorWithKeyboard = false; + return; + } // when moving mouse, use the "magnetic" grid, unless the shift+ctrl keys is pressed // for next cursor position @@ -221,76 +223,18 @@ void SCH_EDIT_FRAME::GeneralControl( wxDC* aDC, const wxPoint& aPosition, int aH if( GetScreen()->m_BlockLocate.GetState() != STATE_NO_BLOCK ) snapToGrid = true; - if( snapToGrid ) - pos = GetNearestGridPosition( pos ); - - oldpos = GetCrossHairPosition(); - gridSize = screen->GetGridSize(); - - switch( aHotKey ) - { - case 0: - break; - - case WXK_NUMPAD8: - case WXK_UP: - pos.y -= KiROUND( gridSize.y ); - m_canvas->MoveCursor( pos ); - break; - - case WXK_NUMPAD2: - case WXK_DOWN: - pos.y += KiROUND( gridSize.y ); - m_canvas->MoveCursor( pos ); - break; - - case WXK_NUMPAD4: - case WXK_LEFT: - pos.x -= KiROUND( gridSize.x ); - m_canvas->MoveCursor( pos ); - break; - - case WXK_NUMPAD6: - case WXK_RIGHT: - pos.x += KiROUND( gridSize.x ); - m_canvas->MoveCursor( pos ); - break; - - default: - break; - } + wxPoint pos = aPosition; + wxPoint oldpos = GetCrossHairPosition(); + GeneralControlKeyMovement( aHotKey, &pos, snapToGrid ); // Update cursor position. SetCrossHairPosition( pos, snapToGrid ); - - if( oldpos != GetCrossHairPosition() ) - { - pos = GetCrossHairPosition(); - SetCrossHairPosition( oldpos, false); - m_canvas->CrossHairOff( aDC ); - SetCrossHairPosition( pos, snapToGrid ); - m_canvas->CrossHairOn( aDC ); - - if( m_canvas->IsMouseCaptured() ) - { -#ifdef USE_WX_OVERLAY - wxDCOverlay oDC( m_overlay, (wxWindowDC*)aDC ); - oDC.Clear(); - m_canvas->CallMouseCapture( aDC, aPosition, false ); -#else - m_canvas->CallMouseCapture( aDC, aPosition, true ); -#endif - } -#ifdef USE_WX_OVERLAY - else - { - m_overlay.Reset(); - } -#endif - } + RefreshCrossHair( oldpos, aPosition, aDC ); if( aHotKey ) { + SCH_SCREEN* screen = GetScreen(); + if( screen->GetCurItem() && screen->GetCurItem()->GetFlags() ) OnHotKey( aDC, aHotKey, aPosition, screen->GetCurItem() ); else @@ -303,9 +247,12 @@ void SCH_EDIT_FRAME::GeneralControl( wxDC* aDC, const wxPoint& aPosition, int aH void LIB_EDIT_FRAME::GeneralControl( wxDC* aDC, const wxPoint& aPosition, int aHotKey ) { - wxRealPoint gridSize; - wxPoint oldpos; - wxPoint pos = aPosition; + // Filter out the 'fake' mouse motion after a keyboard movement + if( !aHotKey && m_movingCursorWithKeyboard ) + { + m_movingCursorWithKeyboard = false; + return; + } // when moving mouse, use the "magnetic" grid, unless the shift+ctrl keys is pressed // for next cursor position @@ -318,73 +265,13 @@ void LIB_EDIT_FRAME::GeneralControl( wxDC* aDC, const wxPoint& aPosition, int aH if( GetScreen()->m_BlockLocate.GetState() != STATE_NO_BLOCK ) snapToGrid = true; - if( snapToGrid ) - pos = GetNearestGridPosition( pos ); - - oldpos = GetCrossHairPosition(); - gridSize = GetScreen()->GetGridSize(); - - switch( aHotKey ) - { - case 0: - break; - - case WXK_NUMPAD8: - case WXK_UP: - pos.y -= KiROUND( gridSize.y ); - m_canvas->MoveCursor( pos ); - break; - - case WXK_NUMPAD2: - case WXK_DOWN: - pos.y += KiROUND( gridSize.y ); - m_canvas->MoveCursor( pos ); - break; - - case WXK_NUMPAD4: - case WXK_LEFT: - pos.x -= KiROUND( gridSize.x ); - m_canvas->MoveCursor( pos ); - break; - - case WXK_NUMPAD6: - case WXK_RIGHT: - pos.x += KiROUND( gridSize.x ); - m_canvas->MoveCursor( pos ); - break; - - default: - break; - } + wxPoint pos = aPosition; + wxPoint oldpos = GetCrossHairPosition(); + GeneralControlKeyMovement( aHotKey, &pos, snapToGrid ); // Update the cursor position. SetCrossHairPosition( pos, snapToGrid ); - - if( oldpos != GetCrossHairPosition() ) - { - pos = GetCrossHairPosition(); - SetCrossHairPosition( oldpos, false ); - m_canvas->CrossHairOff( aDC ); - SetCrossHairPosition( pos, snapToGrid ); - m_canvas->CrossHairOn( aDC ); - - if( m_canvas->IsMouseCaptured() ) - { -#ifdef USE_WX_OVERLAY - wxDCOverlay oDC( m_overlay, (wxWindowDC*)aDC ); - oDC.Clear(); - m_canvas->CallMouseCapture( aDC, aPosition, false ); -#else - m_canvas->CallMouseCapture( aDC, aPosition, true ); -#endif - } -#ifdef USE_WX_OVERLAY - else - { - m_overlay.Reset(); - } -#endif - } + RefreshCrossHair( oldpos, aPosition, aDC ); if( aHotKey ) { @@ -397,72 +284,30 @@ void LIB_EDIT_FRAME::GeneralControl( wxDC* aDC, const wxPoint& aPosition, int aH void LIB_VIEW_FRAME::GeneralControl( wxDC* aDC, const wxPoint& aPosition, int aHotKey ) { - wxRealPoint gridSize; - SCH_SCREEN* screen = GetScreen(); - wxPoint oldpos; - wxPoint pos = aPosition; - - pos = GetNearestGridPosition( pos ); - oldpos = GetCrossHairPosition(); - gridSize = screen->GetGridSize(); - - switch( aHotKey ) + // Filter out the 'fake' mouse motion after a keyboard movement + if( !aHotKey && m_movingCursorWithKeyboard ) { - case 0: - break; - - case WXK_NUMPAD8: - case WXK_UP: - pos.y -= KiROUND( gridSize.y ); - m_canvas->MoveCursor( pos ); - break; - - case WXK_NUMPAD2: - case WXK_DOWN: - pos.y += KiROUND( gridSize.y ); - m_canvas->MoveCursor( pos ); - break; - - case WXK_NUMPAD4: - case WXK_LEFT: - pos.x -= KiROUND( gridSize.x ); - m_canvas->MoveCursor( pos ); - break; - - case WXK_NUMPAD6: - case WXK_RIGHT: - pos.x += KiROUND( gridSize.x ); - m_canvas->MoveCursor( pos ); - break; - - default: - break; + m_movingCursorWithKeyboard = false; + return; } + wxPoint pos = aPosition; + wxPoint oldpos = GetCrossHairPosition(); + GeneralControlKeyMovement( aHotKey, &pos, true ); + // Update cursor position. - SetCrossHairPosition( pos ); - - if( oldpos != GetCrossHairPosition() ) - { - pos = GetCrossHairPosition(); - SetCrossHairPosition( oldpos ); - m_canvas->CrossHairOff( aDC ); - SetCrossHairPosition( pos ); - m_canvas->CrossHairOn( aDC ); - - if( m_canvas->IsMouseCaptured() ) - { - m_canvas->CallMouseCapture( aDC, aPosition, true ); - } - } + SetCrossHairPosition( pos, true ); + RefreshCrossHair( oldpos, aPosition, aDC ); if( aHotKey ) { + SCH_SCREEN* screen = GetScreen(); + if( screen->GetCurItem() && screen->GetCurItem()->GetFlags() ) OnHotKey( aDC, aHotKey, aPosition, screen->GetCurItem() ); else OnHotKey( aDC, aHotKey, aPosition, NULL ); } - UpdateStatusBar(); + UpdateStatusBar(); /* Display cursor coordinates info */ } diff --git a/gerbview/controle.cpp b/gerbview/controle.cpp index fedb66b381..150b23d064 100644 --- a/gerbview/controle.cpp +++ b/gerbview/controle.cpp @@ -34,73 +34,19 @@ void GERBVIEW_FRAME::GeneralControl( wxDC* aDC, const wxPoint& aPosition, int aHotKey ) { - wxRealPoint gridSize; - wxPoint oldpos; - wxPoint pos = aPosition; - - pos = GetNearestGridPosition( pos ); - - oldpos = GetCrossHairPosition(); - gridSize = GetScreen()->GetGridSize(); - - switch( aHotKey ) + // Filter out the 'fake' mouse motion after a keyboard movement + if( !aHotKey && m_movingCursorWithKeyboard ) { - case WXK_NUMPAD8: - case WXK_UP: - pos.y -= KiROUND( gridSize.y ); - m_canvas->MoveCursor( pos ); - break; - - case WXK_NUMPAD2: - case WXK_DOWN: - pos.y += KiROUND( gridSize.y ); - m_canvas->MoveCursor( pos ); - break; - - case WXK_NUMPAD4: - case WXK_LEFT: - pos.x -= KiROUND( gridSize.x ); - m_canvas->MoveCursor( pos ); - break; - - case WXK_NUMPAD6: - case WXK_RIGHT: - pos.x += KiROUND( gridSize.x ); - m_canvas->MoveCursor( pos ); - break; - - default: - break; + m_movingCursorWithKeyboard = false; + return; } + wxPoint pos = aPosition; + wxPoint oldpos = GetCrossHairPosition(); + GeneralControlKeyMovement( aHotKey, &pos, true ); + SetCrossHairPosition( pos ); - - if( oldpos != GetCrossHairPosition() ) - { - pos = GetCrossHairPosition(); - SetCrossHairPosition( oldpos ); - m_canvas->CrossHairOff( aDC ); - SetCrossHairPosition( pos ); - m_canvas->CrossHairOn( aDC ); - - if( m_canvas->IsMouseCaptured() ) - { -#ifdef USE_WX_OVERLAY - wxDCOverlay oDC( m_overlay, (wxWindowDC*)aDC ); - oDC.Clear(); - m_canvas->CallMouseCapture( aDC, aPosition, false ); -#else - m_canvas->CallMouseCapture( aDC, aPosition, true ); -#endif - } -#ifdef USE_WX_OVERLAY - else - { - m_overlay.Reset(); - } -#endif - - } + RefreshCrossHair( oldpos, aPosition, aDC ); if( aHotKey ) { diff --git a/include/draw_frame.h b/include/draw_frame.h index a76e1f4cc6..44023def51 100644 --- a/include/draw_frame.h +++ b/include/draw_frame.h @@ -105,6 +105,9 @@ protected: wxOverlay m_overlay; #endif + /// One-shot to avoid a recursive mouse event during hotkey movement + bool m_movingCursorWithKeyboard; + void SetScreen( BASE_SCREEN* aScreen ) { m_currentScreen = aScreen; } /** @@ -116,6 +119,17 @@ protected: */ virtual void unitsChangeRefresh(); + /** + * Function GeneralControlKeyMovement + * Handle the common part of GeneralControl dedicated to global + * cursor keys (i.e. cursor movement by keyboard) */ + void GeneralControlKeyMovement( int aHotKey, wxPoint *aPos, bool aSnapToGrid ); + + /* Function RefreshCrosshair + * Move and refresh the crosshair after movement; also call the + * mouse capture function, if active. + */ + void RefreshCrossHair( const wxPoint &aOldPos, const wxPoint &aEvtPos, wxDC* aDC ); public: EDA_DRAW_FRAME( KIWAY* aKiway, wxWindow* aParent, FRAME_T aFrameType, diff --git a/pagelayout_editor/controle.cpp b/pagelayout_editor/controle.cpp index 5225200857..6d593faa16 100644 --- a/pagelayout_editor/controle.cpp +++ b/pagelayout_editor/controle.cpp @@ -35,68 +35,20 @@ void PL_EDITOR_FRAME::GeneralControl( wxDC* aDC, const wxPoint& aPosition, int aHotKey ) { - wxPoint pos = GetNearestGridPosition( aPosition ); - wxPoint oldpos = GetCrossHairPosition(); - wxRealPoint gridSize = GetScreen()->GetGridSize(); - - switch( aHotKey ) + // Filter out the 'fake' mouse motion after a keyboard movement + if( !aHotKey && m_movingCursorWithKeyboard ) { - case WXK_NUMPAD8: - case WXK_UP: - pos.y -= KiROUND( gridSize.y ); - m_canvas->MoveCursor( pos ); - break; - - case WXK_NUMPAD2: - case WXK_DOWN: - pos.y += KiROUND( gridSize.y ); - m_canvas->MoveCursor( pos ); - break; - - case WXK_NUMPAD4: - case WXK_LEFT: - pos.x -= KiROUND( gridSize.x ); - m_canvas->MoveCursor( pos ); - break; - - case WXK_NUMPAD6: - case WXK_RIGHT: - pos.x += KiROUND( gridSize.x ); - m_canvas->MoveCursor( pos ); - break; - - default: - break; + m_movingCursorWithKeyboard = false; + return; } - SetCrossHairPosition( pos ); + wxPoint pos = aPosition; + wxPoint oldpos = GetCrossHairPosition(); + GeneralControlKeyMovement( aHotKey, &pos, true ); - if( oldpos != GetCrossHairPosition() ) - { - pos = GetCrossHairPosition(); - SetCrossHairPosition( oldpos ); - m_canvas->CrossHairOff( aDC ); - SetCrossHairPosition( pos ); - m_canvas->CrossHairOn( aDC ); - - if( m_canvas->IsMouseCaptured() ) - { -#ifdef USE_WX_OVERLAY - wxDCOverlay oDC( m_overlay, (wxWindowDC*)aDC ); - oDC.Clear(); - m_canvas->CallMouseCapture( aDC, aPosition, false ); -#else - m_canvas->CallMouseCapture( aDC, aPosition, true ); -#endif - } -#ifdef USE_WX_OVERLAY - else - { - m_overlay.Reset(); - } -#endif - - } + // Update cursor position. + SetCrossHairPosition( pos, true ); + RefreshCrossHair( oldpos, aPosition, aDC ); if( aHotKey ) { diff --git a/pcbnew/controle.cpp b/pcbnew/controle.cpp index 06f07af712..c5f1d00f9f 100644 --- a/pcbnew/controle.cpp +++ b/pcbnew/controle.cpp @@ -284,9 +284,12 @@ BOARD_ITEM* PCB_BASE_FRAME::PcbGeneralLocateAndDisplay( int aHotKeyCode ) void PCB_EDIT_FRAME::GeneralControl( wxDC* aDC, const wxPoint& aPosition, int aHotKey ) { - wxRealPoint gridSize; - wxPoint oldpos; - wxPoint pos = aPosition; + // Filter out the 'fake' mouse motion after a keyboard movement + if( !aHotKey && m_movingCursorWithKeyboard ) + { + m_movingCursorWithKeyboard = false; + return; + } // when moving mouse, use the "magnetic" grid, unless the shift+ctrl keys is pressed // for next cursor position @@ -295,42 +298,9 @@ void PCB_EDIT_FRAME::GeneralControl( wxDC* aDC, const wxPoint& aPosition, int aH if( !aHotKey && wxGetKeyState( WXK_SHIFT ) && wxGetKeyState( WXK_CONTROL ) ) snapToGrid = false; - if( snapToGrid ) - pos = GetNearestGridPosition( pos ); - - oldpos = GetCrossHairPosition(); - - gridSize = GetScreen()->GetGridSize(); - - switch( aHotKey ) - { - case WXK_NUMPAD8: - case WXK_UP: - pos.y -= KiROUND( gridSize.y ); - m_canvas->MoveCursor( pos ); - break; - - case WXK_NUMPAD2: - case WXK_DOWN: - pos.y += KiROUND( gridSize.y ); - m_canvas->MoveCursor( pos ); - break; - - case WXK_NUMPAD4: - case WXK_LEFT: - pos.x -= KiROUND( gridSize.x ); - m_canvas->MoveCursor( pos ); - break; - - case WXK_NUMPAD6: - case WXK_RIGHT: - pos.x += KiROUND( gridSize.x ); - m_canvas->MoveCursor( pos ); - break; - - default: - break; - } + wxPoint oldpos = GetCrossHairPosition(); + wxPoint pos = aPosition; + GeneralControlKeyMovement( aHotKey, &pos, snapToGrid ); // Put cursor in new position, according to the zoom keys (if any). SetCrossHairPosition( pos, snapToGrid ); @@ -347,6 +317,7 @@ void PCB_EDIT_FRAME::GeneralControl( wxDC* aDC, const wxPoint& aPosition, int aH wxPoint curs_pos = pos; + wxRealPoint gridSize = GetScreen()->GetGridSize(); wxSize igridsize; igridsize.x = KiROUND( gridSize.x ); igridsize.y = KiROUND( gridSize.y ); @@ -368,32 +339,7 @@ void PCB_EDIT_FRAME::GeneralControl( wxDC* aDC, const wxPoint& aPosition, int aH } } - - if( oldpos != GetCrossHairPosition() ) - { - pos = GetCrossHairPosition(); - SetCrossHairPosition( oldpos, false ); - m_canvas->CrossHairOff( aDC ); - SetCrossHairPosition( pos, false ); - m_canvas->CrossHairOn( aDC ); - - if( m_canvas->IsMouseCaptured() ) - { -#ifdef USE_WX_OVERLAY - wxDCOverlay oDC( m_overlay, (wxWindowDC*)aDC ); - oDC.Clear(); - m_canvas->CallMouseCapture( aDC, aPosition, false ); -#else - m_canvas->CallMouseCapture( aDC, aPosition, true ); -#endif - } -#ifdef USE_WX_OVERLAY - else - { - m_overlay.Reset(); - } -#endif - } + RefreshCrossHair( oldpos, aPosition, aDC ); if( aHotKey ) { diff --git a/pcbnew/footprint_wizard_frame.cpp b/pcbnew/footprint_wizard_frame.cpp index 0cff8d2bb1..0e0c92cc3c 100644 --- a/pcbnew/footprint_wizard_frame.cpp +++ b/pcbnew/footprint_wizard_frame.cpp @@ -457,18 +457,19 @@ void FOOTPRINT_WIZARD_FRAME::OnActivate( wxActivateEvent& event ) void FOOTPRINT_WIZARD_FRAME::GeneralControl( wxDC* aDC, const wxPoint& aPosition, int aHotKey ) { - wxRealPoint gridSize; - wxPoint oldpos; - PCB_SCREEN* screen = GetScreen(); - wxPoint pos = aPosition; + // Filter out the 'fake' mouse motion after a keyboard movement + if( !aHotKey && m_movingCursorWithKeyboard ) + { + m_movingCursorWithKeyboard = false; + return; + } wxCommandEvent cmd( wxEVT_COMMAND_MENU_SELECTED ); - cmd.SetEventObject( this ); - pos = GetNearestGridPosition( pos ); - oldpos = GetCrossHairPosition(); - gridSize = screen->GetGridSize(); + wxPoint pos = aPosition; + wxPoint oldpos = GetCrossHairPosition(); + GeneralControlKeyMovement( aHotKey, &pos, true ); switch( aHotKey ) { @@ -498,49 +499,12 @@ void FOOTPRINT_WIZARD_FRAME::GeneralControl( wxDC* aDC, const wxPoint& aPosition break; case ' ': - screen->m_O_Curseur = GetCrossHairPosition(); - break; - - case WXK_NUMPAD8: // cursor moved up - case WXK_UP: - pos.y -= KiROUND( gridSize.y ); - m_canvas->MoveCursor( pos ); - break; - - case WXK_NUMPAD2: // cursor moved down - case WXK_DOWN: - pos.y += KiROUND( gridSize.y ); - m_canvas->MoveCursor( pos ); - break; - - case WXK_NUMPAD4: // cursor moved left - case WXK_LEFT: - pos.x -= KiROUND( gridSize.x ); - m_canvas->MoveCursor( pos ); - break; - - case WXK_NUMPAD6: // cursor moved right - case WXK_RIGHT: - pos.x += KiROUND( gridSize.x ); - m_canvas->MoveCursor( pos ); + GetScreen()->m_O_Curseur = GetCrossHairPosition(); break; } SetCrossHairPosition( pos ); - - if( oldpos != GetCrossHairPosition() ) - { - pos = GetCrossHairPosition(); - SetCrossHairPosition( oldpos ); - m_canvas->CrossHairOff( aDC ); - SetCrossHairPosition( pos ); - m_canvas->CrossHairOn( aDC ); - - if( m_canvas->IsMouseCaptured() ) - { - m_canvas->CallMouseCapture( aDC, aPosition, 0 ); - } - } + RefreshCrossHair( oldpos, aPosition, aDC ); UpdateStatusBar(); // Display new cursor coordinates } diff --git a/pcbnew/moduleframe.cpp b/pcbnew/moduleframe.cpp index 7bc72218f6..d844321bdc 100644 --- a/pcbnew/moduleframe.cpp +++ b/pcbnew/moduleframe.cpp @@ -546,9 +546,12 @@ void FOOTPRINT_EDIT_FRAME::Show3D_Frame( wxCommandEvent& event ) void FOOTPRINT_EDIT_FRAME::GeneralControl( wxDC* aDC, const wxPoint& aPosition, int aHotKey ) { - wxRealPoint gridSize; - wxPoint oldpos; - wxPoint pos = aPosition; + // Filter out the 'fake' mouse motion after a keyboard movement + if( !aHotKey && m_movingCursorWithKeyboard ) + { + m_movingCursorWithKeyboard = false; + return; + } // when moving mouse, use the "magnetic" grid, unless the shift+ctrl keys is pressed // for next cursor position @@ -558,69 +561,12 @@ void FOOTPRINT_EDIT_FRAME::GeneralControl( wxDC* aDC, const wxPoint& aPosition, if( !aHotKey && wxGetKeyState( WXK_SHIFT ) && wxGetKeyState( WXK_CONTROL ) ) snapToGrid = false; - if( snapToGrid ) - pos = GetNearestGridPosition( pos ); - - oldpos = GetCrossHairPosition(); - gridSize = GetScreen()->GetGridSize(); - - switch( aHotKey ) - { - case WXK_NUMPAD8: - case WXK_UP: - pos.y -= KiROUND( gridSize.y ); - m_canvas->MoveCursor( pos ); - break; - - case WXK_NUMPAD2: - case WXK_DOWN: - pos.y += KiROUND( gridSize.y ); - m_canvas->MoveCursor( pos ); - break; - - case WXK_NUMPAD4: - case WXK_LEFT: - pos.x -= KiROUND( gridSize.x ); - m_canvas->MoveCursor( pos ); - break; - - case WXK_NUMPAD6: - case WXK_RIGHT: - pos.x += KiROUND( gridSize.x ); - m_canvas->MoveCursor( pos ); - break; - - default: - break; - } + wxPoint oldpos = GetCrossHairPosition(); + wxPoint pos = aPosition; + GeneralControlKeyMovement( aHotKey, &pos, snapToGrid ); SetCrossHairPosition( pos, snapToGrid ); - - if( oldpos != GetCrossHairPosition() ) - { - pos = GetCrossHairPosition(); - SetCrossHairPosition( oldpos, false ); - m_canvas->CrossHairOff( aDC ); - SetCrossHairPosition( pos, snapToGrid ); - m_canvas->CrossHairOn( aDC ); - - if( m_canvas->IsMouseCaptured() ) - { -#ifdef USE_WX_OVERLAY - wxDCOverlay oDC( m_overlay, (wxWindowDC*)aDC ); - oDC.Clear(); - m_canvas->CallMouseCapture( aDC, aPosition, false ); -#else - m_canvas->CallMouseCapture( aDC, aPosition, true ); -#endif - } -#ifdef USE_WX_OVERLAY - else - { - m_overlay.Reset(); - } -#endif - } + RefreshCrossHair( oldpos, aPosition, aDC ); if( aHotKey ) { diff --git a/pcbnew/modview_frame.cpp b/pcbnew/modview_frame.cpp index dc24cf3208..e0a5302d19 100644 --- a/pcbnew/modview_frame.cpp +++ b/pcbnew/modview_frame.cpp @@ -533,17 +533,19 @@ void FOOTPRINT_VIEWER_FRAME::OnActivate( wxActivateEvent& event ) void FOOTPRINT_VIEWER_FRAME::GeneralControl( wxDC* aDC, const wxPoint& aPosition, int aHotKey ) { - wxRealPoint gridSize; - wxPoint oldpos; - PCB_SCREEN* screen = GetScreen(); - wxPoint pos = aPosition; + // Filter out the 'fake' mouse motion after a keyboard movement + if( !aHotKey && m_movingCursorWithKeyboard ) + { + m_movingCursorWithKeyboard = false; + return; + } wxCommandEvent cmd( wxEVT_COMMAND_MENU_SELECTED ); cmd.SetEventObject( this ); - pos = GetNearestGridPosition( pos ); - oldpos = GetCrossHairPosition(); - gridSize = screen->GetGridSize(); + wxPoint oldpos = GetCrossHairPosition(); + wxPoint pos = aPosition; + GeneralControlKeyMovement( aHotKey, &pos, true ); switch( aHotKey ) { @@ -573,49 +575,12 @@ void FOOTPRINT_VIEWER_FRAME::GeneralControl( wxDC* aDC, const wxPoint& aPosition break; case ' ': - screen->m_O_Curseur = GetCrossHairPosition(); - break; - - case WXK_NUMPAD8: // cursor moved up - case WXK_UP: - pos.y -= KiROUND( gridSize.y ); - m_canvas->MoveCursor( pos ); - break; - - case WXK_NUMPAD2: // cursor moved down - case WXK_DOWN: - pos.y += KiROUND( gridSize.y ); - m_canvas->MoveCursor( pos ); - break; - - case WXK_NUMPAD4: // cursor moved left - case WXK_LEFT: - pos.x -= KiROUND( gridSize.x ); - m_canvas->MoveCursor( pos ); - break; - - case WXK_NUMPAD6: // cursor moved right - case WXK_RIGHT: - pos.x += KiROUND( gridSize.x ); - m_canvas->MoveCursor( pos ); + GetScreen()->m_O_Curseur = GetCrossHairPosition(); break; } SetCrossHairPosition( pos ); - - if( oldpos != GetCrossHairPosition() ) - { - pos = GetCrossHairPosition(); - SetCrossHairPosition( oldpos ); - m_canvas->CrossHairOff( aDC ); - SetCrossHairPosition( pos ); - m_canvas->CrossHairOn( aDC ); - - if( m_canvas->IsMouseCaptured() ) - { - m_canvas->CallMouseCapture( aDC, aPosition, 0 ); - } - } + RefreshCrossHair( oldpos, aPosition, aDC ); UpdateStatusBar(); // Display new cursor coordinates }