Commit bee6b9f9 authored by Lorenzo Marcantonio's avatar Lorenzo Marcantonio

Fixes #1186269

- Refactored the common part of cursor key movement and crosshair update
  in the various GeneralControl
- Add x10 movement with the keyboard (CTRL modifier)
- Avoid fixup of the cursor position by dummy mouse movements generated
  by cursor warping (original analysis and idea Chris Gibson)
- Do key handling in a way to permit sub-pixel cursor movement 
parent 00e18d21
......@@ -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 )
}
//-----</BASE_SCREEN API moved here >--------------------------------------------
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;
}
}
......@@ -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 */
}
......
......@@ -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;
}
// Update cursor position.
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() )
{
m_canvas->CallMouseCapture( aDC, aPosition, true );
}
}
// Update cursor position.
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 */
}
......@@ -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;
}
SetCrossHairPosition( pos );
if( oldpos != GetCrossHairPosition() )
{
pos = GetCrossHairPosition();
SetCrossHairPosition( oldpos );
m_canvas->CrossHairOff( aDC );
SetCrossHairPosition( pos );
m_canvas->CrossHairOn( aDC );
wxPoint pos = aPosition;
wxPoint oldpos = GetCrossHairPosition();
GeneralControlKeyMovement( aHotKey, &pos, true );
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
}
SetCrossHairPosition( pos );
RefreshCrossHair( oldpos, aPosition, aDC );
if( aHotKey )
{
......
......@@ -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,
......
......@@ -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 )
{
......
......@@ -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 )
{
......
......@@ -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
}
......
......@@ -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 )
{
......
......@@ -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
}
......
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