eeschema-gal: fix cursor shape switching

This commit is contained in:
Tomasz Wlostowski 2018-08-27 15:28:21 +02:00 committed by Jeff Young
parent ccb594f599
commit 48d36f854e
13 changed files with 49 additions and 99 deletions

View File

@ -469,3 +469,22 @@ void EDA_DRAW_PANEL_GAL::onShowTimer( wxTimerEvent& aEvent )
OnShow(); OnShow();
} }
} }
void EDA_DRAW_PANEL_GAL::SetCurrentCursor( int aCursor )
{
if ( aCursor > wxCURSOR_NONE && aCursor < wxCURSOR_MAX )
{
m_currentCursor = aCursor;
}
else
{
m_currentCursor = wxCURSOR_ARROW;
}
SetCursor( (wxStockCursor) m_currentCursor );
}
void EDA_DRAW_PANEL_GAL::SetDefaultCursor()
{
SetCurrentCursor( m_defaultCursor );
}

View File

@ -201,5 +201,7 @@ void AbortBlockCurrentCommand( EDA_DRAW_PANEL* aPanel, wxDC* aDC )
screen->m_BlockLocate.SetCommand( BLOCK_IDLE ); screen->m_BlockLocate.SetCommand( BLOCK_IDLE );
aPanel->GetParent()->DisplayToolMsg( wxEmptyString ); aPanel->GetParent()->DisplayToolMsg( wxEmptyString );
aPanel->SetDefaultCursor();
// ugly, but temporary
reinterpret_cast<EDA_DRAW_PANEL_GAL*>( aPanel )->SetDefaultCursor();
} }

View File

@ -625,10 +625,6 @@ void EDA_DRAW_FRAME::SetToolID( int aId, int aCursor, const wxString& aToolMsg )
// Keep default cursor in toolbars // Keep default cursor in toolbars
SetCursor( wxNullCursor ); SetCursor( wxNullCursor );
// Change m_canvas cursor if requested.
if( m_canvas && aCursor >= 0 )
m_canvas->SetCurrentCursor( aCursor );
// Change GAL canvas cursor if requested. // Change GAL canvas cursor if requested.
if( IsGalCanvasActive() && aCursor >= 0 ) if( IsGalCanvasActive() && aCursor >= 0 )
GetGalCanvas()->SetCurrentCursor( aCursor ); GetGalCanvas()->SetCurrentCursor( aCursor );
@ -654,8 +650,6 @@ void EDA_DRAW_FRAME::SetNoToolSelected()
// Change GAL canvas cursor if requested. // Change GAL canvas cursor if requested.
if( IsGalCanvasActive() ) if( IsGalCanvasActive() )
defaultCursor = GetGalCanvas()->GetDefaultCursor(); defaultCursor = GetGalCanvas()->GetDefaultCursor();
else if( m_canvas )
defaultCursor = m_canvas->GetDefaultCursor();
SetToolID( ID_NO_TOOL_SELECTED, defaultCursor, wxEmptyString ); SetToolID( ID_NO_TOOL_SELECTED, defaultCursor, wxEmptyString );
} }
@ -1107,13 +1101,11 @@ bool EDA_DRAW_FRAME::saveCanvasTypeSetting( EDA_DRAW_PANEL_GAL::GAL_TYPE aCanvas
wxPoint EDA_DRAW_FRAME::GetCrossHairPosition( bool aInvertY ) const wxPoint EDA_DRAW_FRAME::GetCrossHairPosition( bool aInvertY ) const
{ {
printf("GetCrossHairPos\n");
// subject to change, borrow from old BASE_SCREEN for now. // subject to change, borrow from old BASE_SCREEN for now.
if( IsGalCanvasActive() ) if( IsGalCanvasActive() )
{ {
VECTOR2I cursor = GetGalCanvas()->GetViewControls()->GetCursorPosition(); VECTOR2I cursor = GetGalCanvas()->GetViewControls()->GetCursorPosition();
printf("gal %d %d\n", cursor.x, cursor.y );
return wxPoint( cursor.x, aInvertY ? -cursor.y : cursor.y ); return wxPoint( cursor.x, aInvertY ? -cursor.y : cursor.y );
} }

View File

@ -132,7 +132,7 @@ void SCH_EDIT_FRAME::HandleBlockPlace( wxDC* DC )
if( block->GetMoveVector() == wxPoint( 0, 0 ) ) if( block->GetMoveVector() == wxPoint( 0, 0 ) )
{ {
// This calls the block-abort command routine on cleanup // This calls the block-abort command routine on cleanup
m_canvas->EndMouseCapture( GetToolId(), m_canvas->GetCurrentCursor() ); m_canvas->EndMouseCapture( GetToolId(), GetGalCanvas()->GetCurrentCursor() );
return; return;
} }
@ -179,7 +179,7 @@ void SCH_EDIT_FRAME::HandleBlockPlace( wxDC* DC )
block->ClearItemsList(); block->ClearItemsList();
} }
m_canvas->EndMouseCapture( GetToolId(), m_canvas->GetCurrentCursor(), wxEmptyString, false ); m_canvas->EndMouseCapture( GetToolId(), GetGalCanvas()->GetCurrentCursor(), wxEmptyString, false );
GetCanvas()->GetView()->ClearPreview(); GetCanvas()->GetView()->ClearPreview();
GetCanvas()->GetView()->ClearHiddenFlags(); GetCanvas()->GetView()->ClearHiddenFlags();
@ -395,7 +395,7 @@ bool SCH_EDIT_FRAME::HandleBlockEnd( wxDC* aDC )
block->SetState( STATE_NO_BLOCK ); block->SetState( STATE_NO_BLOCK );
block->SetCommand( BLOCK_IDLE ); block->SetCommand( BLOCK_IDLE );
GetScreen()->SetCurItem( NULL ); GetScreen()->SetCurItem( NULL );
m_canvas->EndMouseCapture( GetToolId(), m_canvas->GetCurrentCursor(), wxEmptyString, m_canvas->EndMouseCapture( GetToolId(), GetGalCanvas()->GetCurrentCursor(), wxEmptyString,
false ); false );
} }

View File

@ -414,7 +414,7 @@ bool LIB_EDIT_FRAME::HandleBlockEnd( wxDC* aDC )
block->SetState( STATE_NO_BLOCK ); block->SetState( STATE_NO_BLOCK );
block->SetCommand( BLOCK_IDLE ); block->SetCommand( BLOCK_IDLE );
GetScreen()->SetCurItem( NULL ); GetScreen()->SetCurItem( NULL );
m_canvas->EndMouseCapture( GetToolId(), m_canvas->GetCurrentCursor(), wxEmptyString, m_canvas->EndMouseCapture( GetToolId(), GetGalCanvas()->GetCurrentCursor(), wxEmptyString,
false ); false );
m_canvas->Refresh( true ); m_canvas->Refresh( true );
} }
@ -525,7 +525,7 @@ void LIB_EDIT_FRAME::HandleBlockPlace( wxDC* DC )
block->SetState( STATE_NO_BLOCK ); block->SetState( STATE_NO_BLOCK );
block->SetCommand( BLOCK_IDLE ); block->SetCommand( BLOCK_IDLE );
GetScreen()->SetCurItem( NULL ); GetScreen()->SetCurItem( NULL );
m_canvas->EndMouseCapture( GetToolId(), m_canvas->GetCurrentCursor(), wxEmptyString, false ); m_canvas->EndMouseCapture( GetToolId(), GetGalCanvas()->GetCurrentCursor(), wxEmptyString, false );
GetCanvas()->GetView()->ClearPreview(); GetCanvas()->GetView()->ClearPreview();
GetCanvas()->GetView()->ClearHiddenFlags(); GetCanvas()->GetView()->ClearHiddenFlags();

View File

@ -612,7 +612,7 @@ void LIB_EDIT_FRAME::OnViewEntryDoc( wxCommandEvent& event )
void LIB_EDIT_FRAME::OnSelectBodyStyle( wxCommandEvent& event ) void LIB_EDIT_FRAME::OnSelectBodyStyle( wxCommandEvent& event )
{ {
m_canvas->EndMouseCapture( ID_NO_TOOL_SELECTED, m_canvas->GetDefaultCursor() ); m_canvas->EndMouseCapture( ID_NO_TOOL_SELECTED, GetGalCanvas()->GetDefaultCursor() );
if( event.GetId() == ID_DE_MORGAN_NORMAL_BUTT ) if( event.GetId() == ID_DE_MORGAN_NORMAL_BUTT )
m_convert = 1; m_convert = 1;
@ -663,7 +663,7 @@ void LIB_EDIT_FRAME::Process_Special_Functions( wxCommandEvent& event )
if( m_canvas->IsMouseCaptured() ) if( m_canvas->IsMouseCaptured() )
m_canvas->EndMouseCapture(); m_canvas->EndMouseCapture();
else else
m_canvas->EndMouseCapture( ID_NO_TOOL_SELECTED, m_canvas->GetDefaultCursor() ); m_canvas->EndMouseCapture( ID_NO_TOOL_SELECTED, GetGalCanvas()->GetDefaultCursor() );
break; break;
case ID_POPUP_LIBEDIT_DELETE_ITEM: case ID_POPUP_LIBEDIT_DELETE_ITEM:
@ -671,14 +671,11 @@ void LIB_EDIT_FRAME::Process_Special_Functions( wxCommandEvent& event )
break; break;
default: default:
m_canvas->EndMouseCapture( ID_NO_TOOL_SELECTED, m_canvas->GetDefaultCursor(), m_canvas->EndMouseCapture( ID_NO_TOOL_SELECTED, GetGalCanvas()->GetDefaultCursor(),
wxEmptyString ); wxEmptyString );
break; break;
} }
//fixme-gal
//INSTALL_UNBUFFERED_DC( dc, m_canvas );
switch( id ) switch( id )
{ {
case ID_POPUP_LIBEDIT_CANCEL_EDITING: case ID_POPUP_LIBEDIT_CANCEL_EDITING:
@ -1026,7 +1023,7 @@ void LIB_EDIT_FRAME::OnEditComponentProperties( wxCommandEvent& event )
bool partLocked = GetCurPart()->UnitsLocked(); bool partLocked = GetCurPart()->UnitsLocked();
wxString oldName = GetCurPart()->GetName(); wxString oldName = GetCurPart()->GetName();
m_canvas->EndMouseCapture( ID_NO_TOOL_SELECTED, m_canvas->GetDefaultCursor() ); m_canvas->EndMouseCapture( ID_NO_TOOL_SELECTED, GetGalCanvas()->GetDefaultCursor() );
if( GetDrawItem() && GetDrawItem()->Type() == LIB_FIELD_T ) if( GetDrawItem() && GetDrawItem()->Type() == LIB_FIELD_T )
SetDrawItem( nullptr ); // selected LIB_FIELD might be deleted SetDrawItem( nullptr ); // selected LIB_FIELD might be deleted
@ -1074,14 +1071,14 @@ void LIB_EDIT_FRAME::OnSelectTool( wxCommandEvent& aEvent )
m_lastDrawItem = NULL; m_lastDrawItem = NULL;
// Stop the current command and deselect the current tool. // Stop the current command and deselect the current tool.
m_canvas->EndMouseCapture( ID_NO_TOOL_SELECTED, m_canvas->GetDefaultCursor() ); m_canvas->EndMouseCapture( ID_NO_TOOL_SELECTED, GetGalCanvas()->GetDefaultCursor() );
LIB_PART* part = GetCurPart(); LIB_PART* part = GetCurPart();
switch( id ) switch( id )
{ {
case ID_NO_TOOL_SELECTED: case ID_NO_TOOL_SELECTED:
SetToolID( id, m_canvas->GetDefaultCursor(), wxEmptyString ); SetToolID( id, GetGalCanvas()->GetDefaultCursor(), wxEmptyString );
break; break;
case ID_MENU_ZOOM_SELECTION: case ID_MENU_ZOOM_SELECTION:
@ -1135,13 +1132,13 @@ void LIB_EDIT_FRAME::OnSelectTool( wxCommandEvent& aEvent )
break; break;
case ID_LIBEDIT_IMPORT_BODY_BUTT: case ID_LIBEDIT_IMPORT_BODY_BUTT:
SetToolID( id, m_canvas->GetDefaultCursor(), _( "Import" ) ); SetToolID( id, GetGalCanvas()->GetDefaultCursor(), _( "Import" ) );
LoadOneSymbol(); LoadOneSymbol();
SetNoToolSelected(); SetNoToolSelected();
break; break;
case ID_LIBEDIT_EXPORT_BODY_BUTT: case ID_LIBEDIT_EXPORT_BODY_BUTT:
SetToolID( id, m_canvas->GetDefaultCursor(), _( "Export" ) ); SetToolID( id, GetGalCanvas()->GetDefaultCursor(), _( "Export" ) );
SaveOneSymbol(); SaveOneSymbol();
SetNoToolSelected(); SetNoToolSelected();
break; break;

View File

@ -255,7 +255,7 @@ void LIB_EDIT_FRAME::OnSaveAll( wxCommandEvent& event )
void LIB_EDIT_FRAME::OnCreateNewPart( wxCommandEvent& event ) void LIB_EDIT_FRAME::OnCreateNewPart( wxCommandEvent& event )
{ {
m_canvas->EndMouseCapture( ID_NO_TOOL_SELECTED, m_canvas->GetDefaultCursor() ); m_canvas->EndMouseCapture( ID_NO_TOOL_SELECTED, GetGalCanvas()->GetDefaultCursor() );
SetDrawItem( NULL ); SetDrawItem( NULL );
wxString lib = getTargetLib(); wxString lib = getTargetLib();
@ -647,7 +647,7 @@ bool LIB_EDIT_FRAME::saveLibrary( const wxString& aLibrary, bool aNewFile )
wxString msg; wxString msg;
PROJECT& prj = Prj(); PROJECT& prj = Prj();
m_canvas->EndMouseCapture( ID_NO_TOOL_SELECTED, m_canvas->GetDefaultCursor() ); m_canvas->EndMouseCapture( ID_NO_TOOL_SELECTED, GetGalCanvas()->GetDefaultCursor() );
if( !aNewFile && ( aLibrary.empty() || !prj.SchSymbolLibTable()->HasLibrary( aLibrary ) ) ) if( !aNewFile && ( aLibrary.empty() || !prj.SchSymbolLibTable()->HasLibrary( aLibrary ) ) )
{ {

View File

@ -351,7 +351,7 @@ void LIB_EDIT_FRAME::EndDrawGraphicItem( wxDC* DC )
if( GetToolId() != ID_NO_TOOL_SELECTED ) if( GetToolId() != ID_NO_TOOL_SELECTED )
SetCursor( wxCURSOR_PENCIL ); SetCursor( wxCURSOR_PENCIL );
else else
SetCursor( (wxStockCursor) m_canvas->GetDefaultCursor() ); SetCursor( (wxStockCursor) GetGalCanvas()->GetDefaultCursor() );
if( GetTempCopyComponent() ) // used when editing an existing item if( GetTempCopyComponent() ) // used when editing an existing item
SaveCopyInUndoList( GetTempCopyComponent() ); SaveCopyInUndoList( GetTempCopyComponent() );

View File

@ -58,11 +58,12 @@ m_parent( aParentWindow )
m_view = new KIGFX::SCH_VIEW( true ); m_view = new KIGFX::SCH_VIEW( true );
m_view->SetGAL( m_gal ); m_view->SetGAL( m_gal );
m_gal->SetWorldUnitLength( 0.01 ); // 1 unit = 0.01 inch
m_painter.reset( new KIGFX::SCH_PAINTER( m_gal ) ); m_painter.reset( new KIGFX::SCH_PAINTER( m_gal ) );
m_view->SetPainter( m_painter.get() ); m_view->SetPainter( m_painter.get() );
m_view->SetScaleLimits( 2000000.0, 30000.0 ); m_view->SetScaleLimits( 2000000.0, 0.002 );
m_view->SetMirror( false, false ); m_view->SetMirror( false, false );
setDefaultLayerOrder(); setDefaultLayerOrder();
@ -337,16 +338,14 @@ void SCH_DRAW_PANEL::OnMouseEvent( wxMouseEvent& event )
m_PanStartCenter = GetParent()->GetScrollCenterPosition(); m_PanStartCenter = GetParent()->GetScrollCenterPosition();
m_PanStartEventPosition = event.GetPosition(); m_PanStartEventPosition = event.GetPosition();
// INSTALL_UNBUFFERED_DC( dc, this );
CrossHairOff( ); CrossHairOff( );
SetCurrentCursor( wxCURSOR_SIZING ); SetCurrentCursor( wxCURSOR_SIZING );
} }
if( event.ButtonUp( wxMOUSE_BTN_MIDDLE ) ) if( event.ButtonUp( wxMOUSE_BTN_MIDDLE ) )
{ {
// INSTALL_UNBUFFERED_DC( dc, this );
CrossHairOn(); CrossHairOn();
SetCursor( (wxStockCursor) m_defaultCursor ); SetDefaultCursor();
} }
if( event.MiddleIsDown() ) if( event.MiddleIsDown() )
@ -644,22 +643,6 @@ void SCH_DRAW_PANEL::OnKeyEvent( wxKeyEvent& event )
event.Skip(); event.Skip();
} }
void SCH_DRAW_PANEL::SetCurrentCursor( int aCursor )
{
m_currentCursor = aCursor;
SetCursor( (wxStockCursor) m_currentCursor );
}
void SCH_DRAW_PANEL::SetCurrentCursor( const wxCursor& aCursor )
{
SetCursor( aCursor );
}
void SCH_DRAW_PANEL::SetDefaultCursor()
{
SetCursor( (wxStockCursor) m_defaultCursor );
}
void SCH_DRAW_PANEL::onPaint( wxPaintEvent& aEvent ) void SCH_DRAW_PANEL::onPaint( wxPaintEvent& aEvent )
{ {
if( m_painter ) if( m_painter )

View File

@ -78,24 +78,6 @@ public:
/// @copydoc wxWindow::Refresh() /// @copydoc wxWindow::Refresh()
void Refresh( bool aEraseBackground = true, const wxRect* aRect = NULL ) override; void Refresh( bool aEraseBackground = true, const wxRect* aRect = NULL ) override;
virtual void SetCurrentCursor( int aCursor ) override;
virtual void SetCurrentCursor( const wxCursor& aCursor ) override;
virtual void SetDefaultCursor() override;
virtual int GetDefaultCursor() const override
{
return EDA_DRAW_PANEL_GAL::GetDefaultCursor();
}
/**
* Function GetCurrentCursor
* @return the current cursor shape, depending on the current selected tool
*/
virtual int GetCurrentCursor() const override
{
return EDA_DRAW_PANEL_GAL::GetCurrentCursor();
}
protected: protected:

View File

@ -161,7 +161,7 @@ void SCH_EDIT_FRAME::Process_Special_Functions( wxCommandEvent& event )
if( m_canvas->IsMouseCaptured() ) if( m_canvas->IsMouseCaptured() )
{ {
m_canvas->EndMouseCapture(); m_canvas->EndMouseCapture();
SetToolID( GetToolId(), m_canvas->GetCurrentCursor(), wxEmptyString ); SetToolID( GetToolId(), GetGalCanvas()->GetCurrentCursor(), wxEmptyString );
} }
else else
{ {
@ -463,7 +463,7 @@ void SCH_EDIT_FRAME::OnCancelCurrentCommand( wxCommandEvent& aEvent )
if( screen->IsBlockActive() ) if( screen->IsBlockActive() )
{ {
// m_canvas->SetCursor( (wxStockCursor) m_canvas->GetDefaultCursor() ); // m_canvas->SetCursor( (wxStockCursor) GetGalCanvas()->GetDefaultCursor() );
screen->ClearBlockCommand(); screen->ClearBlockCommand();
// Stop the current command (if any) but keep the current tool // Stop the current command (if any) but keep the current tool
@ -474,7 +474,7 @@ void SCH_EDIT_FRAME::OnCancelCurrentCommand( wxCommandEvent& aEvent )
if( m_canvas->IsMouseCaptured() ) // Stop the current command but keep the current tool if( m_canvas->IsMouseCaptured() ) // Stop the current command but keep the current tool
m_canvas->EndMouseCapture(); m_canvas->EndMouseCapture();
else // Deselect current tool else // Deselect current tool
m_canvas->EndMouseCapture( ID_NO_TOOL_SELECTED, m_canvas->GetDefaultCursor() ); m_canvas->EndMouseCapture( ID_NO_TOOL_SELECTED, GetGalCanvas()->GetDefaultCursor() );
} }
GetCanvas()->GetView()->ClearHiddenFlags(); GetCanvas()->GetView()->ClearHiddenFlags();
@ -489,7 +489,7 @@ void SCH_EDIT_FRAME::OnSelectTool( wxCommandEvent& aEvent )
int lastToolID = GetToolId(); int lastToolID = GetToolId();
// Stop the current command and deselect the current tool. // Stop the current command and deselect the current tool.
m_canvas->EndMouseCapture( ID_NO_TOOL_SELECTED, m_canvas->GetDefaultCursor() ); m_canvas->EndMouseCapture( ID_NO_TOOL_SELECTED, GetGalCanvas()->GetDefaultCursor() );
switch( id ) switch( id )
{ {

View File

@ -204,15 +204,12 @@ public:
return m_stealsFocus; return m_stealsFocus;
} }
virtual void SetDefaultCursor();
/** /**
* Function SetCurrentCursor * Function SetCurrentCursor
* Set the current cursor shape for this panel * Set the current cursor shape for this panel
*/ */
void SetCurrentCursor( int aCursor ) virtual void SetCurrentCursor( int aCursor );
{
m_currentCursor = aCursor;
SetCursor( (wxStockCursor) m_currentCursor );
}
/** /**
* Function GetDefaultCursor * Function GetDefaultCursor

View File

@ -359,28 +359,6 @@ public:
*/ */
virtual void CallEndMouseCapture( wxDC* aDC ) { printf("Unimplemented\n"); assert(false); };; virtual void CallEndMouseCapture( wxDC* aDC ) { printf("Unimplemented\n"); assert(false); };;
/**
* Function SetCurrentCursor
* Set the current cursor shape for drawpanel
*/
virtual void SetCurrentCursor( int aCursor ) {};
virtual void SetCurrentCursor( const wxCursor& aCursor ) {};
/**
* Function GetDefaultCursor
* @return the default cursor shape
*/
//fixme-gal
virtual int GetDefaultCursor() const = 0;
virtual void SetDefaultCursor() {};
/**
* Function GetCurrentCursor
* @return the current cursor shape, depending on the current selected tool
*/
virtual int GetCurrentCursor() const = 0;
virtual void Refresh( bool eraseBackground = true, const wxRect* rect = NULL ) {} virtual void Refresh( bool eraseBackground = true, const wxRect* rect = NULL ) {}
virtual wxWindow* GetWindow() = 0; virtual wxWindow* GetWindow() = 0;